Changeset 10659

Show
Ignore:
Timestamp:
27.09.2005 17:32:23 (14 years ago)
Author:
mdewsnip
Message:

Write CD/DVD image prompt now gives an estimate of the size of the exported collections.

Location:
trunk/gli
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/gli/classes/dictionary.properties

    r10638 r10659  
    463463WriteCDImagePrompt.Instructions:Export one or more collections to a self-installing Windows CD/DVD (although this works on any platform, the CD/DVD that is created only runs under Windows). 
    464464WriteCDImagePrompt.Progress_Label:Copying Files. This could take some time... 
     465WriteCDImagePrompt.Size_Label:Estimated size:  
    465466WriteCDImagePrompt.Successful_Export:The collections ({0}) have been exported. 
    466467WriteCDImagePrompt.Successful_Title:Export Complete 
  • trunk/gli/src/org/greenstone/gatherer/gui/WriteCDImagePrompt.java

    r10370 r10659  
    4949import org.greenstone.gatherer.LocalGreenstone; 
    5050import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 
     51import org.greenstone.gatherer.collection.CollectionManager; 
    5152import org.greenstone.gatherer.shell.GShell; 
    5253import org.greenstone.gatherer.shell.GShellEvent; 
     
    9091    /** A string array used to pass arguments to the phrase retrieval method. */ 
    9192    private JTextField title_field = null; 
     93    private JTextField estimated_size_field = null; 
    9294    private JLabel title_label = null; 
     95    private JLabel estimated_size_label = null; 
    9396    private String args[] = null; 
    9497    private String cd_title = null; 
     
    99102    /** the error message if any */ 
    100103    private StringBuffer error_message = null; 
     104    /** This is the size of the exported stuff on its own (no collections). */ 
     105    private long total_exported_size = 52000000; 
    101106    /** The size of the export prompt screen. */ 
    102107    public static final Dimension SIZE = new Dimension(500, 500); 
     
    138143    title_label = new JLabel(); 
    139144    Dictionary.setText(title_label, "WriteCDImagePrompt.CD_Name"); 
     145 
     146    estimated_size_field = new JTextField(); 
     147    estimated_size_field.setEditable(false); 
     148    estimated_size_field.setText(Utility.formatFileLength(total_exported_size)); 
     149    estimated_size_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false)); 
     150    estimated_size_label = new JLabel(); 
     151    Dictionary.setText(estimated_size_label, "WriteCDImagePrompt.Size_Label"); 
     152 
    140153    scanForCollections(); 
    141154    list.setListData(all_collections); 
     
    206219 
    207220    // Lower pane 
     221    JPanel estimated_size_pane = new JPanel(new BorderLayout()); 
     222    estimated_size_pane.add(estimated_size_label, BorderLayout.WEST); 
     223    estimated_size_pane.add(estimated_size_field, BorderLayout.CENTER); 
     224    estimated_size_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); 
     225 
    208226    JPanel button_pane = new JPanel(new GridLayout(1, 2)); 
    209227    button_pane.add(ok_button); 
     
    212230 
    213231    JPanel lower_pane = new JPanel(new BorderLayout()); 
     232    lower_pane.add(estimated_size_pane, BorderLayout.NORTH); 
    214233    lower_pane.add(button_pane, BorderLayout.SOUTH); 
    215234    lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); 
     
    424443    public void valueChanged(ListSelectionEvent event) 
    425444    { 
     445        // Wait for things to settle down a bit 
     446        if (event.getValueIsAdjusting()) { 
     447        return; 
     448        } 
     449 
    426450        // Can only export when something is ticked 
    427451        ok_button.setEnabled(!list.isNothingTicked()); 
     
    440464        Dictionary.setText(details_textarea, "DeleteCollectionPrompt.Details", args); 
    441465        details_textarea.setCaretPosition(0); 
     466 
     467        // Find the size of the "etc", "images" and "index" directories of the collection 
     468        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection.getShortName()); 
     469        File etc_directory = new File(collection_directory_path + "etc"); 
     470        File images_directory = new File(collection_directory_path + "images"); 
     471        File index_directory = new File(collection_directory_path + "index"); 
     472        long collection_size_built = getFileSize(etc_directory) + getFileSize(images_directory) + getFileSize(index_directory); 
     473 
     474        // Add/subtract it from the total, depending on whether the collection has just been ticked/unticked 
     475        if (((CheckListEntry) list.getSelectedValue()).isSelected()) { 
     476        total_exported_size += collection_size_built; 
     477        } 
     478        else { 
     479        total_exported_size -= collection_size_built; 
     480        } 
     481 
     482        // Update the size field 
     483        estimated_size_field.setText(Utility.formatFileLength(total_exported_size)); 
     484    } 
     485 
     486 
     487    private long getFileSize(File file) 
     488    { 
     489        long file_size = 0; 
     490 
     491        // Directory case 
     492        if (file.isDirectory()) { 
     493        File files[] = file.listFiles(); 
     494        for (int i = 0; i < files.length; i++) { 
     495            file_size += getFileSize(files[i]); 
     496        } 
     497        } 
     498        // File case 
     499        else { 
     500        file_size = file.length(); 
     501        } 
     502 
     503        return file_size; 
    442504    } 
    443505    }