Example usage for java.awt.event KeyEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:com.kenai.redminenb.query.RedmineQueryController.java

@Override
public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() != KeyEvent.VK_ENTER) {
        return;// w  w  w  . ja  v a 2  s. co  m
    }
    if (e.getSource() == queryPanel.categoryList || e.getSource() == queryPanel.versionList
            || e.getSource() == queryPanel.statusList || e.getSource() == queryPanel.resolutionList
            || e.getSource() == queryPanel.priorityList || e.getSource() == queryPanel.assigneeList) {
        onRefresh();
    }
}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

private void handleKeyEvent(KeyEvent event) {
    if (!(event.getSource() instanceof JComboBox)) {
        if (event.getKeyCode() == KeyEvent.VK_UP) {
            moveCursor(true);//www  .  jav a 2  s.  co m
        } else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
            moveCursor(false);
        }
    }
}

From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override/*  ww  w . j av  a  2 s.c o m*/
        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();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectoryObject(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:net.sf.vfsjfilechooser.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override/* w w w  .j  a  v  a 2s. com*/
        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();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectory(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:net.sf.jabref.gui.AutoCompleteListener.java

@Override
public void keyTyped(KeyEvent e) {
    LOGGER.debug("key typed event caught " + e.getKeyCode());
    char ch = e.getKeyChar();
    if (ch == '\n') {
        // this case is handled at keyPressed(e)
        return;//from www  .ja  v  a  2 s .c  o  m
    }

    if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) {
        // plain key or SHIFT + key is pressed, no handling of CTRL+key,  META+key, ...
        if (Character.isLetter(ch) || Character.isDigit(ch)
                || (Character.isWhitespace(ch) && completer.isSingleUnitField())) {
            JTextComponent comp = (JTextComponent) e.getSource();

            if (toSetIn == null) {
                LOGGER.debug("toSetIn is null");
            } else {
                LOGGER.debug("toSetIn: >" + toSetIn + '<');
            }

            // The case-insensitive system is a bit tricky here
            // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O"
            // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O".

            if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) {
                // User continues on the word that was suggested.
                LOGGER.debug("cont");

                toSetIn = toSetIn.substring(1);
                if (!toSetIn.isEmpty()) {
                    int cp = comp.getCaretPosition();
                    //comp.setCaretPosition(cp+1-toSetIn.);
                    //System.out.println(cp-toSetIn.length()+" - "+cp);
                    comp.select((cp + 1) - toSetIn.length(), cp);
                    lastBeginning = lastBeginning + ch;

                    e.consume();
                    lastCaretPosition = comp.getCaretPosition();

                    //System.out.println("Added char: '"+toSetIn+"'");
                    //System.out.println("LastBeginning: '"+lastBeginning+"'");

                    lastCompletions = findCompletions(lastBeginning, comp);
                    lastShownCompletion = 0;
                    for (int i = 0; i < lastCompletions.length; i++) {
                        String lastCompletion = lastCompletions[i];
                        //System.out.println("Completion["+i+"] = "+lastCompletion);
                        if (lastCompletion.endsWith(toSetIn)) {
                            lastShownCompletion = i;
                            break;
                        }

                    }
                    //System.out.println("Index now: "+lastShownCompletion);
                    if (toSetIn.length() < 2) {
                        // User typed the last character of the autocompleted word
                        // We have to replace the automcompletion word by the typed word.
                        // This helps if the user presses "space" after the completion
                        // "space" indicates that the user does NOT want the autocompletion,
                        // but the typed word
                        String text = comp.getText();
                        comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length())
                                + lastBeginning + text.substring(lastCaretPosition));
                        // there is no selected text, therefore we are not updating the selection
                        toSetIn = null;
                    }
                    return;
                }
            }

            if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) {
                // User discontinues the word that was suggested.
                lastBeginning = lastBeginning + ch;

                LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<');

                String[] completed = findCompletions(lastBeginning, comp);
                if ((completed != null) && (completed.length > 0)) {
                    lastShownCompletion = 0;
                    lastCompletions = completed;
                    String sno = completed[0];
                    // toSetIn = string used for autocompletion last time
                    // this string has to be removed
                    // lastCaretPosition is the position of the caret after toSetIn.
                    int lastLen = toSetIn.length() - 1;
                    toSetIn = sno.substring(lastBeginning.length() - 1);
                    String text = comp.getText();
                    //Util.pr(""+lastLen);
                    //we do not use toSetIn as we want to obey the casing of "sno"
                    comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1)
                            + sno + text.substring(lastCaretPosition));
                    int startSelect = (lastCaretPosition + 1) - lastLen;
                    int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen;
                    comp.select(startSelect, endSelect);

                    lastCaretPosition = comp.getCaretPosition();
                    e.consume();
                    return;
                } else {
                    setUnmodifiedTypedLetters(comp, true, false);
                    e.consume();
                    toSetIn = null;
                    return;
                }
            }

            LOGGER.debug("case else");

            comp.replaceSelection("");

            StringBuffer currentword = getCurrentWord(comp);
            if (currentword == null) {
                currentword = new StringBuffer();
            }

            // only "real characters" end up here
            assert (!Character.isISOControl(ch));
            currentword.append(ch);
            startCompletion(currentword, e);
            return;
        } else {
            if (Character.isWhitespace(ch)) {
                assert (!completer.isSingleUnitField());
                LOGGER.debug("whitespace && !singleUnitField");
                // start a new search if end-of-field is reached

                // replace displayed letters with typed letters
                setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true);
                resetAutoCompletion();
                return;
            }

            LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED");
            // replace displayed letters with typed letters 
            setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch));
            resetAutoCompletion();
            return;
        }
    }
    resetAutoCompletion();
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Listener used to handle search input for the organisations tree
 * //from www.  j ava2  s  .co  m
 * @return
 */
