Example usage for java.awt.event KeyListener KeyListener

List of usage examples for java.awt.event KeyListener KeyListener

Introduction

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

Prototype

KeyListener

Source Link

Usage

From source file:org.OpenNI.Samples.UserTracker.UserTrackerApplication.java

public UserTrackerApplication(JFrame frame) {
    this.frame = frame;
    frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent arg0) {
        }/*w w  w . j a v  a  2  s  .  c  o m*/

        public void keyReleased(KeyEvent arg0) {
        }

        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ESCAPE) {
                shouldRun = false;
            }
        }
    });
}

From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java

public ReadOnlyTextPanePopUpMenu(ReadOnlyTextPane readOnlyTextPane) {

    this.readOnlyTextArea = readOnlyTextPane;
    reflectiveAction = new ReflectiveAction(this);

    String[] menuLabels = { "Copy", "Select All", "Save to File", "Clear" };
    String[] actionCommands = { "copy", "selectAll", "saveToFile", "clear" };
    String[] toolTips = { "", "", "Save the contents to file", "Clear the output pane" };

    for (int i = 0; i < menuLabels.length; i++) {

        add(createMenuItem(menuLabels[i], actionCommands[i], toolTips[i]));
    }/*from   w w w.j ava2s  .c o  m*/

    readOnlyTextPane.getTextComponent().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {

            if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {

                clear(null);
            }
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }

    });

}

From source file:com.emental.mindraider.ui.dialogs.DownloadModelJDialog.java

/**
 * Constructor./*from  www  .j  av  a  2s.  c  o  m*/
 * 
 * @param union
 *            made union of models.
 */
public DownloadModelJDialog(boolean union) {
    super(Messages.getString("DownloadModelJDialog.title"));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5));

    p.add(new JLabel(Messages.getString("DownloadModelJDialog.url")));

    String[] knowUris = new String[] { "http://", "http://wymiwyg.org/", "http://www.osar.ch",
            "http://wymiwyg.org/.rdf?appendLang=en&till=50", "http://www.osar.ch/.rdf?appendLang=de&till=50" };
    modelUrlCombo = new JComboBox(knowUris);
    modelUrlCombo.setEditable(true);
    modelUrlCombo.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                upload();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    p.add(modelUrlCombo);

    JButton uploadButton = new JButton(Messages.getString("DownloadModelJDialog.download"));
    uploadButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            upload();
        }
    });
    p.add(uploadButton);

    JButton cancelButton = new JButton(Messages.getString("DownloadModelJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(cancelButton);

    getContentPane().add(p, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:modmanager.MainWindow.java

private void registerSearch() {
    searchField.addKeyListener(new KeyListener() {

        @Override//  w ww. j a  v a  2s . c  om
        public void keyTyped(KeyEvent ke) {

        }

        @Override
        public void keyPressed(KeyEvent ke) {

        }

        @Override
        public void keyReleased(KeyEvent ke) {
            String sub = searchField.getText();

            for (Modification mod : modifications.getModifications()) {
                if (mod.getName().toLowerCase().contains(sub.toLowerCase())) {
                    modificationList.setSelectedValue(mod, true);

                    if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
                        modificationList.requestFocus();
                        searchField.setText("");
                    }

                    break;
                }
            }

        }
    });
}

From source file:com.wafflesoft.kinectcontroller.Main.java

public void run() {
    KinectUserTracker kinectUserTracker = new KinectUserTracker(_csm);

    _done = false;//  w w  w  . j  a va  2s.c  o  m
    _frame = new JFrame("Kinect Controller");

    // register to key events
    _frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent arg) {
        }

        public void keyReleased(KeyEvent arg) {
        }

        public void keyPressed(KeyEvent arg) {
            if (arg.getKeyCode() == KeyEvent.VK_ESCAPE) {
                _done = true;
            }
        }
    });

    // register to closing event
    _frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            _done = true;
        }
    });

    kinectUserTracker.kinectWindow.setSize(800, 600);

    _frame.add("Center", kinectUserTracker.kinectWindow);

    _eventWindow = new JTextArea();
    _eventWindow.setVisible(!_arguments.hasOption('d'));
    _frame.add(new JScrollPane(_eventWindow));

    _frame.setSize(kinectUserTracker.kinectWindow.getWidth(), kinectUserTracker.kinectWindow.getHeight());
    _frame.setVisible(true);

    while (!_done) {
        _frame.repaint();
        try {
            Thread.sleep(16);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.emental.mindraider.ui.dialogs.ConnectUriqaServerJDialog.java

/**
 * Constructor.//  w  w  w  . ja v  a  2  s .c  om
 */
public ConnectUriqaServerJDialog() {
    super(Messages.getString("ConnectUriqaServerJDialog.title"));
    getContentPane().setLayout(new BorderLayout());

    // north
    JPanel north = new JPanel();
    north.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.serverUrl")));

    uriqaServerUrl = new JTextField("http://sw.nokia.com/uriqa/", 31);
    uriqaServerUrl.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, uriqaServerUrl.getPreferredSize().height));
    uriqaServerUrl.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                connect();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    north.add(uriqaServerUrl);
    getContentPane().add(north, BorderLayout.NORTH);

    // center
    JPanel center = new JPanel();
    center.setLayout(new BorderLayout());

    JPanel centerTop = new JPanel();
    centerTop.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.resource")));
    String[] knowUriqaUris = new String[] { "http://sw.nokia.com/VOC-1/term", "http://sw.nokia.com/MARS-3/Rank",
            "http://sw.nokia.com/MARS-3", "http://sw.nokia.com/schemas/nokia/MARS-3.1.rdf" };
    resourceUri = new JComboBox(knowUriqaUris);
    resourceUri.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, resourceUri.getPreferredSize().height));
    resourceUri.setEditable(true);
    centerTop.add(resourceUri);

    JPanel centerCenter = new JPanel();
    centerCenter.setLayout(new FlowLayout(FlowLayout.LEFT));
    centerCenter.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.loadOverToolTip"));
    centerCenter.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.loadOver")));
    JCheckBox loadOver = new JCheckBox();
    loadOver.setSelected(true);
    loadOver.setEnabled(false);
    centerCenter.add(loadOver);

    JPanel centerBottom = new JPanel();
    centerBottom.setLayout(new FlowLayout(FlowLayout.LEFT));
    centerBottom.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.addInferedToolTip"));
    centerBottom.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.addInfered")));
    addInfered = new JCheckBox();
    addInfered.setSelected(true);
    centerBottom.add(addInfered);

    center.add(centerTop, BorderLayout.NORTH);
    center.add(centerCenter, BorderLayout.CENTER);
    center.add(centerBottom, BorderLayout.SOUTH);
    getContentPane().add(center, BorderLayout.CENTER);

    // south
    JPanel south = new JPanel();
    JButton uploadButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.connect"));
    uploadButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            connect();
        }
    });
    south.add(uploadButton);

    JButton cancelButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    south.add(cancelButton);
    getContentPane().add(south, BorderLayout.SOUTH);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:org.uecide.About.java

