Changeset 5564 for trunk/gli/src/org/greenstone/gatherer/gui/Filter.java
- Timestamp:
- 2003-10-03T14:07:35+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/Filter.java
r5527 r5564 1 package org.greenstone.gatherer.gui;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.gui; 38 38 39 import java.awt.*; 39 40 import java.awt.event.*; … … 42 43 import javax.swing.*; 43 44 import javax.swing.tree.*; 45 import org.greenstone.gatherer.Dictionary; 44 46 import org.greenstone.gatherer.Gatherer; 45 47 import org.greenstone.gatherer.file.FileSystemModel; 46 48 import org.greenstone.gatherer.gui.tree.DragTree; 49 47 50 /** <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> 49 52 * @author John Thompson, Greenstone Digital Library, University of Waikato 50 53 * @version 2.3 … … 72 75 /** Preprogrammed default filters. */ 73 76 static final private String DEFAULTS[] = {"^.*\\.html?$", "^.*\\.xml$", "^.*\\.txt$", "(^.*\\.jpe?g$)|(^.*\\.png$)|(^.\\.gif$)|(^.\\.bmp$)|(^.\\.tif$)"}; 77 74 78 /** Constructor. 75 79 * @param tree A reference to the <strong>JTree</strong> being affected. … … 78 82 this(tree, null); 79 83 } 84 80 85 /** Constructor. 81 86 * @param tree A reference to the <strong>JTree</strong> being affected. … … 84 89 public Filter(DragTree tree, ArrayList others) { 85 90 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; 92 95 this.others.add(this); 93 96 this.this_filter = this; … … 98 101 for(int i = 0; i < DEFAULTS.length; i++) { 99 102 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])); 101 104 combobox.add(entry); 102 105 } … … 106 109 } 107 110 combobox.setEditable(true); 108 label = new JLabel( get("Filter.Filter_Tree"));111 label = new JLabel(); 109 112 label.setPreferredSize(SIZE); 113 Dictionary.setText(label, "Filter.Filter_Tree"); 110 114 // Add listeners. 111 115 combobox.addActionListener(new ComboBoxListener()); … … 141 145 ignore = false; 142 146 } 147 143 148 /** Set the combobox model for this filter. 144 149 * @param model The new <strong>ComboBoxModel</strong> to use. … … 147 152 combobox.setModel(model); 148 153 } 154 149 155 /** Ensure that a certain entry is selected from the combobox. 150 156 * @param selection The <strong>Entry</strong> that should be selected. … … 155 161 ignore = false; 156 162 } 163 157 164 /** Set to signify that this filter is the first in a new run of filters. 158 165 * @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. … … 161 168 this.first = first; 162 169 } 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. 164 172 * @param tree_spawn The <strong>JTree</strong> this filter will affect. 165 173 * @return A new <strong>Filter</strong> which is in the same run as this filter. … … 172 180 return filter; 173 181 } 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 192 183 /** Encode an expression in pseudo-regular expression into regular expression. 193 184 * @param raw The pseudo-regular expression <strong>String</strong> which includes several characters which differ in meaning from regular expression queries. … … 231 222 Gatherer.g_man.wait(false); 232 223 } 224 233 225 /** 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. */ 234 226 private class ComboBoxListener … … 246 238 ///ystem.err.println("Filter = " + temp_str); 247 239 // 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"))) { 249 241 } 250 242 // HTM & HTML 251 else if(temp_str.equals( get("Filter.0"))) {243 else if(temp_str.equals(Dictionary.newget("Filter.0"))) { 252 244 } 253 245 // XML 254 else if(temp_str.equals( get("Filter.1"))) {246 else if(temp_str.equals(Dictionary.newget("Filter.1"))) { 255 247 } 256 248 // Text files 257 else if(temp_str.equals( get("Filter.2"))) {249 else if(temp_str.equals(Dictionary.newget("Filter.2"))) { 258 250 } 259 251 // Images 260 else if(temp_str.equals( get("Filter.3"))) {252 else if(temp_str.equals(Dictionary.newget("Filter.3"))) { 261 253 } 262 254 else { … … 281 273 catch (PatternSyntaxException error) { 282 274 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); 284 276 } 285 277 } … … 322 314 public String toString() { 323 315 String result = null; 324 if (name != null) {316 if (name != null) { 325 317 result = name; 326 318 } 327 else if (pattern == null) {328 result = get("Filter.All_Files");319 else if (pattern == null) { 320 result = Dictionary.newget("Filter.All_Files"); 329 321 } 330 322 else {
Note:
See TracChangeset
for help on using the changeset viewer.