- Timestamp:
- 2004-01-09T15:00:44+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r6325 r6388 38 38 39 39 import java.awt.Component; 40 import java.util.ArrayList; 40 41 import java.util.StringTokenizer; 41 42 import javax.swing.JProgressBar; 43 import org.greenstone.gatherer.Configuration; 42 44 import org.greenstone.gatherer.Dictionary; 43 45 import org.greenstone.gatherer.Gatherer; 46 import org.greenstone.gatherer.shell.GShellElement; 44 47 import org.greenstone.gatherer.shell.GShellProgressMonitor; 45 48 import org.greenstone.gatherer.util.StaticStrings; … … 65 68 /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */ 66 69 private int num_docs; 70 71 private int threshold = Configuration.SYSTEMS_MODE; 67 72 /** The progress bar this monitor updates. */ 68 73 private JProgressBar progress_bar; 69 74 /** */ 70 static final private String C = "c"; 75 static final private String BLOCKED_ATTRIBUTE = "blocked"; 76 static final private String CONSIDERED_ATTRIBUTE = "considered"; 77 static final private String IGNORED_ATTRIBUTE = "ignored"; 78 static final private String IMPORT_ELEMENT = "Import"; 79 static final private String PROCESSED_ATTRIBUTE = "processed"; 71 80 /** */ 72 static final private String N = "n";81 static final private String NAME_ATTRIBUTE = "n"; 73 82 /** */ 74 static final private String P = "p";83 static final private String PLUGIN_ATTRIBUTE = "p"; 75 84 /** The fixed portion of the progress bar used for the calculating of file size and other pre-import functions. */ 76 85 static final private int CALCULATION = 50000; … … 82 91 static final private int PROCESSED = 750000; 83 92 /** The element name of a file detected message. */ 84 static final private String FILE = "File";93 static final private String FILE_ELEMENT = "File"; 85 94 /** The element name of a file processing message. */ 86 static final private String FILE _PROCESSING= "Processing";95 static final private String FILEPROCESSING_ELEMENT = "Processing"; 87 96 /** The element name of an import complete message. */ 88 static final private String IMPORT _COMPLETE= "ImportComplete";97 static final private String IMPORTCOMPLETE_ELEMENT = "ImportComplete"; 89 98 90 99 public GImportProgressMonitor() { … … 93 102 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 94 103 progress_bar.setMinimum(MIN); 104 progress_bar.setString(StaticStrings.SPACE_CHARACTER); 95 105 progress_bar.setStringPainted(true); 96 progress_bar.setValue(MIN);106 setValue(MIN); 97 107 next_progress_value = CALCULATION; 98 108 } … … 105 115 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 106 116 progress_bar.setMinimum(MIN); 107 progress_bar.setValue(MIN);117 setValue(MIN); 108 118 next_progress_value = CALCULATION; 109 119 } … … 145 155 // The current progress is calculated to be: 146 156 // The fixed calculation value plus the fixed processed value plus some portion of the fixed extracted value. This portion is the extracted_file_count over the total number of documents available. Note that this breaks badly for bibliographical files (for now). 147 progress_bar.setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs));157 setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs)); 148 158 } 149 159 150 160 /** This method is used to 'feed in' a line of text captured from the process. 151 * @param event the GShellEvent containing a message or other important shell information 152 */ 153 public void process(GShellEvent event) { 154 // We're into parsing output, so we don't need the 'calculating file size' etc string. 155 if(showing_string) { 156 progress_bar.setString(""); 157 showing_string = false; 158 } 161 * @param queue a queue which at the moment should contain a single GShellEvent 162 */ 163 public void process(ArrayList queue) { 164 // Retrieve the first event. 165 GShellEvent event = (GShellEvent) queue.get(0); 159 166 // Remove 'import.pl> ' bit 160 167 String line = event.getMessage(); 161 168 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1); 162 169 line = line.trim(); 163 ///ystem.err.println("message = " + line);164 170 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) { 165 line = line.substring(1, line.length() - 1); 171 // No original event is passed on, even in the lower modes 172 event.veto(); 173 // Create a new element from it 174 GShellElement element = new GShellElement(line); 175 String name = element.getElementName(); 166 176 // We may be reading a file. Remember we have to offset process as we recieve this message 'before' a document is processed. Hence the use of 'next_progress_value' 167 if(line.startsWith(FILE)) { 177 if(name.equals(IMPORT_ELEMENT)) { 178 // We're into parsing output, so we don't need the 'calculating file size' etc string. 179 if(showing_string) { 180 progress_bar.setString(""); 181 showing_string = false; 182 } 183 if(Gatherer.config.getMode() <= threshold) { 184 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportBegun1"), event.getStatus())); 185 } 186 } 187 else if(name.equals(FILE_ELEMENT)) { 168 188 file_count++; 169 ///ystem.err.println("File #" + file_count);170 189 // Set the next progress 171 progress_bar.setValue(next_progress_value); 190 if(next_progress_value > 0) { 191 setValue(next_progress_value); 192 } 172 193 // Now we calculate the next progress value 173 194 next_progress_value = CALCULATION + ((PROCESSED * file_count) / num_expected_docs); 195 event.veto(); // Unconditional veto 174 196 } 175 197 // Or we're being told what plugin is actually processing the file 176 else if( line.startsWith(FILE_PROCESSING)) {198 else if(name.equals(FILEPROCESSING_ELEMENT)) { 177 199 // If we are at lower mode settings fire a new 'dumbed down' event 178 /** @todo */ 200 if(Gatherer.config.getMode() <= threshold) { 201 String args[] = new String[2]; 202 args[0] = element.getAttribute(NAME_ATTRIBUTE); 203 args[1] = element.getAttribute(PLUGIN_ATTRIBUTE); 204 if(!args[1].equals("")) { 205 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.FileProcessing", args), event.getStatus())); 206 } 207 else { 208 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.FileNotProcessed", args), event.getStatus())); 209 } 210 args = null; 211 } 179 212 } 180 213 // Or the import complete element 181 else if( line.startsWith(IMPORT_COMPLETE)) {214 else if(name.equals(IMPORTCOMPLETE_ELEMENT)) { 182 215 // Set the next progress 183 progress_bar.setValue(next_progress_value); 184 // Determine the number of documents processed by using the 'p' attribute 185 StringTokenizer tokenizer = new StringTokenizer(line); 186 boolean found = false; 187 String token = tokenizer.nextToken(); // Drop the element name 188 while(tokenizer.hasMoreTokens() && !found) { 189 token = tokenizer.nextToken(); 190 if(token.startsWith(P)) { 191 found = true; 192 try { 193 String num_docs_string = token.substring(3, token.length() - 1); 194 num_docs = Integer.parseInt(num_docs_string); 195 } 196 catch(Exception exception) { 197 Gatherer.println("Exception in GImportProgressMonitor.process() - Expected"); 198 Gatherer.printStackTrace(exception); 199 } 200 } 201 } 202 tokenizer = null; 216 setValue(next_progress_value); 203 217 // If we are at lower mode settings fire a new 'dumbed down' event 204 /** @todo */ 205 } 206 207 208 // We also veto this event to prevent other classes handling it (we ensure progress monitors are called first). 218 if(Gatherer.config.getMode() <= threshold) { 219 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete1"), event.getStatus())); 220 String args[] = new String[1]; 221 args[0] = element.getAttribute(CONSIDERED_ATTRIBUTE); 222 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete2", args), event.getStatus())); 223 // The number of documents processed 224 String processed_str = element.getAttribute(PROCESSED_ATTRIBUTE); 225 if(!processed_str.equals(StaticStrings.ZERO_CHARACTER)) { 226 args = new String[3]; 227 args[0] = element.getAttribute(PROCESSED_ATTRIBUTE); 228 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 229 args[1] = Dictionary.get("GShell.Import.Was"); 230 args[2] = Dictionary.get("GShell.Import.Is"); 231 } 232 else { 233 args[1] = Dictionary.get("GShell.Import.Were"); 234 args[2] = Dictionary.get("GShell.Import.Are"); 235 } 236 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Processed", args), event.getStatus())); 237 } 238 // Try to set num docs 239 try { 240 num_docs = Integer.parseInt(processed_str); 241 } 242 catch(Exception exception) { 243 num_docs = 0; 244 } 245 processed_str = null; 246 // The number of documents blocked 247 String blocked_str = element.getAttribute(BLOCKED_ATTRIBUTE); 248 if(!blocked_str.equals(StaticStrings.ZERO_CHARACTER)) { 249 args = new String[2]; 250 args[0] = element.getAttribute(BLOCKED_ATTRIBUTE); 251 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 252 args[1] = Dictionary.get("GShell.Import.Was"); 253 } 254 else { 255 args[1] = Dictionary.get("GShell.Import.Were"); 256 } 257 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Blocked", args), event.getStatus())); 258 } 259 blocked_str = null; 260 // The number of documents ignored 261 String ignored_str = element.getAttribute(IGNORED_ATTRIBUTE); 262 if(!ignored_str.equals(StaticStrings.ZERO_CHARACTER)) { 263 args = new String[3]; 264 args[0] = element.getAttribute(IGNORED_ATTRIBUTE); 265 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 266 args[1] = Dictionary.get("GShell.Import.Was"); 267 args[2] = Dictionary.get("GShell.Import.Is"); 268 } 269 else { 270 args[1] = Dictionary.get("GShell.Import.Were"); 271 args[2] = Dictionary.get("GShell.Import.Are"); 272 } 273 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Ignored", args), event.getStatus())); 274 } 275 ignored_str = null; 276 args = null; 277 // Message is finally ready 278 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete3"), event.getStatus())); 279 } 280 } 281 else { 282 // Veto it 283 event.veto(); 284 } 285 } 286 else if(Gatherer.config.getMode() <= threshold) { 209 287 event.veto(); 210 288 } 289 } 290 291 public void reset() { 292 setValue(MIN); 293 progress_bar.setString(StaticStrings.SPACE_CHARACTER); 294 progress_bar.updateUI(); 211 295 } 212 296 … … 226 310 */ 227 311 public void start() { 312 setValue(MIN); 228 313 progress_bar.setString(Dictionary.get("FileActions.Calculating_Size")); 229 314 showing_string = true; … … 238 323 */ 239 324 public void stop() { 240 progress_bar.setValue(CALCULATION + PROCESSED + EXTRACTED); 325 setValue(CALCULATION + PROCESSED + EXTRACTED); 326 } 327 328 int previous_value = -1; 329 private void setValue(int value) { 330 progress_bar.setValue(value); 331 if(value != 0 && value < previous_value) { 332 Gatherer.println("Progress is decreasing! " + previous_value + " -> " + value); 333 } 334 previous_value = value; 241 335 } 242 336 } 337
Note:
See TracChangeset
for help on using the changeset viewer.