use of javax.swing.InputMap in project smile by haifengl.
the class PlotCanvas method createPropertyDialog.
/**
* Creates the property dialog.
* @return the property dialog.
*/
private JDialog createPropertyDialog() {
Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
JDialog dialog = new JDialog(frame, "Plot Properties", true);
Action okAction = new PropertyDialogOKAction(dialog);
Action cancelAction = new PropertyDialogCancelAction(dialog);
JButton okButton = new JButton(okAction);
JButton cancelButton = new JButton(cancelAction);
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
ActionMap actionMap = buttonsPanel.getActionMap();
actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
String[] columnNames = { "Property", "Value" };
if (base.dimension == 2) {
Object[][] data = { { "Title", title }, { "Title Font", titleFont }, { "Title Color", titleColor }, { "X Axis Title", getAxis(0).getAxisLabel() }, { "X Axis Range", new double[] { base.getLowerBounds()[0], base.getUpperBounds()[0] } }, { "Y Axis Title", getAxis(1).getAxisLabel() }, { "Y Axis Range", new double[] { base.getLowerBounds()[1], base.getUpperBounds()[1] } } };
propertyTable = new Table(data, columnNames);
} else {
Object[][] data = { { "Title", title }, { "Title Font", titleFont }, { "Title Color", titleColor }, { "X Axis Title", getAxis(0).getAxisLabel() }, { "X Axis Range", new double[] { base.getLowerBounds()[0], base.getUpperBounds()[0] } }, { "Y Axis Title", getAxis(1).getAxisLabel() }, { "Y Axis Range", new double[] { base.getLowerBounds()[1], base.getUpperBounds()[1] } }, { "Z Axis Title", getAxis(2).getAxisLabel() }, { "Z Axis Range", new double[] { base.getLowerBounds()[2], base.getUpperBounds()[2] } } };
propertyTable = new Table(data, columnNames);
}
// There is a known issue with JTables whereby the changes made in a
// cell editor are not committed when focus is lost.
// This can result in the table staying in 'edit mode' with the stale
// value in the cell being edited still showing, although the change
// has not actually been committed to the model.
//
// In fact what should happen is for the method stopCellEditing()
// on CellEditor to be called when focus is lost.
// So the editor can choose whether to accept the new value and stop
// editing, or have the editing cancelled without committing.
// There is a magic property which you have to set on the JTable
// instance to turn this feature on.
propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
propertyTable.setFillsViewportHeight(true);
JScrollPane tablePanel = new JScrollPane(propertyTable);
dialog.getContentPane().add(tablePanel, BorderLayout.CENTER);
dialog.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
dialog.pack();
dialog.setLocationRelativeTo(frame);
return dialog;
}
use of javax.swing.InputMap in project binnavi by google.
the class JHexView method initHotkeys.
/**
* Initializes the keys that can be used by the user inside the component.
*/
private void initHotkeys() {
// Don't change focus on TAB
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<KeyStroke>());
final InputMap inputMap = this.getInputMap();
final ActionMap actionMap = getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LEFT");
actionMap.put("LEFT", m_leftAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_DOWN_MASK), "shift LEFT");
actionMap.put("shift LEFT", m_leftAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RIGHT");
actionMap.put("RIGHT", m_rightAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_DOWN_MASK), "shift RIGHT");
actionMap.put("shift RIGHT", m_rightAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "UP");
actionMap.put("UP", m_upAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_DOWN_MASK), "shift UP");
actionMap.put("shift UP", m_upAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "DOWN");
actionMap.put("DOWN", m_downAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_DOWN_MASK), "shift DOWN");
actionMap.put("shift DOWN", m_downAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PAGE_DOWN");
actionMap.put("PAGE_DOWN", m_pageDownAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.SHIFT_DOWN_MASK), "shift PAGE_DOWN");
actionMap.put("shift PAGE_DOWN", m_pageDownAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PAGE_UP");
actionMap.put("PAGE_UP", m_pageUpAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK), "shift PAGE_UP");
actionMap.put("shift PAGE_UP", m_pageUpAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "TAB");
actionMap.put("TAB", m_tabAction);
}
use of javax.swing.InputMap in project binnavi by google.
the class CGraphToolBar method addHotkey.
/**
* Adds a hotkey to a button.
*
* @param button The button the hotkey is added to.
* @param keyStroke The hotkey keystroke.
* @param action Action to be executed on the keystroke.
* @param name Name of the action.
*/
private static void addHotkey(final JButton button, final KeyStroke keyStroke, final AbstractAction action, final String name) {
final InputMap windowImap = button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
windowImap.put(keyStroke, name);
button.getActionMap().put(name, action);
}
use of javax.swing.InputMap in project binnavi by google.
the class GuiInitializer method initializeHotkeys.
/**
* This function unregisters the keys F6 and F8 from JSplitPane components because we would rather
* uses these keys for debugger functions.
*/
private static void initializeHotkeys() {
final InputMap map = (InputMap) UIManager.get("SplitPane.ancestorInputMap");
map.remove(HotKeys.GUI_INITIALIZER_KEY_1.getKeyStroke());
map.remove(HotKeys.GUI_INITIALIZER_KEY_2.getKeyStroke());
}
use of javax.swing.InputMap in project jdk8u_jdk by JetBrains.
the class Test8013370 method run.
@Override
public void run() {
if (this.frame == null) {
JMenuBar menu = new JMenuBar() {
@Override
protected boolean processKeyBinding(KeyStroke stroke, KeyEvent event, int condition, boolean pressed) {
if (stroke == null) {
Test8013370.this.error = true;
return false;
}
return super.processKeyBinding(stroke, event, condition, pressed);
}
};
menu.add(new JMenuItem("Menu"));
InputMap map = menu.getInputMap(WHEN_IN_FOCUSED_WINDOW);
// from a array to a hashtable when more than 8 values are added.
for (int i = 0; i < 9; i++) {
String name = " Action #" + i;
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A + i, CTRL_DOWN_MASK), name);
menu.getActionMap().put(name, new AbstractAction(name) {
@Override
public void actionPerformed(ActionEvent event) {
showMessageDialog(null, getValue(NAME));
}
});
}
this.frame = new JFrame("8013370");
this.frame.setJMenuBar(menu);
this.frame.setVisible(true);
} else {
this.frame.dispose();
}
}
Aggregations