Example usage for java.awt.event KeyEvent CHAR_UNDEFINED

List of usage examples for java.awt.event KeyEvent CHAR_UNDEFINED

Introduction

In this page you can find the example usage for java.awt.event KeyEvent CHAR_UNDEFINED.

Prototype

char CHAR_UNDEFINED

To view the source code for java.awt.event KeyEvent CHAR_UNDEFINED.

Click Source Link

Document

KEY_PRESSED and KEY_RELEASED events which do not map to a valid Unicode character use this for the keyChar value.

Usage

From source file:Main.java

/**
 * Simulate a key press/release event on the component.
 * /*from w  w w  .  j  a va 2 s  . co m*/
 * @param key
 *            KeyEvent.VK_...
 */
public static void simulateKeyPressed(Component component, int key) {
    component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, key, KeyEvent.CHAR_UNDEFINED));
    component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_RELEASED, 0, 2, key, KeyEvent.CHAR_UNDEFINED));
}

From source file:MultiKeyCombo.java

public int selectionForKey(char aKey, ComboBoxModel aModel) {
    // Reset if invalid character
    if (aKey == KeyEvent.CHAR_UNDEFINED) {
        currentSearch.setLength(0);/*from   ww w . j av  a2 s .  co  m*/
        return -1;
    }
    // Since search, don't reset search
    resetTimer.stop();
    // Convert input to uppercase
    char key = Character.toUpperCase(aKey);
    // Build up search string
    currentSearch.append(key);
    // Find selected position within model to starting searching from
    Object selectedElement = aModel.getSelectedItem();
    int selectedIndex = -1;
    if (selectedElement != null) {
        for (int i = 0, n = aModel.getSize(); i < n; i++) {
            if (aModel.getElementAt(i) == selectedElement) {
                selectedIndex = i;
                break;
            }
        }
    }
    boolean found = false;
    String search = currentSearch.toString();
    // Search from selected forward, wrap back to beginning if not found
    for (int i = 0, n = aModel.getSize(); i < n; i++) {
        String element = aModel.getElementAt(selectedIndex).toString().toUpperCase();
        if (element.startsWith(search)) {
            found = true;
            break;
        }
        selectedIndex++;
        if (selectedIndex == n) {
            selectedIndex = 0; // wrap
        }
    }
    // Restart timer
    resetTimer.start();
    return (found ? selectedIndex : -1);
}

From source file:org.openstreetmap.josm.plugins.mapillary.actions.MapillarySubmitCurrentChangesetAction.java

/**
 * Main constructor.//from  w  w  w.java  2  s . c o  m
 */
public MapillarySubmitCurrentChangesetAction() {
    super(tr("Submit changeset"), MapillaryPlugin.getProvider("icon24.png"), tr("Submit the current changeset"),
            Shortcut.registerShortcut("Submit changeset to Mapillary",
                    tr("Submit the current changeset to Mapillary"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
            false, "mapillarySubmitChangeset", false);
    this.setEnabled(false);
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboComponentName.java

private void init() {

    final JTextField tfComponentName = (JTextField) this.getEditor().getEditorComponent();

    tfComponentName.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();
            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && ch != KeyEvent.VK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;

            if (ch == KeyEvent.VK_ENTER) {

                JComboComponentName.this.hidePopup();
                return;
            }/* w w  w. ja  v  a2  s.c om*/
            // 1. save string
            String keyword = tfComponentName.getText();//.trim();
            updateComboBoxList(keyword);

        }
    });

    tfComponentName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (tfComponentName.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });

}

From source file:MemComboBoxDemo.java

public void keyReleased(KeyEvent e) {
    char ch = e.getKeyChar();
    if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))
        return;//w  w w .  j a va 2s.com
    int pos = editor.getCaretPosition();
    String str = editor.getText();
    if (str.length() == 0)
        return;

    for (int k = 0; k < comboBox.getItemCount(); k++) {
        String item = comboBox.getItemAt(k).toString();
        if (item.startsWith(str)) {
            editor.setText(item);
            editor.setCaretPosition(item.length());
            editor.moveCaretPosition(pos);
            break;
        }
    }
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboLicenseName.java

