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:edu.umich.robot.ViewerApplication.java
public ViewerApplication(String[] args) { JPopupMenu.setDefaultLightWeightPopupEnabled(false); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig(); if (config == null) System.exit(1);/*from w w w . j ava2s.c o m*/ setupViewerConfig(config); viewer = new Viewer(config); viewer.getVisCanvas().getViewManager().setInterfaceMode(3); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { frame.dispose(); try { Thread.sleep(500); } catch (InterruptedException ignored) { } System.exit(0); // No way to shut down april threads } }); frame.setLayout(new BorderLayout()); viewerView = new ViewerView(viewer.getVisCanvas()); // TODO SoarApril // viewer.getVisCanvas().setDrawGround(true); frame.add(viewerView, BorderLayout.CENTER); Preferences windowPrefs = getWindowPreferences(); if (windowPrefs.get("x", null) != null) { frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 800), windowPrefs.getInt("height", 800)); } else { frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 600), windowPrefs.getInt("height", 600)); frame.setLocationRelativeTo(null); // center } frame.getRootPane().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); frame.pack(); frame.setVisible(true); String[] splinters = config.getStrings("splinters", new String[0]); for (String s : splinters) { addViewRobot(s); addViewLidars(s); addViewWaypoints(s); // TODO SoarApril addViewTrajectory(s); } }
From source file:com.chenjw.imagegrab.ui.MainFrame.java
public MainFrame() { {//from w ww .j a va 2 s.co m this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } GroupLayout configPanelLayout = new GroupLayout((JComponent) configPanel); configPanel.setLayout(configPanelLayout); configPanel.setPreferredSize(new java.awt.Dimension(1035, 726)); { downloadButton = new JButton(); downloadButton.setText(""); downloadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { executeService.execute(new Runnable() { @Override public void run() { imagegrabService.grab(); } }); } }); downloadButton.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { executeService.execute(new Runnable() { @Override public void run() { imagegrabService.grab(); } }); } }, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); } { jLabel1 = new JLabel(); jLabel1.setText("??"); } { resultScrollPane = new JScrollPane(resultPane); { resultPane = new JTextArea(); resultScrollPane.setViewportView(resultPane); } } { sourceComboBox = new JComboBox(); } { maxNumComboBox = new HistoryComboBox("maxNum"); } { jLabel6 = new JLabel(); jLabel6.setText("??"); } { jLabel3 = new JLabel(); jLabel3.setText("??"); } { searchWordComboBox = new HistoryComboBox("searchWord"); } configPanelLayout.setHorizontalGroup(configPanelLayout.createSequentialGroup().addContainerGap() .addGroup(configPanelLayout.createParallelGroup() .addGroup(configPanelLayout.createSequentialGroup() .addComponent(resultScrollPane, GroupLayout.PREFERRED_SIZE, 979, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(GroupLayout.Alignment.LEADING, configPanelLayout.createSequentialGroup() .addPreferredGap(resultScrollPane, jLabel1, LayoutStyle.ComponentPlacement.INDENT) .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(searchWordComboBox, 0, 213, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE) .addComponent(sourceComboBox, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(maxNumComboBox, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(downloadButton, GroupLayout.PREFERRED_SIZE, 162, GroupLayout.PREFERRED_SIZE) .addGap(0, 164, GroupLayout.PREFERRED_SIZE))) .addContainerGap()); configPanelLayout.setVerticalGroup(configPanelLayout.createSequentialGroup().addContainerGap() .addGroup(configPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(searchWordComboBox, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(sourceComboBox, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(downloadButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) .addComponent(maxNumComboBox, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 698, GroupLayout.PREFERRED_SIZE) .addComponent(resultScrollPane, GroupLayout.PREFERRED_SIZE, 686, GroupLayout.PREFERRED_SIZE)); // pack(); this.setSize(1010, 768); setVisible(true); this.setTitle("?"); getContentPane().add(configPanel, BorderLayout.CENTER); initSpring(); }
From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java
private void enableExitKey() { InputMap rootInput = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap rootAction = getRootPane().getActionMap(); if (SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_WINDOWS) { rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK), "exit"); rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK), "exit"); }//from w w w . j a v a 2 s . c o m if (SystemUtils.IS_OS_MAC) { rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.META_DOWN_MASK), "exit"); } rootAction.put("exit", new KeyAction(actionMapper, "exit")); }
From source file:com.projity.dialog.AbstractDialog.java
protected JRootPane createRootPane() { ActionListener escapeListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { onCancel();/*from w ww.ja v a 2 s . c o m*/ } }; ActionListener enterListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { onOk(); } }; ActionListener helpListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { onHelp(); } }; JRootPane rootPane = new JRootPane(); KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); rootPane.registerKeyboardAction(escapeListener, escapeStroke, JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); rootPane.registerKeyboardAction(enterListener, enterStroke, JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke f1Stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0); rootPane.registerKeyboardAction(helpListener, f1Stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; }
From source file:com.isecpartners.gizmo.FourthIdea.java
private void init(final BlobScroller scroller, String str, final AbstractAction action) { this.scroller = scroller; this.reqText = str; if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) { defaultShellField.setText("cmd.exe /c"); } else {//w w w. java2 s . c o m defaultShellField.setText("sh -c"); } this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { action.actionPerformed(null); } }); command_translation = new Properties(); try { command_translation.load(new FileInputStream(command_map_file_name)); } catch (IOException ex) { try { FileOutputStream fout = new FileOutputStream(command_map_file_name); fout.write("".getBytes()); fout.close(); } catch (IOException ex1) { } GizmoView.log("couldn't find " + command_map_file_name + ".. turning off macro translation"); } jTextPane1.setText(str); jTextPane1.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "esc"); jTextPane1.getActionMap().put("esc", action); }
From source file:dk.dma.epd.shore.gui.views.SendRouteDialog.java
/** * Create the frame./*w w w. j a v a2 s . c om*/ */ public SendRouteDialog(JFrame frame) { super(frame, "Tactical Route Exchange", Dialog.ModalityType.MODELESS); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); setLocation(100, 100); initGUI(); // Hook up enter key to send and escape key to cancel getRootPane().setDefaultButton(sendBtn); getRootPane().registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); pack(); }
From source file:net.sf.jabref.wizard.auximport.gui.FromAuxDialog.java
private void jbInit() { JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout()); selectInDBButton.setText(Localization.lang("Select")); selectInDBButton.setEnabled(false);/*w ww .j a v a2s . c o m*/ selectInDBButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { FromAuxDialog.this.select_actionPerformed(); } }); generateButton.setText(Localization.lang("Generate")); generateButton.setEnabled(false); generateButton.addActionListener(new FromAuxDialog_generate_actionAdapter(this)); cancelButton.setText(Localization.lang("Cancel")); cancelButton.addActionListener(new FromAuxDialog_Cancel_actionAdapter(this)); parseButton.setText(Localization.lang("Parse")); parseButton.addActionListener(new FromAuxDialog_parse_actionAdapter(this)); initPanels(); // insert the buttons ButtonBarBuilder bb = new ButtonBarBuilder(); JPanel buttonPanel = bb.getPanel(); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); bb.addGlue(); bb.addButton(parseButton); bb.addRelatedGap(); bb.addButton(selectInDBButton); bb.addButton(generateButton); bb.addButton(cancelButton); bb.addGlue(); this.setModal(true); this.setResizable(true); this.setTitle(Localization.lang("AUX file import")); JLabel desc = new JLabel("<html><h3>" + Localization.lang("AUX file import") + "</h3><p>" + Localization.lang("This feature generates a new database based on which entries " + "are needed in an existing LaTeX document.") + "</p>" + "<p>" + Localization.lang("You need to select one of your open databases from which to choose " + "entries, as well as the AUX file produced by LaTeX when compiling your document.") + "</p></html>"); desc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel1.add(desc, BorderLayout.NORTH); JPanel centerPane = new JPanel(new BorderLayout()); centerPane.add(buttons, BorderLayout.NORTH); centerPane.add(statusPanel, BorderLayout.CENTER); getContentPane().add(panel1, BorderLayout.NORTH); getContentPane().add(centerPane, BorderLayout.CENTER); getContentPane().add(buttonPanel, BorderLayout.SOUTH); // Key bindings: ActionMap am = statusPanel.getActionMap(); InputMap im = statusPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); }
From source file:net.sf.jabref.gui.PreviewPanel.java
private void createKeyBindings() { ActionMap actionMap = this.getActionMap(); InputMap inputMap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); final String close = "close"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), close); actionMap.put(close, this.closeAction); final String copy = "copy"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.COPY_PREVIEW), copy); actionMap.put(copy, this.copyPreviewAction); final String print = "print"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PRINT_ENTRY_PREVIEW), print); actionMap.put(print, this.printAction); }
From source file:edu.ku.brc.af.ui.forms.ResultSetController.java
/** * /*from w w w . ja va 2 s .c o m*/ */ public void setupGotoListener() { KeyStroke gotoKS = KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); String ACTION_KEY = "GOTO"; InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = panel.getActionMap(); inputMap.put(gotoKS, ACTION_KEY); actionMap.put(ACTION_KEY, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { showGotoRecDlg(); } }); }
From source file:au.org.ala.delta.ui.SearchDialog.java
@Override protected JRootPane createRootPane() { JRootPane rootPane = super.createRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); rootPane.registerKeyboardAction(new ActionListener() { @Override/*from w w w . ja va 2 s .c o m*/ public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; }