List of usage examples for javax.swing JComponent WHEN_FOCUSED
int WHEN_FOCUSED
To view the source code for javax.swing JComponent WHEN_FOCUSED.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the component has the focus. From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
JPanel createMoviehitsList() { /* Movies List panel...*/ JPanel panelMoviesList = new JPanel(); panelMoviesList.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-movie-list.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(5, 5, 5, 5))); listMovies = new JList() { public String getToolTipText(MouseEvent e) { if (getCellBounds(0, 0) == null) return null; String retVal = null; int row = (int) e.getPoint().getY() / (int) getCellBounds(0, 0).getHeight(); if (row >= 0 && row < getModel().getSize() && getMoviesList().getModel().getElementAt(row) instanceof ModelIMDbSearchHit) { retVal = ((ModelIMDbSearchHit) getMoviesList().getModel().getElementAt(row)).getAka(); if (retVal != null && retVal.trim().equals("")) //$NON-NLS-1$ retVal = null;/* w w w . j a v a 2 s . co m*/ } return retVal; } public JToolTip createToolTip() { JMultiLineToolTip tooltip = new JMultiLineToolTip(); tooltip.setComponent(this); return tooltip; } }; // Unfortunately setting tooltip timeout affects ALL tooltips ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.registerComponent(listMovies); ttm.setInitialDelay(0); ttm.setReshowDelay(0); listMovies.setFixedCellHeight(18); listMovies.setFont(new Font(listMovies.getFont().getName(), Font.PLAIN, listMovies.getFont().getSize())); listMovies.setLayoutOrientation(JList.VERTICAL); listMovies.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMovies.setCellRenderer(new MovieHitListCellRenderer()); listMovies.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // Open we page if (SwingUtilities.isRightMouseButton(event)) { int index = listMovies.locationToIndex(event.getPoint()); if (index >= 0) { ModelIMDbSearchHit hit = (ModelIMDbSearchHit) listMovies.getModel().getElementAt(index); if (hit.getUrlID() != null && !hit.getUrlID().equals("")) { BrowserOpener opener = new BrowserOpener(hit.getCompleteUrl()); opener.executeOpenBrowser(MovieManager.getConfig().getSystemWebBrowser(), MovieManager.getConfig().getBrowserPath()); } } } else if (SwingUtilities.isLeftMouseButton(event) && event.getClickCount() >= 2) { buttonSelect.doClick(); } } }); KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); ActionListener listKeyBoardActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { log.debug("ActionPerformed: " + "Movielist - ENTER pressed."); //$NON-NLS-1$ buttonSelect.doClick(); } }; listMovies.registerKeyboardAction(listKeyBoardActionListener, enterKeyStroke, JComponent.WHEN_FOCUSED); JScrollPane scrollPaneMovies = new JScrollPane(listMovies); scrollPaneMovies.setAutoscrolls(true); //scrollPaneMovies.registerKeyboardAction(listKeyBoardActionListener,enterKeyStroke, JComponent.WHEN_FOCUSED); panelMoviesList.setLayout(new BorderLayout()); panelMoviesList.add(scrollPaneMovies, BorderLayout.CENTER); return panelMoviesList; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopLookupField.java
protected void initClearShortcut() { JComponent editor = (JComponent) comboBox.getEditor().getEditorComponent(); KeyStroke clearKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK, false); editor.getInputMap(JComponent.WHEN_FOCUSED).put(clearKeyStroke, "clearShortcut"); editor.getActionMap().put("clearShortcut", new AbstractAction() { @Override/*from ww w .j a va 2 s . co m*/ public void actionPerformed(ActionEvent e) { if (!isRequired() && isEditable() && isEnabled()) { setValue(null); fireUserSelectionListeners(); } } }); }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Adds a component action.//from ww w . j av a 2 s . c o m * * @param component * The compoenet to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Convenience wrapper for {@link #bindKeyToAction(JComponent, KeyStroke, * Action, int) bindKeyToAction(c, key, a, JComponentn.WHEN_FOCUSED)}. *//* w w w .j av a2 s .com*/ public static void bindKeyToAction(JComponent c, KeyStroke key, Action a) { bindKeyToAction(c, key, a, JComponent.WHEN_FOCUSED); }
From source file:net.sf.jabref.EntryEditor.java
protected void setupSwingComponentKeyBindings(JComponent component) { // Set up key bindings and focus listener for the FieldEditor. InputMap im = component.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = component.getActionMap(); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Entry editor, next panel"), "right"); im.put(prefs.getKey("Entry editor, next panel 2"), "right"); am.put("right", switchRightAction); im.put(prefs.getKey("Entry editor, previous panel"), "left"); im.put(prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("left", switchLeftAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); im.put(prefs.getKey("Save database"), "save"); am.put("save", saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", frame.prevTab); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
@Override public void addAction(Action action, int index) { checkNotNullArgument(action, "action must be non null"); int oldIndex = findActionById(actionsOrder, action.getId()); if (oldIndex >= 0) { removeAction(actionsOrder.get(oldIndex)); if (index > oldIndex) { index--;/*from w w w.j a v a 2 s . co m*/ } } actionsOrder.add(index, action); DesktopButton dButton = new DesktopButton(); dButton.setParentEnabled(isEnabledWithParent()); dButton.setShouldBeFocused(false); dButton.setAction(action); dButton.getImpl().setFocusable(false); dButton.getImpl().setText(""); impl.addButton(dButton.getImpl(), index); buttons.add(dButton); // apply Editable after action owner is set if (action instanceof StandardAction) { ((StandardAction) action).setEditable(isEditable()); } updateOrderedShortcuts(); ActionMap actionMap = getImpl().getInputField().getActionMap(); actionMap.put(action.getId(), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { action.actionPerform(dButton); } }); if (action.getShortcutCombination() != null) { InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED); KeyStroke shortcutKeyStroke = DesktopComponentsHelper .convertKeyCombination(action.getShortcutCombination()); inputMap.put(shortcutKeyStroke, action.getId()); } actionsPermissions.apply(action); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
@Override public void removeAction(@Nullable Action action) { if (action != null) { if (actionsOrder.remove(action)) { if (action.getOwner() != null && action.getOwner() instanceof DesktopButton) { JButton button = ((DesktopButton) action.getOwner()).getImpl(); impl.removeButton(button); }/*from www .j ava 2 s .co m*/ InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED); ActionMap actionMap = getImpl().getInputField().getActionMap(); List<KeyStroke> keyStrokes = keyStrokesMap.get(action); if (keyStrokes != null) { for (KeyStroke keyStroke : keyStrokes) { inputMap.remove(keyStroke); } actionMap.remove(action.getId()); } updateOrderedShortcuts(); } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
protected void updateOrderedShortcuts() { InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED); for (int i = 0; i < 9; i++) { KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + i, modifiersMask, false); inputMap.remove(keyStroke);/*from w ww .j av a2 s .c o m*/ } int index = 0; for (Action action : actionsOrder) { KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + index, modifiersMask, false); List<KeyStroke> keyStrokes = new LinkedList<>(); keyStrokes.add(keyStroke); keyStrokesMap.put(action, keyStrokes); inputMap.put(keyStroke, action.getId()); index++; } }
From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java
/** * NOTE: This method is only used for the source panel, not for the * other tabs. Look at EntryEditorTab for the setup of text components * in the other tabs./* ww w . j a va2 s . c o m*/ */ private void setupJTextComponent(JTextComponent textComponent) { // Set up key bindings and focus listener for the FieldEditor. InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED); ActionMap actionMap = textComponent.getActionMap(); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); actionMap.put("store", getStoreFieldAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right"); actionMap.put("right", getSwitchRightAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left"); actionMap.put("left", getSwitchLeftAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); actionMap.put("help", getHelpAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), "save"); actionMap.put("save", getSaveDatabaseAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab"); actionMap.put("nexttab", frame.nextTab); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab"); actionMap.put("prevtab", frame.prevTab); Set<AWTKeyStroke> keys = new HashSet<>( textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); textComponent.addFocusListener(new FieldListener()); }
From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java
private JButton initAction(Action action, ImageId imageId, String toolTip, KeyStroke keyStroke) { KDClientUtils.initAction(imageId, action, toolTip, false); action.setEnabled(false);// w w w . j av a2 s . c om String command = action.toString(); JButton result = new JButton(action); result.getActionMap().put(command, action); result.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, command); return result; }