Skip to content

Commit

Permalink
Fix grid views to show without measurements
Browse files Browse the repository at this point in the history
Fixes qupath#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.
  • Loading branch information
petebankhead committed Mar 1, 2024
1 parent a91e721 commit 53a2fb7
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ private static List<PathObject> getAnnotations(PathObjectHierarchy hierarchy) {
* @return
*/
public Stage getStage() {
if (stage == null)
if (stage == null) {
initializeGUI();
stage.setWidth(600);
}
return stage;
}

Expand Down Expand Up @@ -306,9 +307,7 @@ private void initializeData(ImageData<BufferedImage> 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}


/**
Expand Down Expand Up @@ -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 {

Expand All @@ -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 -> {
Expand All @@ -503,7 +509,6 @@ public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pat
}
});
updateChildren();
textEmpty.setStyle("-fx-fill: -fx-text-base-color;");
StackPane.setAlignment(textEmpty, Pos.CENTER);
}

Expand Down Expand Up @@ -603,15 +608,15 @@ protected void layoutChildren() {
TranslateTransition translate = translationMap.get(node);
boolean doChanges = false;
if (translate == null) {
translate = new TranslateTransition(Duration.seconds(0.5));
translate = new TranslateTransition(Duration.seconds(0.25));
translate.setNode(node);
translationMap.put(node, translate);
doChanges = true;
} else {
if (!GeneralTools.almostTheSame(x, translate.getToX(), 0.001)
|| !GeneralTools.almostTheSame(y, translate.getToY(), 0.001)) {
translate.stop();
translate.setDuration(Duration.seconds(0.5));
translate.setDuration(Duration.seconds(0.25));
doChanges = true;
}
}
Expand Down

0 comments on commit 53a2fb7

Please sign in to comment.