Java Code Examples for javax.swing.InputMap

The following examples show how to use javax.swing.InputMap. 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 check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u-jdk   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 2
Source Project: tn5250j   Source File: KeyboardHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected boolean emulatorAction(KeyStroke ks, KeyEvent e){

      if (sessionGui == null)
         return false;

      InputMap map = getInputMap();
      ActionMap am = getActionMap();

      if(map != null && am != null && sessionGui.isEnabled()) {
         Object binding = map.get(ks);
         Action action = (binding == null) ? null : am.get(binding);
         if (action != null) {
            return true;
         }
      }
      return false;
   }
 
Example 3
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 4
/**
 * Manage low level key strokes ESCAPE : Close the window
 *
 * @return
 */
protected JRootPane createRootPane() {
	JRootPane rootPane = new JRootPane();
	KeyStroke strokeEscape = KeyStroke.getKeyStroke("ESCAPE");

	@SuppressWarnings("serial")
	Action actionListener = new AbstractAction() {
		public void actionPerformed(ActionEvent actionEvent) {
			setVisible(false);
		}
	};

	InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(strokeEscape, "ESCAPE");
	rootPane.getActionMap().put("ESCAPE", actionListener);

	return rootPane;
}
 
Example 5
Source Project: FlatLaf   Source File: UIDefaultsDump.java    License: Apache License 2.0 6 votes vote down vote up
private void dumpInputMap( PrintWriter out, InputMap inputMap, String indent ) {
	if( indent == null )
		indent = "    ";

	out.printf( "%d    %s", inputMap.size(), dumpClass( inputMap ) );

	KeyStroke[] keys = inputMap.keys();
	if( keys != null ) {
		Arrays.sort( keys, (keyStroke1, keyStroke2) -> {
			return String.valueOf( keyStroke1 ).compareTo( String.valueOf( keyStroke2 ) );
		} );
		for( KeyStroke keyStroke : keys ) {
			Object value = inputMap.get( keyStroke );
			String strKeyStroke = keyStroke.toString().replace( "pressed ", "" );
			out.printf( "%n%s%-20s  %s", indent, strKeyStroke, value );
		}
	}

	InputMap parent = inputMap.getParent();
	if( parent != null )
		dumpInputMap( out, parent, indent + "    " );
}
 
Example 6
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 7
Source Project: FlatLaf   Source File: FlatComboBoxUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureEditor() {
	super.configureEditor();

	// explicitly make non-opaque
	if( editor instanceof JComponent )
		((JComponent)editor).setOpaque( false );

	editor.applyComponentOrientation( comboBox.getComponentOrientation() );

	updateEditorColors();

	// macOS
	if( SystemInfo.IS_MAC && editor instanceof JTextComponent ) {
		// delegate actions from editor text field to combobox, which is necessary
		// because text field on macOS already handle those keys
		InputMap inputMap = ((JTextComponent)editor).getInputMap();
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "UP" ) );
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "KP_UP" ) );
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "DOWN" ) );
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "KP_DOWN" ) );
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "HOME" ) );
		new EditorDelegateAction( inputMap, KeyStroke.getKeyStroke( "END" ) );
	}
}
 
Example 8
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 9
Source Project: TencentKona-8   Source File: XTextFieldPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 10
/**
 * Manage low level key strokes ESCAPE : Close the window
 *
 * @return
 */
protected JRootPane createRootPane() {
	JRootPane rootPane = new JRootPane();
	KeyStroke strokeEscape = KeyStroke.getKeyStroke("ESCAPE");

	@SuppressWarnings("serial")
	Action actionListener = new AbstractAction() {
		public void actionPerformed(ActionEvent actionEvent) {
			setVisible(false);
		}
	};

	InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(strokeEscape, "ESCAPE");
	rootPane.getActionMap().put("ESCAPE", actionListener);

	return rootPane;
}
 
Example 11
/**
 * Bind a few keyboard events to actions among assemblies.
 */
