Search in sources :

Example 71 with KeyAdapter

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

the class ExtendedKeyCodeTest method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Frame frame = new Frame();
    frame.setSize(300, 300);
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            eventsCount++;
            setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
        }

        @Override
        public void keyReleased(KeyEvent e) {
            eventsCount++;
            setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
        }
    });
    frame.setVisible(true);
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_D);
    robot.keyRelease(KeyEvent.VK_D);
    toolkit.realSync();
    frame.dispose();
    if (eventsCount != 2 || !setExtendedKeyCode) {
        throw new RuntimeException("Wrong extended key code");
    }
    frame = new Frame();
    frame.setSize(300, 300);
    setExtendedKeyCode = false;
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            setExtendedKeyCode = e.getExtendedKeyCode() == KeyEvent.VK_LEFT;
        }
    });
    frame.setVisible(true);
    toolkit.realSync();
    robot.keyPress(KeyEvent.VK_LEFT);
    robot.keyRelease(KeyEvent.VK_LEFT);
    toolkit.realSync();
    frame.dispose();
    if (!setExtendedKeyCode) {
        throw new RuntimeException("Wrong extended key code!");
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Frame(java.awt.Frame) KeyAdapter(java.awt.event.KeyAdapter) SunToolkit(sun.awt.SunToolkit) Robot(java.awt.Robot)

Example 72 with KeyAdapter

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

the class TestApplet method init.

public void init() {
    final TextArea log = new TextArea("Events:\n");
    log.setEditable(false);
    log.setSize(400, 200);
    this.add(log);
    log.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            log.append("Key typed: char = " + e.getKeyChar() + "\n");
        }

        @Override
        public void keyPressed(KeyEvent e) {
            log.append("Key pressed: char = " + e.getKeyChar() + " code = " + e.getKeyCode() + "\n");
        }

        @Override
        public void keyReleased(KeyEvent e) {
            log.append("Key released: char = " + e.getKeyChar() + " code = " + e.getKeyCode() + "\n");
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) TextArea(java.awt.TextArea) KeyAdapter(java.awt.event.KeyAdapter)

Example 73 with KeyAdapter

use of java.awt.event.KeyAdapter in project jabref by JabRef.

the class BasePanel method createMainTable.

private void createMainTable() {
    bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer());
    bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance());
    tableFormat = new MainTableFormat(bibDatabaseContext.getDatabase());
    tableFormat.updateTableFormat();
    mainTable = new MainTable(tableFormat, tableModel, frame, this);
    selectionListener = new MainTableSelectionListener(this, mainTable);
    mainTable.updateFont();
    mainTable.addSelectionListener(selectionListener);
    mainTable.addMouseListener(selectionListener);
    mainTable.addKeyListener(selectionListener);
    mainTable.addFocusListener(selectionListener);
    // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX)
    mainTable.addSelectionListener(listEvent -> Platform.runLater(() -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())));
    String clearSearch = "clearSearch";
    mainTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), clearSearch);
    mainTable.getActionMap().put(clearSearch, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // need to close these here, b/c this action overshadows the responsible actions when the main table is selected
            switch(mode) {
                case SHOWING_NOTHING:
                    frame.getGlobalSearchBar().endSearch();
                    break;
                case SHOWING_PREVIEW:
                    getPreviewPanel().close();
                    break;
                case SHOWING_EDITOR:
                case WILL_SHOW_EDITOR:
                    getCurrentEditor().close();
                    break;
                default:
                    LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing");
                    break;
            }
        }
    });
    mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.CUT);
            } catch (Throwable ex) {
                LOGGER.warn("Could not cut", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.COPY);
            } catch (Throwable ex) {
                LOGGER.warn("Could not copy", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.PASTE);
            } catch (Throwable ex) {
                LOGGER.warn("Could not paste", ex);
            }
        }
    });
    mainTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            if (e.isControlDown()) {
                switch(keyCode) {
                    case KeyEvent.VK_PAGE_DOWN:
                        frame.nextTab.actionPerformed(null);
                        e.consume();
                        break;
                    case KeyEvent.VK_PAGE_UP:
                        frame.prevTab.actionPerformed(null);
                        e.consume();
                        break;
                    default:
                        break;
                }
            } else if (keyCode == KeyEvent.VK_ENTER) {
                e.consume();
                try {
                    runCommand(Actions.EDIT);
                } catch (Throwable ex) {
                    LOGGER.warn("Could not run action based on key press", ex);
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MainTableFormat(org.jabref.gui.maintable.MainTableFormat) MainTableSelectionListener(org.jabref.gui.maintable.MainTableSelectionListener) MainTable(org.jabref.gui.maintable.MainTable) AbstractAction(javax.swing.AbstractAction)

Example 74 with KeyAdapter

use of java.awt.event.KeyAdapter in project JMRI by JMRI.

the class IconAdder method complete.

/*
     * Supports selection of NamedBean from a pick list table
     * @param addIconAction - ActionListener that adds an icon to the panel -
     * representing either an entity a pick list selection, an
     * arbitrary inmage, or a value, such a
     * memory value.
     * @param changeIconAction - ActionListener that displays sources from
     * which to select an image file.  
     */
public void complete(ActionListener addIconAction, boolean changeIcon, boolean addToTable, boolean update) {
    _update = update;
    if (_buttonPanel != null) {
        this.remove(_buttonPanel);
    }
    _buttonPanel = new JPanel();
    _buttonPanel.setLayout(new BoxLayout(_buttonPanel, BoxLayout.Y_AXIS));
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    if (addToTable) {
        _sysNametext = new JTextField();
        _sysNametext.setPreferredSize(new Dimension(150, _sysNametext.getPreferredSize().height + 2));
        _addTableButton = new JButton(Bundle.getMessage("addToTable"));
        _addTableButton.addActionListener((ActionEvent a) -> {
            addToTable();
        });
        _addTableButton.setEnabled(false);
        _addTableButton.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
        p.add(_sysNametext);
        _sysNametext.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent a) {
                if (_sysNametext.getText().length() > 0) {
                    _addTableButton.setEnabled(true);
                    _addTableButton.setToolTipText(null);
                    _table.clearSelection();
                }
            }
        });
        p.add(_addTableButton);
        _buttonPanel.add(p);
        p = new JPanel();
        //new BoxLayout(p, BoxLayout.Y_AXIS)
        p.setLayout(new FlowLayout());
    }
    if (update) {
        _addButton = new JButton(Bundle.getMessage("ButtonUpdateIcon"));
    } else {
        _addButton = new JButton(Bundle.getMessage("ButtonAddIcon"));
    }
    _addButton.addActionListener(addIconAction);
    _addButton.setEnabled(true);
    if (changeIcon) {
        _changeButton = new JButton(Bundle.getMessage("ButtonChangeIcon"));
        _changeButton.addActionListener((ActionEvent a) -> {
            addCatalog();
        });
        p.add(_changeButton);
        _closeButton = new JButton(Bundle.getMessage("ButtonCloseCatalog"));
        _closeButton.addActionListener((ActionEvent a) -> {
            closeCatalog();
        });
        _closeButton.setVisible(false);
        p.add(_closeButton);
    }
    _buttonPanel.add(p);
    if (_table != null) {
        _addButton.setEnabled(false);
        _addButton.setToolTipText(Bundle.getMessage("ToolTipPickFromTable"));
    }
    addAdditionalButtons(_buttonPanel);
    p = new JPanel();
    p.add(_addButton);
    _buttonPanel.add(p);
    _buttonPanel.add(Box.createVerticalStrut(STRUT_SIZE));
    _buttonPanel.add(new JSeparator());
    this.add(_buttonPanel);
    if (changeIcon) {
        _catalog = CatalogPanel.makeDefaultCatalog();
        _catalog.setVisible(false);
        _catalog.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
        this.add(_catalog);
    }
    if (_type != null) /*&& _defaultIcons == null*/
    {
        getDefaultIconNodeFromMap();
    }
    // Allow initial row to be set without getting callback to valueChanged
    if (_table != null) {
        _table.getSelectionModel().addListSelectionListener(this);
    }
    pack();
}
Also used : KeyEvent(java.awt.event.KeyEvent) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator)

