-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparisonOptionPanel.java
More file actions
103 lines (87 loc) · 2.19 KB
/
ComparisonOptionPanel.java
File metadata and controls
103 lines (87 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.reflect.*;
import java.io.*;
import java.awt.event.*;
/** @author Gergely Kota
ComparisonOptionPanel allows choice of comparisons and
lets user select the tolerance
*/
public class ComparisonOptionPanel extends OptionPanel implements ActionListener
{
private CompPanel cp;
public ComparisonOptionPanel(OptionTab ot)
{
super(DocumentComparison.class, ot);
setCenter(cp = new CompPanel());
setClass();
Config.addActionListener(this);
}
private void setClass()
{
try
{
setClass(Class.forName(Config.read("comparison")));
}
catch(Exception e) {setClass(SentenceComparison.class);}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals("comparison"))
setClass();
}
public Object result()
{
return cp.result();
}
public Object result(Object o)
{
return cp.result((DocumentComparison)o);
}
private class CompPanel extends JPanel implements ActionListener
{
private SelectiveInfo tol;
public CompPanel()
{
setLayout(new BorderLayout());
JPanel filler = new JPanel();
add(tol = new SelectiveInfo("Tolerance", false, 150, true), BorderLayout.NORTH);
tol.set(Config.read("tolerance"));
tol.setDescription("[1, 100] indicating needed similarity to be considered cheating");
Config.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals("tolerance"))
tol.set(Config.read("tolerance"));
}
public Object result()
{
DocumentComparison dc = null;
try
{
Class c = getSelectedClass();
Constructor cons = c.getConstructor(new Class[]{File.class});
File f = getOwner().getWorkingDirectory();
dc = (DocumentComparison) cons.newInstance(new Object[]{f});
getOwner().log("Using " + c.getName());
}
catch(Exception e) {return null;}
return result(dc);
}
public Object result(DocumentComparison dc)
{
try
{
int i = Integer.parseInt(tol.read());
dc.setTolerance(i);
getOwner().log("Set comparison tolerance to " + dc.getTolerance());
}
catch(Exception e) {}
dc.read();
Debug.println("Read DocumentCompnarison " + dc);
return dc;
}
}
}