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