javax.swing.ActionMap Java Examples

The following examples show how to use javax.swing.ActionMap. 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: AddModulePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #2
Source File: ClasspathNavigatorProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public JComponent getComponent() {
    if (panel == null) {
        final PropertySheetView view = new PropertySheetView();
        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;
}
 
Example #3
Source File: SearchUtils.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    KeyStroke ks = null;
    
    if (FIND_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    } else if (FIND_NEXT_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
    } else if (FIND_PREV_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK);
    } else if (FIND_SEL_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.CTRL_MASK);
    }
    
    if (ks != null) {
        actionMap.put(actionKey, action);
        inputMap.put(ks, actionKey);
    }

    return ks;
}
 
Example #4
Source File: CGraphSearchField.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Registers all hotkeys processed by the graph search field.
 */
private void registerHotkeys() {
  final ActionMap actionMap = ((JTextField) getEditor().getEditorComponent()).getActionMap();
  final InputMap imap = ((JTextField) getEditor().getEditorComponent()).getInputMap();
  setActionMap(actionMap);
  setInputMap(JComponent.WHEN_FOCUSED, imap);

  imap.put(HotKeys.GRAPH_SEARCH_NEXT_KEY.getKeyStroke(), "NEXT");
  imap.put(HotKeys.GRAPH_SEARCH_NEXT_ZOOM_KEY.getKeyStroke(), "NEXT_ZOOM");
  imap.put(HotKeys.GRAPH_SEARCH_PREVIOUS_KEY.getKeyStroke(), "PREVIOUS");
  imap.put(HotKeys.GRAPH_SEARCH_PREVIOUS_ZOOM_KEY.getKeyStroke(), "PREVIOUS_ZOOM");

  actionMap.put("NEXT", CActionProxy.proxy(new CActionHotKey("NEXT")));
  actionMap.put("NEXT_ZOOM", CActionProxy.proxy(new CActionHotKey("NEXT_ZOOM")));
  actionMap.put("PREVIOUS", CActionProxy.proxy(new CActionHotKey("PREVIOUS")));
  actionMap.put("PREVIOUS_ZOOM", CActionProxy.proxy(new CActionHotKey("PREVIOUS_ZOOM")));
}
 
Example #5
Source File: PasteAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Finds appropriate map to work with.
 * @return map from lookup or from activated TopComponent, null no available
 */
private ActionMap map() {
    if (result == null) {
        TopComponent tc = TopComponent.getRegistry().getActivated();

        if (tc != null) {
            return tc.getActionMap();
        }
    } else {
        for (ActionMap am : result.allInstances()) {
            return am;
        }
    }

    return null;
}
 
Example #6
Source File: ErrorNavigatorProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: QueryBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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()) ;
   }
 
Example #8
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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);
    
}
 
Example #9
Source File: Outline.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
            }
        }
    });
}
 
Example #10
Source File: CompareResultImages.java    From diirt with MIT License 6 votes vote down vote up
/**
 * Creates new form CompareResultImages
 */
public CompareResultImages() {
    initComponents();
    toReviewList.setModel(new DefaultListModel());
    fillList();
    setSize(800, 600);
    setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
    actualImage.setStretch(false);
    referenceImage.setStretch(false);
    acceptAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D"));

    InputMap keyMap = new ComponentInputMap(acceptButton);
    keyMap.put(KeyStroke.getKeyStroke("control D"), "accept");

    ActionMap actionMap = new ActionMapUIResource();
    actionMap.put("accept", acceptAction);

    SwingUtilities.replaceUIActionMap(acceptButton, actionMap);
    SwingUtilities.replaceUIInputMap(acceptButton, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap);
}
 
