List of usage examples for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
To view the source code for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component. From source file:Main.java
/** * Registers the keystroke of the given action as "command" of the given * component./*from w w w .jav a 2s. co m*/ * <p> * This code is based on the Sulky-tools, found at * <http://github.com/huxi/sulky>. * </p> * * @param aComponent * the component that should react on the keystroke, cannot be * <code>null</code>; * @param aAction * the action of the keystroke, cannot be <code>null</code>; * @param aCommandName * the name of the command to register the keystore under. */ public static void registerKeystroke(final JComponent aComponent, final Action aAction, final String aCommandName) { final KeyStroke keyStroke = (KeyStroke) aAction.getValue(Action.ACCELERATOR_KEY); if (keyStroke == null) { return; } InputMap inputMap = aComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = aComponent.getActionMap(); inputMap.put(keyStroke, aCommandName); actionMap.put(aCommandName, aAction); inputMap = aComponent.getInputMap(JComponent.WHEN_FOCUSED); Object value = inputMap.get(keyStroke); if (value != null) { inputMap.put(keyStroke, aCommandName); } inputMap = aComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); value = inputMap.get(keyStroke); if (value != null) { inputMap.put(keyStroke, aCommandName); } }
From source file:com.github.alexfalappa.nbspringboot.codegen.SpringDependencyDialog.java
/** Creates new form NewOkCancelDialog */ public SpringDependencyDialog(java.awt.Frame parent) { super(parent, true); initComponents();//from w ww.jav a 2s . c om // Close the dialog when Esc is pressed String cancelName = "cancel"; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = rootPane.getActionMap(); actionMap.put(cancelName, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } }); }
From source file:ActionTest.java
public ActionFrame() { setTitle("ActionTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); buttonPanel = new JPanel(); // define actions Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW); Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED); // add buttons for these actions buttonPanel.add(new JButton(yellowAction)); buttonPanel.add(new JButton(blueAction)); buttonPanel.add(new JButton(redAction)); // add panel to frame add(buttonPanel);/*from ww w . j a v a2 s . com*/ // associate the Y, B, and R keys with names InputMap imap = buttonPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow"); imap.put(KeyStroke.getKeyStroke("ctrl B"), "panel.blue"); imap.put(KeyStroke.getKeyStroke("ctrl R"), "panel.red"); // associate the names with actions ActionMap amap = buttonPanel.getActionMap(); amap.put("panel.yellow", yellowAction); amap.put("panel.blue", blueAction); amap.put("panel.red", redAction); }
From source file:net.pandoragames.far.ui.swing.dialog.SubWindow.java
/** * Registers Ctrl + w as a window close event on the specified component; * /*from w w w . ja v a 2 s . co m*/ * @param component to becomce receptive for ctrl + w */ protected void registerCloseWindowKeyListener(JComponent component) { component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK), "windowCloseAction"); component.getActionMap().put("windowCloseAction", windowCloseAction); }
From source file:net.java.sip.communicator.plugin.propertieseditor.SearchField.java
/** * Creates an instance <tt>SearchField</tt>. * /*from w ww . j a v a 2 s .c o m*/ * @param text the text we would like to enter by default * @param sorter the sorter which will be used for filtering. */ public SearchField(String text, JTable table) { super(text); this.table = table; ComponentUI ui = getUI(); if (ui instanceof SearchFieldUI) { SearchFieldUI searchFieldUI = (SearchFieldUI) ui; searchFieldUI.setCallButtonEnabled(false); searchFieldUI.setDeleteButtonEnabled(true); } setBorder(null); setDragEnabled(true); setOpaque(false); setPreferredSize(new Dimension(100, 25)); InputMap imap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); ActionMap amap = getActionMap(); @SuppressWarnings("serial") AbstractAction escapeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { setText(""); } }; amap.put("escape", escapeAction); getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { } public void insertUpdate(DocumentEvent e) { filter(getText()); } public void removeUpdate(DocumentEvent e) { filter(getText()); } }); loadSkin(); }
From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java
public InputWindow(PsiClass mClass) { this.mClass = mClass; project = mClass.getProject();// w w w. j av a 2 s . c o m mFile = mClass.getContainingFile(); setContentPane(contentPane); inputFeedText.getRootPane().setSize(750, 400); setSize(1000, 600); setTitle("Generate DTO"); getRootPane().setDefaultButton(buttonOk); initButtons(); initListeners(); setDefaultConditions(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); contentPane.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
From source file:fxts.stations.util.preferences.PreferencesSheetPanel.java
/** * Constructor PreferencesSheetPanel./*from w ww . j a va 2 s.com*/ * * @param aUserName parent dialog included this panel. */ public PreferencesSheetPanel(String aUserName) { mUserName = aUserName; try { mResMan = ResourceManager.getManager("fxts.stations.util.preferences.resources.Resources"); } catch (Exception e) { mLogger.error("The fatal error"); e.printStackTrace(); } mResMan.addLocaleListener(this); //Define table mTableModel = new PrefTableModel(); mTable = new AAJTable(mTableModel); mTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); PreferencesTableCellRenderer renderer = new PreferencesTableCellRenderer(); mTable.setDefaultRenderer(AValueEditorPanel.class, renderer); mEditor = new PreferencesTableCellEditor(); mTable.setDefaultEditor(AValueEditorPanel.class, mEditor); //Do not change columns order mTable.getTableHeader().setReorderingAllowed(false); //Assign exterior a table mTable.setBorder(new EtchedBorder()); //Prepare to used Escape key mDefaultEditingCancelAction = SwingUtilities.getUIActionMap(mTable).get("cancel"); AbstractAction exitAction = new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { if (mEditor.isEditing()) { mEditor.cancelCellEditing(); if (mDefaultEditingCancelAction != null) { mDefaultEditingCancelAction.actionPerformed(aEvent); } } else { mDefaultExitAction.actionPerformed(aEvent); } } }; KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); mTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, "ExitAction"); SwingUtilities.getUIActionMap(mTable).put("ExitAction", exitAction); super.setViewportView(mTable); }
From source file:de.tor.tribes.ui.views.DSWorkbenchChurchFrame.java
/** * Creates new form DSWorkbenchChurchFrame *///from w ww .jav a 2 s . c o m DSWorkbenchChurchFrame() { initComponents(); centerPanel = new GenericTestPanel(); jChurchPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jXPanel1); buildMenu(); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if ("Delete".equals(e.getActionCommand())) { deleteSelection(); } else if ("BBCopy".equals(e.getActionCommand())) { bbCopySelection(); } } }; capabilityInfoPanel1.addActionListener(listener); jChurchTable.registerKeyboardAction(listener, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jChurchTable.registerKeyboardAction(listener, "BBCopy", bbCopy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jChurchFrameAlwaysOnTop.setSelected(GlobalOptions.getProperties().getBoolean("church.frame.alwaysOnTop")); setAlwaysOnTop(jChurchFrameAlwaysOnTop.isSelected()); jChurchTable.setModel(new ChurchTableModel()); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.church_view", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> jChurchTable.getSelectionModel().addListSelectionListener(DSWorkbenchChurchFrame.this); pack(); }
From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java
private void initGui(String pathToEditingFile) { setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon96.png"))); this.path = pathToEditingFile; setContentPane(contentPane);// w w w . ja va 2 s . c o m getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); // call onCancel() when cross is clicked setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { if (textField.getText().isEmpty()) { fillTextFieldWithClipboard(); } super.windowActivated(e); } @Override public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); createWeblocFileTextPane.setBackground(new Color(232, 232, 232)); initTextField(pathToEditingFile); pack(); /*setMinimumSize(getSize()); setPreferredSize(getSize());*/ setSize(DEFAULT_APPLICATION_WIDTH, 200); setResizable(false); //TODO fix setMaximumSize setLocation(FrameUtils.getFrameOnCenterLocationPoint(this)); }
From source file:de.tor.tribes.ui.views.DSWorkbenchWatchtowerFrame.java
/** * Creates new form DSWorkbenchWatchtowerFrame *//*from ww w .ja v a 2 s.c o m*/ DSWorkbenchWatchtowerFrame() { initComponents(); centerPanel = new GenericTestPanel(); jWatchtowerPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jXPanel1); buildMenu(); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if ("Delete".equals(e.getActionCommand())) { deleteSelection(); } else if ("BBCopy".equals(e.getActionCommand())) { bbCopySelection(); } } }; capabilityInfoPanel1.addActionListener(listener); jWatchtowerTable.registerKeyboardAction(listener, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jWatchtowerTable.registerKeyboardAction(listener, "BBCopy", bbCopy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jWatchtowerFrameAlwaysOnTop .setSelected(GlobalOptions.getProperties().getBoolean("watchtower.frame.alwaysOnTop")); setAlwaysOnTop(jWatchtowerFrameAlwaysOnTop.isSelected()); jWatchtowerTable.setModel(new WatchtowerTableModel()); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { //TODO create help page GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.church_view", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> jWatchtowerTable.getSelectionModel().addListSelectionListener(DSWorkbenchWatchtowerFrame.this); pack(); }