- Timestamp:
- 2003-10-03T17:09:38+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/GProgressBar.java
r5322 r5571 35 35 *######################################################################## 36 36 */ 37 38 39 40 41 42 43 37 package org.greenstone.gatherer.gui; 44 38 45 import java.awt.BorderLayout; 46 import java.awt.Component; 47 import java.awt.Dimension; 48 import java.awt.Graphics2D; 49 import java.awt.GridLayout; 50 import java.awt.Image; 51 import java.awt.event.ActionEvent; 52 import java.awt.event.ActionListener; 53 import java.awt.geom.AffineTransform; 54 import java.awt.image.BufferedImage; 55 import javax.swing.BorderFactory; 56 import javax.swing.ImageIcon; 57 import javax.swing.JButton; 58 import javax.swing.JLabel; 59 import javax.swing.JPanel; 60 import javax.swing.JProgressBar; 61 import javax.swing.border.BevelBorder; 39 import java.awt.*; 40 import java.awt.event.*; 41 import javax.swing.*; 42 import javax.swing.border.*; 43 import org.greenstone.gatherer.Dictionary; 62 44 import org.greenstone.gatherer.Gatherer; 63 45 import org.greenstone.gatherer.collection.Job; … … 71 53 72 54 private Dimension bar_size = new Dimension(520, 15); 73 74 private Gatherer gatherer;75 76 private ImageIcon busy_bar;77 private ImageIcon ready_bar;78 55 79 56 private int current_action; … … 104 81 public JButton cancel; 105 82 106 //public GProgressBar(Gatherer gatherer, WGet owner, String initial_url) {107 // this.gatherer = gatherer;108 83 public GProgressBar(Job owner, String initial_url, boolean simple) { 109 84 this.owner = owner; … … 120 95 this.setLayout(new BorderLayout()); 121 96 this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); 122 //this.setMinimumSize(Utility.PROGRESS_BAR_SIZE);123 //this.setSize(Utility.PROGRESS_BAR_SIZE);124 //this.setMaximumSize(Utility.PROGRESS_BAR_SIZE);125 //this.setAlignmentY(Component.LEFT_ALIGNMENT);126 //this.setHorizontalAlignment(JLabel.LEFT);127 97 128 98 this.current_action = Job.STOPPED; 129 99 130 100 inner_pane = new JPanel(new BorderLayout()); 131 101 inner_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); 132 102 133 103 action = new JButton(Utility.getImage("vcrplay.gif")); 134 //action.setToolTipText(get("Action_Tip"));135 action.setToolTipText("Start current download");136 104 action.addActionListener(this); 137 105 action.addActionListener(owner); 106 Dictionary.setTooltip(action, "Mirroring.Job.Start_Tooltip"); 138 107 139 108 center_pane = new JPanel(new GridLayout(3,1)); … … 146 115 147 116 progress = new JProgressBar(); 148 progress.setString("Waiting to start");149 117 progress.setStringPainted(true); 150 118 progress.setMinimum(0); 151 119 progress.setMaximum(0); 152 120 progress.setEnabled(false); 121 Dictionary.setText(progress, "Mirroring.Job.Waiting"); 153 122 inner_pane.add(progress, BorderLayout.CENTER); 154 123 … … 158 127 159 128 cancel = new JButton(Utility.getImage("vcrstop.gif")); 160 //cancel.setToolTipText(get("Cancel_Tip"));161 cancel.setToolTipText("Cancel current download");162 129 cancel.addActionListener(owner); 163 130 cancel.addActionListener(this); 131 Dictionary.setTooltip(cancel, "Mirroring.Job.Stop_Tooltip"); 164 132 165 133 inner_pane.add(center_pane, BorderLayout.NORTH); … … 175 143 public void actionPerformed(ActionEvent event) { 176 144 if(event.getSource() == action) { 177 if (current_action == Job.RUNNING) {145 if (current_action == Job.RUNNING) { 178 146 current_action = Job.STOPPED; 179 147 action.setIcon(Utility.getImage("vcrplay.gif")); 180 action.setToolTipText("Start current download");148 Dictionary.setTooltip(action, "Mirroring.Job.Start_Tooltip"); 181 149 cancel.setEnabled(true); 182 150 } … … 184 152 current_action = Job.RUNNING; 185 153 action.setIcon(Utility.getImage("vcrpause.gif")); 186 action.setToolTipText("Pause current download");154 Dictionary.setTooltip(action, "Mirroring.Job.Pause_Tooltip"); 187 155 cancel.setEnabled(false); 188 156 } … … 212 180 } 213 181 progress.setValue(progress.getMaximum()); 214 progress.setString("Download Complete.");182 Dictionary.setText(progress, "Mirroring.Job.Download_Complete"); 215 183 refresh(); 216 184 } … … 232 200 } 233 201 234 public Dimension getP erferredSize() {202 public Dimension getPreferredSize() { 235 203 return Utility.PROGRESS_BAR_SIZE; 236 204 } … … 259 227 this.err_count = 0; 260 228 this.warning_count = 0; 261 } 229 } 262 230 current_action = Job.RUNNING; 263 231 action.setIcon(Utility.getImage("vcrpause.gif")); 264 action.setToolTipText("Pause current download");232 Dictionary.setTooltip(cancel, "Mirroring.Job.Pause_Tooltip"); 265 233 // If this is a simple download, then pause is not available (nor is prematurely stopping!) 266 234 action.setEnabled(!simple); … … 283 251 } 284 252 progress.setValue(progress.getMaximum()); 285 progress.setString("Mirroring Complete.");253 Dictionary.setText(progress, "Mirroring.Job.Mirror_Complete"); 286 254 287 255 action.setIcon(Utility.getImage("vcrfastforward.gif")); 288 action.setToolTipText("Restart current download");256 Dictionary.setText(action, "Mirroring.Job.Restart"); 289 257 action.setEnabled(true); 290 258 cancel.setEnabled(true); … … 298 266 file_size = file_size + current; 299 267 if(!progress.isIndeterminate()) { 300 301 268 // If current is zero, then this is the 'precall' before the 269 // downloading actually starts. 302 270 if(current == 0) { 303 271 // Remove the old progress bar, then deallocate it. … … 305 273 progress = null; 306 274 if(expected == 0) { 307 // We don't have a content length. This bar will go from 308 // 0 to 100 only! 275 // We don't have a content length. This bar will go from 0 to 100 only! 309 276 progress = new JProgressBar(0, 100); 310 277 } 311 278 else { 312 // Assign a new progress bar of length expected content 313 // length. 314 progress = 315 new JProgressBar(0, (new Long(expected)).intValue()); 279 // Assign a new progress bar of length expected content length. 280 progress = new JProgressBar(0, (new Long(expected)).intValue()); 316 281 } 317 282 progress.setEnabled(true); … … 320 285 inner_pane.updateUI(); 321 286 } 322 323 287 // Otherwise if expected is not zero move the progress bar and 288 // update percent complete. 324 289 else if (expected != 0) { 325 290 progress.setValue((new Long(file_size)).intValue()); 326 int p_c = 327 (new Double( 328 progress.getPercentComplete() * 100)).intValue(); 291 int p_c = (new Double(progress.getPercentComplete() * 100)).intValue(); 329 292 progress.setString(p_c + "%"); 330 293 progress.setStringPainted(true); 331 294 } 332 333 295 // Finally, in the case we have no content length, we'll instead 296 // write the current number of bytes downloaded again. 334 297 else { 335 progress.setString( file_size + " bytes");298 progress.setString(file_size + " b"); 336 299 progress.setStringPainted(true); 337 300 } 338 301 } 339 302 refresh(); 340 }341 342 /** Retrieve a String from the dictionary using no arguments.343 * @param key The String which acts as a key mapping for the344 * ResourceBundle.345 * @return A String which is the value for the given key.346 */347 private String get(String key) {348 return get(key, null);349 }350 351 /** Retrieve a String from the dictionary using the given arguments.352 * @param key The String which acts as a key mapping for the353 * ResourceBundle.354 * @param args A String array of arguments to be filled out inside the355 * dictionary value.356 * @return A String which is the value for the given key.357 */358 private String get(String key, String args[]) {359 if(key.indexOf('.') == -1) {360 return gatherer.dictionary.get("GProgressBar."+key, args);361 }362 return gatherer.dictionary.get(key, args);363 }364 365 /** The given parameter is taken as the number of bytes and is366 * formatted into a strings such as:367 * 45 bytes368 * 1.21 Kbytes369 * 2.12 Mbytes370 * etc371 * @param size The number to be formatted, in bytes, as a Long.372 * @return A String which contains the size formatting into a373 * nice little number - unit label.374 */375 private String formatMetric(long size) {376 if(size > 1024) {377 return (size / 1024) + " Kbytes";378 }379 return size + " bytes";380 303 } 381 304 … … 389 312 String args1[] = new String[1]; 390 313 args1[0] = initial_url.toString(); 391 392 //main_status.setText(get("Main_Status", args1)); 393 main_status.setText("Mirroring " + args1[0] + "."); 394 395 if(current_url != null) { 396 // Refresh the current label contents. 314 Dictionary.setText(main_status, "Mirroring.Job.Mirroring", args1); 315 316 if (current_url != null) { 317 // Refresh the current label contents. 397 318 String args2[] = new String[1]; 398 319 args2[0] = current_url; 399 400 String cstext = "Downloading " + args2[0]; 401 current_status.setText(Utility.trim(cstext, 50)); 402 } 403 else if(current_action == Job.STOPPED 404 || current_action == Job.PAUSED) { 405 current_status.setText("Waiting for user action."); 406 } 320 Dictionary.setText(current_status, "Mirroring.Job.Downloading", args2); 321 } 322 else if (current_action == Job.STOPPED || current_action == Job.PAUSED) { 323 Dictionary.setText(current_status, "Mirroring.Job.Waiting_User"); 324 } 407 325 else { 408 current_status.setText("Mirroring Complete.");326 Dictionary.setText(current_status, "Mirroring.Job.Mirroring_Complete"); 409 327 } 410 328 … … 415 333 args3[2] = warning_count + ""; 416 334 args3[3] = err_count + ""; 417 418 results_status.setText("Downloaded " + args3[0] + " of " + 419 args3[1] + " files (" + args3[2] + 420 " warnings, " + args3[3] + " errors)"); 335 Dictionary.setText(results_status, "Mirroring.Job.Status", args3); 421 336 422 337 this.updateUI();
Note:
See TracChangeset
for help on using the changeset viewer.