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

Last change on this file since 6394 was 6318, checked in by jmt12, 21 years ago

Changed JButtons for GLIButtons, which know whether they should paint their background depending on what platform they are run on, and finished keyboard shortcuts

  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 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.gui.GLIButton;
52import org.greenstone.gatherer.util.Utility;
53
54/**
55 * @author John Thompson, Greenstone Digital Library, University of Waikato
56 * @version 2.1
57 */
58public class MirrorPane
59 extends JPanel {
60 private JButton download_button = null;
61 private JCheckBox automatic_checkbox = null;
62 private JCheckBox higher_checkbox = null;
63 private JCheckBox overwrite_checkbox = null;
64 private JCheckBox remove_failed_checkbox = null;
65 private JCheckBox same_host_checkbox = null;
66 private JRadioButton public_radiobutton = null;
67 private JRadioButton private_radiobutton = null;
68 private JScrollPane list_scroll = null;
69 private JSpinner depth_spinner = null;
70 private JTextField url_textfield = null;
71 private WGet getter = null;
72
73 public MirrorPane() {
74 super();
75 // Create a new wget thread
76 getter = new WGet();
77 getter.start();
78 // And retrieve its list of pending jobs
79 list_scroll = getter.getJobList();
80
81 // Create
82 JPanel edit_pane = new JPanel();
83 JPanel details_pane = new JPanel();
84
85 JPanel url_pane = new JPanel();
86 JLabel url_label = new JLabel();
87 url_label.setPreferredSize(Utility.LABEL_SIZE);
88 Dictionary.registerText(url_label, "Mirroring.Source_URL");
89 url_textfield = new JTextField();
90 Dictionary.registerTooltip(url_textfield, "Mirroring.Source_URL_Tooltip");
91
92 JPanel depth_pane = new JPanel();
93 JLabel depth_label = new JLabel();
94 Dictionary.registerText(depth_label, "Mirroring.Download_Depth");
95 depth_spinner = new JSpinner();
96 Dictionary.registerTooltip(depth_spinner, "Mirroring.Download_Depth_Tooltip");
97
98 JPanel destination_pane = new JPanel();
99 JLabel destination_label = new JLabel();
100 Dictionary.registerText(destination_label, "Mirroring.Destination_Folder");
101 ButtonGroup group = new ButtonGroup();
102 public_radiobutton = new JRadioButton();
103 public_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
104 public_radiobutton.setOpaque(false);
105 Dictionary.registerText(public_radiobutton, "Tree.Public");
106 private_radiobutton = new JRadioButton();
107 private_radiobutton.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
108 private_radiobutton.setOpaque(false);
109 Dictionary.registerText(private_radiobutton, "Tree.Private");
110 group.add(public_radiobutton);
111 group.add(private_radiobutton);
112 public_radiobutton.setSelected(true);
113
114 JPanel first_pane = new JPanel();
115 automatic_checkbox = new JCheckBox();
116 Dictionary.registerText(automatic_checkbox, "Mirroring.Download_Hidden");
117 overwrite_checkbox = new JCheckBox();
118 Dictionary.registerText(overwrite_checkbox, "Mirroring.Overwrite_Existing");
119
120 JPanel second_pane = new JPanel();
121 higher_checkbox = new JCheckBox();
122 Dictionary.registerText(higher_checkbox, "Mirroring.Higher_Directories");
123 same_host_checkbox = new JCheckBox();
124 Dictionary.registerText(same_host_checkbox, "Mirroring.Same_Host");
125
126 remove_failed_checkbox = new JCheckBox();
127 Dictionary.registerText(remove_failed_checkbox, "Mirroring.Remove_Failed");
128
129 JLabel further_label = new JLabel();
130 Dictionary.registerText(further_label, "Mirroring.Further_Options");
131
132 JPanel button_pane = new JPanel();
133 download_button = new GLIButton();
134 download_button.setMnemonic(KeyEvent.VK_ENTER);
135 Dictionary.registerBoth(download_button, "Mirroring.Download", "Mirroring.Download_Tooltip");
136
137 // Connect
138 download_button.addActionListener(new DownloadButtonListener());
139
140 // Layout
141 url_pane.setLayout(new BorderLayout());
142 url_pane.add(url_label, BorderLayout.WEST);
143 url_pane.add(url_textfield, BorderLayout.CENTER);
144
145 depth_pane.setLayout(new GridLayout(1,3));
146 depth_pane.add(depth_label);
147 depth_pane.add(new JPanel());
148 depth_pane.add(depth_spinner);
149
150 destination_pane.setLayout(new GridLayout(1,3));
151 destination_pane.add(destination_label);
152 destination_pane.add(public_radiobutton);
153 destination_pane.add(private_radiobutton);
154
155 first_pane.setLayout(new GridLayout(1,2));
156 first_pane.add(automatic_checkbox);
157 first_pane.add(overwrite_checkbox);
158
159 second_pane.setLayout(new GridLayout(1,2));
160 second_pane.add(higher_checkbox);
161 second_pane.add(same_host_checkbox);
162
163 details_pane.setLayout(new GridLayout(7,1,0,5));
164 details_pane.add(url_pane);
165 details_pane.add(depth_pane);
166 details_pane.add(destination_pane);
167 details_pane.add(first_pane);
168 details_pane.add(second_pane);
169 details_pane.add(remove_failed_checkbox);
170 details_pane.add(further_label);
171
172 button_pane.setLayout(new GridLayout(1,3));
173 button_pane.add(new JPanel());
174 button_pane.add(new JPanel());
175 button_pane.add(download_button);
176
177 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))));
178 edit_pane.setLayout(new BorderLayout());
179 edit_pane.add(details_pane, BorderLayout.CENTER);
180 edit_pane.add(button_pane, BorderLayout.SOUTH);
181
182 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
183 setLayout(new BorderLayout());
184 add(edit_pane, BorderLayout.NORTH);
185 add(list_scroll, BorderLayout.CENTER);
186 }
187
188 public void collectionChanged(boolean ready) {
189 if(private_radiobutton.isSelected() && !ready) {
190 public_radiobutton.setSelected(true);
191 }
192 private_radiobutton.setEnabled(ready);
193 }
194
195 public void setURL(String url) {
196 url_textfield.setText(url);
197 }
198
199
200 static public FileNode getPublicWebCacheMapping()
201 {
202 if (Gatherer.config.get("workflow.mirror", false)) {
203 return new FileNode(new File(Utility.CACHE_DIR), Dictionary.get("Tree.Public"));
204 }
205
206 return null;
207 }
208
209
210 static public FileNode getPrivateWebCacheMapping()
211 {
212 if (Gatherer.config.get("workflow.mirror", false) && Gatherer.c_man.ready()) {
213 return new FileNode(new File(Gatherer.c_man.getCollectionCache()), Dictionary.get("Tree.Private"));
214 }
215
216 return null;
217 }
218
219
220 private class DownloadButtonListener
221 implements ActionListener {
222
223 public void actionPerformed(ActionEvent event) {
224 // Retrieve the current url and confirm it is valid
225 String url_str = url_textfield.getText();
226 URL url = null;
227 try {
228 url = new URL(url_str);
229 }
230 catch(MalformedURLException error) {
231 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL__Title"), JOptionPane.ERROR_MESSAGE);
232 }
233 if(url != null) {
234 // Otherwise construct a new download job
235 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()));
236 }
237 }
238 }
239}
Note: See TracBrowser for help on using the repository browser.