Java Code Examples for javax.swing.Action#actionPerformed()
The following examples show how to use
javax.swing.Action#actionPerformed() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IsOverriddenAnnotationAction.java From netbeans with Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent e) { if (!invokeDefaultAction((JTextComponent) e.getSource())) { Action actions[] = ImplementationProvider.getDefault().getGlyphGutterActions((JTextComponent) e.getSource()); if (actions == null) return ; int nextAction = 0; while (nextAction < actions.length && actions[nextAction] != this) nextAction++; nextAction++; if (actions.length > nextAction) { Action a = actions[nextAction]; if (a!=null && a.isEnabled()){ a.actionPerformed(e); } } } }
Example 2
Source File: BasicLookAndFeel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * If necessary, invokes {@code actionPerformed} on * {@code audioAction} to play a sound. * The {@code actionPerformed} method is invoked if the value of * the {@code "AuditoryCues.playList"} default is a {@code * non-null} {@code Object[]} containing a {@code String} entry * equal to the name of the {@code audioAction}. * * @param audioAction an Action that knows how to render the audio * associated with the system or user activity * that is occurring; a value of {@code null}, is * ignored * @throws ClassCastException if {@code audioAction} is {@code non-null} * and the value of the default {@code "AuditoryCues.playList"} * is not an {@code Object[]} * @since 1.4 */ protected void playSound(Action audioAction) { if (audioAction != null) { Object[] audioStrings = (Object[]) UIManager.get("AuditoryCues.playList"); if (audioStrings != null) { // create a HashSet to help us decide to play or not HashSet<Object> audioCues = new HashSet<Object>(); for (Object audioString : audioStrings) { audioCues.add(audioString); } // get the name of the Action String actionName = (String)audioAction.getValue(Action.NAME); // if the actionName is in the audioCues HashSet, play it. if (audioCues.contains(actionName)) { audioAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionName)); } } } }
Example 3
Source File: ExplorerActionsCompatTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testActionDeleteDoesNotAffectStateOfPreviousInstances () throws Exception { ExplorerManager em = new ExplorerManager (); Action a1 = ExplorerUtils.actionDelete(em, false); Action a2 = ExplorerUtils.actionDelete(em, true); Node node = new AbstractNode (Children.LEAF) { public boolean canDestroy () { return true; } }; em.setRootContext(node); em.setSelectedNodes(new Node[] { node }); assertTrue ("A1 enabled", a1.isEnabled()); assertTrue ("A2 enabled", a2.isEnabled()); // this should not show a dialog a1.actionPerformed (new java.awt.event.ActionEvent (this, 0, "")); }
Example 4
Source File: EditorOnlyDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean setShowEditorToolbar( boolean show ) { boolean res = true; Action toggleEditorToolbar = FileUtil.getConfigObject( "Editors/Actions/toggle-toolbar.instance", Action.class ); //NOI18N if( null != toggleEditorToolbar ) { if( toggleEditorToolbar instanceof Presenter.Menu ) { JMenuItem menuItem = ((Presenter.Menu)toggleEditorToolbar).getMenuPresenter(); if( menuItem instanceof JCheckBoxMenuItem ) { JCheckBoxMenuItem checkBoxMenu = ( JCheckBoxMenuItem ) menuItem; res = checkBoxMenu.isSelected(); if( checkBoxMenu.isSelected() != show ) { try { toggleEditorToolbar.actionPerformed( new ActionEvent( menuItem, 0, "")); //NOII18N } catch( Exception ex ) { //don't worry too much if it isn't working, we're just trying to be helpful here Logger.getLogger( EditorOnlyDisplayer.class.getName()).log( Level.FINE, null, ex ); } } } } } return res; }
Example 5
Source File: EditorUI.java From netbeans with Apache License 2.0 | 6 votes |
public void showPopupMenu(int x, int y) { // First call the build-popup-menu action to possibly rebuild the popup menu JTextComponent c = getComponent(); if (c != null) { BaseKit kit = Utilities.getKit(c); if (kit != null) { Action a = kit.getActionByName(ExtKit.buildPopupMenuAction); if (a != null) { a.actionPerformed(new ActionEvent(c, 0, "")); // NOI18N } } JPopupMenu pm = getPopupMenu(); if (pm != null) { if (c.isShowing()) { // fix of #18808 if (!c.isFocusOwner()) { c.requestFocus(); } pm.show(c, x, y); } } } }
Example 6
Source File: System2D.java From energy2d with GNU Lesser General Public License v3.0 | 6 votes |
boolean askSaveBeforeLoading() { if (owner == null) // not an application return true; switch (askSaveOption()) { case JOptionPane.YES_OPTION: Action a; if (currentFile != null) { a = view.getActionMap().get("Save"); } else { a = view.getActionMap().get("SaveAs"); } if (a != null) a.actionPerformed(null); return true; case JOptionPane.NO_OPTION: return true; default: return false; } }
Example 7
Source File: DefaultKeyHandler.java From nextreports-designer with Apache License 2.0 | 6 votes |
/** * If a KeyEvent matches the key in the actionMap object, * the associated action will be fired. * * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) */ public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); Set keys = actionMap.keySet(); if (keys.contains(keyCode)) { final Action a = actionMap.get(keyCode); try { a.actionPerformed( new ActionEvent( this, 1, (String) a.getValue(Action.ACTION_COMMAND_KEY))); } catch (Exception ex) { ex.printStackTrace(System.err); } } }
Example 8
Source File: BasicLookAndFeel.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * If necessary, invokes {@code actionPerformed} on * {@code audioAction} to play a sound. * The {@code actionPerformed} method is invoked if the value of * the {@code "AuditoryCues.playList"} default is a {@code * non-null} {@code Object[]} containing a {@code String} entry * equal to the name of the {@code audioAction}. * * @param audioAction an Action that knows how to render the audio * associated with the system or user activity * that is occurring; a value of {@code null}, is * ignored * @throws ClassCastException if {@code audioAction} is {@code non-null} * and the value of the default {@code "AuditoryCues.playList"} * is not an {@code Object[]} * @since 1.4 */ protected void playSound(Action audioAction) { if (audioAction != null) { Object[] audioStrings = (Object[]) UIManager.get("AuditoryCues.playList"); if (audioStrings != null) { // create a HashSet to help us decide to play or not HashSet<Object> audioCues = new HashSet<Object>(); for (Object audioString : audioStrings) { audioCues.add(audioString); } // get the name of the Action String actionName = (String)audioAction.getValue(Action.NAME); // if the actionName is in the audioCues HashSet, play it. if (audioCues.contains(actionName)) { audioAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionName)); } } } }
Example 9
Source File: SearchNbEditorKit.java From netbeans with Apache License 2.0 | 5 votes |
public static void openFindIfNecessary(JTextComponent component, ActionEvent evt) { Object findWhat = EditorFindSupport.getInstance().getFindProperty(EditorFindSupport.FIND_WHAT); if (findWhat == null || !(findWhat instanceof String) || ((String) findWhat).isEmpty()) { Action findAction = ((BaseKit) component.getUI().getEditorKit( component)).getActionByName("find"); if (findAction != null) { findAction.actionPerformed(evt); } } }
Example 10
Source File: ExplorerActionsImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIllegalStateException() throws Exception { N root = new N(); final N ch1 = new N(); final N ch2 = new N(); final N ch3 = new N(); PT mockPaste = new PT(); ch3.pasteTypes = Collections.<PasteType>singletonList(mockPaste); root.getChildren().add(new Node[] { ch1, ch2, ch3 }); final ExplorerManager em = new ExplorerManager(); em.setRootContext(root); em.setSelectedNodes(new Node[] { root }); Action action = ExplorerUtils.actionPaste(em); Action cut = ExplorerUtils.actionCut(em); em.waitActionsFinished(); assertFalse("Not enabled", action.isEnabled()); action.addPropertyChangeListener(this); cut.addPropertyChangeListener(this); em.setSelectedNodes(new Node[] { ch3 }); em.waitActionsFinished(); assertFalse("Cut is not enabled", cut.isEnabled()); assertTrue("Now enabled", action.isEnabled()); action.actionPerformed(new ActionEvent(this, 0, "")); assertEquals("The paste type is going to be called", 1, mockPaste.cnt); if (err != null) { throw err; } if (cnt == 0) { fail("There should be some change in actions: " + cnt); } }
Example 11
Source File: AlwaysEnabledActionTest.java From netbeans with Apache License 2.0 | 5 votes |
private void checkPreferencesAction(Action a, Preferences prefsNode) throws Exception { prefsNode.putBoolean("myKey", true); prefsNode.sync(); class L implements PreferenceChangeListener { boolean notified; public synchronized void preferenceChange(PreferenceChangeEvent evt) { notified = true; notifyAll(); } public synchronized void waitFor() throws Exception { while (!notified) { wait(); } notified = false; } } L listener = new L(); // Verify value assertTrue("Expected true as preference value", prefsNode.getBoolean("myKey", false)); TestCase.assertTrue("Expected to be instance of Presenter.Menu", a instanceof Presenter.Menu); JMenuItem item = ((Presenter.Menu) a).getMenuPresenter(); TestCase.assertTrue("Expected to be selected", item.isSelected()); prefsNode.addPreferenceChangeListener(listener); prefsNode.putBoolean("myKey", false); prefsNode.sync(); listener.waitFor(); TestCase.assertFalse("Expected to not be selected", item.isSelected()); a.actionPerformed(null); // new ActionEvent(null, 0, "")); listener.waitFor(); TestCase.assertTrue("Expected to be selected", item.isSelected()); prefsNode.putBoolean("myKey", false); prefsNode.sync(); listener.waitFor(); }
Example 12
Source File: ShowMembersAction.java From netbeans with Apache License 2.0 | 5 votes |
static void missingNavigatorAPIHack( @NonNull final ActionEvent ev, @NonNull final JavaSource context, @NullAllowed final JTextComponent target) { final Action openNavigator = FileUtil.getConfigObject( "Actions/Window/org-netbeans-modules-navigator-ShowNavigatorAction.instance", Action.class); if (openNavigator != null) { openNavigator.actionPerformed(ev); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { NavigatorHandler.activateNavigator(); final Collection<? extends NavigatorPanel> panels = getPanels(context); NavigatorPanel cmp = null; for (NavigatorPanel panel : panels) { if (panel.getComponent().getClass() == ClassMemberPanelUI.class) { cmp = panel; break; } } if (cmp != null) { NavigatorHandler.activatePanel(cmp); ((ClassMemberPanelUI)cmp.getComponent()).setContext(context, target); } } }); } }
Example 13
Source File: ActionsSearchProvider.java From netbeans with Apache License 2.0 | 5 votes |
public void run() { // be careful, some actions throws assertions etc, because they // are not written to be invoked directly try { Action a = command; ActionEvent ae = createActionEvent(command); Object p = ae.getSource(); if (p instanceof CloneableEditor) { JEditorPane pane = ((CloneableEditor) p).getEditorPane(); Action activeCommand = pane.getActionMap().get(command.getValue(Action.NAME)); if (activeCommand != null) { a = activeCommand; } } a.actionPerformed(ae); uiLog(true); } catch (Throwable thr) { uiLog(false); if (thr instanceof ThreadDeath) { throw (ThreadDeath)thr; } Object name = command.getValue(Action.NAME); String displayName = ""; if (name instanceof String) { displayName = (String)name; } Logger.getLogger(getClass().getName()).log(Level.FINE, displayName + " action can not be invoked.", thr); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage( getClass(), "MSG_ActionFailure", displayName)); } }
Example 14
Source File: AbstractExportDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Invoked when a window is in the process of being closed. The close operation can be overridden at this point. */ public void windowClosing( final WindowEvent e ) { final Action cancelAction = getCancelAction(); if ( cancelAction != null ) { cancelAction.actionPerformed( null ); } else { setConfirmed( false ); setVisible( false ); } }
Example 15
Source File: ExtendedJSliderToolTips.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public static void hideToolTip(JComponent comp) { Action action = comp.getActionMap().get("hideTip"); if (action == null) { return; } ActionEvent ae = new ActionEvent(comp, ActionEvent.ACTION_PERFORMED, "hideTip", EventQueue.getMostRecentEventTime(), 0); action.actionPerformed(ae); }
Example 16
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that an action model is freed, after the actionPerformed is called, * and then the focus shifts so the model is not in Lookup. */ public void testActionModelFreed() { Action a = Actions.forID("Foo", "test.InstAction"); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); a.actionPerformed(new ActionEvent(this, 0, "cmd")); reinitActionLookup(); Reference<ActionModel3> r = new WeakReference<>(mod); mod = null; assertGC("Action model must be GCed", r); }
Example 17
Source File: ETable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if (isEditing() || editorComp != null) { removeEditor(); return; } else { Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Object key = imp.get(escape); if (key == null) { //Default for NbDialog key = "Cancel"; } if (key != null) { Action a = am.get(key); if (a != null) { String commandKey = (String)a.getValue(Action.ACTION_COMMAND_KEY); if (commandKey == null) { commandKey = key.toString(); } a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N } } } }
Example 18
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Check that action with action check enables only after the actual instance enables. */ public void testCustomEnableActionInstantiation() { assertEquals("Not pre-created", 0, created); Action a = Actions.forID("Foo", "test.CustomEnableAction"); assertNotNull(a); assertEquals("Not direcly created from layer", 0, created); a.isEnabled(); assertEquals("Not created unless data present", 0, created); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); // still not enabled assertFalse(a.isEnabled()); assertEquals("Not created unless guard is set", 0, created); mod.boolProp = true; mod.supp.firePropertyChange("boolProp", null, null); // should instantiate the action just because of the property change on guard, // now the action decides the final state. assertEquals("Must be created to evaluate enabled state", 1, created); Action inst = instance; assertNotNull(inst); inst.setEnabled(true); assertSame("Same instance for repeated enable", inst, instance); a.actionPerformed(new ActionEvent(this, 0, "cmd")); assertSame("Same instance for invocation and enable eval", inst, instance); assertNotNull(received); assertEquals("cmd", received.getActionCommand()); }
Example 19
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that an action model is freed, after the actionPerformed is called, * and then the focus shifts so the model is not in Lookup. */ public void testCustomActionModelFreed() { Action a = Actions.forID("Foo", "test.CustomEnableAction"); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); a.actionPerformed(new ActionEvent(this, 0, "cmd")); reinitActionLookup(); Reference<ActionModel3> r = new WeakReference<>(mod); instance = null; mod = null; assertGC("Action model must be GCed", r); }
Example 20
Source File: ExplorerComponent.java From visualvm with GNU General Public License v2.0 | 4 votes |
private void performDefaultAction() { Set<DataSource> selectedDataSources = ExplorerSupport.sharedInstance().getSelectedDataSources(); Action defaultAction = getDefaultAction(selectedDataSources); if (defaultAction != null) defaultAction.actionPerformed(new ActionEvent(selectedDataSources, 0, "Default Action")); // NOI18N }