Search in sources :

Example 41 with Action

use of org.controlsfx.control.action.Action in project qupath by qupath.

the class ScriptTab method initialize.

void initialize() {
    BorderPane panelMainEditor = new BorderPane();
    panelMainEditor.setCenter(editor.getControl());
    ContextMenu popup = new ContextMenu();
    popup.getItems().add(ActionUtils.createMenuItem(new Action("Clear console", e -> console.setText(""))));
    console.setPopup(popup);
    splitEditor = new SplitPane();
    splitEditor.setOrientation(Orientation.VERTICAL);
    splitEditor.getItems().addAll(panelMainEditor, console.getControl());
    SplitPane.setResizableWithParent(console.getControl(), Boolean.FALSE);
    splitEditor.setDividerPosition(0, 0.75);
    updateIsModified();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Action(org.controlsfx.control.action.Action) ContextMenu(javafx.scene.control.ContextMenu) SplitPane(javafx.scene.control.SplitPane)

Example 42 with Action

use of org.controlsfx.control.action.Action in project qupath by qupath.

the class DefaultScriptEditor method createRunProjectScriptAction.

Action createRunProjectScriptAction(final String name, final boolean doSave) {
    Action action = new Action(name, e -> handleRunProject(doSave));
    action.disabledProperty().bind(disableRun.or(qupath.projectProperty().isNull()));
    return action;
}
Also used : Action(org.controlsfx.control.action.Action)

Example 43 with Action

use of org.controlsfx.control.action.Action in project qupath by qupath.

the class QuPathGUI method updateSetAnnotationPathClassMenu.

void updateSetAnnotationPathClassMenu(final ObservableList<MenuItem> menuSetClassItems, final QuPathViewer viewer, final boolean useFancyIcons) {
    // We need a viewer and an annotation, as well as some PathClasses, otherwise we just need to ensure the menu isn't visible
    if (viewer == null || !(viewer.getSelectedObject() instanceof PathAnnotationObject) || availablePathClasses.isEmpty()) {
        menuSetClassItems.clear();
        return;
    }
    PathObject mainPathObject = viewer.getSelectedObject();
    PathClass currentClass = mainPathObject.getPathClass();
    ToggleGroup group = new ToggleGroup();
    List<MenuItem> itemList = new ArrayList<>();
    RadioMenuItem selected = null;
    for (PathClass pathClass : availablePathClasses) {
        PathClass pathClassToSet = pathClass.getName() == null ? null : pathClass;
        String name = pathClass.getName() == null ? "None" : pathClass.toString();
        Action actionSetClass = new Action(name, e -> {
            List<PathObject> changed = new ArrayList<>();
            for (PathObject pathObject : viewer.getAllSelectedObjects()) {
                if (!pathObject.isAnnotation() || pathObject.getPathClass() == pathClassToSet)
                    continue;
                pathObject.setPathClass(pathClassToSet);
                changed.add(pathObject);
            }
            if (!changed.isEmpty())
                viewer.getHierarchy().fireObjectClassificationsChangedEvent(this, changed);
        });
        Node shape;
        if (useFancyIcons) {
            Ellipse r = new Ellipse(TOOLBAR_ICON_SIZE / 2.0, TOOLBAR_ICON_SIZE / 2.0, TOOLBAR_ICON_SIZE, TOOLBAR_ICON_SIZE);
            if ("None".equals(name)) {
                r.setFill(Color.rgb(255, 255, 255, 0.75));
            } else
                r.setFill(ColorToolsFX.getCachedColor(pathClass.getColor()));
            r.setOpacity(0.8);
            DropShadow effect = new DropShadow(6, -3, 3, Color.GRAY);
            r.setEffect(effect);
            shape = r;
        } else {
            Rectangle r = new Rectangle(0, 0, 8, 8);
            r.setFill("None".equals(name) ? Color.TRANSPARENT : ColorToolsFX.getCachedColor(pathClass.getColor()));
            shape = r;
        }
        // actionSetClass.setGraphic(r);
        RadioMenuItem item = ActionUtils.createRadioMenuItem(actionSetClass);
        item.graphicProperty().unbind();
        item.setGraphic(shape);
        item.setToggleGroup(group);
        itemList.add(item);
        if (pathClassToSet == currentClass)
            selected = item;
    }
    group.selectToggle(selected);
    menuSetClassItems.setAll(itemList);
}
Also used : Action(org.controlsfx.control.action.Action) Ellipse(javafx.scene.shape.Ellipse) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) Rectangle(javafx.scene.shape.Rectangle) MenuItem(javafx.scene.control.MenuItem) CheckMenuItem(javafx.scene.control.CheckMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) RadioMenuItem(javafx.scene.control.RadioMenuItem) RadioMenuItem(javafx.scene.control.RadioMenuItem) DropShadow(javafx.scene.effect.DropShadow) PathClass(qupath.lib.objects.classes.PathClass) PathAnnotationObject(qupath.lib.objects.PathAnnotationObject) PathObject(qupath.lib.objects.PathObject) ToggleGroup(javafx.scene.control.ToggleGroup)

