-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebOptionPanel.java
More file actions
225 lines (186 loc) · 5.06 KB
/
WebOptionPanel.java
File metadata and controls
225 lines (186 loc) · 5.06 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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
/** @author Gergely Kota
WebOptionPanel allows the user to select a module and enter
information into textfields for it, specialized for WebSearches
*/
public class WebOptionPanel extends OptionPanel
{
// need to have a list of existing classes
// need to display textfield for each option ... how do??
private WebFields wf;
public WebOptionPanel(OptionTab ot)
{
super(WebSearch.class, ot);
setCenter(wf = new WebFields());
setClass();
Config.addActionListener(this);
}
private void setClass()
{
try
{
setClass(Class.forName(Config.read("websearch")));
}
catch(Exception e) {setClass(WebSearch.class);}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals("websearch"))
setClass();
}
public Object result()
{
return wf.result();
}
public Object result(Object o)
{
return wf.result((WebSearch)o);
}
public void setRecycleDir(boolean x)
{
wf.setRecycleDir(x);
}
public void setDirectory()
{
wf.setDirectory();
}
private class WebFields extends JPanel implements ActionListener
{
private SelectiveInfo regex, destination, depth, num, time;
private boolean freshDir = false;
public WebFields()
{
regex = new SelectiveInfo("Exclude", false, 150, true);
regex.setDescription("Enter regular expressions to filter");
destination = new SelectiveInfo("Download Location", false, 150, true);
destination.setDescription("Select a directory to download files to");
setDirectory();
depth = new SelectiveInfo("Max Search Depth", false, 150, true);
depth.setDescription("Select the depth that links will be followed to");
depth.set(Config.read("maxdepth"));
num = new SelectiveInfo("Max Articles", false, 150, true);
num.setDescription("Select the number of articles to download");
num.set(Config.read("maxdownloads"));
time = new SelectiveInfo("Max Time", false, 150, true);
time.setDescription("Select the maximum time (seconds) the websearch should run for");
time.set(Config.read("timeout"));
setLayout(new BorderLayout());
JPanel entries = new JPanel(new GridLayout(5,1));
entries.add(destination);
entries.add(depth);
entries.add(num);
entries.add(time);
entries.add(regex);
add(entries, BorderLayout.CENTER);
Config.addActionListener(this);
/* JButton s = new JButton("Select All");
s.addActionListener(new ButtonTask(true));
JButton ds = new JButton("Deselect All");
ds.addActionListener(new ButtonTask(false));
JPanel south = new JPanel(new BorderLayout());
south.add(s, BorderLayout.WEST);
south.add(ds, BorderLayout.EAST);
add(south, BorderLayout.SOUTH);
*/
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals("maxdownloads"))
num.set(Config.read("maxdownloads"));
if(ae.getSource().equals("timeout"))
time.set(Config.read("timeout"));
if(ae.getSource().equals("maxdepth"))
depth.set(Config.read("maxdepth"));
}
public void setRecycleDir(boolean x)
{
freshDir = x;
}
private void setDirectory()
{
if(freshDir)
return;
destination.set(getOwner().createDirectory().getName());
freshDir = true;
}
public class ButtonTask implements ActionListener
{
private boolean set;
public ButtonTask(boolean x)
{
set = x;
}
public void actionPerformed(ActionEvent ae)
{
regex.setEnabled(set);
destination.setEnabled(set);
num.setEnabled(set);
depth.setEnabled(set);
time.setEnabled(set);
}
}
public AbstractWebSearch result()
{
AbstractWebSearch ws;
try
{
Class c = getSelectedClass();
ws = (AbstractWebSearch) c.newInstance();
}
catch(Exception e) {e.printStackTrace(); return null;}
return result(ws);
}
public AbstractWebSearch result(AbstractWebSearch ws)
{
String reges, destinationS, depthS, numS, timeS;
reges = regex.read();
destinationS = destination.read();
depthS = depth.read();
numS = num.read();
timeS = time.read();
try
{
((RegExWebSearch) ws).setRegEx(reges);
getOwner().log("Set filtered expression to " + reges);
}
catch(Exception e)
{
getOwner().log("Current websearch does not support regular expression filtering.");
}
if(destinationS != null && !destinationS.equals(""))
{
SplatFile f = new SplatFile(destinationS);
// delete at the end only if starting a new directory
// if(!f.isDirectory())
// f.deleteOnExit();
getOwner().setWorkingDirectory(f);
ws.setDownloadLocation(f);
getOwner().log("Set download location to " + destinationS);
}
try
{
ws.setDownloads(Integer.parseInt(numS));
getOwner().log("Set number of downloads to " + numS);
}
catch(Exception e) {}
try
{
ws.setDepth(Integer.parseInt(depthS));
getOwner().log("Set maximum depth to " + depthS);
}
catch(Exception e) {}
try
{
ws.setTime(Integer.parseInt(timeS));
getOwner().log("Set timeout to " + timeS + " seconds");
}
catch(Exception e) {}
// freshDir = false;
setDirectory();
return ws;
}
}
}