Search in sources :

Example 1 with ComponentInputMapUIResource

use of javax.swing.plaf.ComponentInputMapUIResource 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 2 with ComponentInputMapUIResource

use of javax.swing.plaf.ComponentInputMapUIResource in project jdk8u_jdk by JetBrains.

the class BasicButtonListener method updateMnemonicBinding.

/**
     * Resets the binding for the mnemonic in the WHEN_IN_FOCUSED_WINDOW
     * UI InputMap.
     */
void updateMnemonicBinding(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();
        map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), false), "pressed");
        map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), 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 : ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource)

Example 3 with ComponentInputMapUIResource

use of javax.swing.plaf.ComponentInputMapUIResource in project intellij-community by JetBrains.

the class ActionButtonWithText method updateMnemonic.

private void updateMnemonic(int lastMnemonic, int mnemonic) {
    if (mnemonic == lastMnemonic) {
        return;
    }
    InputMap windowInputMap = SwingUtilities.getUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW);
    int mask = SystemInfo.isMac ? InputEvent.ALT_MASK | InputEvent.CTRL_MASK : InputEvent.ALT_MASK;
    if (lastMnemonic != 0 && windowInputMap != null) {
        windowInputMap.remove(KeyStroke.getKeyStroke(lastMnemonic, mask, false));
    }
    if (mnemonic != 0) {
        if (windowInputMap == null) {
            windowInputMap = new ComponentInputMapUIResource(this);
            SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
        }
        windowInputMap.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "doClick");
    }
}
Also used : ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource)

Example 4 with ComponentInputMapUIResource

use of javax.swing.plaf.ComponentInputMapUIResource in project adempiere by adempiere.

the class AdempiereButtonListener 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 5 with ComponentInputMapUIResource

use of javax.swing.plaf.ComponentInputMapUIResource 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)

Aggregations

ComponentInputMapUIResource (javax.swing.plaf.ComponentInputMapUIResource)8 InputMap (javax.swing.InputMap)6 JCheckBox (javax.swing.JCheckBox)3 Component (java.awt.Component)2 ActionMap (javax.swing.ActionMap)2 JComponent (javax.swing.JComponent)2