Ignore:
Timestamp:
2003-10-03T17:09:38+12:00 (21 years ago)
Author:
mdewsnip
Message:

More small updates and tooltips added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/GProgressBar.java

    r5322 r5571  
    3535 *########################################################################
    3636 */
    37 
    38  
    39 
    40 
    41 
    42 
    4337package org.greenstone.gatherer.gui;
    4438
    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;
     39import java.awt.*;
     40import java.awt.event.*;
     41import javax.swing.*;
     42import javax.swing.border.*;
     43import org.greenstone.gatherer.Dictionary;
    6244import org.greenstone.gatherer.Gatherer;
    6345import org.greenstone.gatherer.collection.Job;
     
    7153
    7254    private Dimension bar_size = new Dimension(520, 15);
    73 
    74     private Gatherer gatherer;
    75 
    76     private ImageIcon busy_bar;
    77     private ImageIcon ready_bar;
    7855
    7956    private int current_action;
     
    10481    public JButton cancel;
    10582
    106     //public GProgressBar(Gatherer gatherer, WGet owner, String initial_url) {
    107     //    this.gatherer = gatherer;
    10883    public GProgressBar(Job owner, String initial_url, boolean simple) {
    10984    this.owner = owner;
     
    12095    this.setLayout(new BorderLayout());
    12196    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);
    12797
    12898    this.current_action = Job.STOPPED;
    129          
     99
    130100    inner_pane = new JPanel(new BorderLayout());
    131101    inner_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
    132102
    133103    action = new JButton(Utility.getImage("vcrplay.gif"));
    134     //action.setToolTipText(get("Action_Tip"));
    135     action.setToolTipText("Start current download");
    136104    action.addActionListener(this);
    137105    action.addActionListener(owner);
     106    Dictionary.setTooltip(action, "Mirroring.Job.Start_Tooltip");
    138107
    139108    center_pane = new JPanel(new GridLayout(3,1));
     
    146115
    147116    progress = new JProgressBar();
    148     progress.setString("Waiting to start");
    149117    progress.setStringPainted(true);
    150118    progress.setMinimum(0);
    151119    progress.setMaximum(0);
    152120    progress.setEnabled(false);
     121    Dictionary.setText(progress, "Mirroring.Job.Waiting");
    153122    inner_pane.add(progress, BorderLayout.CENTER);
    154123
     
    158127
    159128    cancel = new JButton(Utility.getImage("vcrstop.gif"));
    160     //cancel.setToolTipText(get("Cancel_Tip"));
    161     cancel.setToolTipText("Cancel current download");
    162129    cancel.addActionListener(owner);
    163130    cancel.addActionListener(this);
     131    Dictionary.setTooltip(cancel, "Mirroring.Job.Stop_Tooltip");
    164132
    165133    inner_pane.add(center_pane, BorderLayout.NORTH);
     
    175143    public void actionPerformed(ActionEvent event) {
    176144    if(event.getSource() == action) {
    177         if(current_action == Job.RUNNING) {
     145        if (current_action == Job.RUNNING) {
    178146        current_action = Job.STOPPED;
    179147        action.setIcon(Utility.getImage("vcrplay.gif"));
    180         action.setToolTipText("Start current download");
     148        Dictionary.setTooltip(action, "Mirroring.Job.Start_Tooltip");
    181149        cancel.setEnabled(true);
    182150        }
     
    184152        current_action = Job.RUNNING;
    185153        action.setIcon(Utility.getImage("vcrpause.gif"));
    186         action.setToolTipText("Pause current download");
     154        Dictionary.setTooltip(action, "Mirroring.Job.Pause_Tooltip");
    187155        cancel.setEnabled(false);
    188156        }
     
    212180    }
    213181    progress.setValue(progress.getMaximum());
    214     progress.setString("Download Complete.");
     182    Dictionary.setText(progress, "Mirroring.Job.Download_Complete");
    215183    refresh();
    216184    }
     
    232200    }
    233201
    234     public Dimension getPerferredSize() {
     202    public Dimension getPreferredSize() {
    235203    return Utility.PROGRESS_BAR_SIZE;
    236204    }
     
    259227        this.err_count = 0;
    260228        this.warning_count = 0;
    261     }               
     229    }
    262230    current_action = Job.RUNNING;
    263231    action.setIcon(Utility.getImage("vcrpause.gif"));
    264     action.setToolTipText("Pause current download");
     232    Dictionary.setTooltip(cancel, "Mirroring.Job.Pause_Tooltip");
    265233    // If this is a simple download, then pause is not available (nor is prematurely stopping!)
    266234    action.setEnabled(!simple);
     
    283251    }
    284252    progress.setValue(progress.getMaximum());
    285     progress.setString("Mirroring Complete.");
     253    Dictionary.setText(progress, "Mirroring.Job.Mirror_Complete");
    286254
    287255    action.setIcon(Utility.getImage("vcrfastforward.gif"));
    288     action.setToolTipText("Restart current download");
     256    Dictionary.setText(action, "Mirroring.Job.Restart");
    289257    action.setEnabled(true);
    290258    cancel.setEnabled(true);
     
    298266    file_size = file_size + current;
    299267    if(!progress.isIndeterminate()) {
    300                 // If current is zero, then this is the 'precall' before the
    301                 // downloading actually starts.
     268        // If current is zero, then this is the 'precall' before the
     269        // downloading actually starts.
    302270        if(current == 0) {
    303271        // Remove the old progress bar, then deallocate it.
     
    305273        progress = null;
    306274        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!
    309276            progress = new JProgressBar(0, 100);
    310277        }
    311278        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());
    316281        }
    317282        progress.setEnabled(true);
     
    320285        inner_pane.updateUI();
    321286        }
    322                 // Otherwise if expected is not zero move the progress bar and
    323                 // update percent complete.
     287        // Otherwise if expected is not zero move the progress bar and
     288        // update percent complete.
    324289        else if (expected != 0) {
    325290        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();
    329292        progress.setString(p_c + "%");
    330293        progress.setStringPainted(true);
    331294        }
    332                 // Finally, in the case we have no content length, we'll instead
    333                 // write the current number of bytes downloaded again.
     295        // Finally, in the case we have no content length, we'll instead
     296        // write the current number of bytes downloaded again.
    334297        else {
    335         progress.setString( file_size + " bytes");
     298        progress.setString(file_size + " b");
    336299        progress.setStringPainted(true);
    337300        }
    338301    }
    339302    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 the
    344      * 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 the
    353      * ResourceBundle.
    354      * @param args A String array of arguments to be filled out inside the
    355      * 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 is
    366      * formatted into a strings such as:
    367      *   45 bytes
    368      * 1.21 Kbytes
    369      * 2.12 Mbytes
    370      * etc
    371      * @param size The number to be formatted, in bytes, as a Long.
    372      * @return A String which contains the size formatting into a
    373      * 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";
    380303    }
    381304
     
    389312    String args1[] = new String[1];
    390313    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.
    397318        String args2[] = new String[1];
    398319        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    }
    407325    else {
    408         current_status.setText("Mirroring Complete.");
     326        Dictionary.setText(current_status, "Mirroring.Job.Mirroring_Complete");
    409327    }
    410328
     
    415333    args3[2] = warning_count + "";
    416334    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);
    421336
    422337    this.updateUI();
Note: See TracChangeset for help on using the changeset viewer.