public JComboLicenseName() {
    final JTextField editor;
    this.initLicenseComboBox();

    this.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (isEnabled()) {
                if (e.getActionCommand().equals("comboBoxChanged")
                        || e.getActionCommand().equals("comboBoxEdited")) {
                    if (getSelectedIndex() > 0) {
                        setSelectedIndex(getSelectedIndex());
                        IdentifyMediator.getInstance()
                                .setSelectedLicenseName(String.valueOf(getSelectedItem()));
                        log.debug("selected license name : "
                                + IdentifyMediator.getInstance().getSelectedLicenseName());
                    } else {
                        IdentifyMediator.getInstance().setSelectedLicenseName("");
                    }/*from  w  ww  . j a va  2 s. c o m*/
                }
            }
        }
    });
    editor = (JTextField) this.getEditor().getEditorComponent();
    editor.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();

            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;
            if (ch == KeyEvent.VK_ENTER) {
                hidePopup();
                return;
            }

            String str = editor.getText();

            if (getComponentCount() > 0) {
                removeAllItems();
            }

            addItem(str);
            try {
                String tmpLicense = null;
                ArrayList<String> AllLicenseList = new ArrayList<String>();
                AllLicenseList = LicenseAPIWrapper.getAllLicenseList();
                if (str.length() > 0) {
                    for (int i = 0; i < AllLicenseList.size(); i++) {
                        tmpLicense = AllLicenseList.get(i);
                        if (tmpLicense.toLowerCase().startsWith(str.toLowerCase()))
                            addItem(tmpLicense);
                    }
                } else {
                    for (int i = 0; i < AllLicenseList.size(); i++) {
                        addItem(AllLicenseList.get(i));
                    }
                }
            } catch (Exception e1) {
                log.warn(e1.getMessage());
            }

            hidePopup();
            if (str.length() > 0)
                showPopup();
        }
    });

    editor.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (editor.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });
}

From source file:com.sec.ose.osi.ui.frm.main.identification.JComboProjectName.java

public JComboProjectName() {

    this.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    this.setEditable(true);
    this.setPreferredSize(new Dimension(400, 27));
    this.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            long start = System.currentTimeMillis();
            actionOnProjectSelectedonProjectComboBox();
            long end = System.currentTimeMillis();
            log.debug(/*from  ww w. j a v a  2s. c  o  m*/
                    "[JComboProjectName.addActionListener()] Project Loding TIME : " + (end - start) / 1000.0);
        }
    });

    final JTextField editor = (JTextField) this.getEditor().getEditorComponent();
    editor.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {

            char ch = e.getKeyChar();
            int count = 0;
            String newProjectName = editor.getText();

            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))) {
                return;
            }

            if (newProjectName.length() <= 0 && ch == KeyEvent.VK_BACK_SPACE) {
                count++;
                if (count >= 2) {
                    String projectName = IdentifyMediator.getInstance().getSelectedProjectName();
                    ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText(projectName);
                    count = 0;
                    return;
                }
            }
            if (JComboProjectName.this.getComponentCount() > 0) {
                JComboProjectName.this.removeAllItems();
            }

            JComboProjectName.this.addItem(newProjectName);
            try {
                Collection<OSIProjectInfo> ProjectsInfo = OSIProjectInfoMgr.getInstance().getAllProjects();

                String tmpProName = null;
                boolean bAnalysis = false;
                if (newProjectName.length() > 0) {
                    for (OSIProjectInfo projectInfo : ProjectsInfo) {
                        tmpProName = projectInfo.getProjectName();
                        bAnalysis = projectInfo.isAnalyzed();
                        if (tmpProName.toLowerCase().contains(newProjectName.toLowerCase()) && bAnalysis)
                            JComboProjectName.this.addItem(tmpProName);
                    }
                    if (JComboProjectName.this.getItemCount() <= 1) {
                        JComboProjectName.this.removeAllItems();
                        JOptionPane.showOptionDialog(null, "There is no project.", "Project Filter",
                                JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK");
                    }
                } else {
                    for (OSIProjectInfo projectInfo : ProjectsInfo) {
                        if (projectInfo.isManaged() == true && projectInfo.isAnalyzed()) {
                            JComboProjectName.this.addItem(projectInfo.getProjectName());
                        }
                    }
                    JComboProjectName.this.addItem(DIVIDER_LINE);
                    for (OSIProjectInfo projectInfo : ProjectsInfo) {
                        if (projectInfo.isManaged() == false && projectInfo.isAnalyzed()) {
                            JComboProjectName.this.addItem(projectInfo.getProjectName());
                        }
                    }
                    ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText("");
                }
            } catch (Exception e1) {
                log.warn(e1.getMessage());
            }

            JComboProjectName.this.hidePopup();
            if (newProjectName.length() > 0)
                JComboProjectName.this.showPopup();
        }
    });

}

