Search in sources :

Example 16 with KeyStroke

use of javax.swing.KeyStroke in project zaproxy by zaproxy.

the class ExtensionKeyboard method menuToMapping.

private KeyboardMapping menuToMapping(ZapMenuItem menuItem) {
    KeyStroke ks = this.getKeyboardParam().getShortcut(menuItem.getIdenfifier());
    if (ks != null) {
        if (ks.getKeyCode() == 0) {
            // Used to indicate no accelerator should be used
            logger.debug("Cleaning menu " + menuItem.getIdenfifier() + " accelerator");
            menuItem.setAccelerator(null);
        } else {
            logger.debug("Setting menu " + menuItem.getIdenfifier() + " accelerator to " + ks.toString());
            menuItem.setAccelerator(ks);
        }
    }
    return new KeyboardMapping(menuItem);
}
Also used : KeyStroke(javax.swing.KeyStroke)

Example 17 with KeyStroke

use of javax.swing.KeyStroke in project zaproxy by zaproxy.

the class StandardFieldsDialog method initialize.

private void initialize(Dimension dim, String[] tabLabels) {
    this.setLayout(new GridBagLayout());
    this.setSize(dim);
    if (tabLabels == null) {
        this.initializeSinglePane(dim);
    } else {
        this.initializeTabbed(dim, tabLabels);
    }
    //  Handle escape key to close the dialog    
    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    AbstractAction escapeAction = new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (hasCancelSaveButtons()) {
                cancelPressed();
                return;
            }
            savePressed();
        }
    };
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
Also used : GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) AbstractAction(javax.swing.AbstractAction)

Example 18 with KeyStroke

use of javax.swing.KeyStroke in project zaproxy by zaproxy.

the class AbstractDialog method initialize.

/**
	 * This method initializes this
	 */
private void initialize() {
    this.setVisible(false);
    this.setIconImages(DisplayUtils.getZapIconImages());
    this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    if (Model.getSingleton().getOptionsParam().getViewParam().getWmUiHandlingOption() == 0) {
        this.setSize(300, 200);
    }
    this.setTitle(Constant.PROGRAM_NAME);
    //  Handle escape key to close the dialog    
    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    AbstractAction escapeAction = new AbstractAction() {

        private static final long serialVersionUID = 3516424501887406165L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dispatchEvent(new WindowEvent(AbstractDialog.this, WindowEvent.WINDOW_CLOSING));
        }
    };
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
Also used : ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke) AbstractAction(javax.swing.AbstractAction)

Example 19 with KeyStroke

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

the class SettingsSearch method preprocessEventForTextField.

@Override
protected boolean preprocessEventForTextField(KeyEvent event) {
    if (!myDelegatingNow) {
        KeyStroke stroke = KeyStroke.getKeyStrokeForEvent(event);
        String strokeString = stroke.toString();
        if ("pressed ESCAPE".equals(strokeString) && getText().length() > 0) {
            // reset filter on ESC
            setText("");
            return true;
        }
        if (getTextEditor().isFocusOwner()) {
            try {
                myDelegatingNow = true;
                int code = stroke.getKeyCode();
                boolean treeNavigation = stroke.getModifiers() == 0 && (code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN);
                if (treeNavigation || !hasAction(stroke, getTextEditor().getInputMap())) {
                    onTextKeyEvent(event);
                    return true;
                }
            } finally {
                myDelegatingNow = false;
            }
        }
    }
    return false;
}
Also used : KeyStroke(javax.swing.KeyStroke)

Example 20 with KeyStroke

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

Aggregations

KeyStroke (javax.swing.KeyStroke)68 ActionEvent (java.awt.event.ActionEvent)27 ActionListener (java.awt.event.ActionListener)15 AbstractAction (javax.swing.AbstractAction)13 JRootPane (javax.swing.JRootPane)13 Action (javax.swing.Action)10 InputMap (javax.swing.InputMap)9 WindowEvent (java.awt.event.WindowEvent)6 ActionMap (javax.swing.ActionMap)5 GridBagLayout (java.awt.GridBagLayout)4 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 JMenuItem (javax.swing.JMenuItem)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 AWTKeyStroke (java.awt.AWTKeyStroke)3 Dimension (java.awt.Dimension)3 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 KeyEvent (java.awt.event.KeyEvent)3