Ignore:
Timestamp:
2003-10-03T14:07:35+12:00 (21 years ago)
Author:
mdewsnip
Message:

Many more small improvements and tooltips added. Still more to come!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r5536 r5564  
    3232import javax.swing.event.*;
    3333import javax.swing.tree.*;
     34import org.greenstone.gatherer.Dictionary;
    3435import org.greenstone.gatherer.Gatherer;
    3536import org.greenstone.gatherer.file.FileJob;
    3637import org.greenstone.gatherer.file.FileNode;
    3738import org.greenstone.gatherer.gui.LongProgressBar;
    38 import org.greenstone.gatherer.gui.SmudgyLabel;
    3939import org.greenstone.gatherer.gui.tree.DragTree;
    4040import org.greenstone.gatherer.msm.GDMManager;
     
    4444import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
    4545import org.greenstone.gatherer.util.Utility;
     46
    4647/** A threaded object which processes a queue of file actions such as copying and movement. It also handles updating the various trees involved so they are an accurate representation of the file system they are meant to match.
    4748 * @author John Thompson, Greenstone Digital Library, University of Waikato
     
    6465    private HashMap recycle_folder_mappings = new HashMap();
    6566    /** A label explaining the current moving files status. */
    66     private JLabel file_status = null; // was a SmudgyLabel
    67     /** A label explaining the status of this job. */
    68     //private JLabel job_status = null; // no longer used
     67    private JLabel file_status = null;
    6968    /** A list containing a queue of waiting movement jobs. */
    7069    //private LinkedList queue;
     
    7574    private String previous = null;
    7675    /** Constructor.
    77       * @param return_immediately true to cause this file queue to return from run() as soon as there are no jobs left on the queue.
    78       * @see org.greenstone.gatherer.Configuration
    79       * @see org.greenstone.gatherer.gui.Coloring
    80       * @see org.greenstone.gatherer.gui.LongProgressBar
    81       */
     76     * @param return_immediately true to cause this file queue to return from run() as soon as there are no jobs left on the queue.
     77     * @see org.greenstone.gatherer.Configuration
     78     * @see org.greenstone.gatherer.gui.Coloring
     79     * @see org.greenstone.gatherer.gui.LongProgressBar
     80     */
    8281    public FileQueue(boolean return_immediately) {
    8382    this.return_immediately = return_immediately;
     
    8685    args[0] = "0";
    8786    args[1] = "0";
    88     file_status = new JLabel(get("FileActions.Selected", args)); //new SmudgyLabel(get("Selected", args));
    89     //job_status = new JLabel(get("No_Activity"));
     87    file_status = new JLabel();
     88    Dictionary.setText(file_status, "FileActions.Selected", args);
    9089    progress = new LongProgressBar();
    9190    progress.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
    9291    progress.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
    93     progress.setString(get("FileActions.No_Activity"));
     92    progress.setString(Dictionary.newget("FileActions.No_Activity"));
    9493    progress.setStringPainted(true);
    9594    args = null;
     
    106105
    107106    /** Add a new job to the queue, specifiying as many arguments as is necessary to complete this type of job (ie delete needs no target information).
    108       * @param id A long id unique to all jobs created by a single action.
    109       * @param source The DragComponent source of this file, most likely a DragTree.
    110       * @param child The FileNode you wish to mode.
    111       * @param target The DragComponent to move the file to, again most likely a DragTree.
    112       * @param parent The files new FileNode parent within the target.
    113       * @param type The type of this movement as an int, either COPY or DELETE.
    114       * @param undo true if this job should generate undo jobs, false for redo ones.
    115       * @param undoable true if this job can generate undo or redo jobs at all, false otherwise.
    116       */
     107     * @param id A long id unique to all jobs created by a single action.
     108     * @param source The DragComponent source of this file, most likely a DragTree.
     109     * @param child The FileNode you wish to mode.
     110     * @param target The DragComponent to move the file to, again most likely a DragTree.
     111     * @param parent The files new FileNode parent within the target.
     112     * @param type The type of this movement as an int, either COPY or DELETE.
     113     * @param undo true if this job should generate undo jobs, false for redo ones.
     114     * @param undoable true if this job can generate undo or redo jobs at all, false otherwise.
     115     */
    117116    public void addJob(long id, DragComponent source, FileNode child, DragComponent target, FileNode parent, byte type, boolean undo, boolean undoable, boolean folder_level) {
    118117    addJob(id, source, child, target, parent, type, undo, undoable, folder_level, -1);
    119118    }
     119
    120120    synchronized public void addJob(long id, DragComponent source, FileNode child, DragComponent target, FileNode parent, byte type, boolean undo, boolean undoable, boolean folder_level, int position) {
    121121    FileJob job = new FileJob(id, source, child, target, parent, type, undo, undoable);
     
    131131    }
    132132
    133     /** Calculates the total deep file size of the selected file nodes.
    134     * @param files a FileNode[] of selected files
    135     * @return true if a cancel was signalled, false otherwise
    136     * @see org.greenstone.gatherer.file.FileManager.Task#run()
    137     */
     133    /** Calculates the total deep file size of the selected file nodes.
     134     * @param files a FileNode[] of selected files
     135     * @return true if a cancel was signalled, false otherwise
     136     * @see org.greenstone.gatherer.file.FileManager.Task#run()
     137     */
    138138    public boolean calculateSize(FileNode[] files) {
    139139    progress.reset();
    140     progress.setString(get("FileActions.Calculating_Size"));
     140    progress.setString(Dictionary.newget("FileActions.Calculating_Size"));
    141141    progress.setIndeterminate(true);
    142142    Vector remaining = new Vector();
     
    155155        }
    156156    }
    157     progress.setString(get("FileActions.No_Activity"));
     157    progress.setString(Dictionary.newget("FileActions.No_Activity"));
    158158    progress.setIndeterminate(false);
    159159    // Now we return if calculation was cancelled so that the FileManagers Task can skip the addJob phase correctly.
    160160    if(cancel_action) {
    161         cancel_action = false; // reset
    162         return true;
     161        cancel_action = false; // reset
     162        return true;
    163163    }
    164164    else {
    165         return false;
     165        return false;
    166166    }
    167167    }
     
    188188    }
    189189    /** The run method exists in every thread, and here it is used to work its way through the queue of Jobs. If no jobs are waiting and it cans, it waits until a job arrives. If a job is present then it is either COPIED or DELETED, with the records being copied or removed as necessary, and directories being recursed through. Finally the user can press cancel to cause the loop to prematurely dump the job queue then wait.
    190       * @see org.greenstone.gatherer.Gatherer
    191       * @see org.greenstone.gatherer.collection.CollectionManager
    192       * @see org.greenstone.gatherer.file.FileJob
    193       * @see org.greenstone.gatherer.file.FileNode
    194       * @see org.greenstone.gatherer.gui.LongProgressBar
    195       * @see org.greenstone.gatherer.msm.MetadataSetManager
    196       * @see org.greenstone.gatherer.undo.UndoManager
    197       * @see org.greenstone.gatherer.util.Utility
    198       */
     190     * @see org.greenstone.gatherer.Gatherer
     191     * @see org.greenstone.gatherer.collection.CollectionManager
     192     * @see org.greenstone.gatherer.file.FileJob
     193     * @see org.greenstone.gatherer.file.FileNode
     194     * @see org.greenstone.gatherer.gui.LongProgressBar
     195     * @see org.greenstone.gatherer.msm.MetadataSetManager
     196     * @see org.greenstone.gatherer.undo.UndoManager
     197     * @see org.greenstone.gatherer.util.Utility
     198     */
    199199    public void run() {
    200200    super.setName("FileQueue");
     
    239239                else {
    240240                ///atherer.println("Opps! This filename already exists. Give the user some options.");
    241                 Object[] options = { get("General.Yes"), get("FileActions.Yes_To_All"), get("General.No"), get("General.Cancel") };
    242                 int result = JOptionPane.showOptionDialog(Gatherer.g_man, get("FileActions.File_Exists", target_file.getName()), get("General.Warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
     241                Object[] options = { Dictionary.newget("General.Yes"), Dictionary.newget("FileActions.Yes_To_All"), Dictionary.newget("General.No"), Dictionary.newget("General.Cancel") };
     242                int result = JOptionPane.showOptionDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Exists", target_file.getName()), Dictionary.newget("General.Warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
    243243                switch(result) {
    244244                case 1: // Yes To All
     
    271271                String args[] = new String[1];
    272272                args[0] = "" + (queue.size() + 1) + "";
    273                 //job_status.setText(get("Jobs", args));
    274273                if(job.type == FileJob.COPY) {
    275274                args[0] = Utility.formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width);
    276                 file_status.setText(get("FileActions.Copying", args));
     275                file_status.setText(Dictionary.newget("FileActions.Copying", args));
    277276                }
    278277                else {
    279278                args[0] = Utility.formatPath("FileActions.Moving", source_file.getAbsolutePath(), file_status.getSize().width);
    280                 file_status.setText(get("FileActions.Moving", args));
     279                file_status.setText(Dictionary.newget("FileActions.Moving", args));
    281280                }
    282281                args = null;
     
    293292                    cancel_action = true;
    294293                    // Show warning.
    295                     JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Not_Found_Message", source_file.getName()), get("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);
     294                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Not_Found_Message", source_file.getName()), Dictionary.newget("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);
    296295                    // Force refresh of source folder.
    297296                    source_model.refresh(new TreePath(((FileNode)origin_node.getParent()).getPath()));
     
    301300                    cancel_action = true;
    302301                    // Show warning.
    303                     JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Already_Exists_Message", target_file.getName()), get("FileActions.File_Already_Exists_Title"), JOptionPane.ERROR_MESSAGE);
     302                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Already_Exists_Message", target_file.getName()), Dictionary.newget("FileActions.File_Already_Exists_Title"), JOptionPane.ERROR_MESSAGE);
    304303                    // Nothing else can be done by the Gatherer.
    305304                }
     
    308307                    cancel_action = true;
    309308                    // Show warning. The message body of the expection explains how much more space is required for this file copy.
    310                     JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Insufficient_Space_Message", is_exception.getMessage()), get("FileActions.Insufficient_Space_Title"), JOptionPane.ERROR_MESSAGE);
     309                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Insufficient_Space_Message", is_exception.getMessage()), Dictionary.newget("FileActions.Insufficient_Space_Title"), JOptionPane.ERROR_MESSAGE);
    311310                    // Nothing else can be done by the Gatherer. In fact if we are really out of space I'm not even sure we can quit safely.
    312311                }
     
    315314                    cancel_action = true;
    316315                    // Show warning
    317                     JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Unknown_File_Error_Message"), get("FileActions.Unknown_File_Error_Title"), JOptionPane.ERROR_MESSAGE);
     316                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Unknown_File_Error_Message"), Dictionary.newget("FileActions.Unknown_File_Error_Title"), JOptionPane.ERROR_MESSAGE);
    318317                    // Nothing else we can do.
    319318                }
     
    322321                    cancel_action = true;
    323322                    // Show warning
    324                     JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Write_Not_Permitted_Message", target_file.getAbsolutePath()), get("FileActions.Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE);
     323                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Write_Not_Permitted_Message", target_file.getAbsolutePath()), Dictionary.newget("FileActions.Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE);
    325324                    // Nothing else we can do.
    326325                }
     
    378377                // Else inform the users that a directory already exists and files will be copied into it
    379378                //else {
    380                 //    JOptionPane.showMessageDialog(null, get("Directory_Exists", target_file.toString()), get("General.Warning"), JOptionPane.WARNING_MESSAGE);
     379                //    JOptionPane.showMessageDialog(null, Dictionary.newget("Directory_Exists", target_file.toString()), Dictionary.newget("General.Warning"), JOptionPane.WARNING_MESSAGE);
    381380                //}
    382381                // Queue non-filtered child files for copying. If this directory already existed, the child records will have to generate the undo jobs, as we don't want to entirely delete this directory if it already existed.
     
    401400                cancel_action = true;
    402401                // Show warning.
    403                 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Not_Found_Message", source_file.getName()), get("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);
     402                JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Not_Found_Message", source_file.getName()), Dictionary.newget("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);
    404403                // Force refresh of source folder.
    405404                source_model.refresh(new TreePath(((FileNode)origin_node.getParent()).getPath()));
     
    457456                String args[] = new String[1];
    458457                args[0] = "" + (queue.size() + 1) + "";
    459                 //job_status.setText(get("Jobs", args));
     458                //job_status.setText(Dictionary.newget("Jobs", args));
    460459                args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width);
    461                 file_status.setText(get("FileActions.Deleting", args));
     460                file_status.setText(Dictionary.newget("FileActions.Deleting", args));
    462461                args = null;
    463462
     
    593592            }
    594593            // Reset status area
    595             //job_status.setText(get("No_Selection"));
    596             file_status.setText(get("FileActions.No_Activity"));
     594            //job_status.setText(Dictionary.newget("No_Selection"));
     595            file_status.setText(Dictionary.newget("FileActions.No_Activity"));
    597596            progress.reset();
    598             progress.setString(get("FileActions.No_Activity"));
     597            progress.setString(Dictionary.newget("FileActions.No_Activity"));
    599598            yes_to_all = false;
    600599            completed_folder_mappings.clear();
     
    615614    }
    616615    /** A second lock is necessary to prevent the thread waiting, because its notify occured momentarily before it waited. If the flag is set then the thread can't wait, but loops around. This may chew processor time so should only be used if you are certain files are about to be placed on the queue.
    617       * @param wait_allowed The new state of the wait_allowed flag, as a boolean.
    618       */
     616     * @param wait_allowed The new state of the wait_allowed flag, as a boolean.
     617     */
    619618    public void setWaitAllowed(boolean wait_allowed) {
    620619    this.wait_allowed = wait_allowed;
    621620    }
    622621    /** Restore the progress bar so that it updates normally.
    623       * @see org.greenstone.gatherer.gui.LongProgressBar
    624       */
     622     * @see org.greenstone.gatherer.gui.LongProgressBar
     623     */
    625624    synchronized public void unpause() {
    626625    progress.setIndeterminate(false);
     
    730729    }
    731730    }
    732     /** Retrieve a phrase from the dictionary based on the key.
    733       * @param key The key index as a String.
    734       * @return The desired phrase also as a String.
    735       */
    736     private String get(String key) {
    737     return get(key, (String[])null);
    738     }
    739     /** Retrieve a phrase from the dictionary based on the key, and taking into account the given argument.
    740       * @param key The key index as a String.
    741       * @param args A String which is the argument to be added to the phrase.
    742       * @return The desired phrase also as a String.
    743       */
    744     private String get(String key, String arg) {
    745     String args[] = new String[1];
    746     args[0] = arg;
    747     return get(key, args);
    748     }
    749     /** Retrieve a phrase from the dictionary based on the key, and taking into account the given arguments.
    750       * @param key The key index as a String.
    751       * @param args A String[] of arguments to be added to the phrase.
    752       * @return The desired phrase also as a String.
    753       * @see org.greenstone.gatherer.Dictionary
    754       * @see org.greenstone.gatherer.Gatherer
    755       */
    756     private String get(String key, String args[]) {
    757     if(key.indexOf('.') == -1) {
    758         key = "FileActions." + key;
    759     }
    760     return Gatherer.dictionary.get(key, args);
    761     }
     731
    762732
    763733    private FileJob removeJob(int position) {
Note: See TracChangeset for help on using the changeset viewer.