4141import java .awt .event .MouseMotionAdapter ;
4242import java .awt .image .BufferedImage ;
4343import java .io .File ;
44+ import java .nio .file .PathMatcher ;
4445import java .util .ArrayList ;
4546import java .util .HashMap ;
4647
@@ -69,7 +70,7 @@ public class MainFrame extends JFrame {
6970
7071 private int leftTableSelectedRow = -1 ;
7172 private HashMap <String , MyImage > pathImgPair = null ;
72- private HashMap <String , ArrayList <Ellipse >> pathElpsesPair = null ;
73+ private HashMap <String , ArrayList <Ellipse >> pathStaticElpsesPair = null ;
7374 private JButton btnReadAnnotations ;
7475 private String annotContentPrefix = null ;
7576 private String annotContentSuffix = null ;
@@ -85,13 +86,13 @@ public void run() {
8586 MainFrame frame = new MainFrame ();
8687 // frame.recordedOpenPath =
8788 // System.getProperty("user.home")+"/Desktop";
88- frame .recordedImgPath =
89- "/Users/microos/Downloads/originalPics/imgPath.txt" ;
89+ // frame.recordedImgPath =
90+ // "/Users/microos/Downloads/originalPics/imgPath.txt";
9091
9192 // frame.recordedAnnotPath = System.getProperty("user.home")
9293 // + "/Desktop";
93- frame .recordedAnnotPath =
94- "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt" ;
94+ // frame.recordedAnnotPath =
95+ // "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt";
9596 frame .setVisible (true );
9697 } catch (Exception e ) {
9798 e .printStackTrace ();
@@ -243,7 +244,7 @@ void leftTableOnClick(ListSelectionEvent e) {
243244 return ;
244245 int id = (int ) imgListTH .getValueAt (leftTableSelectedRow , 0 );
245246 String path = imgListTH .getBehindRowDataAt (leftTableSelectedRow );
246- MyImage mim = getMyImageFromPathImgPair (path );
247+ MyImage mim = UniversalTool . getMyImageFromPathImgPair (path , pathImgPair );
247248 boolean changed = imagePanel .setCurrentImage (mim );
248249 // display coords on the right
249250 setRightPanelCoords (mim );
@@ -274,8 +275,8 @@ void setRightPanelCoords(MyImage mim) {
274275 // 1 load static ellipse into the table
275276 // when pathElpsesPair set and
276277 ArrayList <Ellipse > staticElps ;
277- if (pathElpsesPair != null ) {
278- staticElps = pathElpsesPair .get (mim .getPath ());
278+ if (pathStaticElpsesPair != null ) {
279+ staticElps = pathStaticElpsesPair .get (mim .getPath ());
279280 mim .setElpsesStatic (staticElps );
280281 }
281282
@@ -317,14 +318,11 @@ void loadImageList() {
317318 String .format ("\" %s\" \n cannot be properly read." , f .getAbsolutePath ()).toString (),
318319 "Reading failed" , JOptionPane .WARNING_MESSAGE );
319320 } else {
320- // read successes
321- // load Images to table
322- // reset
323- // pathImgPair = null;
324- // leftTableSelectedRow = -1;
325- // imagePanel.reset();
326321
327322 pathImgPair = IOTool .filterImageList (imgList , this );
323+ if (pathImgPair .size () == 0 ){
324+ return ;
325+ }
328326 fillImageNameTable ();
329327 leftTableSelectedRow = 0 ;
330328 imgListTH .setSelectedRow (leftTableSelectedRow );
@@ -370,19 +368,21 @@ void loadAnnotList() {
370368 JOptionPane .showMessageDialog (this ,
371369 String .format ("\" %s\" \n is not a txt file." , f .getAbsolutePath ()).toString (), "Not a txt file" ,
372370 JOptionPane .WARNING_MESSAGE );
371+ annotContentPrefix = annotContentSuffix = null ;
373372 } else {
374373 // read
375374 boolean noError = true ;
376375 String errMessage = "" ;
377376 try {
378- pathElpsesPair = IOTool .readAnnotationFile (f , annotContentPrefix , annotContentSuffix );
377+ pathStaticElpsesPair = IOTool .readAnnotationFile (f , annotContentPrefix , annotContentSuffix );
379378 } catch (Exception e ) {
380- pathElpsesPair = null ;
379+ pathStaticElpsesPair = null ;
381380 noError = false ;
382381 errMessage = e .getMessage ();
383382 }
384383
385384 if (noError == false ) {
385+ annotContentPrefix = annotContentSuffix = null ;
386386 // parse failed
387387 JOptionPane
388388 .showMessageDialog (this ,
@@ -394,10 +394,10 @@ void loadAnnotList() {
394394 //
395395 // // put these annotations to mImg.ellispe_static
396396 for (String p : pathImgPair .keySet ()) {
397- ArrayList <Ellipse > elpses = pathElpsesPair .get (p );
397+ ArrayList <Ellipse > elpses = pathStaticElpsesPair .get (p );
398398 if (elpses != null ) {// annotation list contains this
399399 // image's annotations
400- MyImage mim = getMyImageFromPathImgPair (p );
400+ MyImage mim = UniversalTool . getMyImageFromPathImgPair (p , pathImgPair );
401401 mim .setElpsesStatic (elpses );
402402 // update mark nums
403403 } else {
@@ -415,6 +415,8 @@ void loadAnnotList() {
415415
416416 }
417417 }
418+ }else {
419+ annotContentPrefix = annotContentSuffix = null ;
418420 }
419421 }
420422
@@ -444,9 +446,9 @@ void testSetBackgroundImage() {
444446 }
445447
446448 public void marksLoadAnnotationUpdate () {
447- if (pathElpsesPair == null )
449+ if (pathStaticElpsesPair == null )
448450 return ;
449- for (String p : pathElpsesPair .keySet ()) {
451+ for (String p : pathStaticElpsesPair .keySet ()) {
450452 int idx = imgListTH .getRowIndexOfValue (p );
451453 MyImage mim = pathImgPair .get (p );
452454 if (idx != -1 && mim != null ) {
@@ -476,16 +478,8 @@ public void freezeReadImageListBtn(){
476478 public void freezeReadAnnotationBtn (){
477479 this .btnReadAnnotations .setEnabled (false );
478480 }
479- MyImage getMyImageFromPathImgPair (String path ) {
480- MyImage img = pathImgPair .get (path );
481- if (img == null ) {
482- File f = new File (path );
483- img = new MyImage (f );
484- pathImgPair .put (path , img );
485- return img ;
486- } else {
487- return img ;
488- }
481+ public HashMap <String , MyImage > getPathImgPair (){
482+ return pathImgPair ;
489483 }
490484 void outputAnnotations (){
491485 if (pathImgPair == null ){
@@ -497,43 +491,16 @@ void outputAnnotations(){
497491 }
498492 //open a chooser
499493 //make it a .txt file
500- //output only the new Ellipse
494+ // ask: output only the new Ellipse or both new and static
501495
502496 JFileChooser fc = new JFileChooser (recordedSavePath );
503497 // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
504498 int res = fc .showOpenDialog (this );
505499 if (res == JFileChooser .APPROVE_OPTION ) {
506500 File f = fc .getSelectedFile ();
507501 recordedImgPath = f .getParent ();
508- if (!IOTool .isTextFile (f )) {
509- // not a readable text file
510- JOptionPane .showMessageDialog (this ,
511- String .format ("\" %s\" \n is not a txt file." , f .getAbsolutePath ()).toString (), "Not a txt file" ,
512- JOptionPane .WARNING_MESSAGE );
513- } else {
514- // read
515- ArrayList <String > imgList = IOTool .readText (f );
516- if (imgList == null ) {
517- // read failed
518- JOptionPane .showMessageDialog (this ,
519- String .format ("\" %s\" \n cannot be properly read." , f .getAbsolutePath ()).toString (),
520- "Reading failed" , JOptionPane .WARNING_MESSAGE );
521- } else {
522- // read successes
523- // load Images to table
524- // reset
525- // pathImgPair = null;
526- // leftTableSelectedRow = -1;
527- // imagePanel.reset();
528-
529- pathImgPair = IOTool .filterImageList (imgList , this );
530- fillImageNameTable ();
531- leftTableSelectedRow = 0 ;
532- imgListTH .setSelectedRow (leftTableSelectedRow );
533- freezeReadImageListBtn ();
534-
535- }
536- }
502+ IOTool .outputEllipse (pathImgPair , f .getAbsolutePath (),pathStaticElpsesPair != null ,this );
503+
537504 }
538505 }
539506}
0 commit comments