Example usage for java.awt.event KeyEvent VK_ESCAPE

List of usage examples for java.awt.event KeyEvent VK_ESCAPE

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_ESCAPE.

Prototype

int VK_ESCAPE

To view the source code for java.awt.event KeyEvent VK_ESCAPE.

Click Source Link

Document

Constant for the ESCAPE virtual key.

Usage

From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java

private void initListeners() {
    inputFeedText.addMouseListener(new ContextMenuMouseListener());
    inputFeedText.addKeyListener(new KeyListener() {
        @Override//  w w w.  j  av  a2 s  . c om
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                onOK();
                break;
            case KeyEvent.VK_ESCAPE:
                onCancel();
                break;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    makeFieldsPrivate.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (makeFieldsPrivate.isSelected()) {
                setEncapsulationOptionsVisible(true);
                SetEncapsulationOptionsSelected(true);
            } else {
                setEncapsulationOptionsVisible(false);
            }
        }
    });
}

From source file:org.ut.biolab.medsavant.client.util.ClientMiscUtils.java

/**
 * Register the escape key so that it can be used to cancel the associated JDialog.
 *//*from  w  w w  .  j a  v a2s .  c o  m*/
public static void registerCancelButton(final JButton cancelButton) {
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    JDialog dialog = (JDialog) SwingUtilities.getWindowAncestor(cancelButton);
    dialog.getRootPane().registerKeyboardAction(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            cancelButton.doClick();
        }
    }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
}

From source file:org.nuclos.client.layout.wysiwyg.editor.ui.panels.WYSIWYGMetaInformationPicker.java

/**
 * //  w w w.  j a  va 2  s .  c  o  m
 * @param values
 * @param parent
 */
private WYSIWYGMetaInformationPicker(Window owner, List<String> values, TableLayoutPanel parent) {
    super(owner);

    this.setIconImage(NuclosIcons.getInstance().getScaledDialogIcon(48).getImage());

    Container contentPane = this.getContentPane();
    contentPane.setLayout(new TableLayout(layoutDefinition));

    originalValues = values;

    filter = new JTextField();

    /** the keybinding*/
    filter.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            /** up and down cursor for selecting the next or previous entry */
            if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                int selectedItem = itemList.getSelectedIndex();
                if (e.getKeyCode() == KeyEvent.VK_UP)
                    selectedItem--;
                else if (e.getKeyCode() == KeyEvent.VK_DOWN)
                    selectedItem++;

                if (selectedItem < 0) {
                    selectedItem = listModel.getSize() - 1;
                } else if (selectedItem == listModel.getSize()) {
                    selectedItem = 0;
                }

                itemList.setSelectedIndex(selectedItem);
                itemList.ensureIndexIsVisible(selectedItem);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                /** enter for saving, esc for cancel */
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                    selectedEntity = null;
                dispose();

            } else {
                /** every other key is used for filtering the entries */
                filterItems(WYSIWYGMetaInformationPicker.this.filter.getText());
            }
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });
    /** request focus in the filter window */
    filter.requestFocusInWindow();

    this.add(filter, new TableLayoutConstraints(1, 1, 3, 1));
    itemList = new JList(listModel);
    itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    itemList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (itemList.getSelectedValue() != null)
                selectedEntity = (String) itemList.getSelectedValue();
        }

    });
    freeExpr = new JCheckBox(SpringLocaleDelegate.getInstance()
            .getMessageFromResource("wysiwg.metainformation.picker.freeexpr"));
    this.add(freeExpr, new TableLayoutConstraints(1, 2, 3, 2));
    freeExpr.setVisible(true);

    // double click on item to select
    itemList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                performSaveAction();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

    });

    filterItems(null);

    JScrollPane scrollpane = new JScrollPane(itemList);

    this.add(scrollpane, new TableLayoutConstraints(1, 4, 3, 4));

    JButton apply = new JButton(BUTTON_LABELS.LABEL_APPLY);
    apply.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            performSaveAction();
        }

    });
    this.add(apply, new TableLayoutConstraints(1, 6));

    JButton cancel = new JButton(BUTTON_LABELS.LABEL_CANCEL);
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            performCancelAction();
        }

    });

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            performCancelAction();
        }
    });

    this.add(cancel, new TableLayoutConstraints(3, 6));

    this.setBounds(this.getBounds().x, this.getBounds().y, 300, 400);
    this.setTitle(TABLELAYOUT_PANEL.SELECT_FIELD_FOR_METAINFORMATION);
    this.setModal(true);
}

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);// w  ww . jav  a2 s .c om

    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:org.codinjutsu.tools.jenkins.view.BuildParamDialog.java

private void registerListeners() {
    buttonOK.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onOK();//from   w  w w.  j  a v a 2 s. c  o  m
        }
    });

    buttonCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    });

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    contentPane.registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Adds the dispose action with escape key.
 * //from  ww w  .  j  a v  a2s  . co  m
 * @param dialog
 *            the dialog
 */
