-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorOptionTab.java
More file actions
257 lines (224 loc) · 6.29 KB
/
AuthorOptionTab.java
File metadata and controls
257 lines (224 loc) · 6.29 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
/** @author Gergely Kota
AuthorOptionTab allows the user to select a set of authors, their webpages
and the departments they belong to.
*/
public class AuthorOptionTab extends OptionTab
{
private PackWindow window;
private WebOptionPanel web;
private ComparisonOptionPanel compare;
public AuthorOptionTab()
{
// JScrollPane jsp = new JScrollPane();
// jsp.getViewport().add();
super("Author Search");
setCenter(window = new PackWindow());
web = new WebOptionPanel(this);
compare = new ComparisonOptionPanel(this);
JPanel buffer = new JPanel(new BorderLayout());
buffer.add(web, BorderLayout.NORTH);
buffer.add(compare, BorderLayout.SOUTH);
buffer.add(GUtil.filler(10), BorderLayout.CENTER);
setAdvanced(buffer);
setDescription("Enter authors and their websites, along with a File to compare");
}
public void setup()
{
window.setup();
web.setup();
}
public void go()
{
log("****************************");
SplatFile temp = window.getFile();
if(temp == null)
{
log("You must enter a file to compare");
return;
}
AbstractWebSearch wst = window.result();
final AbstractWebSearch ws = (AbstractWebSearch) web.result(wst);
new RepaintRunner(ws).start();
}
/* --------------------------------------------- */
/* --------------------------------------------- */
private class RepaintRunner extends Thread
{
private AbstractWebSearch awb;
public RepaintRunner(AbstractWebSearch a)
{
awb = a;
}
public void run()
{
setGo(false);
try
{
// copy the picked file to the workingdirectory
log("This module is under development and does not work properly");
SplatFile temp = window.getFile();
String path = getWorkingDirectory().getName();
log("Working dir is " + path);
String s = path + "/" + temp.getName();
temp.copyTo(new File(s));
// this is the modified name of the file
String ss = s.substring(0, s.lastIndexOf("."));
String end = Config.read("endtype");
if(end == null)
end = "txt";
ss = ss + "." + end;
temp = new SplatFile(ss);
log("Comparing to " + temp.getAbsolutePath());
getWorkingDirectory().protect();
// all contents of this directory are now protected;
// anything added from here on is not protected
awb.addProgressListener(getProgressBar());
awb.addLogger(AuthorOptionTab.this);
setWebSearch(awb);
awb.startSearch();
log("Converting files to text");
FileConverter fc = new FileConverter(getWorkingDirectory());
fc.addLogger(AuthorOptionTab.this);
fc.convert();
log("Starting a new Comparison");
DocumentComparison dc = (DocumentComparison) compare.result();
dc.addProgressListener(getProgressBar());
dc.addLogger(AuthorOptionTab.this);
log("Showing Comparison Results");
new HTMLFrame(dc.compare(temp)).show();
}
catch(Exception e)
{
log("Error: " + e.toString());
log("Search failed, file is probably invalid");
}
setGo(true);
}
}
private class PackWindow extends JScrollPane
{
private Pack[] packs;
private SelectiveInfo file;
public PackWindow()
{
this(6);
}
public PackWindow(int n)
{
file = new SelectiveInfo("File to Compare", false, 120);
JButton jb = new JButton("Browse");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
File f = FileFrame.getOpenFile();
if(f != null)
file.set(f.getAbsolutePath());
}
});
JPanel top = new JPanel(new BorderLayout());
top.add(file, BorderLayout.CENTER);
top.add(jb, BorderLayout.EAST);
JPanel panel = new JPanel(new GridLayout((n+1)/2,2));
JPanel buffer = new JPanel(new BorderLayout());
packs = new Pack[n];
for(int i = 0; i < n; i++)
panel.add(packs[i] = new Pack());
buffer.add(panel, BorderLayout.CENTER);
buffer.add(top, BorderLayout.NORTH);
getViewport().add(buffer);
// setPreferredSize(new Dimension(150,150));
}
public void setup()
{
for(int i = 0; i < packs.length; i++)
packs[i].clear();
}
public AbstractWebSearch result()
{
AbstractWebSearch temp = new WebSearch();
for(int i = 0; i < packs.length; i++)
temp = packs[i].setParams(temp);
return temp;
}
public SplatFile getFile()
{
String s = file.read();
if(s == null || "".equals(s))
return null;
return new SplatFile(s);
}
}
/* --------------------------------------------- */
/* --------------------------------------------- */
private class Pack extends JPanel
{
private SelectiveInfo author, url; //, dept;
private JCheckBox jcb;
private final int BORDER = 10;
// commented out dept related things
public Pack()
{
author = new SelectiveInfo("Author", false, 100);
url = new SelectiveInfo("Website", false, 100);
// dept = new SelectiveInfo("Department", false, 100);
setLayout(new BorderLayout());
JPanel center = new JPanel(new GridLayout(2,1));
jcb = new JCheckBox("", true);
center.add(author);
center.add(url);
JPanel jp = new JPanel(new BorderLayout());
jp.add(center, BorderLayout.CENTER);
jp.add(jcb, BorderLayout.WEST);
// center.add(dept);
add(GUtil.filler(BORDER), BorderLayout.NORTH);
add(GUtil.filler(BORDER), BorderLayout.SOUTH);
add(GUtil.filler(BORDER), BorderLayout.WEST);
add(GUtil.filler(BORDER), BorderLayout.EAST);
add(jp, BorderLayout.CENTER);
}
public AbstractWebSearch setParams(AbstractWebSearch w)
{
if(!jcb.isSelected())
return w;
if(w == null)
return null;
// set stuff on w from infos
String a = author.read();
String u = url.read();
// String d = dept.read();
if(!"".equals(a))
{
// set author information
log("Added author " + a);
}
if(!"".equals(u))
{
u = FUtil.webfix(u);
url.set(u);
// set a website to start on
log("Added website " + u + " for author " + a);
}
// if(!"".equals(d))
// log("Added department " + d + " for author " + a);
return w;
}
public void clear()
{
author.clear();
url.clear();
// dept.clear();
}
}
/* --------------------------------------------- */
/* --------------------------------------------- */
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setSize(800, 600);
jf.getContentPane().add(new AuthorOptionTab());
jf.show();
}
}