Search in sources :

Example 96 with KeyStroke

use of javax.swing.KeyStroke in project GDSC-SMLM by aherbert.

the class TableColumnAdjuster method installColumnAction.

/*
   * Update the input and action maps with a new ColumnAction
   */
private void installColumnAction(boolean isSelectedColumn, boolean isAdjust, String key, String keyStroke) {
    final Action action = new ColumnAction(isSelectedColumn, isAdjust);
    final KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
    table.getInputMap().put(ks, key);
    table.getActionMap().put(key, action);
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) KeyStroke(javax.swing.KeyStroke)

Example 97 with KeyStroke

use of javax.swing.KeyStroke in project cayenne by apache.

the class CayenneDialog method initCloseOnEscape.

/**
 * Makes dialog closeable when ESC button is clicked.
 */
protected void initCloseOnEscape() {
    // make dialog closable on escape
    // TODO: Note that if a dialog contains subcomponents
    // that use ESC for their own purposes (like editable JTable or JComboBox),
    // this code will still close the dialog  (e.g. not just an expanded
    // ComboBox). To fix it see this advise (Swing is Fun!!):
    // 
    // http://www.eos.dk/pipermail/swing/2001-June/000789.html
    KeyStroke escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    ActionListener closeAction = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (CayenneDialog.this.isVisible()) {
                // dispatch window closing event
                WindowEvent windowClosing = new WindowEvent(CayenneDialog.this, WindowEvent.WINDOW_CLOSING);
                CayenneDialog.super.processWindowEvent(windowClosing);
            }
        }
    };
    getRootPane().registerKeyboardAction(closeAction, escReleased, JComponent.WHEN_IN_FOCUSED_WINDOW);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke)

Example 98 with KeyStroke

use of javax.swing.KeyStroke in project sulky by huxi.

the class KeyStrokes method appendInputMap.

private static void appendInputMap(StringBuilder buffer, String mapName, InputMap inputMap) {
    buffer.append("\tmapName: ").append(mapName).append('\n');
    KeyStroke[] keys = inputMap.allKeys();
    if (keys != null) {
        for (KeyStroke ks : keys) {
            buffer.append("\t\tKey  : ").append(ks).append("\n\t\tValue: ").append(inputMap.get(ks)).append("\n\t\t----------\n");
        }
    }
}
Also used : KeyStroke(javax.swing.KeyStroke) AWTKeyStroke(java.awt.AWTKeyStroke)

Example 99 with KeyStroke

use of javax.swing.KeyStroke in project knime-core by knime.

the class TableView method registerFindAction.

/**
 * Creates and registers the "Find ..." action on this component. Multiple invocation of this method have no effect
 * (lazy initialization).
 *
 * @return The non-null action representing the find task.
 * @see #registerNavigationActions()
 */
