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:vista.Venta.java

private void txtEntradaOcultaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEntradaOcultaKeyPressed
    // TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        if (this.onLogin) {
            this.desbloaquear();
        } else {/*from w ww .j a v  a 2  s. co m*/

        }
    }
}

From source file:vista.Venta.java

private void txtEntradaEfectivoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEntradaEfectivoKeyPressed
    // TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        this.calcularRecaudacion();
        this.calcularVuelto();
    }/*from ww  w.  j  a v a 2s. co  m*/
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        this.formPagoOff();
    }
}

From source file:com.jcraft.weirdx.DDXWindowImpSwing.java

public void keyPressed(KeyEvent e) {
    if (!window.isMapped())
        return;/*www  .j  a  va2s .c  o m*/

    if (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK) {
        if (clck_toggle) {
            clck_toggle = false;
            XWindow.sprite.hot.state &= (~1);
        } else {
            clck_toggle = true;
            XWindow.sprite.hot.state |= 1;
        }
    }

    // Easter Egg...
    if (window == window.screen.root && 0 < px && px < 3 && 0 < py && py < 3) {
        if (((e.getModifiers() & InputEvent.CTRL_MASK) != 0) && e.getKeyCode() == KeyEvent.VK_W) {
            LogoImage.toggle();
        } else if (((e.getModifiers() & InputEvent.CTRL_MASK) != 0) && e.getKeyCode() == KeyEvent.VK_E) {
            XWindow.printWindowTree(window.screen.root);
        }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_I){
        //   if(WeirdX.acontext!=null){
        //     acontext.showDocument(new URL("http://www.weirdx.org/"), "_blank");
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_R){
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_D){
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_X){
        //   }
        //    }
    }

    XWindow dest = XWindow.sprite.win;
    if (XWindow.focus.window != null)
        dest = XWindow.focus.window;

    if (window.screen.windowmode != 0 && dest == window.screen.root) {
        if (XWindow.focus.window != null)
            dest = XWindow.sprite.win;
        else
            dest = window;
    }

    if (dest.client == null)
        return;

    int kcode = Keymap.km.getCode(e);
    event.mkKeyPress(kcode, window.screen.rootId, dest.id, 0, XWindow.sprite.hot.x, XWindow.sprite.hot.y,
            XWindow.sprite.hot.x - window.x, XWindow.sprite.hot.y - window.y, XWindow.sprite.hot.state, 1);

    try {
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(dest, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }

    kcode = e.getKeyCode();
    int state = XWindow.sprite.hot.state;
    if (kcode == KeyEvent.VK_CONTROL) {
        if ((state & 4) == 0)
            state |= 4;
    } else if (kcode == KeyEvent.VK_SHIFT) {
        if ((state & 1) == 0)
            state |= 1;
    } else if (kcode == KeyEvent.VK_ALT) {
        if ((state & 8) == 0)
            state |= 8;
    } else if (kcode == VK_ALT_GRAPH) {
        if ((state & ALT_GR_MASK) == 0)
            state |= ALT_GR_MASK;
    }
    // check for windoze ALT_GR (is equal to ALT+CONTROL), by Marcus.
    if ((state & 12) == 12) {
        state -= 12;
        state |= ALT_GR_MASK;
    }

    XWindow.sprite.hot.state = state;
}

From source file:Interfaz.rubiktimer.java

@Override
public void keyPressed(KeyEvent ke) {
    System.out.println("Pulsado");
    if (verifi != 0) {
        if (ke.getKeyCode() == KeyEvent.VK_SPACE) {
            switch (verificador) {
            case 1:
                // COMIENZA SOLVE
                t_atras.stop();//from  w w  w.  j a  va 2  s .c o m
                t.start();
                actualizarLabel();
                verificador = 2;
                break;
            case 0:
                // CONTEO ATRAS
                t_atras.start();
                actualizarLabel_atras();
                verificador = 1;
                break;
            case 2:
                // DETENER SOLVE
                t.stop();
                segundos_atras = aux;
                minutos = 0.00;
                if (m > 0) {
                    minutos = 60 * (double) m;
                }

                cent_seg = (double) cs / 100;
                tiempo = (double) s + cent_seg + minutos;
                String tiempo_str = (m <= 9 ? "0" : "") + m + ":" + (s <= 9 ? "0" : "") + s + "."
                        + (cs <= 9 ? "0" : "") + cs;
                JLabel nuevo_tiempo = new JLabel(tiempo_str);
                nuevo_tiempo.setFont(new java.awt.Font("Lucida Sans", 0, 25));
                nuevo_tiempo.setForeground(Color.yellow);
                JButton eliminar = new JButton("Eliminar Tiempo");
                eliminar.setFocusable(false);
                JButton Penalizacion = new JButton("Penalizacion +2");
                Penalizacion.setFocusable(false);
                JButton DNF = new JButton("DNF");
                DNF.setFocusable(false);
                if (tipoCubScramble == 0) {
                    Scramble_parametro = Scramble;
                } else {
                    Scramble_parametro = Scramble4x4;
                }
                JLabel nuevo_Scramble = new JLabel(Scramble_parametro);
                nuevo_Scramble.setFont(new java.awt.Font("Lucida Sans", 0, 15));
                nuevo_Scramble.setForeground(Color.white);
                panel.add(nuevo_tiempo);
                panel.add(nuevo_Scramble);
                panel.add(eliminar);
                panel.add(Penalizacion);
                panel.add(DNF);
                panel.updateUI();

                listaT.insertarCabezaLista(tiempo, tiempo_str, Scramble_parametro); //lista todos los solves
                lista5mej.insertarNUMmejores(5, lista5mej, tiempo, nuevo_tiempo, tiempo_str,
                        Scramble_parametro); //lista 5 mejores 
                lista10mej.insertarNUMmejores(10, lista10mej, tiempo, nuevo_tiempo, tiempo_str,
                        Scramble_parametro); // lista 10 mejores
                actualizarGrafica();

                funcionalidad_botones(nuevo_tiempo, nuevo_Scramble, eliminar, Penalizacion, DNF);

                System.out.println("\tLista Generada 3x3");
                listaT3x3.visualizar();
                System.out.println("\tLista Generada 4x4");
                listaT4x4.visualizar();
                System.out.println("\tLista Generada 2x2");
                listaT2x2.visualizar();
                System.out.println("\tLista 5 mejores");
                lista5mej.visualizar();
                System.out.println("\tLista 10 mejores");
                lista10mej.visualizar();

                actualizar_estad();
                verificador = 0;
                m = 0;
                s = 0;
                cs = 0;
                //actualizarLabel();
                if (tipoCubScramble == 0) {
                    actualizarScramble();
                } else {
                    actualizarScramble4x4();
                }
                actualizar_estad();
                actualizarGrafica();
                verificador = 0;
                break;
            default:
                break;
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Primero se tiene que escoger una categoria de cubo",
                "Escoger una Categoria", JOptionPane.INFORMATION_MESSAGE);
    }
}

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

/**
 * Patient search listener./*  ww w .j ava  2s .  com*/
 */
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:com.jcraft.weirdx.DDXWindowImp.java

public void keyPressed(KeyEvent e) {
    if (!window.isMapped())
        return;//from w  w  w. ja  va  2 s . c  o m

    if (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK) {
        if (clck_toggle) {
            clck_toggle = false;
            XWindow.sprite.hot.state &= (~1);
        } else {
            clck_toggle = true;
            XWindow.sprite.hot.state |= 1;
        }
    }

    // Easter Egg...
    if (window == window.screen.root && 0 < px && px < 3 && 0 < py && py < 3) {
        if (((e.getModifiers() & InputEvent.CTRL_MASK) != 0) && e.getKeyCode() == KeyEvent.VK_W) {
            LogoImage.toggle();
        } else if (((e.getModifiers() & InputEvent.CTRL_MASK) != 0) && e.getKeyCode() == KeyEvent.VK_E) {
            XWindow.printWindowTree(window.screen.root);
        }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_I){
        //   if(WeirdX.acontext!=null){
        //     acontext.showDocument(new URL("http://www.weirdx.org/"), "_blank");
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_R){
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_D){
        //   }
        //    }
        //    else if(((e.getModifiers() & InputEvent.CTRL_MASK)!=0) &&
        //         e.getKeyCode()==KeyEvent.VK_X){
        //   }
        //    }
    }

    XWindow dest = XWindow.sprite.win;
    if (XWindow.focus.window != null)
        dest = XWindow.focus.window;

    if (window.screen.windowmode != 0 && dest == window.screen.root) {
        if (XWindow.focus.window != null)
            dest = XWindow.sprite.win;
        else
            dest = window;
    }

    if (dest.client == null)
        return;

    int kcode = Keymap.km.getCode(e);
    event.mkKeyPress(kcode, window.screen.rootId, dest.id, 0, XWindow.sprite.hot.x, XWindow.sprite.hot.y,
            XWindow.sprite.hot.x - window.x, XWindow.sprite.hot.y - window.y, XWindow.sprite.hot.state, 1);

    try {
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(dest, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }

    kcode = e.getKeyCode();
    int state = XWindow.sprite.hot.state;
    if (kcode == KeyEvent.VK_CONTROL) {
        if ((state & 4) == 0)
            state |= 4;
    } else if (kcode == KeyEvent.VK_SHIFT) {
        if ((state & 1) == 0)
            state |= 1;
    } else if (kcode == KeyEvent.VK_ALT) {
        if ((state & 8) == 0)
            state |= 8;
    } else if (kcode == VK_ALT_GRAPH) {
        if ((state & ALT_GR_MASK) == 0)
            state |= ALT_GR_MASK;
    }
    // check for windoze ALT_GR (is equal to ALT+CONTROL)
    if ((state & 12) == 12) {
        state -= 12;
        state |= ALT_GR_MASK;
    }
    XWindow.sprite.hot.state = state;
}

From source file:SIFT_Volume_Stitching.java

public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_F1) && (e.getSource() instanceof TextField)) {
    }/*  w  w w  . ja va  2 s  .c o  m*/
}

