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 | */
|
---|
37 | package org.greenstone.gatherer.gui;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.net.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import javax.swing.border.*;
|
---|
44 | import javax.swing.event.*;
|
---|
45 | import javax.swing.tree.*;
|
---|
46 | import org.greenstone.gatherer.Dictionary;
|
---|
47 | import org.greenstone.gatherer.Gatherer;
|
---|
48 | import org.greenstone.gatherer.WGet;
|
---|
49 | import org.greenstone.gatherer.util.Utility;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
53 | * @version 2.1
|
---|
54 | */
|
---|
55 | public class MirrorPane
|
---|
56 | extends JPanel {
|
---|
57 | private JButton download_button = null;
|
---|
58 | private JCheckBox automatic_checkbox = null;
|
---|
59 | private JCheckBox higher_checkbox = null;
|
---|
60 | private JCheckBox overwrite_checkbox = null;
|
---|
61 | private JCheckBox remove_failed_checkbox = null;
|
---|
62 | private JCheckBox same_host_checkbox = null;
|
---|
63 | private JRadioButton public_radiobutton = null;
|
---|
64 | private JRadioButton private_radiobutton = null;
|
---|
65 | private JScrollPane list_scroll = null;
|
---|
66 | private JSpinner depth_spinner = null;
|
---|
67 | private JTextField url_textfield = null;
|
---|
68 | private WGet getter = null;
|
---|
69 |
|
---|
70 | public MirrorPane() {
|
---|
71 | super();
|
---|
72 | // Create a new wget thread
|
---|
73 | getter = new WGet();
|
---|
74 | getter.start();
|
---|
75 | // And retrieve its list of pending jobs
|
---|
76 | list_scroll = getter.getJobList();
|
---|
77 |
|
---|
78 | // Create
|
---|
79 | JPanel edit_pane = new JPanel();
|
---|
80 | JPanel details_pane = new JPanel();
|
---|
81 |
|
---|
82 | JPanel url_pane = new JPanel();
|
---|
83 | JLabel url_label = new JLabel();
|
---|
84 | url_label.setPreferredSize(Utility.LABEL_SIZE);
|
---|
85 | Dictionary.registerText(url_label, "Mirroring.Source_URL");
|
---|
86 | url_textfield = new JTextField();
|
---|
87 | Dictionary.registerTooltip(url_textfield, "Mirroring.Source_URL_Tooltip");
|
---|
88 |
|
---|
89 | JPanel depth_pane = new JPanel();
|
---|
90 | JLabel depth_label = new JLabel();
|
---|
91 | Dictionary.registerText(depth_label, "Mirroring.Download_Depth");
|
---|
92 | depth_spinner = new JSpinner();
|
---|
93 | Dictionary.registerTooltip(depth_spinner, "Mirroring.Download_Depth_Tooltip");
|
---|
94 |
|
---|
95 | JPanel destination_pane = new JPanel();
|
---|
96 | JLabel destination_label = new JLabel();
|
---|
97 | Dictionary.registerText(destination_label, "Mirroring.Destination_Folder");
|
---|
98 | ButtonGroup group = new ButtonGroup();
|
---|
99 | public_radiobutton = new JRadioButton();
|
---|
100 | public_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
101 | public_radiobutton.setOpaque(false);
|
---|
102 | Dictionary.registerText(public_radiobutton, "Tree.Public");
|
---|
103 | private_radiobutton = new JRadioButton();
|
---|
104 | private_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
105 | private_radiobutton.setOpaque(false);
|
---|
106 | Dictionary.registerText(private_radiobutton, "Tree.Private");
|
---|
107 | group.add(public_radiobutton);
|
---|
108 | group.add(private_radiobutton);
|
---|
109 | public_radiobutton.setSelected(true);
|
---|
110 |
|
---|
111 | JPanel first_pane = new JPanel();
|
---|
112 | automatic_checkbox = new JCheckBox();
|
---|
113 | Dictionary.registerText(automatic_checkbox, "Mirroring.Download_Hidden");
|
---|
114 | overwrite_checkbox = new JCheckBox();
|
---|
115 | Dictionary.registerText(overwrite_checkbox, "Mirroring.Overwrite_Existing");
|
---|
116 |
|
---|
117 | JPanel second_pane = new JPanel();
|
---|
118 | higher_checkbox = new JCheckBox();
|
---|
119 | Dictionary.registerText(higher_checkbox, "Mirroring.Higher_Directories");
|
---|
120 | same_host_checkbox = new JCheckBox();
|
---|
121 | Dictionary.registerText(same_host_checkbox, "Mirroring.Same_Host");
|
---|
122 |
|
---|
123 | remove_failed_checkbox = new JCheckBox();
|
---|
124 | Dictionary.registerText(remove_failed_checkbox, "Mirroring.Remove_Failed");
|
---|
125 |
|
---|
126 | JLabel further_label = new JLabel();
|
---|
127 | Dictionary.registerText(further_label, "Mirroring.Further_Options");
|
---|
128 |
|
---|
129 | JPanel button_pane = new JPanel();
|
---|
130 | download_button = new JButton();
|
---|
131 | Dictionary.registerBoth(download_button, "Mirroring.Download", "Mirroring.Download_Tooltip");
|
---|
132 |
|
---|
133 | // Connect
|
---|
134 | download_button.addActionListener(new DownloadButtonListener());
|
---|
135 |
|
---|
136 | // Layout
|
---|
137 | url_pane.setLayout(new BorderLayout());
|
---|
138 | url_pane.add(url_label, BorderLayout.WEST);
|
---|
139 | url_pane.add(url_textfield, BorderLayout.CENTER);
|
---|
140 |
|
---|
141 | depth_pane.setLayout(new GridLayout(1,3));
|
---|
142 | depth_pane.add(depth_label);
|
---|
143 | depth_pane.add(new JPanel());
|
---|
144 | depth_pane.add(depth_spinner);
|
---|
145 |
|
---|
146 | destination_pane.setLayout(new GridLayout(1,3));
|
---|
147 | destination_pane.add(destination_label);
|
---|
148 | destination_pane.add(public_radiobutton);
|
---|
149 | destination_pane.add(private_radiobutton);
|
---|
150 |
|
---|
151 | first_pane.setLayout(new GridLayout(1,2));
|
---|
152 | first_pane.add(automatic_checkbox);
|
---|
153 | first_pane.add(overwrite_checkbox);
|
---|
154 |
|
---|
155 | second_pane.setLayout(new GridLayout(1,2));
|
---|
156 | second_pane.add(higher_checkbox);
|
---|
157 | second_pane.add(same_host_checkbox);
|
---|
158 |
|
---|
159 | details_pane.setLayout(new GridLayout(7,1,0,5));
|
---|
160 | details_pane.add(url_pane);
|
---|
161 | details_pane.add(depth_pane);
|
---|
162 | details_pane.add(destination_pane);
|
---|
163 | details_pane.add(first_pane);
|
---|
164 | details_pane.add(second_pane);
|
---|
165 | details_pane.add(remove_failed_checkbox);
|
---|
166 | details_pane.add(further_label);
|
---|
167 |
|
---|
168 | button_pane.setLayout(new GridLayout(1,3));
|
---|
169 | button_pane.add(new JPanel());
|
---|
170 | button_pane.add(new JPanel());
|
---|
171 | button_pane.add(download_button);
|
---|
172 |
|
---|
173 | edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.newget("Mirroring.Download_Controls")), BorderFactory.createEmptyBorder(2,2,2,2))));
|
---|
174 | edit_pane.setLayout(new BorderLayout());
|
---|
175 | edit_pane.add(details_pane, BorderLayout.CENTER);
|
---|
176 | edit_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
177 |
|
---|
178 | setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
179 | setLayout(new BorderLayout());
|
---|
180 | add(edit_pane, BorderLayout.NORTH);
|
---|
181 | add(list_scroll, BorderLayout.CENTER);
|
---|
182 | }
|
---|
183 |
|
---|
184 | public void collectionChanged(boolean ready) {
|
---|
185 | if(private_radiobutton.isSelected() && !ready) {
|
---|
186 | public_radiobutton.setSelected(true);
|
---|
187 | }
|
---|
188 | private_radiobutton.setEnabled(ready);
|
---|
189 | }
|
---|
190 |
|
---|
191 | public void setURL(String url) {
|
---|
192 | url_textfield.setText(url);
|
---|
193 | }
|
---|
194 |
|
---|
195 | private class DownloadButtonListener
|
---|
196 | implements ActionListener {
|
---|
197 |
|
---|
198 | public void actionPerformed(ActionEvent event) {
|
---|
199 | // Retrieve the current url and confirm it is valid
|
---|
200 | String url_str = url_textfield.getText();
|
---|
201 | URL url = null;
|
---|
202 | try {
|
---|
203 | url = new URL(url_str);
|
---|
204 | }
|
---|
205 | catch(MalformedURLException error) {
|
---|
206 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("Mirroring.Invalid_URL"), Dictionary.newget("Mirroring.Invalid_URL__Title"), JOptionPane.ERROR_MESSAGE);
|
---|
207 | }
|
---|
208 | if(url != null) {
|
---|
209 | // Otherwise construct a new download job
|
---|
210 | 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()));
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|