Search in sources :

Example 6 with InputMap

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

the class CompiereButtonListener method updateMnemonicBindingX.

//	propertyChange
/**
	 * 	Update Mnemonic Binding
	 *	@param b button
	 */
void updateMnemonicBindingX(AbstractButton b) {
    int m = b.getMnemonic();
    if (m != 0) {
        InputMap map = SwingUtilities.getUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW);
        if (map == null) {
            map = new ComponentInputMapUIResource(b);
            SwingUtilities.replaceUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
        }
        map.clear();
        String className = b.getClass().getName();
        //	Default Buttons
        int mask = InputEvent.ALT_MASK;
        if (//	In Tab
        b instanceof JCheckBox || className.indexOf("VButton") != -1)
            mask = InputEvent.SHIFT_MASK + InputEvent.CTRL_MASK;
        map.put(KeyStroke.getKeyStroke(m, mask, false), "pressed");
        map.put(KeyStroke.getKeyStroke(m, mask, true), "released");
        map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
    } else {
        InputMap map = SwingUtilities.getUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW);
        if (map != null)
            map.clear();
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource) InputMap(javax.swing.InputMap)

Example 7 with InputMap

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

the class VLookup method processKeyBinding.

//	VLookup_mouseAdapter
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    if (e.getSource() == m_combo || e.getSource() == m_text || e.getSource() == this) {
        return super.processKeyBinding(ks, e, condition, pressed);
    }
    JComponent editorComp = null;
    if (m_lookup != null && m_lookup.getDisplayType() != DisplayType.Search)
        editorComp = m_combo;
    else
        editorComp = m_text;
    InputMap map = editorComp.getInputMap(condition);
    ActionMap am = editorComp.getActionMap();
    if (map != null && am != null && isEnabled()) {
        Object binding = map.get(ks);
        Action action = (binding == null) ? null : am.get(binding);
        if (action != null) {
            return SwingUtilities.notifyAction(action, ks, e, editorComp, e.getModifiers());
        }
    }
    return false;
}
Also used : Action(javax.swing.Action) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) InputMap(javax.swing.InputMap)

Example 8 with InputMap

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

the class Util method printActionInputMap.

//	dump (Map)
/**
	 * Print Action and Input Map for component
	 * @param comp  Component with ActionMap
	 */
public static void printActionInputMap(JComponent comp) {
    //	Action Map
    ActionMap am = comp.getActionMap();
    //  including Parents
    Object[] amKeys = am.allKeys();
    if (amKeys != null) {
        System.out.println("-------------------------");
        System.out.println("ActionMap for Component " + comp.toString());
        for (int i = 0; i < amKeys.length; i++) {
            Action a = am.get(amKeys[i]);
            StringBuffer sb = new StringBuffer("- ");
            sb.append(a.getValue(Action.NAME));
            if (a.getValue(Action.ACTION_COMMAND_KEY) != null)
                sb.append(", Cmd=").append(a.getValue(Action.ACTION_COMMAND_KEY));
            if (a.getValue(Action.SHORT_DESCRIPTION) != null)
                sb.append(" - ").append(a.getValue(Action.SHORT_DESCRIPTION));
            System.out.println(sb.toString() + " - " + a);
        }
    }
    /**	Same as below
		KeyStroke[] kStrokes = comp.getRegisteredKeyStrokes();
		if (kStrokes != null)
		{
		System.out.println("-------------------------");
			System.out.println("Registered Key Strokes - " + comp.toString());
			for (int i = 0; i < kStrokes.length; i++)
			{
				System.out.println("- " + kStrokes[i].toString());
			}
		}
		/** Focused				*/
    InputMap im = comp.getInputMap(JComponent.WHEN_FOCUSED);
    KeyStroke[] kStrokes = im.allKeys();
    if (kStrokes != null) {
        System.out.println("-------------------------");
        System.out.println("InputMap for Component When Focused - " + comp.toString());
        for (int i = 0; i < kStrokes.length; i++) {
            System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
        }
    }
    /** Focused in Window	*/
    im = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    kStrokes = im.allKeys();
    if (kStrokes != null) {
        System.out.println("-------------------------");
        System.out.println("InputMap for Component When Focused in Window - " + comp.toString());
        for (int i = 0; i < kStrokes.length; i++) {
            System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
        }
    }
    /** Focused when Ancester	*/
    im = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    kStrokes = im.allKeys();
    if (kStrokes != null) {
        System.out.println("-------------------------");
        System.out.println("InputMap for Component When Ancestor - " + comp.toString());
        for (int i = 0; i < kStrokes.length; i++) {
            System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
        }
    }
    System.out.println("-------------------------");
}
Also used : Action(javax.swing.Action) ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Example 9 with InputMap

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

the class SelectTemplatesDialog method createRootPane.

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

        /**
             *
             */
        private static final long serialVersionUID = -6543764044868772971L;

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

        private static final long serialVersionUID = -3661361497864527363L;

        @Override
        public void actionPerformed(final ActionEvent actionEvent) {
            checkDirtyAndLoad(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)

Example 10 with InputMap

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

the class RowDetailDialog method createRootPane.

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

        private static final long serialVersionUID = -8699034338969407625L;

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

        private static final long serialVersionUID = -1529005452976176873L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doUpdate(actionEvent);
            setVisible(false);
        }
    };
    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

InputMap (javax.swing.InputMap)59 ActionMap (javax.swing.ActionMap)38 AbstractAction (javax.swing.AbstractAction)32 ActionEvent (java.awt.event.ActionEvent)30 Action (javax.swing.Action)18 JButton (javax.swing.JButton)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 JCheckBox (javax.swing.JCheckBox)8 JDialog (javax.swing.JDialog)8 JScrollPane (javax.swing.JScrollPane)8 JTextField (javax.swing.JTextField)7 KeyStroke (javax.swing.KeyStroke)7 JComponent (javax.swing.JComponent)6 JRootPane (javax.swing.JRootPane)6 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 ComponentInputMapUIResource (javax.swing.plaf.ComponentInputMapUIResource)5 Insets (java.awt.Insets)4