@Override protected void processKeyEvent(KeyEvent e) { KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e); if (enter.equals(ks)) { // Prevent JComponent.processKeyBindings() to be called (it is called from // JComponent.processKeyEvent() ), notify only registered key listeners int id = e.getID(); for (KeyListener keyListener : getKeyListeners()) { switch(id) { case KeyEvent.KEY_TYPED: keyListener.keyTyped(e); break; case KeyEvent.KEY_PRESSED: keyListener.keyPressed(e); break; case KeyEvent.KEY_RELEASED: keyListener.keyReleased(e); break; } } if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) { synchronized(listeners) { List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners); for (CellEditorListener listener : list) { listener.editingStopped(new ChangeEvent(this)); } } } e.consume(); } else { super.processKeyEvent(e); } }
public KeyListener updateProviderOnSave() { return new KeyAdapter() { @Override public void keyPressed(KeyEvent ke) { if (isSave(ke)) { onSave(); } } }; }
private KeyListener listenToKeysListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String word = nameField.getText(); if (word.length() < 18) { hotelNameTitle.setText(word); hotelNameTitle.repaint(); } else { JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!", JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE); } super.keyTyped(e); } }; return adapter; }
private KeyListener validatorListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { final EmailValidator validator = new EmailValidator(); if(validator.validate(emailField.getText())) { markerLbl.setVisible(false); infoLabel.setText(""); isValid = true; } else { markerLbl.setVisible(true); infoLabel.setText("Invalid email format!"); } } }; return adapter; }
/** * Checks if this {@code Canvas} contains any in game components. * * @return {@code true} if there is any in game components. */ public boolean containsInGameComponents() { KeyListener[] keyListeners = getKeyListeners(); if (keyListeners.length > 0) { return true; } MouseListener[] mouseListeners = getMouseListeners(); if (mouseListeners.length > 0) { return true; } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); if (mouseMotionListeners.length > 0) { return true; } return false; }
/** * Removes components that is only used when in game. */ public void removeInGameComponents() { // remove listeners, they will be added when launching the new game... KeyListener[] keyListeners = getKeyListeners(); for (KeyListener keyListener : keyListeners) { removeKeyListener(keyListener); } MouseListener[] mouseListeners = getMouseListeners(); for (MouseListener mouseListener : mouseListeners) { removeMouseListener(mouseListener); } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { removeMouseMotionListener(mouseMotionListener); } for (Component c : getComponents()) { removeFromCanvas(c); } }
/** * Description of the Method * * @param e Description of the Parameter */ public void fireKeyPressed(KeyEvent e) { for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) { KeyListener l = en.nextElement(); l.keyPressed(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } }
/** * Description of the Method * * @param e Description of the Parameter */ public void fireKeyReleased(KeyEvent e) { for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) { KeyListener l = en.nextElement(); l.keyReleased(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } }
/** * Adds an event listener to the Panel. * * @param eventListener * The event listener. * * @throws IllegalArgumentException * If the event listener isn't supported by this function. */ public void addListener(final EventListener eventListener) { if (eventListener instanceof KeyListener) { this.addKeyListener((KeyListener) eventListener); return; } if (eventListener instanceof MouseListener) { this.addMouseListener((MouseListener) eventListener); return; } if (eventListener instanceof MouseMotionListener) { this.addMouseMotionListener((MouseMotionListener) eventListener); return; } throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported."); }
/** * Removes an event listener from the Panel. * * @param eventListener * The event listener. * * @throws IllegalArgumentException * If the event listener isn't supported by this function. */ public void removeListener(final EventListener eventListener) { if (eventListener instanceof KeyListener) { this.removeKeyListener((KeyListener) eventListener); return; } if (eventListener instanceof MouseListener) { this.removeMouseListener((MouseListener) eventListener); return; } if (eventListener instanceof MouseMotionListener) { this.removeMouseMotionListener((MouseMotionListener) eventListener); return; } throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported."); }
public void removeListener() { for (MouseListener ml : com.getMouseListeners()) { com.removeMouseListener(ml); } for (MouseMotionListener mml : com.getMouseMotionListeners()) { com.removeMouseMotionListener(mml); } for (KeyListener kl : com.getKeyListeners()) { com.removeKeyListener(kl); } reset(); com.repaint(); }
/** * Maps {@code Component.addKeyListener(KeyListener)} through queue */ public void addKeyListener(final KeyListener keyListener) { runMapping(new MapVoidAction("addKeyListener") { @Override public void map() { getSource().addKeyListener(keyListener); } }); }
@Override public synchronized void addKeyListener(KeyListener keyListener) { textArea.addKeyListener(keyListener); }
public void addSearchKeyListener(KeyListener listener) { txtSearch.addKeyListener(listener); }
private void setupSearch() { // Remove the default key listeners KeyListener[] keyListeners = getListeners(KeyListener.class); for (int i = 0; i < keyListeners.length; i++) { removeKeyListener(keyListeners[i]); } // Add new key listeners addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int modifiers = e.getModifiers(); int keyCode = e.getKeyCode(); if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) { return; } char c = e.getKeyChar(); if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT)) { searchTextField.setText(String.valueOf(c)); displaySearchField(); } } } ); // Create a the "multi-event" listener for the text field. Instead of // adding separate instances of each needed listener, we're using a // class which implements them all. This approach is used in order // to avoid the creation of 4 instances which takes some time SearchFieldListener searchFieldListener = new SearchFieldListener(); searchTextField.addKeyListener(searchFieldListener); searchTextField.addFocusListener(searchFieldListener); searchTextField.getDocument().addDocumentListener(searchFieldListener); }
public static Component setKeyListener(Component c, KeyListener kl) { if(c.getKeyListeners().length > 0) { for(KeyListener g : c.getKeyListeners()) { c.removeKeyListener(g); } } c.addKeyListener(kl); return c; }
/** * Clear all key listeners. NOTE: this method will also remove the default listener. */ public void clearKeyListeners() { KeyListener[] listeners = frame.getKeyListeners(); for (KeyListener listener : listeners) { removeKeyListener(listener); } }
public synchronized void addKeyListener(KeyListener l) { if (listenersActive) { super.addKeyListener(l); } else { keyListeners.add(l); } }
/** * Save all current Key Listeners and remove them from the * map. Used by Traits that need to prevent Key Commands * at certain times. */ public void enableKeyListeners() { if (saveKeyListeners == null) return; for (KeyListener kl : saveKeyListeners) { theMap.addKeyListener(kl); } saveKeyListeners = null; }
/** * Restore the previously disabled KeyListeners */ public void disableKeyListeners() { if (saveKeyListeners != null) return; saveKeyListeners = theMap.getKeyListeners(); for (KeyListener kl : saveKeyListeners) { theMap.removeKeyListener(kl); } }
private KeyListener customKeyListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String modifiedQuery = "(?i)" + searchField.getText(); tableRowShorter.setRowFilter(RowFilter.regexFilter(modifiedQuery)); super.keyTyped(e); } }; return adapter; }
private KeyListener getKeyListener() { KeyAdapter listener = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if(Character.isLetter(c) && !e.isAltDown()) { e.consume(); } } }; return listener; }
public PnlMessageProperties(KeyListener saveKeyListener) { setLayout(null); setBorder(new TitledBorder(null, "Message Properties", TitledBorder.LEADING, TitledBorder.TOP, null, null)); lblMsgType.setHorizontalAlignment(SwingConstants.RIGHT); lblMsgType.setBounds(12, 27, 102, 16); txtMsgType.setColumns(10); txtMsgType.setBounds(126, 24, 70, 22); txtMsgType.addKeyListener(saveKeyListener); lblHeaderEncoding.setHorizontalAlignment(SwingConstants.RIGHT); lblHeaderEncoding.setBounds(12, 56, 102, 16); cmbHeaderEncoding.setBounds(126, 53, 92, 22); EncodingEnum.addCmbItemList(cmbHeaderEncoding); lblBitmapEncoding.setHorizontalAlignment(SwingConstants.RIGHT); lblBitmapEncoding.setBounds(230, 56, 102, 16); cmbBitmapEncoding.setBounds(344, 53, 92, 22); EncodingEnum.addCmbItemList(cmbBitmapEncoding); add(lblMsgType); add(txtMsgType); add(lblHeaderEncoding); add(cmbHeaderEncoding); add(lblBitmapEncoding); add(cmbBitmapEncoding); setEnabled(false); }
/** * Shows the given video Component. * * @param vp The video Component. * @param ml A MouseListener for stopping the video. * @param kl A KeyListener for stopping the video. */ public void showVideoComponent(final Component vp, final MouseListener ml, final KeyListener kl) { addMouseListener(ml); addKeyListener(kl); addCentered(vp, JLayeredPane.PALETTE_LAYER); }
public MTextField(String text, KeyListener keyListener, int width, int height) { this(text); addKeyListener(keyListener); setPreferredSize(new Dimension(width, height)); setSize(new Dimension(width, height)); setFocusHandler(); }
public KeyEditor(KeyListener listener) { initComponents(); passwd1.setText(""); passwd2.setText(""); passwd1.addKeyListener(listener); passwd2.addKeyListener(listener); alias.addKeyListener(listener); firstAndLastName.addKeyListener(listener); organizationUnit.addKeyListener(listener); organization.addKeyListener(listener); city.addKeyListener(listener); stateOrProvince.addKeyListener(listener); countryCode.addKeyListener(listener); }
public InternalKeyboard() { this.component = ServerEngine.getInstance().getCanvas(); this.keyboardlistener = component.getKeyListeners(); this.keyDispatcher = component.getKeyListeners()[0]; for (final KeyListener keyListener : component.getKeyListeners()) { component.removeKeyListener(keyListener); } component.addKeyListener(this); }
public void dispose() { ComponentListener[] listeners = getComponentListeners(); for (int i=0; i<listeners.length; i++) { removeComponentListener(listeners[i]); } MouseListener[] mlisteners = getMouseListeners(); for (int i=0; i<mlisteners.length; i++) { removeMouseListener(mlisteners[i]); } KeyListener[] klisteners = getKeyListeners(); for (int i=0; i<klisteners.length; i++) { removeKeyListener(klisteners[i]); } }
public static JTextField createTextField(String text, KeyListener listener, boolean numbers) { JTextField field = new JTextField(text); field.setMinimumSize(textPrefSize); if(text.length() == 0) field.setPreferredSize(textPrefSize); if(listener != null) field.addKeyListener(listener); if(numbers) field.setDocument(new NumberDocument()); return field; }
/** * Maps {@code Component.removeKeyListener(KeyListener)} through queue */ public void removeKeyListener(final KeyListener keyListener) { runMapping(new MapVoidAction("removeKeyListener") { @Override public void map() { getSource().removeKeyListener(keyListener); } }); }
public void removeSearchKeyListener(KeyListener listener) { txtSearch.removeKeyListener(listener); }
@Override public void addKeyListener(KeyListener listener) { FileSelectorField.this.addKeyListener(listener); }
public void addKeyListener(KeyListener l) { area.addKeyListener(l); }
@Override public synchronized void removeKeyListener(KeyListener l) { addedKeyListeners.remove(l); super.removeKeyListener(l); }