From 53a2fb73ddbaacc74e5d3c896df4f5945a72413e Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 1 Mar 2024 16:17:26 +0000 Subject: [PATCH] Fix grid views to show without measurements Fixes https://github.com/qupath/qupath/issues/1472 Also speeds up the animations a bit (as they were quite sluggish) and sets a 'No measurements!' placeholder in the combo box when there are no measurements available. --- .../lib/gui/commands/PathObjectGridView.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/qupath-gui-fx/src/main/java/qupath/lib/gui/commands/PathObjectGridView.java b/qupath-gui-fx/src/main/java/qupath/lib/gui/commands/PathObjectGridView.java index af7347a84..d1f901142 100644 --- a/qupath-gui-fx/src/main/java/qupath/lib/gui/commands/PathObjectGridView.java +++ b/qupath-gui-fx/src/main/java/qupath/lib/gui/commands/PathObjectGridView.java @@ -211,9 +211,10 @@ private static List getAnnotations(PathObjectHierarchy hierarchy) { * @return */ public Stage getStage() { - if (stage == null) + if (stage == null) { initializeGUI(); stage.setWidth(600); + } return stage; } @@ -306,9 +307,7 @@ private void initializeData(ImageData imageData) { String m = measurement.getValue(); sortPathObjects(backingList, model, m, descending.get()); - filteredList.setPredicate(p -> { - return !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m))); - }); + filteredList.setPredicate(p -> m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m)))); grid.getItems().setAll(filteredList); // Select the first measurement if necessary @@ -345,6 +344,7 @@ private void initializeGUI() { comboMeasurement = new ComboBox<>(); + comboMeasurement.setPlaceholder(createPlaceholderText("No measurements!")); comboMeasurement.setItems(model.getMeasurementNames()); if (!comboMeasurement.getItems().isEmpty()) comboMeasurement.getSelectionModel().select(0); @@ -375,14 +375,7 @@ private void initializeGUI() { CheckBox cbShowMeasurement = new CheckBox("Show measurement"); showMeasurement.bind(cbShowMeasurement.selectedProperty()); - showMeasurement.addListener(c -> { - String m = measurement.getValue(); - sortPathObjects(backingList, model, m, descending.get()); - filteredList.setPredicate(p -> { - return m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m))); - }); - grid.getItems().setAll(filteredList); - }); // Force an update + showMeasurement.addListener(c -> updateMeasurement()); // Force an update CheckBox cbAnimation = new CheckBox("Animate"); @@ -440,6 +433,14 @@ private void initializeGUI() { stage.setOnShowing(e -> refresh()); stage.show(); } + + + private void updateMeasurement() { + String m = measurement.getValue(); + sortPathObjects(backingList, model, m, descending.get()); + filteredList.setPredicate(p -> m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m)))); + grid.getItems().setAll(filteredList); + } /** @@ -479,8 +480,13 @@ public void hierarchyChanged(PathObjectHierarchyEvent event) { requestUpdate(imageData); } } - - + + + private static Text createPlaceholderText(String text) { + var textNode = new Text(text); + textNode.setStyle("-fx-fill: -fx-text-base-color;"); + return textNode; + } class QuPathGridView extends StackPane { @@ -490,7 +496,7 @@ class QuPathGridView extends StackPane { private IntegerProperty imageSize = new SimpleIntegerProperty(); - private Text textEmpty = new Text("No objects available!"); + private Text textEmpty = createPlaceholderText("No objects available!"); QuPathGridView() { imageSize.addListener(v -> { @@ -503,7 +509,6 @@ public void onChanged(javafx.collections.ListChangeListener.Change