Example usage for java.awt.event KeyEvent getKeyCode

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

Introduction

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

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:client.InterfaceJeu.java

private void txtFieldChatEcrKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFieldChatEcrKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        c.ecrireMessage("chat::" + txtFieldChatEcr.getText());
        txtFieldChatEcr.setText("");
    }//from  w  w w.  ja  v  a  2s . c  o m
}

From source file:org.openmicroscopy.shoola.agents.util.SelectionWizard.java

/** 
 * Initializes the components composing the display.
 * //from  w  ww.  j a va 2 s . c  om
 * @param userID The id of the user currently logged in.
 */
private void initComponents() {
    addLabel = UIUtilities.setTextFont("");
    acceptButton = new JButton("Save");
    acceptButton.setToolTipText("Save the selection.");
    cancelButton = new JButton("Cancel");
    cancelButton.setToolTipText("Cancel the selection.");
    resetButton = new JButton("Reset");
    resetButton.setToolTipText("Reset the selection.");

    addNewButton = new JButton("Add");
    addNewButton.setEnabled(false);
    addNewButton.setToolTipText("Add to the selection.");
    addNewButton.setActionCommand("" + ADD_NEW);
    addNewButton.addActionListener(this);

    acceptButton.setActionCommand("" + ACCEPT);
    acceptButton.addActionListener(this);
    acceptButton.setEnabled(false);
    resetButton.setEnabled(false);
    cancelButton.setActionCommand("" + CANCEL);
    cancelButton.addActionListener(this);
    resetButton.setActionCommand("" + RESET);
    resetButton.addActionListener(this);

    //Field creation
    addField = new JTextField(10);
    addField.setToolTipText("Tag Name");
    originalColor = addField.getForeground();
    setTextFieldDefault(addField, DEFAULT_TEXT);
    addField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                if (addField.isFocusOwner()) {
                    addNewObjects();
                }
            }
        }
    });
    descriptionField = new JTextField(15);
    descriptionField.setToolTipText("Tag Description");
    setTextFieldDefault(descriptionField, DEFAULT_DESCRIPTION);
    addField.getDocument().addDocumentListener(this);
    addField.addFocusListener(this);
    descriptionField.addFocusListener(this);
    descriptionField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                if (descriptionField.isFocusOwner()) {
                    addNewObjects();
                }
            }
        }
    });
}

From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java

/**
 * This method initializes jPinPasswordField   
 *    //w  w  w .j av a2  s .  co m
 * @return javax.swing.JPasswordField   
 */
private JPasswordField getJPinPasswordField() {
    if (jPinPasswordField == null) {
        jPinPasswordField = new JPasswordField();
        jPinPasswordField.setPreferredSize(new Dimension(150, 20));
        jPinPasswordField.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 10) {
                    administrarTarjeta();
                }
            }
        });
    }
    return jPinPasswordField;
}

From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java

private KeyAdapter getEditorComponentKeyAdapter() {

    return new KeyAdapter() {
        @Override//from   w w  w .  ja v a  2  s  .  c  om
        public void keyReleased(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                // We are no longer busy.
                busySubject.notify(AjaxAutoCompleteJComboBox.this, false);

                DispType lastEnteredDispType = null;

                if (AjaxAutoCompleteJComboBox.this.getItemCount() > 0) {
                    int index = AjaxAutoCompleteJComboBox.this.getSelectedIndex();

                    if (index == -1) {
                        Object object = AjaxAutoCompleteJComboBox.this.getItemAt(0);
                        if (object instanceof DispType) {
                            lastEnteredDispType = (DispType) object;
                        }
                    } else {
                        Object object = AjaxAutoCompleteJComboBox.this.getItemAt(index);
                        if (object instanceof DispType) {
                            lastEnteredDispType = (DispType) object;
                        }
                    }
                } else {
                    final Object object = AjaxAutoCompleteJComboBox.this.getEditor().getItem();

                    if (object instanceof String) {
                        // All upper-case, if the result is not coming from server.
                        final String string = ((String) object).trim().toUpperCase();
                        if (string.length() > 0) {
                            lastEnteredDispType = new ResultType(string, string);
                        }
                    }
                }

                AjaxAutoCompleteJComboBox.this.removeAllItems();
                if (lastEnteredDispType != null) {
                    AjaxAutoCompleteJComboBox.this.dispSubject.notify(AjaxAutoCompleteJComboBox.this,
                            lastEnteredDispType);
                }
                return;
            } /* if(KeyEvent.VK_ENTER == e.getKeyCode()) */

            // If user removes item from text field, we will hidePopup and
            // removeAllItems. Please refer DocumentListener.handle, on why
            // don't we handle hidePopup and removeAllItems there.
            final Object object = AjaxAutoCompleteJComboBox.this.getEditor().getItem();
            if (object == null || object.toString().length() <= 0) {
                AjaxAutoCompleteJComboBox.this.hidePopup();
                AjaxAutoCompleteJComboBox.this.removeAllItems();
            }
        } /* public void keyReleased(KeyEvent e) */
    };
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java

