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:org.angnysa.yaba.swing.BudgetFrame.java
private void buildReconciliationTable() { reconciliationModel = new ReconciliationTableModel(service); reconciliationTable = new JTable(reconciliationModel); reconciliationTable.setRowHeight((int) (reconciliationTable.getRowHeight() * 1.2)); reconciliationTable.setDefaultEditor(LocalDate.class, new CustomCellEditor(new JFormattedTextField(new JodaLocalDateFormat()))); reconciliationTable.setDefaultEditor(Double.class, new CustomCellEditor(new JFormattedTextField(NumberFormat.getNumberInstance()))); reconciliationTable.setDefaultRenderer(LocalDate.class, new FormattedTableCellRenderer(new JodaLocalDateFormat())); reconciliationTable.setDefaultRenderer(Double.class, new FormattedTableCellRenderer(TransactionAmountFormatFactory.getFormat())); reconciliationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); reconciliationTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); //$NON-NLS-1$ reconciliationTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); //$NON-NLS-1$ reconciliationTable.getActionMap().put("delete", new AbstractAction() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override/*w w w . ja va 2 s. c o m*/ public void actionPerformed(ActionEvent e) { int row = reconciliationTable.getSelectedRow(); if (row >= 0) { reconciliationModel.deleteRow(row); } } }); transactionTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int row = transactionTable.getSelectedRow(); if (row >= 0) { row = transactionTable.getRowSorter().convertRowIndexToModel(row); TransactionDefinition td = transactionModel.getTransactionForRow(row); if (td != null) { reconciliationModel.setCurrentTransactionId(td.getId()); } else { reconciliationModel.setCurrentTransactionId(-1); } } else { reconciliationModel.setCurrentTransactionId(-1); } } } }); }
From source file:edu.ku.brc.ui.tmanfe.SearchReplacePanel.java
/** * sets up the keystroke mappings for "Ctrl-F" firing the find/replace panel * Escape making it disappear, and enter key firing a search *//*from w ww.j a v a 2 s . c o m*/ private void setupKeyStrokeMappings() { //table.getActionMap().clear(); //override the "Ctrl-F" function for launching the find dialog shipped with JXTable table.getInputMap().put( KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), UIRegistry.getResourceString(FIND)); table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK), UIRegistry.getResourceString(FIND)); //create action that will display the find/replace dialog launchFindAction = new LaunchFindAction(); table.getActionMap().put(FIND, launchFindAction); //Allow ESC buttun to call DisablePanelAction String CANCEL_KEY = "CANCELKEY"; // i18n //Allow ENTER button to SearchAction String ENTER_KEY = "ENTERKEY"; // i18n String REPLACE_KEY = "REPLACEKEY"; // i18n KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); InputMap textFieldInputMap = findField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); textFieldInputMap.put(enterKey, ENTER_KEY); textFieldInputMap.put(escapeKey, CANCEL_KEY); ActionMap textFieldActionMap = findField.getActionMap(); textFieldActionMap.put(ENTER_KEY, searchAction); textFieldActionMap.put(CANCEL_KEY, hideFindPanelAction); if (!table.isReadOnly()) { InputMap replaceFieldInputMap = replaceField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); replaceFieldInputMap.put(enterKey, REPLACE_KEY); replaceFieldInputMap.put(escapeKey, CANCEL_KEY); ActionMap replaceFieldActionMap = replaceField.getActionMap(); replaceFieldActionMap.put(REPLACE_KEY, replaceAction); replaceFieldActionMap.put(CANCEL_KEY, hideFindPanelAction); } }
From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java
private void createGUI() { setContentPane(contentPane);// ww w . ja va 2 s . c o m getRootPane().setDefaultButton(buttonOK); if (IS_WINDOWS_XP) { //for windows xp&server 2003 setIconImage(Toolkit.getDefaultToolkit() .getImage(UpdateDialog.class.getResource("/images/updaterIcon64_white.png"))); } else { setIconImage(Toolkit.getDefaultToolkit() .getImage(UpdateDialog.class.getResource("/images/updaterIcon64.png"))); } createDefaultActionListeners(); // call onCancel() when cross is clicked setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); addWindowListener(new WindowAdapter() { 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); updateInfoButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onUpdateInfoButton(); } }); updateInfoButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); manualDownloadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openSetupUrl(); } private void openSetupUrl() { log.debug("Calling to download setup manually"); URL url = null; if (updater != null) { if (updater.getAppVersion() != null) { try { log.debug("Trying to open [" + updater.getAppVersion().getDownloadUrl() + "]"); url = new URL(updater.getAppVersion().getDownloadUrl()); UrlValidator urlValidator = new UrlValidator(); UserUtils.openWebUrl(url); } catch (MalformedURLException e1) { openWebsite(url); } } else UserUtils.openWebUrl(ApplicationConstants.UPDATE_WEB_URL); } else UserUtils.openWebUrl(ApplicationConstants.UPDATE_WEB_URL); } private void openWebsite(URL url) { log.warn("Could not open setup url: [" + url + "]\n" + "Opening " + ApplicationConstants.UPDATE_WEB_URL); UserUtils.openWebUrl(ApplicationConstants.UPDATE_WEB_URL); } }); pack(); setLocation(FrameUtils.getFrameOnCenterLocationPoint(this)); setSize(new Dimension(400, 170)); setResizable(false); }
From source file:com.googlecode.vfsjfilechooser2.plaf.basic.BasicVFSFileChooserUI.java
protected void uninstallListeners(VFSJFileChooser fc) { if (propertyChangeListener != null) { fc.removePropertyChangeListener(propertyChangeListener); }//from w ww. j a va2 s . co m fc.removePropertyChangeListener(getModel()); SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); SwingUtilities.replaceUIActionMap(fc, null); }
From source file:com.brainflow.application.toplevel.Brainflow.java
private void initializeMenu() { log.info("initializing Menu"); GoToVoxelCommand gotoVoxelCommand = new GoToVoxelCommand(); gotoVoxelCommand.bind(getApplicationFrame()); gotoVoxelCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); CommandGroup fileMenuGroup = new CommandGroup("file-menu"); fileMenuGroup.bind(getApplicationFrame()); CommandGroup viewMenuGroup = new CommandGroup("view-menu"); viewMenuGroup.bind(getApplicationFrame()); CommandGroup gotoMenuGroup = new CommandGroup("goto-menu"); gotoMenuGroup.bind(getApplicationFrame()); CommandBar menuBar = new CommandMenuBar(); menuBar.setStretch(true);/*from ww w. j a va 2 s . c om*/ menuBar.setPaintBackground(false); //JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenuGroup.createMenuItem()); menuBar.add(viewMenuGroup.createMenuItem()); menuBar.add(gotoMenuGroup.createMenuItem()); brainFrame.setJMenuBar(menuBar); MountFileSystemCommand mountFileSystemCommand = new MountFileSystemCommand(); mountFileSystemCommand.bind(getApplicationFrame()); ExitApplicationCommand exitCommand = new ExitApplicationCommand(); exitCommand.bind(getApplicationFrame()); ExpansionPointBuilder builder = fileMenuGroup.getExpansionPointBuilder(); builder.add(pathMenu.getCommandGroup()); builder.applyChanges(); brainFrame.getJMenuBar().add(DockWindowManager.getInstance().getDockMenu()); }
From source file:de.tor.tribes.ui.views.DSWorkbenchFarmManager.java
/** * Creates new form DSWorkbenchFarmManager *///w ww. j a va 2 s . c o m DSWorkbenchFarmManager() { initComponents(); centerPanel = new GenericTestPanel(); jCenterPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jFarmPanel); buildMenu(); jFarmTable.setModel(new FarmTableModel()); jFarmTable.getTableHeader().setDefaultRenderer(new de.tor.tribes.ui.renderer.DefaultTableHeaderRenderer()); ColorHighlighter p = new ColorHighlighter(new FarmPredicate(FarmPredicate.PType.BARBARIAN)); p.setBackground(Color.LIGHT_GRAY); ColorHighlighter p1 = new ColorHighlighter(new FarmPredicate(FarmPredicate.PType.PLAYER)); p1.setBackground(new Color(0xffffcc)); jFarmTable.setHighlighters( HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B), p, p1); jFarmTable.setDefaultRenderer(Boolean.class, new CustomBooleanRenderer(CustomBooleanRenderer.LayoutStyle.RES_IN_STORAGE)); jFarmTable.setDefaultRenderer(Date.class, new de.tor.tribes.ui.renderer.DateCellRenderer()); jFarmTable.setDefaultRenderer(Float.class, new de.tor.tribes.ui.renderer.PercentCellRenderer()); jFarmTable.setDefaultRenderer(FarmInformation.FARM_STATUS.class, new EnumImageCellRenderer(EnumImageCellRenderer.LayoutStyle.FarmStatus)); jFarmTable.setDefaultRenderer(FarmInformation.FARM_RESULT.class, new EnumImageCellRenderer(EnumImageCellRenderer.LayoutStyle.FarmResult)); jFarmTable.setDefaultRenderer(StorageStatus.class, new de.tor.tribes.ui.renderer.StorageCellRenderer()); jFarmTable.setDefaultRenderer(FarmInformation.SIEGE_STATUS.class, new EnumImageCellRenderer(EnumImageCellRenderer.LayoutStyle.SiegeStatus)); jFarmTable.setColumnControlVisible(true); jFarmTable.setSortsOnUpdates(false); FarmManager.getSingleton().addManagerListener(DSWorkbenchFarmManager.this); settingsPanel.setLayout(new BorderLayout()); settingsPanel.add(jSettingsPanel, BorderLayout.CENTER); new Timer("FarmTableUpdate").schedule(new TimerTask() { @Override public void run() { jFarmTable.repaint(); } }, new Date(), 1000); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); KeyStroke farmA = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false); KeyStroke farmB = KeyStroke.getKeyStroke(KeyEvent.VK_B, 0, false); KeyStroke farmK = KeyStroke.getKeyStroke(KeyEvent.VK_K, 0, false); KeyStroke farmC = KeyStroke.getKeyStroke(KeyEvent.VK_C, 0, false); ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteSelection(); } }; capabilityInfoPanel1.addActionListener(listener); jFarmTable.setSortsOnUpdates(false); jFarmTable.registerKeyboardAction(listener, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jFarmTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { farmA(); } }, "FarmA", farmA, JComponent.WHEN_IN_FOCUSED_WINDOW); jFarmTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { farmB(); } }, "FarmB", farmB, JComponent.WHEN_IN_FOCUSED_WINDOW); jFarmTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { farmK(); } }, "FarmK", farmK, JComponent.WHEN_IN_FOCUSED_WINDOW); jFarmTable.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { farmC(); } }, "FarmC", farmC, JComponent.WHEN_IN_FOCUSED_WINDOW); aTroops = new TroopSelectionPanelDynamic(); aTroops.setupFarm(TroopSelectionPanel.alignType.GROUPED, -1); bTroops = new TroopSelectionPanelDynamic(); bTroops.setupFarm(TroopSelectionPanel.alignType.GROUPED, -1); kTroops = new TroopSelectionPanelDynamic(); kTroops.setupFarm(TroopSelectionPanel.alignType.GROUPED, -1); cTroops = new TroopSelectionPanelDynamic(); cTroops.setupFarm(TroopSelectionPanel.alignType.GROUPED, -1); rTroops = new TroopSelectionPanelDynamic(); rTroops.setupFarm(TroopSelectionPanel.alignType.GROUPED, -1); jATroopsPanel.add(aTroops, BorderLayout.CENTER); jBTroopsPanel.add(bTroops, BorderLayout.CENTER); jKTroopsPanel.add(kTroops, BorderLayout.CENTER); jCTroopsPanel.add(cTroops, BorderLayout.CENTER); jRSettingsTab.add(rTroops, BorderLayout.CENTER); jXLabel1.setLineWrap(true); jFarmTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { showInfo(jFarmTable.getSelectedRowCount() + " Farm(en) gewhlt"); } }); coordSpinner = new CoordinateSpinner(); coordSpinner.setEnabled(false); java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jFarmFromBarbarianSelectionDialog.getContentPane().add(coordSpinner, gridBagConstraints); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "farmManager", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> }
From source file:eu.europeana.sip.gui.SipCreatorGUI.java
private JPanel createFinishedPanel() { JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); Action finishedAction = new FinishedAction(this); ((JComponent) getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke("ESCAPE"), "finished"); ((JComponent) getContentPane()).getActionMap().put("finished", finishedAction); JButton hide = new JButton(finishedAction); panel.add(hide);/*from w ww . ja v a 2 s.c o m*/ return panel; }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Adds an action to hide a window / dialog. * * On OSX, this is done by typing 'Command-W'. * On all other platforms, this is done by hitting 'ESC'. *///from w ww . j a v a 2 s. c o m public static void addHideAction(JComponent jc) { InputMap map = jc.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); map.put(getHideKeystroke(), "limewire.hideWindow"); jc.getActionMap().put("limewire.hideWindow", getDisposeAction()); }
From source file:javazoom.jlgui.player.amp.StandalonePlayer.java
/** * Set keyboard key shortcut for the whole player. * @param id/*from ww w. j a v a 2s . com*/ * @param key * @param action */ public void setKeyboardAction(String id, KeyStroke key, Action action) { mp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, id); mp.getActionMap().put(id, action); mp.getPlaylistUI().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(key, id); mp.getPlaylistUI().getActionMap().put(id, action); mp.getEqualizerUI().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(key, id); mp.getEqualizerUI().getActionMap().put(id, action); }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
public void setCustomEditorControls(boolean enabled) { if (enabled) { // An action to toggle cell editing with the 'Enter' key. Action toggleEditing = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (isEditing()) { getCellEditor().stopCellEditing(); } else { boolean success = editCellAt(getSelectedRow(), getSelectedColumn(), e); if (success) { // Request focus for TextFieldCellEditors if (getCellEditor() instanceof TextFieldCellEditor) { ((TextFieldCellEditor) getCellEditor()).getTextField().requestFocusInWindow(); }/*www .ja v a 2 s . co m*/ } } } }; /* * Don't edit cells on any keystroke. Let the toggleEditing action handle it for 'Enter' * only. Also surrender focus to any activated editor. */ setAutoStartEditOnKeyStroke(false); setSurrendersFocusOnKeystroke(true); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "toggleEditing"); getActionMap().put("toggleEditing", toggleEditing); } else { setAutoStartEditOnKeyStroke(true); setSurrendersFocusOnKeystroke(false); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "selectNextRowCell"); } }