@Override public void performClickAction(final Document doc, final int offset, final HyperlinkType type) { UIGesturesSupport.submit("USG_CND_LINE_HYPERLINK", type); //NOI18N goToLine(doc, Utilities.getFocusedComponent(), offset, type); }
private void addAcceleretors(Action a, JMenuItem item, BaseKit kit){ // Try to get the accelerator javax.swing.text.JTextComponent target = Utilities.getFocusedComponent(); if (target == null) return; javax.swing.text.Keymap km = target.getKeymap(); if (km != null) { javax.swing.KeyStroke[] keys = km.getKeyStrokesForAction(a); if (keys != null && keys.length > 0) { item.setAccelerator(keys[0]); }else{ // retrieve via actionName String actionName = (String)a.getValue(Action.NAME); if (actionName == null) return; BaseAction action = (BaseAction)kit.getActionByName(actionName); if (action == null) return; keys = km.getKeyStrokesForAction(action); if (keys != null && keys.length > 0) { item.setAccelerator(keys[0]); } } } }
@Override public void actionPerformed(ActionEvent event) { ActiveEditorDrop drop = (ActiveEditorDrop) item.lookup(ActiveEditorDrop.class); JTextComponent target = Utilities.getFocusedComponent(); if (target == null) { String msg = NbBundle.getMessage(PHPPaletteActions.class, "MSG_ErrorNoFocusedDocument"); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE)); return; } if (drop == null) { Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, "{0} doesn''t provide {1}", new Object[]{item.getClass(), ActiveEditorDrop.class}); //NOI18N return; } try { drop.handleTransfer(target); } finally { Utilities.requestFocus(target); } try { PaletteController paletteController = PHPPaletteFactory.getPalette(); paletteController.clearSelection(); } catch (IOException ioe) { Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, null, ioe); } } }
@Override public boolean isEnabled() { if (isValid(Utilities.getFocusedComponent()) == false) { return false; } FileObject fileObject = findTargetFO(); if (fileObject != null && fileObject.canRead()) { return true; } return false; }
@Override public void performClickAction(Document originalDoc, final int offset, final HyperlinkType type) { if (originalDoc == null) { return; } final Document doc = originalDoc; final JTextComponent target = Utilities.getFocusedComponent(); if (target == null || target.getDocument() != doc) { return; } Runnable run = new Runnable() { @Override public void run() { int[] span = CsmMacroExpansion.getMacroExpansionSpan(doc, offset, false); if (type == HyperlinkType.ALT_HYPERLINK && (span != null && span[0] != span[1])) { // in this mode we open MacroView CsmMacroExpansion.showMacroExpansionView(doc, offset); } else { performAction(doc, target, offset, type); } } }; if (hyperLinkTask != null) { hyperLinkTask.cancel(); } hyperLinkTask = CsmModelAccessor.getModel().enqueue(run, "Following hyperlink");// NOI18N }
private FileObject findTargetFO() { DataObject dataObject = getDataObjectFromComponent(Utilities.getFocusedComponent()); FileObject sourceFO = dataObject.getPrimaryFile(); return getTargetFO(dataObject.getName(), sourceFO); }
public void actionPerformed(ActionEvent e) { ActiveEditorDrop drop = (ActiveEditorDrop) item.lookup(ActiveEditorDrop.class); JTextComponent target = Utilities.getFocusedComponent(); if (target == null) { String msg = NbBundle.getMessage(JspPaletteActions.class, "MSG_ErrorNoFocusedDocument"); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE)); return; } try { drop.handleTransfer(target); } finally { Utilities.requestFocus(target); } try { PaletteController pc = JspPaletteFactory.getPalette(); pc.clearSelection(); } catch (IOException ioe) { //should not occur } } }
PREPROCESSOR_MENU = createMenu(PREPROCESSOR_MENU, Utilities.getFocusedComponent()); final ActionMap am = getContextActionMap(); Action action = null;
JTextComponent target = Utilities.getFocusedComponent();
@Override public void implement() throws Exception { EditList edits = new EditList(baseDoc); int start = context.selectionStart; int end = context.selectionEnd; JTextComponent component = Utilities.getFocusedComponent(); switch (operation) { case COMMENT_OUT: edits.replace(end, 0, "*/", false, 0); edits.replace(start, 0, "/*", false, 1); edits.apply(); // Clear selection component.setCaretPosition(start); break; case ADD_IF: String START_INSERT = "if (true) {\n"; String END_INSERT = "\n}"; edits.replace(end, 0, END_INSERT, false, 0); int startOfRow = Utilities.getRowStart(baseDoc, start); edits.replace(startOfRow, 0, START_INSERT, false, 1); edits.setFormatAll(true); edits.apply(); component.setCaretPosition(start + 4); component.moveCaretPosition(start + 8); break; } }