List of usage examples for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW
int WHEN_IN_FOCUSED_WINDOW
To view the source code for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component. From source file:org.jdal.swing.table.TablePanel.java
/** * Initialize TablePanel after property set. Usally called by container. *//*w w w .j a v a 2 s. co m*/ public void init() { // Header this.add(createFilterBox(), BorderLayout.NORTH); this.add(createTableBox(), BorderLayout.CENTER); if (filterView != null) table.setFilter(filterView.getModel()); if (guiFactory != null) table.setGuiFactory(guiFactory); // Key Bindings getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F2"), "addAction"); getActionMap().put("addAction", new AddAction()); }
From source file:TextFieldDemo.java
public TextFieldDemo() { initComponents();//from w w w . ja va 2 s . c o m InputStream in = getClass().getResourceAsStream("content.txt"); try { textArea.read(new InputStreamReader(in), null); } catch (IOException e) { e.printStackTrace(); } hilit = new DefaultHighlighter(); painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR); textArea.setHighlighter(hilit); entryBg = entry.getBackground(); entry.getDocument().addDocumentListener(this); InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = entry.getActionMap(); im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION); am.put(CANCEL_ACTION, new CancelAction()); }
From source file:eu.lp0.cursus.ui.AboutDialog.java
private void initialise() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$ DefaultUnitConverter duc = DefaultUnitConverter.getInstance(); FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$ "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$ getContentPane().setLayout(layout);//ww w. j ava 2 s . c om JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$ getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$ getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$ JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$ JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$ txtCopying.setFont(Font.decode(Font.MONOSPACED)); txtCopying.setEditable(false); scrCopying.setViewportView(txtCopying); scrCopying.setPreferredSize( new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying))); Action actClose = new CloseDialogAction(this); JButton btnClose = new JButton(actClose); getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$ getRootPane().setDefaultButton(btnClose); getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName()); getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose); pack(); setMinimumSize(getSize()); setSize(getSize().width, getSize().height * 3 / 2); btnClose.requestFocusInWindow(); }
From source file:net.sf.keystore_explorer.gui.dialogs.DCheckUpdate.java
private void initComponents() { jlCheckUpdate = new JLabel(res.getString("DCheckUpdate.jlCheckUpdate.text")); ImageIcon icon = new ImageIcon(getClass().getResource(res.getString("DCheckUpdate.jlCheckUpdate.image"))); jlCheckUpdate.setIcon(icon);// w w w .j a v a 2 s . co m jlCheckUpdate.setHorizontalTextPosition(SwingConstants.LEADING); jlCheckUpdate.setIconTextGap(15); jpCheckUpdate = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpCheckUpdate.add(jlCheckUpdate); jpCheckUpdate.setBorder(new EmptyBorder(5, 5, 5, 5)); jpbCheckUpdate = new JProgressBar(); jpbCheckUpdate.setIndeterminate(true); jpbCheckUpdate.setString("DCheckUpdate.jlCheckUpdate.text"); jpProgress = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpProgress.add(jpbCheckUpdate); jpProgress.setBorder(new EmptyBorder(5, 5, 5, 5)); jbCancel = new JButton(res.getString("DCheckUpdate.jbCancel.text")); jbCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { cancelPressed(); } }); jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY); jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() { @Override public void actionPerformed(ActionEvent evt) { cancelPressed(); } }); jpCancel = PlatformUtil.createDialogButtonPanel(jbCancel, false); getContentPane().add(jpCheckUpdate, BorderLayout.NORTH); getContentPane().add(jpProgress, BorderLayout.CENTER); getContentPane().add(jpCancel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { if ((checker != null) && (checker.isAlive())) { checker.interrupt(); } closeDialog(); } }); setTitle(res.getString("DCheckUpdate.Title")); setResizable(false); pack(); }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Creates Action objects and initializes Input and Action mappings *//*from w w w .j a va 2 s. co m*/ private void initActions() { JRootPane rp = getRootPane(); ActionMap am = rp.getActionMap(); InputMap im = rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); am.put(DeleteAction.class, deleteAction); am.put(CloneAction.class, cloneAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DeleteAction.class); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), CloneAction.class); }
From source file:com.github.alexfalappa.nbspringboot.projects.customizer.CfgPropsDialog.java
/** Creates new form CfgPropsDialog */ public CfgPropsDialog(java.awt.Dialog parent) { super(parent, true); initComponents();/*from w w w. ja va2 s .c o m*/ // retrieve some flads from prefs final Preferences prefs = NbPreferences.forModule(PrefConstants.class); final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true); bDeprErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, false); // setup props sorting this.sortedProps = new TreeSet<>(new ConfigurationMetadataComparator(bDeprLast)); // setup property list lCfgProps.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final ConfigurationMetadataProperty selectedValue = lCfgProps.getSelectedValue(); if (selectedValue != null) { tpDetails.setText(Utils.cfgPropDetailsHtml(selectedValue)); tpDetails.setCaretPosition(0); } } } }); // set default button rootPane.setDefaultButton(bOk); // close dialog with ESC key final ActionListener escAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { CfgPropsDialog.this.setVisible(false); } }; rootPane.registerKeyboardAction(escAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:net.sf.jabref.openoffice.CitationManager.java
public CitationManager(final JabRefFrame frame, OOBibBase ooBase) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { diag = new JDialog(frame, Localization.lang("Manage citations"), true); this.ooBase = ooBase; list = new BasicEventList<>(); XNameAccess nameAccess = ooBase.getReferenceMarks(); java.util.List<String> names = ooBase.getJabRefReferenceMarks(nameAccess); for (String name : names) { list.add(new CitEntry(name, "<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>", ooBase.getCustomProperty(name))); }//from w ww . j av a 2 s . c o m tableModel = new DefaultEventTableModel<>(list, new CitEntryFormat()); table = new JTable(tableModel); diag.add(new JScrollPane(table), BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton ok = new JButton(Localization.lang("OK")); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.add(bb.getPanel(), BorderLayout.SOUTH); diag.pack(); diag.setSize(700, 400); ok.addActionListener(e -> { try { storeSettings(); } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException | IllegalArgumentException ex) { LOGGER.warn("Problem modifying citation", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation")); } diag.dispose(); }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { diag.dispose(); } }; cancel.addActionListener(cancelAction); bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); bb.getPanel().getActionMap().put("close", cancelAction); table.getColumnModel().getColumn(0).setPreferredWidth(600); table.getColumnModel().getColumn(1).setPreferredWidth(90); table.setPreferredScrollableViewportSize(new Dimension(700, 500)); table.addMouseListener(new TableClickListener()); }
From source file:org.pgptool.gui.ui.keyslist.KeysTableView.java
@SuppressWarnings("serial") private void initTableKeyListener() { int condition = JComponent.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = table.getInputMap(condition); ActionMap actionMap = table.getActionMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE); actionMap.put(DELETE, new AbstractAction() { @Override// ww w .j av a 2s .com public void actionPerformed(ActionEvent e) { if (pm == null) { return; } safePerformAction(pm.getActionDelete(), null); } }); }
From source file:net.sf.jabref.gui.openoffice.CitationManager.java
public CitationManager(final JabRefFrame frame, OOBibBase ooBase) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { diag = new JDialog(frame, Localization.lang("Manage citations"), true); this.ooBase = ooBase; list = new BasicEventList<>(); XNameAccess nameAccess = ooBase.getReferenceMarks(); List<String> names = ooBase.getJabRefReferenceMarks(nameAccess); for (String name : names) { list.add(new CitationEntry(name, "<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>", ooBase.getCustomProperty(name))); }/* w ww . jav a2 s . co m*/ tableModel = new DefaultEventTableModel<>(list, new CitationEntryFormat()); table = new JTable(tableModel); diag.add(new JScrollPane(table), BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton ok = new JButton(Localization.lang("OK")); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.add(bb.getPanel(), BorderLayout.SOUTH); diag.pack(); diag.setSize(700, 400); ok.addActionListener(e -> { try { storeSettings(); } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException | IllegalArgumentException ex) { LOGGER.warn("Problem modifying citation", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation")); } diag.dispose(); }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { diag.dispose(); } }; cancel.addActionListener(cancelAction); bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); bb.getPanel().getActionMap().put("close", cancelAction); table.getColumnModel().getColumn(0).setPreferredWidth(580); table.getColumnModel().getColumn(1).setPreferredWidth(110); table.setPreferredScrollableViewportSize(new Dimension(700, 500)); table.addMouseListener(new TableClickListener()); }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
DSWorkbenchStatsFrame() { initComponents();/* w w w . j av a 2 s . c o m*/ centerPanel = new GenericTestPanel(); jStatsPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jMainStatPanel); buildMenu(); capabilityInfoPanel1.addActionListener(this); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); jTabbedPane1.registerKeyboardAction(DSWorkbenchStatsFrame.this, "BBCopy", bbCopy, JComponent.WHEN_IN_FOCUSED_WINDOW); jTribeList.registerKeyboardAction(DSWorkbenchStatsFrame.this, "Delete", delete, JComponent.WHEN_IN_FOCUSED_WINDOW); jAlwaysOnTopBox.setSelected(GlobalOptions.getProperties().getBoolean("stats.frame.alwaysOnTop")); setAlwaysOnTop(jAlwaysOnTopBox.isSelected()); jAllyList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { List allySelection = jAllyList.getSelectedValuesList(); jTribeList.clearSelection(); List<Tribe> tribes = new LinkedList<>(); for (Object o : allySelection) { Tribe[] tribesForAlly = StatManager.getSingleton().getMonitoredTribes((Ally) o); for (Tribe t : tribesForAlly) { if (!tribes.contains(t)) { tribes.add(t); } } Collections.sort(tribes); DefaultListModel<Tribe> model = new DefaultListModel<>(); for (Tribe t : tribes) { model.addElement(t); } jTribeList.setModel(model); } } }); jTribeList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { fireUpdateChartEvent(null); } }); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); jStartDate.setDate(c.getTime()); jEndDate.setDate(c.getTime()); jStatCreatePanel.setVisible(false); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.stats_view", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> pack(); }