Changeset 7662
- Timestamp:
- 2004-06-29T15:03:46+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/MirrorPane.java
r7540 r7662 46 46 import javax.swing.event.*; 47 47 import javax.swing.tree.*; 48 import org.greenstone.gatherer.Configuration; 48 49 import org.greenstone.gatherer.Dictionary; 49 50 import org.greenstone.gatherer.Gatherer; … … 53 54 import org.greenstone.gatherer.gui.Preferences; 54 55 import org.greenstone.gatherer.gui.URLField; 56 import org.greenstone.gatherer.gui.tree.WorkspaceTree; 55 57 import org.greenstone.gatherer.util.StaticStrings; 56 58 import org.greenstone.gatherer.util.Utility; … … 63 65 extends JPanel { 64 66 67 /** The threshold for when the advanced options get added */ 68 static private final int THRESHOLD = Configuration.SYSTEMS_MODE; 69 65 70 private boolean download_button_enabled = false; 66 71 private boolean ready = false; 72 private int current_mode; 73 private JButton clear_cache_button; 67 74 private JButton download_button; 68 75 private JCheckBox higher_checkbox; … … 71 78 private JScrollPane list_scroll; 72 79 private JComboBox depth_combobox; 73 private URLField url_field; 80 //private URLField url_field; 81 private JPanel options_pane; 82 private JTextField url_field; 74 83 private Vector depth_model; 75 84 private WGet getter; … … 81 90 getter.start(); 82 91 // And retrieve its list of pending jobs 83 list_scroll = getter.getJobList(); 84 92 list_scroll = getter.getDownloadJobList(); 93 94 current_mode = Gatherer.config.getMode(); 95 String user_dir = System.getProperty("user.dir"); 96 System.err.println("user dir = "+user_dir); 85 97 // Create 86 98 JPanel edit_pane = new JPanel(); 87 99 JPanel details_pane = new JPanel(); 100 options_pane = new JPanel(); 88 101 89 102 JPanel url_pane = new JPanel(); 90 103 JLabel url_label = new JLabel(); 91 104 Dictionary.registerText(url_label, "Mirroring.Source_URL"); 92 url_field = new URLField(Gatherer.config.getColor("coloring.editable_foreground", false), Gatherer.config.getColor("coloring.editable_background", false), Gatherer.config.getColor("coloring.error_foreground", false), Gatherer.config.getColor("coloring.error_background", false));105 url_field = new JTextField(); 93 106 Dictionary.registerTooltip(url_field, "Mirroring.Source_URL_Tooltip"); 94 107 95 108 depth_model = new Vector(); 96 /* @todo - add to dictionary */ 97 depth_model.add(new DepthEntry(0, "Mirroring.Download_Depth.Zero")); 109 depth_model.add(new DepthEntry(0, Dictionary.get("Mirroring.Download_Depth.Zero"))); 98 110 /* @todo - add to dictionary */ 99 111 depth_model.add(new DepthEntry(1, String.valueOf(1))); 100 112 /* @todo - add to dictionary */ 101 depth_model.add(new DepthEntry(2, String.valueOf( 3)));113 depth_model.add(new DepthEntry(2, String.valueOf(2))); 102 114 /* @todo - add to dictionary */ 103 115 depth_model.add(new DepthEntry(3, String.valueOf(3))); … … 106 118 /* @todo - add to dictionary */ 107 119 depth_model.add(new DepthEntry(5, String.valueOf(5))); 108 /* @todo - add to dictionary */ 109 depth_model.add(new DepthEntry(-1, "Mirroring.Download_Depth.Unlimited")); 120 depth_model.add(new DepthEntry(-1, Dictionary.get("Mirroring.Download_Depth.Unlimited"))); 110 121 JPanel depth_pane = new JPanel(); 111 122 JLabel depth_label = new JLabel(); … … 115 126 116 127 requisite_checkbox = new JCheckBox(); 117 Dictionary.registerText(requisite_checkbox, "Mirroring.Download_Hidden"); 128 Dictionary.registerText(requisite_checkbox, "Mirroring.Download_Embedded"); 129 118 130 119 131 higher_checkbox = new JCheckBox(); 120 132 Dictionary.registerText(higher_checkbox, "Mirroring.Higher_Directories"); 121 133 higher_checkbox.addActionListener(new CheckboxClickListener()); 134 122 135 same_host_checkbox = new JCheckBox(); 123 136 same_host_checkbox.setSelected(true); … … 126 139 JPanel button_pane = new JPanel(); 127 140 128 JButton preferences_button = new GLIButton("Mirroring.Further_Options"); 141 JButton preferences_button = new GLIButton(); 142 preferences_button.setEnabled(true); 129 143 preferences_button.setMnemonic(KeyEvent.VK_P); 144 Dictionary.registerBoth(preferences_button, "Mirroring.Preferences", "Mirroring.Preferences_Tooltip"); 145 146 clear_cache_button = new GLIButton(); 147 clear_cache_button.setEnabled(true); 148 clear_cache_button.setMnemonic(KeyEvent.VK_C); 149 Dictionary.registerBoth(clear_cache_button, "Mirroring.ClearCache", "Mirroring.ClearCache_Tooltip"); 130 150 131 151 download_button = new GLIButton(); 132 download_button.setEnabled( false);152 download_button.setEnabled(true); 133 153 download_button.setMnemonic(KeyEvent.VK_D); 134 154 Dictionary.registerBoth(download_button, "Mirroring.Download", "Mirroring.Download_Tooltip"); 135 136 155 // Connect 156 clear_cache_button.addActionListener(new ClearCacheListener()); 137 157 download_button.addActionListener(new DownloadButtonListener()); 138 158 preferences_button.addActionListener(new PreferencesButtonActionListener()); 139 url_field.getDocument().addDocumentListener(new DownloadButtonEnabler());140 159 141 160 // Layout … … 149 168 depth_pane.add(depth_combobox); 150 169 151 details_pane.setLayout(new GridLayout(5,1,0,5)); 170 details_pane.setLayout(new GridLayout(2,1,0,5)); 171 details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,5,2)); 152 172 details_pane.add(url_pane); 153 173 details_pane.add(depth_pane); 154 details_pane.add(requisite_checkbox); 155 details_pane.add(higher_checkbox); 156 details_pane.add(same_host_checkbox); 157 158 button_pane.setLayout(new GridLayout(1,3)); 174 175 options_pane.setLayout(new GridLayout(3,1,0,5)); 176 177 options_pane.add(higher_checkbox); 178 options_pane.add(same_host_checkbox); 179 if (current_mode >= THRESHOLD) { 180 options_pane.add(requisite_checkbox); 181 } 182 183 button_pane.setLayout(new GridLayout(3,1)); 159 184 button_pane.add(preferences_button); 160 button_pane.add( new JPanel());185 button_pane.add(clear_cache_button); 161 186 button_pane.add(download_button); 162 187 163 188 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)))); 164 189 edit_pane.setLayout(new BorderLayout()); 165 edit_pane.add(details_pane, BorderLayout.CENTER); 166 edit_pane.add(button_pane, BorderLayout.SOUTH); 190 edit_pane.add(details_pane, BorderLayout.NORTH); 191 edit_pane.add(button_pane, BorderLayout.EAST); 192 edit_pane.add(options_pane, BorderLayout.CENTER); 167 193 168 194 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); … … 191 217 download_button_enabled = false; 192 218 // And we tell the user why. 193 /** @todo - add to dictionary */ 194 JOptionPane.showMessageDialog(Gatherer.g_man, "Mirroring.No_WGet", "Mirroring.No_WGet_Title", JOptionPane.ERROR_MESSAGE); 219 Gatherer.missingWGET(); 195 220 } 196 221 else if(wget_version_str.equals(StaticStrings.WGET_OLD_STR)) { … … 198 223 download_button_enabled = true; 199 224 // But we display a preventable warning message about the path problems. 200 WarningDialog dialog = new WarningDialog("warning.OldWGet", false); 201 dialog.display(); 202 dialog.dispose(); 203 dialog = null; 225 Gatherer.oldWGET(); 204 226 } 205 227 // Otherwise version must be ok … … 208 230 } 209 231 // It is also a good time to determine if the download should be enabled - ie if its allowed to be enabled and a valid URL is present in the field. 210 download_button.setEnabled(download_button_enabled && !url_field.isEmpty() && url_field.validateURL()); 211 } 212 213 // public void setURL(String url) { 214 // url_field.setText(url); 215 // } 216 217 218 // static public FileNode getWebCacheMapping() 219 // { 220 // if (Gatherer.config.get("workflow.mirror", true) || Gatherer.config.get("workflow.mirror", false)) { 221 // /* @todo - add to dictionary */ 222 // return new FileNode(Utility.getCacheDir(), "Mirroring.Mirror_Cache"); 223 // } 224 // return null; 225 // } 232 download_button.setEnabled(download_button_enabled); 233 } 234 235 public void modeChanged(int mode) { 236 int old_mode = current_mode; 237 current_mode = mode; 238 if (old_mode >= THRESHOLD && current_mode >= THRESHOLD) { 239 return; 240 } 241 if (old_mode < THRESHOLD && current_mode < THRESHOLD) { 242 return; 243 } 244 if (current_mode >= THRESHOLD) { 245 options_pane.add(requisite_checkbox); 246 } else { 247 options_pane.remove(requisite_checkbox); 248 requisite_checkbox.setSelected(false); 249 } 250 251 } 252 226 253 227 254 /** A DepthEntry contains a depth value, as an int, and a representitive text string. This allows for a more meaningful appearance than '0' for instance. */ … … 278 305 } 279 306 280 private class DownloadButtonEnabler 281 implements DocumentListener { 282 /** Gives notification that an attribute or set of attributes changed. */ 283 public void changedUpdate(DocumentEvent e) { 284 validateDownloadButton(); 285 } 286 /** Gives notification that there was an insert into the document. */ 287 public void insertUpdate(DocumentEvent e) { 288 validateDownloadButton(); 289 } 290 /** Gives notification that a portion of the document has been removed. */ 291 public void removeUpdate(DocumentEvent e) { 292 validateDownloadButton(); 293 } 294 private void validateDownloadButton() { 295 download_button.setEnabled(download_button_enabled && !url_field.isEmpty() && url_field.validateURL()); 296 } 297 } 298 307 private class ClearCacheListener 308 implements ActionListener { 309 public void actionPerformed(ActionEvent event) { 310 // Retrieve the cache folder and delete it. 311 Utility.delete(Utility.getCacheDir()); 312 // ...and refresh the node in the workspace tree to show it's all gone 313 Gatherer.g_man.refreshWorkspaceTree(WorkspaceTree.DOWNLOADED_FILES_CHANGED); 314 } 315 } 316 317 private class CheckboxClickListener 318 implements ActionListener { 319 public void actionPerformed(ActionEvent event) { 320 if (higher_checkbox.isSelected()) { 321 same_host_checkbox.setEnabled(false); 322 } else { 323 same_host_checkbox.setEnabled(true); 324 } 325 } 326 } 327 299 328 private class DownloadButtonListener 300 329 implements ActionListener { … … 350 379 351 380 if(url != null) { 352 getter.new Job(!higher_checkbox.isSelected(), !same_host_checkbox.isSelected(),requisite_checkbox.isSelected(), url, depth_value, destination_filename);381 getter.newDownloadJob(higher_checkbox.isSelected(), (higher_checkbox.isSelected()? false : !same_host_checkbox.isSelected()), !requisite_checkbox.isSelected(), url, depth_value, destination_filename); 353 382 } 354 383 } … … 361 390 } 362 391 } 392 393 363 394 }
Note:
See TracChangeset
for help on using the changeset viewer.