-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionTab.java
More file actions
318 lines (276 loc) · 7.23 KB
/
OptionTab.java
File metadata and controls
318 lines (276 loc) · 7.23 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
/** @author Gergely Kota
OptionTabs hold OptionPanels and combine their info to run Splats
*/
public abstract class OptionTab extends JPanel implements Logger, ActionListener
{
private SplatFile workingDirectory;
private JButton go, help;
private boolean ready;
private JTextArea info, log;
private InfoPanel logp;
private JPanel content, jp;
private HeaderPanel header;
private ArrayList files;
private final static ArrayList createdDirs = new ArrayList();
private AbstractWebSearch current;
private String title;
private ProgressBar progressBar;
public OptionTab(String t)
{
title = t;
ready = true;
setLayout(new BorderLayout());
jp = new JPanel(new GridLayout(2,1));
setButtons();
JPanel jpbuffer = new JPanel(new BorderLayout());
jpbuffer.add(jp, BorderLayout.NORTH);
info = new JTextArea();
info.setEditable(false);
log = new JTextArea();
log.setEditable(false);
files = new ArrayList();
JPanel texts = new JPanel(new BorderLayout());
texts.add(new InfoPanel(info, "Info"), BorderLayout.NORTH);
texts.add(logp = new InfoPanel(log, "Log"), BorderLayout.CENTER);
texts.add(progressBar = new ProgressBar(), BorderLayout.SOUTH);
// this is where the local-to-tab options used to be
header = new HeaderPanel();
// texts.add(header, BorderLayout.SOUTH);
JPanel bottom = new JPanel(new BorderLayout());
bottom.add(texts, BorderLayout.CENTER);
add(bottom, BorderLayout.CENTER);
content = new JPanel(new BorderLayout());
// put go and help on the side
content.add(jpbuffer, BorderLayout.EAST);
add(content, BorderLayout.NORTH);
Config.addActionListener(this);
}
public String getTitle()
{
return title;
}
public ProgressBar getProgressBar()
{
return progressBar; //header.getProgressBar();
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals("helpbutton"))
setButtons();
if(ae.getSource().equals("gobutton"))
setButtons();
}
public void setButtons()
{
jp.removeAll();
go = new JButton();
jp.add(go, BorderLayout.NORTH);
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(ready)
go();
else
killSearch();
}
});
current = null;
help = new JButton();
jp.add(help, BorderLayout.SOUTH);
help.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String s = OptionTab.this.getClass().getName();
HelpFrame.getTop().goTopic(s).show();
}
});
if(!GUtil.buttonFix(go, ready? Color.green: Color.red, ready? Config.read("gobutton"): Config.read("stopbutton")))
go.setText(ready? "Go": "Stop");
if(!GUtil.buttonFix(help, Color.yellow, Config.read("helpbutton")))
help.setText("Help");
}
public void setWebSearch(AbstractWebSearch awb)
{
current = awb;
}
private void killSearch()
{
if(current == null)
return;
current.halt();
log("Terminated WebSearch");
setGo(true);
}
public void goClick()
{
go.doClick();
}
public void setGo(boolean x)
{
// go.setEnabled(x);
ready = x;
setButtons();
}
public abstract void go();
public abstract void setup();
public void cleanup()
{
if("true".equals(Config.read("deleteonexit")))
for(int i = 0; i < files.size(); i++)
((SplatFile) files.get(i)).deleteAll();
}
public void log(String s)
{
if(!s.endsWith("\n"))
s += "\n";
log.append(time() + s);
logp.scrollToBottom();
}
public String time()
{
GregorianCalendar gc = new GregorianCalendar();
String hour = "" + gc.get(gc.HOUR_OF_DAY);
String minute = "" + gc.get(gc.MINUTE);
while(minute.length() < 2)
minute = "0" + minute;
String second = "" + gc.get(gc.SECOND);
while(second.length() < 2)
second = "0" + second;
return hour + ":" + minute + ":" + second + " - ";
}
public void setDescription(String s)
{
info.setText(s);
}
public void setCenter(Component c)
{
content.add(c, BorderLayout.CENTER);
}
public void setAdvanced(Component c)
{
header.addContent(c);
}
public SplatFile getWorkingDirectory()
{
if(workingDirectory == null)
workingDirectory = createDirectory();
return workingDirectory;
}
public void launch(DocumentComparisonResult dcr)
{
new HTMLFrame(dcr).show();
}
public void setWorkingDirectory(SplatFile f)
{
if(!f.isDirectory())
f.mkdirs();
else
f.protect();
files.add(workingDirectory = f);
}
public SplatFile createDirectory()
{
String s = Config.read("workingdir");
int counter = 0;
File toRet = new File(s + "/Download_" + counter++);
do
{
createdDirs.add(toRet);
toRet = new File(s + "/Download_" + counter++);
}
while(toRet.exists() || alreadyCreated(toRet));
createdDirs.add(toRet);
return new SplatFile(toRet, "");
}
private boolean alreadyCreated(File f)
{
for(int i = 0; i < createdDirs.size(); i++)
if(f.getName().equals(((File)createdDirs.get(i)).getName()))
return true;
return false;
}
/* -------------------------------------------- */
/* -------------------------------------------- */
private class HeaderPanel extends JPanel
{
private JButton toggle;
private Component center;
private boolean on;
private ProgressBar pb;
public HeaderPanel()
{
// make progress bar not exist by default
this(false);
}
public HeaderPanel(boolean progress)
{
setLayout(new BorderLayout());
add(GUtil.filler(4), BorderLayout.NORTH);
add(GUtil.filler(4), BorderLayout.SOUTH);
add(GUtil.filler(4), BorderLayout.EAST);
add(GUtil.filler(4), BorderLayout.WEST);
final JPanel inner = new JPanel(new BorderLayout());
toggle = new JButton(title + " Parameters");
toggle.setEnabled(false);
on = false;
toggle.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
OptionTab.this.invalidate();
if(on)
inner.remove(center);
else
inner.add(center, BorderLayout.CENTER);
on = !on;
OptionTab.this.validate();
OptionTab.this.repaint();
}
});
JPanel north = new JPanel(new BorderLayout());
north.add(toggle, BorderLayout.WEST);
if(progress)
north.add(pb = new ProgressBar(), BorderLayout.CENTER);
inner.add(north, BorderLayout.SOUTH);
// inner.add(center, BorderLayout.CENTER);
add(inner, BorderLayout.CENTER);
}
public ProgressBar getProgressBar()
{
return pb;
}
public void addContent(Component c)
{
toggle.setEnabled(true);
center = c;
ComponentedConfigWindow.addComponent(center, getTitle() + " Parameters");
// add(center, BorderLayout.CENTER);
}
}
/* -------------------------------------------- */
/* -------------------------------------------- */
private class InfoPanel extends JPanel
{
private JScrollPane jsp;
private int BIG = 100000;
public InfoPanel(JTextArea jtf, String title)
{
setLayout(new BorderLayout());
JPanel buffer = new JPanel(new BorderLayout());
buffer.add(new JLabel(title.trim() + ":"), BorderLayout.WEST);
add(buffer, BorderLayout.NORTH);
jsp = new JScrollPane();
jsp.getViewport().add(jtf);
add(jsp, BorderLayout.CENTER);
}
public void scrollToBottom()
{
jsp.scrollRectToVisible(new Rectangle(0, BIG/2, BIG, BIG));
}
}
public static void main(String[] args)
{
// o.getWorkingDirectory();
}
}