Skip to content

Commit

Permalink
Add preferences to store values used during stitching
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSNelson committed Apr 10, 2024
1 parent 0fe16f5 commit d8b8ac6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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<String> 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<String> stitchingGridBox = new ComboBox<>(); // New combo box for stitching grid options
static Button folderButton = new Button("Select Folder");
// Declare labels as static fields
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

}

0 comments on commit d8b8ac6

Please sign in to comment.