Java Code Examples for javax.swing.ActionMap

The following examples show how to use javax.swing.ActionMap. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   Source File: AddModulePanel.java    License: 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 Project: netbeans   Source File: Outline.java    License: 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 3
Source Project: visualvm   Source File: SearchUtils.java    License: 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 Project: netbeans   Source File: QueryBuilder.java    License: 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 5
Source Project: portmapper   Source File: PortMapperView.java    License: 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 6
Source Project: netbeans   Source File: SearchUtils.java    License: 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 7
Source Project: diirt   Source File: CompareResultImages.java    License: 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 8
Source Project: netbeans   Source File: TemplatesPanel.java    License: 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 Project: netbeans   Source File: ErrorNavigatorProviderImpl.java    License: 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 10
Source Project: netbeans   Source File: PasteAction.java    License: 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 11
Source Project: netbeans   Source File: ClasspathNavigatorProviderImpl.java    License: 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 12
Source Project: binnavi   Source File: CGraphSearchField.java    License: 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 13
Source Project: netbeans   Source File: MultiViewActionMapTest.java    License: 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 14
Source Project: netbeans   Source File: CallbackSystemAction.java    License: 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 Project: netbeans   Source File: NodeOperationImpl.java    License: 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 16
Source Project: portmapper   Source File: PortMapperView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JComponent getMappingsPanel() {
    // Mappings panel

    final ActionMap actionMap = this.getContext().getActionMap(this.getClass(), this);

    tableModel = new PortMappingsTableModel(app);
    mappingsTable = new JTable(tableModel);
    mappingsTable.setAutoCreateRowSorter(true);
    mappingsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    mappingsTable.setSize(new Dimension(400, 100));
    mappingsTable.getSelectionModel().addListSelectionListener(
            e -> firePropertyChange(PROPERTY_MAPPING_SELECTED, false, isMappingSelected()));

    final JScrollPane mappingsTabelPane = new JScrollPane();
    mappingsTabelPane.setViewportView(mappingsTable);

    final JPanel mappingsPanel = new JPanel(new MigLayout("", "[fill,grow]", "[grow,fill][]"));
    mappingsPanel.setName("port_mappings");
    final Border panelBorder = BorderFactory
            .createTitledBorder(app.getResourceMap().getString("mainFrame.port_mappings.title"));
    mappingsPanel.setBorder(panelBorder);
    mappingsPanel.add(mappingsTabelPane, "height 100::, span 2, wrap");

    mappingsPanel.add(new JButton(actionMap.get(ACTION_REMOVE_MAPPINGS)), "");
    mappingsPanel.add(new JButton(actionMap.get(ACTION_UPDATE_PORT_MAPPINGS)), "wrap");
    return mappingsPanel;
}
 
Example 17
Source Project: jclic   Source File: Actions.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * This function is for debug purposes only. Prints out the
 *
 * @param actionKeys
 * @param am
 */
public static void dumpActionKeys(Map<String, Object[]> actionKeys, ActionMap am) {
  for (String key : actionKeys.keySet()) {
    System.out.println(key + ":");
    for (Object val : (Object[]) actionKeys.get(key))
      System.out.println(" - " + val + " >> " + am.get(val));
  }
}
 
Example 18
Source Project: netbeans   Source File: GlobalActionContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
static void blickActionMapImpl(ActionMap map, Component[] focus) {
    assert EventQueue.isDispatchThread();
    Object obj = Lookup.getDefault ().lookup (ContextGlobalProvider.class);
    if (obj instanceof GlobalActionContextImpl) {
        GlobalActionContextImpl g = (GlobalActionContextImpl)obj;
        
        Lookup[] arr = {
            map == null ? Lookup.EMPTY : Lookups.singleton (map),
            Lookups.exclude (g.getLookup (), new Class[] { javax.swing.ActionMap.class }),
        };
        
        Lookup originalLkp = g.getLookup();
        Lookup prev = temporary;
        try {
            temporary = new ProxyLookup (arr);
            Lookup actionsGlobalContext = Utilities.actionsGlobalContext();
            Object q = actionsGlobalContext.lookup (javax.swing.ActionMap.class);
            assert q == map : dumpActionMapInfo(map, q, prev, temporary, actionsGlobalContext, originalLkp);
            if (focus != null) {
                setFocusOwner(focus[0]);
            }
        } finally {
            temporary = prev;
            // fire the changes about return of the values back
            org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap.class);
        }
    }
}
 
Example 19
Source Project: netbeans   Source File: ExplorerPanel.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 20
Source Project: PacketProxy   Source File: GUIMain.java    License: Apache License 2.0 5 votes vote down vote up
private void addShortcutForWindows() {
	if (PacketProxyUtility.getInstance().isMac()) {
		return;
	}
	JPanel p = (JPanel) getContentPane();
	InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	ActionMap am = p.getActionMap();
	int hotkey = (KeyEvent.CTRL_MASK);
	registerTabShortcut(KeyEvent.VK_H, hotkey, im, am, Panes.HISTORY.ordinal());
	registerTabShortcut(KeyEvent.VK_I, hotkey, im, am, Panes.INTERCEPT.ordinal());
	registerTabShortcut(KeyEvent.VK_R, hotkey, im, am, Panes.REPEATER.ordinal());
	registerTabShortcut(KeyEvent.VK_B, hotkey, im, am, Panes.BULKSENDER.ordinal());
	registerTabShortcut(KeyEvent.VK_O, hotkey, im, am, Panes.OPTIONS.ordinal());
	registerTabShortcut(KeyEvent.VK_L, hotkey, im, am, Panes.LOG.ordinal());
}
 
