Search in sources :

Example 1 with CheckListView

use of org.controlsfx.control.CheckListView in project qupath by qupath.

the class Commands method promptToAddShapeFeatures.

/**
 * Prompt to add shape features for selected objects.
 * @param qupath current QuPath instance
 */
public static void promptToAddShapeFeatures(QuPathGUI qupath) {
    var listView = new CheckListView<ShapeFeatures>();
    listView.getItems().setAll(ShapeFeatures.values());
    listView.getCheckModel().checkAll();
    // This is to work around a bug in ControlsFX 11.0.1 that can throw a NPE if the parent is unavailable
    listView.setCellFactory(view -> {
        var cell = new CheckBoxListCell<ShapeFeatures>(item -> listView.getItemBooleanProperty(item));
        cell.focusedProperty().addListener((o, ov, nv) -> {
            if (nv) {
                var parent = cell.getParent();
                if (parent != null)
                    parent.requestFocus();
            }
        });
        return cell;
    });
    listView.setPrefHeight(Math.min(listView.getItems().size() * 30, 320));
    var pane = new BorderPane(listView);
    listView.setTooltip(new Tooltip("Choose shape features"));
    var label = new Label("Add shape features to selected objects.\nNote that not all measurements are compatible with all objects.");
    label.setTextAlignment(TextAlignment.CENTER);
    label.setPadding(new Insets(10));
    pane.setTop(label);
    var btnSelectAll = new Button("Select all");
    btnSelectAll.setOnAction(e -> listView.getCheckModel().checkAll());
    var btnSelectNone = new Button("Select none");
    btnSelectNone.setOnAction(e -> listView.getCheckModel().clearChecks());
    btnSelectAll.setMaxWidth(Double.MAX_VALUE);
    btnSelectNone.setMaxWidth(Double.MAX_VALUE);
    pane.setBottom(PaneTools.createColumnGrid(btnSelectAll, btnSelectNone));
    var dialog = Dialogs.builder().title("Shape features").content(pane).modality(Modality.NONE).buttons(ButtonType.APPLY, ButtonType.CANCEL).build();
    var btnApply = (Button) dialog.getDialogPane().lookupButton(ButtonType.APPLY);
    btnApply.disableProperty().bind(qupath.imageDataProperty().isNull());
    btnApply.setOnAction(e -> requestShapeFeatures(qupath.getImageData(), listView.getCheckModel().getCheckedItems()));
    dialog.show();
// var result = dialog.showAndWait();
// if (result.orElse(ButtonType.CANCEL) == ButtonType.APPLY)
// requestShapeFeatures(qupath.getImageData(), listView.getSelectionModel().getSelectedItems());
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) Button(javafx.scene.control.Button) DialogButton(qupath.lib.gui.dialogs.Dialogs.DialogButton) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) CheckListView(org.controlsfx.control.CheckListView)

Example 2 with CheckListView

use of org.controlsfx.control.CheckListView in project qupath by qupath.

the class CreateChannelTrainingImagesCommand method run.