public TableAction registerFindAction() {
    if (m_findAction == null) {
        String name = "Find...";
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
        TableAction action = new TableAction(stroke, name) {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (!hasData()) {
                    return;
                }
                if (m_searchPosition == null) {
                    initNewSearchPostion(new SearchOptions(true, true, true));
                }
                m_searchPosition.reset();
                SearchOptions searchOptions = m_searchPosition.getSearchOptions();
                boolean isSearchRowID = searchOptions.isSearchRowID();
                boolean isSearchColumnName = searchOptions.isSearchColumnName();
                boolean isSearchData = searchOptions.isSearchData();
                JCheckBox rowKeyBox = new JCheckBox("Search RowID Column", isSearchRowID);
                JCheckBox colNameBox = new JCheckBox("Search Column Names", isSearchColumnName);
                JCheckBox dataBox = new JCheckBox("Search Data", isSearchData);
                JCheckBox[] asArray = new JCheckBox[] { rowKeyBox, colNameBox, dataBox };
                rowKeyBox.addItemListener(new AtLeastOnButtonSelectedItemListener(dataBox, asArray));
                colNameBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
                dataBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
                JCheckBox caseSensitiveBox = new JCheckBox("Case sensitive", m_searchString.map(i -> !i.isIgnoreCase()).orElse(false));
                JCheckBox regexBox = new JCheckBox("Regular Expression", m_searchString.map(i -> i.isRegex()).orElse(false));
                JPanel panel = new JPanel(new BorderLayout());
                panel.add(new JLabel("Options: "), BorderLayout.NORTH);
                JPanel centerPanel = new JPanel(new GridLayout(0, 1));
                centerPanel.add(rowKeyBox);
                centerPanel.add(colNameBox);
                centerPanel.add(dataBox);
                centerPanel.add(new JLabel());
                centerPanel.add(caseSensitiveBox);
                centerPanel.add(regexBox);
                centerPanel.add(new JLabel());
                panel.add(centerPanel, BorderLayout.CENTER);
                panel.add(new JLabel("    "), BorderLayout.WEST);
                panel.add(new JLabel("Find String: "), BorderLayout.SOUTH);
                SearchString newSearchString;
                while (true) {
                    String in = (String) JOptionPane.showInputDialog(TableView.this, panel, "Search", JOptionPane.QUESTION_MESSAGE, null, null, m_searchString.map(s -> s.getSearchString()).orElse(""));
                    if (StringUtils.isEmpty(in)) {
                        // canceled
                        return;
                    }
                    try {
                        newSearchString = new SearchString(in, !caseSensitiveBox.isSelected(), regexBox.isSelected());
                        break;
                    } catch (PatternSyntaxException pse) {
                        JOptionPane.showMessageDialog(TableView.this, pse.getMessage(), "Invalid regular expression", JOptionPane.ERROR_MESSAGE);
                    }
                }
                searchOptions = new SearchOptions(rowKeyBox.isSelected(), colNameBox.isSelected(), dataBox.isSelected());
                find(newSearchString, searchOptions);
            }
        };
        registerAction(action);
        m_findAction = action;
    }
    return m_findAction;
}
Also used : RowKey(org.knime.core.data.RowKey) Enumeration(java.util.Enumeration) Cursor(java.awt.Cursor) Point(java.awt.Point) ItemListener(java.awt.event.ItemListener) SearchOptions(org.knime.core.node.tableview.FindPosition.SearchOptions) TableCellRenderer(javax.swing.table.TableCellRenderer) StringUtils(org.apache.commons.lang3.StringUtils) GraphicsEnvironment(java.awt.GraphicsEnvironment) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) MouseAdapter(java.awt.event.MouseAdapter) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) Clipboard(java.awt.datatransfer.Clipboard) KeyStroke(javax.swing.KeyStroke) ScrollPaneConstants(javax.swing.ScrollPaneConstants) ChangeEvent(javax.swing.event.ChangeEvent) ItemEvent(java.awt.event.ItemEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) Font(java.awt.Font) Collection(java.util.Collection) JMenu(javax.swing.JMenu) MouseInputAdapter(javax.swing.event.MouseInputAdapter) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) Objects(java.util.Objects) Dimension(java.awt.Dimension) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractAction(javax.swing.AbstractAction) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) CheckUtils(org.knime.core.node.util.CheckUtils) JPanel(javax.swing.JPanel) TableContentFilter(org.knime.core.node.tableview.TableContentModel.TableContentFilter) Toolkit(java.awt.Toolkit) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Rectangle(java.awt.Rectangle) ActionListener(java.awt.event.ActionListener) TableColumnModel(javax.swing.table.TableColumnModel) GraphicsDevice(java.awt.GraphicsDevice) Transferable(java.awt.datatransfer.Transferable) MethodUtils(org.apache.commons.lang3.reflect.MethodUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Action(javax.swing.Action) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) TransferHandler(javax.swing.TransferHandler) NodeLogger(org.knime.core.node.NodeLogger) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) AbstractButton(javax.swing.AbstractButton) BasicTableUI(javax.swing.plaf.basic.BasicTableUI) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) DataTable(org.knime.core.data.DataTable) Field(java.lang.reflect.Field) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JViewport(javax.swing.JViewport) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) SearchOptions(org.knime.core.node.tableview.FindPosition.SearchOptions) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) KeyStroke(javax.swing.KeyStroke) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 100 with KeyStroke

use of javax.swing.KeyStroke in project knime-core by knime.

the class TableView method registerCopyWithColHeaderAction.

// createViewMenu()
/**
 * Creates and registers the "Copy With Column Header" action on this component.
 *
 * @return The non-null action representing the copy task.
 * @since 4.2
 */
public TableAction registerCopyWithColHeaderAction() {
    if (m_copyWithColHeaderAction == null) {
        String name = "Copy with Column Header";
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | InputEvent.SHIFT_DOWN_MASK);
        TableAction action = new TableAction(stroke, name) {

            @Override
            public void actionPerformed(final ActionEvent e) {
                copySelectionToClipboard(false, true);
            }
        };
        registerAction(action);
        m_copyWithColHeaderAction = action;
    }
    return m_copyWithColHeaderAction;
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke)

Aggregations

KeyStroke (javax.swing.KeyStroke)194 ActionEvent (java.awt.event.ActionEvent)77 AbstractAction (javax.swing.AbstractAction)56 InputMap (javax.swing.InputMap)46 Action (javax.swing.Action)44 JRootPane (javax.swing.JRootPane)36 ActionListener (java.awt.event.ActionListener)27 JPanel (javax.swing.JPanel)20 ActionMap (javax.swing.ActionMap)17 JComponent (javax.swing.JComponent)16 KeyEvent (java.awt.event.KeyEvent)15 JMenuItem (javax.swing.JMenuItem)14 JScrollPane (javax.swing.JScrollPane)14 Point (java.awt.Point)13 JFrame (javax.swing.JFrame)12 JPopupMenu (javax.swing.JPopupMenu)12 WindowEvent (java.awt.event.WindowEvent)10 Dimension (java.awt.Dimension)9 MouseAdapter (java.awt.event.MouseAdapter)9 MouseEvent (java.awt.event.MouseEvent)9