Search in sources :

Example 1 with RunnableAction

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;
}
Also used : Window(java.awt.Window) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionMap(javax.swing.ActionMap) RunnableAction(com.revolsys.swing.action.RunnableAction) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) KeyStroke(javax.swing.KeyStroke) KeyListener(java.awt.event.KeyListener) JRootPane(javax.swing.JRootPane) InputMap(javax.swing.InputMap) JDialog(javax.swing.JDialog)

Example 2 with RunnableAction

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));
}
Also used : ActionMap(javax.swing.ActionMap) RunnableAction(com.revolsys.swing.action.RunnableAction) InputMap(javax.swing.InputMap)

Example 3 with RunnableAction

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);
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) Icon(javax.swing.Icon)

Example 4 with RunnableAction

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);
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) Icon(javax.swing.Icon)

Example 5 with RunnableAction

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;
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) Icon(javax.swing.Icon)

Aggregations

RunnableAction (com.revolsys.swing.action.RunnableAction)19 Icon (javax.swing.Icon)10 ActionMap (javax.swing.ActionMap)4 InputMap (javax.swing.InputMap)4 EnableCheck (com.revolsys.swing.action.enablecheck.EnableCheck)2 JComponent (javax.swing.JComponent)2 KeyStroke (javax.swing.KeyStroke)2 ObjectPropertyEnableCheck (com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck)1 MeasureOverlay (com.revolsys.swing.map.overlay.MeasureOverlay)1 MenuFactory (com.revolsys.swing.menu.MenuFactory)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Window (java.awt.Window)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 ButtonGroup (javax.swing.ButtonGroup)1 JButton (javax.swing.JButton)1 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1 JComboBox (javax.swing.JComboBox)1