Java Code Examples for javax.swing.InputMap#put()

The following examples show how to use javax.swing.InputMap#put() . 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: CAbstractTreeTable.java    From binnavi with 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 2
Source File: frmSearchPoint.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: FindInQueryBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
FindInQueryBar(FindInQuerySupport support) {
    this.support = support;
    initComponents();
    lastSearchModel = new DefaultComboBoxModel();
    findCombo.setModel(lastSearchModel);
    findCombo.setSelectedItem(""); // NOI18N
    initialized = true;
    addComboEditorListener();
    InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    String closeKey = "close"; // NOI18N
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeKey);
    getActionMap().put(closeKey, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FindInQueryBar.this.support.cancel();
        }
    });
}
 
Example 4
Source File: FlatInputMaps.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
public Object createValue( UIDefaults table ) {
	// get base input map
	InputMap inputMap = (baseInputMap instanceof LazyValue)
		? (InputMap) ((LazyValue)baseInputMap).createValue( table )
		: (InputMap) baseInputMap;

	// 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 5
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 6
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 7
Source File: CAddressSpacesTable.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new address spaces table.
 * 
 * @param projectTree Project tree of the main window.
 * @param database Database the address space belongs to.
 * @param project The project that contains the address spaces.
 * @param container View container of the project.
 */
public CAddressSpacesTable(final JTree projectTree, final IDatabase database,
    final INaviProject project, final IViewContainer container) {
  super(projectTree, new CAddressSpacesModel(project), new CAddressSpacesTableHelp());

  m_database = Preconditions.checkNotNull(database, "IE02871: database argument can not be null");
  m_project = Preconditions.checkNotNull(project, "IE02872: project argument can not be null");
  m_container =
      Preconditions.checkNotNull(container, "IE02873: container argument can not be null");

  setDefaultRenderer(Object.class, new AddressSpaceLoadedRenderer());

  final InputMap windowImap = getInputMap(JComponent.WHEN_FOCUSED);

  windowImap.put(HotKeys.LOAD_HK.getKeyStroke(), "LOAD");
  getActionMap().put("LOAD", CActionProxy.proxy(new LoadAddressSpaceAction()));
}
 
Example 8
Source File: TableTabCaret.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
TableTabCaret(TableTab table) {
	this.table = table;
	cursorRow = 0;
	cursorCol = 0;
	markRow = 0;
	markCol = 0;
	table.getTruthTable().addTruthTableListener(listener);
	table.addMouseListener(listener);
	table.addMouseMotionListener(listener);
	table.addKeyListener(listener);
	table.addFocusListener(listener);

	InputMap imap = table.getInputMap();
	ActionMap amap = table.getActionMap();
	AbstractAction nullAction = new AbstractAction() {
		/**
		 * 
		 */
		private static final long serialVersionUID = 7932515593155479627L;

		@Override
		public void actionPerformed(ActionEvent e) {
		}
	};
	String nullKey = "null";
	amap.put(nullKey, nullAction);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), nullKey);
	imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), nullKey);
}
 
Example 9
Source File: OutlineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void putActionDelegate(InputMap map, KeyStroke ks) {
    String binding = COPY_ACTION_DELEGATE+ks.toString();
    Action action = getCopyActionDelegate(map, ks);
    if (action != null) {
        getActionMap().put(binding, action);
        map.put(ks, binding);
    }
}
 
Example 10
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public StatTableModel(CharacterFacade character, JTable jtable)
{
	this.character = character;
	this.table = jtable;
	this.stats = character.getDataSet().getStats();
	int min = Integer.MAX_VALUE;
	for (PCStat sf : stats)
	{
		min = Math.min(sf.getSafe(IntegerKey.MIN_VALUE), min);
	}
	editor.setMinValue(min);

	final JTextField field = editor.getTextField();
	InputMap map = field.getInputMap(JComponent.WHEN_FOCUSED);

	map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), MOVEDOWN);
	map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), MOVEDOWN);
	Action action = new AbstractAction()
	{

		@Override
		public void actionPerformed(ActionEvent e)
		{
			//Logging.log(Logging.WARNING, "Got handleEnter from " + e.getSource());
			int row = table.getEditingRow();
			final int col = table.getEditingColumn();
			table.getCellEditor().stopCellEditing(); // store user input
			final int nextRow = row + 1;
			startEditingNextRow(table, col, nextRow, field);
		}

	};
	field.getActionMap().put(MOVEDOWN, action);
}
 
