use of java.awt.AWTKeyStroke in project jabref by JabRef.
the class EntryEditor method setupJTextComponent.
/**
* NOTE: This method is only used for the source panel, not for the
* other tabs. Look at EntryEditorTab for the setup of text components
* in the other tabs.
*/
private void setupJTextComponent(JTextComponent textComponent) {
// Set up key bindings and focus listener for the FieldEditor.
InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED);
ActionMap actionMap = textComponent.getActionMap();
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store");
actionMap.put("store", storeFieldAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right");
actionMap.put("right", switchRightAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left");
actionMap.put("left", switchLeftAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help");
actionMap.put("help", helpAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab");
actionMap.put("nexttab", frame.nextTab);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab");
actionMap.put("prevtab", frame.prevTab);
Set<AWTKeyStroke> keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
keys.clear();
keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB"));
textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
keys.clear();
keys.add(KeyStroke.getKeyStroke("shift pressed TAB"));
textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);
textComponent.addFocusListener(new FieldListener());
}
use of java.awt.AWTKeyStroke in project gate-core by GateNLP.
the class FeaturesSchemaEditor method initGUI.
// init()
protected void initGUI() {
featuresModel = new FeaturesTableModel();
setModel(featuresModel);
setTableHeader(null);
setSortable(false);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
setShowGrid(false);
setBackground(getBackground());
setIntercellSpacing(new Dimension(2, 2));
setTabSkipUneditableCell(true);
setEditCellAsSoonAsFocus(true);
featureEditorRenderer = new FeatureEditorRenderer();
getColumnModel().getColumn(ICON_COL).setCellRenderer(featureEditorRenderer);
getColumnModel().getColumn(NAME_COL).setCellRenderer(featureEditorRenderer);
getColumnModel().getColumn(NAME_COL).setCellEditor(featureEditorRenderer);
getColumnModel().getColumn(VALUE_COL).setCellRenderer(featureEditorRenderer);
getColumnModel().getColumn(VALUE_COL).setCellEditor(featureEditorRenderer);
getColumnModel().getColumn(DELETE_COL).setCellRenderer(featureEditorRenderer);
getColumnModel().getColumn(DELETE_COL).setCellEditor(featureEditorRenderer);
// //the background colour seems to change somewhere when using the GTK+
// //look and feel on Linux, so we copy the value now and set it
// Color tableBG = getBackground();
// //make a copy of the value (as the reference gets changed somewhere)
// tableBG = new Color(tableBG.getRGB());
// setBackground(tableBG);
// allow Tab key to select the next cell in the table
setSurrendersFocusOnKeystroke(true);
setFocusCycleRoot(true);
// remove (shift) control tab as traversal keys
Set<AWTKeyStroke> keySet = new HashSet<AWTKeyStroke>(getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
keySet.remove(KeyStroke.getKeyStroke("control TAB"));
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keySet);
keySet = new HashSet<AWTKeyStroke>(getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
keySet.remove(KeyStroke.getKeyStroke("shift control TAB"));
setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keySet);
// add (shift) control tab to go the container of this component
keySet.clear();
keySet.add(KeyStroke.getKeyStroke("control TAB"));
setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, keySet);
keySet.clear();
keySet.add(KeyStroke.getKeyStroke("shift control TAB"));
setFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, keySet);
}
use of java.awt.AWTKeyStroke in project adempiere by adempiere.
the class CompiereTextAreaUI method updateFocusTraversalKeysX.
// propertyChange
/**
* UpdateFocusTraversalKeysX
*/
void updateFocusTraversalKeysX() {
if (m_editor == null)
return;
//
EditorKit editorKit = getEditorKit(m_editor);
if (editorKit != null && editorKit instanceof DefaultEditorKit) {
Set<AWTKeyStroke> storedForwardTraversalKeys = m_editor.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> storedBackwardTraversalKeys = m_editor.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> forwardTraversalKeys = new HashSet<AWTKeyStroke>(storedForwardTraversalKeys);
Set<AWTKeyStroke> backwardTraversalKeys = new HashSet<AWTKeyStroke>(storedBackwardTraversalKeys);
//
forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
forwardTraversalKeys.remove(s_stroke);
backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
//
LookAndFeel.installProperty(m_editor, "focusTraversalKeysForward", forwardTraversalKeys);
LookAndFeel.installProperty(m_editor, "focusTraversalKeysBackward", backwardTraversalKeys);
}
}
use of java.awt.AWTKeyStroke in project jdk8u_jdk by JetBrains.
the class EmbeddedFrame method dispatchKeyEvent.
/**
* Need this method to detect when the focus may have chance to leave the
* focus cycle root which is EmbeddedFrame. Mostly, the code here is copied
* from DefaultKeyboardFocusManager.processKeyEvent with some minor
* modifications.
*/
public boolean dispatchKeyEvent(KeyEvent e) {
Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor().getCurrentFocusCycleRoot();
// if we are not in EmbeddedFrame's cycle, we should not try to leave.
if (this != currentRoot) {
return false;
}
// KEY_TYPED events cannot be focus traversal keys
if (e.getID() == KeyEvent.KEY_TYPED) {
return false;
}
if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
return false;
}
AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
Set<AWTKeyStroke> toTest;
Component currentFocused = e.getComponent();
toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
if (toTest.contains(stroke)) {
// 6581899: performance improvement for SortingFocusTraversalPolicy
Component last = getFocusTraversalPolicy().getLastComponent(this);
if (currentFocused == last || last == null) {
if (traverseOut(FORWARD)) {
e.consume();
return true;
}
}
}
toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
if (toTest.contains(stroke)) {
// 6581899: performance improvement for SortingFocusTraversalPolicy
Component first = getFocusTraversalPolicy().getFirstComponent(this);
if (currentFocused == first || first == null) {
if (traverseOut(BACKWARD)) {
e.consume();
return true;
}
}
}
return false;
}
use of java.awt.AWTKeyStroke in project jsql-injection by ron190.
the class ActionHandler method addShortcut.
/**
* Add action to global root (ctrl-tab, ctrl-shift-tab, ctrl-W).
*/
@SuppressWarnings("serial")
public static void addShortcut(JRootPane rootPane, final JTabbedPane valuesTabbedPane) {
Action closeTab = new ActionCloseTabResult();
Action nextTab = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (valuesTabbedPane.getTabCount() > 0) {
int selectedIndex = valuesTabbedPane.getSelectedIndex();
if (selectedIndex + 1 < valuesTabbedPane.getTabCount()) {
valuesTabbedPane.setSelectedIndex(selectedIndex + 1);
} else {
valuesTabbedPane.setSelectedIndex(0);
}
}
}
};
Action previousTab = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (valuesTabbedPane.getTabCount() > 0) {
int selectedIndex = valuesTabbedPane.getSelectedIndex();
if (selectedIndex - 1 > -1) {
valuesTabbedPane.setSelectedIndex(selectedIndex - 1);
} else {
valuesTabbedPane.setSelectedIndex(valuesTabbedPane.getTabCount() - 1);
}
}
}
};
Set<AWTKeyStroke> forwardKeys = new HashSet<>(rootPane.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
forwardKeys.remove(KeyStroke.getKeyStroke("ctrl TAB"));
rootPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
Set<AWTKeyStroke> forwardKeys2 = new HashSet<>(rootPane.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
forwardKeys2.remove(KeyStroke.getKeyStroke("ctrl shift TAB"));
rootPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, forwardKeys2);
InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = rootPane.getActionMap();
inputMap.put(KeyStroke.getKeyStroke("ctrl W"), "actionString-closeTab");
actionMap.put("actionString-closeTab", closeTab);
inputMap.put(KeyStroke.getKeyStroke("ctrl TAB"), "actionString-nextTab");
actionMap.put("actionString-nextTab", nextTab);
inputMap.put(KeyStroke.getKeyStroke("ctrl shift TAB"), "actionString-previousTab");
actionMap.put("actionString-previousTab", previousTab);
int i = MediatorGui.tabManagers().getTabCount();
for (int k = 1; k <= i; k++) {
inputMap.put(KeyStroke.getKeyStroke("ctrl " + k), "actionString-selectTab" + k);
inputMap.put(KeyStroke.getKeyStroke("ctrl NUMPAD" + k), "actionString-selectTab" + k);
final int l = k;
actionMap.put("actionString-selectTab" + k, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
MediatorGui.tabManagers().setSelectedIndex(l - 1);
}
});
}
inputMap.put(KeyStroke.getKeyStroke("ctrl S"), "actionString-saveTab");
actionMap.put("actionString-saveTab", new ActionSaveTab());
}
Aggregations