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);
}
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);
}
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);
}
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;
}
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("-------------------------");
}
Aggregations