Skip to content

Commit

Permalink
Directory functionality (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Alan O'Callaghan <[email protected]>
  • Loading branch information
finglis and alanocallaghan authored Apr 16, 2024
1 parent cf897ee commit 15ef5e1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
46 changes: 43 additions & 3 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import org.controlsfx.control.CheckComboBox;
import org.controlsfx.control.SearchableComboBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import qupath.ext.instanseg.core.InstanSegModel;
import qupath.ext.instanseg.core.InstanSegTask;
import qupath.fx.dialogs.FileChoosers;
import qupath.fx.utils.FXUtils;
import qupath.lib.common.ThreadTools;
import qupath.lib.display.ChannelDisplayInfo;
import qupath.lib.gui.QuPathGUI;
import qupath.lib.gui.tools.GuiTools;
import qupath.lib.images.ImageData;
import qupath.lib.images.servers.ColorTransforms;
import qupath.lib.images.servers.ImageServer;
Expand All @@ -43,6 +46,7 @@
import qupath.lib.scripting.QP;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down Expand Up @@ -204,7 +208,6 @@ private static Collection<String> getAvailableUniqueChannelNames(ImageServer<?>
}



private static String getTitle(CheckComboBox<ColorTransforms.ColorTransform> comboBox) {
int n = comboBox.getCheckModel().getCheckedItems().size();
if (n == 0)
Expand Down Expand Up @@ -298,7 +301,6 @@ private void configureDeviceChoices() {
// changed elsewhere
deviceChoices.getSelectionModel().selectedItemProperty().addListener(
(value, oldValue, newValue) -> InstanSegPreferences.preferredDeviceProperty().set(newValue));

}

private void configureMessageLabel() {
Expand All @@ -317,7 +319,6 @@ private void configureMessageLabel() {
});
}


static void addModelsFromPath(String dir, ComboBox<InstanSegModel> box) {
if (dir == null || dir.isEmpty()) return;
box.getItems().clear();
Expand Down Expand Up @@ -650,5 +651,44 @@ private void updateSelectedObjectCounts() {

}

/**
* Open the model directory in the system file browser when double-clicked.
* @param event
*/
@FXML
public void handleModelDirectoryLabelClick(MouseEvent event) {
if (event.getClickCount() != 2)
return;
var path = InstanSegPreferences.modelDirectoryProperty().get();
if (path == null || path.isEmpty())
return;
var file = new File(path);
if (file.exists())
GuiTools.browseDirectory(file);
else
logger.debug("Can't browse directory for {}", file);
}

@FXML
public void promptForModelDirectory() {
promptToUpdateDirectory(InstanSegPreferences.modelDirectoryProperty());
}

private void promptToUpdateDirectory(StringProperty dirPath) {
var modelDirPath = dirPath.get();
var dir = modelDirPath == null || modelDirPath.isEmpty() ? null : new File(modelDirPath);
if (dir != null) {
if (dir.isFile())
dir = dir.getParentFile();
else if (!dir.exists())
dir = null;
}
var newDir = FileChoosers.promptForDirectory(
FXUtils.getWindow(tfModelDirectory), // Get window from any node here
resources.getString("ui.model-directory.choose-directory"),
dir);
if (newDir == null)
return;
dirPath.set(newDir.getAbsolutePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@
<!-- Model Directory Selection-->
<VBox alignment="CENTER" styleClass="standard-vertical-spacing">
<children>
<Label styleClass="regular" text="%ui.options.directory" />
<Label onMouseClicked="#handleModelDirectoryLabelClick" styleClass="regular" text="%ui.options.directory" />
<HBox styleClass="standard-spacing">
<children>
<TextField fx:id="tfModelDirectory" HBox.hgrow="ALWAYS">
<tooltip>
<Tooltip text="%ui.options.directory.tooltip" />
</tooltip>
</TextField>
<Button fx:id="modelDirButton" mnemonicParsing="false">
<Button fx:id="modelDirButton" mnemonicParsing="false" onAction="#promptForModelDirectory">
<tooltip>
<Tooltip text="%ui.options.directory.tooltip" />
</tooltip>
Expand Down

0 comments on commit 15ef5e1

Please sign in to comment.