public About(Editor e) {
    editor = e;//from   w  w  w  .j a va 2  s . c o m
    frame = new JDialog(editor, JDialog.ModalityType.APPLICATION_MODAL);
    mainContainer = new JPanel();
    mainContainer.setLayout(new BorderLayout());
    frame.add(mainContainer);

    int imageWidth = 0;

    try {
        URL loc = About.class.getResource("/org/uecide/icons/about.png");
        image = ImageIO.read(loc);
        imageWidth = image.getWidth();
        JLabel picLabel = new JLabel(new ImageIcon(image));

        mainContainer.add(picLabel, BorderLayout.NORTH);
    } catch (Exception ex) {
        Base.error(ex);
    }

    infoScroll = new JScrollPane();
    infoScroll.setPreferredSize(new Dimension(imageWidth, 150));

    info = new JTextPane();
    info.setContentType("text/html");
    infoScroll.setViewportView(info);

    info.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    info.setEditable(false);
    info.setBackground(new Color(0, 0, 0));
    info.setForeground(new Color(0, 255, 0));
    Font f = info.getFont();

    info.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e.getDescription().equals("uecide://close")) {
                    frame.dispose();
                    return;
                }
                Base.openURL(e.getURL().toString());
            }
        }
    });

    HTMLEditorKit kit = new HTMLEditorKit();
    info.setEditorKit(kit);
    StyleSheet css = kit.getStyleSheet();

    css.addRule("body {color: #88ff88; font-family: Arial,Helvetica,Sans-Serif;}");
    css.addRule("a {color: #88ffff;}");
    css.addRule("a:visited {color: #00aaaa;}");
    Document doc = kit.createDefaultDocument();
    info.setDocument(doc);

    info.setText(generateInfoData());

    info.setCaretPosition(0);
    mainContainer.add(infoScroll, BorderLayout.CENTER);

    frame.pack();

    Dimension mySize = frame.getSize();

    Dimension eSize = editor.getSize();
    Point ePos = editor.getLocation();
    frame.setLocation(new Point(ePos.x + (eSize.width / 2) - mySize.width / 2,
            ePos.y + (eSize.height / 2) - mySize.height / 2));

    frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent ev) {
        }

        public void keyPressed(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) {
                frame.dispose();
            }
        }

        public void keyReleased(KeyEvent ev) {
        }
    });

    frame.setVisible(true);
}

From source file:com.emental.mindraider.ui.dialogs.AddTripletJDialog.java

/**
 * Constructor./*from ww  w.  java 2  s.c o m*/
 */
