Example usage for java.awt.event KeyEvent VK_ENTER

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

Introduction

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

Prototype

int VK_ENTER

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

Click Source Link

Document

Constant for the ENTER virtual key.

Usage

From source file:frames.LoginFrame.java

private void emailTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_emailTextFieldKeyReleased

    //Get email typed by user
    email = emailTextField.getText().trim();

    //Verify if email field do not exceed 255 words (allowed into database)
    if (email.length() > 255) {
        email = email.substring(0, 255);
        emailTextField.setText(email);/* ww w  . j  ava 2 s.  co m*/
    }

    //Enable/Disable loginButton
    if (!email.equals(""))
        loginButton.setEnabled(true);
    else
        loginButton.setEnabled(false);

    //If user press enter, click loginButton
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        loginButton.doClick();
    }
}

From source file:net.sf.profiler4j.console.ClassListPanel.java

/**
 * This method initializes filterTextField
 * //from  w ww  .  j ava 2s. com
 * @return javax.swing.JTextField
 */
private JTextField getFilterTextField() {
    if (filterTextField == null) {
        filterTextField = new JTextField();
        filterTextField.setColumns(20);
        filterTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    refreshClassList();
                }
            }
        });
    }
    return filterTextField;
}

From source file:org.orbisgis.view.beanshell.BshConsolePanel.java

/**
 * Create actions instances/*  w w  w.j  av a  2s  .  c om*/
 * 
 * Each action is put in the Popup menu and the tool bar
 * Their shortcuts are registered also in the editor
 */
private void initActions() {
    //Execute action
    executeAction = new DefaultAction(BeanShellAction.A_EXECUTE, I18N.tr("Execute"),
            I18N.tr("Execute the java script"), OrbisGISIcon.getIcon("execute"),
            EventHandler.create(ActionListener.class, this, "onExecute"),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK));
    actions.addAction(executeAction);

    //Clear action
    clearAction = new DefaultAction(BeanShellAction.A_CLEAR, I18N.tr("Clear"),
            I18N.tr("Erase the content of the editor"), OrbisGISIcon.getIcon("erase"),
            EventHandler.create(ActionListener.class, this, "onClear"), null);
    actions.addAction(clearAction);

    //Open action
    actions.addAction(
            new DefaultAction(BeanShellAction.A_OPEN, I18N.tr("Open"), I18N.tr("Load a file in this editor"),
                    OrbisGISIcon.getIcon("open"), EventHandler.create(ActionListener.class, this, "onOpenFile"),
                    KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)));
    //Save
    saveAction = new DefaultAction(BeanShellAction.A_SAVE, I18N.tr("Save"),
            I18N.tr("Save the editor content into a file"), OrbisGISIcon.getIcon("save"),
            EventHandler.create(ActionListener.class, this, "onSaveFile"),
            KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
    actions.addAction(saveAction);
    //Find action
    findAction = new DefaultAction(BeanShellAction.A_SEARCH, I18N.tr("Search.."),
            I18N.tr("Search text in the document"), OrbisGISIcon.getIcon("find"),
            EventHandler.create(ActionListener.class, this, "openFindReplaceDialog"),
            KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK))
                    .addStroke(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK));
    actions.addAction(findAction);

}

From source file:uom.research.thalassemia.ui.PatientUI.java

/**
 * Patient search listener./*from  www .j a va  2 s. c om*/
 */
void setPatientSearchListener() {
    textField = (JTextField) cmbSearch.getEditor().getEditorComponent();
    textField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent evt) {
            try {
                String s = textField.getText();
                //List<ODocument> rst = DatabaseAccess.selectData("select from Patient where firstName like '" + s + "%' and isActive=true");
                FillData.fillCombo(cmbSearch,
                        "select from Patient where firstName like '" + s + "%' and isActive=true", "firstName");
                int rw = cmbSearch.getMaximumRowCount();
                if (rw > 5) {
                    cmbSearch.setMaximumRowCount(5);
                } else {
                    cmbSearch.setMaximumRowCount(rw);
                }
                if (s.isEmpty() || evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    cmbSearch.hidePopup();
                } else {
                    cmbSearch.showPopup();
                }
                cmbSearch.setSelectedItem(s);

            } catch (Exception e) {
            }
        }
    });
}

From source file:org.orbisgis.groovy.GroovyConsolePanel.java

/**
 * Create actions instances//  ww w .  jav  a 2s. com
 *
 * Each action is put in the Popup menu and the tool bar Their shortcuts are
 * registered also in the editor
 */
