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/gui/Filter.java

    r5527 r5564  
    1 package org.greenstone.gatherer.gui;
    21/**
    32 *#########################################################################
     
    3635 *########################################################################
    3736 */
     37package org.greenstone.gatherer.gui;
     38
    3839import java.awt.*;
    3940import java.awt.event.*;
     
    4243import javax.swing.*;
    4344import javax.swing.tree.*;
     45import org.greenstone.gatherer.Dictionary;
    4446import org.greenstone.gatherer.Gatherer;
    4547import org.greenstone.gatherer.file.FileSystemModel;
    4648import org.greenstone.gatherer.gui.tree.DragTree;
     49
    4750/** <p>This object allows the user to set a filter on one of the workspace trees, specifying a preset type, or a regular expression that a files must match to be in the tree. Note that all directories are included. This class includes the controls for editing the filter. The trick is that several instances of the Filter class can share the same internal data (termed a 'run' of filters), so that the filter set on the CollectionPane and the MetaEditPane are virtually the same.</p>
    48  * <p>The regular expression typed can uses '*' as a wildcard character (equivelent to '.*'), and does not use '.' to match any single character (use '?' instead).</p>
     51 * <p>The regular expression typed uses '*' as a wildcard character (equivalent to '.*'), and does not use '.' to match any single character (use '?' instead).</p>
    4952 * @author John Thompson, Greenstone Digital Library, University of Waikato
    5053 * @version 2.3
     
    7275    /** Preprogrammed default filters. */
    7376    static final private String DEFAULTS[] = {"^.*\\.html?$", "^.*\\.xml$", "^.*\\.txt$", "(^.*\\.jpe?g$)|(^.*\\.png$)|(^.\\.gif$)|(^.\\.bmp$)|(^.\\.tif$)"};
     77
    7478    /** Constructor.
    7579     * @param tree A reference to the <strong>JTree</strong> being affected.
     
    7882    this(tree, null);
    7983    }
     84
    8085    /** Constructor.
    8186     * @param tree A reference to the <strong>JTree</strong> being affected.
     
    8489    public Filter(DragTree tree, ArrayList others) {
    8590    super();
    86     if(others == null) {
    87         this.others = new ArrayList();
    88     }
    89     else {
    90         this.others = others;
    91     }
     91    if (others == null) {
     92        others = new ArrayList();
     93    }
     94    this.others = others;
    9295    this.others.add(this);
    9396    this.this_filter = this;
     
    98101    for(int i = 0; i < DEFAULTS.length; i++) {
    99102        try {
    100         Entry entry = new Entry(get((new Integer(i)).toString(), null), Pattern.compile(DEFAULTS[i]));
     103        Entry entry = new Entry(Dictionary.newget("Filter." + i), Pattern.compile(DEFAULTS[i]));
    101104        combobox.add(entry);
    102105        }
     
    106109    }
    107110    combobox.setEditable(true);
    108     label = new JLabel(get("Filter.Filter_Tree"));
     111    label = new JLabel();
    109112    label.setPreferredSize(SIZE);
     113    Dictionary.setText(label, "Filter.Filter_Tree");
    110114    // Add listeners.
    111115    combobox.addActionListener(new ComboBoxListener());
     
    141145    ignore = false;
    142146    }
     147
    143148    /** Set the combobox model for this filter.
    144149     * @param model The new <strong>ComboBoxModel</strong> to use.
     
    147152    combobox.setModel(model);
    148153    }
     154
    149155    /** Ensure that a certain entry is selected from the combobox.
    150156     * @param selection The <strong>Entry</strong> that should be selected.
     
    155161    ignore = false;
    156162    }
     163
    157164    /** Set to signify that this filter is the first in a new run of filters.
    158165     * @param first <i>true</i> if this is the first filter in a run, <i>false</i> if it will just be added to the current run.
     
    161168    this.first = first;
    162169    }
    163     /** Spawn produces a copy of this filter, which has new controls, but shares listeners wih this filter, and vice versa. Thus we can have two synchronized, but differing sets of controls.
     170
     171    /** Spawn produces a copy of this filter, which has new controls, but shares listeners with this filter, and vice versa. Thus we can have two synchronized, but differing sets of controls.
    164172     * @param tree_spawn The <strong>JTree</strong> this filter will affect.
    165173     * @return A new <strong>Filter</strong> which is in the same run as this filter.
     
    172180    return filter;
    173181    }
    174     /** Retrieve a phrase from the dictionary.
    175      * @param key The unique identification <strong>String</strong> of a phrase from the dictionary.
    176      */
    177     private String get(String key) {
    178     return get(key, null);
    179     }
    180     /** Retrieve a phrase from the dictionary, augmenting with the given text fragments
    181      * @param key The unique identification <strong>String</strong> of a phrase from the dictionary.
    182      * @param args A <strong>String[]</strong> of arguments to be used to fill out parameter fields in the phrase returned.
    183      * @see org.greenstone.gatherer.Dictionary
    184      * @see org.greenstone.gatherer.Gatherer
    185      */
    186     private String get(String key, String args[]) {
    187     if(key.indexOf(".") == -1) {
    188         key = "Filter." + key;
    189     }
    190     return Gatherer.dictionary.get(key, args);
    191     }
     182
    192183    /** Encode an expression in pseudo-regular expression into regular expression.
    193184     * @param raw The pseudo-regular expression <strong>String</strong> which includes several characters which differ in meaning from regular expression queries.
     
    231222    Gatherer.g_man.wait(false);
    232223    }
     224
    233225    /** Listens for changes in the combobox as when one is detected attempts to compile a regular expression from whatever text was entered. If successful, or if the item chosen was a predefined filter, it then applies the filter to the target tree. */
    234226    private class ComboBoxListener
     
    246238            ///ystem.err.println("Filter = " + temp_str);
    247239            // Ignore any string which matches a predefined filter, starting with All Files.
    248             if(temp_str.equals(get("Filter.All_Files"))) {
     240            if(temp_str.equals(Dictionary.newget("Filter.All_Files"))) {
    249241            }
    250242            // HTM & HTML
    251             else if(temp_str.equals(get("Filter.0"))) {
     243            else if(temp_str.equals(Dictionary.newget("Filter.0"))) {
    252244            }
    253245            // XML
    254             else if(temp_str.equals(get("Filter.1"))) {
     246            else if(temp_str.equals(Dictionary.newget("Filter.1"))) {
    255247            }
    256248            // Text files
    257             else if(temp_str.equals(get("Filter.2"))) {
     249            else if(temp_str.equals(Dictionary.newget("Filter.2"))) {
    258250            }
    259251            // Images
    260             else if(temp_str.equals(get("Filter.3"))) {
     252            else if(temp_str.equals(Dictionary.newget("Filter.3"))) {
    261253            }
    262254            else {
     
    281273        catch (PatternSyntaxException error) {
    282274        if(first) {
    283             JOptionPane.showMessageDialog(Gatherer.g_man, get("Filter.Invalid_Pattern"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     275            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("Filter.Invalid_Pattern"), Dictionary.newget("General.Error"), JOptionPane.ERROR_MESSAGE);
    284276        }
    285277        }
     
    322314    public String toString() {
    323315        String result = null;
    324         if(name != null) {
     316        if (name != null) {
    325317        result = name;
    326318        }
    327         else if(pattern == null) {
    328         result = get("Filter.All_Files");
     319        else if (pattern == null) {
     320        result = Dictionary.newget("Filter.All_Files");
    329321        }
    330322        else {
Note: See TracChangeset for help on using the changeset viewer.