Search in sources :

Example 46 with KeyAdapter

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

the class ChooseBuildConfigurationDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    List<Module> modules = new ArrayList<>(myTreeItems.keySet());
    Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    for (Module module : modules) {
        DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
        root.add(moduleNode);
        List<FlexBCConfigurable> bcs = myTreeItems.get(module);
        Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
        for (FlexBCConfigurable bc : bcs) {
            DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
            moduleNode.add(bcNode);
        }
    }
    myTree.setModel(new DefaultTreeModel(root));
    myTree.setRootVisible(false);
    new TreeSpeedSearch(myTree, o -> {
        Object lastPathComponent = o.getLastPathComponent();
        return getText((DefaultMutableTreeNode) lastPathComponent);
    }, true).setComparator(new SpeedSearchComparator(false));
    TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateOnSelectionChange();
        }
    });
    myTree.setCellRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
            Object object = treeNode.getUserObject();
            if (object instanceof Module) {
                Module module = (Module) object;
                setIcon(ModuleType.get(module).getIcon());
                append(module.getName());
            } else if (object instanceof FlexBCConfigurable) {
                FlexBCConfigurable configurable = (FlexBCConfigurable) object;
                setIcon(configurable.getIcon());
                BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
            }
        }
    });
    TreeUtil.expandAll(myTree);
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (mySelection != null) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                doOKAction();
            }
        }
    });
    updateOnSelectionChange();
    return myContentPane;
}
Also used : FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) HashMap(com.intellij.util.containers.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) ModuleStructureConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) KeyEvent(java.awt.event.KeyEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module)

Example 47 with KeyAdapter

use of java.awt.event.KeyAdapter in project processdash by dtuma.

the class PreferencesTextField method addUpdateFromTextListeners.

@Override
protected void addUpdateFromTextListeners() {
    addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "updateFromText"));
    addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            updateFromText();
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter)

Example 48 with KeyAdapter

use of java.awt.event.KeyAdapter in project aerospike-client-java by aerospike.

