From d8b8ac613438b040f40e035788c4acff78681508 Mon Sep 17 00:00:00 2001 From: MichaelSNelson Date: Tue, 9 Apr 2024 22:02:48 -0500 Subject: [PATCH] Add preferences to store values used during stitching --- .../functions/StitchingGUI.groovy | 23 ++++--- .../utilities/QPPreferences.groovy | 69 +++++++++++++++++++ 2 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 src/main/groovy/qupath/ext/basicstitching/utilities/QPPreferences.groovy diff --git a/src/main/groovy/qupath/ext/basicstitching/functions/StitchingGUI.groovy b/src/main/groovy/qupath/ext/basicstitching/functions/StitchingGUI.groovy index bd728b0..45963a1 100644 --- a/src/main/groovy/qupath/ext/basicstitching/functions/StitchingGUI.groovy +++ b/src/main/groovy/qupath/ext/basicstitching/functions/StitchingGUI.groovy @@ -12,6 +12,7 @@ import javafx.stage.Modality import org.slf4j.Logger import org.slf4j.LoggerFactory import qupath.ext.basicstitching.stitching.StitchingImplementations +import qupath.ext.basicstitching.utilities.AutoFillPersistentPreferences import qupath.lib.gui.scripting.QPEx import java.awt.* @@ -21,11 +22,11 @@ import static qupath.ext.basicstitching.utilities.UtilityFunctions.getCompressio class StitchingGUI { private static final Logger logger = LoggerFactory.getLogger(StitchingGUI.class); - static TextField folderField = new TextField(); + static TextField folderField = new TextField(AutoFillPersistentPreferences.getFolderLocationSaved()); static ComboBox compressionBox = new ComboBox<>(); - static TextField pixelSizeField = new TextField("0.4988466"); - static TextField downsampleField = new TextField("1"); - static TextField matchStringField = new TextField("20x"); + static TextField pixelSizeField = new TextField(AutoFillPersistentPreferences.getImagePixelSizeInMicronsSaved()); + static TextField downsampleField = new TextField(AutoFillPersistentPreferences.getDownsampleSaved()); + static TextField matchStringField = new TextField(AutoFillPersistentPreferences.getSearchStringSaved()); static ComboBox stitchingGridBox = new ComboBox<>(); // New combo box for stitching grid options static Button folderButton = new Button("Select Folder"); // Declare labels as static fields @@ -59,17 +60,23 @@ class StitchingGUI { // Handling the response if (result.isPresent() && result.get() == ButtonType.OK) { + //read values from dialog and + // save to persistent preferences so they will be saved for the next use String folderPath = folderField.getText() // Assuming folderField is accessible + AutoFillPersistentPreferences.setFolderLocationSaved(folderPath) String compressionType = compressionBox.getValue() // Assuming compressionBox is accessible - + AutoFillPersistentPreferences.setCompressionTypeSaved(compressionType) // Check if pixelSizeField and downsampleField are not empty double pixelSize = pixelSizeField.getText() ? Double.parseDouble(pixelSizeField.getText()) : 0 + AutoFillPersistentPreferences.setImagePixelSizeInMicronsSaved(pixelSize.toString()) // Default to 0 if empty double downsample = downsampleField.getText() ? Double.parseDouble(downsampleField.getText()) : 1 // Default to 1 if empty - + AutoFillPersistentPreferences.setDownsampleSaved(downsample.toString()) String matchingString = matchStringField.getText() // Assuming matchStringField is accessible + AutoFillPersistentPreferences.setSearchStringSaved(matchingString) String stitchingType = stitchingGridBox.getValue() + AutoFillPersistentPreferences.setStitchingMethodSaved(stitchingType) // Call the function with collected data String finalImageName = StitchingImplementations.stitchCore(stitchingType, folderPath, folderPath, compressionType, pixelSize, downsample, matchingString) //stitchByFileName(folderPath, compressionType, pixelSize, downsample, matchingString) @@ -217,7 +224,7 @@ class StitchingGUI { ); // Set the default value for the combo box - stitchingGridBox.setValue("Coordinates in TileConfiguration.txt file"); + stitchingGridBox.setValue(AutoFillPersistentPreferences.getStitchingMethodSaved()); // Define an action to be performed when a new item is selected in the combo box // This action updates the visibility of other components based on the selection @@ -306,7 +313,7 @@ class StitchingGUI { compressionBox.getItems().addAll(compressionTypes); // Set the default value for the combo box - compressionBox.setValue("J2K_LOSSY"); + compressionBox.setValue(AutoFillPersistentPreferences.getCompressionTypeSaved()); // Create and set a tooltip for additional information Tooltip compressionTooltip = new Tooltip("Select the type of image compression."); diff --git a/src/main/groovy/qupath/ext/basicstitching/utilities/QPPreferences.groovy b/src/main/groovy/qupath/ext/basicstitching/utilities/QPPreferences.groovy new file mode 100644 index 0000000..b898c35 --- /dev/null +++ b/src/main/groovy/qupath/ext/basicstitching/utilities/QPPreferences.groovy @@ -0,0 +1,69 @@ +package qupath.ext.basicstitching.utilities + +import javafx.beans.property.ObjectProperty +import javafx.beans.property.StringProperty +import qupath.lib.gui.prefs.PathPrefs +import qupath.lib.images.writers.ome.OMEPyramidWriter + +class QPPreferences { + +} + +class AutoFillPersistentPreferences{ + + //private AutoFillPersistentPreferences options = AutoFillPersistentPreferences.getInstance(); + private static StringProperty folderLocationSaved = PathPrefs.createPersistentPreference("folderLocation", "C:/"); + + public static String getFolderLocationSaved(){ + return folderLocationSaved.value + } + public static void setFolderLocationSaved(final String folderLocationSaved){ + this.folderLocationSaved.value = folderLocationSaved + } + + private static StringProperty imagePixelSizeInMicronsSaved = PathPrefs.createPersistentPreference("imagePixelSizeInMicrons", "7.2"); + + public static String getImagePixelSizeInMicronsSaved(){ + return imagePixelSizeInMicronsSaved.value + } + public static void setImagePixelSizeInMicronsSaved(final String imagePixelSizeInMicronsSaved){ + this.imagePixelSizeInMicronsSaved.value = imagePixelSizeInMicronsSaved + } + + private static StringProperty downsampleSaved = PathPrefs.createPersistentPreference("downsample", "1"); + + public static String getDownsampleSaved(){ + return downsampleSaved.value + } + public static void setDownsampleSaved(final String downsampleSaved){ + this.downsampleSaved.value = downsampleSaved + } + + private static StringProperty searchStringSaved = PathPrefs.createPersistentPreference("searchString", "20x"); + + public static String getSearchStringSaved(){ + return searchStringSaved.value + } + public static void setSearchStringSaved(final String searchStringSaved){ + this.searchStringSaved.value = searchStringSaved + } + + private static StringProperty compressionTypeSaved = PathPrefs.createPersistentPreference("compressionType","J2K") + + public static String getCompressionTypeSaved(){ + return compressionTypeSaved.value + } + public static void setCompressionTypeSaved(final String compressionTypeSaved){ + this.compressionTypeSaved.value = compressionTypeSaved + } + + private static StringProperty stitchingMethodSaved = PathPrefs.createPersistentPreference("compressionType","Coordinates in TileConfiguration.txt file") + + public static String getStitchingMethodSaved(){ + return stitchingMethodSaved.value + } + public static void setStitchingMethodSaved(final String stitchingMethodSaved){ + this.stitchingMethodSaved.value = stitchingMethodSaved + } + +} \ No newline at end of file