20
20
import eu .digitisation .gui .InputFileSelector ;
21
21
import eu .digitisation .gui .OutputFileSelector ;
22
22
import eu .digitisation .io .Batch ;
23
+ import eu .digitisation .io .CharFilter ;
23
24
import eu .digitisation .ocrevaluation .Report ;
24
25
import java .awt .*;
25
26
import javax .swing .*;
@@ -37,63 +38,88 @@ public class MainGUI extends JFrame implements ActionListener {
37
38
static final long serialVersionUID = 1L ;
38
39
static final Color bgcolor = Color .decode ("#FAFAFA" );
39
40
static final Color forecolor = Color .decode ("#4C501E" );
40
- static final Border border = BorderFactory .createLineBorder (forecolor , 4 );
41
- Container pane ; // top panel
42
- JButton trigger ; // Go button
43
- File [] files ; // input/output files
41
+ static final Border border = BorderFactory .createLineBorder (forecolor , 2 );
42
+
43
+ Container pane ; // main panel
44
+ JPanel basic ; // basic inputs
45
+ JPanel advanced ; // more options panel
46
+ JPanel actions ; // actions panel
47
+
48
+ InputFileSelector gtinput ; // GT file
49
+ InputFileSelector ocrinput ;// OCR file
50
+ InputFileSelector eqinput ; // equivalences file
51
+ JCheckBox compatibility ; // Unicode comaptiblity mode
52
+ JButton trigger ; // Go button
53
+ JCheckBox more ; // Checkbox for more options
44
54
45
55
public MainGUI () {
46
56
47
57
pane = getContentPane ();
48
58
trigger = new JButton ("Generate report" );
49
- files = new File [4 ];
50
59
51
- // frame attributes
60
+ // JFrame attributes
52
61
setTitle ("Input files" );
53
- setBackground (Color . decode ( "#FAFAFA" ) );
54
- setSize (400 , 300 );
62
+ setBackground (bgcolor );
63
+ setSize (400 , 200 );
55
64
setDefaultCloseOperation (EXIT_ON_CLOSE );
56
- setLayout (new BoxLayout (pane , BoxLayout .PAGE_AXIS ));
65
+ setLayout (new BoxLayout (pane , BoxLayout .Y_AXIS ));
57
66
setLocationRelativeTo (null );
58
- setVisible (true );
59
-
60
- // Create drop areas
61
- pane .add (new InputFileSelector (forecolor , bgcolor ,
62
- border , "ground-truth file" ));
63
- pane .add (new InputFileSelector (forecolor , bgcolor ,
64
- border , "ocr file" ));
65
- pane .add (new InputFileSelector (forecolor , bgcolor ,
66
- border , "Unicode character equivalences file (if available)" ));
67
67
68
+ // Basic input subpanel
69
+ basic = new JPanel ();
70
+ basic .setLayout (new GridLayout (0 , 1 ));
71
+ gtinput = new InputFileSelector (forecolor , bgcolor ,
72
+ border , "ground-truth file" );
73
+ ocrinput = new InputFileSelector (forecolor , bgcolor ,
74
+ border , "ocr file" );
75
+ basic .add (gtinput );
76
+ basic .add (ocrinput );
77
+
78
+ // Advanced options subpanel
79
+ advanced = new JPanel ();
80
+ advanced .setLayout (new GridLayout (0 , 1 ));
81
+ advanced .setBorder (BorderFactory .createEmptyBorder (0 , 0 , 0 , 0 ));
82
+ eqinput = new InputFileSelector (forecolor , bgcolor ,
83
+ border , "Unicode character equivalences file (if available)" );
84
+
85
+ compatibility = new JCheckBox ();
86
+ compatibility .setText ("Unicode compatibility of characters" );
87
+ compatibility .setForeground (forecolor );
88
+ compatibility .setBackground (bgcolor );
89
+ compatibility .setAlignmentX (Component .LEFT_ALIGNMENT );
90
+ /*
91
+ String[] options = {"unknown", "utf8", "iso8859-1", "windows-1252"};
92
+ Pulldown encoding = new Pulldown(forecolor, bgcolor, null,
93
+ "Text encoding:", options);
94
+ */
95
+ advanced .add (eqinput );
96
+ advanced .add (compatibility );
97
+ //advanced.add(encoding);
98
+ advanced .setVisible (false );
99
+
100
+ // Actions subpanel
101
+ actions = new JPanel ();
102
+ actions .setLayout (new BoxLayout (actions , BoxLayout .X_AXIS ));
103
+ actions .setBackground (Color .LIGHT_GRAY );
104
+ // Switch for more more
105
+ more = new JCheckBox ("Advanced options" );
106
+ more .setForeground (forecolor );
107
+ more .setBackground (Color .LIGHT_GRAY );
108
+ more .addActionListener (this );
109
+ actions .add (more , BorderLayout .WEST );
110
+ // Space between checkbox and button
111
+ actions .add (Box .createHorizontalGlue ());
68
112
// Button with inverted colors
69
113
trigger .setForeground (bgcolor );
70
114
trigger .setBackground (forecolor );
71
115
trigger .addActionListener (this );
72
- pane .add (trigger );
116
+ actions .add (trigger );
73
117
74
- repaint ();
75
- }
76
-
77
- /**
78
- *
79
- * @return true if all required files have been selected
80
- */
81
- private boolean checkInputFiles () {
82
- boolean ready = true ;
83
- Component [] components = pane .getComponents ();
84
- boolean [] required = {true , true , false };
85
-
86
- for (int n = 0 ; n < 3 ; ++n ) {
87
- InputFileSelector ifs = (InputFileSelector ) components [n ];
88
- if (ifs .ready ()) {
89
- files [n ] = ifs .getFile ();
90
- } else if (required [n ]) {
91
- ifs .shade (Color .decode ("#fffacd" ));
92
- ifs .repaint ();
93
- ready = false ;
94
- }
95
- }
96
- return ready ;
118
+ // Fianlly, put everything together
119
+ pane .add (basic );
120
+ pane .add (advanced );
121
+ pane .add (actions );
122
+ setVisible (true );
97
123
}
98
124
99
125
/**
@@ -111,30 +137,35 @@ private void warning(String text) {
111
137
112
138
@ Override
113
139
public void actionPerformed (ActionEvent e ) {
114
- JButton pressed = ( JButton ) e .getSource ();
115
-
116
- if ( pressed == trigger ) {
117
- boolean checked = checkInputFiles ();
118
- if ( checked ) {
119
- File dir = files [ 1 ] .getParentFile ();
120
- String name = files [ 1 ] .getName ().replaceAll ("\\ .\\ w+" , "" )
140
+ if ( e .getSource () == trigger ) {
141
+ if ( gtinput . ready () && ocrinput . ready ()) {
142
+ File gtfile = gtinput . getFile ();
143
+ File ocrfile = ocrinput . getFile ();
144
+ File eqfile = eqinput . getFile ();
145
+ File dir = ocrfile .getParentFile ();
146
+ String name = ocrfile .getName ().replaceAll ("\\ .\\ w+" , "" )
121
147
+ "_report.html" ;
122
148
File preselected = new File (name );
123
149
OutputFileSelector selector = new OutputFileSelector ();
150
+ File outfile = selector .choose (dir , preselected );
124
151
125
- files [ 3 ] = selector . choose ( dir , preselected );
126
- if ( files [ 3 ] != null ) {
152
+ if ( outfile != null ) {
153
+ Report report ;
127
154
try {
128
155
/*
129
156
Report report = new Report(files[0], null,
130
157
files[1], null,
131
158
files[2]);
132
159
*/
133
- Batch batch = new Batch (files [0 ], files [1 ]);
134
- Report report = new Report (batch , null , null , files [2 ]);
135
- report .write (files [3 ]);
160
+ Batch batch = new Batch (gtfile , ocrfile );
161
+ CharFilter filter = (eqfile == null )
162
+ ? new CharFilter ()
163
+ : new CharFilter (eqfile );
164
+ filter .setCompatibility (compatibility .isSelected ());
165
+ report = new Report (batch , null , null , filter );
166
+ report .write (outfile );
136
167
if (Desktop .isDesktopSupported ()) {
137
- URI uri = new URI ("file://" + files [ 3 ] .getCanonicalPath ());
168
+ URI uri = new URI ("file://" + outfile .getCanonicalPath ());
138
169
System .out .println (uri );
139
170
Desktop .getDesktop ().browse (uri );
140
171
}
@@ -146,7 +177,18 @@ public void actionPerformed(ActionEvent e) {
146
177
Logger .getLogger (MainGUI .class .getName ()).log (Level .SEVERE , null , ex );
147
178
}
148
179
}
180
+ } else {
181
+ gtinput .checkout ();
182
+ ocrinput .checkout ();
183
+ }
184
+ } else if (e .getSource () == more ) {
185
+ boolean marked = more .isSelected ();
186
+ if (marked ) {
187
+ setSize (400 , 300 );
188
+ } else {
189
+ setSize (400 , 200 );
149
190
}
191
+ advanced .setVisible (marked );
150
192
}
151
193
}
152
194
0 commit comments