@Override
public void run() {
    var project = qupath.getProject();
    var imageData = qupath.getImageData();
    var entry = project != null && imageData != null ? project.getEntry(imageData) : null;
    if (entry == null) {
        Dialogs.showErrorMessage(title, "This command requires an open image within a project!");
        return;
    }
    var channels = new ArrayList<>(imageData.getServer().getMetadata().getChannels());
    var list = new CheckListView<ImageChannel>();
    list.getItems().setAll(channels);
    list.getCheckModel().checkAll();
    list.setCellFactory(v -> new CheckBoxListCell<>(item -> list.getItemBooleanProperty(item)) {

        @Override
        public void updateItem(ImageChannel item, boolean empty) {
            super.updateItem(item, empty);
            if (item == null || empty) {
                setText(null);
                return;
            }
            setText(item.getName());
        }
    });
    var label = new Label("Create duplicate images for each of the following channels?");
    if (channels.size() == 1)
        label.setText("Create a duplicate image for the one and only channel?");
    var labelName = new Label("Root name");
    var tfName = new TextField(entry.getImageName().trim());
    labelName.setLabelFor(tfName);
    String namePrompt = "Enter root image name for duplicate images";
    tfName.setPromptText(namePrompt);
    tfName.setTooltip(new Tooltip(namePrompt));
    var cbInitializePoints = new CheckBox("Initialize Points annotations");
    var pane = new GridPane();
    int row = 0;
    PaneTools.addGridRow(pane, row++, 0, null, label, label);
    PaneTools.addGridRow(pane, row++, 0, namePrompt, labelName, tfName);
    PaneTools.addGridRow(pane, row++, 0, "Channels to duplicate", list, list);
    PaneTools.addGridRow(pane, row++, 0, "Create Points annotations for the corresponding channel", cbInitializePoints, cbInitializePoints);
    PaneTools.setFillWidth(Boolean.TRUE, label, tfName, list, cbInitializePoints);
    PaneTools.setHGrowPriority(Priority.ALWAYS, label, tfName, list, cbInitializePoints);
    PaneTools.setVGrowPriority(Priority.ALWAYS, list);
    PaneTools.setMaxWidth(Double.MAX_VALUE, label, tfName, list, cbInitializePoints);
    list.setPrefHeight(240);
    pane.setHgap(5.0);
    pane.setVgap(5.0);
    if (!Dialogs.showConfirmDialog(title, pane))
        return;
    var name = tfName.getText().trim();
    boolean initializePoints = cbInitializePoints.isSelected();
    try {
        for (var channel : list.getCheckModel().getCheckedItems()) {
            var entry2 = project.addDuplicate(entry, true);
            String channelName = channel.getName();
            entry2.setImageName(name.trim() + " - " + channelName);
            if (initializePoints) {
                var imageData2 = entry2.readImageData();
                imageData2.getHierarchy().addPathObjects(Arrays.asList(PathObjects.createAnnotationObject(ROIs.createPointsROI(ImagePlane.getDefaultPlane()), PathClassFactory.getPathClass(channelName, channel.getColor())), PathObjects.createAnnotationObject(ROIs.createPointsROI(ImagePlane.getDefaultPlane()), PathClassFactory.getPathClass(PathClassFactory.StandardPathClasses.IGNORE))));
                entry2.saveImageData(imageData2);
            }
        }
        project.syncChanges();
    } catch (Exception e) {
        Dialogs.showErrorMessage(title, e);
    }
    qupath.refreshProject();
}
Also used : Arrays(java.util.Arrays) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) PathObjects(qupath.lib.objects.PathObjects) CheckBox(javafx.scene.control.CheckBox) ImageChannel(qupath.lib.images.servers.ImageChannel) PathClassFactory(qupath.lib.objects.classes.PathClassFactory) ArrayList(java.util.ArrayList) Dialogs(qupath.lib.gui.dialogs.Dialogs) CheckListView(org.controlsfx.control.CheckListView) Priority(javafx.scene.layout.Priority) ROIs(qupath.lib.roi.ROIs) ImagePlane(qupath.lib.regions.ImagePlane) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) QuPathGUI(qupath.lib.gui.QuPathGUI) PaneTools(qupath.lib.gui.tools.PaneTools) GridPane(javafx.scene.layout.GridPane) Tooltip(javafx.scene.control.Tooltip) ArrayList(java.util.ArrayList) Label(javafx.scene.control.Label) CheckListView(org.controlsfx.control.CheckListView) CheckBox(javafx.scene.control.CheckBox) ImageChannel(qupath.lib.images.servers.ImageChannel) TextField(javafx.scene.control.TextField)

Aggregations

Label (javafx.scene.control.Label)2 Tooltip (javafx.scene.control.Tooltip)2 CheckBoxListCell (javafx.scene.control.cell.CheckBoxListCell)2 CheckListView (org.controlsfx.control.CheckListView)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 CheckBox (javafx.scene.control.CheckBox)1 TextField (javafx.scene.control.TextField)1 BorderPane (javafx.scene.layout.BorderPane)1 GridPane (javafx.scene.layout.GridPane)1 Priority (javafx.scene.layout.Priority)1 QuPathGUI (qupath.lib.gui.QuPathGUI)1 Dialogs (qupath.lib.gui.dialogs.Dialogs)1 DialogButton (qupath.lib.gui.dialogs.Dialogs.DialogButton)1 PaneTools (qupath.lib.gui.tools.PaneTools)1 ImageChannel (qupath.lib.images.servers.ImageChannel)1 PathObjects (qupath.lib.objects.PathObjects)1 PathClassFactory (qupath.lib.objects.classes.PathClassFactory)1