/** Initializes the components composing the display. */
private void initComponents() {
    IconManager icons = IconManager.getInstance();
    addButton = new JButton(icons.getIcon(IconManager.RIGHT_ARROW));
    addButton.setToolTipText(TOOLTIP_BUTTON_ADD);
    addButton.setEnabled(false);//from ww  w .j  av  a2 s  .  c om
    removeButton = new JButton(icons.getIcon(IconManager.LEFT_ARROW));
    removeButton.setToolTipText(TOOLTIP_BUTTON_REMOVE);
    removeButton.setEnabled(false);
    removeAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_LEFT_ARROW));
    removeAllButton.setToolTipText(TOOLTIP_BUTTON_REMOVE_ALL);
    removeAllButton.setEnabled(false);
    addButton.setActionCommand("" + ADD);
    addButton.addActionListener(this);
    removeButton.setActionCommand("" + REMOVE);
    removeButton.addActionListener(this);
    removeAllButton.setActionCommand("" + REMOVE_ALL);
    removeAllButton.addActionListener(this);

    table = new JTable(new FileTableModel());
    keyListener = new KeyAdapter() {

        /**
         * Adds the files to the import queue.
         * @see KeyListener#keyPressed(KeyEvent)
         */
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                if (table.isFocusOwner())
                    removeSelectedFiles();
            }
        }
    };
    table.addKeyListener(keyListener);
    formatTableModel();
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.getSource() != table) {
        return;/*  www.  ja va  2s .  c  om*/
    }

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        // What's the current selection ?
        final List<File> selection = getSelection();

        if (selection.size() == 1) {
            final File selectedFile = selection.iterator().next();

            if (selectedFile.isDirectory()) {
                // Change to the selected directory
                setDirectory(selectedFile);
            }
        }
    } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        // Return to the parent directory (if any)
        final File parentDir = getParentDirectory();

        if ((parentDir != null) && parentDir.exists()) {
            setDirectory(parentDir);
        }
    } else {
        // Propagate event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }
}

From source file:schemagenerator.DBbeheer.java

