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:com.mirth.connect.client.ui.ChangePasswordDialog.java

private void checkAndTriggerFinishButton(java.awt.event.KeyEvent evt) {
    if (StringUtils.isBlank(String.valueOf(password.getPassword()))
            || StringUtils.isBlank(String.valueOf(confirmPassword.getPassword()))) {
        setFinishButtonEnabled(false);/* w  w w.  j a  v a2 s. c  o  m*/
    } else {
        setFinishButtonEnabled(true);

        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            finishButtonActionPerformed(null);
        }
    }
}

From source file:org.ut.biolab.medsavant.client.view.LoginView.java

private void databaseFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_databaseFieldKeyPressed
    int key = evt.getKeyCode();
    if (key == KeyEvent.VK_ENTER) {
        loginUsingEnteredUsernameAndPassword();
    }//from w  w w .  j a v a 2  s  . com
}

From source file:org.ut.biolab.medsavant.client.view.LoginView.java

private void passwordFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_passwordFieldKeyPressed
    int key = evt.getKeyCode();
    if (key == KeyEvent.VK_ENTER) {
        loginUsingEnteredUsernameAndPassword();
    }/*from  w w w.  j a v  a 2  s .com*/
}

From source file:uk.co.markfrimston.tasktree.Main.java

public Main(TaskTree taskTree) {
    super();//ww w. j  a v  a2  s.c  om

    this.taskTree = taskTree;

    this.setTitle("Task Tree");
    this.setSize(new Dimension(300, 500));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel quickInPanel = new JPanel(new BorderLayout());
    this.quickIn = new JTextArea();
    this.quickIn.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ENTER) {
                String newText = quickIn.getText().trim();
                if (newText != null && newText.length() > 0) {
                    addTask(Main.this.taskTree.getRoot(), 0, newText, true);
                    try {
                        Main.this.taskTree.changesMade();
                    } catch (Exception e) {
                        error(e.getMessage());
                    }
                }
                quickIn.setText("");
            }
        }
    });
    this.quickIn.setPreferredSize(new Dimension(300, 75));
    this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input"));
    quickInPanel.add(this.quickIn, BorderLayout.CENTER);
    this.syncButton = new JButton("Sync");
    this.syncButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new SyncThread(Main.this).start();
        }
    });
    quickInPanel.add(this.syncButton, BorderLayout.EAST);
    this.getContentPane().add(quickInPanel, BorderLayout.NORTH);

    this.tree = new JTree(taskTree.getTreeModel());
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object newVal = htmlFilter(String.valueOf(node.getUserObject()));
            if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) {
                DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf();
                newVal = htmlFilter(String.valueOf(node.getUserObject()))
                        + " <span style='color:silver;font-style:italic'>" + "("
                        + String.valueOf(firstLeaf.getUserObject()) + ")</span>";
            }
            newVal = "<html>" + newVal + "</html>";

            return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus);
        }
    };
    ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif"));
    renderer.setLeafIcon(bulletIcon);
    renderer.setOpenIcon(bulletIcon);
    renderer.setClosedIcon(bulletIcon);
    renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
    this.tree.setCellRenderer(renderer);
    this.tree.setRootVisible(false);
    this.tree.setShowsRootHandles(true);
    this.tree.addMouseListener(new MouseAdapter() {
        protected void doSelectRow(MouseEvent arg0) {
            int row = tree.getRowForLocation(arg0.getX(), arg0.getY());
            if (row != -1) {
                tree.setSelectionRow(row);
                if (arg0.isPopupTrigger()) {
                    popup.show(tree, arg0.getX(), arg0.getY());
                }
            }
        }

        public void mousePressed(MouseEvent arg0) {
            doSelectRow(arg0);
        }

        public void mouseReleased(MouseEvent arg0) {
            doSelectRow(arg0);
        }
    });
    JScrollPane treeScroll = new JScrollPane(tree);
    treeScroll.setBorder(BorderFactory.createTitledBorder("Task List"));
    this.getContentPane().add(treeScroll, BorderLayout.CENTER);

    this.popup = new JPopupMenu();
    JMenuItem addBefore = new JMenuItem("Add Before");
    addBefore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = parent.getIndex(selected);
            promptAndInsert(parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(addBefore);
    JMenuItem addAfter = new JMenuItem("Add After");
    addAfter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = parent.getIndex(selected) + 1;
            promptAndInsert(parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(addAfter);
    JMenuItem addNested = new JMenuItem("Add Nested");
    addNested.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            int pos = selected.getChildCount();
            promptAndInsert(selected, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                ex.getMessage();
            }
        }
    });
    this.popup.add(addNested);
    this.popup.add(new JSeparator());
    JMenuItem moveTop = new JMenuItem("Move to Top");
    moveTop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            moveTask(selected, parent, 0);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveTop);
    JMenuItem moveUp = new JMenuItem("Move Up");
    moveUp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = Math.max(parent.getIndex(selected) - 1, 0);
            moveTask(selected, parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveUp);
    JMenuItem moveDown = new JMenuItem("Move Down");
    moveDown.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1);
            moveTask(selected, parent, pos);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveDown);
    JMenuItem moveBottom = new JMenuItem("Move to Bottom");
    moveBottom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent();
            moveTask(selected, parent, parent.getChildCount() - 1);
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(moveBottom);
    this.popup.add(new JSeparator());
    JMenuItem rename = new JMenuItem("Edit");
    rename.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selected = getSelectedNode();
            String newText = prompt((String) selected.getUserObject());
            if (newText != null && newText.length() > 0) {
                selected.setUserObject(newText);
                Main.this.taskTree.getTreeModel().reload(selected);
                try {
                    Main.this.taskTree.changesMade();
                } catch (Exception ex) {
                    error(ex.getMessage());
                }
            }
        }
    });
    this.popup.add(rename);
    JMenuItem delete = new JMenuItem("Delete");
    delete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            promptAndRemove(getSelectedNode());
            try {
                Main.this.taskTree.changesMade();
            } catch (Exception ex) {
                error(ex.getMessage());
            }
        }
    });
    this.popup.add(delete);

    this.setVisible(true);

    loadConfig();
    load();

    syncButton.setVisible(this.taskTree.hasSyncCapability());
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java

