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:net.sf.jabref.importer.ImportCustomizationDialog.java
/** * * @param frame// w w w. j av a2 s . c o m */ public ImportCustomizationDialog(final JabRefFrame frame) { super(frame, Localization.lang("Manage custom imports"), false); ImportTableModel tableModel = new ImportTableModel(); customImporterTable = new JTable(tableModel); TableColumnModel cm = customImporterTable.getColumnModel(); cm.getColumn(0).setPreferredWidth(COL_0_WIDTH); cm.getColumn(1).setPreferredWidth(COL_1_WIDTH); cm.getColumn(2).setPreferredWidth(COL_2_WIDTH); cm.getColumn(3).setPreferredWidth(COL_3_WIDTH); JScrollPane sp = new JScrollPane(customImporterTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); customImporterTable.setPreferredScrollableViewportSize(getSize()); if (customImporterTable.getRowCount() > 0) { customImporterTable.setRowSelectionInterval(0, 0); } JButton addFromFolderButton = new JButton(Localization.lang("Add from folder")); addFromFolderButton.addActionListener(e -> { CustomImporter importer = new CustomImporter(); importer.setBasePath(FileDialogs.getNewDir(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Collections.emptyList(), Localization.lang("Select Classpath of New Importer"), JFileChooser.CUSTOM_DIALOG, false)); String chosenFileStr = null; if (importer.getBasePath() != null) { chosenFileStr = FileDialogs.getNewFile(frame, importer.getFileFromBasePath(), Collections.singletonList(".class"), Localization.lang("Select new ImportFormat subclass"), JFileChooser.CUSTOM_DIALOG, false); } if (chosenFileStr != null) { try { importer.setClassName(pathToClass(importer.getFileFromBasePath(), new File(chosenFileStr))); importer.setName(importer.getInstance().getFormatName()); importer.setCliId(importer.getInstance().getId()); addOrReplaceImporter(importer); customImporterTable.revalidate(); customImporterTable.repaint(); } catch (Exception exc) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", chosenFileStr)); } catch (NoClassDefFoundError exc) { JOptionPane.showMessageDialog(frame, Localization.lang( "Could not instantiate %0. Have you chosen the correct package path?", chosenFileStr)); } } }); addFromFolderButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a class path.") + "\n" + Localization.lang("The path need not be on the classpath of JabRef.")); JButton addFromJarButton = new JButton(Localization.lang("Add from jar")); addFromJarButton.addActionListener(e -> { String basePath = FileDialogs.getNewFile(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Arrays.asList(".zip", ".jar"), Localization.lang("Select a Zip-archive"), JFileChooser.CUSTOM_DIALOG, false); if (basePath != null) { try (ZipFile zipFile = new ZipFile(new File(basePath), ZipFile.OPEN_READ)) { ZipFileChooser zipFileChooser = new ZipFileChooser(this, zipFile); zipFileChooser.setVisible(true); customImporterTable.revalidate(); customImporterTable.repaint(10); } catch (IOException exc) { LOGGER.info("Could not open Zip-archive.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not open %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } catch (NoClassDefFoundError exc) { LOGGER.info("Could not instantiate Zip-archive reader.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } } }); addFromJarButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a Zip-archive.") + "\n" + Localization.lang("The Zip-archive need not be on the classpath of JabRef.")); JButton showDescButton = new JButton(Localization.lang("Show description")); showDescButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { CustomImporter importer = ((ImportTableModel) customImporterTable.getModel()).getImporter(row); try { ImportFormat importFormat = importer.getInstance(); JOptionPane.showMessageDialog(frame, importFormat.getDescription()); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException exc) { LOGGER.warn("Could not instantiate importer " + importer.getName(), exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0 %1", importer.getName() + ":\n", exc.getMessage())); } } }); JButton removeButton = new JButton(Localization.lang("Remove")); removeButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { customImporterTable.removeRowSelectionInterval(row, row); Globals.prefs.customImports .remove(((ImportTableModel) customImporterTable.getModel()).getImporter(row)); Globals.IMPORT_FORMAT_READER.resetImportFormats(); customImporterTable.revalidate(); customImporterTable.repaint(); } }); Action closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; JButton closeButton = new JButton(Localization.lang("Close")); closeButton.addActionListener(closeAction); JButton helpButton = new HelpAction(HelpFile.CUSTOM_IMPORTS).getHelpButton(); // Key bindings: JPanel mainPanel = new JPanel(); ActionMap am = mainPanel.getActionMap(); InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); mainPanel.setLayout(new BorderLayout()); mainPanel.add(sp, BorderLayout.CENTER); JPanel buttons = new JPanel(); ButtonBarBuilder bb = new ButtonBarBuilder(buttons); buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); bb.addGlue(); bb.addButton(addFromFolderButton); bb.addButton(addFromJarButton); bb.addButton(showDescButton); bb.addButton(removeButton); bb.addButton(closeButton); bb.addUnrelatedGap(); bb.addButton(helpButton); bb.addGlue(); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(buttons, BorderLayout.SOUTH); this.setSize(getSize()); pack(); this.setLocationRelativeTo(frame); new FocusRequester(customImporterTable); }
From source file:org.pgptool.gui.ui.mainframe.MainFrameView.java
@SuppressWarnings("serial") private void initTableKeyListener() { InputMap inputMap = table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE); table.getActionMap().put(DELETE, new AbstractAction() { @Override//from w ww . ja v a 2s . c om public void actionPerformed(ActionEvent e) { if (pm == null) { return; } pm.actionDelete.actionPerformed(e); } }); InputMap inputMap2 = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), CHOOSE); table.getActionMap().put(CHOOSE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (pm == null) { return; } pm.actionOpen.actionPerformed(e); } }); }
From source file:net.sf.jabref.gui.journals.ManageJournalsPanel.java
public ManageJournalsPanel(final JabRefFrame frame) { this.frame = frame; personalFile.setEditable(false);/*from w w w . j ava2 s.com*/ ButtonGroup group = new ButtonGroup(); group.add(newFile); group.add(oldFile); addExtPan.setLayout(new BorderLayout()); JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon()); addExtPan.add(addExt, BorderLayout.EAST); addExtPan.setToolTipText(Localization.lang("Add")); FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); FormBuilder builder = FormBuilder.create().layout(layout); builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6); JLabel description = new JLabel( "<HTML>" + Localization.lang("JabRef includes a built-in list of journal abbreviations.") + "<br>" + Localization.lang( "You can add additional journal names by setting up a personal journal list,<br>as " + "well as linking to external journal lists.") + "</HTML>"); description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); builder.add(description).xyw(2, 2, 6); JButton viewBuiltin = new JButton(Localization.lang("View")); builder.add(viewBuiltin).xy(7, 2); builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6); builder.add(newFile).xy(3, 4); builder.add(newNameTf).xy(5, 4); JButton browseNew = new JButton(Localization.lang("Browse")); builder.add(browseNew).xy(7, 4); builder.add(oldFile).xy(3, 5); builder.add(personalFile).xy(5, 5); JButton browseOld = new JButton(Localization.lang("Browse")); builder.add(browseOld).xy(7, 5); userPanel.setLayout(new BorderLayout()); builder.add(userPanel).xyw(2, 6, 4); ButtonStackBuilder butBul = new ButtonStackBuilder(); butBul.addButton(add); butBul.addButton(remove); butBul.addGlue(); builder.add(butBul.getPanel()).xy(7, 6); builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6); externalFilesPanel.setLayout(new BorderLayout()); setLayout(new BorderLayout()); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(builder.getPanel(), BorderLayout.NORTH); add(externalFilesPanel, 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.addUnrelatedGap(); JButton help = new HelpAction(HelpFile.JOURNAL_ABBREV).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Set up panel for editing a single journal, to be used in a dialog box: FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p"); FormBuilder builder2 = FormBuilder.create().layout(layout2); builder2.add(Localization.lang("Journal name")).xy(1, 1); builder2.add(nameTf).xy(3, 1); builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3); builder2.add(abbrTf).xy(3, 3); journalEditPanel = builder2.getPanel(); viewBuiltin.addActionListener(e -> { JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(Globals.journalAbbreviationLoader .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) .getAbbreviations())); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); }); browseNew.addActionListener(e -> { Path old = null; if (!newNameTf.getText().isEmpty()) { old = Paths.get(newNameTf.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.SAVE_DIALOG, false); if (name != null) { newNameTf.setText(name); newFile.setSelected(true); } }); browseOld.addActionListener(e -> { Path old = null; if (!personalFile.getText().isEmpty()) { old = Paths.get(personalFile.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.OPEN_DIALOG, false); if (name != null) { personalFile.setText(name); oldFile.setSelected(true); oldFile.setEnabled(true); setupUserTable(); } }); ok.addActionListener(e -> { if (readyToClose()) { storeSettings(); dialog.dispose(); } }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); add.addActionListener(tableModel); remove.addActionListener(tableModel); addExt.addActionListener(e -> { externals.add(new ExternalFileEntry()); buildExternalsPanel(); }); // Key bindings: ActionMap am = getActionMap(); InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); int xSize = getPreferredSize().width; dialog.setSize(xSize + 10, 700); }
From source file:de.tor.tribes.ui.views.DSWorkbenchFarmManager.java
/** * Creates new form DSWorkbenchFarmManager */// w w w. ja v a 2 s .co 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:de.ailis.xadrian.utils.SwingUtils.java
/** * Adds a component action./* w w w . j a va 2s . 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:net.sf.jabref.util.Util.java
/** * Binds ESC-Key to cancel button//from www . j ava 2s.com * * @param rootPane the pane to bind the action to. Typically, this variable is retrieved by this.getRootPane(); * @param cancelAction the action to bind */ // TODO: move to GUI public static void bindCloseDialogKeyToCancelAction(JRootPane rootPane, Action cancelAction) { InputMap im = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = rootPane.getActionMap(); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); }
From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java
private void genUI() { getActionMap().put("Save", new SaveAction()); getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "Save"); m_TestRequirementTable = new JTable() { @Override// w ww .j a va2s . com public String getToolTipText(MouseEvent e) { Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); if (colIndex < 0) { return null; } return convertObjectToToolTip(getValueAt(rowIndex, colIndex)); } // overwrite cell content when typing on a selected cell @Override public Component prepareEditor(TableCellEditor editor, int row, int column) { Component c = super.prepareEditor(editor, row, column); if (c instanceof JTextComponent) { ((JTextField) c).selectAll(); } return c; } // select entire rows when selecting first column (row id) @Override public void columnSelectionChanged(ListSelectionEvent e) { if (e.getFirstIndex() == 0 && e.getValueIsAdjusting()) { setColumnSelectionInterval(1, getColumnCount() - 1); } else { super.columnSelectionChanged(e); } } }; m_TestRequirementTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); m_TestRequirementModel = new TestRequirementTableModel(); m_TestRequirementTable.setModel(m_TestRequirementModel); m_TableColumnModelListener = new MyTableColumnModelListener(); m_TestRequirementTable.setSurrendersFocusOnKeystroke(true); m_TestRequirementTable.setColumnSelectionAllowed(true); m_TestRequirementTable.addMouseListener(new TableMouseListener(m_TestRequirementTable)); m_TestRequirementTable.getTableHeader().addMouseListener(new TableMouseListener(m_TestRequirementTable)); m_TestRequirementTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); m_TestRequirementTable.getActionMap().put("Save", new SaveAction()); m_TestRequirementTable.setDefaultEditor(String.class, new TestDataTableCellEditor()); m_TestRequirementTable.setDefaultEditor(Integer.class, new TestDataTableCellEditor()); m_TestRequirementTable.getTableHeader().getInputMap() .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "Save"); m_TestRequirementTable.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "Save"); m_TestRequirementTable.setRowHeight(ROW_HEIGHT); m_TestRequirementTable.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // if (e.getKeyCode() == KeyEvent.VK_UP) { // check if previous line is empty } if (e.getKeyCode() == KeyEvent.VK_DOWN) { // if current row is the last one if (m_TestRequirementTable.getSelectedRow() == m_TestRequirementTable.getRowCount() - 1) { addNewRow(); } } if ((e.getKeyCode() == KeyEvent.VK_S) && (e.isControlDown())) { save(); } if ((e.getKeyCode() == KeyEvent.VK_C) && (e.isControlDown())) { copySelectionToClipboard(); } if ((e.getKeyCode() == KeyEvent.VK_V) && (e.isControlDown())) { if (m_TestRequirementTable.getSelectedColumn() != 0) { pasteSelectionFromClipboard(); } } } }); tableListener = new TableModelListener() { public void tableChanged(TableModelEvent e) { // build the test data if (e.getType() == TableModelEvent.UPDATE) { if (e.getFirstRow() >= 0) { setModified(true); } } } }; m_TestRequirementModel.addTableModelListener(tableListener); JScrollPane sp = new JScrollPane(m_TestRequirementTable); sp.addMouseListener(new TableMouseListener(null)); add(sp); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
private void setKeyboardAccelerators() { serverList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F"), "search"); serverList.getActionMap().put("search", new AbstractAction() { private static final long serialVersionUID = 1L; @Override//from w w w .ja va2 s .co m public void actionPerformed(final ActionEvent e) { showFilter(); } }); }
From source file:javazoom.jlgui.player.amp.StandalonePlayer.java
/** * Set keyboard key shortcut for the whole player. * @param id//from w ww . j av a2s. c o m * @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.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }//from ww w .j a v a2 s .co m }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }