Search in sources :

Example 51 with KeyAdapter

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

the class WrappedNodeDialog 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 btnApply = createButton(parent, IDialogConstants.FINISH_ID, "Apply", false);
    final Button btnCancel = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
    ((GridLayout) parent.getLayout()).numColumns++;
    final Button btnHelp = new Button(parent, SWT.PUSH | SWT.FLAT);
    Image img = ImageRepository.getIconImage(SharedImages.Help);
    btnHelp.setImage(img);
    boolean writeProtected = m_dialogPane.isWriteProtected();
    btnOK.setEnabled(!writeProtected);
    btnApply.setEnabled(!writeProtected);
    this.swtKeyListener = new KeyListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyReleased(final KeyEvent ke) {
            if (ke.keyCode == SWT.MOD1) {
                btnOK.setText("OK");
            }
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyPressed(final KeyEvent ke) {
            if ((ke.keyCode == SWT.ESC) && m_dialogPane.closeOnESC()) {
                // close dialog on ESC
                doCancel();
            }
            // this locks the WFM so avoid calling it each time.
            Predicate<NodeContainer> canExecutePredicate = n -> n.getParent().canExecuteNode(n.getID());
            if (ke.keyCode == SWT.MOD1 && canExecutePredicate.test(m_nodeContainer)) {
                // change OK button label, when CTRL/COMMAND is pressed
                btnOK.setText("OK - Execute");
            }
            if ((ke.keyCode == SWT.CR) && ((ke.stateMask & SWT.MOD1) != 0)) {
                // Bug 3942: transfer focus to OK button to have all component to auto-commit their changes
                btnOK.forceFocus();
                // force OK - Execute when CTRL/COMMAND and ENTER is pressed
                // open first out-port view if SHIFT is pressed
                ke.doit = doApply();
                if (ke.doit) {
                    runOK(canExecutePredicate.test(m_nodeContainer), (ke.stateMask & SWT.SHIFT) != 0);
                }
                // reset ok button state/label
                if (!ke.doit) {
                    btnOK.setText("OK");
                }
            }
        }
    };
    this.awtKeyListener = new KeyAdapter() {

        @Override
        public void keyReleased(final java.awt.event.KeyEvent ke) {
            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) && m_dialogPane.closeOnESC()) {
                // close dialog on ESC
                getShell().getDisplay().asyncExec(() -> {
                    doCancel();
                });
            }
            // this locks the WFM so avoid calling it each time.
            final Predicate<NodeContainer> canExecutePredicate = n -> n.getParent().canExecuteNode(n.getID());
            int menuAccelerator = (Platform.OS_MACOSX.equals(Platform.getOS())) ? java.awt.event.KeyEvent.VK_META : java.awt.event.KeyEvent.VK_CONTROL;
            if ((ke.getKeyCode() == menuAccelerator) && canExecutePredicate.test(m_nodeContainer)) {
                // change OK button label, when CTRL/COMMAND is pressed
                getShell().getDisplay().asyncExec(() -> {
                    btnOK.setText("OK - Execute");
                });
            }
            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(() -> {
                    // Bug 3942: transfer focus to OK button to have all component to auto-commit their changes
                    btnOK.forceFocus();
                    // open first out-port view if SHIFT is pressed
                    if (doApply()) {
                        runOK(canExecutePredicate.test(m_nodeContainer), ((ke.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0));
                    } else {
                        // reset ok button state/label
                        btnOK.setText("OK");
                    }
                });
            }
        }
    };
    if (!Platform.OS_MACOSX.equals(Platform.getOS())) {
        btnOK.addKeyListener(this.swtKeyListener);
        btnApply.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) {
            if ((se.stateMask & SWT.SHIFT) != 0 && (se.stateMask & SWT.MOD1) != 0) {
                // OK plus execute and open first out-port view
                doOK(se, true, true);
            } else if ((se.stateMask & SWT.MOD1) != 0) {
                // OK plus execute only
                doOK(se, true, false);
            } else {
                // OK only
                doOK(se, false, false);
            }
            if (!se.doit) {
                // reset ok button state/label
                btnOK.setText("OK");
            }
        }
    });
    btnApply.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent se) {
            se.doit = doApply();
            // reset ok button state/label
            btnOK.setText("OK");
        }
    });
    btnCancel.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent se) {
            doCancel();
        }
    });
    btnHelp.addSelectionListener(new SelectionAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void widgetSelected(final SelectionEvent e) {
            doOpenNodeDescription();
        }
    });
}
Also used : KeyAdapter(java.awt.event.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Image(org.eclipse.swt.graphics.Image) Predicate(java.util.function.Predicate) KeyEvent(org.eclipse.swt.events.KeyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener)

Example 52 with KeyAdapter

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

the class ColumnSelectionSearchableListPanel method addKeyMouseSelectionListerersToColumnList.

private void addKeyMouseSelectionListerersToColumnList() {
    m_columnList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyChar()) {
                fireConfigurationRequested(Type.CREATION);
            } else if (KeyEvent.VK_DELETE == e.getKeyChar()) {
                fireConfigurationRequested(Type.DELETION);
            }
        }
    });
    m_columnList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                fireConfigurationRequested(Type.CREATION);
            }
        }
    });
    m_columnList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            fireConfigurationRequested(Type.SELECTION);
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 53 with KeyAdapter

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

the class ParameterizedDBQueryPanel method createColumnsAndVariablesPanel.