public MaterialIconsImporter(@Nullable final Project project, Module module) {
    super(project, true);
    this.project = project;

    setTitle("Material Icons Importer");
    setResizable(false);/*from w w w  .  j  av a  2 s. c o m*/

    AndroidResourcesHelper.initResourceBrowser(project, module, "Select res root", this.resRoot);
    assetRoot = SettingsHelper.getAssetPath(IconPack.MATERIAL_ICONS);

    getHelpAction().setEnabled(true);

    fillCategories();
    fillAssets();
    fillSizes();
    fillColors();

    categorySpinner.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            fillAssets();
            updateImage();
        }
    });
    AssetSpinnerRenderer renderer = new AssetSpinnerRenderer();
    //noinspection GtkPreferredJComboBoxRenderer
    assetSpinner.setRenderer(renderer);
    assetSpinner.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            fillSizes();
            updateImage();
        }
    });
    sizeSpinner.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String size = (String) sizeSpinner.getSelectedItem();
            if (size != null) {
                lastSelectedSize = size;
            }
            fillColors();
            updateImage();
        }
    });
    colorSpinner.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            String color = (String) colorSpinner.getSelectedItem();
            if (color != null) {
                lastSelectedColor = color;
            }
            updateImage();
        }
    });

    resExportName.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent keyEvent) {
            super.keyTyped(keyEvent);
            if (!exportNameChanged && keyEvent != null && keyEvent.getKeyCode() > -1) {
                exportNameChanged = true;
            }
        }

        @Override
        public void keyPressed(KeyEvent keyEvent) {
            super.keyPressed(keyEvent);
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            super.keyReleased(keyEvent);
        }
    });
    imageContainer.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            super.componentResized(e);
            updateImage();
        }
    });

    init();
}

From source file:org.apache.cayenne.modeler.CayenneModelerFrame.java

