Skip to content

Commit bb88e51

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

File tree

10 files changed

+373
-284
lines changed

10 files changed

+373
-284
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>eu.digitisation</groupId>
55
<artifactId>ocrevalUAtion</artifactId>
66
<name>ocrevalUAtion</name>
7-
<version>1.2.6</version>
7+
<version>1.2.7</version>
88
<packaging>jar</packaging>
99
<description>OCR Evaluation Tool</description>
1010
<organization>

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: 97 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import eu.digitisation.gui.InputFileSelector;
2121
import eu.digitisation.gui.OutputFileSelector;
2222
import eu.digitisation.io.Batch;
23+
import eu.digitisation.io.CharFilter;
2324
import eu.digitisation.ocrevaluation.Report;
2425
import java.awt.*;
2526
import javax.swing.*;
@@ -37,63 +38,88 @@ public class MainGUI extends JFrame implements ActionListener {
3738
static final long serialVersionUID = 1L;
3839
static final Color bgcolor = Color.decode("#FAFAFA");
3940
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
4454

4555
public MainGUI() {
4656

4757
pane = getContentPane();
4858
trigger = new JButton("Generate report");
49-
files = new File[4];
5059

51-
// frame attributes
60+
// JFrame attributes
5261
setTitle("Input files");
53-
setBackground(Color.decode("#FAFAFA"));
54-
setSize(400, 300);
62+
setBackground(bgcolor);
63+
setSize(400, 200);
5564
setDefaultCloseOperation(EXIT_ON_CLOSE);
56-
setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
65+
setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
5766
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)"));
6767

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());
68112
// Button with inverted colors
69113
trigger.setForeground(bgcolor);
70114
trigger.setBackground(forecolor);
71115
trigger.addActionListener(this);
72-
pane.add(trigger);
116+
actions.add(trigger);
73117

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);
97123
}
98124

99125
/**
@@ -111,30 +137,35 @@ private void warning(String text) {
111137

112138
@Override
113139
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+", "")
121147
+ "_report.html";
122148
File preselected = new File(name);
123149
OutputFileSelector selector = new OutputFileSelector();
150+
File outfile = selector.choose(dir, preselected);
124151

125-
files[3] = selector.choose(dir, preselected);
126-
if (files[3] != null) {
152+
if (outfile != null) {
153+
Report report;
127154
try {
128155
/*
129156
Report report = new Report(files[0], null,
130157
files[1], null,
131158
files[2]);
132159
*/
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);
136167
if (Desktop.isDesktopSupported()) {
137-
URI uri = new URI("file://" + files[3].getCanonicalPath());
168+
URI uri = new URI("file://" + outfile.getCanonicalPath());
138169
System.out.println(uri);
139170
Desktop.getDesktop().browse(uri);
140171
}
@@ -146,7 +177,18 @@ public void actionPerformed(ActionEvent e) {
146177
Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
147178
}
148179
}
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);
149190
}
191+
advanced.setVisible(marked);
150192
}
151193
}
152194

0 commit comments

Comments
 (0)