Search in sources :

Example 21 with Action

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);
    });
}
Also used : Action(org.controlsfx.control.action.Action) ImageRow(qupath.lib.gui.panes.ProjectTreeRow.ImageRow)

Example 22 with Action

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;
}
Also used : StringBinding(javafx.beans.binding.StringBinding) BooleanBinding(javafx.beans.binding.BooleanBinding) Date(java.util.Date) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) KeyCombination(javafx.scene.input.KeyCombination) Future(java.util.concurrent.Future) Task(javafx.concurrent.Task) QuPathGUI(qupath.lib.gui.QuPathGUI) ScriptException(javax.script.ScriptException) PrintWriter(java.io.PrintWriter) Orientation(javafx.geometry.Orientation) SplitPane(javafx.scene.control.SplitPane) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Font(javafx.scene.text.Font) KeyEvent(javafx.scene.input.KeyEvent) GroovyLanguage(qupath.lib.gui.scripting.languages.GroovyLanguage) Collectors(java.util.stream.Collectors) RunnableLanguage(qupath.lib.gui.scripting.languages.RunnableLanguage) Objects(java.util.Objects) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Project(qupath.lib.projects.Project) Clipboard(javafx.scene.input.Clipboard) Writer(java.io.Writer) Optional(java.util.Optional) Toggle(javafx.scene.control.Toggle) Pattern(java.util.regex.Pattern) BorderPane(javafx.scene.layout.BorderPane) LogManager(qupath.lib.gui.logging.LogManager) Scene(javafx.scene.Scene) RadioMenuItem(javafx.scene.control.RadioMenuItem) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) ButtonType(javafx.scene.control.ButtonType) Action(org.controlsfx.control.action.Action) ProgressDialog(org.controlsfx.dialog.ProgressDialog) SimpleScriptContext(javax.script.SimpleScriptContext) Bindings(javafx.beans.binding.Bindings) ProjectDialogs(qupath.lib.gui.dialogs.ProjectDialogs) TransferMode(javafx.scene.input.TransferMode) Projects(qupath.lib.projects.Projects) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Dialogs(qupath.lib.gui.dialogs.Dialogs) ScriptLanguage(qupath.lib.gui.scripting.languages.ScriptLanguage) ActionTools(qupath.lib.gui.ActionTools) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) LinkedHashSet(java.util.LinkedHashSet) ImageData(qupath.lib.images.ImageData) KeyCode(javafx.scene.input.KeyCode) ObjectProperty(javafx.beans.property.ObjectProperty) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Dialog(javafx.scene.control.Dialog) MenuBar(javafx.scene.control.MenuBar) TitledPane(javafx.scene.control.TitledPane) ProjectImageEntry(qupath.lib.projects.ProjectImageEntry) GeneralTools(qupath.lib.common.GeneralTools) Node(javafx.scene.Node) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) MenuTools(qupath.lib.gui.tools.MenuTools) File(java.io.File) ScriptContext(javax.script.ScriptContext) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) ScriptLanguageProvider(qupath.lib.gui.scripting.languages.ScriptLanguageProvider) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) PlainLanguage(qupath.lib.gui.scripting.languages.PlainLanguage) PathPrefs(qupath.lib.gui.prefs.PathPrefs) DialogButton(qupath.lib.gui.dialogs.Dialogs.DialogButton) Action(org.controlsfx.control.action.Action) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) IOException(java.io.IOException)

Example 23 with 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;
}
Also used : Action(org.controlsfx.control.action.Action) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) File(java.io.File) ScriptException(javax.script.ScriptException) IOException(java.io.IOException)

Example 24 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 25 with Action

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;
}
Also used : Action(org.controlsfx.control.action.Action) KeyCodeCombination(javafx.scene.input.KeyCodeCombination)

Aggregations

Action (org.controlsfx.control.action.Action)31 KeyCodeCombination (javafx.scene.input.KeyCodeCombination)13 BorderPane (javafx.scene.layout.BorderPane)10 File (java.io.File)7 MenuItem (javafx.scene.control.MenuItem)7 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Button (javafx.scene.control.Button)6 KeyCode (javafx.scene.input.KeyCode)6 Stage (javafx.stage.Stage)6 ActionUtils (org.controlsfx.control.action.ActionUtils)6 List (java.util.List)5 Node (javafx.scene.Node)5 ButtonType (javafx.scene.control.ButtonType)5 ContextMenu (javafx.scene.control.ContextMenu)5 Label (javafx.scene.control.Label)5 Menu (javafx.scene.control.Menu)5 Tooltip (javafx.scene.control.Tooltip)5 KeyCombination (javafx.scene.input.KeyCombination)5