/** * Sets the dialog for this service to the specified dialog. * * @param dialog The dialog for this service to maintain. */ protected void setDialog(JDialog dialog) { this.dialog = dialog; dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { dispose(); } }); JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "closeDialog"); root.getActionMap() .put( "closeDialog", new AbstractAction() { private static final long serialVersionUID = 2759447330549410101L; @Override public void actionPerformed(ActionEvent e) { BaseService.this.dispose(); } }); root.setDefaultButton(defaultButton); }
@Override protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); // Hide Window on ESC Action escapeAction = new AbstractAction("ESCAPE") { // $NON-NLS-1$ /** */ private static final long serialVersionUID = -6543764044868772971L; @Override public void actionPerformed(ActionEvent actionEvent) { setVisible(false); } }; // Do search on Enter Action enterAction = new AbstractAction("ENTER") { // $NON-NLS-1$ private static final long serialVersionUID = -3661361497864527363L; @Override public void actionPerformed(final ActionEvent actionEvent) { checkDirtyAndLoad(actionEvent); } }; ActionMap actionMap = rootPane.getActionMap(); actionMap.put(escapeAction.getValue(Action.NAME), escapeAction); actionMap.put(enterAction.getValue(Action.NAME), enterAction); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME)); inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME)); return rootPane; }
/* * Assign ENTER and ESCAPE keystrokes to be equivalent to OK and Cancel buttons, respectively. */ @SuppressWarnings("serial") protected void setupKeys() { // Get the InputMap and ActionMap of the RootPane of this JDialog. JRootPane rootPane = this.getRootPane(); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = rootPane.getActionMap(); // Setup ENTER key. inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); actionMap.put( "enter", new AbstractAction() { public void actionPerformed(ActionEvent e) { okChosen(); } }); // Setup ESCAPE key. inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); actionMap.put( "escape", new AbstractAction() { public void actionPerformed(ActionEvent e) { cancelChosen(); } }); // Stop table_ from consuming the ENTER keystroke and preventing it from being received by this // (JDialog). table_ .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "none"); }
/** Creates new form ClienteUsuarioModifica */ public DlgClienteNuevo(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); InitDialogData(); setTitle(TDSLanguageUtils.getMessage("client.SS2.Client.NuevoDialog")); b_OK.setText(TDSLanguageUtils.getMessage("client.SS2.btnOK")); b_Cancel.setText(TDSLanguageUtils.getMessage("client.SS2.btnCancel")); l_numeroCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.numclient")); l_fechAltaCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.dataalta")); l_nifCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.nif")); l_nombreCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.nom")); l_apellidosCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.cognoms")); l_direccionCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.adreca")); l_poblacionCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.poblacio")); l_codigoPostalCliente.setText(TDSLanguageUtils.getMessage("client.SS2.Client.codipostal")); l_error.setText(""); JRootPane rootPanel = this.getRootPane(); InputMap iMap = rootPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); ActionMap aMap = rootPanel.getActionMap(); aMap.put( "escape", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); }; }); }
/** * @param owner * @param modal * @throws java.awt.HeadlessException */ public CustomDialog(Frame owner, boolean modal) throws HeadlessException { super(owner, modal); setLocationRelativeTo(owner); Action cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { exitDialog(false); } }; final JRootPane pane = getRootPane(); pane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "escape"); pane.getActionMap().put("escape", cancelAction); }
@SuppressWarnings("serial") protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { setVisible(false); ok = false; } }; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); return rootPane; }
@Override protected JRootPane createRootPane() { JRootPane root = new JRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { private static final long serialVersionUID = -1L; public void actionPerformed(ActionEvent actionEvent) { setVisible(false); } }; InputMap inputMap = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); root.getActionMap().put("ESCAPE", actionListener); return root; }
private void addRunShortcutToOmegaT() { JRootPane appliRootPane = Core.getMainWindow().getApplicationFrame().getRootPane(); appliRootPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put( KeyStroke.getKeyStroke( KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK, false), "RUN_CURRENT_SCRIPT"); appliRootPane .getActionMap() .put( "RUN_CURRENT_SCRIPT", new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { runScript(); } }); }
private boolean showDialog(Component root, String title, boolean decorated) { if (dialog != null) { throw new IllegalStateException("Dialog already exists"); } dialog = Util.newJDialog(root, title, modal); if (!decorated) { dialog.setUndecorated(true); } JRootPane rootPane = dialog.getRootPane(); JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // Do this to reorder buttons so "cancel" and "ok" are last! // For Windows L&F, cancel button is on the right. For Nimbus // check the "isYesLast" option. boolean cancelonright = Util.isLAFWindows() || !UIManager.getBoolean("OptionPane.isYesLast"); if (actions.containsKey("cancel") && !cancelonright) { actions.put("cancel", actions.remove("cancel")); } if (actions.containsKey("ok")) { actions.put("ok", actions.remove("ok")); } if (actions.containsKey("cancel") && cancelonright) { actions.put("cancel", actions.remove("cancel")); } for (Iterator<Map.Entry<String, Action>> i = actions.entrySet().iterator(); i.hasNext(); ) { Map.Entry<String, Action> e = i.next(); String name = e.getKey(); Action action = e.getValue(); rootPane.getActionMap().put(name, action); buttonpanel.add(new JButton(action)); for (Iterator<Map.Entry<KeyStroke, String>> j = keystrokes.entrySet().iterator(); j.hasNext(); ) { Map.Entry<KeyStroke, String> e2 = j.next(); if (e2.getValue().equals(name)) { rootPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(e2.getKey(), e2.getValue()); } } } GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = gbc.REMAINDER; gbc.anchor = gbc.EAST; gbc.weighty = 0.01; add(buttonpanel, gbc); dialog.setContentPane(this); dialog.setResizable(true); dialog.pack(); dialog.setLocationRelativeTo(root); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent event) { if (actions.containsKey("cancel")) { cancelDialog(); } else { acceptDialog(); } } }); dialog.setVisible(true); return response; }