use of javax.swing.KeyStroke in project processing by processing.
the class DefaultInputHandler method addKeyBinding.
/**
* Adds a key binding to this input handler. The key binding is
* a list of white space separated key strokes of the form
* <i>[modifiers+]key</i> where modifier is C for Control, A for Alt,
* or S for Shift, and key is either a character (a-z) or a field
* name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
* @param keyBinding The key binding
* @param action The action
*/
public void addKeyBinding(String keyBinding, ActionListener action) {
Map current = bindings;
StringTokenizer st = new StringTokenizer(keyBinding);
while (st.hasMoreTokens()) {
KeyStroke keyStroke = parseKeyStroke(st.nextToken());
if (keyStroke == null)
return;
if (st.hasMoreTokens()) {
Object o = current.get(keyStroke);
if (o instanceof Map)
current = (Map) o;
else {
o = new HashMap();
current.put(keyStroke, o);
current = (Map) o;
}
} else
current.put(keyStroke, action);
}
}
use of javax.swing.KeyStroke in project processing by processing.
the class DefaultInputHandler method keyTyped.
/**
* Handle a key typed event. This inserts the key into the text area.
*/
public void keyTyped(KeyEvent evt) {
int modifiers = evt.getModifiers();
char c = evt.getKeyChar();
// in an attempt to prevent.
if ((modifiers & InputEvent.META_MASK) != 0)
return;
// http://code.google.com/p/processing/issues/detail?id=596
if ((modifiers & InputEvent.CTRL_MASK) != 0 && c == '/')
return;
if (// &&
c != KeyEvent.CHAR_UNDEFINED) // (modifiers & KeyEvent.ALT_MASK) == 0)
{
if (c >= 0x20 && c != 0x7f) {
KeyStroke keyStroke = KeyStroke.getKeyStroke(Character.toUpperCase(c));
Object o = currentBindings.get(keyStroke);
if (o instanceof Map) {
currentBindings = (Map) o;
return;
} else if (o instanceof ActionListener) {
currentBindings = bindings;
executeAction((ActionListener) o, evt.getSource(), String.valueOf(c));
return;
}
currentBindings = bindings;
if (grabAction != null) {
handleGrabAction(evt);
return;
}
// 0-9 adds another 'digit' to the repeat number
if (repeat && Character.isDigit(c)) {
repeatCount *= 10;
repeatCount += (c - '0');
return;
}
executeAction(INSERT_CHAR, evt.getSource(), String.valueOf(evt.getKeyChar()));
repeatCount = 0;
repeat = false;
}
}
}
use of javax.swing.KeyStroke in project GCViewer by chewiebug.
the class ScreenCenteredDialog method createRootPane.
protected JRootPane createRootPane() {
KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
JRootPane rootPane = new JRootPane();
rootPane.registerKeyboardAction(this, escapeStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
rootPane.registerKeyboardAction(this, enterStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
return rootPane;
}
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 DialogEditShortcut method save.
@Override
public void save() {
KeyboardShortcut ksDup = this.getDuplicate();
if (ksDup != null) {
// used for another menu item, so remove it from that
ksDup.setKeyStroke(null);
}
KeyStroke ks = getKeyStroke();
shortcut.setKeyStroke(ks);
}
Aggregations