3636import org .scijava .command .ContextCommand ;
3737import org .scijava .plugin .Parameter ;
3838import org .scijava .plugin .Plugin ;
39+ import org .scijava .prefs .PrefService ;
3940import org .scijava .widget .Button ;
4041import org .scijava .widget .FileWidget ;
4142import sc .fiji .snt .PathAndFillManager ;
@@ -88,23 +89,35 @@ and big data formats with lazy loading (N5, Zarr, HDF5, OME-TIFF,
8889 @ Parameter (required = false , visibility = ItemVisibility .MESSAGE , persist = false )
8990 String msgHeader = "<HTML>All files can be specified by either local paths or remote URLs. Only <i>Main volume</i> is a mandatory field." ;
9091
91- @ Parameter (label = "Main volume" , style = FileWidget .FILE_AND_DIRECTORY_STYLE ,
92+ // NB: persist = false on all four File parameters below: SciJava's own generic File-parameter persistence restores
93+ // a value via `new File(persistedString)`, which mangles a remote URL (see toPathString()). Persistence is instead
94+ // handled manually below via PrefService, storing/restoring the repaired string (toPathString()) so URLs work
95+
96+ @ Parameter (label = "Main volume" , style = FileWidget .FILE_AND_DIRECTORY_STYLE , persist = false ,
9297 description = "Primary image volume.\n " + TOOLTIP )
9398 File img1File ;
9499
95- @ Parameter (required = false , style = FileWidget .FILE_AND_DIRECTORY_STYLE ,
100+ @ Parameter (required = false , style = FileWidget .FILE_AND_DIRECTORY_STYLE , persist = false ,
96101 label = "Secondary volume" , description = "Optional image volume (e.g., a second channel saved separately).\n " + TOOLTIP )
97102 File img2File ;
98103
99- @ Parameter (required = false , label = "Reconstruction(s)" ,
104+ @ Parameter (required = false , label = "Reconstruction(s)" , persist = false ,
100105 description = "Optional.\n Either a single file (TRACES, SWC, JSON), or a\n " +
101106 "folder/.zip archive of several such files." )
102107 File recFiles ;
103108
104- @ Parameter (required = false , label = "Markers" ,
109+ @ Parameter (required = false , label = "Markers" , persist = false ,
105110 description = "Optional.\n A CSV file containing bookmarked locations." )
106111 File markerFile ;
107112
113+ @ Parameter
114+ private PrefService prefService ;
115+
116+ private static final String IMG1_KEY = "img1File" ;
117+ private static final String IMG2_KEY = "img2File" ;
118+ private static final String REC_KEY = "recFiles" ;
119+ private static final String MARKER_KEY = "markerFile" ;
120+
108121 @ Parameter (label = "Viewer type" , description = "The type of viewer.\n Tracing capabilities are provided by SNT Stream." ,
109122 choices = {
110123 "Big Data Viewer (BDV): Interactive reslicing" ,
@@ -133,6 +146,32 @@ private void loadDemo() {
133146 private void init () {
134147 msg = (SNTUtils .getInstance () == null )
135148 ? "" : "<HTML>NB: <i>SNT Stream</i> requires SNT to not already be running. Please close the active instance first." ;
149+ populateLastUsed ();
150+ }
151+
152+ /** Restores the four File fields from PrefService, in place of SciJava's own (URL-mangling) persistence. */
153+ private void populateLastUsed () {
154+ final String lastImg1 = prefService .get (BigDataLoaderCmd .class , IMG1_KEY );
155+ if (lastImg1 != null ) img1File = new File (lastImg1 );
156+ final String lastImg2 = prefService .get (BigDataLoaderCmd .class , IMG2_KEY );
157+ if (lastImg2 != null ) img2File = new File (lastImg2 );
158+ final String lastRec = prefService .get (BigDataLoaderCmd .class , REC_KEY );
159+ if (lastRec != null ) recFiles = new File (lastRec );
160+ final String lastMarker = prefService .get (BigDataLoaderCmd .class , MARKER_KEY );
161+ if (lastMarker != null ) markerFile = new File (lastMarker );
162+ }
163+
164+ /** Persists the four File fields as their repaired (toPathString()) string form. */
165+ private void saveLastUsed () {
166+ putOrRemove (IMG1_KEY , img1File );
167+ putOrRemove (IMG2_KEY , img2File );
168+ putOrRemove (REC_KEY , recFiles );
169+ putOrRemove (MARKER_KEY , markerFile );
170+ }
171+
172+ private void putOrRemove (final String key , final File file ) {
173+ if (file == null ) prefService .remove (BigDataLoaderCmd .class , key );
174+ else prefService .put (BigDataLoaderCmd .class , key , toPathString (file ));
136175 }
137176
138177 @ Override
@@ -142,6 +181,7 @@ public void run() {
142181 error ("Main volume is required." );
143182 return ;
144183 }
184+ saveLastUsed ();
145185 final String [] filePaths = Stream .of (img1File , img2File )
146186 .filter (Objects ::nonNull )
147187 .map (BigDataLoaderCmd ::toPathString )
0 commit comments