private void bindKeys ()
{
    final InputMap inputMap = stubsPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    final ActionMap actionMap = stubsPane.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke("PAGE_UP"), "PageUpAction");
    actionMap.put("PageUpAction", new PageUpAction());

    inputMap.put(KeyStroke.getKeyStroke("PAGE_DOWN"), "PageDownAction");
    actionMap.put("PageDownAction", new PageDownAction());

    inputMap.put(KeyStroke.getKeyStroke("control HOME"), "CtrlHomeAction");
    actionMap.put("CtrlHomeAction", new CtrlHomeAction());

    inputMap.put(KeyStroke.getKeyStroke("control END"), "CtrlEndAction");
    actionMap.put("CtrlEndAction", new CtrlEndAction());
}
 
Example 12
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 13
Source Project: netbeans   Source File: NbEditorToolBar.java    License: Apache License 2.0 6 votes vote down vote up
private void installNoOpActionMappings(){
    InputMap im = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    // cut
    KeyStroke[] keys = findEditorKeys(DefaultEditorKit.cutAction, KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    for (int i = 0; i < keys.length; i++) {
        im.put(keys[i], NOOP_ACTION_KEY);
    }
    // copy
    keys = findEditorKeys(DefaultEditorKit.copyAction, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
    for (int i = 0; i < keys.length; i++) {
        im.put(keys[i], NOOP_ACTION_KEY);
    }
    // delete
    keys = findEditorKeys(DefaultEditorKit.deleteNextCharAction, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); //NOI18N
    for (int i = 0; i < keys.length; i++) {
        im.put(keys[i], NOOP_ACTION_KEY);
    }
    // paste
    keys = findEditorKeys(DefaultEditorKit.pasteAction, KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
    for (int i = 0; i < keys.length; i++) {
        im.put(keys[i], NOOP_ACTION_KEY);
    }
    
    getActionMap().put(NOOP_ACTION_KEY, NOOP_ACTION);
}
 
Example 14
Source Project: marathonv5   Source File: JavaElementPropertyAccessor.java    License: Apache License 2.0 6 votes vote down vote up
private String getKeyStrokeFor(String action) {
    JSONArray r = new JSONArray();
    if (component instanceof JComponent) {
        InputMap inputMap = ((JComponent) component).getInputMap();
        KeyStroke[] allKeys = inputMap.allKeys();
        for (KeyStroke ks : allKeys) {
            if (action.equals(inputMap.get(ks))) {
                r.put(ks.toString());
            }
        }
    }
    if (r.length() > 0) {
        return r.toString();
    }
    return null;
}
 
Example 15
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    KeyStroke ks = null;

    if (FilterUtils.FILTER_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    } else if (SearchUtils.FIND_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    } else if (SearchUtils.FIND_NEXT_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
    } else if (SearchUtils.FIND_PREV_ACTION_KEY.equals(actionKey)) {
        ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK);
    } else if (SearchUtils.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 16
Source Project: openjdk-jdk9   Source File: XTextAreaPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 17
Source Project: netbeans   Source File: ToolTipManagerEx.java    License: Apache License 2.0 6 votes vote down vote up
/**
    * Registers a component for tooltip management.
    * <p>
    * This will register key bindings to show and hide the tooltip text
    * only if <code>component</code> has focus bindings. This is done
    * so that components that are not normally focus traversable, such
    * as <code>JLabel</code>, are not made focus traversable as a result
    * of invoking this method.
    *
    * @param component  a <code>JComponent</code> object to add
    * @see JComponent#isFocusTraversable
    */
   protected void registerComponent(JComponent component) {
       component.removeMouseListener(this);
       component.addMouseListener(this);
       component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    // register our accessibility keybindings for this component
    // this will apply globally across L&F
    // Post Tip: Ctrl+F1
    // Unpost Tip: Esc and Ctrl+F1
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
Example 18
Source Project: netbeans   Source File: CheckTreeView.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
    
    setFocusable( false );
    
    CheckListener l = new CheckListener();
    tree.addMouseListener( l );
    tree.addKeyListener( l );

    CheckRenderer check = new CheckRenderer();
    tree.setCellRenderer( check );
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    tree.setShowsRootHandles(false);
    
    InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
    if( null != input )
        input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
    
    setBorder( UIManager.getBorder("ScrollPane.border") );
}
 
Example 19
Source Project: netbeans   Source File: CheckTreeView.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
    
    setFocusable( false );
    
    CheckListener l = new CheckListener();
    tree.addMouseListener( l );
    tree.addKeyListener( l );

    CheckRenderer check = new CheckRenderer();
    tree.setCellRenderer( check );
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    tree.setShowsRootHandles(false);
    
    InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
    if( null != input )
        input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
    
    setBorder( UIManager.getBorder("ScrollPane.border") );
}
 
Example 20
Source Project: netbeans   Source File: OutlineView.java    License: Apache License 2.0 6 votes vote down vote up
private void removeDefaultCutCopyPaste(InputMap map) {
    putActionDelegate(map, KeyStroke.getKeyStroke("control C")); // NOI18N
    map.put(KeyStroke.getKeyStroke("control V"), "none"); // NOI18N
    map.put(KeyStroke.getKeyStroke("control X"), "none"); // NOI18N
    putActionDelegate(map, KeyStroke.getKeyStroke("COPY")); // NOI18N
    map.put(KeyStroke.getKeyStroke("PASTE"), "none"); // NOI18N
    map.put(KeyStroke.getKeyStroke("CUT"), "none"); // NOI18N

    if (Utilities.isMac()) {
        putActionDelegate(map, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.META_MASK)); // NOI18N
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.META_MASK), "none"); // NOI18N
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.META_MASK), "none"); // NOI18N
    } else {
        putActionDelegate(map, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK)); // NOI18N
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK), "none"); // NOI18N
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK), "none"); // NOI18N
    }
}
 
