private void detachSystemActionPerformer(JTextComponent c){ if (c == null) return; Action action = getEditorAction(c); if (action == null) return; Action globalSystemAction = getSystemAction(c); if (globalSystemAction == null) return; if (globalSystemAction instanceof CallbackSystemAction){ Object key = ((CallbackSystemAction)globalSystemAction).getActionMapKey(); ActionMap am = c.getActionMap(); if (am != null) { Object ea = am.get(key); if (action.equals(ea)) { am.remove(key); } } } }
public void editorActivated() { Action ea = getEditorAction(); Action sa = getSystemAction(); if (ea != null && sa != null) { if (updatePerformer) { if (ea.isEnabled() && sa instanceof CallbackSystemAction) { ((CallbackSystemAction)sa).setActionPerformer(this); } } if (syncEnabling) { if (enabledPropertySyncL == null) { enabledPropertySyncL = new EnabledPropertySyncListener(sa); } ea.addPropertyChangeListener(enabledPropertySyncL); } } }
private FindSupport(TopComponent tc) { this.tc = tc; bar = new FindBar(this); ActionMap actionMap = tc.getActionMap(); CallbackSystemAction a = SystemAction.get(org.openide.actions.FindAction.class); actionMap.put(a.getActionMapKey(), new FindAction(true)); actionMap.put(FIND_NEXT_ACTION, new FindAction(true)); actionMap.put(FIND_PREVIOUS_ACTION, new FindAction(false)); // Hack ensuring the same shortcuts as editor JEditorPane pane = new JEditorPane(); for (Action action : pane.getEditorKitForContentType("text/x-java").getActions()) { // NOI18N Object name = action.getValue(Action.NAME); if (FIND_NEXT_ACTION.equals(name) || FIND_PREVIOUS_ACTION.equals(name)) { reuseShortcut(action); } } // PENDING the colors below should not be hardcoded highlighterAll = new DefaultHighlighter.DefaultHighlightPainter(new Color(255,180,66)); highlighterCurrent = new DefaultHighlighter.DefaultHighlightPainter(new Color(176,197,227)); pattern = Pattern.compile("$^"); // NOI18N }
void setActions (final Node.Property pd) { final CallbackSystemAction setDefault = (CallbackSystemAction)SystemAction .get(SetDefaultValueAction.class); // Enable / Disable DefaultValueAction if (pd.supportsDefaultValue () && pd.canWrite ()) { setDefault.setActionPerformer (new ActionPerformer () { public void performAction (SystemAction a) { try { pd.restoreDefaultValue (); // workaround of bug #21182: forces a node's property change propertyChange ( new PropertyChangeEvent (this, pd.getName (), null, null)); } catch (Exception e) { setDefault.setActionPerformer (null); } } }); } else { setDefault.setActionPerformer (null); } }
@Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { boolean ret = super.processKeyBinding(ks, e, condition, pressed); // XXX #250546 Reason of overriding: to process global shortcut. if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) { Keymap km = Lookup.getDefault().lookup(Keymap.class); Action action = (km != null) ? km.getAction(ks) : null; if (action == null) { return false; } if (action instanceof CallbackSystemAction) { CallbackSystemAction csAction = (CallbackSystemAction) action; if (tabbedPane != null) { Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey()); if (a != null) { a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks))); return true; } } } return false; } else { return ret; } }
private void editorActivated(final JEditorPane editor) { //System.out.println("editor("+editor+") activated."); final Action copy = getAction (DefaultEditorKit.copyAction, editor); if (copy != null) { final CallbackSystemAction sysCopy = ((CallbackSystemAction) SystemAction.get (CopyAction.class)); final ActionPerformer perf = new ActionPerformer () { public void performAction (SystemAction action) { copy.actionPerformed (new ActionEvent (editor, 0, "")); // NOI18N } }; sysCopy.setActionPerformer(copy.isEnabled() ? perf : null); PropertyChangeListener copyListener; copy.addPropertyChangeListener(copyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("enabled".equals(evt.getPropertyName())) { // NOI18N if (((Boolean)evt.getNewValue()).booleanValue()) { sysCopy.setActionPerformer(perf); } else if (sysCopy.getActionPerformer() == perf) { sysCopy.setActionPerformer(null); } } } }); if (editor.equals(jEditorPane1)) copyL = copyListener; else copyP = copyListener; } }
private void editorActivated(final JEditorPane editor) { final Action copy = getAction (DefaultEditorKit.copyAction, editor); if (copy != null) { final CallbackSystemAction sysCopy = ((CallbackSystemAction) SystemAction.get (CopyAction.class)); final ActionPerformer perf = new ActionPerformer () { public void performAction (SystemAction action) { copy.actionPerformed (new ActionEvent (editor, 0, "")); // NOI18N } }; sysCopy.setActionPerformer(copy.isEnabled() ? perf : null); PropertyChangeListener copyListener; copy.addPropertyChangeListener(copyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("enabled".equals(evt.getPropertyName())) { // NOI18N if (((Boolean)evt.getNewValue()).booleanValue()) { sysCopy.setActionPerformer(perf); } else if (sysCopy.getActionPerformer() == perf) { sysCopy.setActionPerformer(null); } } } }); if (editor.equals(jEditorPane1)) copyL = copyListener; else copyP = copyListener; } }
private void attachSystemActionPerformer(JTextComponent c){ if (c == null) return; Action action = getEditorAction(c); if (action == null) return; Action globalSystemAction = getSystemAction(c); if (globalSystemAction == null) return; if (globalSystemAction instanceof CallbackSystemAction){ Object key = ((CallbackSystemAction)globalSystemAction).getActionMapKey(); c.getActionMap ().put (key, action); } }
/** * Lazy creation of the popup menu. Adds SetDeafulValuetAction * to the menu. */ private void createPopup() { if (popupMenu == null) { popupMenu = new JPopupMenuPlus(); // popupMenu.add (new CopyAction ().getPopupPresenter ()); // popupMenu.add (new PasteAction ().getPopupPresenter ()); // popupMenu.addSeparator (); CallbackSystemAction setDefault = (CallbackSystemAction)SystemAction.get(SetDefaultValueAction.class); popupMenu.add(setDefault.getPopupPresenter()); } }
protected Class<? extends CallbackSystemAction> actionClass() { return DeleteAction.class; }
protected Class<? extends CallbackSystemAction> actionClass() { return CopyAction.class; }
protected Class<? extends CallbackSystemAction> actionClass() { return CutAction.class; }
protected Class<? extends CallbackSystemAction> actionClass() { return PasteAction.class; }
/** Which action to test. */ protected abstract Class<? extends CallbackSystemAction> actionClass();