public AddTripletJDialog() {
    super("Add Triplet");

    JPanel framePanel = new JPanel();
    framePanel.setLayout(new GridLayout(4, 1));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(" Predicate: "));

    predicateNs = new JTextField(30);
    predicateNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    predicateNs.selectAll();
    p.add(predicateNs);
    p.add(new JLabel("#"));
    predicateLocalName = new JTextField(15);
    p.add(predicateLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(" Object: "));

    objectNs = new JTextField(30);
    objectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    objectNs.selectAll();
    p.add(objectNs);
    p.add(new JLabel("#"));
    objectLocalName = new JTextField(15);
    objectLocalName.grabFocus();
    objectLocalName.selectAll();
    objectLocalName.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                createTriplet();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });

    p.add(objectLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    literalCheckBox = new JCheckBox("literal", false);
    p.add(literalCheckBox);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton("Add");
    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            createTriplet();
        }
    });

    JButton cancelButton = new JButton("Cancel");
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            AddTripletJDialog.this.dispose();
        }
    });
    framePanel.add(p);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);

    addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            getObjectLocalName().requestFocusInWindow();
        }
    });
}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

public MirthTable(String prefix, Set<String> defaultVisibleColumns) {
    super();//from   www. j  a  v a  2  s .co  m

    this.prefix = prefix;
    this.defaultVisibleColumns = defaultVisibleColumns;

    userPreferences = Preferences.userNodeForPackage(Mirth.class);
    columnOrderMap = new HashMap<String, Integer>();
    if (StringUtils.isNotEmpty(prefix)) {
        try {
            userPreferences = Preferences.userNodeForPackage(Mirth.class);
            String columns = userPreferences.get(prefix + "ColumnOrderMap", "");

            if (StringUtils.isNotEmpty(columns)) {
                columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns,
                        Map.class);
            }
        } catch (Exception e) {
        }

        sortKeys = new ArrayList<SortKey>();
        try {
            String sortOrder = userPreferences.get(prefix + "SortOrder", "");

            if (StringUtils.isNotEmpty(sortOrder)) {
                sortKeys = ObjectXMLSerializer.getInstance().deserialize(sortOrder, List.class);
            }
        } catch (Exception e) {
        }
    }

    setDragEnabled(true);
    addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            boolean isAccelerated = (((e.getModifiers()
                    & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0)
                    || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0));
            if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) {
                PlatformUI.MIRTH_FRAME.doContextSensitiveSave();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

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

    /*
     * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping
     * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can
     * override it.
     */
    putClientProperty("terminateEditOnFocusLost", Boolean.FALSE);

    getTableHeader().addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            saveColumnOrder();
        }
    });

    final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon());

    columnControlButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu columnMenu = getColumnMenu();
            Dimension buttonSize = columnControlButton.getSize();
            int xPos = columnControlButton.getComponentOrientation().isLeftToRight()
                    ? buttonSize.width - columnMenu.getPreferredSize().width
                    : 0;
            columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight());
        }
    });

    setColumnControl(columnControlButton);
}

From source file:com.floreantpos.ui.views.CookingInstructionSelectionView.java

private void createUI() {
    setTitle(Messages.getString("CookingInstructionSelectionView.1"));
    setTitlePaneText(Messages.getString("CookingInstructionSelectionView.1")); //$NON-NLS-1$
    getContentPanel().setBorder(new EmptyBorder(10, 20, 0, 20));

    JScrollPane scrollPane = new JScrollPane();
    table = new JTable();
    table.setRowHeight(35);//from ww  w .  j  av  a2s .c  o  m
    scrollPane.setViewportView(table);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = table.getSelectedRow();
            if (index < 0)
                return;
            CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel();
            CookingInstruction cookingInstruction = model.rowsList.get(index);
            tfCookingInstruction.setText(cookingInstruction.getDescription());
        }
    });

    tfCookingInstruction.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            doFilter();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            doFilter();
        }

        @Override
        public void keyPressed(KeyEvent e) {

        }
    });

    PosButton btnSave = new PosButton(IconFactory.getIcon("save.png"));
    btnSave.setText(POSConstants.SAVE.toUpperCase());
    btnSave.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String instruction = tfCookingInstruction.getText();
            if (instruction == null || instruction.isEmpty()) {
                POSMessageDialog.showMessage(Application.getPosWindow(), "Instruction cannot be empty.");
                return;
            }
            CookingInstruction cookingInstruction = new CookingInstruction();
            cookingInstruction.setDescription(instruction);
            CookingInstructionDAO.getInstance().save(cookingInstruction);
            updateView();
            CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel();
            table.getSelectionModel().addSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1);
        }
    });
    JPanel contentPanel = new JPanel(new MigLayout("fill,wrap 1,inset 0"));
    contentPanel.add(scrollPane, "grow");
    contentPanel.add(tfCookingInstruction, "h 35!,split 2,grow");
    contentPanel.add(btnSave, "h 35!,w 90!");
    QwertyKeyPad keyPad = new QwertyKeyPad();
    contentPanel.add(keyPad, "grow");
    getContentPanel().add(contentPanel);
}