Netbeansçšã®PB4NBãã©ã°ã€ã³ããããŸãããpastebinã®APIã®å€æŽã«ããæ©èœããŸããã ãã®ãããç¬èªã®ãã©ã°ã€ã³ãäœæãã奜ã¿ã«åãããŠæ§æãããšåæã«ãNetbeansãã©ãããã©ãŒã ãå°ãæ±ããŸãã ã«èå³ããããŸããïŒ ç«ãžããããã
æºåãã
Netbeansã®ãã©ã°ã€ã³ãäœæããã«ã¯ãæåã«éçºã¢ãžã¥ãŒã«ãã¢ã¯ãã£ãã«ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãã¡ãã¥ãŒã®ãããŒã«->ãã©ã°ã€ã³ãã«é²ã¿ããã€ã³ã¹ããŒã«æžã¿ãã¿ãã§ãNetbeansã®éçºããæå¹ã«ããŸãã 次ã«ãNetbeansãã©ãããã©ãŒã ã®ããã¥ã¡ã³ããå¿ èŠã«ãªããŸãã ããã¯ãAvailable Pluginsã¿ãã§ãã©ã°ã€ã³ãšããŠå©çšã§ããNetbeans APIããã¥ã¡ã³ããšåŒã°ããŸãã ããããããã ãã§ãã
ãããžã§ã¯ãäœæ
æ°ãããããžã§ã¯ããäœæãïŒããã¡ã€ã«->æ°èŠãããžã§ã¯ã-> Netbeansã¢ãžã¥ãŒã«->ã¢ãžã¥ãŒã«ãïŒãã次ãžããã¯ãªãã¯ããŸãã
ããããžã§ã¯ãåããã£ãŒã«ãã«ç®çã®ååãå ¥åãããããŒã¹ããã³ãã«ããŠã次ãžããã¯ãªãã¯ããŸãã
ãã³ãŒãåããŒã¹ããã£ãŒã«ãã«å ¥åããŸãããcom.pastebin.pastebinpluginããšããŸã-ããã¯ãã©ã°ã€ã³ã®ã³ãŒãåãšãªãœãŒã¹ããã³ã¯ã©ã¹ãžã®ãã¹ã®äž¡æ¹ã«ãªããŸãã ãã¢ãžã¥ãŒã«è¡šç€ºåããã£ãŒã«ãã¯ããããžã§ã¯ãå ã®ãã©ã°ã€ã³ã®è¡šç€ºåãèšå®ããŸãããPastebin.comã«éä¿¡ããšããŠå ¥åããŸãããããã«ç¬èªã®ååãå ¥åã§ããŸãã æ®ãã®ãã£ãŒã«ãã¯è§Šããªãã§ããå®äºããã¯ãªãã¯ããŸãã
æ°ãããããžã§ã¯ããäœæããããã®æ§é ã¯ãã®åœ¢åŒã«ãªã£ãŠããŸãã
ã¢ã¯ã·ã§ã³äœæ
次ã«ããã©ã°ã€ã³èªäœã®äœæãã€ãŸãã¢ã¯ã·ã§ã³ã®ã¯ã©ã¹ã«çŽæ¥é²ã¿ãŸãã ãæ°èŠã->ããã®ä»ã->ãã¢ãžã¥ãŒã«éçºãã§ãã¢ã¯ã·ã§ã³ããéžæããã次ãžããã¯ãªãã¯ããŸãã
ã¢ã¯ã·ã§ã³ã®ã¿ã€ããéžæããããã«æ±ããããŸãïŒãç¶ç¶çã«æå¹åããŸãã¯ãæäŸãããæå¹åãã éžæããã³ãŒãããšãã£ã¿ãŒããååŸãããããã€ãŸãã³ãŒããšãã£ã¿ãŒãéããŠãããšãã«ã®ã¿ãã©ã°ã€ã³ãã¢ã¯ãã£ãã«ããå¿ èŠãããããã2çªç®ã®ã¿ã€ããConditionally EnabledããéžæããŸãã ãCookieã¯ã©ã¹ãã«ãEditorCookieããé 眮ããŸããããããžã§ã¯ãå šäœã§ã¯ãªãããšãã£ã¿ãŒãžã®ã¢ã¯ã»ã¹ãå¿ èŠãªããã§ãã EditorCookieããµããŒããããµã€ããå°ãªããšã1ã€éããšãã«ãã©ã°ã€ã³ã䜿çšå¯èœã§ããå¿ èŠãããããããUser Selects One Nodeãã¯éžæããããŸãŸã§ãã ã次ãžããã¯ãªãã¯ããŸãã
次ã®ã¹ãããã§ã¯ããã©ã°ã€ã³ã®GUIãç»é²ããŸãã ã€ãŸããNetbeansãŠã£ã³ããŠå ã®å Žæã§ãã ä»»æã®ã¡ãã¥ãŒãããŒã«ããŒãããã³ã³ã³ããã¹ãã¡ãã¥ãŒã§äœ¿çšå¯èœãªå Žæã ãŸããã«ããŽãªãèšå®ããŸãããã ææ¡ããããªã¹ãããããç·šéããšããœãŒã¹ããç§ãã¡ã«æãé©ããŠããŸããæã奜ããªãã®ãéžæããæåã«éžæããŸããã 次ã«ããã©ã°ã€ã³ãåŒã³åºãã®ãæãç°¡åã«ãªãæ¹æ³ã«ã€ããŠèããå¿ èŠããããŸãã å人çã«ã¯ãåžžã«ç®ã®åã«ããã«ã«ã¢ã€ã³ã³ã衚瀺ãããããªãã®ã§ã[ç·šé]ã¡ãã¥ãŒã®[貌ãä»ã]ã¢ã€ãã ã®çŽåŸã«ã¢ã€ãã ãè¿œå ããŸããã ããã«ã®ã¢ã€ã³ã³ãã¯ãªãã¯ããŠãã©ã°ã€ã³ãèµ·åããæ¹ã䟿å©ãªå Žåã¯ããã°ããŒãã«ããŒã«ããŒãã¿ã³ãã®åã«ãã§ãã¯ããŒã¯ãä»ããŠã䟿å©ãªå ŽæãéžæããŸãã ãã¹ãŠãå³ããããã«æ§æãããã次ã®æé ã«é²ã¿ãŸãã
ã¯ã©ã¹åã«ã¯ãPastebinActionããå ¥åãããŸãã ããã¯ã¡ãã¥ãŒé ç®ã®è¡šç€ºåã§ãããããããšãã°ãpastebin.comã«éä¿¡ããªã©ãã衚瀺åããã§ããã ãæ確ã«å ¥åããããšããå§ãããŸãã 次ã«ã16x16ã¢ã€ã³ã³ãéžæããŸãã åã®æé ã§ããŒã«ããŒã®å Žæãéžæããå Žåã24x24ã®ãµã€ãºã®ã¢ã€ã³ã³ãè¿œå ããå¿ èŠããããŸãã ãã®åŸããå®äºããã¯ãªãã¯ããŸãã
ãããã®èšå®ã¯ãã¹ãŠãçæãããã³ãŒãã«è¡šç€ºãããŸãã
@ActionID( category = "Edit", id = "com.pastebin.pastebinplugin.PastebinAction") @ActionRegistration( iconBase = "com/pastebin/pastebinplugin/pastebin.png", displayName = "#CTL_PastebinAction") @ActionReference(path = "Menu/Edit", position = 1250) @Messages("CTL_PastebinAction=Send to pastebin.com")
æåã®æã¡äžã
ãŸã äœãæžããŠããŸããããæ€èšŒã®ããã«ãã©ã°ã€ã³ãå®è¡ããããšã¯ãã§ã«å¯èœã§ãã ãå®è¡ããã¯ãªãã¯ããŠãæ°ããNetbeansãŠã£ã³ããŠã衚瀺ãããã®ãåŸ ã¡ãŸãã ãã®åŸãä»»æã®ããã¹ããã¡ã€ã«ãéããåæ§ã®ç»åã確èªããŸãã
äžæãªçç±ã«ãããæ°ããNetbeansãŠã£ã³ããŠã¯ãã·ã¢èªã®ããŒã«ã©ã€ãºããå§ãŸããŸããããåé¡ã§ã¯ãããŸãããããã«ãã©ã°ã€ã³ã«ãã·ã¢èªãæããŸãããä»ã®ãšããããŠã£ã³ããŠãéããŠãæçµçã«ã³ãŒããæžãå§ããŸã
ã«ãŒãã³
ãã©ã°ã€ã³ã®å®è¡ã¯actionPerformedã¡ãœããã§å§ãŸããšæšæž¬ããããããããã®ã¡ãœããã®æ¬äœã«ã³ãŒããèšè¿°ããŸãã ãŸãã¯ãIDEèªäœãæäŸããEditorCookieãè©ŠããŠã¿ãŸãããã ãã ãããã®åã«å¿ èŠãªã©ã€ãã©ãªãè¿œå ããŸããããããªããšãåŸç¶ã®ã³ãŒããã³ã³ãã€ã«ãããŸããã
ãããžã§ã¯ãã®ããããã£ã§ããã©ã€ãã©ãªãã¿ããéžæãããè¿œå ããã¯ãªãã¯ããŸãã
ãNodes APIããšãEditorããè¿œå ããŸãã
次ã®ã³ãŒããæžããŸãããã
public void actionPerformed(ActionEvent ev) { try { JEditorPane pane = context.getOpenedPanes()[0]; pane.setText("// Hello, editor pane!\n"+pane.getText()); context.openDocument().insertString(0, "// Hello, document!\n", null); } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
ãã®ã³ãŒãã¯ããã©ã°ã€ã³ãåŒã³åºããããšããªãŒãã³ãœãŒã¹ããã¹ãã«æ°è¡ãè¿œå ããŸãã ããã¯ãJEditorPaneãšStyledDocumentã®2ã€ã®ç°ãªãæ¹æ³ã§è¡ãããŸãã
ãããžã§ã¯ããèµ·åãããã¡ã€ã«ãéããŠãã©ã°ã€ã³ãåŒã³åºããšã2è¡ãè¿œå ãããããšãããããŸãã
//ããã«ã¡ã¯ãããã¥ã¡ã³ãïŒ
//ããã«ã¡ã¯ããšãã£ã¿ãã€ã³ïŒ
ããŠããã©ã°ã€ã³èªäœã®äœæãç¶ããŸãããã pastebinã§æ§æã®åŒ·èª¿è¡šç€ºãæ£ããæ§æã§ããããã«ãç·šéãããœãŒã¹ã®åœ¢åŒã ãã§ãªããããã¹ãã®éžæããéšåãååŸããå¿ èŠããããŸãã æåã®ã¡ãœããã§ããJEditorPaneã䜿çšããŸããããã«ã¯ãå¿ èŠãªãã¹ãŠã®ã¡ãœãããå«ãŸããŠããããã§ãã ç·šéäžã®ããã¥ã¡ã³ãã®MIMEã¿ã€ãã«åºã¥ããŠãæ§æ匷調衚瀺圢åŒãååŸããŸãã
public void actionPerformed(ActionEvent ev) { JEditorPane currentPane = context.getOpenedPanes()[0]; final String mimeType = NbEditorUtilities.getMimeType(currentPane); final String code = getSelectedText(currentPane); System.out.println(mimeType + "\n" + code); } private String getSelectedText(JEditorPane currentPane) { String text = currentPane.getSelectedText(); if (text == null) return currentPane.getText(); return text; }
ãããžã§ã¯ããå®è¡ããã³ãŒãã®äžéšãéžæãããã©ã°ã€ã³ãå®è¡ããŠãã³ã³ãœãŒã«ã§çµæã確èªããŸãã 次ã«ããã©ã°ã€ã³ãå®è¡ããããã«äœã匷調衚瀺ããªãã§ãã ãã-ãœãŒã¹ã³ãŒãå šäœãã³ã³ãœãŒã«ã«è¡šç€ºãããŸãã åŸè ã®æ©èœã¯ãã³ãŒããå®å šã«éä¿¡ããªããã°ãªããªãå Žåãããããã䟿å©ãªããã«æããŸããã
ãããã£ãŠãã³ãŒããšãã®MIMEã¿ã€ããæå ã«çœ®ããŠãã¯ã©ã€ã¢ã³ãã®äœæãéå§ã§ããŸãã ããã§ãPastebin APIã®ãã«ããååŸããéçºè ããŒãèŠã€ããããšãã§ããŸãã
ã³ãŒãïŒ PastebinRequest ã PastebinSender ã
ãã£ãŒã«ããè¿œå ããŸãã
ãã©ã€ããŒãã®æçµPastebinRequestãªã¯ãšã¹ãã
ãããŠãã³ã³ã¹ãã©ã¯ã¿ãŒã§åæåããŸãã
request = new PastebinRequestïŒïŒ;
次ã«ãactionPerformedã¡ãœãããæŽæ°ããŸãã
JEditorPane currentPane = context.getOpenedPanes()[0]; final String mimeType = NbEditorUtilities.getMimeType(currentPane); final String code = getSelectedText(currentPane); if (code != null) { RequestProcessor.getDefault().execute(new Runnable() { @Override public void run() { setupRequest(code, mimeType); String pastedUrl = PastebinSender.sendRequest(request.getRequestMessage()); System.out.println(pastedUrl); } }); }
ããŒãºã«åãããŠsetupRequestã¡ãœãããæ§æããŸããããèªåã§ãã©ã¡ãŒã¿ãŒãå€æŽã§ããŸãã
private void setupRequest(String code, String mimeType) { request.initRequest(); request.setSourceCode(code); request.setFormat(mimeType); request.setExpireDate(PastebinRequest.EXPIRE_DATE.ONE_DAY); request.setUnlisted(true); request.setName(""); }
éå§ããåã«ããããããŒãè¿œå ããŠã¢ã¯ãã£ãåããããšã«ããããã©ã°ã€ã³ã®åŒã³åºããåçŽåããŸãããã
次ã®è¡ã眮ãæããŸãã
@ActionReferenceïŒãã¹= "ã¡ãã¥ãŒ/ç·šé"ãäœçœ®= 1250ïŒ
ã«ïŒ
@ActionReferencesïŒ{
@ActionReferenceïŒpath = "Menu / Edit"ãposition = 1250ïŒã
@ActionReferenceïŒãã¹=ãã·ã§ãŒãã«ããããåå=ãOS-PãïŒ
}ïŒ
ãã®å ŽåããOS-Pãã¯ãAlt + Shift + Pããæå³ããŸãã æ¢åã®ãããããŒãšç«¶åããªãå Žåããããžã§ã¯ããéå§ãããšã次ã®ããã«è¡šç€ºãããŸãã
ããã¹ããéžæããæå®ãããçµã¿åãããã¯ãªãã¯ããŠãã³ã³ãœãŒã«ã«æçš¿ãããã³ãŒããžã®ãªã³ã¯ã確èªããŸãã ãããããç§ãã¡ã¯ãã£ãïŒ ãã®ãªã³ã¯ãå«ããã€ã¢ãã°ããã¯ã¹ã衚瀺ããã ãã§ãã å§ããŸãããã
æ°ããã¯ã©ã¹ãäœæãããUrlDialogããšåŒã³ãŸãã ãã®ã¯ã©ã¹ã®ãœãŒã¹ã³ãŒãã¯ãã¡ãã§ãã PastebinActionã¯ã©ã¹ã«ã¡ãœãããè¿œå ããŸãã
private void showUrlDialog(final String pastedUrl) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Frame frame = WindowManager.getDefault().getMainWindow(); UrlDialog dialog = new UrlDialog(frame, pastedUrl); dialog.setLocation(frame.getWidth() / 2, frame.getHeight()/2); dialog.setVisible(true); } }); }
actionPerformedã¡ãœããã§ã次ã®è¡ã眮ãæããŸãã
System.out.printlnïŒpastedUrlïŒ;
ã«ïŒ
showUrlDialogïŒpastedUrlïŒ;
ãŸãããããžã§ã¯ãã®ããããã£ã§å¥ã®ã©ã€ãã©ãªãè¿œå ããå¿ èŠããããŸãããã®ããããã©ã€ãã©ãªãã¿ããå床éããããŠã£ã³ããŠã·ã¹ãã APIããè¿œå ããŸãã
æåŸã«ãBundle.propertiesããŒã«ã©ã€ãºãã¡ã€ã«ãéããŠã次ã®è¡ãè¿œå ããå¿ èŠããããŸãã
UrlDialog.title =貌ãä»ããããURL
UrlDialog.copyButton.text =ã³ããŒ
ããã§ãããžã§ã¯ããéå§ã§ããŸãã ã³ãŒããéžæãããã©ã°ã€ã³ãã¢ã¯ãã£ãã«ããŠããŠã£ã³ããŠã確èªããŸãã
ãã³ããŒããã¿ã³ãã¯ãªãã¯ãããšããªã³ã¯ãã¯ãªããããŒãã«ã³ããŒãããŸãã ãã®ãŠã£ã³ããŠã¯ã³ããŒåŸããã«éããããšãã§ããŸããéåžžããŠã£ã³ããŠã衚瀺ããããšã¯ã§ããŸããããããã«ã¯ãªããããŒãã«ã³ããŒããŸãã ããªãã®æ³ååã瀺ããããªãã奜ããªããã«ããŠãã ããã
ããŒã«ãªãŒãŒã·ã§ã³
èšäºã®éäžã§ããã©ã°ã€ã³ã«ãã·ã¢èªãæããããšãçŽæããŸããã é£ãããããŸããã PastebinActionã¯ã©ã¹ã®åã®ææ°ã®æ³šéãèŠãŠãã ããã è¡ãèªç€ºããŸãïŒ
@MessagesïŒ "CTL_PastebinAction = pastebin.comã«éä¿¡"ïŒ
åé€ããŠããBundle.propertiesãéããŠãããã«è¡ãè¿œå ããŠãã ããïŒ
CTL_PastebinAction = pastebin.comã«éä¿¡
次ã«ããããžã§ã¯ããã©ãŠã¶ãŠã£ã³ããŠã§ãBundle.propertiesãã¡ã€ã«ãå³ã¯ãªãã¯ãããè¿œå ->ãã±ãŒã«ããéžæããŸãã äºåå®çŸ©ãããããŒã«ãªãŒãŒã·ã§ã³ã®ãªã¹ãããããã·ã¢èªãéžæãããOKããã¯ãªãã¯ããŸãã
æ°ãããã¡ã€ã«ãè¿œå ãããéããŠå€æŽããå¿ èŠããããŸãã æåã®è¡ã¯ç¿»èš³ã§ããŸããã翻蚳ããªããšããããžã§ã¯ããã©ãŠã¶ãŠã£ã³ããŠã§ç¿»èš³ãããèŠãç®ãæªããªããŸãã
OpenIDE-Module-Name = Pastebin.comã«éä¿¡
UrlDialog.title =ãªã³ã¯
UrlDialog.copyButton.text =ã³ããŒ
CTL_PastebinAction = pastebin.comã«éä¿¡
ããŠãäœæ¥ã確èªããæéã§ãã éå§ããŠç¢ºèªããŸãïŒ
NBMã¢ãžã¥ãŒã«ã®äœæ
ãããã£ãŠãæåŸã«è¡ãããšã¯ããã©ã°ã€ã³ãNetbeansã«æ¥ç¶ããããšã§ãã ãããžã§ã¯ãã®ã¿ã€ãã«ãå³ã¯ãªãã¯ããŠããCreate NBMããéžæããŸãã Netbeansã¯ãããã©ã°ã€ã³ã®è¿œå ããã¯ãªãã¯ããŠnbmãã¡ã€ã«ãéžæããããšã§ããããŒã«ã->ããã©ã°ã€ã³ã->ãããŠã³ããŒããã«ã®ã¿æ¥ç¶ãããããããããããã¡ã€ã«ã«ã¢ã¯ãã£ããã£ã®è£œåãåéããŸãã
ãŸãšã
Netbeansçšã«ç¬èªã®ãã©ã°ã€ã³ãäœæããèªåçšã«ã«ã¹ã¿ãã€ãºããŸããããŸããNetbeansãã©ãããã©ãŒã ã«å°ã粟éããŸããã
ãããžã§ã¯ãå šäœã¯ãã¡ãããããŠã³ããŒãã§ããŸã ã
Netbeansãã©ãããã©ãŒã ã«é¢ããæ å ±ã¯ããŸããããŸããããå°ãªããšãäœããèŠã€ããããšãã§ãããªã³ã¯ããããŸãã