Example #11
Source File: PortMapperView.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
private JComponent getPresetPanel() {
    final ActionMap actionMap = this.getContext().getActionMap(this.getClass(), this);

    final JPanel presetPanel = new JPanel(new MigLayout("", "[grow, fill][]", ""));
    presetPanel.setBorder(BorderFactory
            .createTitledBorder(app.getResourceMap().getString("mainFrame.port_mapping_presets.title")));

    portMappingPresets = new JList<>(new PresetListModel(app.getSettings()));
    portMappingPresets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    portMappingPresets.setLayoutOrientation(JList.VERTICAL);

    portMappingPresets.addListSelectionListener(e -> {
        logger.trace("Selection of preset list has changed: {}", isPresetMappingSelected());
        firePropertyChange(PROPERTY_PRESET_MAPPING_SELECTED, false, isPresetMappingSelected());
    });

    presetPanel.add(new JScrollPane(portMappingPresets), "spany 4, grow");

    presetPanel.add(new JButton(actionMap.get(ACTION_CREATE_PRESET_MAPPING)), "wrap, sizegroup preset_buttons");
    presetPanel.add(new JButton(actionMap.get(ACTION_EDIT_PRESET_MAPPING)), "wrap, sizegroup preset_buttons");
    presetPanel.add(new JButton(actionMap.get(ACTION_REMOVE_PRESET_MAPPING)), "wrap, sizegroup preset_buttons");
    presetPanel.add(new JButton(actionMap.get(ACTION_USE_PRESET_MAPPING)), "wrap, sizegroup preset_buttons");

    return presetPanel;
}
 
Example #12
Source File: MultiViewActionMapTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSimplifiedActionMapChanges81117() {
    MultiViewTopComponentLookup.InitialProxyLookup lookup = new MultiViewTopComponentLookup.InitialProxyLookup(new ActionMap());
    Lookup.Result res = lookup.lookup(new Lookup.Template(ActionMap.class));
    LookListener list = new LookListener();
    list.resetCount();
    res.addLookupListener(list);
    assertEquals(1, res.allInstances().size());
    assertEquals(0, list.getCount());
    lookup.refreshLookup();
    assertEquals(1, list.getCount());
    assertEquals(1, res.allInstances().size());
    
    MultiViewTopComponentLookup lookup2 = new MultiViewTopComponentLookup(new ActionMap());
    res = lookup2.lookup(new Lookup.Template(ActionMap.class));
    list = new LookListener();
    list.resetCount();
    res.addLookupListener(list);
    assertEquals(1, res.allInstances().size());
    assertEquals(0, list.getCount());
    lookup2.setElementLookup(Lookups.fixed(new Object[] {new Object()} ));
    assertEquals(1, list.getCount());
    assertEquals(1, res.allInstances().size());
    
}
 
Example #13
Source File: SearchUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    KeyStroke ks = null;
    
    if (FIND_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK);
    } else if (FIND_NEXT_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
    } else if (FIND_PREV_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK);
    } else if (FIND_SEL_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.CTRL_MASK);
    }
    
    if (ks != null) {
        actionMap.put(actionKey, action);
        inputMap.put(ks, actionKey);
    }

    return ks;
}
 
Example #14
Source File: CallbackSystemAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/*** Finds an action that we should delegate to
 * @return the action or null
 */
private Action findAction() {
    Collection<? extends ActionMap> c = result != null ? result.allInstances() : Collections.<ActionMap>emptySet();

    if (!c.isEmpty()) {
        Object key = delegate.getActionMapKey();
        for (ActionMap map : c) {
            Action action = map.get(key);
            if (action != null) {
                return action;
            }
        }
    }

    return null;
}
 
Example #15
Source File: GlobalSearchPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds an Action to the actionMap of the necessary steps to be executed for closing the global search results dialog
 *
 * @param actionMap
 * 		the ActionMap that should know how to close the global search results dialog
 */
private void addCloseFullSearchDialogAction(ActionMap actionMap) {
	actionMap.put(CLOSE_FULL_SEARCH_DIALOG, new ResourceAction("") {
		@Override
		public void actionPerformed(ActionEvent e) {
			searchField.requestFocusInWindow();
			SwingUtilities.invokeLater(() -> {
				GlobalSearchPanel.this.hideComponents();
				logGlobalSearchFocusLost();
			});
		}
	});
}
 
Example #16
Source File: Tab.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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));
}
 
