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:edmondskarp.Gui.EdmondsKarpGui.java
private void setupUndoHotkeys() { String UNDO = "Undo action key"; String REDO = "Redo action key"; Action undoAction = new AbstractAction() { @Override/*from ww w . ja v a2 s .c om*/ public void actionPerformed(ActionEvent e) { controller.restoreState(true); } }; Action redoAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { controller.restoreState(false); } }; myPanel.getActionMap().put(UNDO, undoAction); myPanel.getActionMap().put(REDO, redoAction); InputMap[] inputMaps = new InputMap[] { myPanel.getInputMap(JComponent.WHEN_FOCUSED), myPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT), myPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), }; for (InputMap i : inputMaps) { i.put(KeyStroke.getKeyStroke("control Z"), UNDO); i.put(KeyStroke.getKeyStroke("control Y"), REDO); i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), UNDO); } }
From source file:net.sourceforge.pmd.cpd.GUI.java
private JComponent makeMatchList() { resultsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/* w ww. j a v a2 s .com*/ public void valueChanged(ListSelectionEvent e) { populateResultArea(); } }); resultsTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copyMatchListSelectionsToClipboard(); } }, "Copy", COPY_KEY_STROKE, JComponent.WHEN_FOCUSED); resultsTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteMatchlistSelections(); } }, "Del", DELETE_KEY_STROKE, JComponent.WHEN_FOCUSED); int[] alignments = new int[matchColumns.length]; for (int i = 0; i < alignments.length; i++) { alignments[i] = matchColumns[i].alignment(); } resultsTable.setDefaultRenderer(Object.class, new AlignmentRenderer(alignments)); final JTableHeader header = resultsTable.getTableHeader(); header.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { sortOnColumn(header.columnAtPoint(new Point(e.getX(), e.getY()))); } }); return new JScrollPane(resultsTable); }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Fires a button click when using the enter key * //from ww w.j av a 2 s .c om * @param button to press when enter is pressed */ public static void enterPressesWhenFocused(JButton button) { button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED); button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED); }
From source file:org.docx4all.swing.text.WordMLEditorKit.java
private void initKeyBindings(JEditorPane editor) { ActionMap myActionMap = new ActionMap(); InputMap myInputMap = new InputMap(); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK); myActionMap.put(insertSoftBreakAction, new InsertSoftBreakAction(insertSoftBreakAction)); myInputMap.put(ks, insertSoftBreakAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); myActionMap.put(enterKeyTypedAction, new EnterKeyTypedAction(enterKeyTypedAction)); myInputMap.put(ks, enterKeyTypedAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); myActionMap.put(deleteNextCharAction, new DeleteNextCharAction(deleteNextCharAction)); myInputMap.put(ks, deleteNextCharAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0); myActionMap.put(deletePrevCharAction, new DeletePrevCharAction(deletePrevCharAction)); myInputMap.put(ks, deletePrevCharAction); myActionMap.setParent(editor.getActionMap()); myInputMap.setParent(editor.getInputMap()); editor.setActionMap(myActionMap);/*www . j av a 2 s . c o m*/ editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap); }
From source file:org.executequery.gui.browser.FindAction.java
private void init() { searchPanel = new JPanel(new GridBagLayout()); popup = new JPopupMenu(); searchField = WidgetFactory.createTextField(); searchField.setPreferredSize(new Dimension(270, 22)); resultsList = initSearchResultsList(); JScrollPane scrollPane = new JScrollPane(resultsList); scrollPane.setPreferredSize(new Dimension(300, 150)); JLabel label = new JLabel(" Search: "); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;/*from w w w. j a v a 2 s.c o m*/ gbc.gridy = 0; gbc.insets.left = 3; gbc.insets.top = 3; gbc.insets.bottom = 3; searchPanel.add(label, gbc); gbc.gridx = 1; gbc.insets.right = 3; gbc.insets.left = 0; gbc.fill = GridBagConstraints.HORIZONTAL; searchPanel.add(searchField, gbc); gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 2; gbc.insets.left = 3; gbc.insets.top = 0; gbc.fill = GridBagConstraints.BOTH; searchPanel.add(scrollPane, gbc); popup.setBorder(BorderFactory.createLineBorder(UIUtils.getDefaultBorderColour())); popup.add(searchPanel); // when the window containing the "comp" has registered Esc key // then on pressing Esc instead of search popup getting closed // the event is sent to the window. to overcome this we // register an action for Esc. searchField.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { popup.setVisible(false); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED); }
From source file:org.fhaes.util.JTableSpreadsheetByRowAdapter.java
/** * The Excel Adapter is constructed with a JTable on which it enables Copy-Paste and acts as a Clipboard listener. *///from ww w .jav a2 s . co m public JTableSpreadsheetByRowAdapter(JTable myJTable) { mainTable = myJTable; KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false); // Identifying the copy KeyStroke user can modify this // to copy on some other Key combination. KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false); // KeyStroke pasteappend = // KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK,false); // Identifying the Paste KeyStroke user can modify this // to copy on some other Key combination. mainTable.registerKeyboardAction(this, "Copy", copy, JComponent.WHEN_FOCUSED); mainTable.registerKeyboardAction(this, "Paste", paste, JComponent.WHEN_FOCUSED); system = Toolkit.getDefaultToolkit().getSystemClipboard(); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the focus default for the specified button. * //from ww w.j a v a2s.c o m * @param button The button to handle. */ public static void enterPressesWhenFocused(JButton button) { if (button == null) return; button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED); button.registerKeyboardAction( button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED); }
From source file:org.piraso.ui.base.ContextMonitorTopComponent.java
private void initKeyboardActions() { Action findAction = new AbstractAction() { @Override/*from w w w . j a v a2 s. c o m*/ public void actionPerformed(ActionEvent e) { searcher.reset(); btnSearch.setSelected(!btnSearch.isSelected()); btnSearchActionPerformed(e); } }; Action nextAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { btnNextActionPerformed(e); } }; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.META_MASK); registerKeyboardAction(findAction, stroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); txtSearch.registerKeyboardAction(findAction, stroke, JComponent.WHEN_FOCUSED); stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); txtSearch.registerKeyboardAction(nextAction, stroke, JComponent.WHEN_FOCUSED); }
From source file:org.roche.antibody.ui.components.AntibodyEditorPane.java
private void configureKeyboardActions() { Graph2DViewActions keyboardActions = new Graph2DViewActions(abstractAntibodyView); ActionMap defaultActions = keyboardActions.createActionMap(); InputMap defaultInputMap = keyboardActions.createDefaultInputMap(defaultActions); defaultInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), Graph2DViewActions.DELETE_SELECTION); defaultActions.put(Graph2DViewActions.DELETE_SELECTION, new GraphDeleteAction()); abstractAntibodyView.getCanvasComponent().setActionMap(defaultActions); abstractAntibodyView.getCanvasComponent().setInputMap(JComponent.WHEN_FOCUSED, defaultInputMap); }
From source file:org.trianacode.gui.hci.ApplicationFrame.java
/** * Initialises the panels in the main window *//*www.ja va2 s.c o m*/ private void initLayout() { GUIEnv.setApplicationFrame(this); ColorManager.setDefaultColorModel(new TrianaColorModel()); ColorManager.registerColorModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptColorModel()); // do this after all other color loading ColorTable.instance().loadUserPrefs(); TaskGraphView defaultview = new TaskGraphView("Default View"); TrianaComponentModel compmodel = new TrianaComponentModel(tools, this, this); defaultview.setDefaultToolModel(compmodel); defaultview.setDefaultOpenGroupModel(compmodel); defaultview.registerToolModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptComponentModel()); defaultview.registerToolModel(TextToolConstants.TEXT_TOOL_RENDERING_HINT, new TextToolComponentModel()); defaultview.registerToolModel(HiddenToolConstants.HIDDEN_RENDERING_HINT, new HiddenComponentModel()); TaskGraphView mapview = new TaskGraphView("Map View", defaultview); mapview.registerOpenGroupModel(MapConstants.MAP_RENDERING_HINT, new MapComponentModel()); mapview.registerToolModel(MapConstants.MAP_LOCATION_RENDERING_HINT, new MapLocationComponentModel()); TaskGraphViewManager.setDefaultTaskGraphView(defaultview); TaskGraphViewManager.registerTaskGraphView(MapConstants.MAP_RENDERING_HINT, mapview); taskGraphFileHandler = new TaskGraphFileHandler(); trianaMenuBar = new TrianaMainMenu(this, tools); this.setJMenuBar(trianaMenuBar); TrianaShutdownHook shutDownHook = new TrianaShutdownHook(); Runtime.getRuntime().addShutdownHook(shutDownHook); getDesktopViewManager().addDesktopViewListener(this); this.workspace.add(getDesktopViewManager().getWorkspace(), BorderLayout.CENTER); ((TrianaMainMenu) trianaMenuBar).addHelp(); ToolTreeModel treemodel = new ToolTreeModel(tools); toolboxTree = new JTree(treemodel); toolboxTree.addFocusListener(this); toolboxTree.setCellRenderer(new TrianaTreeRenderer()); toolmonitor.setTree(toolboxTree); treemodel.addTreeModelListener(this); ToolTipManager.sharedInstance().registerComponent(toolboxTree); ToolTipManager.sharedInstance().setInitialDelay(TOOL_TIP_SHOW_DELAY); ToolTipManager.sharedInstance().setDismissDelay(TOOL_TIP_HIDE_DELAY); //set up key maps MainTrianaKeyMapFactory keymaps = new MainTrianaKeyMapFactory(this, ActionDisplayOptions.DISPLAY_NAME); InputMap inputMap = keymaps.getInputMap(); inputMap.setParent(this.getRootPane().getInputMap()); this.getRootPane().setInputMap(JComponent.WHEN_FOCUSED, inputMap); ActionMap actMap = keymaps.getActionMap(); actMap.setParent(this.getRootPane().getActionMap()); this.getRootPane().setActionMap(actMap); leaflistener = new LeafListener(toolboxTree, this, tools); keymaps = new MainTrianaKeyMapFactory(leaflistener, ActionDisplayOptions.DISPLAY_NAME); inputMap = keymaps.getInputMap(); inputMap.setParent(toolboxTree.getInputMap()); toolboxTree.setInputMap(JComponent.WHEN_FOCUSED, inputMap); actMap = keymaps.getActionMap(); actMap.setParent(toolboxTree.getActionMap()); toolboxTree.setActionMap(actMap); toolboxTree.addMouseListener(leaflistener); toolboxTree.addMouseMotionListener(leaflistener); //toolboxTree.setRootVisible(false); JPanel toolPanel = new JPanel(new BorderLayout()); SearchToolBar searchtoolbar = new SearchToolBar("Search", toolboxTree, treemodel); searchtoolbar.setFloatable(false); toolPanel.add(searchtoolbar, BorderLayout.NORTH); JScrollPane scroll = new JScrollPane(toolboxTree); toolPanel.add(scroll, BorderLayout.CENTER); JSplitPane verticalSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, toolPanel, workspace); TrianaToolBar toolbar = new TrianaToolBar("Main ToolBar", this); TrianaUnitToolBar unitToolbar = new TrianaUnitToolBar("Unit ToolBar"); toolbar.setRollover(true); unitToolbar.setRollover(true); JPanel innerpanel = new JPanel(); innerpanel.setLayout(new BoxLayout(innerpanel, BoxLayout.X_AXIS)); innerpanel.add(toolbar); innerpanel.add(Box.createHorizontalStrut(10)); innerpanel.add(unitToolbar); innerpanel.add(Box.createHorizontalGlue()); JPanel outerpanel = new JPanel(new BorderLayout()); outerpanel.add(innerpanel, BorderLayout.NORTH); outerpanel.add(verticalSplit, BorderLayout.CENTER); getContentPane().add(outerpanel); }