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