Example 21
Source Project: netbeans   Source File: Preview.java    License: Apache License 2.0 6 votes vote down vote up
private void populateInputMap(InputMap inputMap) {
    inputMap.put(KeyStroke.getKeyStroke('k'), INCREASE);
    inputMap.put(KeyStroke.getKeyStroke('K'), INCREASE);
    inputMap.put(KeyStroke.getKeyStroke('+'), INCREASE);
    inputMap.put(KeyStroke.getKeyStroke('='), INCREASE);
    inputMap.put(KeyStroke.getKeyStroke('g'), DECREASE);
    inputMap.put(KeyStroke.getKeyStroke('G'), DECREASE);
    inputMap.put(KeyStroke.getKeyStroke('-'), DECREASE);
    inputMap.put(KeyStroke.getKeyStroke('_'), DECREASE);
    inputMap.put(KeyStroke.getKeyStroke('l'), LAST);
    inputMap.put(KeyStroke.getKeyStroke('L'), LAST);
    inputMap.put(KeyStroke.getKeyStroke('*'), LAST);
    inputMap.put(KeyStroke.getKeyStroke('f'), FIRST);
    inputMap.put(KeyStroke.getKeyStroke('F'), FIRST);
    inputMap.put(KeyStroke.getKeyStroke('/'), FIRST);
}
 
Example 22
Source Project: netbeans   Source File: AutoHidingMenuBar.java    License: Apache License 2.0 6 votes vote down vote up
private void populateMenuOpenKeyboardShortcuts(JComponent component) {
    /* In the future, it would be nice to include the shortcut from
    o.n.modules.quicksearch.QuickSearchAction/QuickSearchComboBar here. That shortcut isn't set
    via a regular InputMap, however, so a new cross-module API (maybe a client property that
    could be set on QuickSearchComboBar) would be needed to let QuickSearchComboBar tell
    AutoHidingMenuBar about its shortcut. */
    InputMap im = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (im != null) {
        KeyStroke keyStrokes[] = im.allKeys();
        if (keyStrokes != null) {
            for (KeyStroke keyStroke : keyStrokes) {
                menuOpenKeyboardShortcuts.put(keyStroke,
                        "OpenMenu"); // Value doesn't matter, just use some non-null string.
            }
        }
    }
    // Don't descend into the actual menus.
    if (!(component instanceof JMenu)) {
        for (Component childComponent : component.getComponents()) {
            if (childComponent instanceof JComponent)
                populateMenuOpenKeyboardShortcuts((JComponent) childComponent);
        }
    }
}
 
