Changeset 5323 for trunk/gli/src


Ignore:
Timestamp:
2003-08-28T12:43:19+12:00 (21 years ago)
Author:
jmt12
Message:

Complete redesign and recode. Choped almost 300 lines out of the class. Whoopee. Pretty much has the same functionality bar the removal of the Workspace Tree, that was only really there for eye-candy anyway

File:
1 edited

Legend:

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

    r5157 r5323  
    3838import java.awt.*;
    3939import java.awt.event.*;
     40import java.net.*;
    4041import javax.swing.*;
    4142import javax.swing.border.*;
     
    5859 */
    5960public class MirrorPane
    60     extends JPanel
    61     implements ActionListener {
     61    extends JPanel {
     62    private JButton download_button = null;
     63    private JCheckBox automatic_checkbox = null;
     64    private JCheckBox higher_checkbox = null;
     65    private JCheckBox overwrite_checkbox = null;
     66    private JCheckBox remove_failed_checkbox = null;
     67    private JCheckBox same_host_checkbox = null;
     68    private JRadioButton public_radiobutton = null;
     69    private JRadioButton private_radiobutton = null;
     70    private JScrollPane list_scroll = null;
     71    private JSpinner depth_spinner = null;
     72    private JTextField url_textfield = null;
     73    private WGet getter = null;
     74    public MirrorPane() {
     75    super();
     76    // Create a new wget thread
     77        getter = new WGet();
     78        getter.start();
     79    // And retrieve its list of pending jobs
     80    list_scroll = getter.getJobList();
    6281
    63     private ButtonGroup destination_folder_options;
    64     private DragTree workspace_tree = null;
    65     private FileSystemModel model = null;
    66     /** The filter currently applied to the workspace tree. */
    67     private Filter workspace_filter = null;
     82    // Create
     83    JPanel edit_pane = new JPanel();
     84    JPanel details_pane = new JPanel();
    6885
    69     private ImageIcon thumbnail;
     86    JPanel url_pane = new JPanel();
     87    JLabel url_label = new JLabel(Gatherer.dictionary.get("Mirroring.Source_URL"));
     88    url_label.setPreferredSize(Utility.LABEL_SIZE);
     89    url_textfield = new JTextField();
    7090
    71     private JButton download;
    72     private JButton view_selector;
     91    JPanel depth_pane = new JPanel();
     92    JLabel depth_label = new JLabel(Gatherer.dictionary.get("Mirroring.Download_Depth"));
     93    depth_spinner = new JSpinner();
    7394
    74     private JCheckBox download_hidden;
    75     private JCheckBox higher_directories;
    76     private JCheckBox infinite;
    77     private JCheckBox overwrite_existing;
    78     private JCheckBox remove_failed;
    79     private JCheckBox same_host;
     95    JPanel destination_pane = new JPanel();
     96    JLabel destination_label = new JLabel(Gatherer.dictionary.get("Mirroring.Destination_Folder"));
     97    ButtonGroup group = new ButtonGroup();
     98    public_radiobutton = new JRadioButton(Gatherer.dictionary.get("Tree.Public"));
     99    private_radiobutton = new JRadioButton(Gatherer.dictionary.get("Tree.Private"));
     100    group.add(public_radiobutton);
     101    group.add(private_radiobutton);
     102    public_radiobutton.setSelected(true);
    80103
    81     private JScrollPane list_scroll;
    82     private JScrollPane workspace_scroll;
     104    JPanel first_pane = new JPanel();
     105    automatic_checkbox = new JCheckBox(Gatherer.dictionary.get("Mirroring.Download_Hidden"));
     106    overwrite_checkbox = new JCheckBox(Gatherer.dictionary.get("Mirroring.Overwrite_Existing"));
    83107
    84     private JTextField download_depth;
    85     private JTextField number_downloads;
    86     private JTextField number_each_host;
    87     private JTextField source_url;
     108    JPanel second_pane = new JPanel();
     109    higher_checkbox = new JCheckBox(Gatherer.dictionary.get("Mirroring.Higher_Directories"));
     110    same_host_checkbox = new JCheckBox(Gatherer.dictionary.get("Mirroring.Same_Host"));
    88111
    89     private JToggleButton destination_private;
    90     private JToggleButton destination_shared;
     112    remove_failed_checkbox = new JCheckBox(Gatherer.dictionary.get("Mirroring.Remove_Failed"));
     113    JLabel further_label = new JLabel(Gatherer.dictionary.get("Mirroring.Further_Options"));
     114   
     115    JPanel button_pane = new JPanel();
     116    download_button = new JButton(Gatherer.dictionary.get("Mirroring.Download"));
    91117
     118    // Connect
     119    download_button.addActionListener(new DownloadButtonListener());
    92120
    93     /** Ensures that expansion and selection events between workspace trees based on the same model are synchronized. */
    94     private TreeSynchronizer tree_sync = null;
    95     /** A reference to the object that provides JNI ability. */
    96     private WGet getter;
    97     /** The default size of a label in the interface. */
    98     static final private Dimension LABEL_SIZE = new Dimension(100,30);
    99     /** The default size of the tree in the interface. */
    100     static final private Dimension TREE_SIZE = new Dimension(250, 430);
     121    // Layout
     122    url_pane.setLayout(new BorderLayout());
     123    url_pane.add(url_label, BorderLayout.WEST);
     124    url_pane.add(url_textfield, BorderLayout.CENTER);
    101125
    102     public MirrorPane(TreeSynchronizer workspace_tree_sync) {
    103     this.tree_sync = workspace_tree_sync;
    104     getter = new WGet();
    105     getter.start();
    106     }
     126    depth_pane.setLayout(new GridLayout(1,3));
     127    depth_pane.add(depth_label);
     128    depth_pane.add(new JPanel());
     129    depth_pane.add(depth_spinner);
    107130
    108     public void actionPerformed(ActionEvent event) {
    109     Object event_source = event.getSource();
    110     if(event_source == download) {
    111                 // Check we have a valid url.
    112         GURL target_gurl = new GURL(source_url.getText());
    113         if(target_gurl.getURL() != null) {
    114         // Update configuration settings.
    115         Gatherer.config.set("mirroring.page_requisites", false, download_hidden.isSelected());
    116         Gatherer.config.set("mirroring.no_parents", false, !higher_directories.isSelected());
    117         Gatherer.config.set("mirroring.clobber", false, overwrite_existing.isSelected());
    118         Gatherer.config.set("mirroring.remove_failed", false, remove_failed.isSelected());
    119         Gatherer.config.set("mirroring.other_hosts", false, !same_host.isSelected());
    120         // Depth
    121         if(infinite.isSelected()) {
    122             Gatherer.config.setInt("mirroring.depth", false, -1);
    123         }
    124         else if(download_depth.getText().length() > 0){
    125             //Gatherer.println("Download_depth = " + download_depth.getText().trim());
    126             Gatherer.config.setInt("mirroring.depth", false, Integer.parseInt(download_depth.getText().trim()));
    127         }
     131    destination_pane.setLayout(new GridLayout(1,3));
     132    destination_pane.add(destination_label);
     133    destination_pane.add(public_radiobutton);
     134    destination_pane.add(private_radiobutton);
    128135
    129         // Queue download
    130         if(destination_shared.isSelected()) {
    131             getter.newJob(new GURL(source_url.getText()), model, Utility.CACHE_DIR);
    132         }
    133         else {
    134             getter.newJob(new GURL(source_url.getText()), model, Gatherer.c_man.getCollectionCache());
    135         }
    136         }
    137                 // Otherwise indicate to the user that they've done something
    138                 // wrong.
    139         else {
    140         // Error message box.
    141         String args[] = new String[1];
    142         args[0] = source_url.getText();
    143         message(Message.ERROR, get("Malformed_URL", args));
    144         // Colour source_url red
    145         source_url.setForeground(Color.red);
    146         }
     136    first_pane.setLayout(new GridLayout(1,2));
     137    first_pane.add(automatic_checkbox);
     138    first_pane.add(overwrite_checkbox);
    147139
    148     }
    149     else if(event_source == source_url) {
    150                 // They've typed something. Change colour back to black
    151         source_url.setForeground(Color.black);
    152     }
     140    second_pane.setLayout(new GridLayout(1,2));
     141    second_pane.add(higher_checkbox);
     142    second_pane.add(same_host_checkbox);
     143
     144    details_pane.setLayout(new GridLayout(7,1,0,5));
     145    details_pane.add(url_pane);
     146    details_pane.add(depth_pane);
     147    details_pane.add(destination_pane);
     148    details_pane.add(first_pane);
     149    details_pane.add(second_pane);
     150    details_pane.add(remove_failed_checkbox);
     151    details_pane.add(further_label);
     152
     153    button_pane.setLayout(new GridLayout(1,3));
     154    button_pane.add(new JPanel());
     155    button_pane.add(new JPanel());
     156    button_pane.add(download_button);
     157
     158    edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Gatherer.dictionary.get("Mirroring.Download_Controls")), BorderFactory.createEmptyBorder(2,2,2,2))));
     159    edit_pane.setLayout(new BorderLayout());
     160    edit_pane.add(details_pane, BorderLayout.CENTER);
     161    edit_pane.add(button_pane, BorderLayout.SOUTH);
     162
     163    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     164    setLayout(new BorderLayout());
     165    add(list_scroll, BorderLayout.CENTER);
     166    add(edit_pane, BorderLayout.SOUTH);
    153167    }
    154168
    155169    public void collectionChanged(boolean ready) {
    156     // Some buttons are only enabled if a collection is open.
    157     if(ready) {
    158         destination_private.setEnabled(true);
     170    if(private_radiobutton.isSelected() && !ready) {
     171        public_radiobutton.setSelected(true);
    159172    }
    160     else {
    161         destination_shared.setSelected(true);
    162         destination_private.setEnabled(false);
    163     }
    164     // Retrieve appropriate workspace
    165     model = (FileSystemModel) Gatherer.c_man.getWorkspace();
    166     workspace_tree.setModel(model);
    167     tree_sync.add(workspace_tree);
    168     }
    169 
    170     public void display() {
    171     this.setLayout(new BorderLayout());
    172 
    173     // Create
    174     JPanel tree_pane = new JPanel(new BorderLayout());
    175     tree_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    176     tree_pane.setMinimumSize(TREE_SIZE);
    177     tree_pane.setSize(TREE_SIZE);
    178     tree_pane.setPreferredSize(TREE_SIZE);
    179 
    180     //Gatherer.println("\tCreating tree_label");
    181     JLabel tree_label = new JLabel(get("Workspace_Tree"));
    182 
    183     //Gatherer.println("\tCreating public tree");
    184     model = (FileSystemModel) Gatherer.c_man.getWorkspace();
    185     workspace_tree = new DragTree("Workspace_Mirror", model, null, true);
    186     workspace_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    187     workspace_tree.putClientProperty("JTree.lineStyle", "Angled");
    188     workspace_tree.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_background", false));
    189     workspace_tree.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false));
    190     workspace_tree.setRootVisible(false);
    191     workspace_tree.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_background", false));
    192     workspace_tree.setTextSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_foreground", false));
    193 
    194     // Add to a dummy drag-group.
    195     DragGroup group = new DragGroup();
    196     group.add(workspace_tree);
    197     group = null;
    198 
    199     workspace_filter = Gatherer.g_man.getFilter(workspace_tree);
    200     workspace_filter.setBackground(Gatherer.config.getColor("coloring.workspace_heading_background", false));
    201     // Change the default colours of this filters combobox.
    202     GComboBox fcb = workspace_filter.getComboBox();
    203     fcb.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_background", false));
    204     fcb.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false));
    205     fcb.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_background", false));
    206     fcb.setTextSelectionColor(Gatherer.config.getColor("coloring.workspace_selection_foreground", false));
    207     fcb = null;
    208 
    209     tree_pane.add(tree_label, BorderLayout.NORTH);
    210     tree_pane.add(new JScrollPane(workspace_tree), BorderLayout.CENTER);
    211     tree_pane.add(workspace_filter, BorderLayout.SOUTH);
    212 
    213     // Create control_pane
    214     JPanel control_pane = new JPanel(new BorderLayout());
    215 
    216     //Gatherer.println("\tCreating control_label");
    217     JLabel control_label = new JLabel(get("Download_Controls"));
    218     control_label.setHorizontalAlignment(JLabel.CENTER);
    219     control_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    220 
    221     //central_pane = new JPanel(new GridLayout(7,1));
    222     JPanel central_pane = new JPanel();
    223     central_pane.setLayout(new BoxLayout(central_pane, BoxLayout.Y_AXIS));
    224 
    225     //Gatherer.println("\tCreating source_url_pane");
    226     JPanel source_url_pane = new JPanel(new BorderLayout());
    227     JLabel source_url_label = new JLabel(get("Source_URL"));
    228     source_url_label.setPreferredSize(LABEL_SIZE);
    229     source_url = new JTextField("");
    230     source_url_pane.add(source_url_label, BorderLayout.WEST);
    231     source_url_pane.add(source_url, BorderLayout.CENTER);
    232 
    233 
    234     //Gatherer.println("\tCreating download_depth");
    235     JPanel download_depth_pane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    236     JLabel download_depth_label = new JLabel(get("Download_Depth"));
    237     // Default depth. Its an int so we'll do some magic handwaving to magic it into a String. Alakazam.
    238     download_depth = new JTextField(Utility.getDepthString(6));
    239     infinite = new JCheckBox("Infinite");
    240     download_depth_pane.add(download_depth_label);
    241     download_depth_pane.add(download_depth);
    242     download_depth_pane.add(infinite);
    243 
    244     //Gatherer.println("\tCreating destination_folder");
    245     JPanel destination_folder_pane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    246     JLabel destination_folder_label = new JLabel(get("Destination_Folder"));
    247     destination_folder_options = new ButtonGroup();
    248     destination_private = new JToggleButton(get("Destination_Private"));
    249     destination_private.setEnabled(Gatherer.c_man != null && Gatherer.c_man.ready());
    250     destination_private.setIcon(Utility.OFF_ICON);
    251     destination_private.setSelectedIcon(Utility.ON_ICON);
    252     destination_private.setSelected(false);
    253     destination_private.addActionListener(this);
    254     destination_folder_options.add(destination_private);
    255     destination_shared = new JToggleButton(get("Destination_Shared"));
    256     destination_shared.setIcon(Utility.OFF_ICON);
    257     destination_shared.setSelectedIcon(Utility.ON_ICON);
    258     destination_shared.setSelected(true);
    259     destination_shared.addActionListener(this);
    260     destination_folder_options.add(destination_shared);
    261     destination_folder_pane.add(destination_folder_label);
    262     destination_folder_pane.add(destination_private);
    263     destination_folder_pane.add(destination_shared);
    264 
    265     //Gatherer.println("\tCreating download_hidden");
    266     download_hidden = new JCheckBox(get("Download_Hidden"));
    267     // Why the friken heil is the horizontal alignment called Y?
    268     download_hidden.setAlignmentY(Component.LEFT_ALIGNMENT);
    269     download_hidden.setSelected(Gatherer.config.get("mirroring.page_requisites", false));
    270 
    271     //Gatherer.println("\tCreating higher_directories");
    272     higher_directories = new JCheckBox(get("Higher_Directories"));
    273     higher_directories.setSelected(!Gatherer.config.get("mirroring.no_parents", false));
    274 
    275     //Gatherer.println("\tCreating same_host");
    276     same_host = new JCheckBox(get("Same_Host"));
    277     same_host.setSelected(!Gatherer.config.get("mirroring.other_hosts", false));
    278 
    279     //Gatherer.println("\tCreating overwrite");
    280     overwrite_existing = new JCheckBox(get("Overwrite_Existing"));
    281     overwrite_existing.setSelected(Gatherer.config.get("mirroring.overwrite", false));
    282 
    283     JLabel further_options = new JLabel(get("Further_Options"));
    284     further_options.setHorizontalAlignment(JLabel.LEFT);
    285 
    286     central_pane.add(source_url_pane);
    287     central_pane.add(download_depth_pane);
    288     central_pane.add(destination_folder_pane);
    289 
    290     JPanel three_mid = new JPanel(new GridLayout(5,1));
    291 
    292     three_mid.add(download_hidden);
    293     three_mid.add(higher_directories);
    294     three_mid.add(same_host);
    295     three_mid.add(overwrite_existing);
    296     three_mid.add(further_options);
    297 
    298     central_pane.add(three_mid);
    299 
    300     //Gatherer.println("\tCreating thumbnail");
    301     thumbnail = new ImageIcon(Utility.RES_DIR + "no_thumbnail.gif");
    302     JLabel thumbnail_holder = new JLabel(thumbnail);
    303     // Default thumbnail size.
    304     //thumbnail_holder.setSize(Gatherer.config.getDimension("mirroring.thumbnail_size", false));
    305     thumbnail_holder.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    306 
    307     JPanel lower_pane = new JPanel(new BorderLayout());
    308     lower_pane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED), get("Download_List_Configuration")));
    309 
    310     remove_failed = new JCheckBox(get("Remove_Failed"));
    311     remove_failed.setSelected(Gatherer.config.get("mirroring.remove_failed", false));
    312 
    313     //Gatherer.println("\tCreating download_button");
    314     download = new JButton(get("Download"));
    315     download.addActionListener(this);
    316     download.setHorizontalAlignment(JLabel.CENTER);
    317     JPanel download_pane = new JPanel(new BorderLayout());
    318 
    319     lower_pane.add(remove_failed, BorderLayout.NORTH);
    320     lower_pane.add(download_pane, BorderLayout.CENTER);
    321 
    322     control_pane.add(control_label, BorderLayout.NORTH);
    323     control_pane.add(central_pane, BorderLayout.WEST);
    324     //control_pane.add(thumbnail_holder, BorderLayout.CENTER);
    325     control_pane.add(lower_pane, BorderLayout.SOUTH);
    326 
    327     // Create list_pane
    328     JPanel list_pane = new JPanel(new BorderLayout());
    329     list_pane.setPreferredSize(new Dimension(Gatherer.g_man.getSize().width, Gatherer.g_man.getSize().height / 4));
    330 
    331     download_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    332     download_pane.add(download);
    333 
    334     //Gatherer.println("\tCreating list");
    335     list_scroll = getter.getJobList();
    336 
    337     //list_pane.add(download_pane, BorderLayout.NORTH);
    338     list_pane.add(list_scroll, BorderLayout.CENTER);
    339 
    340     // Add to content
    341     JPanel temp_pane = new JPanel(new BorderLayout());
    342     this.add(tree_pane, BorderLayout.WEST);
    343     this.add(control_pane, BorderLayout.CENTER);
    344     //temp_pane.add(control_pane, BorderLayout.NORTH);
    345     //temp_pane.add(list_pane, BorderLayout.CENTER);
    346     this.add(list_pane, BorderLayout.SOUTH);
    347     }
    348 
    349     public void refreshTrees() {
    350     workspace_tree.refresh(null);
     173    private_radiobutton.setEnabled(ready);
    351174    }
    352175
    353176    public void setURL(String url) {
    354     source_url.setText(url);
     177    url_textfield.setText(url);
    355178    }
    356179
    357     private String get(String key) {
    358     return get(key, null);
    359     }
     180    private class DownloadButtonListener
     181    implements ActionListener {
    360182
    361     private String get(String key, String args[]) {
    362     if(key.indexOf('.') == -1) {
    363         key = "Mirroring." + key;
    364     }
    365     return Gatherer.dictionary.get(key,args);
    366     }
    367 
    368     /** Creates and dispatches a message given the initial details.
    369      * @param level An int indicating the message level for this message.
    370      * @param message A String which contains the payload of this message.
    371      */
    372     private void message(int level, String message) {
    373     Message msg = new Message(Message.MIRRORING, level, message);
    374     if(Gatherer.g_man != null) {
    375         Gatherer.g_man.message_pane.show(msg);
    376     } else {
    377         Gatherer.println(msg.toString());
     183    public void actionPerformed(ActionEvent event) {
     184        // Retrieve the current url and confirm its valid
     185        String url_str = url_textfield.getText();
     186        URL url = null;
     187        try {
     188        url = new URL(url_str);
     189        }
     190        catch(MalformedURLException error) {
     191        JOptionPane.showMessageDialog(Gatherer.g_man, Gatherer.dictionary.get("Mirroring.Invalid_URL"), Gatherer.dictionary.get("Mirroring.Invalid_URL__Title"), JOptionPane.ERROR_MESSAGE);
     192        }
     193        if(url != null) {
     194        // Otherwise construct a new download job
     195        getter.newJob(Gatherer.c_man.getWorkspace(), overwrite_checkbox.isSelected(), !higher_checkbox.isSelected(), !same_host_checkbox.isSelected(), automatic_checkbox.isSelected(), url, ((Integer)depth_spinner.getValue()).intValue(), (public_radiobutton.isSelected() ? Utility.CACHE_DIR : Gatherer.c_man.getCollectionCache()));
     196        }
    378197    }
    379198    }
Note: See TracChangeset for help on using the changeset viewer.