List of usage examples for java.awt.event KeyEvent VK_ESCAPE
int VK_ESCAPE
To view the source code for java.awt.event KeyEvent VK_ESCAPE.
Click Source Link
From source file:org.openconcerto.erp.core.common.ui.DeviseField.java
@Override public void init(String sqlName, Set<SQLField> fields) { this.field = CollectionUtils.getSole(fields); this.sqlName = sqlName; this.helper = new EmptyObjectHelper(this, new Predicate() { public boolean evaluate(Object object) { return object == null; // final String val = GestionDevise.currencyToString(((Long) // object).longValue()); }//from w w w . j a v a2 s . c o m }); // TODO use JFormattedTextField => conflit getValue() // DefaultFormatterFactory NumberFormatter (getAllowsInvalid) NumberFormat addFilteringKeyListener(this); // select all on focus gained // except if the user is selecting with the mouse this.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { DeviseField.this.gained = true; DeviseField.this.initialText = getText(); if (!DeviseField.this.mousePressed) { selectAll(); } } }); this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { DeviseField.this.mousePressed = true; } public void mouseReleased(MouseEvent e) { // don't override the user selection if (DeviseField.this.gained && getSelectedText() == null) { selectAll(); } // don't select all for each mouse released DeviseField.this.gained = false; DeviseField.this.mousePressed = false; } }); this.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent keyEvent) { // Sert a annuler une saisie if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) { DeviseField.this.setValue(DeviseField.this.initialText); selectAll(); } } }); }
From source file:org.jannocessor.ui.RenderPreviewDialog.java
private void initialize() { logger.debug("Initializing UI..."); DefaultSyntaxKit.initKit();// www . j a v a2s . co m JEditorPane.registerEditorKitForContentType("text/java_template", "org.jannocessor.syntax.JavaTemplateKit", getClass().getClassLoader()); JEditorPane.registerEditorKitForContentType("text/java_output", "org.jannocessor.syntax.JavaOutputKit", getClass().getClassLoader()); setTitle("JAnnocessor - Java Annotation Processor"); setLayout(new BorderLayout(5, 5)); listFiles(); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); double width = screenSize.getWidth() * 0.9; double height = screenSize.getHeight() * 0.8; // Font font = new Font("Courier New", Font.PLAIN, 14); input = createInput(); JScrollPane scroll1 = new JScrollPane(input, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); input.setContentType("text/java_template"); input.setText(""); scroll1.setMinimumSize(new Dimension(200, 200)); scroll1.setPreferredSize(new Dimension((int) (width * 0.5), (int) height)); add(scroll1, BorderLayout.CENTER); output = Box.createVerticalBox(); scroll2 = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll2.setMinimumSize(new Dimension(200, 200)); scroll2.setPreferredSize(new Dimension((int) (width * 0.5), (int) height)); add(scroll2, BorderLayout.EAST); combo = createCombo(); combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { load((File) combo.getSelectedItem()); } }); add(combo, BorderLayout.NORTH); JLabel help = new JLabel( " Choose a template from the drop-down box to edit it. Navigation: Alt + Left & Alt + Right; Refresh = F5, Close = Esc", JLabel.CENTER); help.setForeground(Color.WHITE); help.setBackground(Color.BLACK); help.setOpaque(true); help.setFont(new Font("Courier New", Font.BOLD, 14)); add(help, BorderLayout.SOUTH); keyListener = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_F5) { e.consume(); processElements(); refresh(); } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { e.consume(); dispose(); } else if (e.getKeyCode() == KeyEvent.VK_LEFT && e.isAltDown()) { e.consume(); moveBackward(); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT && e.isAltDown()) { e.consume(); moveForward(); } else if (e.getKeyCode() == KeyEvent.VK_S && e.isControlDown()) { e.consume(); save(); } else if (e.getKeyCode() == KeyEvent.VK_I && e.isControlDown()) { e.consume(); increase(); } else if (e.getKeyCode() == KeyEvent.VK_D && e.isControlDown()) { e.consume(); decrease(); } } }; input.addKeyListener(keyListener); combo.addKeyListener(keyListener); setActive(0); pack(); setModal(true); setLocationRelativeTo(null); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); input.requestFocus(); logger.debug("Initialized UI."); }
From source file:org.notebook.gui.widget.GuiUtils.java
/** * Adds the dispose action with escape key. * //from w ww.j a va 2 s .c om * @param frame * the frame */ public static void addDisposeActionWithEscapeKey(final JFrame frame) { // 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) { frame.dispose(); } }; frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); frame.getRootPane().getActionMap().put("ESCAPE", disposeAction); }
From source file:com.projity.dialog.AbstractDialog.java
protected JRootPane createRootPane() { ActionListener escapeListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { onCancel();//w w w . j a va2 s . co 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:se.trixon.mapollage.ui.MainFrame.java
private void initActions() { mActionManager = ActionManager.getInstance().init(getRootPane().getActionMap(), getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); InputMap inputMap = mPopupMenu.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = mPopupMenu.getActionMap(); Action action = new AbstractAction("HideMenu") { @Override// w w w . j a v a 2s . co m public void actionPerformed(ActionEvent e) { mPopupMenu.setVisible(false); } }; String key = "HideMenu"; actionMap.put(key, action); KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); inputMap.put(keyStroke, key); //about PomInfo pomInfo = new PomInfo(Mapollage.class, "se.trixon", "mapollage"); AboutModel aboutModel = new AboutModel(SystemHelper.getBundle(Mapollage.class, "about"), SystemHelper.getResourceAsImageIcon(MainFrame.class, "icon-1024px.png")); aboutModel.setAppVersion(pomInfo.getVersion()); AboutPanel aboutPanel = new AboutPanel(aboutModel); action = AboutPanel.getAction(MainFrame.this, aboutPanel); getRootPane().getActionMap().put(ActionManager.ABOUT, action); //File quitMenuItem.setAction(mActionManager.getAction(ActionManager.QUIT)); //Profile addMenuItem.setAction(mActionManager.getAction(ActionManager.ADD)); cloneMenuItem.setAction(mActionManager.getAction(ActionManager.CLONE)); renameMenuItem.setAction(mActionManager.getAction(ActionManager.RENAME)); removeMenuItem.setAction(mActionManager.getAction(ActionManager.REMOVE)); removeAllMenuItem.setAction(mActionManager.getAction(ActionManager.REMOVE_ALL)); //Tools optionsMenuItem.setAction(mActionManager.getAction(ActionManager.OPTIONS)); //Help helpMenuItem.setAction(mActionManager.getAction(ActionManager.HELP)); aboutDateFormatMenuItem.setAction(mActionManager.getAction(ActionManager.ABOUT_DATE_FORMAT)); aboutMenuItem.setAction(mActionManager.getAction(ActionManager.ABOUT)); //Toolbar startButton.setAction(mActionManager.getAction(ActionManager.START)); cancelButton.setAction(mActionManager.getAction(ActionManager.CANCEL)); menuButton.setAction(mActionManager.getAction(ActionManager.MENU)); SwingHelper.clearText(toolBar); }
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 . j a va 2 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 ww .ja v a2 s . c o m */ 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: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/* ww w . j a v a2 s . c o m*/ public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; }
From source file:org.nuclos.client.genericobject.statehistory.StateHistoryController.java
private static void setupEscapeKey(final MainFrameTab ifrm, final StateHistoryPanel pnlHistory) { // Escape key is to close the window: final Action actClose = new AbstractAction() { @Override//from w w w. j a va2 s . c o m public void actionPerformed(ActionEvent ev) { ifrm.dispose(); } }; final String KEY_CLOSE = "Close"; ifrm.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), KEY_CLOSE); ifrm.getRootPane().getActionMap().put(KEY_CLOSE, actClose); pnlHistory.getTable().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), KEY_CLOSE); pnlHistory.getTable().getActionMap().put(KEY_CLOSE, actClose); }
From source file:com.headswilllol.basiclauncher.Launcher.java
public Launcher() { f.setTitle(NAME + " Launcher"); if (progress == null) { this.setLayout(null); play = new JButton("Play Game"); play.setVerticalTextPosition(AbstractButton.CENTER); play.setHorizontalTextPosition(AbstractButton.CENTER); play.setMnemonic(KeyEvent.VK_ENTER); play.setActionCommand("play"); play.addActionListener(this); play.setPreferredSize(new Dimension(btnWidth, btnHeight)); play.setBounds((width / 2) - (btnWidth / 2), 125, btnWidth, btnHeight); this.add(play); force = new JButton("Force Update"); force.setVerticalTextPosition(AbstractButton.CENTER); force.setHorizontalTextPosition(AbstractButton.CENTER); force.setMnemonic(KeyEvent.VK_ENTER); force.setActionCommand("force"); force.addActionListener(this); force.setPreferredSize(new Dimension(btnWidth, btnHeight)); force.setBounds((width / 2) - (btnWidth / 2), 200, btnWidth, btnHeight); this.add(force); noUpdate = new JButton("Do Not Reacquire"); noUpdate.setVerticalTextPosition(AbstractButton.CENTER); noUpdate.setHorizontalTextPosition(AbstractButton.CENTER); noUpdate.setMnemonic(KeyEvent.VK_ENTER); noUpdate.setActionCommand("noReacquire"); noUpdate.addActionListener(this); noUpdate.setPreferredSize(new Dimension(btnWidth, btnHeight)); noUpdate.setBounds((width / 2) - (btnWidth / 2), 275, btnWidth, btnHeight); this.add(noUpdate); quit = new JButton("Exit Launcher"); quit.setVerticalTextPosition(AbstractButton.CENTER); quit.setHorizontalTextPosition(AbstractButton.CENTER); quit.setMnemonic(KeyEvent.VK_ESCAPE); quit.setActionCommand("quit"); quit.addActionListener(this); quit.setPreferredSize(new Dimension(btnWidth, btnHeight)); quit.setBounds((width / 2) - (btnWidth / 2), 350, btnWidth, btnHeight); this.add(quit); }/* w w w . j av a 2 s .c o m*/ launcher = this; }