private void Table_OefeningenKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Table_OefeningenKeyReleased
    if (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP) {
        try {// ww w  . ja  v a2s .  c o  m
            int row = Table_Oefeningen.getSelectedRow();
            String tableClick = (Table_Oefeningen.getModel().getValueAt(row, 0).toString());
            String sql = "SELECT * FROM oefeningen WHERE spiergroep='" + tableClick + "'";
            pst = con.prepareStatement(sql);
            rs = pst.executeQuery();
            if (rs.next()) {
                String add1 = rs.getString("ID");
                jtfID.setText(add1);
                String add2 = rs.getString("spiergroep");
                jtfSpiergroep.setText(add2);
                String add3 = rs.getString("oefening");
                jtfOefening.setText(add3);
                String add4 = rs.getString("categorie");
                jtfCategorie.setText(add4);
                byte[] imagedata = rs.getBytes("plaatje");
                format = new ImageIcon(imagedata);
                jlPlaatje.setIcon(format);
            }
        } catch (Exception ex) {
            try {
                int row = Table_Oefeningen.getSelectedRow();
                String tableClick = (Table_Oefeningen.getModel().getValueAt(row, 0).toString());
                String sql = "SELECT * FROM oefeningen WHERE spiergroep='" + tableClick + "'";
                pst = con.prepareStatement(sql);
                rs = pst.executeQuery();
                if (rs.next()) {
                    String add1 = rs.getString("ID");
                    jtfID.setText(add1);
                    String add2 = rs.getString("spiergroep");
                    jtfSpiergroep.setText(add2);
                    String add3 = rs.getString("oefening");
                    jtfOefening.setText(add3);
                    String add4 = rs.getString("categorie");
                    jtfCategorie.setText(add4);
                    jlPlaatje.setIcon(null);
                }
            } catch (Exception ex1) {
                JOptionPane.showMessageDialog(null, ex1);
            }
        }
    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.dialog.JDlgProjectCreate.java

/**
 * This method initializes jTextFieldNewProjectName   
 *    //from w w  w .  j  a v a  2s  .  c o  m
 * @return javax.swing.JTextField   
 */
private JTextField getJTextFieldNewProjectName() {
    if (jTextFieldNewProjectName == null) {
        jTextFieldNewProjectName = new JTextField();
        jTextFieldNewProjectName.setText(ProjectNamePolicy.getProjectNamePrefix());
        jTextFieldNewProjectName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent e) {
                setButtonState();
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    eventHandler.handleEvent(EventHandler.BTN_CHECK);
                } else {
                    jTextFieldNewProjectName.setToolTipText(jTextFieldNewProjectName.getText());
                }
            }
        });
    }
    return jTextFieldNewProjectName;
}

From source file:uk.ac.liverpool.narrative.SolutionGraph.java

/**
 * @param template/*from  w ww . j  av  a2s .  com*/
 * @param out
 * @param in
 * @param current
 * @return
 * @throws IOException
 */
private StringBuilder mainLoop(final Template template, final JTextArea out, final JTextField in,
        STRIPSState current) throws IOException {
    Collection<Action> aa = ggraph.getOutEdges(current);
    StringBuilder ssf = new StringBuilder();
    if (aa == null) {
        out.append("No action from the start?\n");
        return ssf;
    }

    do {

        if (aa.size() == 1) {
            Action a = aa.iterator().next();
            out.append(actionToString(template, a));
            ssf.append(actionToString(template, a));
            if (a != null) {
                current = ggraph.getOpposite(current, a);

            }
        } else if (aa.size() > 1) {
            int n = 0;
            final Map<Integer, Action> hm = new MapWrapper<Integer, Action>();
            out.append("   Please select the next action: " + "\n");
            Iterator<Action> it = aa.iterator();
            while (it.hasNext()) {
                n++;
                Action a = it.next();
                out.append("   " + n + ") " + actionToString(template, a));
                hm.put(n, a);
            }
            out.append("" + "\n");
            final STRIPSState c2 = current;
            in.addKeyListener(new KeyAdapter() {
                @Override
                public void keyReleased(KeyEvent e) {
                    if (e.getKeyCode() != KeyEvent.VK_ENTER)
                        return;
                    int a = 0;
                    String s = in.getText();
                    try {
                        a = Integer.parseInt(s);
                    } catch (Exception x) {

                    }
                    try {
                        a = Integer.parseInt(s);
                        Action a2 = hm.get(a);
                        if (a2 != null) {
                            out.append(actionToString(template, a2));
                            in.removeKeyListener(this);
                            in.setText("");
                            mainLoop(template, out, in, ggraph.getOpposite(c2, a2));
                        }

                    } catch (Exception x) {
                        return;
                    }
                    super.keyReleased(e);
                }
            });
            return ssf;
        } else {
            break;
        }

        aa = ggraph.getOutEdges(current);
    } while (aa.size() > 0);
    out.append("The end");
    return ssf;
}

From source file:ucar.unidata.idv.control.chart.ChartHolder.java

/**
 * Handle event//from  w ww  . java2 s .c o m
 *
 * @param e The event
 */
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        panPlot(true);
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        panPlot(false);
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        upDownPlot(true);
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        upDownPlot(false);
    } else if ((e.getKeyCode() == KeyEvent.VK_R) && e.isControlDown()) {
        chartPanel.restoreAutoBounds();
    } else {
        //            super.keyPressed(e);
    }
}