source: trunk/gli/src/org/greenstone/gatherer/gui/MirrorPane.java@ 5181

Last change on this file since 5181 was 5157, checked in by jmt12, 21 years ago

Fix 203B008

  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import javax.swing.*;
41import javax.swing.border.*;
42import javax.swing.event.*;
43import javax.swing.tree.*;
44import org.greenstone.gatherer.Gatherer;
45import org.greenstone.gatherer.Message;
46import org.greenstone.gatherer.WGet;
47import org.greenstone.gatherer.file.FileSystemModel;
48import org.greenstone.gatherer.gui.Filter;
49import org.greenstone.gatherer.gui.GComboBox;
50import org.greenstone.gatherer.gui.tree.DragTree;
51import org.greenstone.gatherer.util.DragGroup;
52import org.greenstone.gatherer.util.GURL;
53import org.greenstone.gatherer.util.TreeSynchronizer;
54import org.greenstone.gatherer.util.Utility;
55/**
56 * @author John Thompson, Greenstone Digital Library, University of Waikato
57 * @version 2.1
58 */
59public class MirrorPane
60 extends JPanel
61 implements ActionListener {
62
63 private ButtonGroup destination_folder_options;
64 private DragTree workspace_tree = null;
65 private FileSystemModel model = null;
66 /** The filter currently applied to the workspace tree. */
67 private Filter workspace_filter = null;
68
69 private ImageIcon thumbnail;
70
71 private JButton download;
72 private JButton view_selector;
73
74 private JCheckBox download_hidden;
75 private JCheckBox higher_directories;
76 private JCheckBox infinite;
77 private JCheckBox overwrite_existing;
78 private JCheckBox remove_failed;
79 private JCheckBox same_host;
80
81 private JScrollPane list_scroll;
82 private JScrollPane workspace_scroll;
83
84 private JTextField download_depth;
85 private JTextField number_downloads;
86 private JTextField number_each_host;
87 private JTextField source_url;
88
89 private JToggleButton destination_private;
90 private JToggleButton destination_shared;
91
92
93 /** Ensures that expansion and selection events between workspace trees based on the same model are synchronized. */
94 private TreeSynchronizer tree_sync = null;
95 /** A reference to the object that provides JNI ability. */
96 private WGet getter;
97 /** The default size of a label in the interface. */
98 static final private Dimension LABEL_SIZE = new Dimension(100,30);
99 /** The default size of the tree in the interface. */
100 static final private Dimension TREE_SIZE = new Dimension(250, 430);
101
102 public MirrorPane(TreeSynchronizer workspace_tree_sync) {
103 this.tree_sync = workspace_tree_sync;
104 getter = new WGet();
105 getter.start();
106 }
107
108 public void actionPerformed(ActionEvent event) {
109 Object event_source = event.getSource();
110 if(event_source == download) {
111 // Check we have a valid url.
112 GURL target_gurl = new GURL(source_url.getText());
113 if(target_gurl.getURL() != null) {
114 // Update configuration settings.
115 Gatherer.config.set("mirroring.page_requisites", false, download_hidden.isSelected());
116 Gatherer.config.set("mirroring.no_parents", false, !higher_directories.isSelected());
117 Gatherer.config.set("mirroring.clobber", false, overwrite_existing.isSelected());
118 Gatherer.config.set("mirroring.remove_failed", false, remove_failed.isSelected());
119 Gatherer.config.set("mirroring.other_hosts", false, !same_host.isSelected());
120 // Depth
121 if(infinite.isSelected()) {
122 Gatherer.config.setInt("mirroring.depth", false, -1);
123 }
124 else if(download_depth.getText().length() > 0){
125 //Gatherer.println("Download_depth = " + download_depth.getText().trim());
126 Gatherer.config.setInt("mirroring.depth", false, Integer.parseInt(download_depth.getText().trim()));
127 }
128
129 // Queue download
130 if(destination_shared.isSelected()) {
131 getter.newJob(new GURL(source_url.getText()), model, Utility.CACHE_DIR);
132 }
133 else {
134 getter.newJob(new GURL(source_url.getText()), model, Gatherer.c_man.getCollectionCache());
135 }
136 }
137 // Otherwise indicate to the user that they've done something
138 // wrong.
139 else {
140 // Error message box.
141 String args[] = new String[1];
142 args[0] = source_url.getText();
143 message(Message.ERROR, get("Malformed_URL", args));
144 // Colour source_url red
145 source_url.setForeground(Color.red);
146 }
147
148 }
149 else if(event_source == source_url) {
150 // They've typed something. Change colour back to black
151 source_url.setForeground(Color.black);
152 }
153 }
154
155 public void collectionChanged(boolean ready) {
156 // Some buttons are only enabled if a collection is open.
157 if(ready) {
158 destination_private.setEnabled(true);
159 }
160 else {
161 destination_shared.setSelected(true);
162 destination_private.setEnabled(false);
163 }
164 // Retrieve appropriate workspace
165 model = (FileSystemModel) Gatherer.c_man.getWorkspace();
166 workspace_tree.setModel(model);
167 tree_sync.add(workspace_tree);
168 }
169
170 public void display() {
171 this.setLayout(new BorderLayout());
172
173 // Create
174 JPanel tree_pane = new JPanel(new BorderLayout());
175 tree_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
176 tree_pane.setMinimumSize(TREE_SIZE);
177 tree_pane.setSize(TREE_SIZE);
178 tree_pane.setPreferredSize(TREE_SIZE);
179
180 //Gatherer.println("\tCreating tree_label");
181 JLabel tree_label = new JLabel(get("Workspace_Tree"));
182
183 //Gatherer.println("\tCreating public tree");
184 model = (FileSystemModel) Gatherer.c_man.getWorkspace();
185 workspace_tree = new DragTree("Workspace_Mirror", model, null, true);
186 workspace_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
187 workspace_tree.putClientProperty("JTree.lineStyle", "Angled");
188 workspace_tree.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_background", false));
189 workspace_tree.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false));
190 workspace_tree.setRootVisible(false);
191 workspace_tree.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_background", false));
192 workspace_tree.setTextSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_foreground", false));
193
194 // Add to a dummy drag-group.
195 DragGroup group = new DragGroup();
196 group.add(workspace_tree);
197 group = null;
198
199 workspace_filter = Gatherer.g_man.getFilter(workspace_tree);
200 workspace_filter.setBackground(Gatherer.config.getColor("coloring.workspace_heading_background", false));
201 // Change the default colours of this filters combobox.
202 GComboBox fcb = workspace_filter.getComboBox();
203 fcb.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_background", false));
204 fcb.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false));
205 fcb.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_background", false));
206 fcb.setTextSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_foreground", false));
207 fcb = null;
208
209 tree_pane.add(tree_label, BorderLayout.NORTH);
210 tree_pane.add(new JScrollPane(workspace_tree), BorderLayout.CENTER);
211 tree_pane.add(workspace_filter, BorderLayout.SOUTH);
212
213 // Create control_pane
214 JPanel control_pane = new JPanel(new BorderLayout());
215
216 //Gatherer.println("\tCreating control_label");
217 JLabel control_label = new JLabel(get("Download_Controls"));
218 control_label.setHorizontalAlignment(JLabel.CENTER);
219 control_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
220
221 //central_pane = new JPanel(new GridLayout(7,1));
222 JPanel central_pane = new JPanel();
223 central_pane.setLayout(new BoxLayout(central_pane, BoxLayout.Y_AXIS));
224
225 //Gatherer.println("\tCreating source_url_pane");
226 JPanel source_url_pane = new JPanel(new BorderLayout());
227 JLabel source_url_label = new JLabel(get("Source_URL"));
228 source_url_label.setPreferredSize(LABEL_SIZE);
229 source_url = new JTextField("");
230 source_url_pane.add(source_url_label, BorderLayout.WEST);
231 source_url_pane.add(source_url, BorderLayout.CENTER);
232
233
234 //Gatherer.println("\tCreating download_depth");
235 JPanel download_depth_pane = new JPanel(new FlowLayout(FlowLayout.LEFT));
236 JLabel download_depth_label = new JLabel(get("Download_Depth"));
237 // Default depth. Its an int so we'll do some magic handwaving to magic it into a String. Alakazam.
238 download_depth = new JTextField(Utility.getDepthString(6));
239 infinite = new JCheckBox("Infinite");
240 download_depth_pane.add(download_depth_label);
241 download_depth_pane.add(download_depth);
242 download_depth_pane.add(infinite);
243
244 //Gatherer.println("\tCreating destination_folder");
245 JPanel destination_folder_pane = new JPanel(new FlowLayout(FlowLayout.LEFT));
246 JLabel destination_folder_label = new JLabel(get("Destination_Folder"));
247 destination_folder_options = new ButtonGroup();
248 destination_private = new JToggleButton(get("Destination_Private"));
249 destination_private.setEnabled(Gatherer.c_man != null && Gatherer.c_man.ready());
250 destination_private.setIcon(Utility.OFF_ICON);
251 destination_private.setSelectedIcon(Utility.ON_ICON);
252 destination_private.setSelected(false);
253 destination_private.addActionListener(this);
254 destination_folder_options.add(destination_private);
255 destination_shared = new JToggleButton(get("Destination_Shared"));
256 destination_shared.setIcon(Utility.OFF_ICON);
257 destination_shared.setSelectedIcon(Utility.ON_ICON);
258 destination_shared.setSelected(true);
259 destination_shared.addActionListener(this);
260 destination_folder_options.add(destination_shared);
261 destination_folder_pane.add(destination_folder_label);
262 destination_folder_pane.add(destination_private);
263 destination_folder_pane.add(destination_shared);
264
265 //Gatherer.println("\tCreating download_hidden");
266 download_hidden = new JCheckBox(get("Download_Hidden"));
267 // Why the friken heil is the horizontal alignment called Y?
268 download_hidden.setAlignmentY(Component.LEFT_ALIGNMENT);
269 download_hidden.setSelected(Gatherer.config.get("mirroring.page_requisites", false));
270
271 //Gatherer.println("\tCreating higher_directories");
272 higher_directories = new JCheckBox(get("Higher_Directories"));
273 higher_directories.setSelected(!Gatherer.config.get("mirroring.no_parents", false));
274
275 //Gatherer.println("\tCreating same_host");
276 same_host = new JCheckBox(get("Same_Host"));
277 same_host.setSelected(!Gatherer.config.get("mirroring.other_hosts", false));
278
279 //Gatherer.println("\tCreating overwrite");
280 overwrite_existing = new JCheckBox(get("Overwrite_Existing"));
281 overwrite_existing.setSelected(Gatherer.config.get("mirroring.overwrite", false));
282
283 JLabel further_options = new JLabel(get("Further_Options"));
284 further_options.setHorizontalAlignment(JLabel.LEFT);
285
286 central_pane.add(source_url_pane);
287 central_pane.add(download_depth_pane);
288 central_pane.add(destination_folder_pane);
289
290 JPanel three_mid = new JPanel(new GridLayout(5,1));
291
292 three_mid.add(download_hidden);
293 three_mid.add(higher_directories);
294 three_mid.add(same_host);
295 three_mid.add(overwrite_existing);
296 three_mid.add(further_options);
297
298 central_pane.add(three_mid);
299
300 //Gatherer.println("\tCreating thumbnail");
301 thumbnail = new ImageIcon(Utility.RES_DIR + "no_thumbnail.gif");
302 JLabel thumbnail_holder = new JLabel(thumbnail);
303 // Default thumbnail size.
304 //thumbnail_holder.setSize(Gatherer.config.getDimension("mirroring.thumbnail_size", false));
305 thumbnail_holder.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
306
307 JPanel lower_pane = new JPanel(new BorderLayout());
308 lower_pane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED), get("Download_List_Configuration")));
309
310 remove_failed = new JCheckBox(get("Remove_Failed"));
311 remove_failed.setSelected(Gatherer.config.get("mirroring.remove_failed", false));
312
313 //Gatherer.println("\tCreating download_button");
314 download = new JButton(get("Download"));
315 download.addActionListener(this);
316 download.setHorizontalAlignment(JLabel.CENTER);
317 JPanel download_pane = new JPanel(new BorderLayout());
318
319 lower_pane.add(remove_failed, BorderLayout.NORTH);
320 lower_pane.add(download_pane, BorderLayout.CENTER);
321
322 control_pane.add(control_label, BorderLayout.NORTH);
323 control_pane.add(central_pane, BorderLayout.WEST);
324 //control_pane.add(thumbnail_holder, BorderLayout.CENTER);
325 control_pane.add(lower_pane, BorderLayout.SOUTH);
326
327 // Create list_pane
328 JPanel list_pane = new JPanel(new BorderLayout());
329 list_pane.setPreferredSize(new Dimension(Gatherer.g_man.getSize().width, Gatherer.g_man.getSize().height / 4));
330
331 download_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
332 download_pane.add(download);
333
334 //Gatherer.println("\tCreating list");
335 list_scroll = getter.getJobList();
336
337 //list_pane.add(download_pane, BorderLayout.NORTH);
338 list_pane.add(list_scroll, BorderLayout.CENTER);
339
340 // Add to content
341 JPanel temp_pane = new JPanel(new BorderLayout());
342 this.add(tree_pane, BorderLayout.WEST);
343 this.add(control_pane, BorderLayout.CENTER);
344 //temp_pane.add(control_pane, BorderLayout.NORTH);
345 //temp_pane.add(list_pane, BorderLayout.CENTER);
346 this.add(list_pane, BorderLayout.SOUTH);
347 }
348
349 public void refreshTrees() {
350 workspace_tree.refresh(null);
351 }
352
353 public void setURL(String url) {
354 source_url.setText(url);
355 }
356
357 private String get(String key) {
358 return get(key, null);
359 }
360
361 private String get(String key, String args[]) {
362 if(key.indexOf('.') == -1) {
363 key = "Mirroring." + key;
364 }
365 return Gatherer.dictionary.get(key,args);
366 }
367
368 /** Creates and dispatches a message given the initial details.
369 * @param level An int indicating the message level for this message.
370 * @param message A String which contains the payload of this message.
371 */
372 private void message(int level, String message) {
373 Message msg = new Message(Message.MIRRORING, level, message);
374 if(Gatherer.g_man != null) {
375 Gatherer.g_man.message_pane.show(msg);
376 } else {
377 Gatherer.println(msg.toString());
378 }
379 }
380}
Note: See TracBrowser for help on using the repository browser.