Ignore:
Timestamp:
2004-01-27T16:35:34+13:00 (20 years ago)
Author:
jmt12
Message:

More modifications to mirroring including testing for a valid version of Wget (and complaining if its missing or it is old) and rearranging buttons on the GProgressBar

File:
1 edited

Legend:

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

    r6590 r6622  
    5151import org.greenstone.gatherer.file.FileNode;
    5252import org.greenstone.gatherer.gui.GLIButton;
     53import org.greenstone.gatherer.gui.URLField;
     54import org.greenstone.gatherer.util.StaticStrings;
    5355import org.greenstone.gatherer.util.Utility;
    5456
     
    6062    extends JPanel {
    6163
     64    private boolean download_button_enabled = false;
     65    private boolean ready = false;
    6266    private JButton download_button;
    6367    private JCheckBox higher_checkbox;
     
    6670    private JScrollPane list_scroll;
    6771    private JComboBox depth_combobox;
    68     private JTextField url_textfield;
     72    private URLField url_field;
    6973    private Vector depth_model;
    7074    private WGet getter;
     
    8690    url_label.setPreferredSize(Utility.LABEL_SIZE);
    8791    Dictionary.registerText(url_label, "Mirroring.Source_URL");
    88     url_textfield = new JTextField();
    89     Dictionary.registerTooltip(url_textfield, "Mirroring.Source_URL_Tooltip");
     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));
     93    Dictionary.registerTooltip(url_field, "Mirroring.Source_URL_Tooltip");
    9094
    9195    depth_model = new Vector();
    9296    /* @todo - add to dictionary */
    93     depth_model.add(new DepthEntry(0, "0 (this page only)"));
    94     /* @todo - add to dictionary */
    95     depth_model.add(new DepthEntry(1, "1"));
    96     /* @todo - add to dictionary */
    97     depth_model.add(new DepthEntry(2, "2"));
    98     /* @todo - add to dictionary */
    99     depth_model.add(new DepthEntry(3, "3"));
    100     /* @todo - add to dictionary */
    101     depth_model.add(new DepthEntry(4, "4"));
    102     /* @todo - add to dictionary */
    103     depth_model.add(new DepthEntry(5, "5"));
    104     /* @todo - add to dictionary */
    105     depth_model.add(new DepthEntry(-1, "Unlimited"));
     97    depth_model.add(new DepthEntry(0, "Mirroring.Download_Depth.Zero"));
     98    /* @todo - add to dictionary */
     99    depth_model.add(new DepthEntry(1, String.valueOf(1)));
     100    /* @todo - add to dictionary */
     101    depth_model.add(new DepthEntry(2, String.valueOf(3)));
     102    /* @todo - add to dictionary */
     103    depth_model.add(new DepthEntry(3, String.valueOf(3)));
     104    /* @todo - add to dictionary */
     105    depth_model.add(new DepthEntry(4, String.valueOf(4)));
     106    /* @todo - add to dictionary */
     107    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"));
    106110    JPanel depth_pane = new JPanel();
    107111    JLabel depth_label = new JLabel();
     
    121125   
    122126    /* @todo - add to dictionary */
    123     JLabel further_label = new JLabel("For further options see File->Preferences->Connection");
     127    JLabel further_label = new JLabel("Mirroring.Further_Options");
    124128
    125129    JPanel button_pane = new JPanel();
     
    130134    // Connect
    131135    download_button.addActionListener(new DownloadButtonListener());
     136    url_field.getDocument().addDocumentListener(new DownloadButtonEnabler());
    132137
    133138    // Layout
    134139    url_pane.setLayout(new BorderLayout());
    135140    url_pane.add(url_label, BorderLayout.WEST);
    136     url_pane.add(url_textfield, BorderLayout.CENTER);
     141    url_pane.add(url_field, BorderLayout.CENTER);
    137142
    138143    depth_pane.setLayout(new GridLayout(1,3));
     
    165170    }
    166171
     172    public void afterDisplay() {
     173    ready = true;
     174    }
     175
    167176    public void collectionChanged(boolean ready) {
    168177    }
    169178
     179    /** This method is called whenever the Mirror pane is brought into focus and is a good time to display a warning message if WGet is not available or of an older, problematic, version.
     180     */
     181    public void gainFocus() {
     182    if(!ready) {
     183        return;
     184    }
     185    // Lets see what warning message we should display, if any.
     186    String wget_version_str = Gatherer.config.getWGetVersion();
     187    if(wget_version_str.equals(StaticStrings.NO_WGET_STR)) {
     188        // If there was no WGet available then downloading is disabled entirely
     189        download_button_enabled = false;
     190        // And we tell the user why.
     191        /** @todo - add to dictionary */
     192        JOptionPane.showMessageDialog(Gatherer.g_man, "Mirroring.No_WGet", "Mirroring.No_WGet_Title", JOptionPane.ERROR_MESSAGE);
     193    }
     194    else if(wget_version_str.equals(StaticStrings.WGET_OLD_STR)) {
     195        // Downloading is enabled
     196        download_button_enabled = true;
     197        // But we display a preventable warning message about the path problems.
     198        WarningDialog dialog = new WarningDialog("warning.OldWGet", false);
     199        dialog.display();
     200        dialog.dispose();
     201        dialog = null;
     202    }
     203    // Otherwise version must be ok
     204    else {
     205        download_button_enabled = true;
     206    }
     207    // 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.
     208    download_button.setEnabled(download_button_enabled && !url_field.isEmpty() && url_field.validateURL());
     209    }
     210
    170211    public void setURL(String url) {
    171     url_textfield.setText(url);
     212    url_field.setText(url);
    172213    }
    173214
     
    175216    static public FileNode getWebCacheMapping()
    176217    {
    177     if (Gatherer.config.get("workflow.mirror", false) && Gatherer.c_man.ready()) {
     218    if (Gatherer.config.get("workflow.mirror", true) || Gatherer.config.get("workflow.mirror", false)) {
    178219        /* @todo - add to dictionary */
    179         return new FileNode(Utility.getCacheDir(), "Mirror Cache");
     220        return new FileNode(Utility.getCacheDir(), "Mirroring.Mirror_Cache");
    180221    }
    181222    return null;
     
    235276    }
    236277
     278    private class DownloadButtonEnabler
     279    implements DocumentListener {
     280    /** Gives notification that an attribute or set of attributes changed. */
     281    public void changedUpdate(DocumentEvent e) {
     282        validateDownloadButton();
     283    }
     284        /** Gives notification that there was an insert into the document. */
     285    public void insertUpdate(DocumentEvent e) {
     286        validateDownloadButton();
     287    }
     288        /** Gives notification that a portion of the document has been removed. */
     289    public void removeUpdate(DocumentEvent e) {
     290        validateDownloadButton();
     291    }
     292    private void validateDownloadButton() {
     293        download_button.setEnabled(download_button_enabled && !url_field.isEmpty() && url_field.validateURL());
     294    }
     295    }
     296
    237297    private class DownloadButtonListener
    238298    implements ActionListener {
     
    240300    public void actionPerformed(ActionEvent event) {
    241301        // Retrieve the current url and confirm it is valid
    242         String url_str = url_textfield.getText();
     302        String url_str = url_field.getText();
    243303        URL url = null;
    244304        try {
     
    273333        catch(Exception exception) {
    274334            /* @todo - add to dictionary */
    275             JOptionPane.showMessageDialog(Gatherer.g_man, "The depth value you have entered is not valid.\nPlease choose an item from the list, or type in\na number.", "Invalid Depth", JOptionPane.ERROR_MESSAGE);
     335            JOptionPane.showMessageDialog(Gatherer.g_man, "Mirroring.Mirror_Depth.Invalid_Depth", "Mirroring.Mirror_Depth.Invalid_Depth_Title", JOptionPane.ERROR_MESSAGE);
    276336            return;
    277337        }
Note: See TracChangeset for help on using the changeset viewer.