List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:view.MainWindow.java
private void jtOpenedDocumentsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtOpenedDocumentsKeyPressed if (evt.getKeyCode() == KeyEvent.VK_DELETE) { closeDocument(true);//from w ww . j a v a 2 s . c o m } }
From source file:net.minelord.gui.panes.IRCPane.java
public IRCPane() { super();//ww w .j a v a 2 s .com this.setBorder(new EmptyBorder(5, 5, 5, 5)); this.setLayout(null); nickSelectPane = new JPanel(); nickSelectPane.setLayout(null); nickSelectPane.setBounds(325, 70, 200, 200); TitledBorder title = BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Pick a nick"); title.setTitleJustification(TitledBorder.RIGHT); nickSelectPane.setBorder(title); nickSelect = new JTextField(); final JButton done = new JButton("Done"); nickSelect.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { String nick = nickSelect.getText(); boolean success = true; if (nick.length() > 0) { if (nick.substring(0, 1).matches("[0-9]") || nick.charAt(0) == '-' || nick.contains(" ")) success = false; } else success = false; if (success) IRCPane.nick = nick; done.setEnabled(success); } @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == 10) done.doClick(); } }); nickSelect.setBounds(50, 65, 100, 30); done.setBounds(50, 125, 100, 30); done.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { remove(nickSelectPane); repaint(); startClient(nickSelect.getText()); } }); done.setEnabled(false); nickSelectPane.add(nickSelect); nickSelectPane.add(done); add(nickSelectPane); addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent paramFocusEvent) { } @Override public void focusGained(FocusEvent paramFocusEvent) { if (nickSelectPane.getParent() != null) nickSelect.requestFocus(); if (input != null && input.getParent() != null) input.requestFocus(); } }); instance = this; }
From source file:com.proyecto.vista.MantenimientoInventario.java
private void txtBuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBuscarKeyPressed // TODO add your handling code here: int code = evt.getKeyCode(); if (!(txtBuscar.getText().equals("")) && code == KeyEvent.VK_ENTER) { buscarInventario();/* w w w.j ava 2 s .c o m*/ } }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** Initializes the components composing the display.*/ private void initComponents() { filterAnywhere = true;//from w ww .j av a 2 s . c om filterArea = new JTextField(); originalColor = filterArea.getForeground(); setTextFieldDefault(DEFAULT_FILTER_TEXT); StringBuilder builder = new StringBuilder(); builder.append("Filter"); if (TagAnnotationData.class.equals(type)) { builder.append(" Tags."); } else if (FileAnnotationData.class.equals(type)) { builder.append(" Attachments."); } else if (DatasetData.class.equals(type)) { builder.append(" Datasets."); } else builder.append("."); filterArea.setToolTipText(builder.toString()); filterArea.getDocument().addDocumentListener(this); filterArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent evt) { String value = filterArea.getText(); if (StringUtils.isBlank(value)) { setTextFieldDefault(DEFAULT_FILTER_TEXT); } } @Override public void focusGained(FocusEvent evt) { } }); filterArea.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { String value = filterArea.getText(); if (DEFAULT_FILTER_TEXT.equals(value)) { setTextFieldDefault(null); } } }); filterArea.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && filterArea.isFocusOwner()) { addItem(); //reset filter setTextFieldDefault(DEFAULT_FILTER_TEXT); availableItemsListbox.requestFocus(); } } }); sorter = new ViewerSorter(); availableItemsListbox = new JTree(); initializeTree(availableItemsListbox, user); availableItemsListbox.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && availableItemsListbox.isFocusOwner()) { addItem(); } } }); availableItemsListbox.addMouseListener(new MouseAdapter() { /** * Adds the items to the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (availableItemsListbox.isFocusOwner()) addItem(); } } }); availableItemsListbox.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent evt) { firePropertyChange(AVAILABLE_SELECTION_CHANGE, Boolean.TRUE, Boolean.FALSE); } }); selectedItemsListbox = new JTree(); initializeTree(selectedItemsListbox, user); selectedItemsListbox.addKeyListener(new KeyAdapter() { /** * Removes the selected elements from the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && selectedItemsListbox.isFocusOwner()) { removeItem(); } } }); selectedItemsListbox.addMouseListener(new MouseAdapter() { /** * Removes the selected elements from the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (selectedItemsListbox.isFocusOwner()) removeItem(); } } }); IconManager icons = IconManager.getInstance(); addButton = new JButton(icons.getIcon(IconManager.RIGHT_ARROW)); removeButton = new JButton(icons.getIcon(IconManager.LEFT_ARROW)); addAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_RIGHT_ARROW)); removeAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_LEFT_ARROW)); addButton.setActionCommand("" + ADD); addButton.addActionListener(this); addAllButton.setActionCommand("" + ADD_ALL); addAllButton.addActionListener(this); removeButton.setActionCommand("" + REMOVE); removeButton.addActionListener(this); removeAllButton.setActionCommand("" + REMOVE_ALL); removeAllButton.addActionListener(this); setImmutableElements(null); }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * Processes the KeyEvent.//from w w w . j a va2 s . c o m * @param ev event */ protected void cbxKeyReleased(KeyEvent ev) { if (isReadOnlyMode) { return; } if (ev.getKeyCode() == KeyEvent.VK_SHIFT || ev.getKeyCode() == KeyEvent.VK_LEFT || ev.getKeyCode() == KeyEvent.VK_RIGHT || ev.getKeyCode() == KeyEvent.VK_CONTROL || ev.getKeyCode() == KeyEvent.VK_META) { return; } currentText = textField.getText(); if (uiFieldFormatter != null) { currentText = uiFieldFormatter.formatFromUI(currentText).toString(); } if (currentText.length() == 0 || !hasNewText) { if (ev.getKeyCode() == KeyEvent.VK_TAB) { if (ev.isShiftDown()) { textField.transferFocusBackward(); } else { textField.transferFocus(); } return; } if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY || ev.getKeyCode() == KeyEvent.VK_DOWN) { showPopup(0); // add only return; } if (ev.getKeyCode() != KeyEvent.VK_ENTER) { // Add variable to track whether it once had a value and now it does not rods - 02/28/08 idList.clear(); list.clear(); selectedId = null; // 02/09/08 - This should not be done here - rods // The reason is, that we may have added something only to remove // before leaving the control. So we should never send the notification // just because we delete the contents. (see wasCleared above) /*if (listSelectionListeners != null) { notifyListenersOfChange(TextFieldWithQuery.this); }*/ //log.debug("setting hasNewText to true"); //$NON-NLS-1$ hasNewText = true; } } else { hasNewText = true; //log.debug("setting hasNewText to true"); } if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY || ev.getKeyCode() == KeyEvent.VK_TAB || ev.getKeyCode() == KeyEvent.VK_DOWN) { String origText = textField.getText(); String text = origText; if (uiFieldFormatter != null && !uiFieldFormatter.isNumeric()) { text = uiFieldFormatter.formatFromUI(text).toString(); } text = StringUtils.replace(text, "'", "\'"); text = StringUtils.replace(text, "\"", "\\\""); // direction of focus change 1: forward 0: none -1: backwards int focusChange = (ev.isShiftDown() ? -1 : 1) * (ev.getKeyCode() == KeyEvent.VK_TAB ? 1 : 0); doQuery(text, origText, focusChange); } }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void octAnalysisPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_octAnalysisPanelKeyPressed OCTSelection sel = null;/*from w ww .j a va 2s. c o m*/ //determine direction to move the selection switch (evt.getKeyCode()) { case KeyEvent.VK_RIGHT: switch (analysisMngr.getAnalysisMode()) { case MIRROR: sel = selectionLRPManager.getSelectedSelection(); if (sel.getSelectionName().equals("Left")) { //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection) selectionLRPManager.moveSelectionRight(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Right")).findFirst().get(); selectionLRPManager.moveSelectionLeft(sel); } else { //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection) selectionLRPManager.moveSelectionRight(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Left")).findFirst().get(); selectionLRPManager.moveSelectionLeft(sel); } break; case SINGLE: case EZ: sel = selectionLRPManager.getSelectedSelection(); if (sel.isMoveable()) { selectionLRPManager.moveSelectionRight(sel); } break; default: break; } break; case KeyEvent.VK_LEFT: switch (analysisMngr.getAnalysisMode()) { case MIRROR: sel = selectionLRPManager.getSelectedSelection(); if (sel.getSelectionName().equals("Right")) { //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection) selectionLRPManager.moveSelectionLeft(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Left")).findFirst().get(); selectionLRPManager.moveSelectionRight(sel); } else { //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection) selectionLRPManager.moveSelectionLeft(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Right")).findFirst().get(); selectionLRPManager.moveSelectionRight(sel); } break; case SINGLE: case EZ: sel = selectionLRPManager.getSelectedSelection(); if (sel.isMoveable()) { selectionLRPManager.moveSelectionRight(sel); } break; default: break; } break; default: break; } //refresh the OCT analysis panel with the updated selection information octAnalysisPanel.repaint(); }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * /*from w w w . j av a 2s. co m*/ */ public void createUI() { //setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setLayout(new BorderLayout()); setOpaque(false); textField = new JTextField(10); // we are going to handle focus traversal manually // so that we can do searches when 'tab' is pressed textField.setFocusTraversalKeysEnabled(false); setControlSize(textField); ImageIcon img = IconManager.getIcon("DropDownArrow", IconManager.IconSize.NonStd); //$NON-NLS-1$ dbBtn = UIHelper.isMacOS() ? new MacGradiantBtn(img) : new JButton(img); dbBtn.setFocusable(false); PanelBuilder pb = new PanelBuilder(new FormLayout("f:d:g,p", "f:p:g"), this); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); pb.add(textField, cc.xy(1, 1)); pb.add(dbBtn, cc.xy(2, 1)); textField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (ignoreTab && e.getKeyCode() == KeyEvent.VK_TAB) { ignoreTab = false; } else { cbxKeyReleased(e); } super.keyReleased(e); } @Override public void keyPressed(KeyEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } super.keyReleased(e); } }); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { prevEnteredText = textField.getText(); boolean oldWasCleared = wasCleared; if (!ignoreDocChange) { wasCleared = wasCleared || selectedId != null; idList.clear(); list.clear(); selectedId = null; if (oldWasCleared != wasCleared && wasCleared) { notifyListenersOfChange( StringUtils.isEmpty(prevEnteredText) ? null : TextFieldWithQuery.this); } } } }); StringBuilder sb = new StringBuilder(); for (String k : keyColumns) { String title = k; DBFieldInfo fi = tableInfo.getFieldByName(k); if (fi != null) { title = fi.getTitle(); } if (sb.length() > 0) sb.append(", "); sb.append(title); } textField.setToolTipText(UIRegistry.getFormattedResStr("TFWQ_SEARCHES_FLDS", sb.toString())); textField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { if (e instanceof CausedFocusEvent) { switch (((CausedFocusEvent) e).getCause()) { case TRAVERSAL: case TRAVERSAL_BACKWARD: case TRAVERSAL_FORWARD: case TRAVERSAL_UP: case TRAVERSAL_DOWN: ignoreTab = true; } } } @Override public void focusLost(FocusEvent e) { int len = textField.getText().length(); if (len < 1) { setText(""); //$NON-NLS-1$ /////////////////////////////////////////////////////////////////////////////////// // We only want to generate a change event if it once had a value and then it is // cleared and the user tabs to a new control. - rods 02/28/08 /////////////////////////////////////////////////////////////////////////////////// if (wasCleared || selectedId != null) { notifyListenersOfChange(TextFieldWithQuery.this); } } textField.setCaretPosition(0); } }); dbBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } log.debug("currentText: " + currentText); doQuery(currentText, currentText, 0); } }); }
From source file:view.MainWindow.java
@Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.isControlDown()) { if (e.getKeyCode() == KeyEvent.VK_W) { closeDocument(true);/*from w ww .ja v a2 s . c o m*/ } else if (e.getKeyCode() == KeyEvent.VK_ADD) { workspacePanel.zoomIn(); } else if (e.getKeyCode() == KeyEvent.VK_SUBTRACT) { workspacePanel.zoomOut(); } else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_RIGHT) { workspacePanel.pageUp(); } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_LEFT) { workspacePanel.pageDown(); } if (e.isShiftDown()) { if (e.getKeyCode() == KeyEvent.VK_S) { workspacePanel.changeCard(WorkspacePanel.CardEnum.SIGN_PANEL, true); } else if (e.getKeyCode() == KeyEvent.VK_V) { workspacePanel.changeCard(WorkspacePanel.CardEnum.VALIDATE_PANEL, true); } } } } else if (e.getID() == KeyEvent.KEY_RELEASED) { } else if (e.getID() == KeyEvent.KEY_TYPED) { } return false; }
From source file:tax.MainForm.java
private void nameTextSKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameTextSKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (!afmToName.containsKey(nameTextS.getText()) && !nameTextS.getText().equals("")) { afmTextS.setEnabled(true);/*from w ww . ja v a2 s .c o m*/ afmTextS.requestFocus(); Util.fadeInAndOut(nameTextS, Util.darkGreen); } else { nameTextS.setText(""); Util.fadeInAndOut(nameTextS, Util.darkOrange); } } }
From source file:tax.MainForm.java
private void afmTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_afmTextKeyReleased int keyCode = evt.getKeyCode(); if ((keyCode == KeyEvent.VK_BACK_SPACE) || (keyCode == KeyEvent.VK_DELETE)) { lastDateTextLength = dateText.getText().length(); }//from w ww . jav a2 s. co m }