Search in sources :

Example 11 with KeyAdapter

use of java.awt.event.KeyAdapter in project jdk8u_jdk by JetBrains.

the class SwallowKeyEvents method main.

public static void main(String[] args) {
    if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.WINDOWS) {
        System.out.println("Skipped. Test not for MS Windows.");
        return;
    }
    f.add(t);
    f.pack();
    f.setVisible(true);
    t.requestFocus();
    try {
        r = new Robot();
    } catch (AWTException ex) {
        throw new RuntimeException(ex);
    }
    Util.waitForIdle(r);
    t.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent ke) {
            System.out.println(ke);
            if (ke.getKeyCode() == KeyEvent.VK_M) {
                keyPressedCount++;
            }
        }
    });
    test();
    System.out.println("key_pressed count: " + keyPressedCount);
    if (keyPressedCount != PRESS_COUNT) {
        throw new RuntimeException("Test failed!");
    } else {
        System.out.println("Test passed.");
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 12 with KeyAdapter

use of java.awt.event.KeyAdapter in project pcgen by PCGen.

the class TipOfTheDay method initUI.

//
// initialize the dialog
//
private void initUI() {
    final JPanel panel = new JPanel(new BorderLayout(2, 2));
    panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JLabel iconLabel;
    final Icon icon = Icons.TipOfTheDay24.getImageIcon();
    iconLabel = icon != null ? new JLabel(icon) : new JLabel("TipOfTheDay24.gif");
    iconLabel.setOpaque(true);
    panel.add(iconLabel, BorderLayout.WEST);
    final JLabel lblDidYouKnow = new JLabel("    " + LanguageBundle.getString("in_tod_didyouknow"));
    FontManipulation.xxlarge(lblDidYouKnow);
    lblDidYouKnow.setOpaque(true);
    tipText = new JLabelPane();
    tipText.setBorder(null);
    tipText.setFocusable(false);
    tipText.addHyperlinkListener(new Hyperactive());
    final JScrollPane pane = new JScrollPane(tipText);
    pane.setBorder(null);
    final JPanel content = new JPanel(new BorderLayout(0, 2));
    content.add(lblDidYouKnow, BorderLayout.NORTH);
    content.add(pane, BorderLayout.CENTER);
    content.setPreferredSize(new Dimension(585, 230));
    panel.add(content, BorderLayout.CENTER);
    chkShowTips = new JCheckBox(LanguageBundle.getString("in_tod_showTips"), propertyContext.initBoolean("showTipOfTheDay", true));
    final JButton btnClose = new JButton(LanguageBundle.getString("in_close"));
    btnClose.setMnemonic(LanguageBundle.getMnemonic("in_mn_close"));
    btnClose.addActionListener(this);
    // TODO give focus to close button
    final JButton btnPrevTip = new JButton(LanguageBundle.getString("in_tod_prevTip"));
    btnPrevTip.setMnemonic(LanguageBundle.getMnemonic("in_mn_tod_prevTip"));
    btnPrevTip.addActionListener(this);
    btnPrevTip.setActionCommand(PREV);
    final JButton btnNextTip = new JButton(LanguageBundle.getString("in_tod_nextTip"));
    btnNextTip.setMnemonic(LanguageBundle.getMnemonic("in_mn_tod_nextTip"));
    btnNextTip.addActionListener(this);
    btnNextTip.setActionCommand(NEXT);
    final JPanel actions = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0);
    actions.add(chkShowTips, c);
    final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttons.add(btnPrevTip);
    buttons.add(btnNextTip);
    buttons.add(btnClose);
    c.gridx = 1;
    c.anchor = GridBagConstraints.EAST;
    actions.add(buttons, c);
    panel.add(actions, BorderLayout.SOUTH);
    setContentPane(panel);
    getRootPane().setDefaultButton(btnClose);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                quit();
            }
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JLabelPane(pcgen.gui2.util.JLabelPane) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) Hyperactive(pcgen.gui2.tools.Hyperactive) WindowEvent(java.awt.event.WindowEvent) Icon(javax.swing.Icon)

Example 13 with KeyAdapter

use of java.awt.event.KeyAdapter in project yyl_example by Relucent.

the class KeyToolUI method initContainer.

/**
	 * 初始化界面
	 */