private void initActions() {
    //Execute action
    executeAction = new DefaultAction(GroovyConsoleActions.A_EXECUTE, I18N.tr("Execute"),
            I18N.tr("Execute the groovy script"), GroovyIcon.getIcon("execute"),
            EventHandler.create(ActionListener.class, this, "onExecute"),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK)).setLogicalGroup("custom");
    actions.addAction(executeAction);

    //Execute Selected SQL
    executeSelectedAction = new DefaultAction(GroovyConsoleActions.A_EXECUTE_SELECTION,
            I18N.tr("Execute selected"), I18N.tr("Run selected code"), GroovyIcon.getIcon("execute_selection"),
            EventHandler.create(ActionListener.class, this, "onExecuteSelected"),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK)).setLogicalGroup("custom")
                    .setAfter(GroovyConsoleActions.A_EXECUTE);
    actions.addAction(executeSelectedAction);

    //Clear action
    clearAction = new DefaultAction(GroovyConsoleActions.A_CLEAR, I18N.tr("Clear"),
            I18N.tr("Erase the content of the editor"), GroovyIcon.getIcon("erase"),
            EventHandler.create(ActionListener.class, this, "onClear"), null);
    actions.addAction(clearAction);

    //Open action
    actions.addAction(new DefaultAction(GroovyConsoleActions.A_OPEN, I18N.tr("Open"),
            I18N.tr("Load a file in this editor"), GroovyIcon.getIcon("open"),
            EventHandler.create(ActionListener.class, this, "onOpenFile"),
            KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)));
    //Save
    saveAction = new DefaultAction(GroovyConsoleActions.A_SAVE, I18N.tr("Save"),
            I18N.tr("Save the editor content into a file"), GroovyIcon.getIcon("save"),
            EventHandler.create(ActionListener.class, this, "onSaveFile"),
            KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
    actions.addAction(saveAction);
    // Save As
    saveAsAction = new DefaultAction(GroovyConsoleActions.A_SAVE, I18N.tr("Save As"),
            I18N.tr("Save the editor content into a new file"), GroovyIcon.getIcon("page_white_save"),
            EventHandler.create(ActionListener.class, this, "onSaveAsNewFile"),
            KeyStroke.getKeyStroke("ctrl maj s"));
    actions.addAction(saveAsAction);
    //Find action
    findAction = new DefaultAction(GroovyConsoleActions.A_SEARCH, I18N.tr("Search.."),
            I18N.tr("Search text in the document"), GroovyIcon.getIcon("find"),
            EventHandler.create(ActionListener.class, this, "openFindReplaceDialog"),
            KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK))
                    .addStroke(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK));
    actions.addAction(findAction);

    // Comment/Uncomment
    commentAction = new DefaultAction(GroovyConsoleActions.A_COMMENT, I18N.tr("(Un)comment"),
            I18N.tr("(Un)comment the selected text"), null,
            EventHandler.create(ActionListener.class, this, "onComment"), KeyStroke.getKeyStroke("alt C"))
                    .setLogicalGroup("format");
    actions.addAction(commentAction);

    // Block Comment/Uncomment
    blockCommentAction = new DefaultAction(GroovyConsoleActions.A_BLOCKCOMMENT, I18N.tr("Block (un)comment"),
            I18N.tr("Block (un)comment the selected text."), null,
            EventHandler.create(ActionListener.class, this, "onBlockComment"),
            KeyStroke.getKeyStroke("alt shift C")).setLogicalGroup("format");
    actions.addAction(blockCommentAction);
}

From source file:edu.ku.brc.af.ui.db.JEditComboBox.java

protected KeyAdapter createKeyAdapter() {
    return new KeyAdapter() {
        @Override// w ww .j  av  a2  s .c o  m
        public void keyReleased(KeyEvent ev) {
            char key = ev.getKeyChar();

            if (ev.getKeyCode() == clearKeyStroke.getKeyCode()) {
                int selectedIndex = getSelectedIndex();
                if (selectedIndex > -1 && dbAdapter != null && textField != null
                        && textField.getText().length() == 0 && !dbAdapter.isReadOnly()) {
                    // delete item
                    PickListItem item = (PickListItem) getSelectedItem();
                    dbAdapter.getList().remove(item);
                }

            } else if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) {
                if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
                    addNewItemFromTextField();
                }
            } else {
                if (textField != null) {
                    if (getSelectedIndex() > -1) {
                        int pos = textField.getCaretPosition();
                        String currentText = textField.getText();
                        setSelectedIndex(-1);
                        textField.setText(currentText);
                        textField.moveCaretPosition(pos);
                        textField.setSelectionStart(pos);
                        textField.setSelectionEnd(pos);
                    }

                } else {
                    setSelectedIndex(-1);
                }
            }
        }
    };
}

From source file:ru.goodfil.catalog.ui.forms.OePanel.java

private void tbSearchBrandKeyTyped(KeyEvent e) {
    if (e != null) {
        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
            tbSearchBrand.setText("");
        }//  w w w.  java 2 s.c o  m
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            btnSearchBrandActionPerformed(null);
        }
    }

    adjustButtonsEnabled();
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java

