3737import java .io .File ;
3838import java .util .ArrayList ;
3939import java .util .HashMap ;
40+ import java .awt .event .WindowAdapter ;
41+ import java .awt .event .WindowEvent ;
4042
4143public class MainFrame extends JFrame {
4244
@@ -55,10 +57,10 @@ public class MainFrame extends JFrame {
5557 private JTable coordTable ;
5658 public TableHelper imgListTH ;
5759 public TableHelper coordListTH ;
58- private String recordedImgPath = "/home/rick/Space/work/FDDB/data/Annotations " ;
60+ private String recordedImgPath = "" ;
5961
60- private String recordedAnnotPath = "/home/rick/Space/work/FDDB/data/Annotations " ;
61- private String recordedSavePath = "/home/rick/Space/work/FDDB/data/Annotations " ;
62+ private String recordedAnnotPath = "" ;
63+ private String recordedSavePath = "" ;
6264 private JButton btnReadImageList ;
6365
6466 private int leftTableSelectedRow = -1 ;
@@ -79,15 +81,16 @@ public static void main(String[] args) {
7981 public void run () {
8082 try {
8183 MainFrame frame = new MainFrame ();
82- // frame.recordedOpenPath =
83- // System.getProperty("user.home")+"/Desktop";
84- // frame.recordedImgPath =
85- // "/Users/microos/Downloads/originalPics/imgPath.txt";
84+ frame .recordedImgPath = System .getProperty ("user.home" )+"/Desktop" ;
85+ // frame.recordedImgPath =
86+ // "/Users/microos/Downloads/originalPics/imgPath.txt";
8687
87- // frame.recordedAnnotPath = System.getProperty("user.home")
88- // + "/Desktop";
88+ frame .recordedAnnotPath = System .getProperty ("user.home" ) + "/Desktop" ;
8989 // frame.recordedAnnotPath =
9090 // "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt";
91+
92+ frame .recordedSavePath = System .getProperty ("user.home" ) + "/Desktop" ;
93+
9194 frame .setVisible (true );
9295 } catch (Exception e ) {
9396 e .printStackTrace ();
@@ -101,9 +104,22 @@ public void run() {
101104 * Create the frame.
102105 */
103106 public MainFrame () {
107+ addWindowListener (new WindowAdapter () {
108+ @ Override
109+ public void windowClosing (WindowEvent e ) {
110+ if (Flags .numNewEllipse != 0 ){
111+ int op = JOptionPane .showConfirmDialog (MainFrame .this , "Do you want to exit?" , "Exiting" , JOptionPane .YES_NO_OPTION );
112+ if (op == JOptionPane .YES_OPTION ){
113+ System .exit (0 );
114+ }
115+ }else {
116+ System .exit (0 );
117+ }
118+ }
119+ });
104120 setResizable (false );
105121 setTitle ("Face Annotation Tool" );
106- setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
122+ setDefaultCloseOperation (JFrame .DO_NOTHING_ON_CLOSE );
107123 setBounds (100 , 100 , 1195 , 601 );
108124 contentPane = new JPanel ();
109125 contentPane .setBorder (new EmptyBorder (5 , 5 , 5 , 5 ));
@@ -308,7 +324,6 @@ void updateImagePanelSize(MyImage mim) {
308324
309325 void loadImageList () {
310326 JFileChooser fc = new JFileChooser (recordedImgPath );
311- // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
312327 int res = fc .showOpenDialog (this );
313328 if (res == JFileChooser .APPROVE_OPTION ) {
314329 File f = fc .getSelectedFile ();
@@ -369,7 +384,6 @@ void loadAnnotList() {
369384 annotContentSuffix = s == null ? "" : s ;
370385 }
371386 JFileChooser fc = new JFileChooser (recordedAnnotPath );
372- // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
373387 int res = fc .showOpenDialog (this );
374388 if (res == JFileChooser .APPROVE_OPTION ) {
375389 File f = fc .getSelectedFile ();
@@ -429,37 +443,37 @@ void loadAnnotList() {
429443 // all failed
430444
431445
432- String m = "Did not found any matched images for the annotation file you selected.\n " ;
446+ String m = "Did not find any matching images for the annotation file you selected.\n " ;
433447 m += "Please check the paths in your annotation file.\n " ;
434448 m += "To match an annotation with a loaded image,\n " ;
435- m += "make sure two paths are identical to each other.\n " ;
436- m += "Maybe a carefully-set prefix and suffix will help." ;
449+ m += " make sure two paths are identical to each other.\n " ;
450+ m += "Maybe a carefully-set prefix and suffix will help.\n \n " ;
437451 String p = annotContentPrefix == null ? "" : annotContentPrefix ;
438452 String s = annotContentSuffix == null ? "" : annotContentSuffix ;
439453
440454 if (pathStaticElpsesPair != null && pathStaticElpsesPair .size () != 0 ) {
441- m += "\n \n Current path concatenated with prefix and sufix:\n " ;
455+ m += "Current path concatenated with prefix and sufix:\n " ;
442456 m += String .format ("Prefix = \" %s\" \n " , p );
443457 m += String .format ("Suffix = \" %s\" \n " , s );
444458 m += ("Concatenated: " +pathStaticElpsesPair .keySet ().iterator ().next ());
445459 } else {
446- m += "\n \n Your current prefix and sufix :\n " ;
460+ m += "Your current prefix and suffix :\n " ;
447461 m += String .format ("Prefix = \" %s\" \n " , p );
448462 m += String .format ("Suffix = \" %s\" \n " , s );
449463 }
450464
451- JOptionPane .showMessageDialog (this , m , "Not found any matched annotations" ,
465+ JOptionPane .showMessageDialog (this , m , "No matching annotations found " ,
452466 JOptionPane .WARNING_MESSAGE );
453467 annotContentPrefix = annotContentSuffix = null ;
454468 pathStaticElpsesPair = null ;
455469 return ;
456470 }
457471 if (failedNum != 0 ){
458- String m = "Did not found any match annotations for the following loaded images:\n " ;
472+ String m = "Did not find any matching annotations for the following loaded images:\n " ;
459473 if (failed .size () < failedNum ){
460474 m += String .format ("(%d listed, %d in total)\n " , failed .size (), failedNum );
461475 }else {
462- m += String .format ("(num of images has no annotations : %d)\n " , failed .size () );
476+ m += String .format ("(num of images: %d)\n " , failed .size () );
463477 }
464478 int i = 1 ;
465479 for (String fal : failed ) {
@@ -474,10 +488,6 @@ void loadAnnotList() {
474488 imagePanel .repaint ();
475489 freezeReadAnnotationBtn ();
476490 JOptionPane .showMessageDialog (this , String .format ("Load annotations for %d images." , foundNum ));
477- // // reset
478- // pathImgPair = null;
479- // leftTableSelectedRow = -1;
480- // imagePanel.reset();
481491
482492 }
483493 }
@@ -492,8 +502,6 @@ void setImgPanelSize(int w, int h) {
492502 Dimension d = new Dimension (w , h );
493503 imagePanel .setSize (d );
494504 imagePanel .setPreferredSize (d );
495- // imagePanel.setMaximumSize(d);
496- // imagePanel.setMinimumSize(d);
497505 }
498506
499507 void testSetBackgroundImage () {
@@ -559,7 +567,6 @@ void outputAnnotations() {
559567 // ask: output only the new Ellipse or both new and static
560568
561569 JFileChooser fc = new JFileChooser (recordedSavePath );
562- // fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
563570 int res = fc .showOpenDialog (this );
564571 if (res == JFileChooser .APPROVE_OPTION ) {
565572 File f = fc .getSelectedFile ();
0 commit comments