private void initContainer() {
    Container container = frame.getContentPane();
    tabbedPane = new JTabbedPane();
    container.add(tabbedPane);
    tabbedPane.add("产生密钥", new CertContent1().getContainer());
    tabbedPane.add("导出密钥", new CertContent2().getContainer());
    tabbedPane.add("检查密钥", new CertContent3().getContainer());
    tabbedPane.add("导入密钥", new CertContent4().getContainer());
    tabbedPane.add("删除密钥", new CertContent5().getContainer());
    tabbedPane.add("生成私钥", new CertContent6().getContainer());
    tabbedPane.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_F1 == e.getKeyCode()) {
                frame.setTitle("Copyright (c) 2009 YaoYiLang  redrainyi@gmail.com");
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (KeyEvent.VK_F1 == e.getKeyCode()) {
                frame.setTitle("Keystore");
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) Container(java.awt.Container) JTabbedPane(javax.swing.JTabbedPane) KeyAdapter(java.awt.event.KeyAdapter)

Example 14 with KeyAdapter

use of java.awt.event.KeyAdapter in project yyl_example by Relucent.

the class Command method registerListener.

private void registerListener() {
    txtDebug.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
                e.setKeyCode(27);
            }
            if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
                try {
                    String str = doc.getText(execOffset, doc.getLength() - execOffset);
                    exec(str + "\n");
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

        public void keyTyped(KeyEvent e) {
        // System.out.println(e.getKeyChar());
        }
    });
    doc.addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
        }

        public void removeUpdate(DocumentEvent e) {
        }
    });
    txtDebug.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
                caret.setDot(execOffset);
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) CaretEvent(javax.swing.event.CaretEvent) DocumentListener(javax.swing.event.DocumentListener) CaretListener(javax.swing.event.CaretListener) KeyAdapter(java.awt.event.KeyAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 15 with KeyAdapter

use of java.awt.event.KeyAdapter in project intellij-community by JetBrains.

the class MavenArtifactSearchPanel method initComponents.

private void initComponents(String initialText) {
    myResultList = new Tree();
    myResultList.setExpandableItemsEnabled(false);
    myResultList.getEmptyText().setText("Loading...");
    myResultList.setRootVisible(false);
    myResultList.setShowsRootHandles(true);
    myResultList.setModel(null);
    MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
    myResultList.setCellRenderer(renderer);
    myResultList.setRowHeight(renderer.getPreferredSize().height);
    mySearchField = new JTextField(initialText);
    mySearchField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            int d;
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                d = 1;
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                d = -1;
            } else {
                return;
            }
            int row = myResultList.getSelectionModel().getLeadSelectionRow();
            row += d;
            if (row >= 0 && row < myResultList.getRowCount()) {
                myResultList.setSelectionRow(row);
            }
        }
    });
    setLayout(new BorderLayout());
    add(mySearchField, BorderLayout.NORTH);
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // Don't remove this line.
    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
    // works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
    add(pane, BorderLayout.CENTER);
    mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            scheduleSearch();
        }
    });
    myResultList.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!myAlarm.isEmpty())
                return;
            boolean hasSelection = !myResultList.isSelectionEmpty();
            myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
        }
    });
    myResultList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
                myListener.itemSelected();
                e.consume();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
            if (path != null && myResultList.isPathSelected(path)) {
                Object sel = path.getLastPathComponent();
                if (sel != null && myResultList.getModel().isLeaf(sel)) {
                    myListener.itemSelected();
                    return true;
                }
            }
            return false;
        }
    }.installOn(myResultList);
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DocumentEvent(javax.swing.event.DocumentEvent) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

KeyAdapter (java.awt.event.KeyAdapter)70 KeyEvent (java.awt.event.KeyEvent)70 MouseEvent (java.awt.event.MouseEvent)26 MouseAdapter (java.awt.event.MouseAdapter)16 JPanel (javax.swing.JPanel)15 ActionEvent (java.awt.event.ActionEvent)14 JLabel (javax.swing.JLabel)14 ActionListener (java.awt.event.ActionListener)13 JButton (javax.swing.JButton)12 JScrollPane (javax.swing.JScrollPane)12 BorderLayout (java.awt.BorderLayout)11 JTextField (javax.swing.JTextField)11 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 NotNull (org.jetbrains.annotations.NotNull)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Dimension (java.awt.Dimension)8 ListSelectionEvent (javax.swing.event.ListSelectionEvent)7 ListSelectionListener (javax.swing.event.ListSelectionListener)7