use of javax.swing.KeyStroke in project knime-core by knime.
the class TableView method registerGotoRowAction.
/**
* Creates and registers the "Go to Row" action on this component. Multiple invocation of this method have no effect
* (lazy initialization).
*
* @return The non-null action representing the go to row task.
* @see #registerNavigationActions()
*/
public TableAction registerGotoRowAction() {
if (m_gotoRowAction == null) {
String name = "Go to Row...";
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
TableAction action = new TableAction(stroke, name) {
@Override
public void actionPerformed(final ActionEvent e) {
if (!hasData()) {
return;
}
String rowString = JOptionPane.showInputDialog(TableView.this, "Enter row number:", "Go to Row", JOptionPane.QUESTION_MESSAGE);
if (rowString == null) {
// canceled
return;
}
try {
int row = Integer.parseInt(rowString);
gotoCell(row - 1, 0);
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(TableView.this, "Can't parse " + rowString, "Error", JOptionPane.ERROR_MESSAGE);
}
}
};
registerAction(action);
m_gotoRowAction = action;
}
return m_gotoRowAction;
}
use of javax.swing.KeyStroke in project knime-core by knime.
the class TableView method createFontSizeAction.
/**
* Implementation of {@link #registerIncreaseFontSizeAction()} and {@link #registerDecreaseFontSizeAction()}.
* @return a new registered action
*/
private TableAction createFontSizeAction(final boolean isIncrease) {
String name = (isIncrease ? "Increase" : "Decrease") + " Font Size";
// increase has two keystrokes - Ctrl-+ and Ctrl-= (due to US keyboard layouts)
KeyStroke[] keyStrokes;
// CTRL on Windows, Apple key on Mac
int shortcut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
final int sizeIncrement;
if (isIncrease) {
sizeIncrement = +1;
keyStrokes = new KeyStroke[] { // on US layout this is next to '-'
KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, shortcut), KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, shortcut) };
} else {
sizeIncrement = -1;
keyStrokes = new KeyStroke[] { KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, shortcut) };
}
TableAction action = null;
for (KeyStroke keyStroke : keyStrokes) {
action = new TableAction(keyStroke, name) {
@Override
public void actionPerformed(final ActionEvent e) {
if (!hasData()) {
return;
}
int curFontSize = getContentTable().getFont().getSize();
setFontSize(curFontSize + sizeIncrement);
}
};
registerAction(action);
}
return action;
}
use of javax.swing.KeyStroke in project processdash by dtuma.
the class WBSJTable method buildCustomActionMaps.
/** Populate the <tt>customActions</tt> list with actions for editing
* the work breakdown structure. */
private void buildCustomActionMaps() {
// Map "Tab" and "Shift-Tab" to the demote/promote actions
customActions.add(new WbsActionMapping(KeyEvent.VK_TAB, 0, "Demote", DEMOTE_ACTION));
customActions.add(new WbsActionMapping(KeyEvent.VK_TAB, SHIFT, "Promote", PROMOTE_ACTION));
customActions.add(new ActionMapping(KeyEvent.VK_INSERT, 0, "Insert", INSERT_ACTION));
customActions.add(new ActionMapping(KeyEvent.VK_ENTER, 0, "Enter", ENTER_ACTION));
customActions.add(new ActionMapping(KeyEvent.VK_ENTER, SHIFT, "InsertAfter", INSERT_AFTER_ACTION));
customActions.add(new ActionMapping("collapseTree", COLLAPSE_ACTION));
customActions.add(new ActionMapping("expandTree", EXPAND_ACTION));
customActions.add(new ActionMapping("moveTreeUp", MOVEUP_ACTION));
customActions.add(new ActionMapping("moveTreeDown", MOVEDOWN_ACTION));
// Find the default row navigation actions for the table, and replace
// them with new actions which (1) perform the original action, then
// (2) restart editing on the newly selected cell.
InputMap inputMap = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap actionMap = getActionMap();
List filter = Arrays.asList(new String[] { "selectPreviousRow", "selectNextRow", "selectFirstRow", "selectLastRow", "scrollUpChangeSelection", "scrollDownChangeSelection" });
KeyStroke[] keys = inputMap.allKeys();
for (int i = 0; i < keys.length; i++) {
Object actionKey = inputMap.get(keys[i]);
if (!filter.contains(actionKey))
continue;
Action action = actionMap.get(actionKey);
if (action == null)
continue;
customActions.add(new ActionMapping(keys[i], actionKey + "-WBS", new DelegateActionRestartEditing(action, actionKey)));
}
}
use of javax.swing.KeyStroke in project chipKIT32-MAX by chipKIT32.
the class DefaultInputHandler method keyPressed.
/**
* Handle a key pressed event. This will look up the binding for
* the key stroke and execute it.
*/
public void keyPressed(KeyEvent evt) {
int keyCode = evt.getKeyCode();
int modifiers = evt.getModifiers();
// moved this earlier so it doesn't get random meta clicks
if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_META) {
return;
}
//if ((modifiers & KeyEvent.META_MASK) != 0) return;
if ((modifiers & KeyEvent.META_MASK) != 0) {
KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
if (currentBindings.get(keyStroke) == null) {
return;
}
}
if ((modifiers & ~KeyEvent.SHIFT_MASK) != 0 || evt.isActionKey() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) {
if (grabAction != null) {
handleGrabAction(evt);
return;
}
KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
Object o = currentBindings.get(keyStroke);
if (o == null) {
// beep when caps lock is pressed, etc.
if (currentBindings != bindings) {
Toolkit.getDefaultToolkit().beep();
// F10 should be passed on, but C+e F10
// shouldn't
repeatCount = 0;
repeat = false;
evt.consume();
}
currentBindings = bindings;
return;
} else if (o instanceof ActionListener) {
currentBindings = bindings;
executeAction(((ActionListener) o), evt.getSource(), null);
evt.consume();
return;
} else if (o instanceof Hashtable) {
currentBindings = (Hashtable) o;
evt.consume();
return;
}
}
}
use of javax.swing.KeyStroke in project chipKIT32-MAX by chipKIT32.
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) {
Hashtable 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 Hashtable)
current = (Hashtable) o;
else {
o = new Hashtable();
current.put(keyStroke, o);
current = (Hashtable) o;
}
} else
current.put(keyStroke, action);
}
}
Aggregations