use of javax.swing.KeyStroke in project languagetool by languagetool-org.
the class LanguageManagerDialog method show.
public void show() {
dialog = new JDialog(owner, true);
dialog.setTitle(messages.getString("guiLanguageManagerDialog"));
// close dialog when user presses Escape key:
// TODO: taken from ConfigurationDialog, avoid duplication:
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
ActionListener actionListener = new ActionListener() {
@Override
@SuppressWarnings("unused")
public void actionPerformed(ActionEvent actionEvent) {
dialog.setVisible(false);
}
};
JRootPane rootPane = dialog.getRootPane();
rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new GridBagLayout());
list = new JList<>(ruleFiles.toArray(new File[ruleFiles.size()]));
GridBagConstraints cons = new GridBagConstraints();
cons.insets = new Insets(4, 4, 4, 4);
cons.gridx = 0;
cons.gridy = 0;
cons.fill = GridBagConstraints.BOTH;
cons.weightx = 2.0f;
cons.weighty = 2.0f;
contentPane.add(new JScrollPane(list), cons);
cons = new GridBagConstraints();
cons.insets = new Insets(4, 4, 4, 4);
cons.fill = GridBagConstraints.HORIZONTAL;
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
addButton = new JButton(messages.getString("guiAddButton"));
addButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 0;
buttonPanel.add(addButton, cons);
removeButton = new JButton(messages.getString("guiRemoveButton"));
removeButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 1;
buttonPanel.add(removeButton, cons);
closeButton = new JButton(messages.getString("guiCloseButton"));
closeButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 2;
buttonPanel.add(closeButton, cons);
cons.gridx = 1;
cons.gridy = 0;
cons = new GridBagConstraints();
cons.anchor = GridBagConstraints.NORTH;
contentPane.add(buttonPanel, cons);
dialog.pack();
dialog.setSize(300, 200);
dialog.setLocationByPlatform(true);
dialog.setVisible(true);
}
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 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("-------------------------");
}
use of javax.swing.KeyStroke in project adempiere by adempiere.
the class AMenu method createMenu.
// getPreferredSize
/**
* Create Menu
*/
private void createMenu() {
// File
JMenu mFile = AEnv.getMenu("File");
menuBar.add(mFile);
AEnv.addMenuItem("PrintScreen", null, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0), mFile, this);
AEnv.addMenuItem("ScreenShot", null, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, KeyEvent.SHIFT_MASK), mFile, this);
mFile.addSeparator();
AEnv.addMenuItem("Logout", null, KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.SHIFT_MASK + Event.ALT_MASK), mFile, this);
AEnv.addMenuItem("Exit", null, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.SHIFT_MASK + Event.ALT_MASK), mFile, this);
// View
JMenu mView = AEnv.getMenu("View");
menuBar.add(mView);
if (MRole.getDefault().isAllow_Info_Product()) {
AEnv.addMenuItem("InfoProduct", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK), mView, this);
}
if (MRole.getDefault().isAllow_Info_BPartner()) {
AEnv.addMenuItem("InfoBPartner", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK + Event.CTRL_MASK), mView, this);
}
if (MRole.getDefault().isShowAcct() && MRole.getDefault().isAllow_Info_Account()) {
AEnv.addMenuItem("InfoAccount", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK + Event.CTRL_MASK), mView, this);
}
if (MRole.getDefault().isAllow_Info_Schedule()) {
AEnv.addMenuItem("InfoSchedule", null, null, mView, this);
}
//FR [ 1966328 ]
if (MRole.getDefault().isAllow_Info_MRP()) {
AEnv.addMenuItem("InfoMRP", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_CRP()) {
AEnv.addMenuItem("InfoCRP", "Info", null, mView, this);
}
mView.addSeparator();
if (MRole.getDefault().isAllow_Info_Order()) {
AEnv.addMenuItem("InfoOrder", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Invoice()) {
AEnv.addMenuItem("InfoInvoice", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_InOut()) {
AEnv.addMenuItem("InfoInOut", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Payment()) {
AEnv.addMenuItem("InfoPayment", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_CashJournal()) {
AEnv.addMenuItem("InfoCashLine", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Resource()) {
AEnv.addMenuItem("InfoAssignment", "Info", null, mView, this);
}
if (MRole.getDefault().isAllow_Info_Asset()) {
AEnv.addMenuItem("InfoAsset", "Info", null, mView, this);
}
// Tools
JMenu mTools = AEnv.getMenu("Tools");
menuBar.add(mTools);
AEnv.addMenuItem("Calculator", null, null, mTools, this);
AEnv.addMenuItem("Calendar", null, null, mTools, this);
AEnv.addMenuItem("Editor", null, null, mTools, this);
MUser user = MUser.get(Env.getCtx());
if (user.isAdministrator())
AEnv.addMenuItem("Script", null, null, mTools, this);
if (AEnv.isWorkflowProcess())
AEnv.addMenuItem("WorkFlow", null, null, mTools, this);
if (MRole.getDefault().isShowPreference()) {
mTools.addSeparator();
AEnv.addMenuItem("Preference", null, null, mTools, this);
}
//Window Menu
m_WindowMenu = new WindowMenu(windowManager, this);
menuBar.add(m_WindowMenu);
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_MASK);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, "ShowAllWindow");
AppsAction action = new AppsAction("ShowAllWindow", ks, false);
this.getRootPane().getActionMap().put("ShowAllWindow", action);
action.setDelegate(this);
// Help
JMenu mHelp = AEnv.getMenu("Help");
menuBar.add(mHelp);
AEnv.addMenuItem("Online", null, null, mHelp, this);
AEnv.addMenuItem("EMailSupport", null, null, mHelp, this);
AEnv.addMenuItem("About", null, null, mHelp, this);
}
Aggregations