use of org.controlsfx.control.action.Action in project qupath by qupath.
the class ProjectBrowser method createSortByKeyAction.
private Action createSortByKeyAction(final String name, final String key) {
return new Action(name, e -> {
if (model == null)
return;
model.setMetadataKey(key);
ImageRow selectedImageRow = getSelectedImageRow();
refreshTree(selectedImageRow);
});
}
use of org.controlsfx.control.action.Action in project qupath by qupath.
the class DefaultScriptEditor method createInsertAction.
Action createInsertAction(final String name) {
Action action = new Action(name, e -> {
var control = getCurrentTextComponent();
String join = "," + System.lineSeparator() + " ";
String listFormat = "[" + System.lineSeparator() + " %s" + System.lineSeparator() + "]";
if (name.toLowerCase().equals("pixel classifiers")) {
try {
String classifiers = qupath.getProject().getPixelClassifiers().getNames().stream().map(classifierName -> "\"" + classifierName + "\"").collect(Collectors.joining(join));
String s = classifiers.isEmpty() ? "[]" : String.format(listFormat, classifiers);
control.paste(s);
} catch (IOException ex) {
logger.error("Could not fetch classifiers", ex.getLocalizedMessage());
}
} else if (name.toLowerCase().equals("object classifiers")) {
try {
String classifiers = qupath.getProject().getObjectClassifiers().getNames().stream().map(classifierName -> "\"" + classifierName + "\"").collect(Collectors.joining(join));
String s = classifiers.isEmpty() ? "[]" : String.format(listFormat, classifiers);
control.paste(s);
} catch (IOException ex) {
logger.error("Could not fetch classifiers", ex.getLocalizedMessage());
}
} else if (name.toLowerCase().equals("detection")) {
var imageData = qupath.getImageData();
String measurements = "";
if (imageData != null) {
measurements = imageData.getHierarchy().getDetectionObjects().stream().flatMap(d -> d.getMeasurementList().getMeasurementNames().stream()).distinct().map(m -> "\"" + m + "\"").collect(Collectors.joining(join));
}
String s = measurements.isEmpty() ? "[]" : String.format(listFormat, measurements);
control.paste(s);
} else if (name.toLowerCase().equals(GeneralTools.SYMBOL_MU + ""))
control.paste(GeneralTools.SYMBOL_MU + "");
else {
// TODO: fix
// // Imports (end with a new line)
// if (name.toLowerCase().equals("qpex"))
// control.insertText(0, "import static qupath.lib.gui.scripting.QPEx.*");
// else if (name.toLowerCase().equals("qp"))
// control.insertText(0, "import static qupath.lib.gui.scripting.QP.*");
// else if (name.toLowerCase().equals("all default"))
// control.insertText(0, QPEx.getDefaultImports(false));
// currentLanguage.get().getSyntax().handleNewLine(control, smartEditing.get());
}
e.consume();
});
if (name.equals(GeneralTools.SYMBOL_MU + ""))
action.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
else if (name.toLowerCase().equals("pixel classifiers") || name.toLowerCase().equals("object classifiers"))
action.disabledProperty().bind(qupath.projectProperty().isNull());
else if (name.toLowerCase().equals("detection"))
action.disabledProperty().bind(qupath.imageDataProperty().isNull());
return action;
}
use of org.controlsfx.control.action.Action in project qupath by qupath.
the class DefaultScriptEditor method createOpenAction.
Action createOpenAction(final String name) {
Action action = new Action(name, e -> {
String dirPath = PathPrefs.scriptsPathProperty().get();
File dir = null;
if (dirPath != null)
dir = new File(dirPath);
// File file = Dialogs.promptForFile("Choose script file", dir, "Known script files", SCRIPT_EXTENSIONS);
File file = Dialogs.promptForFile("Choose script file", dir, "Groovy script", ".groovy");
if (file == null)
return;
try {
addScript(file, true);
PathPrefs.scriptsPathProperty().set(file.getParent());
} catch (Exception ex) {
logger.error("Unable to open script file: {}", ex);
ex.printStackTrace();
}
});
action.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
return 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();
}
use of org.controlsfx.control.action.Action in project qupath by qupath.
the class DefaultScriptEditor method createFindAction.
Action createFindAction(final String name) {
ScriptFindCommand findCommand = new ScriptFindCommand(this);
Action action = new Action(name, e -> {
findCommand.run();
e.consume();
});
action.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN));
return action;
}
Aggregations