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();
}
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;
}
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);
}
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;
}
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);
}
Aggregations