77
88import java .io .IOException ;
99import java .util .ArrayList ;
10+ import java .util .concurrent .ExecutionException ;
1011
1112import javax .swing .SwingWorker ;
1213
@@ -33,7 +34,6 @@ public class ROIsLoadBG < T extends RealType< T > & NativeType< T > > extends Sw
3334 public String sFilename ;
3435 public int nLoadMode ;
3536 String sFinalOut = "" ;
36-
3737
3838 @ Override
3939 public String getProgressState ()
@@ -50,12 +50,14 @@ public void setProgressState(String state_)
5050 protected Void doInBackground () throws Exception {
5151 String [] line_array ;
5252
53- int nRoiN =1 ;
54- int nVertN =0 ;
53+ int nRoiN = 1 ;
54+
55+ int nVertN = 0 ;
56+
5557 int i ,j ;
5658
57-
5859 ArrayList <RealPoint > vertices ;
60+
5961 ArrayList <RealPoint > segment ;
6062
6163 int nROIGroupInd = 0 ;
@@ -69,22 +71,20 @@ protected Void doInBackground() throws Exception {
6971 int nRenderType = 0 ;
7072 String sUnits = "" ;
7173 double [] globCalNew = new double [3 ];
72- globCalNew [0 ]= Double .NaN ;
73- globCalNew [1 ]= Double .NaN ;
74- globCalNew [2 ]= Double .NaN ;
74+ globCalNew [0 ] = Double .NaN ;
75+ globCalNew [1 ] = Double .NaN ;
76+ globCalNew [2 ] = Double .NaN ;
7577
7678 Roi3DGroupManager <T > roiGM ;
77-
78- bt .bInputLock = true ;
79- bt .setLockMode (true );
79+
8080 try ( BufferedReader br = new BufferedReader (new FileReader (sFilename ));)
8181 {
8282 String line = "" ;
8383 //read Groups first
8484 if (nLoadMode == 0 )
8585 {
8686 roiGM = new Roi3DGroupManager <>(bt .roiManager );
87- if (roiGM .loadGroups (br )< 0 )
87+ if (roiGM .loadGroups (br ) < 0 )
8888 {
8989 System .err .println ("Not a BigTrace ROI Group file format or plugin/file version mismatch,\n loading Groups failed.\n " +
9090 "Try 'Append' loading mode.\n " );
@@ -109,9 +109,11 @@ protected Void doInBackground() throws Exception {
109109 }
110110 line_array = line .split ("," );
111111
112- if (line_array .length == 3 && line_array [0 ].equals ("BigTrace_ROIs" ))
112+ if (line_array .length == 3 && line_array [0 ].equals ("BigTrace_ROIs" ))
113113 {
114114 bBeginROIpart = true ;
115+
116+ System .out .println ("First ROI line ok! " );
115117 }
116118 else
117119 {
@@ -123,8 +125,8 @@ protected Void doInBackground() throws Exception {
123125 }
124126
125127 //initial part check
126-
127128 line_array = line .split ("," );
129+
128130 if (!line_array [0 ].equals ("BigTrace_ROIs" ))
129131 {
130132 System .err .println ("Not a BigTrace ROI file format, aborting" );
@@ -243,8 +245,8 @@ protected Void doInBackground() throws Exception {
243245
244246 case "Vertices" :
245247 nVertN = Integer .parseInt (line_array [1 ]);
246- vertices =new ArrayList <>();
247- for (i = 0 ; i < nVertN ;i ++)
248+ vertices = new ArrayList <>();
249+ for (i = 0 ; i < nVertN ; i ++)
248250 {
249251 line = br .readLine ();
250252 line_array = line .split ("," );
@@ -288,14 +290,14 @@ protected Void doInBackground() throws Exception {
288290 line = br .readLine ();
289291 line_array = line .split ("," );
290292 int nTotSegm = Integer .parseInt (line_array [1 ]);
291- for (i = 0 ; i < nTotSegm ;i ++)
293+ for (i = 0 ; i < nTotSegm ; i ++)
292294 {
293295 //points number
294296 line = br .readLine ();
295297 line_array = line .split ("," );
296298 nVertN = Integer .parseInt (line_array [3 ]);
297299 segment = new ArrayList <>();
298- for (j = 0 ; j < nVertN ;j ++)
300+ for (j = 0 ; j < nVertN ; j ++)
299301 {
300302 line = br .readLine ();
301303 line_array = line .split ("," );
@@ -321,12 +323,13 @@ protected Void doInBackground() throws Exception {
321323
322324 }
323325 line = br .readLine ();
324- }
326+ System .out .println ("lineoutside" + line );
327+ }
325328
326329 br .close ();
327330 setProgress (100 );
328-
329- sFinalOut = "loading ROIs done." ;
331+ System . out . println ( "finished reading file" );
332+ sFinalOut = "loading ROIs done." ;
330333 setProgressState (sFinalOut );
331334
332335 /** load voxel calibration **/
@@ -336,7 +339,6 @@ protected Void doInBackground() throws Exception {
336339 bt .btData .sVoxelUnit = new String (sUnits );
337340 bt .btPanel .voxelSizePanel .setVoxelSize (globCalNew , sUnits );
338341 sFinalOut = "loading ROIs done (+voxel calibration)." ;
339-
340342 setProgressState (sFinalOut );
341343 }
342344 else
@@ -371,7 +373,28 @@ protected Void doInBackground() throws Exception {
371373 */
372374 @ Override
373375 public void done ()
374- {
376+ {
377+ //see if we have some errors
378+ try {
379+
380+ get ();
381+ }
382+ catch (ExecutionException e )
383+ {
384+ e .getCause ().printStackTrace ();
385+ String msg = String .format ("Unexpected error during ROI loading: %s" ,
386+ e .getCause ().toString ());
387+ System .out .println (msg );
388+ }
389+ catch (InterruptedException e )
390+ {
391+ System .out .println (e .toString ());
392+ }
393+ catch (Exception e )
394+ {
395+ }
396+ System .out .println ("done load lock thread" );
397+
375398 //unlock user interaction
376399 bt .bInputLock = false ;
377400 bt .setLockMode (false );
0 commit comments