private JComponent createColumnsAndVariablesPanel() {
    /* Create database column list */
    final JPanel dbColumnsPanel = new JPanel(new BorderLayout());
    dbColumnsPanel.setPreferredSize(new Dimension(200, 150));
    final JLabel dbColumnsLabel = new JLabel("Database Column List");
    dbColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
    dbColumnsPanel.add(dbColumnsLabel, BorderLayout.NORTH);
    dbColumnsPanel.add(new JScrollPane(m_dbColumnsList), BorderLayout.CENTER);
    m_dbColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
    m_dbColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_dbColumnsList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent evt) {
            if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
                onSelectionInDatabaseList();
            }
        }
    });
    m_dbColumnsList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                onSelectionInDatabaseList();
            }
        }
    });
    /* Create Knime column list */
    final JPanel knimeColumnsPanel = new JPanel(new BorderLayout());
    knimeColumnsPanel.setPreferredSize(new Dimension(200, 150));
    final JLabel knimeColumnsLabel = new JLabel("Column List");
    knimeColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
    knimeColumnsPanel.add(knimeColumnsLabel, BorderLayout.NORTH);
    knimeColumnsPanel.add(new JScrollPane(m_knimeColumnsList), BorderLayout.CENTER);
    m_knimeColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
    m_knimeColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_knimeColumnsList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent evt) {
            if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
                onSelectionInColumnList();
            }
        }
    });
    m_knimeColumnsList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                onSelectionInColumnList();
            }
        }
    });
    final JSplitPane columnsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    columnsSplitPane.setResizeWeight(0.5);
    columnsSplitPane.setOneTouchExpandable(true);
    columnsSplitPane.setDividerSize(8);
    columnsSplitPane.setTopComponent(dbColumnsPanel);
    columnsSplitPane.setBottomComponent(knimeColumnsPanel);
    columnsSplitPane.setDividerLocation(150);
    /* Create flow variables list*/
    final JPanel variablesPanel = new JPanel(new BorderLayout());
    variablesPanel.setPreferredSize(new Dimension(200, 150));
    final JLabel variablesLabel = new JLabel("Flow Variable List");
    variablesLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
    variablesPanel.add(variablesLabel, BorderLayout.NORTH);
    variablesPanel.add(new JScrollPane(m_flowVariablesList), BorderLayout.CENTER);
    m_flowVariablesList.setCellRenderer(new FlowVariableListCellRenderer());
    m_flowVariablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_flowVariablesList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent evt) {
            if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
                onSelectionInFlowVariableList();
            }
        }
    });
    m_flowVariablesList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                onSelectionInFlowVariableList();
            }
        }
    });
    final JSplitPane columnsVariableSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    columnsVariableSplitPane.setResizeWeight(0.5);
    columnsVariableSplitPane.setOneTouchExpandable(true);
    columnsVariableSplitPane.setDividerSize(8);
    columnsVariableSplitPane.setTopComponent(columnsSplitPane);
    columnsVariableSplitPane.setBottomComponent(variablesPanel);
    columnsVariableSplitPane.setDividerLocation(300);
    return columnsVariableSplitPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) KeyEvent(java.awt.event.KeyEvent) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) BorderLayout(java.awt.BorderLayout) EmptyBorder(javax.swing.border.EmptyBorder) JSplitPane(javax.swing.JSplitPane)

Example 54 with KeyAdapter

use of java.awt.event.KeyAdapter in project eclipse.platform.swt by eclipse.

the class Bug164015_G2DDrawImage method main.

public static void main(String[] args) {
    /**
     * create SWT GUI
     */
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("AWT_SWT Test");
    Composite swtAwtComponent = new Composite(shell, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(swtAwtComponent);
    final Bug164015_G2DDrawImage myJPanel = new Bug164015_G2DDrawImage();
    frame.add(myJPanel);
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                myJPanel.scroll(20, 0);
            }
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                myJPanel.scroll(-20, 0);
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                myJPanel.scroll(0, 20);
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                myJPanel.scroll(0, -20);
            }
        }
    });
    shell.setLayout(new FillLayout());
    shell.pack();
    shell.open();
    shell.setMaximized(true);
    try {
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    } finally {
        display.dispose();
        System.err.println("EXITING NORMALLY!!");
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(java.awt.event.KeyAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display)

Example 55 with KeyAdapter

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

the class TeamsPanel method initialize.

private void initialize() {
    JButton refreshTeams = new JButton(Translation.get("gb.refresh"));
    refreshTeams.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshTeams();
        }
    });
    JButton createTeam = new JButton(Translation.get("gb.create"));
    createTeam.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createTeam();
        }
    });
    final JButton editTeam = new JButton(Translation.get("gb.edit"));
    editTeam.setEnabled(false);
    editTeam.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editTeam(getSelectedTeams().get(0));
        }
    });
    final JButton delTeam = new JButton(Translation.get("gb.delete"));
    delTeam.setEnabled(false);
    delTeam.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteTeams(getSelectedTeams());
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new TeamsTableModel();
    defaultSorter = new TableRowSorter<TeamsTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    String name = table.getColumnName(TeamsTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    int w = 125;
    name = table.getColumnName(TeamsTableModel.Columns.Members.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    name = table.getColumnName(TeamsTableModel.Columns.Repositories.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(TeamsTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean selected = table.getSelectedRow() > -1;
            boolean singleSelection = table.getSelectedRows().length == 1;
            editTeam.setEnabled(singleSelection && selected);
            delTeam.setEnabled(selected);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                editTeam(getSelectedTeams().get(0));
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterTeams(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterTeams(filterTextfield.getText());
        }
    });
    JPanel teamFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    teamFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    teamFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel teamTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    teamTablePanel.add(teamFilterPanel, BorderLayout.NORTH);
    teamTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    JPanel teamControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    teamControls.add(refreshTeams);
    teamControls.add(createTeam);
    teamControls.add(editTeam);
    teamControls.add(delTeam);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.teams"), "users_16x16.png");
    add(header, BorderLayout.NORTH);
    add(teamTablePanel, BorderLayout.CENTER);
    add(teamControls, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

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