Example usage for javax.swing ActionMap remove

List of usage examples for javax.swing ActionMap remove

Introduction

In this page you can find the example usage for javax.swing ActionMap remove.

Prototype

public void remove(Object key) 

Source Link

Document

Removes the binding for key from this ActionMap.

Usage

From source file:Main.java

public static void main(String args[]) {
    String ACTION_KEY = "The Action";

    JFrame frame = new JFrame("KeyStroke Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton buttonA = new JButton("FOCUSED (control alt 7)");
    JButton buttonB = new JButton("FOCUS/RELEASE (VK_ENTER)");
    JButton buttonC = new JButton("ANCESTOR  (VK_F4+SHIFT_MASK)");
    JButton buttonD = new JButton("WINDOW (' ')");

    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            JButton source = (JButton) actionEvent.getSource();
            System.out.println("Activated: " + source.getText());
        }// w  w  w .ja va 2s.  c  o m
    };

    KeyStroke controlAlt7 = KeyStroke.getKeyStroke("control alt 7");
    InputMap inputMap = buttonA.getInputMap();
    inputMap.put(controlAlt7, ACTION_KEY);
    ActionMap actionMap = buttonA.getActionMap();
    Object[] keys = actionMap.keys();
    for (Object key : keys) {
        actionMap.remove(key);
    }
    actionMap.put(ACTION_KEY, actionListener);

    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
    inputMap = buttonB.getInputMap();
    inputMap.put(enter, ACTION_KEY);
    buttonB.setActionMap(actionMap);

    KeyStroke shiftF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_MASK);
    inputMap = buttonC.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(shiftF4, ACTION_KEY);
    buttonC.setActionMap(actionMap);

    KeyStroke space = KeyStroke.getKeyStroke(' ');
    inputMap = buttonD.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(space, ACTION_KEY);
    buttonD.setActionMap(actionMap);

    frame.setLayout(new GridLayout(2, 2));
    frame.add(buttonA);
    frame.add(buttonB);
    frame.add(buttonC);
    frame.add(buttonD);

    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopFrameActionsHolder.java