/** Initializes main toolbar. */
protected void initToolbar() {
    JToolBar toolBar = new JToolBar();

    toolBar.add(getAction(NewProjectAction.class).buildButton());
    toolBar.add(getAction(OpenProjectAction.class).buildButton());
    toolBar.add(getAction(SaveAction.class).buildButton());

    toolBar.addSeparator();//from w ww .j av a  2 s. c  om
    toolBar.add(getAction(RemoveAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CutAction.class).buildButton());
    toolBar.add(getAction(CopyAction.class).buildButton());
    toolBar.add(getAction(PasteAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(UndoAction.class).buildButton());
    toolBar.add(getAction(RedoAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateNodeAction.class).buildButton());
    toolBar.add(getAction(CreateDataMapAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateDbEntityAction.class).buildButton());
    toolBar.add(getAction(CreateProcedureAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateObjEntityAction.class).buildButton());
    toolBar.add(getAction(CreateEmbeddableAction.class).buildButton());
    toolBar.add(getAction(CreateQueryAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(NavigateBackwardAction.class).buildButton());
    toolBar.add(getAction(NavigateForwardAction.class).buildButton());

    JPanel east = new JPanel(new BorderLayout()); // is used to place search feature
    // components the most right on a
    // toolbar
    final JTextField findField = new JTextField(10);
    findField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() != KeyEvent.VK_ENTER) {
                findField.setBackground(Color.white);
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    findField.setAction(getAction(FindAction.class));
    JLabel findLabel = new JLabel("Search:");
    findLabel.setLabelFor(findField);
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        public void eventDispatched(AWTEvent event) {

            if (event instanceof KeyEvent) {

                if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                        && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) {
                    findField.requestFocus();
                }
            }
        }

    }, AWTEvent.KEY_EVENT_MASK);

    JPanel box = new JPanel(); // is used to place label and text field one after
    // another
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(findLabel);
    box.add(findField);
    east.add(box, BorderLayout.EAST);
    toolBar.add(east);

    getContentPane().add(toolBar, BorderLayout.NORTH);
}

From source file:stockit.ClientFrame.java

private void StockInfoTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_StockInfoTableKeyPressed
    //up arrow (40), down arrow (38), enter-key (10)
    if (evt.getKeyCode() == 40 || evt.getKeyCode() == 38 || evt.getKeyCode() == 10) {
        setSelectedStock();//  w ww  .j  av  a2s.  c  om
    }
}

From source file:stockit.ClientFrame.java

private void StockInfoTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_StockInfoTableKeyReleased
    //up arrow (40), down arrow (38), enter-key (10)
    if (evt.getKeyCode() == 40 || evt.getKeyCode() == 38 || evt.getKeyCode() == 10) {
        setSelectedStock();//  w  w w.j a  va 2s .c  o m
    }
}

From source file:com.petersoft.advancedswing.enhancedtextarea.EnhancedTextArea.java

private void jSearchTextFieldKeyReleased(KeyEvent evt) {
    String text = jTextArea.getText().toLowerCase();
    String searchPattern = jSearchTextField.getText().toLowerCase();

    if (evt != null && evt.getKeyCode() == 10) {
        int caretPosition = jTextArea.getCaretPosition();
        boolean found = false;
        for (int j = caretPosition + 1; j < text.length() - searchPattern.length(); j += 1) {
            if (searchPattern.equals(text.substring(j, j + searchPattern.length()))) {
                jTextArea.setCaretPosition(j);
                found = true;//  ww w . j  av  a 2  s  . c om
                break;
            }
        }
        if (!found) {
            for (int j = 0; j < caretPosition; j++) {
                if (searchPattern.equals(text.substring(j, j + searchPattern.length()))) {
                    jTextArea.setCaretPosition(j);
                    break;
                }
            }
        }
    }

    if (searchPattern.length() > 0) {
        Highlighter h = jTextArea.getHighlighter();
        DefaultHighlightPainter painter = new DefaultHighlightPainter(Color.YELLOW);
        DefaultHighlightPainter painter2 = new DefaultHighlightPainter(Color.RED);
        h.removeAllHighlights();

        int count = 0;
        boolean isCurrent = false;
        for (int j = 0; j < text.length(); j += 1) {
            if (j < text.length() - searchPattern.length()
                    && searchPattern.equals(text.substring(j, j + searchPattern.length()))) {
                count++;
                try {
                    if (j >= jTextArea.getCaretPosition() && isCurrent == false) {
                        h.addHighlight(j, j + searchPattern.length(), painter2);
                        isCurrent = true;
                    } else {
                        h.addHighlight(j, j + searchPattern.length(), painter);
                    }
                } catch (BadLocationException ble) {
                }
            }
        }
        jSearchLabel.setText("Match:" + count);
    } else {
        jSearchLabel.setText("");
        Highlighter h = jTextArea.getHighlighter();
        h.removeAllHighlights();
    }
}

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

