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

Last change on this file since 6160 was 5869, checked in by mdewsnip, 21 years ago

More improvements to workspace tree refreshing... still not perfect though.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.File;
42import java.net.*;
43import javax.swing.*;
44import javax.swing.border.*;
45import javax.swing.event.*;
46import javax.swing.tree.*;
47import org.greenstone.gatherer.Dictionary;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.WGet;
50import org.greenstone.gatherer.file.FileNode;
51import org.greenstone.gatherer.util.Utility;
52
53/**
54 * @author John Thompson, Greenstone Digital Library, University of Waikato
55 * @version 2.1
56 */
57public class MirrorPane
58 extends JPanel {
59 private JButton download_button = null;
60 private JCheckBox automatic_checkbox = null;
61 private JCheckBox higher_checkbox = null;
62 private JCheckBox overwrite_checkbox = null;
63 private JCheckBox remove_failed_checkbox = null;
64 private JCheckBox same_host_checkbox = null;
65 private JRadioButton public_radiobutton = null;
66 private JRadioButton private_radiobutton = null;
67 private JScrollPane list_scroll = null;
68 private JSpinner depth_spinner = null;
69 private JTextField url_textfield = null;
70 private WGet getter = null;
71
72 public MirrorPane() {
73 super();
74 // Create a new wget thread
75 getter = new WGet();
76 getter.start();
77 // And retrieve its list of pending jobs
78 list_scroll = getter.getJobList();
79
80 // Create
81 JPanel edit_pane = new JPanel();
82 JPanel details_pane = new JPanel();
83
84 JPanel url_pane = new JPanel();
85 JLabel url_label = new JLabel();
86 url_label.setPreferredSize(Utility.LABEL_SIZE);
87 Dictionary.registerText(url_label, "Mirroring.Source_URL");
88 url_textfield = new JTextField();
89 Dictionary.registerTooltip(url_textfield, "Mirroring.Source_URL_Tooltip");
90
91 JPanel depth_pane = new JPanel();
92 JLabel depth_label = new JLabel();
93 Dictionary.registerText(depth_label, "Mirroring.Download_Depth");
94 depth_spinner = new JSpinner();
95 Dictionary.registerTooltip(depth_spinner, "Mirroring.Download_Depth_Tooltip");
96
97 JPanel destination_pane = new JPanel();
98 JLabel destination_label = new JLabel();
99 Dictionary.registerText(destination_label, "Mirroring.Destination_Folder");
100 ButtonGroup group = new ButtonGroup();
101 public_radiobutton = new JRadioButton();
102 public_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
103 public_radiobutton.setOpaque(false);
104 Dictionary.registerText(public_radiobutton, "Tree.Public");
105 private_radiobutton = new JRadioButton();
106 private_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
107 private_radiobutton.setOpaque(false);
108 Dictionary.registerText(private_radiobutton, "Tree.Private");
109 group.add(public_radiobutton);
110 group.add(private_radiobutton);
111 public_radiobutton.setSelected(true);
112
113 JPanel first_pane = new JPanel();
114 automatic_checkbox = new JCheckBox();
115 Dictionary.registerText(automatic_checkbox, "Mirroring.Download_Hidden");
116 overwrite_checkbox = new JCheckBox();
117 Dictionary.registerText(overwrite_checkbox, "Mirroring.Overwrite_Existing");
118
119 JPanel second_pane = new JPanel();
120 higher_checkbox = new JCheckBox();
121 Dictionary.registerText(higher_checkbox, "Mirroring.Higher_Directories");
122 same_host_checkbox = new JCheckBox();
123 Dictionary.registerText(same_host_checkbox, "Mirroring.Same_Host");
124
125 remove_failed_checkbox = new JCheckBox();
126 Dictionary.registerText(remove_failed_checkbox, "Mirroring.Remove_Failed");
127
128 JLabel further_label = new JLabel();
129 Dictionary.registerText(further_label, "Mirroring.Further_Options");
130
131 JPanel button_pane = new JPanel();
132 download_button = new JButton();
133 Dictionary.registerBoth(download_button, "Mirroring.Download", "Mirroring.Download_Tooltip");
134
135 // Connect
136 download_button.addActionListener(new DownloadButtonListener());
137
138 // Layout
139 url_pane.setLayout(new BorderLayout());
140 url_pane.add(url_label, BorderLayout.WEST);
141 url_pane.add(url_textfield, BorderLayout.CENTER);
142
143 depth_pane.setLayout(new GridLayout(1,3));
144 depth_pane.add(depth_label);
145 depth_pane.add(new JPanel());
146 depth_pane.add(depth_spinner);
147
148 destination_pane.setLayout(new GridLayout(1,3));
149 destination_pane.add(destination_label);
150 destination_pane.add(public_radiobutton);
151 destination_pane.add(private_radiobutton);
152
153 first_pane.setLayout(new GridLayout(1,2));
154 first_pane.add(automatic_checkbox);
155 first_pane.add(overwrite_checkbox);
156
157 second_pane.setLayout(new GridLayout(1,2));
158 second_pane.add(higher_checkbox);
159 second_pane.add(same_host_checkbox);
160
161 details_pane.setLayout(new GridLayout(7,1,0,5));
162 details_pane.add(url_pane);
163 details_pane.add(depth_pane);
164 details_pane.add(destination_pane);
165 details_pane.add(first_pane);
166 details_pane.add(second_pane);
167 details_pane.add(remove_failed_checkbox);
168 details_pane.add(further_label);
169
170 button_pane.setLayout(new GridLayout(1,3));
171 button_pane.add(new JPanel());
172 button_pane.add(new JPanel());
173 button_pane.add(download_button);
174
175 edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("Mirroring.Download_Controls")), BorderFactory.createEmptyBorder(2,2,2,2))));
176 edit_pane.setLayout(new BorderLayout());
177 edit_pane.add(details_pane, BorderLayout.CENTER);
178 edit_pane.add(button_pane, BorderLayout.SOUTH);
179
180 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
181 setLayout(new BorderLayout());
182 add(edit_pane, BorderLayout.NORTH);
183 add(list_scroll, BorderLayout.CENTER);
184 }
185
186 public void collectionChanged(boolean ready) {
187 if(private_radiobutton.isSelected() && !ready) {
188 public_radiobutton.setSelected(true);
189 }
190 private_radiobutton.setEnabled(ready);
191 }
192
193 public void setURL(String url) {
194 url_textfield.setText(url);
195 }
196
197
198 static public FileNode getPublicWebCacheMapping()
199 {
200 if (Gatherer.config.get("workflow.mirror", false)) {
201 return new FileNode(new File(Utility.CACHE_DIR), Dictionary.get("Tree.Public"));
202 }
203
204 return null;
205 }
206
207
208 static public FileNode getPrivateWebCacheMapping()
209 {
210 if (Gatherer.config.get("workflow.mirror", false) && Gatherer.c_man.ready()) {
211 return new FileNode(new File(Gatherer.c_man.getCollectionCache()), Dictionary.get("Tree.Private"));
212 }
213
214 return null;
215 }
216
217
218 private class DownloadButtonListener
219 implements ActionListener {
220
221 public void actionPerformed(ActionEvent event) {
222 // Retrieve the current url and confirm it is valid
223 String url_str = url_textfield.getText();
224 URL url = null;
225 try {
226 url = new URL(url_str);
227 }
228 catch(MalformedURLException error) {
229 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL__Title"), JOptionPane.ERROR_MESSAGE);
230 }
231 if(url != null) {
232 // Otherwise construct a new download job
233 getter.newJob(/* Gatherer.c_man.getWorkspace(), */ overwrite_checkbox.isSelected(), !higher_checkbox.isSelected(), !same_host_checkbox.isSelected(), automatic_checkbox.isSelected(), url, ((Integer)depth_spinner.getValue()).intValue(), (public_radiobutton.isSelected() ? Utility.CACHE_DIR : Gatherer.c_man.getCollectionCache()));
234 }
235 }
236 }
237}
Note: See TracBrowser for help on using the repository browser.