public void removeAction(Action action) {
    if (actionList.remove(action)) {
        if (action.getShortcutCombination() != null) {
            InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
            ActionMap actionMap = panel.getActionMap();
            KeyStroke keyStroke = shortcutActions.get(action);
            if (keyStroke != null) {
                inputMap.remove(keyStroke);
                actionMap.remove(action.getId());
            }//  w  ww  .ja  va2 s  .c  o m
        }
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java

@Override
public void removeAction(@Nullable Action action) {
    if (action != null) {
        if (actionsOrder.remove(action)) {
            if (action.getOwner() != null && action.getOwner() instanceof DesktopButton) {
                JButton button = ((DesktopButton) action.getOwner()).getImpl();
                impl.removeButton(button);
            }/*from ww w.ja v a2  s .c  o m*/

            InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED);
            ActionMap actionMap = getImpl().getInputField().getActionMap();
            List<KeyStroke> keyStrokes = keyStrokesMap.get(action);
            if (keyStrokes != null) {
                for (KeyStroke keyStroke : keyStrokes) {
                    inputMap.remove(keyStroke);
                }
                actionMap.remove(action.getId());
            }

            updateOrderedShortcuts();
        }
    }
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public JPanel createDetailsView() {
    final VFSJFileChooser chooser = getFileChooser();

    JPanel p = new JPanel(new BorderLayout());

    final JTable detailsTable = new JTable(getDetailsTableModel()) {
        // Handle Escape key events here
        @Override//w  w  w . jav  a2 s  . co m
        protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
            if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) {
                // We are not editing, forward to filechooser.
                chooser.dispatchEvent(e);

                return true;
            }

            return super.processKeyBinding(ks, e, condition, pressed);
        }

        @Override
        public void tableChanged(TableModelEvent e) {
            super.tableChanged(e);

            if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                // update header with possibly changed column set
                updateDetailsColumnModel(this);
            }
        }
    };

    //        detailsTable.setRowSorter(getRowSorter());
    detailsTable.setAutoCreateColumnsFromModel(false);
    detailsTable.setComponentOrientation(chooser.getComponentOrientation());
    //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    detailsTable.setShowGrid(false);
    detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

    //        detailsTable.addKeyListener(detailsKeyListener);
    Font font = list.getFont();
    detailsTable.setFont(font);
    detailsTable.setIntercellSpacing(new Dimension(0, 0));

    TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer(
            detailsTable.getTableHeader().getDefaultRenderer());
    detailsTable.getTableHeader().setDefaultRenderer(headerRenderer);

    TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser);
    detailsTable.setDefaultRenderer(Object.class, cellRenderer);

    // So that drag can be started on a mouse press
    detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    detailsTable.addMouseListener(getMouseHandler());
    // No need to addListSelectionListener because selections are forwarded
    // to our JList.

    // 4835633 : tell BasicTableUI that this is a file list
    detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE);

    if (listViewWindowsStyle) {
        detailsTable.addFocusListener(repaintListener);
    }

    JTableHeader header = detailsTable.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(detailsTableModel.new ColumnListener());
    header.setReorderingAllowed(true);

    // TAB/SHIFT-TAB should transfer focus and ENTER should select an item.
    // We don't want them to navigate within the table
    ActionMap am = SwingUtilities.getUIActionMap(detailsTable);
    am.remove("selectNextRowCell");
    am.remove("selectPreviousRowCell");
    am.remove("selectNextColumnCell");
    am.remove("selectPreviousColumnCell");
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);

    JScrollPane scrollpane = new JScrollPane(detailsTable);
    scrollpane.setComponentOrientation(chooser.getComponentOrientation());
    LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground");

    // Adjust width of first column so the table fills the viewport when
    // first displayed (temporary listener).
    scrollpane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JScrollPane sp = (JScrollPane) e.getComponent();
            fixNameColumnWidth(sp.getViewport().getSize().width);
            sp.removeComponentListener(this);
        }
    });

    // 4835633.
    // If the mouse is pressed in the area below the Details view table, the
    // event is not dispatched to the Table MouseListener but to the
    // scrollpane.  Listen for that here so we can clear the selection.
    scrollpane.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            JScrollPane jsp = ((JScrollPane) e.getComponent());
            JTable table = (JTable) jsp.getViewport().getView();

            if (!e.isShiftDown()
                    || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) {
                clearSelection();

                TableCellEditor tce = table.getCellEditor();

                if (tce != null) {
                    tce.stopCellEditing();
                }
            }
        }
    });

    detailsTable.setForeground(list.getForeground());
    detailsTable.setBackground(list.getBackground());

    if (listViewBorder != null) {
        scrollpane.setBorder(listViewBorder);
    }

    p.add(scrollpane, BorderLayout.CENTER);

    detailsTableModel.fireTableStructureChanged();

    return p;
}

From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

private void resetEditorActions() {

    JTextComponent textComponent = queryEditorTextComponent();

    ActionMap actionMap = textComponent.getActionMap();
    actionMap.remove(LIST_FOCUS_ACTION_KEY);
    actionMap.remove(LIST_SELECTION_ACTION_KEY);
    actionMap.remove(LIST_SCROLL_ACTION_KEY_DOWN);
    actionMap.remove(LIST_SCROLL_ACTION_KEY_UP);

    InputMap inputMap = textComponent.getInputMap();
    inputMap.remove(KEY_STROKE_DOWN);/*  w ww . j  av a 2 s.co  m*/
    inputMap.remove(KEY_STROKE_UP);
    inputMap.remove(KEY_STROKE_PAGE_DOWN);
    inputMap.remove(KEY_STROKE_PAGE_UP);
    inputMap.remove(KEY_STROKE_ENTER);
    inputMap.remove(KEY_STROKE_TAB);

    inputMap.put(KEY_STROKE_DOWN, existingKeyStrokeDownAction);
    inputMap.put(KEY_STROKE_UP, existingKeyStrokeUpAction);
    inputMap.put(KEY_STROKE_PAGE_DOWN, existingKeyStrokePageDownAction);
    inputMap.put(KEY_STROKE_PAGE_UP, existingKeyStrokePageUpAction);
    inputMap.put(KEY_STROKE_TAB, existingKeyStrokeTabAction);
    inputMap.put(KEY_STROKE_ENTER, existingKeyStrokeEnterAction);

    textComponent.removeCaretListener(this);
}