Skip to content

Commit

Permalink
Merge pull request #6 from finglis/UI-update
Browse files Browse the repository at this point in the history
UI Select all button update
  • Loading branch information
finglis authored Feb 19, 2024
2 parents f1c5070 + 23a61f9 commit 320f8d4
Showing 4 changed files with 50 additions and 30 deletions.
52 changes: 36 additions & 16 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegController.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.util.StringConverter;
@@ -62,7 +63,6 @@ public class InstanSegController extends BorderPane {
private static final Logger logger = LoggerFactory.getLogger(InstanSegController.class);
private static final ResourceBundle resources = ResourceBundle.getBundle("qupath.ext.instanseg.ui.strings");


@FXML
private VBox vBox;
private final Watcher watcher = new Watcher();
@@ -87,7 +87,9 @@ public VBox getVBox() {
@FXML
private Spinner<Integer> threadSpinner;
@FXML
private Button selectAllAnnotationsButton;
private ToggleButton selectAllAnnotationsButton;
@FXML
private ToggleButton selectAllTMACoresButton;

private final ExecutorService pool = Executors.newSingleThreadExecutor(ThreadTools.createThreadFactory("wsinfer", true));
private final QuPathGUI qupath = QuPathGUI.getInstance();
@@ -105,22 +107,28 @@ private InstanSegController() throws IOException {
loader.setController(this);
loader.load();
configureMessageLabel();
configureTileSizes();
addListeners();
configureDeviceChoices();
configureSelectButtons();
}

private void configureTileSizes() {
tileSizeChoiceBox.getItems().addAll(128, 256, 512, 1024);
tileSizeChoiceBox.getSelectionModel().select(Integer.valueOf(256));
addListeners();
configureAvailableDevices();
modelChoiceBox.setConverter(new StringConverter<>() {
@Override
public String toString(Path object) {
if (object == null) return null;
return object.getFileName().toString();
}
}

@Override
public Path fromString(String string) {
return Path.of(InstanSegPreferences.modelDirectoryProperty().get(), string);
}
});
private void configureSelectButtons() {
selectAllAnnotationsButton.disableProperty().bind(qupath.imageDataProperty().isNull());
selectAllTMACoresButton.disableProperty().bind(qupath.imageDataProperty().isNull());
overrideToggleSelected(selectAllAnnotationsButton);
overrideToggleSelected(selectAllTMACoresButton);
}

// Hack to prevent the toggle buttons from staying selected
// This allows us to use a segmented button with the appearance of regular, non-toggle buttons
private static void overrideToggleSelected(ToggleButton button) {
button.selectedProperty().addListener((value, oldValue, newValue) -> button.setSelected(false));
}

public void interrupt() {
@@ -162,7 +170,7 @@ private void handleModelDirectory(String n) {
tryToPopulateChoiceBox(n);
}

private void configureAvailableDevices() {
private void configureDeviceChoices() {
var available = PytorchManager.getAvailableDevices();
deviceChoices.getItems().setAll(available);
var selected = InstanSegPreferences.preferredDeviceProperty().get();
@@ -175,6 +183,18 @@ private void configureAvailableDevices() {
// changed elsewhere
deviceChoices.getSelectionModel().selectedItemProperty().addListener(
(value, oldValue, newValue) -> InstanSegPreferences.preferredDeviceProperty().set(newValue));
modelChoiceBox.setConverter(new StringConverter<>() {
@Override
public String toString(Path object) {
if (object == null) return null;
return object.getFileName().toString();
}

@Override
public Path fromString(String string) {
return Path.of(InstanSegPreferences.modelDirectoryProperty().get(), string);
}
});
}

private void configureMessageLabel() {
5 changes: 0 additions & 5 deletions src/main/resources/qupath/ext/instanseg/ui/instanseg.css
Original file line number Diff line number Diff line change
@@ -45,11 +45,6 @@
-fx-padding: 2;
}

/*download button*/
/*.download-btn {
-fx-background-image: url("icons/download.png");
}*/

.fa-icon {
-fx-font-family: FontAwesome;
-fx-font-size: 14px;
19 changes: 12 additions & 7 deletions src/main/resources/qupath/ext/instanseg/ui/instanseg_control.fxml
Original file line number Diff line number Diff line change
@@ -48,13 +48,18 @@
<children>
<Label styleClass="regular" text="%ui.selection.label" />
<Label alignment="CENTER" styleClass="instanseg-sub-title" text="%ui.selection.alt" textAlignment="CENTER" />
<HBox>
<Button maxWidth="500" fx:id="toggleSelectAllDetections" mnemonicParsing="false" text="%ui.selection.all-annotations" onAction="#selectAllAnnotations">
<tooltip><Tooltip text="%ui.selection.all-annotations.tooltip" /></tooltip>
</Button>
<Button maxWidth="500" fx:id="toggleSelectAllTMACores" mnemonicParsing="false" text="%ui.selection.all-TMA-cores" onAction="#selectAllTMACores">
<tooltip><Tooltip text="%ui.selection.all-TMA-cores.tooltip" /></tooltip>
</Button>
<HBox alignment="CENTER" styleClass="standard-spacing">
<Label styleClass="regular" text="%ui.selection.sub-label" />
<SegmentedButton fx:id="segButton" maxWidth="500">
<buttons>
<ToggleButton fx:id="selectAllAnnotationsButton" onAction="#selectAllAnnotations" text="%ui.selection.all-annotations">
<tooltip><Tooltip text="%ui.selection.all-annotations.tooltip" /></tooltip>
</ToggleButton>
<ToggleButton fx:id="selectAllTMACoresButton" onAction="#selectAllTMACores" text="%ui.selection.all-TMA-cores">
<tooltip><Tooltip text="%ui.selection.all-TMA-cores.tooltip" /></tooltip>
</ToggleButton>
</buttons>
</SegmentedButton>
</HBox>
</children>
</VBox>
4 changes: 2 additions & 2 deletions src/main/resources/qupath/ext/instanseg/ui/strings.properties
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@ ui.model.info.tooltip = Show model description and citation
ui.selection.label = Create or select annotation(s) or TMA core(s)
ui.selection.alt = or
ui.selection.sub-label = Select all
ui.selection.all-annotations = Select all annotations
ui.selection.all-annotations = Annotations
ui.selection.all-annotations.tooltip = Selects all annotations in current image - tiles will be generated within these annotations
ui.selection.all-TMA-cores = Select all TMA cores
ui.selection.all-TMA-cores = TMA cores
ui.selection.all-TMA-cores.tooltip = Selects all TMA cores in current image - tiles will be generated within these cores

ui.run = Run

0 comments on commit 320f8d4

Please sign in to comment.