Example 44 with Action

use of org.controlsfx.control.action.Action in project qupath by qupath.

the class ActionTools method getAnnotatedActions.

/**
 * Actions can be parsed from the accessible (usually public) fields of any object, as well as methods annotated with {@link ActionMethod}.
 * Any annotations associated with the actions will be parsed.
 *
 * @param obj the object containing the action fields or methods
 * @return a list of parsed and configured actions
 */
public static List<Action> getAnnotatedActions(Object obj) {
    List<Action> actions = new ArrayList<>();
    Class<?> cls = obj instanceof Class<?> ? (Class<?>) obj : obj.getClass();
    // If the class is annotated with a menu, use that as a base; all other menus will be nested within this
    var menuAnnotation = cls.getAnnotation(ActionMenu.class);
    String baseMenu = menuAnnotation == null ? "" : menuAnnotation.value();
    // Get accessible fields corresponding to actions
    for (var f : cls.getDeclaredFields()) {
        if (!f.canAccess(obj))
            continue;
        try {
            var value = f.get(obj);
            if (value instanceof Action) {
                var action = (Action) value;
                parseAnnotations(action, f, baseMenu);
                actions.add(action);
            } else if (value instanceof Action[]) {
                for (var temp : (Action[]) value) {
                    parseAnnotations(temp, f, baseMenu);
                    actions.add(temp);
                }
            }
        } catch (Exception e) {
            logger.error("Error setting up action: {}", e.getLocalizedMessage(), e);
        }
    }
    // Get accessible & annotated methods that may be converted to actions
    for (var m : cls.getDeclaredMethods()) {
        if (!m.isAnnotationPresent(ActionMethod.class) || !m.canAccess(obj))
            continue;
        try {
            Action action = null;
            if (m.getParameterCount() == 0) {
                action = new Action(e -> {
                    try {
                        m.invoke(obj);
                    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
                        logger.error("Error invoking method: " + e1.getLocalizedMessage(), e1);
                    }
                });
            } else {
                logger.warn("Only methods with 0 parameters can currently be converted to actions by annotation only!");
            }
            if (action != null) {
                parseAnnotations(action, m, baseMenu);
                actions.add(action);
            }
        } catch (Exception e) {
            logger.error("Error setting up action: {}", e.getLocalizedMessage(), e);
        }
    }
    return actions;
}
Also used : Button(javafx.scene.control.Button) Action(org.controlsfx.control.action.Action) ActionUtils(org.controlsfx.control.action.ActionUtils) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) KeyCombination(javafx.scene.input.KeyCombination) Map(java.util.Map) Documented(java.lang.annotation.Documented) Tooltip(javafx.scene.control.Tooltip) Logger(org.slf4j.Logger) MenuItem(javafx.scene.control.MenuItem) IconFactory(qupath.lib.gui.tools.IconFactory) ActionTextBehavior(org.controlsfx.control.action.ActionUtils.ActionTextBehavior) Node(javafx.scene.Node) Property(javafx.beans.property.Property) CheckBox(javafx.scene.control.CheckBox) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Field(java.lang.reflect.Field) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) ToggleButton(javafx.scene.control.ToggleButton) ObservableValue(javafx.beans.value.ObservableValue) RetentionPolicy(java.lang.annotation.RetentionPolicy) AnnotatedElement(java.lang.reflect.AnnotatedElement) Action(org.controlsfx.control.action.Action) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 45 with Action

use of org.controlsfx.control.action.Action in project mapton by trixon.

the class XkcdTopComponent method createScene.

