Skip to content

Commit 9535c15

Browse files
committed
Graphic interface now hides advanced (Unicode compatibility) options
1 parent b12a0e0 commit 9535c15

File tree

9 files changed

+374
-283
lines changed

9 files changed

+374
-283
lines changed

src/main/java/eu/digitisation/Main.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.digitisation;
22

33
import eu.digitisation.io.Batch;
4+
import eu.digitisation.io.CharFilter;
45
import eu.digitisation.ocrevaluation.Report;
56
import java.io.File;
67
import java.io.InvalidObjectException;
@@ -15,7 +16,7 @@ public class Main {
1516
static final String helpMsg = "Usage:\t"
1617
+ "ocrevalUAtion -gt file1 [encoding] "
1718
+ "-ocr file2 [encoding] "
18-
+ "-d output_dir [-r equivalences_file]";
19+
+ "-d output_dir [-r equivalences_file] [-c]";
1920

2021
private static void exit_gracefully() {
2122
System.err.println(helpMsg);
@@ -34,7 +35,8 @@ public static void main(String[] args) {
3435
String gtencoding = null;
3536
String ocrencoding = null;
3637
File workingDirectory = null; // working directory
37-
38+
boolean compatibility = false; // Unicode comaptibility mode
39+
3840
// Read parameters (String switch needs Java 1.7 or later)
3941
for (int n = 0; n < args.length; ++n) {
4042
String arg = args[n];
@@ -56,6 +58,8 @@ public static void main(String[] args) {
5658
repfile = new File(args[++n]);
5759
} else if (arg.equals("-o")) {
5860
ofile = new File(args[++n]);
61+
} else if (arg.equals("-c")) {
62+
compatibility = true;
5963
} else {
6064
System.err.println("Unrecognized option " + arg);
6165
exit_gracefully();
@@ -85,8 +89,11 @@ public static void main(String[] args) {
8589
}
8690
// Report report = new Report(gtfile, gtencoding, ocrfile, ocrencoding, repfile);
8791
Batch batch = new Batch(gtfile, ocrfile); // accepts also directories
88-
Report report = new Report(batch, gtencoding, ocrencoding, repfile);
89-
92+
CharFilter filter = (repfile == null)
93+
? new CharFilter()
94+
: new CharFilter(repfile);
95+
filter.setCompatibility(compatibility);
96+
Report report = new Report(batch, gtencoding, ocrencoding, filter);
9097
report.write(ofile);
9198
} catch (InvalidObjectException ex) {
9299
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

src/main/java/eu/digitisation/MainGUI.java

Lines changed: 99 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import eu.digitisation.gui.InputFileSelector;
2121
import eu.digitisation.gui.OutputFileSelector;
22+
import eu.digitisation.gui.Pulldown;
2223
import eu.digitisation.io.Batch;
24+
import eu.digitisation.io.CharFilter;
2325
import eu.digitisation.ocrevaluation.Report;
2426
import java.awt.*;
2527
import javax.swing.*;
@@ -31,69 +33,95 @@
3133
import java.util.logging.Level;
3234
import java.util.logging.Logger;
3335
import javax.swing.border.Border;
36+
import javax.swing.border.EmptyBorder;
3437

3538
public class MainGUI extends JFrame implements ActionListener {
3639

3740
static final long serialVersionUID = 1L;
3841
static final Color bgcolor = Color.decode("#FAFAFA");
3942
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
4456

4557
public MainGUI() {
4658

4759
pane = getContentPane();
4860
trigger = new JButton("Generate report");
49-
files = new File[4];
5061

51-
// frame attributes
62+
// JFrame attributes
5263
setTitle("Input files");
53-
setBackground(Color.decode("#FAFAFA"));
54-
setSize(400, 300);
64+
setBackground(bgcolor);
65+
setSize(400, 200);
5566
setDefaultCloseOperation(EXIT_ON_CLOSE);
56-
setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
67+
setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
5768
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)"));
6769

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());
68114
// Button with inverted colors
69115
trigger.setForeground(bgcolor);
70116
trigger.setBackground(forecolor);
71117
trigger.addActionListener(this);
72-
pane.add(trigger);
118+
actions.add(trigger);
73119

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);
97125
}
98126

99127
/**
@@ -111,30 +139,35 @@ private void warning(String text) {
111139

112140
@Override
113141
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+", "")
121149
+ "_report.html";
122150
File preselected = new File(name);
123151
OutputFileSelector selector = new OutputFileSelector();
152+
File outfile = selector.choose(dir, preselected);
124153

125-
files[3] = selector.choose(dir, preselected);
126-
if (files[3] != null) {
154+
if (outfile != null) {
155+
Report report;
127156
try {
128157
/*
129158
Report report = new Report(files[0], null,
130159
files[1], null,
131160
files[2]);
132161
*/
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);
136169
if (Desktop.isDesktopSupported()) {
137-
URI uri = new URI("file://" + files[3].getCanonicalPath());
170+
URI uri = new URI("file://" + outfile.getCanonicalPath());
138171
System.out.println(uri);
139172
Desktop.getDesktop().browse(uri);
140173
}
@@ -146,7 +179,18 @@ public void actionPerformed(ActionEvent e) {
146179
Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
147180
}
148181
}
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);
149192
}
193+
advanced.setVisible(marked);
150194
}
151195
}
152196

0 commit comments

Comments
 (0)