public static void addDisposeActionWithEscapeKey(final JDialog dialog) {
    //  Handle escape key to close the dialog

    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    Action disposeAction = new AbstractAction() {
        private static final long serialVersionUID = 0L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    dialog.getRootPane().getActionMap().put("ESCAPE", disposeAction);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewParametersDialog.java

private void initialize(final MasterReport report) {
    if (report == null) {
        throw new NullPointerException();
    }/*from  w w w.  j ava 2  s.  c  om*/

    masterReport = report;
    messages = new ResourceBundleSupport(Locale.getDefault(), SwingPreviewModule.BUNDLE_NAME,
            ObjectUtilities.getClassLoader(PreviewParametersDialog.class));
    confirmAction = new OkAction();

    setTitle(messages.getString("PreviewParametersDialog.Title"));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(createParametersPanel(), BorderLayout.CENTER);
    contentPane.add(createButtonsPanel(), BorderLayout.SOUTH);
    setContentPane(contentPane);

    final InputMap inputMap = contentPane.getInputMap();
    final ActionMap actionMap = contentPane.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirm"); // NON-NLS
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NON-NLS
    actionMap.put("confirm", new OkAction()); // NON-NLS
    actionMap.put("cancel", new CancelAction()); // NON-NLS

    setModal(true);
    pack();
    LibSwingUtil.centerDialogInParent(this);
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * If this view or a parent view is a JDialog, makes it closeable on ESC hit. Dialog
 * "defaultCloseOperation" property is taken into account when processing ESC button
 * click.//from   ww  w.j  a va  2 s .c o m
 */
protected void makeCloseableOnEscape() {

    Window window = getWindow();
    if (!(window instanceof JDialog)) {
        return;
    }

    final JDialog dialog = (JDialog) window;

    KeyStroke escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    ActionListener closeAction = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.isVisible()) {
                switch (dialog.getDefaultCloseOperation()) {
                case JDialog.HIDE_ON_CLOSE:
                    dialog.setVisible(false);
                    break;
                case JDialog.DISPOSE_ON_CLOSE:
                    dialog.setVisible(false);
                    dialog.dispose();
                    break;
                case JDialog.DO_NOTHING_ON_CLOSE:
                default:
                    break;
                }
            }
        }
    };
    dialog.getRootPane().registerKeyboardAction(closeAction, escReleased, JComponent.WHEN_IN_FOCUSED_WINDOW);
}

From source file:org.kalypso.ogc.gml.map.widgets.MeasureMapWidget.java

@Override
public void keyPressed(final KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        e.consume();/* w ww.  j a v  a2s  .  c om*/

        final int currentIndex = ArrayUtils.indexOf(m_delegates, m_delegate);
        final int newIndex = (currentIndex + 1) % m_delegates.length;
        updateDelegate(newIndex);

        getMapPanel().repaintMap();
        return;
    }

    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
        e.consume();

        reset();
        getMapPanel().repaintMap();
        return;
    }

    super.keyPressed(e);
}

From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java

private void initComponents() {

    jlUpgradeInstructions = new JLabel(res.getString("DUpgradeCryptoStrength.jlUpgradeInstructions.text"));
    jlDownloadPolicyInstructions = new JLabel(
            res.getString("DUpgradeCryptoStrength.jlDownloadPolicyInstructions.text"));
    jbDownloadPolicy = new JButton(res.getString("DUpgradeCryptoStrength.jbDownloadPolicy.text"));
    PlatformUtil.setMnemonic(jbDownloadPolicy,
            res.getString("DUpgradeCryptoStrength.jbDownloadPolicy.mnemonic").charAt(0));

    jlDropPolicyInstructions = new JLabel(
            res.getString("DUpgradeCryptoStrength.jlDropPolicyInstructions.text"));
    policyZipDropTarget = new PolicyZipDropTarget();
    jbBrowsePolicy = new JButton(res.getString("DUpgradeCryptoStrength.jbBrowsePolicy.text"));
    PlatformUtil.setMnemonic(jbBrowsePolicy,
            res.getString("DUpgradeCryptoStrength.jbBrowsePolicy.mnemonic").charAt(0));

    jbUpgrade = new JButton(res.getString("DUpgradeCryptoStrength.jbUpgrade.text"));
    PlatformUtil.setMnemonic(jbUpgrade, res.getString("DUpgradeCryptoStrength.jbUpgrade.mnemonic").charAt(0));
    jbUpgrade.setEnabled(false);//from  w ww.jav  a 2s.  c  om

    jbCancel = new JButton(res.getString("DUpgradeCryptoStrength.jbCancel.text"));
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            CANCEL_KEY);

    jpButtons = PlatformUtil.createDialogButtonPanel(jbUpgrade, jbCancel);

    // layout
    Container pane = getContentPane();
    pane.setLayout(new MigLayout("insets dialog, fill", "", "[]para[]"));
    pane.add(jlUpgradeInstructions, "wrap");
    pane.add(jlDownloadPolicyInstructions, "wrap");
    pane.add(jbDownloadPolicy, "wrap");
    pane.add(jlDropPolicyInstructions, "split");
    pane.add(policyZipDropTarget, "gap para, pad para, wrap");
    pane.add(jbBrowsePolicy, "wrap");
    pane.add(new JSeparator(), "spanx, growx, wrap para");
    pane.add(jpButtons, "right, spanx");

    // actions
    jbDownloadPolicy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DUpgradeCryptoStrength.this);
                downloadPolicyPressed();
            } finally {
                CursorUtil.setCursorFree(DUpgradeCryptoStrength.this);
            }
        }
    });
    jbUpgrade.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            upgradePressed();
        }
    });
    jbCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbBrowsePolicy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DUpgradeCryptoStrength.this);
                browsePolicyPressed();
            } finally {
                CursorUtil.setCursorFree(DUpgradeCryptoStrength.this);
            }
        }
    });
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    setResizable(false);

    getRootPane().setDefaultButton(jbUpgrade);

    pack();
}