Search in sources :

Example 31 with ActionMap

use of javax.swing.ActionMap in project adempiere by adempiere.

the class AdempiereLabelUI method installKeyboardActions.

//	createUI
/**
	 * 	Install Keyboard Actions
	 *	@param l label
	 */
protected void installKeyboardActions(JLabel l) {
    //	super.installKeyboardActions(l);
    int dka = l.getDisplayedMnemonic();
    if (dka != 0) {
        Component lf = l.getLabelFor();
        if (lf != null) {
            ActionMap actionMap = l.getActionMap();
            actionMap.put(PRESS, ACTION_PRESS);
            InputMap inputMap = SwingUtilities.getUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW);
            if (inputMap == null) {
                inputMap = new ComponentInputMapUIResource(l);
                SwingUtilities.replaceUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
            }
            inputMap.clear();
            inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK, false), PRESS);
        }
    }
}
Also used : ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 32 with ActionMap

use of javax.swing.ActionMap in project adempiere by adempiere.

the class VTreePanel method setMappings.

private void setMappings(JTree tree) {
    ActionMap map = tree.getActionMap();
    map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
    map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
}
Also used : ActionMap(javax.swing.ActionMap)

Example 33 with ActionMap

use of javax.swing.ActionMap in project adempiere by adempiere.

the class ADempiereAutoCompleteDecorator method decorate.

/**
     * Decorates a given text component for automatic completion using the
     * given AutoCompleteDocument and AbstractAutoCompleteAdaptor.
     * 
     * 
     * @param textComponent a text component that should be decorated
     * @param document the AutoCompleteDocument to be installed on the text component
     * @param adaptor the AbstractAutoCompleteAdaptor to be used
     */
public static void decorate(JTextComponent textComponent, AutoCompleteDocument document, final AbstractAutoCompleteAdaptor adaptor) {
    // install the document on the text component
    textComponent.setDocument(document);
    // mark entire text when the text component gains focus
    // otherwise the last mark would have been retained which is quiet confusing
    textComponent.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            JTextComponent textComponent = (JTextComponent) e.getSource();
            adaptor.markEntireText();
        }
    });
    // Tweak some key bindings
    InputMap editorInputMap = textComponent.getInputMap();
    if (document.isStrictMatching()) {
        // move the selection to the left on VK_BACK_SPACE
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), DefaultEditorKit.selectionBackwardAction);
        // ignore VK_DELETE and CTRL+VK_X and beep instead when strict matching
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0), errorFeedbackAction);
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), errorFeedbackAction);
    } else {
        ActionMap editorActionMap = textComponent.getActionMap();
        // leave VK_DELETE and CTRL+VK_X as is
        // VK_BACKSPACE will move the selection to the left if the selected item is in the list
        // it will delete the previous character otherwise
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), "nonstrict-backspace");
        editorActionMap.put("nonstrict-backspace", new NonStrictBackspaceAction(editorActionMap.get(DefaultEditorKit.deletePrevCharAction), editorActionMap.get(DefaultEditorKit.selectionBackwardAction), adaptor));
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.event.KeyEvent.CTRL_DOWN_MASK), "NextMatchAction");
        editorActionMap.put("NextMatchAction", new NextMatchAction(textComponent, document, adaptor));
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ActionMap(javax.swing.ActionMap) JTextComponent(javax.swing.text.JTextComponent) InputMap(javax.swing.InputMap) FocusEvent(java.awt.event.FocusEvent)

Example 34 with ActionMap

use of javax.swing.ActionMap in project adempiere by adempiere.

the class CompiereLabelUI method installKeyboardActions.

//	createUI
/**
	 * 	Install Keyboard Actions
	 *	@param l label
	 */
protected void installKeyboardActions(JLabel l) {
    //	super.installKeyboardActions(l);
    int dka = l.getDisplayedMnemonic();
    if (dka != 0) {
        Component lf = l.getLabelFor();
        if (lf != null) {
            ActionMap actionMap = l.getActionMap();
            actionMap.put(PRESS, ACTION_PRESS);
            InputMap inputMap = SwingUtilities.getUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW);
            if (inputMap == null) {
                inputMap = new ComponentInputMapUIResource(l);
                SwingUtilities.replaceUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
            }
            inputMap.clear();
            inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK, false), PRESS);
        }
    }
}
Also used : ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 35 with ActionMap

use of javax.swing.ActionMap in project jmeter by apache.

the class SearchTreeDialog method createRootPane.

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    // Hide Window on ESC
    Action escapeAction = new AbstractAction("ESCAPE") {

        private static final long serialVersionUID = -6543764044868772971L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    };
    // Do search on Enter
    Action enterAction = new AbstractAction("ENTER") {

        private static final long serialVersionUID = -3661361497864527363L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doSearch(actionEvent);
        }
    };
    ActionMap actionMap = rootPane.getActionMap();
    actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
    actionMap.put(enterAction.getValue(Action.NAME), enterAction);
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME));
    return rootPane;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JRootPane(javax.swing.JRootPane) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Aggregations

ActionMap (javax.swing.ActionMap)54 InputMap (javax.swing.InputMap)45 AbstractAction (javax.swing.AbstractAction)27 ActionEvent (java.awt.event.ActionEvent)23 Action (javax.swing.Action)14 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 JButton (javax.swing.JButton)11 BorderLayout (java.awt.BorderLayout)9 JTextField (javax.swing.JTextField)9 JDialog (javax.swing.JDialog)8 JPanel (javax.swing.JPanel)8 JScrollPane (javax.swing.JScrollPane)7 JComponent (javax.swing.JComponent)6 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 ActionListener (java.awt.event.ActionListener)5 KeyStroke (javax.swing.KeyStroke)5 AWTKeyStroke (java.awt.AWTKeyStroke)3 Component (java.awt.Component)3 Insets (java.awt.Insets)3