Example #17
Source File: MultiViewActionMapTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testActionMapChanges() throws Exception {
    MVElemTopComponent elem1 = new MVElemTopComponent();
    MVElemTopComponent elem2 = new MVElemTopComponent();
    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);
    // WARNING: as anything else the first element's action map is set only after the tc is opened..
    Lookup.Result result = tc.getLookup().lookup(new Lookup.Template(ActionMap.class));
    LookListener list = new LookListener();
    list.resetCount();
    result.addLookupListener(list);
    result.allItems();
    
    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);
    handler.requestVisible(Accessor.DEFAULT.createPerspective(desc2));
    assertEquals(2, list.getCount());
    
    Accessor.DEFAULT.createPerspective(desc3);
    handler.requestVisible(Accessor.DEFAULT.createPerspective(desc3));
    assertEquals(3, list.getCount());
}
 
Example #18
Source File: CallbackSystemAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DelegateAction(CallbackSystemAction a, Lookup actionContext) {
    this.delegate = a;
    this.weakL = org.openide.util.WeakListeners.propertyChange(this, null);
    this.enabled = a.getActionPerformer() != null;

    this.result = actionContext.lookup(new Lookup.Template<ActionMap>(ActionMap.class));
    this.result.addLookupListener(WeakListeners.create(LookupListener.class, this, this.result));
    resultChanged(null);
}
 
Example #19
Source File: GeneralAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void updateState(ActionMap prev, ActionMap now, boolean fire) {
    if (key == null) {
        return;
    }

    boolean prevEnabled = false;
    if (prev != null) {
        Action prevAction = prev.get(key);
        if (prevAction != null) {
            prevEnabled = fire && prevAction.isEnabled();
            prevAction.removePropertyChangeListener(weakL);
        }
    }
    if (now != null) {
        Action nowAction = now.get(key);
        boolean nowEnabled;
        if (nowAction != null) {
            nowAction.addPropertyChangeListener(weakL);
            nowEnabled = nowAction.isEnabled();
        } else {
            nowEnabled = fallback != null && fallback.isEnabled();
        }
        PropertyChangeSupport sup = fire ? support : null;
        if (sup != null && nowEnabled != prevEnabled) {
            sup.firePropertyChange("enabled", prevEnabled, !prevEnabled); // NOI18N
        }
    }
}
 
Example #20
Source File: FindActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    if (!SearchUtils.FIND_ACTION_KEY.equals(actionKey)) return null;
    
    Action find = Actions.forID(FIND_ACTION_CATEGORY, FIND_ACTION_KEY);
    if (find == null) return null;
    
    actionMap.put(FIND_ACTION_KEY, action);
    
    Object acc = find.getValue(Action.ACCELERATOR_KEY);
    return acc instanceof KeyStroke ? (KeyStroke)acc : ActionsSupport.NO_KEYSTROKE;
}
 
Example #21
Source File: TMSettingsControl.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void initTMTable(JTable table) {
    InputMap imTD = table.getInputMap(WHEN_FOCUSED);
    ActionMap amTD = table.getActionMap();
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mItemEnc = new JMenuItem("Encrypt");
    popup.add(mItemEnc);
    Action enc = getEncryptAction(table);
    mItemEnc.setAccelerator(Keystroke.ENCRYPT);
    mItemEnc.addActionListener(enc);
    imTD.put(Keystroke.ENCRYPT, "encrypt");
    amTD.put("encrypt", enc);
    table.setComponentPopupMenu(popup);
    JtableUtils.addlisteners(table, Boolean.FALSE);
}
 
Example #22
Source File: SettingsDialog.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
private JPanel getDialogPane() {
    final ActionMap actionMap = app.getContext().getActionMap(this.getClass(), this);
    final Settings settings = app.getSettings();

    final JPanel dialogPane = new JPanel(new MigLayout("", // Layout
            // Constraints
            "[right]rel[left,grow 100]", // Column Constraints
            "")); // Row Constraints

    logger.debug("Use entity encoding is {}", settings.isUseEntityEncoding());
    useEntityEncoding = new JCheckBox("settings_dialog.use_entity_encoding", settings.isUseEntityEncoding());
    useEntityEncoding.setName("settings_dialog.use_entity_encoding");

    dialogPane.add(useEntityEncoding, "span 2, wrap");

    dialogPane.add(createLabel("settings_dialog.log_level"));

    logLevelComboBox = new JComboBox<>(new Vector<>(AVAILABLE_LOG_LEVELS));
    logLevelComboBox.setSelectedItem(Level.toLevel(settings.getLogLevel()));

    dialogPane.add(logLevelComboBox, "wrap");

    dialogPane.add(createLabel("settings_dialog.upnp_lib"));

    routerFactoryClassComboBox = new JComboBox<>(new Vector<>(AVAILABLE_ROUTER_FACTORIES));
    routerFactoryClassComboBox.setSelectedItem(settings.getRouterFactoryClassName());
    dialogPane.add(routerFactoryClassComboBox, "span 2, wrap");

    dialogPane.add(new JButton(actionMap.get(ACTION_CANCEL)), "tag cancel, span 2");
    okButton = new JButton(actionMap.get(ACTION_SAVE));
    dialogPane.add(okButton, "tag ok, wrap");

    return dialogPane;
}
 
