Java 类java.awt.event.KeyListener 实例源码

项目:incubator-netbeans    文件:WatchesColumnModels.java   
@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);
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:StyledEditor.java   
public KeyListener updateProviderOnSave() {
    return new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent ke) {
            if (isSave(ke)) {
                onSave();
            }
        }
    };
}
项目:incubator-netbeans    文件:ColumnModels.java   
@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);
    }
}
项目:Hotel-Properties-Management-System    文件:HotelPropertiesWindow.java   
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;
}
项目:Hotel-Properties-Management-System    文件:AddUserWindow.java   
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;
}
项目:freecol    文件:Canvas.java   
/**
 * 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;
}
项目:freecol    文件:Canvas.java   
/**
 * 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);
    }
}
项目:Yass    文件:YassInput.java   
/**
 * 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()));
    }
}
项目:Yass    文件:YassInput.java   
/**
 * 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()));
    }
}
项目:VTerminal    文件:Panel.java   
/**
 * 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.");
}
项目:VTerminal    文件:Panel.java   
/**
 * 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.");
}
项目:Cognizant-Intelligent-Test-Scripter    文件:SelectionManager.java   
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();
}
项目:openjdk-jdk10    文件:ComponentOperator.java   
/**
 * Maps {@code Component.addKeyListener(KeyListener)} through queue
 */
public void addKeyListener(final KeyListener keyListener) {
    runMapping(new MapVoidAction("addKeyListener") {
        @Override
        public void map() {
            getSource().addKeyListener(keyListener);
        }
    });
}
项目:FreeCol    文件:Canvas.java   
/**
 * 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;
}
项目:FreeCol    文件:Canvas.java   
/**
 * 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);
    }
}
项目:VISNode    文件:CodeEditor.java   
@Override
public synchronized void addKeyListener(KeyListener keyListener) {
    textArea.addKeyListener(keyListener); 
}
项目:incubator-netbeans    文件:SearchField.java   
public void addSearchKeyListener(KeyListener listener) {
    txtSearch.addKeyListener(listener);
}
项目:incubator-netbeans    文件:ListView.java   
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);
}
项目:JAddOn    文件:JUtils.java   
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;
}
项目:Lunar    文件:Game.java   
/**
 * 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);
    }
}
项目:VASSAL-src    文件:PrivateMap.java   
public synchronized void addKeyListener(KeyListener l) {
  if (listenersActive) {
    super.addKeyListener(l);
  }
  else {
    keyListeners.add(l);
  }
}
项目:VASSAL-src    文件:Map.java   
/**
 * 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;
}
项目:VASSAL-src    文件:Map.java   
/**
 * Restore the previously disabled KeyListeners
 */
public void disableKeyListeners() {
  if (saveKeyListeners != null) return;

  saveKeyListeners = theMap.getKeyListeners();
  for (KeyListener kl : saveKeyListeners) {
    theMap.removeKeyListener(kl);
  }
}
项目:Hotel-Properties-Management-System    文件:Main_Blockade.java   
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;
}
项目:Hotel-Properties-Management-System    文件:Main_RoomCleaning.java   
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;
}
项目:Hotel-Properties-Management-System    文件:ExchangeWindow.java   
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;
}
项目:ISO8583    文件:PnlMessageProperties.java   
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);
}
项目:freecol    文件:Canvas.java   
/**
 * 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);
}
项目:WordnetLoom    文件:MTextField.java   
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();
}
项目:NBANDROID-V2    文件:KeyEditor.java   
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);
}
项目:Parabot-317-API-Minified-OS-Scape    文件:InternalKeyboard.java   
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);
}
项目:etomica    文件:DisplayCanvas.java   
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]);
    }
}
项目:MaxSim    文件:CommonUI.java   
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;
}
项目:openjdk-jdk10    文件:CommonUI.java   
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;
}
项目:openjdk-jdk10    文件:ComponentOperator.java   
/**
 * Maps {@code Component.removeKeyListener(KeyListener)} through queue
 */
public void removeKeyListener(final KeyListener keyListener) {
    runMapping(new MapVoidAction("removeKeyListener") {
        @Override
        public void map() {
            getSource().removeKeyListener(keyListener);
        }
    });
}
项目:FreeCol    文件:Canvas.java   
/**
 * 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);
}
项目:incubator-netbeans    文件:SearchField.java   
public void removeSearchKeyListener(KeyListener listener) {
    txtSearch.removeKeyListener(listener);
}
项目:incubator-netbeans    文件:FileSelectorField.java   
@Override
public void addKeyListener(KeyListener listener) {
    FileSelectorField.this.addKeyListener(listener);
}
项目:myster    文件:MessageWindow.java   
public void addKeyListener(KeyListener l) {
    area.addKeyListener(l);
}
项目:incubator-netbeans    文件:QuickSearchTest.java   
@Override
public synchronized void removeKeyListener(KeyListener l) {
    addedKeyListeners.remove(l);
    super.removeKeyListener(l);
}