Example 75 with KeyAdapter

use of java.awt.event.KeyAdapter in project JMRI by JMRI.

the class AddProfileDialog method initComponents.

/**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
@SuppressWarnings("unchecked")
private // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
void initComponents() {
    lblProfileNameAndLocation = new JLabel();
    jSeparator2 = new JSeparator();
    profileName = new JTextField();
    lblProfileName = new JLabel();
    lblProfileLocation = new JLabel();
    profileLocation = new JTextField();
    profileFolder = new JTextField();
    btnBrowse = new JButton();
    lblProfileFolder = new JLabel();
    jSeparator1 = new JSeparator();
    btnCancel = new JButton();
    btnOk = new JButton();
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    // NOI18N
    ResourceBundle bundle = ResourceBundle.getBundle("jmri/profile/Bundle");
    // NOI18N
    setTitle(bundle.getString("AddProfileDialog.title"));
    setMinimumSize(new Dimension(413, 239));
    lblProfileNameAndLocation.setFont(lblProfileNameAndLocation.getFont().deriveFont(lblProfileNameAndLocation.getFont().getStyle() | Font.BOLD));
    // NOI18N
    lblProfileNameAndLocation.setText(bundle.getString("AddProfileDialog.lblProfileNameAndLocation.text"));
    profileName.setText("");
    profileName.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            profileNameActionPerformed(null);
        }

        public void insertUpdate(DocumentEvent e) {
            profileNameActionPerformed(null);
        }

        public void removeUpdate(DocumentEvent e) {
            profileNameActionPerformed(null);
        }
    });
    profileName.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent evt) {
            profileNameFocusLost(evt);
        }
    });
    profileName.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            profileNameActionPerformed(evt);
        }
    });
    profileName.addKeyListener(new KeyAdapter() {

        public void keyTyped(KeyEvent evt) {
            profileNameKeyTyped(evt);
        }
    });
    // NOI18N
    lblProfileName.setText(bundle.getString("AddProfileDialog.lblProfileName.text"));
    // NOI18N
    lblProfileLocation.setText(bundle.getString("AddProfileDialog.lblProfileLocation.text"));
    profileLocation.setText(ProfileManager.getDefault().getDefaultSearchPath().getPath());
    profileLocation.setMinimumSize(new Dimension(14, 128));
    profileLocation.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent evt) {
            profileLocationFocusLost(evt);
        }
    });
    profileLocation.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            profileLocationActionPerformed(evt);
        }
    });
    profileLocation.addKeyListener(new KeyAdapter() {

        public void keyTyped(KeyEvent evt) {
            profileLocationKeyTyped(evt);
        }
    });
    profileFolder.setEditable(false);
    profileFolder.setText(ProfileManager.getDefault().getDefaultSearchPath().getPath());
    profileFolder.setEnabled(false);
    profileFolder.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            profileFolderActionPerformed(evt);
        }
    });
    // NOI18N
    btnBrowse.setText(bundle.getString("AddProfileDialog.btnBrowse.text"));
    btnBrowse.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            btnBrowseActionPerformed(evt);
        }
    });
    // NOI18N
    lblProfileFolder.setText(bundle.getString("AddProfileDialog.lblProfileFolder.text"));
    // NOI18N
    btnCancel.setText(bundle.getString("AddProfileDialog.btnCancel.text"));
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            btnCancelActionPerformed(evt);
        }
    });
    // NOI18N
    btnOk.setText(bundle.getString("AddProfileDialog.btnOk.text"));
    btnOk.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            btnOkActionPerformed(evt);
        }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jSeparator2).addGroup(layout.createSequentialGroup().addGap(6, 6, 6).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(lblProfileName).addGap(24, 24, 24).addComponent(profileName, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(lblProfileLocation).addComponent(lblProfileFolder)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(profileFolder).addComponent(profileLocation, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(btnBrowse)).addGroup(layout.createSequentialGroup().addComponent(lblProfileNameAndLocation).addGap(0, 0, Short.MAX_VALUE)).addComponent(jSeparator1).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(btnOk).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(btnCancel))).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(lblProfileNameAndLocation).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jSeparator2, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblProfileName)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(btnBrowse).addComponent(lblProfileLocation)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileFolder, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblProfileFolder)).addGap(18, 18, 18).addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(btnCancel).addComponent(btnOk)).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    pack();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) FocusAdapter(java.awt.event.FocusAdapter) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) FocusEvent(java.awt.event.FocusEvent) JSeparator(javax.swing.JSeparator) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) GroupLayout(javax.swing.GroupLayout) ResourceBundle(java.util.ResourceBundle)

Aggregations

KeyAdapter (java.awt.event.KeyAdapter)77 KeyEvent (java.awt.event.KeyEvent)75 MouseEvent (java.awt.event.MouseEvent)29 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 ActionEvent (java.awt.event.ActionEvent)15 JLabel (javax.swing.JLabel)15 ActionListener (java.awt.event.ActionListener)14 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 JButton (javax.swing.JButton)12 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)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9