Example 11
Source File: PCGenFrame.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static InputMap createInputMap(ActionMap actionMap)
{
	InputMap inputMap = new InputMap();
	for (Object obj : actionMap.keys())
	{
		KeyStroke key = (KeyStroke) actionMap.get(obj).getValue(Action.ACCELERATOR_KEY);
		if (key != null)
		{
			inputMap.put(key, obj);
		}
	}
	return inputMap;
}
 
Example 12
Source File: AnimationAutoCompletion.java    From 3Dscript with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Uninstalls this auto-completion from its text component. If it is not
 * installed on any text component, nothing happens.
 *
 * @see #install(JTextComponent)
 */
@Override
public void uninstall() {

	if (textComponent != null) {

		hidePopupWindow(); // Unregisters listeners, actions, etc.

		uninstallTriggerKey();

		// Uninstall the function completion key.
		char start = provider.getParameterListStart();
		if (start != 0) {
			KeyStroke ks = KeyStroke.getKeyStroke(start);
			InputMap im = textComponent.getInputMap();
			im.put(ks, oldParenKey);
			ActionMap am = textComponent.getActionMap();
			am.put(PARAM_COMPLETE_KEY, oldParenAction);
		}

		textComponentListener.removeFrom(textComponent);
		if (parentWindow != null) {
			parentWindowListener.removeFrom(parentWindow);
		}

		if (isAutoActivationEnabled()) {
			autoActivationListener.removeFrom(textComponent);
		}

		UIManager.removePropertyChangeListener(lafListener);

		textComponent = null;
		popupWindowListener.uninstall(popupWindow);
		popupWindow = null;

	}

}
 
Example 13
Source File: CommitPanel.java    From netbeans with 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 14
Source File: CGraphHotkeys.java    From binnavi with 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 15
Source File: EuropePanel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
public EuropeButton(String text, int keyEvent, String command,
                    ActionListener listener) {
    setOpaque(true);
    setText(text);
    setActionCommand(command);
    addActionListener(listener);
    InputMap closeInputMap = new ComponentInputMap(this);
    closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, false),
                      "pressed");
    closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, true),
                      "released");
    SwingUtilities.replaceUIInputMap(this,
                                     JComponent.WHEN_IN_FOCUSED_WINDOW,
                                     closeInputMap);
}
 
Example 16
Source File: GlobalSearchPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the Global Search result visualization. Has no effect if it already is visualized.
 */
public void initializeSearchResultVisualization() {
	synchronized (SINGLETON_LOCK) {
		if (resultDialog == null) {
			resultDialog = new GlobalSearchDialog(ApplicationFrame.getApplicationFrame(), controller) {

				@Override
				public Dimension getPreferredSize() {
					// make sure width is same as this panel + width of the i18n label
					int width = PREFERRED_WIDTH + GlobalSearchCategoryPanel.I18N_NAME_WIDTH + 1;
					Dimension prefSize = super.getPreferredSize();
					prefSize.width = width;

					// make sure height does not exceed certain amount
					prefSize.height = Math.min(prefSize.height, MAX_RESULT_DIALOG_HEIGHT);

					return prefSize;
				}
			};
			resultDialog.setFocusableWindowState(false);

			// even though dialog cannot be focused, it should hide when RM Studio is minimized
			ApplicationFrame.getApplicationFrame().addWindowListener(new WindowAdapter() {

				@Override
				public void windowIconified(WindowEvent e) {
					GlobalSearchPanel.this.hideComponents();
				}
			});

			// also close everything if results are displayed
			InputMap inputMap = resultDialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
			ActionMap actionMap = resultDialog.getRootPane().getActionMap();

			inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CLOSE_FULL_SEARCH_DIALOG);
			addCloseFullSearchDialogAction(actionMap);
		}
	}
}
 
