use of javax.swing.KeyStroke in project java-jotasync by trixon.
the class TabHolder method initActions.
void initActions() {
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = getRootPane().getActionMap();
int commandMask = SystemHelper.getCommandMask();
mCloseAction = mActionManager.getAction(ActionManager.CLOSE_TAB);
mSaveAction = mActionManager.getAction(ActionManager.SAVE_TAB);
for (int i = 0; i < 10; i++) {
KeyStroke keyStroke = KeyStroke.getKeyStroke(0x31 + i, commandMask);
String key = "key_" + i;
final int tabIndex = i;
AbstractAction action = new AbstractAction("Tab") {
@Override
public void actionPerformed(ActionEvent e) {
displayTab(tabIndex);
}
};
inputMap.put(keyStroke, key);
actionMap.put(key, action);
}
AbstractAction action = new AbstractAction("TabNext") {
@Override
public void actionPerformed(ActionEvent e) {
displayTab(getSelectedIndex() + 1);
}
};
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, commandMask);
String key = "nextTab";
inputMap.put(keyStroke, key);
actionMap.put(key, action);
action = new AbstractAction("TabPrev") {
@Override
public void actionPerformed(ActionEvent e) {
displayTab(Math.max(getSelectedIndex() - 1, 0));
}
};
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, commandMask + InputEvent.SHIFT_MASK);
key = "prevTab";
inputMap.put(keyStroke, key);
actionMap.put(key, action);
mActionManager.addAppListener(new ActionManager.AppAdapter() {
@Override
public void onCancel(ActionEvent actionEvent) {
if (getSelectedComponent() instanceof TabItem) {
TabItem tabItem = (TabItem) getSelectedComponent();
if (tabItem.isCancelable()) {
tabItem.cancel();
}
}
}
@Override
public void onMenu(ActionEvent actionEvent) {
mMenuMouseAdapter.mousePressed(null);
}
});
}
use of javax.swing.KeyStroke in project java-jotasync by trixon.
the class TabHolder method init.
private void init() {
setFocusTraversalKeysEnabled(false);
mSpeedDialPanel = new SpeedDialPanel();
IconColor iconColor = mAlmondOptions.getIconColor();
add(mSpeedDialPanel, MaterialIcon._Action.HOME.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
setIconAt(0, MaterialIcon._Action.HOME.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
HistoryPanel historyPanel = new HistoryPanel();
add(historyPanel, MaterialIcon._Action.HISTORY.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
setIconAt(1, MaterialIcon._Action.HISTORY.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
mJobMap.values().stream().forEach((tabItem) -> {
tabItem.updateIcons(iconColor);
});
mManager.addConnectionListeners(this);
mManager.getClient().addServerEventListener(this);
mMenuMouseAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e == null || e.getButton() == MouseEvent.BUTTON1) {
Component component = ((TabListener) getSelectedComponent()).getMenuButton();
JPopupMenu popupMenu = MainFrame.getPopupMenu();
InputMap inputMap = popupMenu.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = popupMenu.getActionMap();
Action action = new AbstractAction("HideMenu") {
@Override
public void actionPerformed(ActionEvent e) {
popupMenu.setVisible(false);
}
};
String key = "HideMenu";
actionMap.put(key, action);
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
inputMap.put(keyStroke, key);
if (popupMenu.isVisible()) {
popupMenu.setVisible(false);
} else {
popupMenu.show(component, component.getWidth() - popupMenu.getWidth(), component.getHeight());
int x = component.getLocationOnScreen().x + component.getWidth() - popupMenu.getWidth();
int y = component.getLocationOnScreen().y + component.getHeight();
popupMenu.setLocation(x, y);
}
}
}
};
mSpeedDialPanel.getMenuButton().addMouseListener(mMenuMouseAdapter);
// FIXME Why is this necessary?
setTabLayoutPolicy(SCROLL_TAB_LAYOUT);
setTabLayoutPolicy(WRAP_TAB_LAYOUT);
}
use of javax.swing.KeyStroke in project triplea by triplea-game.
the class JDialogBuilder method build.
/**
* Constructs a Swing JDialog using current builder values.
* Values that must be set: title, contents
*/
public JDialog build() {
checkNotNull(title);
checkNotNull(contents);
final JDialog dialog = new JDialog(parentFrame, title, true);
dialog.getContentPane().add(contents);
final Action closeAction = SwingAction.of("", e -> dialog.setVisible(false));
final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
final String key = "dialog.close";
dialog.getRootPane().getActionMap().put(key, closeAction);
dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key);
return dialog;
}
use of javax.swing.KeyStroke in project logisim-evolution by reds-heig.
the class KeyboardToolSelection method register.
public static void register(Toolbar toolbar) {
ActionMap amap = toolbar.getActionMap();
InputMap imap = toolbar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
int mask = toolbar.getToolkit().getMenuShortcutKeyMask();
for (int i = 0; i < 10; i++) {
KeyStroke keyStroke = KeyStroke.getKeyStroke((char) ('0' + i), mask);
int j = (i == 0 ? 10 : i - 1);
KeyboardToolSelection action = new KeyboardToolSelection(toolbar, j);
String key = "ToolSelect" + i;
amap.put(key, action);
imap.put(keyStroke, key);
}
}
use of javax.swing.KeyStroke in project artisynth_core by artisynth.
the class ReadlinePanel method initializeKeyMap.
private void initializeKeyMap() {
addKeyListener(new MyKeyListener());
InputMap map = getInputMap();
KeyStroke[] keys = map.allKeys();
for (int i = 0; i < keys.length; i++) {
// disable this key binding
map.put(keys[i], "none");
}
}
Aggregations