From source file:brainflow.app.toplevel.BrainFlow.java

private void initializeToolBar() {

    CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar");

    mainToolbarGroup.bind(getApplicationFrame());

    ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group");
    interpToggleGroup.bind(getApplicationFrame());

    bindCommand(new OpenImageCommand(), true);
    bindCommand(new SnapshotCommand(), true);
    bindCommand(new NewCanvasCommand(), true);

    bindCommand(new CreateAxialViewCommand(), true);
    bindCommand(new CreateSagittalViewCommand(), true);

    bindCommand(new CreateCoronalViewCommand(), true);
    bindCommand(new CreateMontageViewCommand(), true);
    bindCommand(new CreateVerticalOrthogonalCommand(), true);

    bindCommand(new CreateHorizontalOrthogonalCommand(), true);
    bindCommand(new CreateTriangularOrthogonalCommand(), true);

    CommandGroup orthoGroup = new CommandGroup("ortho-view-group");
    orthoGroup.bind(getApplicationFrame());

    final NextSliceCommand nextSliceCommand = new NextSliceCommand();
    bindCommand(nextSliceCommand, false);

    final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand();
    bindCommand(previousSliceCommand, false);

    bindCommand(new PageBackSliceCommand(), true);
    bindCommand(new PageForwardSliceCommand(), true);

    bindCommand(new IncreaseContrastCommand(), true);
    bindCommand(new DecreaseContrastCommand(), true);

    bindCommand(new NearestInterpolationToggleCommand(), true);
    bindCommand(new LinearInterpolationToggleCommand(), true);
    bindCommand(new CubicInterpolationToggleCommand(), true);
    bindCommand(new ToggleAxisLabelCommand(), true);
    bindCommand(new ToggleCrossCommand(), true);

    //JToolBar mainToolbar = mainToolbarGroup.createToolBar();
    final CommandBar mainToolbar = new CommandBar();
    // for nimbus look and feel
    mainToolbar.setPaintBackground(false);
    // for nimbus look and feel

    mainToolbar.setBorder(new EmptyBorder(0, 0, 0, 0));
    final ButtonFactory buttonFactory = createToolBarButtonFactory();

    mainToolbarGroup.visitMembers(new GroupVisitor() {
        @Override/*www  . j a v a  2s  . co  m*/
        public void visit(ActionCommand actionCommand) {
            JideButton jb = new JideButton(actionCommand.getActionAdapter());
            jb.setButtonStyle(JideButton.TOOLBAR_STYLE);
            jb.setText("");
            mainToolbar.add(jb);
        }

        @Override
        public void visit(CommandGroup commandGroup) {
            JComponent jc = commandGroup.createButton(buttonFactory);
            mainToolbar.add(jc);
        }
    });

    mainToolbar.setKey("toolbar");
    brainFrame.getDockableBarManager().addDockableBar(mainToolbar);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {

            if (event.getID() == KeyEvent.KEY_PRESSED) {

                KeyEvent ke = (KeyEvent) event;
                Component comp = ke.getComponent();
                if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if (/*view.hasFocus() || */ parentIsImageView(comp)) {
                        previousSliceCommand.execute();
                    }
                } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if ( /*view.hasFocus() */ parentIsImageView(comp)) {
                        nextSliceCommand.execute();
                    } else {
                        System.out.println("no focus");
                    }
                }

            }

        }
    }, AWTEvent.KEY_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == MouseEvent.MOUSE_RELEASED) {
                MouseEvent me = (MouseEvent) event;
                if (me.isPopupTrigger()) {
                    showActionMenu(me);
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);

}