Example 21
Source Project: netbeans   Source File: ActionsSupport.java    License: Apache License 2.0 5 votes vote down vote up
public static KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    for (ActionsSupportProvider provider : Lookup.getDefault().lookupAll(ActionsSupportProvider.class)) {
        KeyStroke ks = provider.registerAction(actionKey, action, actionMap, inputMap);
        if (ks != null) return ks;
    }
    return null;
}
 
Example 22
ActionListener treeActionAdapter(ActionMap map, String actionName) {
    final Action selectPrevious = map.get(actionName);
    return e -> {
        e.setSource(tree);
        selectPrevious.actionPerformed(e);
    };
}
 
Example 23
public GlobalSearchAction() {
	super(true, GLOBAL_SEARCH);
	InputMap inputMap = ApplicationFrame.getApplicationFrame().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	ActionMap actionMap = ApplicationFrame.getApplicationFrame().getRootPane().getActionMap();

	inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), GLOBAL_SEARCH);
	actionMap.put(GLOBAL_SEARCH, this);
}
 
Example 24
Source Project: netbeans   Source File: CommitPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void initActions () {
    InputMap inputMap = getInputMap( WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
    ActionMap actionMap = getActionMap();
    Object action = recentLabel.getClientProperty("openAction");
    if (action instanceof Action) {
        inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_R, KeyEvent.ALT_DOWN_MASK, false ), "messageHistory" ); //NOI18N
        actionMap.put("messageHistory", (Action) action); //NOI18N
    }
    action = templatesLabel.getClientProperty("openAction");
    if (action instanceof Action) {
        inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_L, KeyEvent.ALT_DOWN_MASK, false ), "messageTemplate" ); //NOI18N
        actionMap.put("messageTemplate", (Action) action); //NOI18N
    }
}
 
Example 25
Source Project: jdk8u60   Source File: BasicLookAndFeel.java    License: 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 26
Source Project: BART   Source File: StatExecutionsTopComponent.java    License: MIT License 5 votes vote down vote up
public StatExecutionsTopComponent() {
    initComponents();
    setDisplayName(Bundle.CTL_StatExecutionsTopComponent());
    setName(ViewResource.TOP_NAME_StatExecutionsTopComponent);
    setToolTipText(Bundle.HINT_StatExecutionsTopComponent());
    setBackground(Color.WHITE);
    setLayout(new BorderLayout());
    add(new BeanTreeView(),BorderLayout.CENTER);
    ActionMap  map = this.getActionMap();
    map.put("delete", ExplorerUtils.actionDelete(exm, true));
    associateLookup(ExplorerUtils.createLookup(exm, this.getActionMap()));
}
 
Example 27
Source Project: jdk8u-jdk   Source File: BasicLookAndFeel.java    License: 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);
            }
        }
    }
}
 
Example 28
Source Project: JDKSourceCode1.8   Source File: BasicLookAndFeel.java    License: MIT License 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 29
Source Project: binnavi   Source File: CGraphHotkeys.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register the default hotkeys of a graph view.
 * 
 * @param parent Parent window used for dialogs.
 * @param panel The panel where the view is shown.
 * @param debuggerProvider Provides the debugger used by some hotkeys.
 * @param searchField The search field that is shown in the graph panel.
 * @param addressField The address field that is shown in the graph panel.
 */
public static void registerHotKeys(final JFrame parent, final CGraphPanel panel,
    final IFrontEndDebuggerProvider debuggerProvider, final CGraphSearchField searchField,
    final CGotoAddressField addressField) {
  Preconditions.checkNotNull(parent, "IE01606: Parent argument can not be null");
  Preconditions.checkNotNull(panel, "IE01607: Panel argument can not be null");
  Preconditions.checkNotNull(searchField, "IE01608: Search field argument can not be null");
  Preconditions.checkNotNull(addressField, "IE01609: Address field argument can not be null");

  final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  final ActionMap actionMap = panel.getActionMap();

  inputMap.put(HotKeys.GRAPH_GOTO_ADDRESS_FIELD_KEY.getKeyStroke(), "GOTO_ADDRESS_FIELD");

  actionMap.put("GOTO_ADDRESS_FIELD", new AbstractAction() {
    /**
     * Used for serialization.
     */
    private static final long serialVersionUID = -8994014581850287793L;

    @Override
    public void actionPerformed(final ActionEvent event) {
      addressField.requestFocusInWindow();
    }
  });

  inputMap.put(HotKeys.GRAPH_SHOW_HOTKEYS_ACCELERATOR_KEY.getKeyStroke(), "SHOW_HOTKEYS");
  actionMap.put("SHOW_HOTKEYS", new CShowHotkeysAction(parent));

  registerSearchKeys(panel.getModel().getGraph().getView(), searchField, inputMap, actionMap);

  registerDebuggerKeys(panel.getModel().getParent(), panel.getModel().getGraph(),
      debuggerProvider, inputMap, actionMap);
}
 
Example 30
Source Project: jdk8u-jdk   Source File: BasicLookAndFeel.java    License: 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());
    }
}