private void init() { // Close the dialog when Esc is pressed String cancelName = "cancel"; InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = getRootPane().getActionMap(); actionMap.put(cancelName, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } }); DefaultComboBoxModel<String> comboBoxModel = (DefaultComboBoxModel<String>) encodingComboBox.getModel(); for (Map.Entry<String, Charset> entry : Charset.availableCharsets().entrySet()) { if (!"UTF-8".equals(entry.getKey())) { comboBoxModel.addElement(entry.getValue().name()); } } }
/** Converts an action map to a string representation. */ static public String toString(ActionMap am) { StringBuilder result = new StringBuilder(); LinkedHashMap<Object,Object> map = new LinkedHashMap<>(); for (Object key : am.allKeys()) { map.put(key, am.get(key)); } result.append(map); result.append('\n'); ActionMap parent = am.getParent(); if (parent != null) { result.append("Parent: "); result.append(toString(parent)); } return result.toString(); }
private static void exchangeCommands(String[][] commandsToExchange, final JComponent target, final JComponent source) { InputMap targetBindings = target.getInputMap(); KeyStroke[] targetBindingKeys = targetBindings.allKeys(); ActionMap targetActions = target.getActionMap(); InputMap sourceBindings = source.getInputMap(); ActionMap sourceActions = source.getActionMap(); for (int i = 0; i < commandsToExchange.length; i++) { String commandFrom = commandsToExchange[i][0]; String commandTo = commandsToExchange[i][1]; final Action orig = targetActions.get(commandTo); if (orig == null) { continue; } sourceActions.put(commandTo, new AbstractAction() { public void actionPerformed(ActionEvent e) { orig.actionPerformed(new ActionEvent(target, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers())); } }); for (int j = 0; j < targetBindingKeys.length; j++) { if (targetBindings.get(targetBindingKeys[j]).equals(commandFrom)) { sourceBindings.put(targetBindingKeys[j], commandTo); } } } }
MVMapElement(TLDataObject dataObject) { // Hack if (Beans.isDesignTime()) { Beans.setDesignTime(false); } this.dataObject = dataObject; glPanel = new TLMapGLPanel(dataObject.getDatabase().getMap(), dataObject.getDatabase()); slider = new TLSlider(dataObject.getDatabase()); elementPanel = new JPanel(new BorderLayout()); elementPanel.add(glPanel, BorderLayout.CENTER); elementPanel.add(slider, BorderLayout.PAGE_END); ActionMap map = new ActionMap(); map.put("save", SystemAction.get(SaveAction.class)); elementPanel.setActionMap(map); lookupContent = new InstanceContent(); lookup = new ProxyLookup(dataObject.getLookup(), new AbstractLookup(lookupContent)); }
@RandomlyFails // NB-Core-Build #7816: expected:<0> but was:<1> public void testPropertyChangeListenersDetachedAtFinalizeIssue58100() throws Exception { class MyAction extends AbstractAction implements ActionPerformer { public void actionPerformed(ActionEvent ev) { } public void performAction(SystemAction a) { } } MyAction action = new MyAction(); ActionMap map = new ActionMap(); CallbackSystemAction systemaction = (CallbackSystemAction)SystemAction.get(SimpleCallbackAction.class); map.put(systemaction.getActionMapKey(), action); Lookup context = Lookups.singleton(map); Action delegateaction = systemaction.createContextAwareInstance(context); assertTrue("Action is expected to have a PropertyChangeListener attached", action.getPropertyChangeListeners().length > 0); Reference actionref = new WeakReference(systemaction); systemaction = null; delegateaction = null; assertGC("CallbackSystemAction is supposed to be GCed", actionref); assertEquals("Action is expected to have no PropertyChangeListener attached", 0, action.getPropertyChangeListeners().length); }
private void sendAction(final Object key) throws Exception { class Process implements Runnable { @Override public void run() { final ActionMap map = treeView.tree.getActionMap(); Action a = map.get(key); String all = Arrays.toString(map.allKeys()).replace(',', '\n'); assertNotNull("Action for key " + key + " found: " + all, a); a.actionPerformed(new ActionEvent(treeView.tree, 0, null)); } } Process processEvent = new Process(); LOG.log(Level.INFO, "Sending action {0}", key); SwingUtilities.invokeAndWait(processEvent); LOG.log(Level.INFO, "Action {0} send", key); }
private boolean initActionMapInEDT() { // Init action map: cut,copy,delete,paste actions. javax.swing.ActionMap am = editor.getActionMap(); //#43157 - editor actions need to be accessible from outside using the TopComponent.getLookup(ActionMap.class) call. // used in main menu enabling/disabling logic. javax.swing.ActionMap paneMap = pane.getActionMap(); // o.o.windows.DelegateActionMap.setParent() leads to CloneableEditor.getEditorPane() provideUnfinishedPane = true; try { am.setParent(paneMap); } finally { provideUnfinishedPane = false; } //#41223 set the defaults befor the custom editor + kit get initialized, giving them opportunity to // override defaults.. paneMap.put(DefaultEditorKit.cutAction, getAction(DefaultEditorKit.cutAction)); paneMap.put(DefaultEditorKit.copyAction, getAction(DefaultEditorKit.copyAction)); paneMap.put("delete", getAction(DefaultEditorKit.deleteNextCharAction)); // NOI18N paneMap.put(DefaultEditorKit.pasteAction, getAction(DefaultEditorKit.pasteAction)); return true; }
private void init() { initialized = true; setDefaultRenderer(Object.class, new DefaultOutlineCellRenderer()); ActionMap am = getActionMap(); //make rows expandable with left/rigt arrow keys Action a = am.get("selectNextColumn"); //NOI18N am.put("selectNextColumn", new ExpandAction(true, a)); //NOI18N a = am.get("selectPreviousColumn"); //NOI18N am.put("selectPreviousColumn", new ExpandAction(false, a)); //NOI18N getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (getSelectedRowCount() == 1) { selectedRow = getSelectedRow(); } else { selectedRow = -1; } } }); }
/** Creates new form TemplatesPanel */ public TemplatesPanel (String pathToSelect) { ActionMap map = getActionMap (); map.put (DefaultEditorKit.copyAction, ExplorerUtils.actionCopy (getExplorerManager ())); map.put (DefaultEditorKit.cutAction, ExplorerUtils.actionCut (getExplorerManager ())); map.put (DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste (getExplorerManager ())); map.put ("delete", ExplorerUtils.actionDelete (getExplorerManager (), true)); // NOI18N initComponents (); createTemplateView (); treePanel.add (view, BorderLayout.CENTER); associateLookup (ExplorerUtils.createLookup (getExplorerManager (), map)); initialize (pathToSelect); }
ResultPanelTree(ResultDisplayHandler displayHandler, StatisticsPanel statPanel) { super(new BorderLayout()); treeView = new ResultTreeView(); treeView.getAccessibleContext().setAccessibleName(Bundle.ACSN_TestResults()); treeView.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_TestResults()); treeView.setBorder(BorderFactory.createEtchedBorder()); // resultBar.setPassedPercentage(0.0f); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.add(resultBar); toolBar.setBorder(BorderFactory.createEtchedBorder()); add(toolBar, BorderLayout.NORTH); add(treeView, BorderLayout.CENTER); explorerManager = new ExplorerManager(); explorerManager.setRootContext(rootNode = new RootNode(displayHandler.getSession(), filterMask)); explorerManager.addPropertyChangeListener(this); initAccessibility(); this.displayHandler = displayHandler; this.statPanel = statPanel; displayHandler.setLookup(ExplorerUtils.createLookup(explorerManager, new ActionMap())); }
/** Opened for the first time */ @Override protected void componentOpened() { Log.getLogger().entering("QueryBuilder", "componentOpened"); activateActions(); ActionMap map = getActionMap(); InputMap keys = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); installActions(map, keys); // QueryBuilder does not need to listen to VSE, because it will notify us // directly if something changes. The SqlCommandCustomizer needs to listen // to VSE, because that's the only way it is notified of changes to the command // sqlStatement.addPropertyChangeListener(sqlStatementListener) ; // vse.addPropertyChangeListener(sqlStatementListener) ; // do NOT force a parse here. It's done in componentShowing(). // populate( sqlStatement.getCommand()) ; }
public JComponent getComponent() { if (panel == null) { final BeanTreeView view = new BeanTreeView(); view.setRootVisible(false); view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); class Panel extends JPanel implements ExplorerManager.Provider, Lookup.Provider { // Make sure action context works correctly: private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap()); { setLayout(new BorderLayout()); add(view, BorderLayout.CENTER); } public ExplorerManager getExplorerManager() { return manager; } public Lookup getLookup() { return lookup; } } panel = new Panel(); } return panel; }
public JComponent getComponent() { if (panel == null) { final BeanTreeView view = new BeanTreeView(); view.setRootVisible(true); view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); class Panel extends JPanel implements ExplorerManager.Provider, Lookup.Provider { // Make sure action context works correctly: private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap()); { setLayout(new BorderLayout()); add(view, BorderLayout.CENTER); } public ExplorerManager getExplorerManager() { return manager; } public Lookup getLookup() { return lookup; } } panel = new Panel(); } return panel; }
/** * Test of allKeys method, of class DelegateActionMap. */ @Test public void testNPEinAllKeys() { System.out.println( "allKeys" ); TopComponent tc = new TopComponent(); ActionMap delegate = new ActionMap(); delegate.put( "test", new AbstractAction() { @Override public void actionPerformed( ActionEvent e ) { throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. } }); assertNotNull( delegate.allKeys() ); DelegateActionMap instance = new DelegateActionMap( tc, delegate ); Object[] result = instance.allKeys(); assertNotNull( result ); instance.clear(); result = instance.allKeys(); assertNotNull( result ); }
/** Creates new form LicensePanel */ public LicensePanel(URL url) { this.url = url; initComponents(); initAccessibility(); try { jEditorPane1.setPage(url); } catch (IOException exc) { //Problem with locating file System.err.println("Exception: " + exc.getMessage()); //NOI18N exc.printStackTrace(); } ActionMap actionMap = jEditorPane1.getActionMap(); actionMap.put(DefaultEditorKit.upAction, new ScrollAction(-1)); actionMap.put(DefaultEditorKit.downAction, new ScrollAction(1)); }
/** Creates new form CatalogPanel */ public CatalogPanel() { ActionMap map = getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(getExplorerManager())); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(getExplorerManager())); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(getExplorerManager())); map.put("delete", ExplorerUtils.actionDelete(getExplorerManager(), true)); // NOI18N initComponents(); createCatalogView(); treePanel.add(view, BorderLayout.CENTER); associateLookup(ExplorerUtils.createLookup(getExplorerManager(), map)); initialize(); }
private void init() { manager = new ExplorerManager(); helpAction = new HelpAction(); final ActionMap map = AbstractDesignEditor.this.getActionMap(); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0), ACTION_INVOKE_HELP); map.put(ACTION_INVOKE_HELP, helpAction); SaveAction act = (SaveAction) org.openide.util.actions.SystemAction.get(SaveAction.class); KeyStroke stroke = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(stroke, "save"); //NOI18N map.put("save", act); //NOI18N associateLookup(ExplorerUtils.createLookup(manager, map)); manager.addPropertyChangeListener(new NodeSelectedListener()); setLayout(new BorderLayout()); }
public ListViewNavigatorPanel () { manager = new ExplorerManager(); ActionMap map = getActionMap(); copyAction = ExplorerUtils.actionCopy(manager); map.put(DefaultEditorKit.copyAction, copyAction); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false lookup = ExplorerUtils.createLookup(manager, map); listView = new ListView(); fillListView(listView); add(listView); }
public void testChangeOfNodeDoesNotFireChangeInActionMap() { ActionMap am = (ActionMap)tc.getLookup().lookup(ActionMap.class); assertNotNull(am); Node m1 = new AbstractNode(Children.LEAF); m1.setName("old m1"); Node m2 = new AbstractNode(Children.LEAF); m2.setName("new m2"); tc.setActivatedNodes(new Node[] { m1 }); assertEquals("No change in ActionMap 1", 0, cnt); tc.setActivatedNodes(new Node[] { m2 }); assertEquals("No change in ActionMap 2", 0, cnt); tc.setActivatedNodes(new Node[0]); assertEquals("No change in ActionMap 3", 0, cnt); tc.setActivatedNodes(null); assertEquals("No change in ActionMap 4", 0, cnt); ActionMap am2 = (ActionMap)tc.getLookup().lookup(ActionMap.class); assertEquals("Still the same action map", am, am2); }
/** Change all that do not survive ActionMap change */ @Override public final void resultChanged(org.openide.util.LookupEvent ev) { Collection<? extends Lookup.Item<? extends ActionMap>> all = result.allItems(); ActionMap a = all.isEmpty() ? null : all.iterator().next().getInstance(); if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "changed map : {0}", a); // NOI18N LOG.log(Level.FINE, "previous map: {0}", actionMap.get()); // NOI18N } final ActionMap prev = actionMap.get(); if (a == prev) { return; } final ActionMap newMap = newMap(prev, a); actionMap = new WeakReference<ActionMap>(newMap); if (LOG.isLoggable(Level.FINE)) { LOG.fine("clearActionPerformers"); // NOI18N } Mutex.EVENT.readAccess(new Runnable() { @Override public void run() { notifyListeners(prev, newMap); } }); }
protected void installKeyboard() { InputMap im = getInputMap(); ActionMap am = getActionMap(); installKeyboardAction(im, am, COPY_ACTION); installKeyboardAction(im, am, CUT_ACTION); installKeyboardAction(im, am, PASTE_ACTION); installKeyboardAction(im, am, FILL_ACTION); installKeyboardAction(im, am, CLEAR_ACTION); }
/** * Adds key bindings to this popup. */ private void installKeyBindings() { InputMap im = getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escapeKS = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); im.put(escapeKS, "onEscape"); am.put("onEscape", new EscapeAction()); }
private void assertActionMap () { ActionMap map = lookup.lookup(ActionMap.class); assertNotNull ("Map has to be there", map); javax.swing.Action action = map.get (KEY); assertEquals ("It is really our action", sampleAction, action); }
@Override public Lookup.Item lookupItem(Lookup.Template template) { Lookup.Item retValue; if (template.getType() == ActionMap.class || (template.getId() != null && template.getId().equals("javax.swing.ActionMap"))) { return initial.lookupItem(template); } // do something here?? retValue = super.lookupItem(template); return retValue; }
public void actionPerformed(ActionEvent e) { ActionMap m = TEdit.getActionMap(); m.get(DefaultEditorKit.pasteAction).actionPerformed(e); TEdit.getTextArea().requestFocus(); TEdit.setEnabled("Save",true); TEdit.setEnabled("SaveAs",true); //displayResult("Action for first button/menu item", e); }
public void actionPerformed(ActionEvent e) { //TEdit.saveOld(); //TEdit.updateTextArea("","Untitled"); ActionMap m = TEdit.getActionMap(); m.get(DefaultEditorKit.copyAction).actionPerformed(e); TEdit.setEnabled("Save",true); TEdit.setEnabled("SaveAs",true); //displayResult("Action for first button/menu item", e); }
public void testSurviveFocusChangeBehavior() throws Exception { class MyAction extends AbstractAction { public int cntEnabled; public int cntPerformed; @Override public boolean isEnabled() { cntEnabled++; return true; } @Override public void actionPerformed(ActionEvent ev) { cntPerformed++; } } MyAction myAction = new MyAction(); ActionMap disable = new ActionMap(); ActionMap enable = new ActionMap(); InstanceContent ic = new InstanceContent(); AbstractLookup al = new AbstractLookup(ic); ContextAwareAction temp = (ContextAwareAction) Actions.forID("Windows", "my.survival.action"); Action a = temp.createContextAwareInstance(al); enable.put(SURVIVE_KEY, myAction); ic.add(enable); assertTrue("MyAction is enabled", a.isEnabled()); ic.set(Collections.singletonList(disable), null); assertTrue("Remains enabled on other component", a.isEnabled()); ic.remove(disable); }
public void testWithFallback() throws Exception { MyAction myAction = new MyAction(); MyAction fallAction = new MyAction(); ActionMap other = new ActionMap(); ActionMap tc = new ActionMap(); tc.put("somekey", myAction); InstanceContent ic = new InstanceContent(); AbstractLookup al = new AbstractLookup(ic); ic.add(tc); ContextAwareAction a = callback("somekey", fallAction, al, false); CntListener l = new CntListener(); a.addPropertyChangeListener(l); assertTrue("My action is on", myAction.isEnabled()); assertTrue("Callback is on", a.isEnabled()); l.assertCnt("No change yet", 0); ic.remove(tc); assertTrue("fall is on", fallAction.isEnabled()); assertTrue("My is on as well", a.isEnabled()); l.assertCnt("Still enabled, so no change", 0); fallAction.setEnabled(false); l.assertCnt("Now there was one change", 1); assertFalse("fall is off", fallAction.isEnabled()); assertFalse("My is off as well", a.isEnabled()); Action a2 = a.createContextAwareInstance(Lookup.EMPTY); assertEquals("Both actions are equal", a, a2); assertEquals("and have the same hash", a.hashCode(), a2.hashCode()); }
public void testActionMapChangesForElementsWithComponentShowingInit() throws Exception { Action act1 = new TestAction("MultiViewAction1"); Action act2 = new TestAction("MultiViewAction2"); MVElemTopComponent elem1 = new ComponentShowingElement("testAction", act1); MVElemTopComponent elem2 = new ComponentShowingElement("testAction", act2); MVElem elem3 = new MVElem(); MultiViewDescription desc1 = new MVDesc("desc1", null, 0, elem1); MultiViewDescription desc2 = new MVDesc("desc2", null, 0, elem2); MultiViewDescription desc3 = new MVDesc("desc3", null, 0, elem3); MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 }; TopComponent tc = MultiViewFactory.createMultiView(descs, desc1); Lookup.Result result = tc.getLookup().lookup(new Lookup.Template(ActionMap.class)); LookListener2 list = new LookListener2(); result.addLookupListener(list); result.allInstances().size(); list.setCorrectValues("testAction", act1); // WARNING: as anything else the first element's action map is set only after the tc is opened.. tc.open(); assertEquals(1, list.getCount()); MultiViewHandler handler = MultiViews.findMultiViewHandler(tc); // test related hack, easy establishing a connection from Desc->perspective Accessor.DEFAULT.createPerspective(desc2); list.setCorrectValues("testAction", act2); handler.requestVisible(Accessor.DEFAULT.createPerspective(desc2)); assertEquals(2, list.getCount()); Accessor.DEFAULT.createPerspective(desc3); list.setCorrectValues("testAction", null); handler.requestVisible(Accessor.DEFAULT.createPerspective(desc3)); assertEquals(3, list.getCount()); }
/** Setup component with lookup. */ protected void setUp() { System.setProperty("org.openide.util.Lookup", "-"); map = new ActionMap(); ic = new InstanceContent(); ic.add(map); lookup = new AbstractLookup(ic); top = new TopComponent(lookup); }
final javax.swing.ActionMap setupActionMap(javax.swing.ActionMap map) { map.put(DefaultEditorKit.copyAction, copyActionPerformer); map.put(DefaultEditorKit.cutAction, cutActionPerformer); //map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(explorerManager)); map.put("delete", deleteActionPerformer); // NOI18N return map; }
private void consumeIfKeyPressInActionMap(KeyEvent e) { // get popup's registered keyboard actions ActionMap am = popup.getActionMap(); InputMap im = popup.getInputMap(); // check whether popup registers keystroke // If we consumed key pressed, we need to consume other key events as well: KeyStroke ks = KeyStroke.getKeyStrokeForEvent( new KeyEvent((Component) e.getSource(), KeyEvent.KEY_PRESSED, e.getWhen(), e.getModifiers(), KeyEvent.getExtendedKeyCodeForChar(e.getKeyChar()), e.getKeyChar(), e.getKeyLocation()) ); Object obj = im.get(ks); if (obj != null && !obj.equals("tooltip-no-action") //NOI18N ignore ToolTipSupport installed actions ) { // if yes, if there is a popup's action, consume key event Action action = am.get(obj); if (action != null && action.isEnabled()) { // actionPerformed on key press only. e.consume(); } } }
private static void filterBindings(ActionMap actionMap) { for(Object key : actionMap.allKeys()) { String actionName = key.toString().toLowerCase(Locale.ENGLISH); LOG.log(Level.FINER, "Action-name: {0}", actionName); //NOI18N if (actionName.contains("delete") || actionName.contains("insert") || //NOI18N actionName.contains("paste") || actionName.contains("default") || //NOI18N actionName.contains("cut") //NOI18N ) { actionMap.put(key, NO_ACTION); } } }
TableTabCaret(TableTab table) { this.table = table; cursorRow = 0; cursorCol = 0; markRow = 0; markCol = 0; table.getTruthTable().addTruthTableListener(listener); table.addMouseListener(listener); table.addMouseMotionListener(listener); table.addKeyListener(listener); table.addFocusListener(listener); InputMap imap = table.getInputMap(); ActionMap amap = table.getActionMap(); AbstractAction nullAction = new AbstractAction() { /** * */ private static final long serialVersionUID = 7932515593155479627L; @Override public void actionPerformed(ActionEvent e) { } }; String nullKey = "null"; amap.put(nullKey, nullAction); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), nullKey); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), nullKey); }
/** Creates */ private Tab() { this.manager = new ExplorerManager(); ActionMap map = this.getActionMap (); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete (manager, true)); // or false // following line tells the top component which lookup should be associated with it associateLookup (ExplorerUtils.createLookup (manager, map)); }
public Action findGlobalAction(Object key, boolean surviveFocusChange) { // search action in all action maps from global context Action a = null; for (Reference<ActionMap> ref : actionMaps) { ActionMap am = ref.get(); a = am == null ? null : am.get(key); if (a != null) { break; } } if (surviveFocusChange) { if (a == null) { a = survive.get(key); if (a != null) { a = ((WeakAction) a).getDelegate(); } if (err.isLoggable(Level.FINE)) { err.fine("No action for key: " + key + " using delegate: " + a); // NOI18N } } else { if (err.isLoggable(Level.FINE)) { err.fine("New action for key: " + key + " put: " + a); } survive.put(key, new WeakAction(a)); } } if (err.isLoggable(Level.FINE)) { err.fine("Action for key: " + key + " is: " + a); // NOI18N } return a; }
protected final ActionMap getContextActionMap() { if (globalActionMap == null) { globalActionMap = org.openide.util.Utilities.actionsGlobalContext().lookupResult(ActionMap.class); globalActionMap.addLookupListener(WeakListeners.create(LookupListener.class, this, globalActionMap)); } Collection<? extends ActionMap> am = globalActionMap.allInstances(); return am.size() > 0 ? am.iterator().next() : null; }
protected void setUp() throws Exception { tc = new TopComponent(); res = tc.getLookup().lookup(new Lookup.Template<ActionMap> (ActionMap.class)); assertEquals("One instance", 1, res.allItems().size()); res.addLookupListener(this); }
public ExplorerPanel() { manager = new ExplorerManager(); ActionMap map = getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, true)); }