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.emental.mindraider.ui.dialogs.AddTripletJDialog.java

/**
 * Constructor./*from   www  .  ja  v  a 2s .c  o  m*/
 */
public AddTripletJDialog() {
    super("Add Triplet");

    JPanel framePanel = new JPanel();
    framePanel.setLayout(new GridLayout(4, 1));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(" Predicate: "));

    predicateNs = new JTextField(30);
    predicateNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    predicateNs.selectAll();
    p.add(predicateNs);
    p.add(new JLabel("#"));
    predicateLocalName = new JTextField(15);
    p.add(predicateLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(" Object: "));

    objectNs = new JTextField(30);
    objectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    objectNs.selectAll();
    p.add(objectNs);
    p.add(new JLabel("#"));
    objectLocalName = new JTextField(15);
    objectLocalName.grabFocus();
    objectLocalName.selectAll();
    objectLocalName.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                createTriplet();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });

    p.add(objectLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    literalCheckBox = new JCheckBox("literal", false);
    p.add(literalCheckBox);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton("Add");
    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            createTriplet();
        }
    });

    JButton cancelButton = new JButton("Cancel");
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            AddTripletJDialog.this.dispose();
        }
    });
    framePanel.add(p);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);

    addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            getObjectLocalName().requestFocusInWindow();
        }
    });
}

From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java

public void onReaderListKeyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER && !fileChooser.hasSelectedFile()) {
        fileChooser.askForFile();/*w w w  .  j a  va2  s. com*/
        e.consume();
    }
}

From source file:client.InterfaceSalon.java

private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER && btnSalon.isEnabled()) {
        c.creerSalon(jTextField1.getText(), jTextField2.getText());
    }//from w w w .  j  a  v  a 2s  .  c  om
}

From source file:client.InterfaceSalon.java

private void jTextField2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER && btnSalon.isEnabled()) {
        c.creerSalon(jTextField1.getText(), jTextField2.getText());
    }//from  ww w.  j  a  v  a 2s .c  om
}

From source file:playground.sergioo.networkBusLaneAdder2012.gui.BusLaneAdderPanel.java

@Override
public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
    case KeyEvent.VK_DELETE:
        ((NetworkTwoNodesPainterManager) ((NetworkPainter) getActiveLayer().getPainter())
                .getNetworkPainterManager()).clearNodesSelection();
        break;//from w  w w  .  j a v a 2 s.  co  m
    }
    busLaneAdderWindow.setVisible(true);
    busLaneAdderWindow.repaint();
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.fenetRoughness.CreatePolygonWidgetWrapper.java

@Override
public void keyPressed(final KeyEvent e) {
    switch (e.getKeyCode()) {
    case KeyEvent.VK_BACK_SPACE:
        m_builder.removeLastPoint();//from ww w.j  av  a2 s .  c  o m
        repaintMap();
        break;

    case KeyEvent.VK_ESCAPE:
        reset();
        break;
    }
}

From source file:org.uecide.About.java

public About(Editor e) {
    editor = e;/*from w w  w  . j ava 2 s  .c o  m*/
    frame = new JDialog(editor, JDialog.ModalityType.APPLICATION_MODAL);
    mainContainer = new JPanel();
    mainContainer.setLayout(new BorderLayout());
    frame.add(mainContainer);

    int imageWidth = 0;

    try {
        URL loc = About.class.getResource("/org/uecide/icons/about.png");
        image = ImageIO.read(loc);
        imageWidth = image.getWidth();
        JLabel picLabel = new JLabel(new ImageIcon(image));

        mainContainer.add(picLabel, BorderLayout.NORTH);
    } catch (Exception ex) {
        Base.error(ex);
    }

    infoScroll = new JScrollPane();
    infoScroll.setPreferredSize(new Dimension(imageWidth, 150));

    info = new JTextPane();
    info.setContentType("text/html");
    infoScroll.setViewportView(info);

    info.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    info.setEditable(false);
    info.setBackground(new Color(0, 0, 0));
    info.setForeground(new Color(0, 255, 0));
    Font f = info.getFont();

    info.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e.getDescription().equals("uecide://close")) {
                    frame.dispose();
                    return;
                }
                Base.openURL(e.getURL().toString());
            }
        }
    });

    HTMLEditorKit kit = new HTMLEditorKit();
    info.setEditorKit(kit);
    StyleSheet css = kit.getStyleSheet();

    css.addRule("body {color: #88ff88; font-family: Arial,Helvetica,Sans-Serif;}");
    css.addRule("a {color: #88ffff;}");
    css.addRule("a:visited {color: #00aaaa;}");
    Document doc = kit.createDefaultDocument();
    info.setDocument(doc);

    info.setText(generateInfoData());

    info.setCaretPosition(0);
    mainContainer.add(infoScroll, BorderLayout.CENTER);

    frame.pack();

    Dimension mySize = frame.getSize();

    Dimension eSize = editor.getSize();
    Point ePos = editor.getLocation();
    frame.setLocation(new Point(ePos.x + (eSize.width / 2) - mySize.width / 2,
            ePos.y + (eSize.height / 2) - mySize.height / 2));

    frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent ev) {
        }

        public void keyPressed(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) {
                frame.dispose();
            }
        }

        public void keyReleased(KeyEvent ev) {
        }
    });

    frame.setVisible(true);
}

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {
    int id = e.getID();
    String keyString;//from w  ww  .  j ava  2  s. c o m
    if (id == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {
    int id = e.getID();
    String keyString;/*from  www  . ja v  a  2 s. c  om*/
    if (id == KeyEvent.KEY_PRESSED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {
    int id = e.getID();
    String keyString;//from  w  ww  .  j  av a  2  s  .  c o  m
    if (id == KeyEvent.KEY_RELEASED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}