Search in sources :

Example 11 with RunnableAction

use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.

the class ProjectFrame method newMenuTools.

protected MenuFactory newMenuTools() {
    final MenuFactory tools = new MenuFactory("Tools");
    final MapPanel map = getMapPanel();
    final MeasureOverlay measureOverlay = map.getMapOverlay(MeasureOverlay.class);
    tools.addCheckboxMenuItem("map", new RunnableAction("Measure Length", Icons.getIcon("ruler_line"), () -> measureOverlay.toggleMeasureMode(DataTypes.LINE_STRING)), new ObjectPropertyEnableCheck(measureOverlay, "measureDataType", DataTypes.LINE_STRING));
    tools.addCheckboxMenuItem("map", new RunnableAction("Measure Area", Icons.getIcon("ruler_polygon"), () -> measureOverlay.toggleMeasureMode(DataTypes.POLYGON)), new ObjectPropertyEnableCheck(measureOverlay, "measureDataType", DataTypes.POLYGON));
    tools.addMenuItem("script", "Run Script...", "script_go", this::actionRunScript);
    return tools;
}
Also used : ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) MeasureOverlay(com.revolsys.swing.map.overlay.MeasureOverlay) MenuFactory(com.revolsys.swing.menu.MenuFactory) RunnableAction(com.revolsys.swing.action.RunnableAction)

Example 12 with RunnableAction

use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.

the class SwingUtil method addAction.

static void addAction(final JComponent component, final KeyStroke keyStroke, final String actionKey, final Runnable runnable) {
    final InputMap inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(keyStroke, actionKey);
    final ActionMap actionMap = component.getActionMap();
    final RunnableAction action = new RunnableAction(actionKey, runnable);
    actionMap.put(actionKey, action);
    if (component instanceof JComboBox) {
        final JComboBox comboBox = (JComboBox) component;
        final JComponent editorComponent = (JComponent) comboBox.getEditor().getEditorComponent();
        addAction(editorComponent, keyStroke, actionKey, runnable);
    }
}
Also used : JComboBox(javax.swing.JComboBox) ActionMap(javax.swing.ActionMap) RunnableAction(com.revolsys.swing.action.RunnableAction) JComponent(javax.swing.JComponent) InputMap(javax.swing.InputMap)

Example 13 with RunnableAction

use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.

the class TreeItemScaleMenu method addScaleMenuItem.

protected void addScaleMenuItem(final long layerScale, final JMenu menu, final T object, final long scale) {
    final String label;
    if (scale <= 0) {
        label = "Unlimited";
    } else {
        label = MapScale.formatScale(scale);
    }
    final RunnableAction action = new RunnableAction(label, () -> this.setScaleFunction.accept(object, scale));
    final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(action);
    final boolean selected = scale == layerScale;
    menuItem.setSelected(selected);
    menuItem.setPreferredSize(new Dimension(140, 22));
    menuItem.setHorizontalTextPosition(SwingConstants.RIGHT);
    menu.add(menuItem);
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) Dimension(java.awt.Dimension) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 14 with RunnableAction

use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.

the class LayerRecordMenu method addMenuItem.

public static <V extends Record> RunnableAction addMenuItem(final MenuFactory menu, final String groupName, final int index, final CharSequence name, final String toolTip, final String iconName, final EnableCheck enableCheck, final Consumer<V> consumer) {
    final Icon icon = Icons.getIcon(iconName);
    final RunnableAction action = MenuFactory.newMenuItem(name, toolTip, icon, enableCheck, () -> {
        final V record = getEventRecord();
        if (record != null && consumer != null) {
            consumer.accept(record);
        }
    });
    menu.addComponentFactory(groupName, index, action);
    return action;
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) Icon(javax.swing.Icon)

Example 15 with RunnableAction

use of com.revolsys.swing.action.RunnableAction in project com.revolsys.open by revolsys.

the class TreeNodes method addMenuItem.

static <V extends BaseTreeNode> RunnableAction addMenuItem(final MenuFactory menu, final String groupName, final int index, final CharSequence name, final String iconName, final Predicate<V> enabledFilter, final Consumer<V> consumer) {
    final Icon icon = Icons.getIcon(iconName);
    final EnableCheck enableCheck = enableCheck(enabledFilter);
    final RunnableAction action = new RunnableAction(name, name.toString(), icon, true, () -> {
        final V object = BaseTree.getMenuNode();
        consumer.accept(object);
    });
    action.setEnableCheck(enableCheck);
    menu.addMenuItem(groupName, action);
    return action;
}
Also used : RunnableAction(com.revolsys.swing.action.RunnableAction) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) 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