Changeset 7662


Ignore:
Timestamp:
2004-06-29T15:03:46+12:00 (20 years ago)
Author:
kjdon
Message:

lots of changes. url field is now just a plain textfield. does no validation of url. interface redesigned slightly. clear cache button now here.

File:
1 edited

Legend:

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

    r7540 r7662  
    4646import javax.swing.event.*;
    4747import javax.swing.tree.*;
     48import org.greenstone.gatherer.Configuration;
    4849import org.greenstone.gatherer.Dictionary;
    4950import org.greenstone.gatherer.Gatherer;
     
    5354import org.greenstone.gatherer.gui.Preferences;
    5455import org.greenstone.gatherer.gui.URLField;
     56import org.greenstone.gatherer.gui.tree.WorkspaceTree;
    5557import org.greenstone.gatherer.util.StaticStrings;
    5658import org.greenstone.gatherer.util.Utility;
     
    6365    extends JPanel {
    6466
     67    /** The threshold for when the advanced options get added */
     68    static private final int THRESHOLD = Configuration.SYSTEMS_MODE;
     69
    6570    private boolean download_button_enabled = false;
    6671    private boolean ready = false;
     72    private int current_mode;
     73    private JButton clear_cache_button;
    6774    private JButton download_button;
    6875    private JCheckBox higher_checkbox;
     
    7178    private JScrollPane list_scroll;
    7279    private JComboBox depth_combobox;
    73     private URLField url_field;
     80    //private URLField url_field;
     81    private JPanel options_pane;
     82    private JTextField url_field;
    7483    private Vector depth_model;
    7584    private WGet getter;
     
    8190        getter.start();
    8291    // 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);
    8597    // Create
    8698    JPanel edit_pane = new JPanel();
    8799    JPanel details_pane = new JPanel();
     100    options_pane = new JPanel();
    88101
    89102    JPanel url_pane = new JPanel();
    90103    JLabel url_label = new JLabel();
    91104    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();
    93106    Dictionary.registerTooltip(url_field, "Mirroring.Source_URL_Tooltip");
    94107
    95108    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")));
    98110    /* @todo - add to dictionary */
    99111    depth_model.add(new DepthEntry(1, String.valueOf(1)));
    100112    /* @todo - add to dictionary */
    101     depth_model.add(new DepthEntry(2, String.valueOf(3)));
     113    depth_model.add(new DepthEntry(2, String.valueOf(2)));
    102114    /* @todo - add to dictionary */
    103115    depth_model.add(new DepthEntry(3, String.valueOf(3)));
     
    106118    /* @todo - add to dictionary */
    107119    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")));
    110121    JPanel depth_pane = new JPanel();
    111122    JLabel depth_label = new JLabel();
     
    115126
    116127    requisite_checkbox = new JCheckBox();
    117     Dictionary.registerText(requisite_checkbox, "Mirroring.Download_Hidden");
     128    Dictionary.registerText(requisite_checkbox, "Mirroring.Download_Embedded");
     129   
    118130
    119131    higher_checkbox = new JCheckBox();
    120132    Dictionary.registerText(higher_checkbox, "Mirroring.Higher_Directories");
    121 
     133    higher_checkbox.addActionListener(new CheckboxClickListener());
     134   
    122135    same_host_checkbox = new JCheckBox();
    123136    same_host_checkbox.setSelected(true);
     
    126139    JPanel button_pane = new JPanel();
    127140
    128     JButton preferences_button = new GLIButton("Mirroring.Further_Options");
     141    JButton preferences_button = new GLIButton();
     142    preferences_button.setEnabled(true);
    129143    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");
    130150
    131151    download_button = new GLIButton();
    132     download_button.setEnabled(false);
     152    download_button.setEnabled(true);
    133153    download_button.setMnemonic(KeyEvent.VK_D);
    134154    Dictionary.registerBoth(download_button, "Mirroring.Download", "Mirroring.Download_Tooltip");
    135 
    136155    // Connect
     156    clear_cache_button.addActionListener(new ClearCacheListener());
    137157    download_button.addActionListener(new DownloadButtonListener());
    138158    preferences_button.addActionListener(new PreferencesButtonActionListener());
    139     url_field.getDocument().addDocumentListener(new DownloadButtonEnabler());
    140159
    141160    // Layout
     
    149168    depth_pane.add(depth_combobox);
    150169
    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));
    152172    details_pane.add(url_pane);
    153173    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));
    159184    button_pane.add(preferences_button);
    160     button_pane.add(new JPanel());
     185    button_pane.add(clear_cache_button);
    161186    button_pane.add(download_button);
    162187
    163188    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))));
    164189    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);
    167193
    168194    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     
    191217        download_button_enabled = false;
    192218        // 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();
    195220    }
    196221    else if(wget_version_str.equals(StaticStrings.WGET_OLD_STR)) {
     
    198223        download_button_enabled = true;
    199224        // 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();
    204226    }
    205227    // Otherwise version must be ok
     
    208230    }
    209231    // 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
    226253
    227254    /** 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. */
     
    278305    }
    279306
    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   
    299328    private class DownloadButtonListener
    300329    implements ActionListener {
     
    350379
    351380        if(url != null) {
    352         getter.newJob(!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);
    353382        }
    354383    }
     
    361390    }
    362391    }
     392
     393
    363394}
Note: See TracChangeset for help on using the changeset viewer.