private Scene createScene() {
    Action firstAction = new Action(Dict.FIRST.toString(), event -> {
        clear();
        mManager.goFirst();
    });
    firstAction.setGraphic(MaterialIcon._Navigation.FIRST_PAGE.getImageView(getIconSizeToolBarInt()));
    Action previousAction = new Action(Dict.PREVIOUS.toString(), event -> {
        clear();
        mManager.goPrevious();
    });
    previousAction.setGraphic(MaterialIcon._Navigation.CHEVRON_LEFT.getImageView(getIconSizeToolBarInt()));
    Action nextAction = new Action(Dict.NEXT.toString(), event -> {
        clear();
        mManager.goNext();
    });
    nextAction.setGraphic(MaterialIcon._Navigation.CHEVRON_RIGHT.getImageView(getIconSizeToolBarInt()));
    Action lastAction = new Action(Dict.LAST.toString(), event -> {
        clear();
        mManager.goLast();
    });
    lastAction.setGraphic(MaterialIcon._Navigation.LAST_PAGE.getImageView(getIconSizeToolBarInt()));
    Action randomAction = new Action(Dict.RANDOM.toString(), event -> {
        clear();
        mManager.goRandom();
    });
    randomAction.setGraphic(MaterialIcon._Places.CASINO.getImageView(getIconSizeToolBarInt()));
    Action clearAction = new Action(Dict.CLEAR.toString(), event -> {
        clear();
    });
    clearAction.setGraphic(MaterialIcon._Content.CLEAR.getImageView(getIconSizeToolBarInt()));
    List<Action> actions = Arrays.asList(firstAction, previousAction, randomAction, nextAction, lastAction, ActionUtils.ACTION_SPAN, clearAction);
    ToolBar toolBar = ActionUtils.createToolBar(actions, ActionUtils.ActionTextBehavior.HIDE);
    FxHelper.adjustButtonWidth(toolBar.getItems().stream(), getIconSizeToolBarInt());
    toolBar.getItems().stream().filter((item) -> (item instanceof ButtonBase)).map((item) -> (ButtonBase) item).forEachOrdered((buttonBase) -> {
        FxHelper.undecorateButton(buttonBase);
    });
    FxHelper.slimToolBar(toolBar);
    Label titleLabel = Mapton.createTitle(Bundle.CTL_XkcdAction());
    mLogPanel = new LogPanel();
    mLogPanel.setMonospaced();
    mLogPanel.setWrapText(true);
    BorderPane innerPane = new BorderPane(toolBar);
    mRoot = new BorderPane(mLogPanel);
    innerPane.setTop(titleLabel);
    mRoot.setTop(innerPane);
    titleLabel.prefWidthProperty().bind(mRoot.widthProperty());
    return new Scene(mRoot);
}
Also used : TopComponent(org.openide.windows.TopComponent) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) Label(javafx.scene.control.Label) ActionID(org.openide.awt.ActionID) ConvertAsProperties(org.netbeans.api.settings.ConvertAsProperties) ToolBar(javafx.scene.control.ToolBar) ButtonBase(javafx.scene.control.ButtonBase) Action(org.controlsfx.control.action.Action) ActionUtils(org.controlsfx.control.action.ActionUtils) MTopComponent(org.mapton.core.api.MTopComponent) MaterialIcon(se.trixon.almond.util.icons.material.MaterialIcon) ActionReference(org.openide.awt.ActionReference) List(java.util.List) Mapton(org.mapton.api.Mapton) ActionReferences(org.openide.awt.ActionReferences) Dict(se.trixon.almond.util.Dict) Exceptions(org.openide.util.Exceptions) Mapton.getIconSizeToolBarInt(org.mapton.api.Mapton.getIconSizeToolBarInt) BorderPane(javafx.scene.layout.BorderPane) NbBundle(org.openide.util.NbBundle) FxHelper(se.trixon.almond.util.fx.FxHelper) LogPanel(se.trixon.almond.util.fx.control.LogPanel) Action(org.controlsfx.control.action.Action) BorderPane(javafx.scene.layout.BorderPane) LogPanel(se.trixon.almond.util.fx.control.LogPanel) ToolBar(javafx.scene.control.ToolBar) Label(javafx.scene.control.Label) ButtonBase(javafx.scene.control.ButtonBase) Scene(javafx.scene.Scene)

Aggregations

Action (org.controlsfx.control.action.Action)54 BorderPane (javafx.scene.layout.BorderPane)21 ActionUtils (org.controlsfx.control.action.ActionUtils)16 KeyCodeCombination (javafx.scene.input.KeyCodeCombination)15 Arrays (java.util.Arrays)14 Dict (se.trixon.almond.util.Dict)14 MaterialIcon (se.trixon.almond.util.icons.material.MaterialIcon)14 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)12 MenuItem (javafx.scene.control.MenuItem)12 Mapton.getIconSizeToolBarInt (org.mapton.api.Mapton.getIconSizeToolBarInt)12 FxHelper (se.trixon.almond.util.fx.FxHelper)12 Platform (javafx.application.Platform)11 Node (javafx.scene.Node)11 ContextMenu (javafx.scene.control.ContextMenu)11 Label (javafx.scene.control.Label)11 List (java.util.List)10 Insets (javafx.geometry.Insets)10 File (java.io.File)9 ActionEvent (javafx.event.ActionEvent)9