the class GuiDisplay method initialize.

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmAerospikeExamples = new JFrame();
    frmAerospikeExamples.setTitle("Aerospike Java Client Examples");
    frmAerospikeExamples.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmAerospikeExamples.pack();
    frmAerospikeExamples.getContentPane().setLayout(new BorderLayout(0, 0));
    splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    frmAerospikeExamples.getContentPane().add(splitPane, BorderLayout.CENTER);
    mainPanel = new JPanel();
    splitPane.setLeftComponent(mainPanel);
    mainPanel.setLayout(new BorderLayout(0, 0));
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    runButton = new JButton("Run");
    runButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent ev) {
            consoleTextArea.setText("");
            run_selected_examples();
        }
    });
    buttonPanel.add(runButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    exitButton = new JButton("Quit");
    exitButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            Container Frame = exitButton.getParent();
            do {
                Frame = Frame.getParent();
            } while (!(Frame instanceof JFrame));
            ((JFrame) Frame).dispose();
        }
    });
    buttonPanel.add(exitButton);
    sourceTextPane = new JTextArea();
    sourceTextPane.setTabSize(2);
    sourceTextPane.setEditable(false);
    scrollPane = new JScrollPane(sourceTextPane);
    scrollPane.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    scrollPane.setPreferredSize(new Dimension(600, 100));
    mainPanel.add(scrollPane, BorderLayout.CENTER);
    connectionPanel = new JPanel();
    connectionPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    lblServerHost = new JLabel("Server Host");
    connectionPanel.add(lblServerHost);
    seedHostTextField = new JTextField();
    seedHostTextField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            params.host = seedHostTextField.getText();
        }
    });
    connectionPanel.add(seedHostTextField);
    seedHostTextField.setColumns(10);
    lblPort = new JLabel("Port");
    connectionPanel.add(lblPort);
    portTextField = new JTextField();
    portTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent arg0) {
            String newValue = namespaceTextField.getText();
            if (newValue != null && newValue != "") {
                try {
                    params.port = Integer.parseInt(newValue);
                } catch (NumberFormatException ne) {
                // ne.printStackTrace();
                }
            }
        }
    });
    connectionPanel.add(portTextField);
    portTextField.setColumns(4);
    lblusername = new JLabel("User");
    connectionPanel.add(lblusername);
    usernameTextField = new JTextField();
    usernameTextField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            params.user = usernameTextField.getText();
        }
    });
    connectionPanel.add(usernameTextField);
    usernameTextField.setColumns(8);
    lblpassword = new JLabel("Password");
    connectionPanel.add(lblpassword);
    passwordTextField = new JPasswordField();
    passwordTextField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            params.user = new String(passwordTextField.getPassword());
        }
    });
    connectionPanel.add(passwordTextField);
    passwordTextField.setColumns(8);
    lblnameSpace = new JLabel("Namespace");
    connectionPanel.add(lblnameSpace);
    namespaceTextField = new JTextField();
    namespaceTextField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            params.namespace = namespaceTextField.getText();
        }
    });
    connectionPanel.add(namespaceTextField);
    namespaceTextField.setColumns(8);
    lblSet = new JLabel("Set");
    connectionPanel.add(lblSet);
    txtSetTextfield = new JTextField();
    txtSetTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            params.set = txtSetTextfield.getText();
        }
    });
    connectionPanel.add(txtSetTextfield);
    txtSetTextfield.setColumns(8);
    mainPanel.add(connectionPanel, BorderLayout.NORTH);
    examplePanel = new JPanel();
    examplePanel.setLayout(new BoxLayout(examplePanel, BoxLayout.Y_AXIS));
    exampleScrollPane = new JScrollPane(examplePanel);
    mainPanel.add(exampleScrollPane, BorderLayout.WEST);
    // init values
    seedHostTextField.setText(params.host);
    portTextField.setText(Integer.toString(params.port));
    namespaceTextField.setText(params.namespace);
    txtSetTextfield.setText(params.set);
    // int width = 785;
    int width = 1000;
    int height = 180;
    consoleTextArea = new JTextArea();
    consoleTextArea.setSize(new Dimension(width, height));
    consoleTextArea.setEditable(false);
    consoleScrollPane = new JScrollPane(consoleTextArea);
    consoleScrollPane.setPreferredSize(new Dimension(width, height));
    consoleScrollPane.setSize(new Dimension(width, height));
    splitPane.setRightComponent(consoleScrollPane);
    buttonGroup = new ButtonGroup();
    JRadioButton jrb;
    for (String example : Main.getAllExampleNames()) {
        jrb = new JRadioButton(example);
        jrb.setActionCommand(example);
        jrb.addActionListener(this);
        buttonGroup.add(jrb);
        examplePanel.add(jrb);
    }
    frmAerospikeExamples.pack();
}
Also used : JPanel(javax.swing.JPanel) FocusAdapter(java.awt.event.FocusAdapter) FlowLayout(java.awt.FlowLayout) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) KeyAdapter(java.awt.event.KeyAdapter) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) EtchedBorder(javax.swing.border.EtchedBorder) JPasswordField(javax.swing.JPasswordField) ButtonGroup(javax.swing.ButtonGroup) JSplitPane(javax.swing.JSplitPane)

Example 49 with KeyAdapter

use of java.awt.event.KeyAdapter in project knime-core by knime.

the class JSnippetPanel method initComponents.

