Changeset 10007


Ignore:
Timestamp:
2005-06-03T14:40:55+12:00 (19 years ago)
Author:
mdewsnip
Message:

Moved Utility.formatPath into FileQueue, as part of tidying up the Utility class.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

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

    r9855 r10007  
    156156    cancel_action = true;
    157157    }
     158
     159
     160    /** Format the given filename path string so that it is no longer than the given width. If it is wider replace starting directories with ...
     161     * @param key The key <strong>String</Strong> used to retrieve a phrase from the dictionary for this item.
     162     * @param raw The raw filename path <strong>String</strong>.
     163     * @param width The maximum width as an <i>int</i>.
     164     * @return A path <strong>String</strong> no longer than width.
     165     */
     166    private String formatPath(String key, String raw, int width)
     167    {
     168    JLabel label = new JLabel(Dictionary.get(key, raw));
     169    int position = -1;
     170    while(label.getPreferredSize().width > width && (position = raw.indexOf(File.separator)) != -1) {
     171        raw = "..." + raw.substring(position + 1);
     172        label.setText(Dictionary.get(key, raw));
     173    }
     174    if(raw.indexOf(File.separator) == -1 && raw.startsWith("...")) {
     175        raw = raw.substring(3);
     176    }
     177    return raw;
     178    }
     179
     180
    158181    /** Access to the file state label. */
    159182    public JLabel getFileStatus() {
     
    285308                args[0] = "" + (queue.size() + 1) + "";
    286309                if(job.type == FileJob.COPY) {
    287                     args[0] = Utility.formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width);
     310                    args[0] = formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width);
    288311                    file_status.setText(Dictionary.get("FileActions.Copying", args));
    289312                }
    290313                else {
    291                     args[0] = Utility.formatPath("FileActions.Moving", source_file.getAbsolutePath(), file_status.getSize().width);
     314                    args[0] = formatPath("FileActions.Moving", source_file.getAbsolutePath(), file_status.getSize().width);
    292315                    file_status.setText(Dictionary.get("FileActions.Moving", args));
    293316                }
     
    443466                // Update status area
    444467                String args[] = new String[1];
    445                 args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width);
     468                args[0] = formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width);
    446469                file_status.setText(Dictionary.get("FileActions.Deleting", args));
    447470
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r10006 r10007  
    333333    return result;
    334334    }
    335     /** Format the given filename path string so that it is no longer than the given width. If it is wider replace starting directories with ...
    336      * @param key The key <strong>String</Strong> used to retrieve a phrase from the dictionary for this item.
    337      * @param raw The raw filename path <strong>String</strong>.
    338      * @param width The maximum width as an <i>int</i>.
    339      * @return A path <strong>String</strong> no longer than width.
    340      */
    341     static public String formatPath(String key, String raw, int width) {
    342     JLabel label = new JLabel(Dictionary.get(key, raw));
    343     int position = -1;
    344     while(label.getPreferredSize().width > width && (position = raw.indexOf(File.separator)) != -1) {
    345         raw = "..." + raw.substring(position + 1);
    346         label.setText(Dictionary.get(key, raw));
    347     }
    348     if(raw.indexOf(File.separator) == -1 && raw.startsWith("...")) {
    349         raw = raw.substring(3);
    350     }
    351     return raw;
    352     }
    353335
    354336
Note: See TracChangeset for help on using the changeset viewer.