use of javax.swing.InputMap in project vcell by virtualcell.
the class MultiPurposeTextPanel method getSearchTextField.
private JTextField getSearchTextField() {
if (searchTextField == null) {
try {
searchTextField = new JTextField();
searchTextField.setColumns(15);
searchTextFieldBackground = searchTextField.getBackground();
searchTextField.getDocument().addDocumentListener(eventHandler);
InputMap im = searchTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
ActionMap am = searchTextField.getActionMap();
am.put(CANCEL_ACTION, new CancelSearchAction());
} catch (java.lang.Throwable ivjExc) {
ivjExc.printStackTrace();
}
}
return searchTextField;
}
use of javax.swing.InputMap in project sulky by huxi.
the class SwingLogging method logInputMaps.
public static void logInputMaps(JComponent component) {
final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
if (logger.isDebugEnabled()) {
final int[] conditions = { JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT };
final String[] conditionStrings = { "WHEN_IN_FOCUSED_WINDOW", "WHEN_FOCUSED", "WHEN_ANCESTOR_OF_FOCUSED_COMPONENT" };
StringBuilder msg = new StringBuilder();
for (int i = 0; i < conditions.length; i++) {
@SuppressWarnings("MagicConstant") InputMap inputMap = component.getInputMap(conditions[i]);
msg.append("InputMap for '").append(conditionStrings[i]).append("':\n");
for (; ; ) {
KeyStroke[] keyStrokes = inputMap.keys();
if (keyStrokes != null) {
for (KeyStroke ks : keyStrokes) {
msg.append("\tKeyStroke: ").append(ks).append("\n\tActionMapKey: ").append(inputMap.get(ks)).append("\n\n");
}
}
msg.append("######################################\n");
inputMap = inputMap.getParent();
if (inputMap == null) {
msg.append("No parent.\n\n");
break;
} else {
msg.append("Parent:\n");
}
}
}
ActionMap actionMap = component.getActionMap();
msg.append("ActionMap:\n");
for (; ; ) {
Object[] keys = actionMap.keys();
if (keys != null) {
for (Object key : keys) {
msg.append("\tKey: ").append(key).append("\n\tAction: ").append(actionMap.get(key)).append("\n\n");
}
}
msg.append("######################################\n");
actionMap = actionMap.getParent();
if (actionMap == null) {
msg.append("No parent.\n\n");
break;
} else {
msg.append("Parent:\n");
}
}
if (logger.isDebugEnabled())
logger.debug(msg.toString());
}
}
use of javax.swing.InputMap in project sulky by huxi.
the class KeyStrokes method registerCommand.
public static void registerCommand(JComponent component, Action action, String commandName) {
KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
if (keyStroke == null) {
return;
}
logInputMaps(component, "BEFORE");
InputMap inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = component.getActionMap();
inputMap.put(keyStroke, commandName);
actionMap.put(commandName, action);
Object value;
inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
value = inputMap.get(keyStroke);
if (value != null) {
inputMap.put(keyStroke, commandName);
}
inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
value = inputMap.get(keyStroke);
if (value != null) {
inputMap.put(keyStroke, commandName);
}
logInputMaps(component, "AFTER");
}
use of javax.swing.InputMap in project cayenne by apache.
the class EditorTextField method initTabHandler.
private void initTabHandler() {
this.combo.setFocusTraversalKeysEnabled(false);
this.combo.getActionMap().put("tab-action", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
combo.setSelectedItem(getText());
Component component = getParent().getParent();
if (component instanceof JTable) {
JTable table = (JTable) component;
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
table.changeSelection(table.getEditingRow(), table.getEditingColumn() - 1, false, false);
} else {
table.changeSelection(table.getEditingRow(), table.getEditingColumn() + 1, false, false);
}
} else {
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
transferFocusBackward();
} else {
transferFocus();
}
}
}
});
InputMap inputMap = this.combo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke("TAB"), "tab-action");
inputMap.put(KeyStroke.getKeyStroke("shift TAB"), "tab-action");
}
Aggregations