private KeyListener getSearchFieldListener() {

    return new KeyListener() {

        public void keyTyped(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            requestSearchTree(((JTextField) e.getSource()).getText());
        }

        public void keyPressed(KeyEvent e) {
        }
    };
}

From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java

/**
 * /*from  www .j  a  v  a  2s  .  c  om*/
 */
private void addUserToDS() {
    final Vector<String> wsList = new Vector<String>();
    final Vector<String> instItems = new Vector<String>();

    String addStr = getResourceString("ADD");
    instItems.add(addStr);
    wsList.add(addStr);
    for (String fullName : cloudHelper.getInstList()) {
        String[] toks = StringUtils.split(fullName, '\t');
        instItems.add(toks[0]);
        wsList.add(toks[1]);
    }

    final JTextField userNameTF = createTextField(20);
    final JTextField passwordTF = createTextField(20);
    final JLabel pwdLbl = createI18NFormLabel("Password");
    final JLabel statusLbl = createLabel("");
    final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User");
    final JLabel instLbl = createI18NFormLabel("Insitution");
    final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray());

    if (instItems.size() == 2) {
        instCmbx.setSelectedIndex(1);
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p"));

    pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3));
    pb.add(createI18NFormLabel("Username"), cc.xy(1, 3));
    pb.add(userNameTF, cc.xy(3, 3));
    pb.add(pwdLbl, cc.xy(1, 5));
    pb.add(passwordTF, cc.xy(3, 5));
    pb.add(instLbl, cc.xy(1, 7));
    pb.add(instCmbx, cc.xy(3, 7));

    pb.add(isNewUser, cc.xy(3, 9));

    pb.add(statusLbl, cc.xyw(1, 11, 3));
    pb.setDefaultDialogBorder();

    pwdLbl.setVisible(false);
    passwordTF.setVisible(false);
    instLbl.setVisible(false);
    instCmbx.setVisible(false);

    final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) {
        @Override
        protected void okButtonPressed() {
            String usrName = userNameTF.getText();
            if (cloudHelper.isUserNameOK(usrName)) {
                String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                    super.okButtonPressed();
                } else {
                    iPadDBExporterPlugin.setErrorMsg(statusLbl,
                            String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid));
                }
            } else if (isNewUser.isSelected()) {
                String pwdStr = passwordTF.getText();
                String guid = null;
                if (instCmbx.getSelectedIndex() == 0) {
                    //                        InstDlg instDlg = new InstDlg(cloudHelper);
                    //                        if (!instDlg.isInstOK())
                    //                        {
                    //                            instDlg.createUI();
                    //                            instDlg.pack();
                    //                            centerAndShow(instDlg, 600, null);
                    //                            if (instDlg.isCancelled())
                    //                            {
                    //                                return;
                    //                            }
                    //                            //guid = instDlg.getGuid()();
                    //                        }
                } else {
                    //webSite = wsList.get(instCmbx.getSelectedIndex());

                }

                if (guid != null) {
                    String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                    if (cloudHelper.addNewUser(usrName, pwdStr, guid)) {
                        if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                            ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList();
                            super.okButtonPressed();
                        } else {
                            iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                    String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                        }
                    } else {
                        iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                    }
                } else {
                    // error
                }
            } else {
                iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName));
            }
        }
    };

    KeyAdapter ka = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            statusLbl.setText("");
            String usrNmStr = userNameTF.getText();
            boolean hasData = StringUtils.isNotEmpty(usrNmStr)
                    && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText()))
                    && UIHelper.isValidEmailAddress(usrNmStr);
            dlg.getOkBtn().setEnabled(hasData);
        }

    };
    userNameTF.addKeyListener(ka);
    passwordTF.addKeyListener(ka);

    final Color textColor = userNameTF.getForeground();

    FocusAdapter fa = new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (!tf.getForeground().equals(textColor)) {
                tf.setText("");
                tf.setForeground(textColor);
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (tf.getText().length() == 0) {
                tf.setText("Enter email address");
                tf.setForeground(Color.LIGHT_GRAY);
            }
        }
    };
    userNameTF.addFocusListener(fa);

    userNameTF.setText("Enter email address");
    userNameTF.setForeground(Color.LIGHT_GRAY);

    isNewUser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = isNewUser.isSelected();
            pwdLbl.setVisible(isSel);
            passwordTF.setVisible(isSel);
            instLbl.setVisible(isSel);
            instCmbx.setVisible(isSel);

            Dimension s = dlg.getSize();
            int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height;
            s.height += isSel ? hgt : -hgt;
            dlg.setSize(s);
        }
    });

    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        loadUsersForDataSetsIntoJList();
    }
}

