List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:KeyEventDemo.java
protected void displayInfo(KeyEvent e, String s) { String keyString, modString, tmpString, actionString, locationString; //You should only rely on the key char if the event //is a key typed event. int id = e.getID(); if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else {//www . j a va 2s.c om int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiers = e.getModifiersEx(); modString = "modifiers = " + modifiers; tmpString = KeyEvent.getModifiersExText(modifiers); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no modifiers)"; } actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } 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(s + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions[lastShownCompletion]; int end = comp.getSelectionEnd(); comp.select(end, end);//from w w w . j a v a2 s. co m toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() != KeyEvent.VK_SHIFT) { // shift is OK, everyhting else leads to a reset resetAutoCompletion(); } else { LOGGER.debug("Special case: shift pressed. No action."); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java
private void buildTree() { tree = new JTree(new ScriptsTreeModel(roots)); tree.setCellRenderer(new ScriptsTreeCellRenderer()); tree.setRootVisible(false);/*ww w. j ava2 s .c om*/ tree.setShowsRootHandles(true); tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { runScripts(); } } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (!e.isPopupTrigger() && e.getClickCount() == 2) { if (tree.getModel().isLeaf(tree.getSelectionPath().getLastPathComponent())) { runScripts(); } } } @Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } }); }
From source file:com.nbt.TileCanvas.java
protected void keyPressed(KeyEvent e) { final int keyCode = e.getKeyCode(); switch (keyCode) { case KeyEvent.VK_UP: int z = getTileZ(); setTileZ(z - 1);//from w ww. j a va 2 s .c om break; case KeyEvent.VK_DOWN: z = getTileZ(); setTileZ(z + 1); break; case KeyEvent.VK_LEFT: int x = getTileX(); setTileX(x - 1); break; case KeyEvent.VK_RIGHT: x = getTileX(); setTileX(x + 1); break; case KeyEvent.VK_PAGE_UP: int altitude = getAltitude(); setAltitude(altitude + 1); break; case KeyEvent.VK_PAGE_DOWN: altitude = getAltitude(); setAltitude(altitude - 1); break; } updateXYZ(); doRepaint(); save(); }
From source file:nl.ru.ai.projects.parrot.biomav.editor.BehaviorEditor.java
public BehaviorEditor() { ///////// Graph stuff graphViewer.addKeyListener(new KeyListener() { @Override//from w w w .j a v a2s . c o m public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { for (TransitionEdge edge : graphViewer.getPickedEdgeState().getPicked()) { graph.removeEdge(edge); } for (BehaviorVertex vertex : graphViewer.getPickedVertexState().getPicked()) { graph.removeVertex(vertex); } e.consume(); repaint(); } } }); graphViewer.setBackground(Color.GRAY); graphViewer.setGraphMouse(graphMouse); graphMouse.add(graphMouseEditPlugin); graphMouse.add(graphMouseTranslatePlugin); graphMouse.add(graphMousePickPlugin); // Set label renderer VertexLabelAsShapeRenderer<BehaviorVertex, TransitionEdge> renderer = new VertexLabelAsShapeRenderer<BehaviorVertex, TransitionEdge>( graphViewer.getRenderContext()); graphViewer.getRenderContext().setVertexShapeTransformer(renderer); graphViewer.getRenderer().setVertexLabelRenderer(renderer); // Set label contents graphViewer.getRenderContext().setVertexLabelTransformer(new Transformer<BehaviorVertex, String>() { @Override public String transform(BehaviorVertex v) { return v.getSelectedBehavior(); } }); graphViewer.getRenderContext().setEdgeLabelTransformer(new Transformer<TransitionEdge, String>() { @Override public String transform(TransitionEdge e) { return e.getTransition(); } }); // Set fonts graphViewer.getRenderContext().setVertexFontTransformer(new Transformer<BehaviorVertex, Font>() { @Override public Font transform(BehaviorVertex v) { return new Font(graphViewer.getFont().getName(), graphViewer.getFont().getStyle(), 20); } }); graphViewer.getRenderContext().setEdgeFontTransformer(new Transformer<TransitionEdge, Font>() { @Override public Font transform(TransitionEdge arg0) { return new Font(graphViewer.getFont().getName(), graphViewer.getFont().getStyle(), 16); } }); // Fill color dependent on vertex activity graphViewer.getRenderContext().setVertexFillPaintTransformer(new Transformer<BehaviorVertex, Paint>() { @Override public Paint transform(BehaviorVertex vertex) { return vertex.isActive() ? Color.ORANGE : Color.RED; } }); graphViewer.getPickedVertexState().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { BehaviorVertex vertex = (BehaviorVertex) e.getItem(); if (e.getStateChange() == ItemEvent.SELECTED) { setNewSelectedParameterControlInterface(vertex); } if (e.getStateChange() == ItemEvent.DESELECTED) { if (vertex == selectedPCInterface) { setNewSelectedParameterControlInterface(null); } } } }); graphViewer.getPickedEdgeState().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { TransitionEdge edge = (TransitionEdge) e.getItem(); if (e.getStateChange() == ItemEvent.SELECTED) { setNewSelectedParameterControlInterface(edge); } if (e.getStateChange() == ItemEvent.DESELECTED) { if (edge == selectedPCInterface) { setNewSelectedParameterControlInterface(null); } } } }); this.addComponentListener(new ComponentListener() { @Override public void componentShown(ComponentEvent e) { } @Override public void componentResized(ComponentEvent e) { graphViewer.getGraphLayout().setSize(graphViewer.getSize()); } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } }); ///////////// Side panel (parameter control) pcInterfacePanel.setPreferredSize(new Dimension(200, 0)); pcInterfacePanel.setLayout(new BorderLayout()); pcInterfacePanelContents.setLayout(new GridLayout(0, 2, 0, 5)); pcInterfacePanel.add(pcInterfacePanelContents, BorderLayout.NORTH); ///////////// [this] setLayout(new BorderLayout(10, 10)); add(graphViewer, BorderLayout.CENTER); add(pcInterfacePanel, BorderLayout.EAST); }
From source file:mazewar.Mazewar.java
@Subscribe public void quitEvent(KeyEvent e) throws Exception { assert (e.getKeyCode() == KeyEvent.VK_Q); eventBus.unregister(this); zooKeeper.delete(clientPath, -1);/*from w w w. java2s . c om*/ System.exit(0); }
From source file:de.tor.tribes.ui.components.GroupSelectionList.java
public GroupSelectionList(String pResourceURL) { super(pResourceURL); setCellRenderer(renderer);/* w ww . j ava2 s .c o m*/ addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_LEFT) { fireDecrementEvent(); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { fireIncrementEvent(); } else if (e.getKeyCode() == KeyEvent.VK_DELETE) { fireResetEvent(); } else if (e.getKeyCode() == KeyEvent.VK_O) { fireSetStateEvent(ListItem.RELATION_TYPE.OR); } else if (e.getKeyCode() == KeyEvent.VK_U) { fireSetStateEvent(ListItem.RELATION_TYPE.AND); } else if (e.getKeyCode() == KeyEvent.VK_N) { fireSetStateEvent(ListItem.RELATION_TYPE.NOT); } else if (e.getKeyCode() == KeyEvent.VK_I) { fireSetStateEvent(ListItem.RELATION_TYPE.DISABLED); } else if (e.getKeyCode() == KeyEvent.VK_H) { JOptionPaneHelper.showInformationBox(GroupSelectionList.this, getRelationAsPlainText(), "Information"); } } }); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { if (e.getButton() == MouseEvent.BUTTON1) { fireClickedEvent(e.getPoint()); } else { fireResetEvent(e.getPoint()); } } } }); TagManager.getSingleton().addManagerListener(GroupSelectionList.this); }
From source file:org.ut.biolab.medsavant.client.view.LoginView.java
private void portFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_portFieldKeyPressed int key = evt.getKeyCode(); if (key == KeyEvent.VK_ENTER) { loginUsingEnteredUsernameAndPassword(); }/*from ww w .j a va 2 s .co m*/ }
From source file:org.ut.biolab.medsavant.client.view.LoginView.java
private void hostFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hostFieldKeyPressed int key = evt.getKeyCode(); if (key == KeyEvent.VK_ENTER) { loginUsingEnteredUsernameAndPassword(); }/*from w ww . ja v a 2 s . c o m*/ }
From source file:org.ut.biolab.medsavant.client.view.LoginView.java
private void userFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_userFieldKeyPressed int key = evt.getKeyCode(); if (key == KeyEvent.VK_ENTER) { loginUsingEnteredUsernameAndPassword(); }// w ww. j a va2s .co m }