private void initComponents() {
    m_colList = new JList(new DefaultListModel());
    m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_colList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.setCellRenderer(new ListRenderer());
    m_flowVarsList = new JList(new DefaultListModel());
    m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // enable tooltip
    m_flowVarsList.setToolTipText("");
    m_flowVarsList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
    m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
    m_categories.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            String category = (String) cb.getSelectedItem();
            updateManipulatorList(category);
        }
    });
    m_manipulators = new JList(new DefaultListModel());
    m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
    m_manipulators.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            Object selected = m_manipulators.getSelectedValue();
            if (selected != null) {
                Manipulator manipulator = (Manipulator) selected;
                m_description.setText(manipulator.getDescription());
                m_description.setCaretPosition(0);
            } else {
                m_description.setText("");
            }
        }
    });
    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet css = new StyleSheet();
    css.addRule("* { font-family: sans-serif; }");
    kit.setStyleSheet(css);
    m_description = new JTextPane();
    m_description.setEditorKit(kit);
    m_description.setEditable(false);
    m_description.setBackground(getBackground());
    updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
    initSubComponents();
}
Also used : MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) ListSelectionListener(javax.swing.event.ListSelectionListener) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator) KeyEvent(java.awt.event.KeyEvent) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) JTextPane(javax.swing.JTextPane) StyleSheet(javax.swing.text.html.StyleSheet) ActionListener(java.awt.event.ActionListener) JList(javax.swing.JList)

Example 50 with KeyAdapter

use of java.awt.event.KeyAdapter in project knime-core by knime.

the class WrappedMultipleNodeDialog method createButtonsForButtonBar.

/**
 * {@inheritDoc}
 */
@Override
protected void createButtonsForButtonBar(final Composite parent) {
    // WORKAROUND: can't use IDialogConstants.OK_ID here, as this always
    // closes the dialog, regardless if the settings couldn't be applied.
    final Button btnOK = createButton(parent, IDialogConstants.NEXT_ID, IDialogConstants.OK_LABEL, false);
    final Button btnCancel = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
    ((GridLayout) parent.getLayout()).numColumns++;
    this.swtKeyListener = new KeyListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyReleased(final KeyEvent ke) {
            // TODO there's no point to this presently since we don't ever change the text
            if (ke.keyCode == SWT.MOD1) {
                btnOK.setText("OK");
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyPressed(final KeyEvent ke) {
            if (ke.keyCode == SWT.ESC) {
                // close dialog on ESC
                doCancel();
            }
            // TODO this does not mimic the same behavior as found in WrappedNodeDialog to change the OK button text
            if ((ke.keyCode == SWT.CR) && ((ke.stateMask == SWT.MOD1) || (ke.stateMask == SWT.SHIFT + SWT.MOD1))) {
                // force OK - Execute when CTRL/Command and ENTER is pressed
                // open first out-port view if SHIFT is pressed
                doOK(ke);
            }
        }
    };
    this.awtKeyListener = new KeyAdapter() {

        @Override
        public void keyReleased(final java.awt.event.KeyEvent ke) {
            // TODO there's no point to this presently since we don't ever change the text
            int menuAccelerator = (Platform.OS_MACOSX.equals(Platform.getOS())) ? java.awt.event.KeyEvent.VK_META : java.awt.event.KeyEvent.VK_CONTROL;
            if (ke.getKeyCode() == menuAccelerator) {
                getShell().getDisplay().asyncExec(() -> {
                    btnOK.setText("OK");
                });
            }
        }

        @Override
        public void keyPressed(final java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                // close dialog on ESC
                getShell().getDisplay().asyncExec(() -> {
                    doCancel();
                });
            }
            // TODO this does not mimic the same behavior as found in WrappedNodeDialog to change the OK button text
            int modifierKey = (Platform.OS_MACOSX.equals(Platform.getOS())) ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
            if ((ke.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) && ((ke.getModifiersEx() & modifierKey) != 0)) {
                getShell().getDisplay().asyncExec(() -> {
                    // force OK - Execute when CTRL/Command and ENTER is pressed
                    if (doApply()) {
                        runOK();
                    }
                });
            }
        }
    };
    if (!Platform.OS_MACOSX.equals(Platform.getOS())) {
        btnOK.addKeyListener(this.swtKeyListener);
        btnCancel.addKeyListener(this.swtKeyListener);
        m_wrapper.addKeyListener(this.swtKeyListener);
    }
    // Register listeners that notify the content object, which
    // in turn notify the dialog about the particular event.
    btnOK.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent se) {
            // OK only
            doOK(se);
        }
    });
    btnCancel.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent se) {
            doCancel();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Button(org.eclipse.swt.widgets.Button) KeyAdapter(java.awt.event.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener)

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