Example #23
Source File: FilterUtils.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    if (!FILTER_ACTION_KEY.equals(actionKey)) return null;
    
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    actionMap.put(actionKey, action);
    inputMap.put(ks, actionKey);

    return ks;
}
 
Example #24
Source File: TopComponentLookupToNodesBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example #25
Source File: PreferencePanel.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Creates a modal dialog displaying this PreferencePanel. */
public JFrame createFrame(String name) {
	JFrame f = new JFrame(name);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	if (isMac) {
		f.getRootPane().putClientProperty("apple.awt.brushMetalLook",
				Boolean.TRUE);
		separator.setForeground(new Color(64, 64, 64));
	}
	f.getContentPane().setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.weighty = 1;
	c.fill = GridBagConstraints.BOTH;
	f.getContentPane().add(this, c);
	f.setResizable(false);
	InputMap inputMap = f.getRootPane().getInputMap(
			JComponent.WHEN_IN_FOCUSED_WINDOW);
	ActionMap actionMap = f.getRootPane().getActionMap();

	inputMap.put(escapeKey, escapeKey);
	inputMap.put(commandPeriodKey, escapeKey);
	actionMap.put(escapeKey, closeDialogAndDisposeAction);

	return f;
}
 
Example #26
Source File: CompletionActionsMainMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Sets the state of JMenuItem*/
protected @Override void setMenu(){
    
    ActionMap am = getContextActionMap();
    Action action = null;
    if (am != null) {
        action = am.get(getActionName());
    }
    
    JMenuItem presenter = getMenuPresenter();
    Action presenterAction = presenter.getAction();
    if (presenterAction == null){
        presenter.setAction(this);
        presenter.setToolTipText(null); /* bugfix #62872 */ 
        menuInitialized = false;
    } 
    else {
        if (!this.equals(presenterAction)){
            presenter.setAction(this);
            presenter.setToolTipText(null); /* bugfix #62872 */
            menuInitialized = false;
        }
    }

    if (!menuInitialized){
        Mnemonics.setLocalizedText(presenter, getMenuItemText());
        menuInitialized = true;
    }

    presenter.setEnabled(action != null);
    JTextComponent comp = Utilities.getFocusedComponent();
    if (comp != null && comp instanceof JEditorPane){
        addAccelerators(this, presenter, comp);
    } else {
        presenter.setAccelerator(getDefaultAccelerator());
    }

}
 
Example #27
Source File: NodeOperationImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ExplorerPanel(Node n) {
    manager = new ExplorerManager();
    manager.setRootContext(n);
    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));
    associateLookup(ExplorerUtils.createLookup (manager, map));
    setLayout(new BorderLayout());
    add(new BeanTreeView());
    setName(n.getDisplayName());
}
 
Example #28
Source File: TableUtils.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
private void addKey(JTable table, String name, int key, int mask, Action action) {
    InputMap inputMap = table.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = table.getActionMap();
    KeyStroke keyStroke = KeyStroke.getKeyStroke(key, mask);
    inputMap.put(keyStroke, name);
    actionMap.put(name, action);
}
 
Example #29
Source File: BasicLookAndFeel.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the parent of the passed in ActionMap to be the audio action
 * map.
 */
static void installAudioActionMap(ActionMap map) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        map.setParent(((BasicLookAndFeel)laf).getAudioActionMap());
    }
}
 
Example #30
Source File: BasicLookAndFeel.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}