From source file:SwingTypeTester8.java

private void initComponents() {
    handler = new CharacterEventHandler();
    producer = new RandomCharacterGenerator();
    producer.setDone(true);/*from  w  w w  .j a  v a 2 s  .  c o  m*/
    producer.start();
    displayCanvas = new AnimatedCharacterDisplayCanvas(producer);
    feedbackCanvas = new CharacterDisplayCanvas(this);
    quitButton = new JButton();
    startButton = new JButton();
    stopButton = new JButton();
    score = new ScoreLabel(producer, this);

    Container pane = getContentPane();
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.PAGE_AXIS));
    p1.add(displayCanvas);
    p1.add(feedbackCanvas);

    JPanel p2 = new JPanel();
    score.setText("      ");
    score.setFont(new Font("MONOSPACED", Font.BOLD, 30));
    p2.add(score);
    startButton.setText("Start");
    p2.add(startButton);
    stopButton.setText("Stop");
    stopButton.setEnabled(false);
    p2.add(stopButton);
    quitButton.setText("Quit");
    p2.add(quitButton);
    p1.add(p2);
    pane.add(p1, BorderLayout.NORTH);
    pack();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            quit();
        }
    });
    feedbackCanvas.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent ke) {
            char c = ke.getKeyChar();
            if (c != KeyEvent.CHAR_UNDEFINED)
                newCharacter((int) c);
        }
    });
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            displayCanvas.setDone(false);
            producer.setDone(false);
            score.resetScore();
            startButton.setEnabled(false);
            stopButton.setEnabled(true);
            feedbackCanvas.setEnabled(true);
            feedbackCanvas.requestFocus();
        }
    });
    stopButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            startButton.setEnabled(true);
            stopButton.setEnabled(false);
            producer.setDone(true);
            displayCanvas.setDone(true);
            feedbackCanvas.setEnabled(false);
        }
    });
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            quit();
        }
    });
}

From source file:SwingTypeTester9.java

private void initComponents() {
    parent = this;
    handler = new CharacterEventHandler();
    producer = new RandomCharacterGenerator();
    producer.setDone(true);//  w  w  w. j  a v  a 2s  .c  om
    producer.start();
    displayCanvas = new AnimatedCharacterDisplayCanvas(producer);
    feedbackCanvas = new CharacterDisplayCanvas(this);
    quitButton = new JButton();
    startButton = new JButton();
    stopButton = new JButton();
    score = new ScoreLabel(producer, this);

    Container pane = getContentPane();
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.PAGE_AXIS));
    p1.add(displayCanvas);
    p1.add(feedbackCanvas);

    JPanel p2 = new JPanel();
    score.setText("      ");
    score.setFont(new Font("MONOSPACED", Font.BOLD, 30));
    p2.add(score);
    startButton.setText("Start");
    p2.add(startButton);
    stopButton.setText("Stop");
    stopButton.setEnabled(false);
    p2.add(stopButton);
    quitButton.setText("Quit");
    p2.add(quitButton);
    p1.add(p2);
    pane.add(p1, BorderLayout.NORTH);
    pack();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            quit();
        }
    });
    feedbackCanvas.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent ke) {
            char c = ke.getKeyChar();
            if (c != KeyEvent.CHAR_UNDEFINED)
                newCharacter((int) c);
        }
    });
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            new FeedbackFrame(parent).show();
        }
    });
    stopButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            startButton.setEnabled(true);
            stopButton.setEnabled(false);
            producer.setDone(true);
            displayCanvas.setDone(true);
            feedbackCanvas.setEnabled(false);
        }
    });
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            quit();
        }
    });
}

From source file:jetbrains.exodus.sshd.RhinoCommand.java

private boolean isPrintableChar(char c) {
    Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
    return (!Character.isISOControl(c)) && c != KeyEvent.CHAR_UNDEFINED && block != null
            && block != Character.UnicodeBlock.SPECIALS;
}