Example 17
Source File: AnnotationEditor.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setShortCuts(InputMap inputMap, String[] keyStrokes,
    String action) {
  for(String aKeyStroke : keyStrokes) {
    inputMap.put(KeyStroke.getKeyStroke(aKeyStroke), action);
  }
}
 
Example 18
Source File: CMemoryRangeDialog.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new memory range dialog.
 * 
 * @param owner The parent frame of the dialog.
 */
public CMemoryRangeDialog(final JFrame owner) {
  super(owner, "Enter a memory range", true);

  setLayout(new BorderLayout());

  setSize(400, 170);

  final JLabel startLabel = new JLabel("Start Address (Hex)");

  final JLabel endLabel = new JLabel("Number of Bytes (Hex)");

  m_startField = new JFormattedTextField(new CHexFormatter(8));
  m_endField = new JFormattedTextField(new CHexFormatter(8));

  final JPanel labelPanel = new JPanel(new GridBagLayout());

  final GridBagConstraints constraints = new GridBagConstraints();

  constraints.gridx = 0;
  constraints.gridy = 0;
  constraints.weightx = 0.2;
  constraints.insets = new Insets(5, 5, 0, 0);
  constraints.fill = GridBagConstraints.HORIZONTAL;

  labelPanel.add(startLabel, constraints);

  constraints.gridx = 1;
  constraints.gridy = 0;
  constraints.weightx = 1;
  constraints.insets = new Insets(5, 0, 0, 0);
  labelPanel.add(m_startField, constraints);

  constraints.gridx = 0;
  constraints.gridy = 1;
  constraints.weightx = 0.2;
  constraints.insets = new Insets(5, 5, 0, 0);

  labelPanel.add(endLabel, constraints);

  constraints.gridx = 1;
  constraints.gridy = 1;
  constraints.weightx = 1;
  constraints.insets = new Insets(5, 0, 0, 0);
  labelPanel.add(m_endField, constraints);

  final JPanel topPanel = new JPanel(new BorderLayout());

  final JTextArea area =
      new JTextArea(
          "Please enter a memory range to display. \nBe careful. Displaying invalid memory can crash the device.");
  area.setBorder(new EmptyBorder(0, 5, 0, 0));

  area.setEditable(false);

  topPanel.add(area, BorderLayout.NORTH);
  topPanel.add(labelPanel, BorderLayout.CENTER);

  topPanel.setBorder(new TitledBorder(new LineBorder(Color.BLACK)));

  final CPanelTwoButtons buttonPanel =
      new CPanelTwoButtons(new InternalListener(), "OK", "Cancel");

  add(topPanel, BorderLayout.NORTH);
  add(buttonPanel, BorderLayout.SOUTH);

  m_startField.requestFocusInWindow();

  final InputMap windowImap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

  windowImap.put(HotKeys.APPLY_HK.getKeyStroke(), "APPLY");
  getRootPane().getActionMap().put("APPLY", CActionProxy.proxy(new ApplyAction()));

  setLocationRelativeTo(null);
}
 
Example 19
Source File: CommentPanel.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void setupKeyMap() {
  final InputMap nextMessageKeymap = nextMessage.getInputMap();
  nextMessageKeymap.put(KeyStroke.getKeyStroke('\n'), saveAction);
}
 
Example 20
Source File: FlatComboBoxUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
EditorDelegateAction( InputMap inputMap, KeyStroke keyStroke ) {
	this.keyStroke = keyStroke;

	// add to input map
	inputMap.put( keyStroke, this );
}