From source file:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java

private JPanel createPanel() {
    treeModel = createTreeModel();/*  ww w.ja  v  a2 s .  c  o m*/
    tree.setModel(treeModel);
    setColors(tree);
    tree.setRootVisible(false);

    //      for (int i = 0; i < tree.getRowCount(); i++) {
    //         tree.expandRow(i);
    //      }

    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                final WorkspaceTreeNode selection = getSelectedNode();
                if (selection != null) {
                    deleteResource(selection);
                }
            } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                refreshWorkspace(null);
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
                if (path != null) {
                    final WorkspaceTreeNode selected = (WorkspaceTreeNode) path.getLastPathComponent();
                    final IAssemblyProject project = getProject(selected);
                    try {
                        if (project != null) {
                            onTreeNodeLeftClick(project, selected);
                        } else {
                            System.err.println("Unable to locate project for " + selected);
                        }
                    } catch (IOException e1) {
                        LOG.error("mouseClicked(): Internal error", e1);
                    }
                }
            }
        }
    });

    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

        }
    };

    tree.getSelectionModel().addTreeSelectionListener(selectionListener);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        public Color getTextSelectionColor() {
            return Color.GREEN;
        };

        public java.awt.Color getTextNonSelectionColor() {
            return Color.GREEN;
        };

        public Color getBackgroundSelectionColor() {
            return Color.BLACK;
        };

        public Color getBackgroundNonSelectionColor() {
            return Color.BLACK;
        };

        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {

            java.awt.Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                    row, hasFocus);

            String label = value.toString();
            Color color = getTextColor();
            if (value instanceof WorkspaceTreeNode) {
                if (value instanceof ProjectNode) {
                    final ProjectNode projectNode = (ProjectNode) value;
                    final IAssemblyProject project = projectNode.getValue();
                    label = project.getName();

                    if (project.isClosed()) {
                        color = Color.LIGHT_GRAY;
                    } else {
                        if (projectNode.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                    }
                } else if (value instanceof FileNode) {
                    FileNode fn = (FileNode) value;
                    label = fn.getValue().getName();
                    switch (fn.type) {
                    case DIRECTORY:
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    case OBJECT_FILE:
                        label = "[O] " + label;
                        break;
                    case EXECUTABLE:
                        label = "[E] " + label;
                        break;
                    case SOURCE_CODE:
                        label = "[S] " + label;
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    default:
                        // ok
                    }
                }
            }
            setForeground(color);
            setText(label);
            return result;
        };

    });

    setupPopupMenu();

    final JScrollPane pane = new JScrollPane(tree);
    setColors(pane);

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());
    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    setColors(result);
    result.add(pane, cnstrs);
    return result;
}

From source file:Filter3dTest.java

private GameAction getKeyAction(KeyEvent e) {
    int keyCode = e.getKeyCode();
    if (keyCode < keyActions.length) {
        return keyActions[keyCode];
    } else {/*from  w ww.  j av a 2  s .c  o m*/
        return null;
    }
}