use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.
the class ValueField method showDialog.
@SuppressWarnings("unchecked")
public <V> V showDialog(final Component parent) {
Window window;
if (parent == null) {
window = SwingUtil.getActiveWindow();
} else if (parent instanceof Window) {
window = (Window) parent;
} else {
window = SwingUtilities.windowForComponent(parent);
}
final JDialog dialog = new JDialog(window, this.title, ModalityType.APPLICATION_MODAL);
if (this.iconImage != null) {
dialog.setIconImage(this.iconImage);
}
dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
dialog.setLayout(new BorderLayout());
dialog.addKeyListener(new KeyListener() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
cancel(dialog);
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
save(dialog);
}
}
@Override
public void keyReleased(final KeyEvent e) {
}
@Override
public void keyTyped(final KeyEvent e) {
}
});
dialog.add(this, BorderLayout.CENTER);
final JRootPane rootPane = dialog.getRootPane();
final InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
final ActionMap actionMap = rootPane.getActionMap();
final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final Runnable cancelRunnable = () -> cancel(dialog);
buttons.add(RunnableAction.newButton("Cancel", cancelRunnable));
final KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
inputMap.put(escapeStroke, "cancel");
actionMap.put("cancel", new RunnableAction(cancelRunnable));
final Runnable saveRunnable = () -> save(dialog);
buttons.add(RunnableAction.newButton("OK", saveRunnable));
dialog.add(buttons, BorderLayout.SOUTH);
final KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
inputMap.put(enterStroke, "save");
actionMap.put("save", new RunnableAction(saveRunnable));
dialog.pack();
SwingUtil.autoAdjustPosition(window, dialog);
this.saved = false;
dialog.setVisible(true);
final V value = (V) getFieldValue();
SwingUtil.dispose(dialog);
return value;
}
use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.
the class ProjectFrame method addSaveActions.
public static void addSaveActions(final JComponent component, final Project project) {
final InputMap inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK), SAVE_PROJECT_KEY);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.META_DOWN_MASK), SAVE_PROJECT_KEY);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK), SAVE_CHANGES_KEY);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.META_DOWN_MASK | InputEvent.ALT_DOWN_MASK), SAVE_CHANGES_KEY);
final ActionMap actionMap = component.getActionMap();
actionMap.put(SAVE_PROJECT_KEY, new RunnableAction(SAVE_PROJECT_KEY, project::saveAllSettings));
actionMap.put(SAVE_CHANGES_KEY, new RunnableAction(SAVE_CHANGES_KEY, project::saveChanges));
}
use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.
the class ToolBar method addButton.
public JButton addButton(final String groupName, String title, final String iconName, final EnableCheck enableCheck, final Runnable runnable) {
String name = null;
Icon icon = null;
if (Property.hasValue(iconName)) {
icon = Icons.getIcon(iconName);
} else {
name = title;
title = null;
}
final RunnableAction action = new RunnableAction(name, title, icon, enableCheck, runnable);
return addButton(groupName, action);
}
use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.
the class MenuFactory method addMenuItem.
public void addMenuItem(final String groupName, final String title, final String iconName, final EnableCheck enableCheck, final Runnable runnable) {
final Icon icon = Icons.getIcon(iconName);
final RunnableAction menuItem = newMenuItem(title, title, icon, enableCheck, runnable);
addComponentFactory(groupName, menuItem);
}
use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.
the class MenuFactory method addMenuItemTitleIcon.
public RunnableAction addMenuItemTitleIcon(final String groupName, final CharSequence name, final String iconName, final EnableCheck enableCheck, final Runnable runnable) {
final Icon icon = Icons.getIcon(iconName);
final RunnableAction action = newMenuItem(name, null, icon, enableCheck, runnable);
addComponentFactory(groupName, action);
return action;
}
Aggregations