Example 23
Source Project: jdk8u-dev-jdk   Source File: XTextFieldPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example 24
Source Project: netbeans   Source File: FlatLFCustoms.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object createValue(UIDefaults table) {
    // get base input map from look and feel defaults (resolves lazy base input map)
    InputMap inputMap = (InputMap) UIManager.getLookAndFeelDefaults().get(baseKey);

    // modify input map (replace or remove)
    for (int i = 0; i < bindings.length; i += 2) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke((String) bindings[i]);
        if (bindings[i + 1] != null) {
            inputMap.put(keyStroke, bindings[i + 1]);
        } else {
            inputMap.remove(keyStroke);
        }
    }

    return inputMap;
}
 
Example 25
Source Project: binnavi   Source File: CAbstractTreeTable.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new abstract tree table object.
 *
 * @param projectTree The project tree shown in the main window.
 * @param model The raw model that is responsible for the table layout.
 * @param helpInfo Provides context-sensitive information for the table.
 */
public CAbstractTreeTable(final JTree projectTree, final CAbstractTreeTableModel<T> model,
    final IHelpInformation helpInfo) {
  super(model, helpInfo);

  treeTableModel = Preconditions.checkNotNull(model, "IE01939: Model argument can't be null");
  tree =
      Preconditions.checkNotNull(projectTree, "IE02343: Project tree argument can not be null");

  addMouseListener(mouseListener);

  setDefaultRenderer(String.class, new CProjectTreeTableRenderer());

  final InputMap windowImap = getInputMap(JComponent.WHEN_FOCUSED);

  windowImap.put(HotKeys.SEARCH_HK.getKeyStroke(), "SEARCH");
  getActionMap().put("SEARCH", CActionProxy.proxy(new SearchAction()));

  windowImap.put(HotKeys.DELETE_HK.getKeyStroke(), "DELETE");
  getActionMap().put("DELETE", CActionProxy.proxy(new DeleteAction()));

  updateUI();
}
 
Example 26
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 27
Source Project: wpcleaner   Source File: JCloseableTabbedPane.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 * 
 * @param tabPlacement the placement for the tabs relative to the content
 * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
 */
public JCloseableTabbedPane(int tabPlacement, int tabLayoutPolicy) {
  super(tabPlacement, tabLayoutPolicy);
  addKeyListener(this);
  ActionMap actionMap = getActionMap();
  InputMap inputMap = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_DOWN_MASK);
  inputMap.put(keyStroke, "close-current-tab");
  actionMap.put("close-current-tab", new AbstractAction() {
    
    /** Serialization */
    private static final long serialVersionUID = -1886432591524366546L;

    /**
     * @param e Event.
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent e) {
      remove(getSelectedIndex());
    }
  });
}
 
Example 28
Source Project: beautyeye   Source File: SwingSet2.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the popup menu.
 *
 * @return the j popup menu
 */
public JPopupMenu createPopupMenu() {
	JPopupMenu popup = new JPopupMenu("JPopupMenu demo");

	createPopupMenuItem(popup, "LafMenu.java_label", "LafMenu.java_mnemonic",
			"LafMenu.java_accessible_description", metal);

	createPopupMenuItem(popup, "LafMenu.windows_label", "LafMenu.windows_mnemonic",
			"LafMenu.windows_accessible_description", windows);

	createPopupMenuItem(popup, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic",
			"LafMenu.gtk_accessible_description", gtk);

	// register key binding to activate popup menu
	InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	map.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.SHIFT_MASK),
	"postMenuAction");
	map.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), "postMenuAction");
	getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));

	return popup;
}
 
Example 29
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 30
Source Project: netbeans   Source File: PageFlowScene.java    License: Apache License 2.0 6 votes vote down vote up
private WidgetAction createActionMapAction(Page page) {
    InputMap inputMap = new InputMap();
    ActionMap actionMap = new ActionMap();
    Action[] actions = page.getActions(true);
    for (Action action : actions) {
        KeyStroke keyStroke = (KeyStroke) action.getValue(javax.swing.Action.ACCELERATOR_KEY);
        if (keyStroke != null) {
            inputMap.put(keyStroke, action.toString());
            actionMap.put(action.toString(), action);
        }
    }
    if (actionMap.size() < 1) {
        return null;
    }
    /* Not sure if it is the right thing to create a new action map
     * should I be adding it?
     */
    return new MyActionMapAction(inputMap, actionMap);


    //return  ActionFactory.createActionMapAction(inputMap, actionMap);
}