List of usage examples for java.awt.event KeyEvent consume
public void consume()
From source file:schoolsystem.FeeModuleDialog.java
private void txt_fee_moduleKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_moduleKeyTyped if (evt.getKeyChar() >= '0' && evt.getKeyChar() <= '9') { } else {/*from ww w. jav a 2 s . c o m*/ if (evt.getKeyChar() == KeyEvent.VK_SLASH) { } else { evt.consume(); Toolkit.getDefaultToolkit().beep(); } } // TODO add your handling }
From source file:net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseKeyTextHandler.java
/** * If the field is not allowed to have nulls, we need to let the * user erase the entire contents of the field so that they can enter * a brand-new value from scratch. While the empty field is not a legal * value, we cannot avoid allowing it. This is the normal editing behavior, * so we do not need to add anything special here except for the cyclic * re-entering of the original data if user hits delete when field is empty * /*from w ww . j a va2 s. co m*/ * @param text * @param c * @param e * @param _textComponent */ protected void handleNotNullableField(String text, char c, KeyEvent e, IRestorableTextComponent _textComponent) { if (text.length() == 0) { // We want to detect two empty text values in a row before // we decide to restore the original value. Since 'text' // contains the new value, we want to allow the first empty // 'text' so that the user can clear the field, and on the // second one we will set it to the original value. if (firstBlankText) { firstBlankText = false; return; } else { firstBlankText = true; } if (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE) { // delete when null => original value _textComponent.restoreText(); e.consume(); } } }
From source file:org.kontalk.view.View.java
void setHotkeys() { final boolean enterSends = Config.getInstance().getBoolean(Config.MAIN_ENTER_SENDS); for (KeyListener l : mSendTextArea.getKeyListeners()) mSendTextArea.removeKeyListener(l); mSendTextArea.addKeyListener(new KeyListener() { @Override//w w w.j a v a2 s . co m public void keyPressed(KeyEvent e) { if (enterSends && e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK) { e.consume(); mSendTextArea.append(System.getProperty("line.separator")); } if (enterSends && e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == 0) { // only ignore e.consume(); } } @Override public void keyReleased(KeyEvent e) { } @Override public void keyTyped(KeyEvent e) { } }); mSendButton.removeHotkeys(); HotkeyData sendHotkey = enterSends ? Hotkey.ENTER : Hotkey.CTRL_ENTER; mSendButton.addHotkey(sendHotkey, TooltipWay.up); }
From source file:vista.ArchToxHome.java
private void Consume(java.awt.event.KeyEvent evt) { char c = evt.getKeyChar(); if (c < '0' || c > '9') { evt.consume(); }/* w ww . j a v a 2 s. c o m*/ }
From source file:com.cmsoftware.keyron.vista.admin.AgregarEmpleado.java
private void cedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cedulaKeyTyped labelError.setText(""); cedula.setBackground(new Color(255, 255, 255)); if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') { evt.consume(); Toolkit.getDefaultToolkit().beep(); }/*w w w . j av a2 s . c o m*/ }
From source file:net.sf.jabref.gui.autocompleter.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.get(lastShownCompletion); int end = comp.getSelectionEnd(); comp.select(end, end);//from w w w . jav 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, everything else leads to a reset LOGGER.debug("Special case: shift pressed. No action."); } else { resetAutoCompletion(); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
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);// w ww . ja va 2 s. c o 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.sec.ose.osi.ui.dialog.setting.JPanProjectAnalysisSetting.java
/** * This method initializes jTextFieldUserHour * /*from w w w .ja v a2 s .c o m*/ * @return javax.swing.JTextField */ private JTextField getJTextFieldUserHour() { if (jTextFieldUserHour == null) { jTextFieldUserHour = new JTextField(); jTextFieldUserHour.setPreferredSize(new Dimension(80, 22)); jTextFieldUserHour.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) { getToolkit().beep(); e.consume(); } } }); } return jTextFieldUserHour; }
From source file:nl.ru.ai.projects.parrot.biomav.editor.BehaviorEditor.java
public BehaviorEditor() { ///////// Graph stuff graphViewer.addKeyListener(new KeyListener() { @Override//www . jav a 2 s.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:vista.ArchToxHome.java
private void CampoIDKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CampoIDKeyTyped Consume(evt);/* w w w. j a v a 2 s. c o m*/ if (CampoID.getText().length() == 10) { evt.consume(); } }