protected void keyReleasedInternal(KeyEvent ev) {
    //System.out.println(ev);
    if (dbAdapter != null) {
        if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY) {
            /*lookup(getText());
                    /*from   ww  w  .j  a va2s  . co m*/
            if (!foundMatch)
            {
            setText("");
            }*/

            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JMenuItem mi = (JMenuItem) ae.getSource();
                    int inx = 0;
                    for (PickListItemIFace pli : dbAdapter.getList()) {
                        String title = pli.getTitle();
                        if (mi.getText().equals(title)) {
                            setSelectedIndex(inx);
                            break;
                        }
                        inx++;
                    }
                    popupMenu = null;
                }
            };

            String txt = getText();

            int cnt = 0;
            for (PickListItemIFace pli : dbAdapter.getList()) {
                String title = pli.getTitle();
                if (title.length() >= txt.length() && title.startsWith(txt)) {
                    cnt++;
                }
            }

            if (cnt > 0) {
                popupMenu = new JPopupMenu();
                for (PickListItemIFace pli : dbAdapter.getList()) {
                    String title = pli.getTitle();
                    if (title.length() >= txt.length() && title.startsWith(txt)) {
                        JMenuItem mi = new JMenuItem(title);
                        setControlSize(mi);
                        popupMenu.add(mi);
                        mi.addActionListener(al);
                    }
                }
                Point location = getLocation();
                Dimension size = getSize();
                popupMenu.show(this, location.x, location.y + size.height);
            }

        } else if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
            addNewItemFromTextField();

        } else if (ev.getKeyCode() == KeyEvent.VK_END)// || ev.getKeyCode() == KeyEvent.VK_SHIFT)
        {
            setSelectionStart(prevCaretPos);
            setSelectionEnd(getText().length());
        }

        /*else
        {
        char key = ev.getKeyChar();
        if (ev.getKeyCode() == KeyEvent.VK_BACK_SPACE)
        {
            String s = getText();
            if (foundMatch)
            {
                //System.out.println("len ["+s.length()+"]");
                //System.out.println(s+"["+s.substring(0, s.length()-1)+"]");
                
                setText(s.length() == 0 ? "" : s.substring(0, s.length()-1));
                        
            } else
            {
                hasChanged = true;
            }
            return;
                    
        } else if ((!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) && 
                     ev.getKeyCode() != KeyEvent.VK_DELETE)
        {
            if (ev.getKeyCode() == KeyEvent.VK_ENTER) 
            {
                addNewItemFromTextField();
            }
            //System.out.println("Key Code "+ev.getKeyCode()+"  Pos: "+getCaretPosition()+"  Del: "+KeyEvent.VK_DELETE);
                    
            if (ev.getKeyCode() == KeyEvent.VK_END)// || ev.getKeyCode() == KeyEvent.VK_SHIFT)
            {
                setSelectionStart(prevCaretPos);
                setSelectionEnd(getText().length());
            }
            return;
                    
        } else if(ev.getKeyCode() == KeyEvent.VK_DELETE)
        {
            foundMatch = false;
            hasChanged = true;
            return;
        }
        //System.out.println("["+ev.getKeyCode()+"]["+KeyEvent.VK_DELETE+"]");
                
        caretPos = getCaretPosition();
        String text = "";
        try
        {
            text = getText(0, caretPos);
                    
        } catch (Exception ex)
        {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JAutoCompTextField.class, ex);
            ex.printStackTrace();
        }
                
        lookup(text);
        }*/
    }
}