1313import javax .swing .table .DefaultTableModel ;
1414
1515import hk .microos .data .Ellipse ;
16+ import hk .microos .data .Flags ;
1617import hk .microos .data .MyImage ;
1718import hk .microos .tools .ClickHelper ;
1819import hk .microos .tools .IOTool ;
@@ -63,13 +64,16 @@ public class MainFrame extends JFrame {
6364 private String recordedImgPath = "/home/rick/Space/work/FDDB/data/Annotations" ;
6465
6566 private String recordedAnnotPath = "/home/rick/Space/work/FDDB/data/Annotations" ;
67+ private String recordedSavePath = "/home/rick/Space/work/FDDB/data/Annotations" ;
6668 private JButton btnReadImageList ;
6769
6870 private int leftTableSelectedRow = -1 ;
6971 private HashMap <String , MyImage > pathImgPair = null ;
7072 private HashMap <String , ArrayList <Ellipse >> pathElpsesPair = null ;
7173 private JButton btnReadAnnotations ;
72-
74+ private String annotContentPrefix = null ;
75+ private String annotContentSuffix = null ;
76+ private JButton btnOutputAnnotation ;
7377 /**
7478 * Launch the application.
7579 */
@@ -81,13 +85,13 @@ public void run() {
8185 MainFrame frame = new MainFrame ();
8286 // frame.recordedOpenPath =
8387 // System.getProperty("user.home")+"/Desktop";
84- // frame.recordedImgPath =
85- // "/Users/microos/Downloads/originalPics/imgPath.txt";
88+ frame .recordedImgPath =
89+ "/Users/microos/Downloads/originalPics/imgPath.txt" ;
8690
8791 // frame.recordedAnnotPath = System.getProperty("user.home")
8892 // + "/Desktop";
89- // frame.recordedAnnotPath =
90- // "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt";
93+ frame .recordedAnnotPath =
94+ "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt" ;
9195 frame .setVisible (true );
9296 } catch (Exception e ) {
9397 e .printStackTrace ();
@@ -167,6 +171,14 @@ public void actionPerformed(ActionEvent e) {
167171 }
168172 });
169173 toolPanel .add (btnReadAnnotations );
174+
175+ btnOutputAnnotation = new JButton ("Output Annotation" );
176+ btnOutputAnnotation .addActionListener (new ActionListener () {
177+ public void actionPerformed (ActionEvent e ) {
178+ outputAnnotations ();
179+ }
180+ });
181+ toolPanel .add (btnOutputAnnotation );
170182
171183 imagePanel = new MyImagePanel (this , scrollPanel );
172184 imagePanel .addMouseListener (new MouseAdapter () {
@@ -242,7 +254,8 @@ void leftTableOnClick(ListSelectionEvent e) {
242254 }
243255
244256 void setRightPanelCoords (MyImage mim ) {
245-
257+ //call this will update right panel with image's staticEllipse/Ellipse
258+ //use null as the arg will use a selectedRow as target image
246259 if (mim == null ) {
247260 System .out .println ("setRightPanelCoords with null" );
248261 if (leftTableSelectedRow == -1 ) {
@@ -307,14 +320,15 @@ void loadImageList() {
307320 // read successes
308321 // load Images to table
309322 // reset
310- pathImgPair = null ;
311- leftTableSelectedRow = -1 ;
312- imagePanel .reset ();
323+ // pathImgPair = null;
324+ // leftTableSelectedRow = -1;
325+ // imagePanel.reset();
313326
314327 pathImgPair = IOTool .filterImageList (imgList , this );
315328 fillImageNameTable ();
316329 leftTableSelectedRow = 0 ;
317330 imgListTH .setSelectedRow (leftTableSelectedRow );
331+ freezeReadImageListBtn ();
318332
319333 }
320334 }
@@ -334,6 +348,16 @@ void loadAnnotList() {
334348 if (pathImgPair == null ) {
335349 // no images loaded, abort
336350 return ;
351+ }
352+ if (annotContentPrefix == null ){
353+ String s = JOptionPane .showInputDialog (this , "Please set a prefix string for your annotation image path.\n (leave empty or cancel if not necessary)" , "Prefix" , JOptionPane .QUESTION_MESSAGE );
354+ annotContentPrefix = s ==null ? "" : s ;
355+
356+ s = JOptionPane .showInputDialog (this , "Please set a suffix(usually is image format extention) for your annotation image path.\n (leave empty or cancel if not necessary)" , "Suffix" , JOptionPane .QUESTION_MESSAGE );
357+ annotContentSuffix = s ==null ? "" : s ;
358+
359+
360+
337361 }
338362 JFileChooser fc = new JFileChooser (recordedAnnotPath );
339363 // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
@@ -351,7 +375,7 @@ void loadAnnotList() {
351375 boolean noError = true ;
352376 String errMessage = "" ;
353377 try {
354- pathElpsesPair = IOTool .readAnnotationFile (f );
378+ pathElpsesPair = IOTool .readAnnotationFile (f , annotContentPrefix , annotContentSuffix );
355379 } catch (Exception e ) {
356380 pathElpsesPair = null ;
357381 noError = false ;
@@ -382,6 +406,8 @@ void loadAnnotList() {
382406 }
383407 }
384408 marksLoadAnnotationUpdate ();
409+ imagePanel .repaint ();
410+ freezeReadAnnotationBtn ();
385411 // // reset
386412 // pathImgPair = null;
387413 // leftTableSelectedRow = -1;
@@ -431,7 +457,7 @@ public void marksLoadAnnotationUpdate() {
431457 }
432458
433459 public void marksUpdatedAtSelected (MyImage mim ) {
434-
460+
435461 if (leftTableSelectedRow == -1 ) {
436462 System .err .println ("marking on non-loaded image?" );
437463 }
@@ -444,7 +470,12 @@ public void marksUpdatedAtSelected(MyImage mim) {
444470 imgListTH .setValueAt (leftTableSelectedRow , 2 , mim .getMarkNumString ());
445471 setRightPanelCoords (mim );
446472 }
447-
473+ public void freezeReadImageListBtn (){
474+ this .btnReadImageList .setEnabled (false );
475+ }
476+ public void freezeReadAnnotationBtn (){
477+ this .btnReadAnnotations .setEnabled (false );
478+ }
448479 MyImage getMyImageFromPathImgPair (String path ) {
449480 MyImage img = pathImgPair .get (path );
450481 if (img == null ) {
@@ -455,6 +486,54 @@ MyImage getMyImageFromPathImgPair(String path) {
455486 } else {
456487 return img ;
457488 }
489+ }
490+ void outputAnnotations (){
491+ if (pathImgPair == null ){
492+ return ; //even no image loaded? abort
493+ }
494+ if (Flags .numNewEllipse <= 0 ){
495+ JOptionPane .showMessageDialog (this , "You did not mark any annotations, nothing to output." ,"Nothing to output" ,JOptionPane .WARNING_MESSAGE );
496+ return ;
497+ }
498+ //open a chooser
499+ //make it a .txt file
500+ //output only the new Ellipse
501+
502+ JFileChooser fc = new JFileChooser (recordedSavePath );
503+ // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
504+ int res = fc .showOpenDialog (this );
505+ if (res == JFileChooser .APPROVE_OPTION ) {
506+ File f = fc .getSelectedFile ();
507+ 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 ();
458534
535+ }
536+ }
537+ }
459538 }
460539}
0 commit comments