/** Initializes the components composing the display. */
private void initComponents() {
    usersBox = new JComboBox();
    groupsBox = createGroupBox();//from   w w  w. j a va 2 s.  com
    scopes = new HashMap<Integer, JCheckBox>(model.getNodes().size());
    types = new HashMap<Integer, JCheckBox>(model.getTypes().size());
    IconManager icons = IconManager.getInstance();
    fromDate = UIUtilities.createDatePicker(true, EditorUtil.DATE_PICKER_FORMAT);
    fromDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    fromDate.addPropertyChangeListener("date", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Date d = (Date) evt.getNewValue();
            if (d != null) {
                if (d.after(new Date())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date", "Selecting a future 'From' date doesn't make any sense.");
                    fromDate.setDate(null);
                }
                if (toDate.getDate() != null && d.after(toDate.getDate())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date",
                            "Cannot set a 'From' date which is more recent than the 'To' date.");
                    fromDate.setDate(null);
                }
            }
        }
    });
    fromDate.setToolTipText(DATE_TOOLTIP);

    toDate = UIUtilities.createDatePicker(true, EditorUtil.DATE_PICKER_FORMAT);
    toDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    toDate.setToolTipText(DATE_TOOLTIP);
    toDate.addPropertyChangeListener("date", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Date d = (Date) evt.getNewValue();
            if (d != null) {
                if (fromDate.getDate() != null && d.before(fromDate.getDate())) {
                    UserNotifier un = DataBrowserAgent.getRegistry().getUserNotifier();
                    un.notifyWarning("Invalid Date",
                            "Cannot set a 'To' date which is prior to the 'From' date.");
                    toDate.setDate(null);
                }
            }
        }
    });

    clearDate = new JButton(icons.getIcon(IconManager.CLOSE));
    clearDate.setToolTipText("Reset the dates");
    UIUtilities.unifiedButtonLookAndFeel(clearDate);
    clearDate.setBackground(UIUtilities.BACKGROUND_COLOR);
    clearDate.setActionCommand("" + SearchComponent.RESET_DATE);
    clearDate.addActionListener(model);

    fullTextArea = new JTextField(AREA_COLUMNS);
    fullTextArea.addKeyListener(new KeyAdapter() {

        /** Finds the phrase. */
        public void keyPressed(KeyEvent e) {
            Object source = e.getSource();
            if (source != fullTextArea)
                return;
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                model.search();
            }
        }
    });

    helpBasicButton = new JButton(icons.getIcon(IconManager.HELP));
    helpBasicButton.setToolTipText("Search Tips.");
    helpBasicButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    UIUtilities.unifiedButtonLookAndFeel(helpBasicButton);
    helpBasicButton.addActionListener(model);
    helpBasicButton.setActionCommand("" + SearchComponent.HELP);

    SearchContext ctx = model.getSearchContext();
    if (ctx == null)
        return;
}

From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java

/**
 * This method initializes jTextFieldUser   
 *    /*from  www.j  a  v  a  2  s.c om*/
 * @return javax.swing.JTextField   
 */
private JTextField getJTextFieldUser() {
    if (jTextFieldUser == null) {
        jTextFieldUser = new JTextField();

        jTextFieldUser.setPreferredSize(new Dimension(200, 22));
        jTextFieldUser.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent e) {
                mEventHandler.handle(EventHandler.TF_USER_ID);
            }
        });
        jTextFieldUser.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    mEventHandler.handle(EventHandler.ENTER_KEY_TYTPED);
                }
            }
        });
        jTextFieldUser.addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                jTextFieldUser.selectAll();
            }

            @Override
            public void focusLost(FocusEvent e) {
                jTextFieldUser.select(0, 0);
            }
        });
    }
    return jTextFieldUser;
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

public ListenerWindow(AbstractPrologEngine e, boolean autoDisplay) throws IOException {

    try {/*www.j  av a2  s .c  o m*/
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(ListenerWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ListenerWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ListenerWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ListenerWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }

    //        constructWindowContents();
    initComponents();

    graphComponents();

    /* 
     Forest<String, Integer> forest = new DelegateForest<>();
     forest = new GraphGenerator().createTree(forest);
            
     UpdategraphComponents(forest);
     //ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));
     //ObservableGraph g = new ObservableGraph(new GraphGenerator().createTree(forest));
            
     */
    /// super("PrologEngine listener (Swing)");
    if (e != null) {
        engine = e;
    } else {
        throw new IPException("missing Prolog engine");
    }

    String VF = e.getImplementationPeer().visualizationFilename();
    if (engine.getLoadFromJar()) {
        engine.consultFromPackage(VF, ListenerWindow.class);
    } else {
        engine.consultRelative(VF, ListenerWindow.class);
    }
    engine.teachMoreObjects(guiExamples());

    if (engine == null) {
        dispose(); // no interface object permitted!
    } else {
        topLevelCount++;
    }
    debug = engine.isDebug();

    loadedFiles = new Vector();

    constructMenu();

    addWindowListener(this);

    prologInput.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                sendToProlog();
                e.consume();
            }
        }
    });
    //prologOutput.append("Welcome to an InterProlog top level\n" + e.getPrologVersion() + "\n\n");
    prologOutput.append("\n ARG ENGINE v18 ALPHA ");
    prologOutput.append("\t Argument Engine based on WFS \n\n");
    prologOutput.append("\t UIKM Group - Umea University \n\n");
    prologOutput.append("\t {esteban, jcnieves, helena}@cs.umu.se \n\n");

    if (autoDisplay) {
        setVisible(true);
        focusInput();
    }

    /**
     * *******************************************************************************************
     */
    this.setVisible(true);

}