Skip to content

Commit 2e90835

Browse files
committed
bug fix, more dialogs
1 parent fa1495e commit 2e90835

6 files changed

Lines changed: 44 additions & 35 deletions

File tree

src/hk/microos/data/Ellipse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public Ellipse(Point_ mjA, Point_ mjB, Point_ miC) {
4848
keyPts.add(miC);
4949
keyPts.add(new Point_(this.x, this.y));
5050
}
51-
public void setOffsetForTableDisplay(double ofx, double ofy){
51+
public void setOffsetForTableDisplayAndOutput(double ofx, double ofy){
52+
//only new added ellipse will need this
5253
this.offsetX = ofx;
5354
this.offsetY = ofy;
5455
}
@@ -96,7 +97,7 @@ public String toRowFormatString() {
9697
public String toOutputFormatString(){
9798
//major minor angle x y 1
9899
String fmt = "%.6f %.6f %.6f %.6f %.6f 1";
99-
return String.format(fmt,this.major, this.minor, this.angle, this.x, this.y);
100+
return String.format(fmt,this.major, this.minor, this.angle, this.x-offsetX, this.y-offsetY);
100101
}
101102

102103
}

src/hk/microos/data/Flags.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
public class Flags {
44
public static boolean GLOABAL_DEBUG = false;
5-
public static boolean FUNC_INVOKE_PRINT = true;
65
public static double minStroke = 2;
76
public static double maxStroke = 5;
87
public static int numNewEllipse = 0;

src/hk/microos/data/MyImage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public String getOutputString(boolean withBoth){
105105
sb.append(elpse4Output.size()+"\n");
106106
double[] offset = UniversalTool.getOffset(this);
107107
for(Ellipse e : elpse4Output){
108-
e = e.offset(-offset[0], -offset[1]);
109108
sb.append(e.toOutputFormatString()+"\n");
110109
}
111110
return sb.toString();

src/hk/microos/frames/MainFrame.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.io.File;
3838
import java.util.ArrayList;
3939
import java.util.HashMap;
40+
import java.awt.event.WindowAdapter;
41+
import java.awt.event.WindowEvent;
4042

4143
public 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\nCurrent 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\nYour 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();

src/hk/microos/frames/MyImagePanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void updateStatus() {
262262
int idx = -1;
263263
if (unfinishedSize == 3) {
264264
Ellipse e = new Ellipse(unfinished.get(0), unfinished.get(1), this.projPoint);
265-
e.setOffsetForTableDisplay(this.minX, this.minY);
265+
e.setOffsetForTableDisplayAndOutput(this.minX, this.minY);
266266
mImg.addElps(e);
267267
Flags.numNewEllipse++;
268268
unfinished = new ArrayList<>();

src/hk/microos/tools/IOTool.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static HashMap<String, ArrayList<Ellipse>> readAnnotationFile(File f, Str
140140

141141
ArrayList<Ellipse> elpses = null;
142142
try {
143-
elpses = readNEllipse(lines, at, detNum);
143+
elpses = readEllipse(lines, at, detNum);
144144

145145
} catch (Exception e) {
146146
throw new Exception(e.getMessage());
@@ -156,7 +156,7 @@ public static HashMap<String, ArrayList<Ellipse>> readAnnotationFile(File f, Str
156156
return map;
157157
}
158158

159-
private static ArrayList<Ellipse> readNEllipse(ArrayList<String> lines, int start, int num) throws Exception {
159+
private static ArrayList<Ellipse> readEllipse(ArrayList<String> lines, int start, int num) throws Exception {
160160
ArrayList<Ellipse> elps = new ArrayList<>();
161161
for (int i = 0; i < num; i++) {
162162
int at = start + i;
@@ -183,7 +183,7 @@ public static void outputEllipse(HashMap<String, MyImage> pathImgPair, String ou
183183
int res = JOptionPane.showConfirmDialog(dialogFatherFrame,
184184
String.format("File %s exists, do you want to overwrite it?", f.getAbsolutePath()), "File exists",
185185
JOptionPane.YES_NO_OPTION);
186-
if (res == JOptionPane.NO_OPTION)
186+
if (res == JOptionPane.NO_OPTION || res == -1)
187187
return;
188188
}
189189
boolean withBoth = false;
@@ -193,6 +193,8 @@ public static void outputEllipse(HashMap<String, MyImage> pathImgPair, String ou
193193
+ "(Noted that a image without any annotation will not be included in the output file)",
194194
"", JOptionPane.NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
195195
new String[] { "both loaded and marked annotations", "only annotations marked by me" }, 0);
196+
if(res == -1)
197+
return;
196198
if (res == 0)
197199
withBoth = true;
198200
if (res == 1)
@@ -201,6 +203,7 @@ public static void outputEllipse(HashMap<String, MyImage> pathImgPair, String ou
201203
int numImage = 0;
202204
int numAnnot = 0;
203205
StringBuffer sb = new StringBuffer();
206+
204207
for (String p : pathImgPair.keySet()) {
205208
MyImage mim = UniversalTool.getMyImageFromPathImgPair(p, pathImgPair);
206209
String s = mim.getOutputString(withBoth);

0 commit comments

Comments
 (0)