From source file:PVGraph.java

public PVGraph(Calendar date, int initialViewIndex) {
    super(WINDOW_TITLE_PREFIX);
    this.date = date;
    synchronized (graphs) {
        graphs.add(this);
    }//ww w  .  j av  a  2  s. com

    views = new PVGraphView[4];
    views[DAY_VIEW_INDEX] = new DayView();
    views[MONTH_VIEW_INDEX] = new MonthView();
    views[YEAR_VIEW_INDEX] = new YearView();
    views[YEARS_VIEW_INDEX] = new YearsView();

    tabPane = new JTabbedPane();
    for (PVGraphView v : views)
        tabPane.addTab(v.getTabLabel(), v.makePanel());
    tabPane.setSelectedIndex(initialViewIndex);
    setContentPane(tabPane);
    pack();
    try {
        java.net.URL url = getClass().getResource("sun.png");
        if (url != null)
            setIconImage(ImageIO.read(url));
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    ;
    setVisible(true);

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent ke) {
            Object src = ke.getSource();
            if (src instanceof JComponent && ((JComponent) src).getRootPane().getContentPane() == tabPane) {
                if (ke.getID() == KeyEvent.KEY_TYPED) {
                    switch (ke.getKeyChar()) {
                    case 'd':
                        tabPane.setSelectedIndex(DAY_VIEW_INDEX);
                        return true;
                    case 'm':
                        tabPane.setSelectedIndex(MONTH_VIEW_INDEX);
                        return true;
                    case 'N' - 0x40:
                        new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex());
                        return true;
                    case 'Q' - 0x40:
                        dispatchEvent(new WindowEvent(PVGraph.this, WindowEvent.WINDOW_CLOSING));
                        return true;
                    case 'R' - 0x40:
                        loadProperties();
                        updateView();
                        return true;
                    case 'S':
                        try {
                            runSmatool();
                            updateView();
                        } catch (IOException ioe) {
                            System.err.println(ioe.getMessage());
                        }
                        return true;
                    case 'y':
                        tabPane.setSelectedIndex(YEAR_VIEW_INDEX);
                        return true;
                    case 'Y':
                        tabPane.setSelectedIndex(YEARS_VIEW_INDEX);
                        return true;
                    default:
                        return views[tabPane.getSelectedIndex()].handleKey(ke.getKeyChar());
                    }
                }
            }
            return false;
        }
    });
}

From source file:SIFT_Volume_Stitching.java

public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_F1) && (e.getSource() instanceof TextField)) {
    }/*from w w w .java 2  s.  co  m*/
}

From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java

private void buildTree() {
    tree = new JTree(new ScriptsTreeModel(roots));
    tree.setCellRenderer(new ScriptsTreeCellRenderer());
    tree.setRootVisible(false);//from  w  w w .  j  a  v a  2s .co m
    tree.setShowsRootHandles(true);
    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                runScripts();
            }
        }
    });
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (!e.isPopupTrigger() && e.getClickCount() == 2) {
                if (tree.getModel().isLeaf(tree.getSelectionPath().getLastPathComponent())) {
                    runScripts();
                }
            }
        }

        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
                TreePath[] paths = tree.getSelectionPaths();
                boolean newPath = true;
                for (TreePath path : paths) {
                    if (selPath.equals(path)) {
                        newPath = false;
                        break;
                    }
                }
                if (newPath) {
                    tree.setSelectionPath(selPath);
                }
                popup.show((Component) e.getSource(), e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
                TreePath[] paths = tree.getSelectionPaths();
                boolean newPath = true;
                for (TreePath path : paths) {
                    if (selPath.equals(path)) {
                        newPath = false;
                        break;
                    }
                }
                if (newPath) {
                    tree.setSelectionPath(selPath);
                }
                popup.show((Component) e.getSource(), e.getX(), e.getY());
            }
        }
    });
}