Changeset 6533 for trunk/gli/src/org/greenstone/gatherer/shell
- Timestamp:
- 2004-01-16T15:52:11+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/shell
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/shell/GBasicProgressMonitor.java
r6388 r6533 82 82 return this; 83 83 } 84 85 public JProgressBar getSharedProgress() { 86 return null; 87 } 88 84 89 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 85 90 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. -
trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java
r6388 r6533 121 121 /** The progress bar this monitor updates. */ 122 122 private JProgressBar progress_bar; 123 /** A progress bar that is shared between this this listener and the Import monitor. */ 124 private JProgressBar shared_progress_bar; 123 125 124 126 /** Construct a new GBuildProgressMonitor. */ 125 public GBuildProgressMonitor() { 127 public GBuildProgressMonitor(JProgressBar shared_progress_bar) { 128 this.shared_progress_bar = shared_progress_bar; 126 129 progress_bar = new JProgressBar(); 127 130 progress_bar.setMaximum(MAX); 128 131 progress_bar.setMinimum(MIN); 129 progress_bar.setValue(MIN); 132 progress_bar.setString(null); 133 progress_bar.setStringPainted(true); 134 setValue(MIN); 130 135 } 131 136 … … 137 142 progress_bar.setMaximum(MAX); 138 143 progress_bar.setMinimum(MIN); 139 progress_bar.setValue(MIN); 144 progress_bar.setStringPainted(false); 145 progress_bar.setString(null); 146 setValue(MIN); 140 147 } 141 148 … … 155 162 return progress_bar; 156 163 } 164 165 public JProgressBar getSharedProgress() { 166 return shared_progress_bar; 167 } 168 157 169 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 158 170 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 159 171 */ 160 public boolean hasSignalledStop() {172 public synchronized boolean hasSignalledStop() { 161 173 return stop; 162 174 } … … 193 205 state = BUILD; 194 206 // Produce a lower detail message if required 195 if(Gatherer.config.getMode() <= threshold ) {207 if(Gatherer.config.getMode() <= threshold && !stop) { 196 208 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildBegun1"), event.getStatus())); 197 209 } … … 254 266 else if(name.equals(BUILD_ELEMENT) && element.isClosed()) { 255 267 progress_bar.setIndeterminate(false); 256 progress_bar.setValue(MAX);268 setValue(MAX); 257 269 state = BASE; 258 270 if(Gatherer.config.getMode() <= threshold) { … … 279 291 // One third complete 280 292 progress_bar.setIndeterminate(false); 281 progress_bar.setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages);293 setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages); 282 294 } 283 295 else if(value.equals(COMPRESSINGTEXT_VALUE)) { 284 296 // Two thirds complete 285 297 progress_bar.setIndeterminate(false); 286 progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);298 setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages); 287 299 } 288 300 else { … … 302 314 current_stages++; 303 315 progress_bar.setIndeterminate(false); 304 progress_bar.setValue((current_stages * MAX) / expected_stages);316 setValue((current_stages * MAX) / expected_stages); 305 317 state = BUILD; 306 318 } … … 323 335 // One fifth complete 324 336 progress_bar.setIndeterminate(false); 325 progress_bar.setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages);337 setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages); 326 338 } 327 339 else if(value.equals(CREATETHEWEIGHTS_VALUE)) { 328 340 // Two fifths complete 329 341 progress_bar.setIndeterminate(false); 330 progress_bar.setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages);342 setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages); 331 343 } 332 344 else if(value.equals(CREATESTEMMEDDIC_VALUE)) { 333 345 // Three fifths complete 334 346 progress_bar.setIndeterminate(false); 335 progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);347 setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages); 336 348 } 337 349 else if(value.equals(CREATINGSTEMINDX_VALUE)) { 338 350 // Four fifths complete 339 351 progress_bar.setIndeterminate(false); 340 progress_bar.setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages);352 setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages); 341 353 } 342 354 else { … … 359 371 current_stages++; 360 372 progress_bar.setIndeterminate(false); 361 progress_bar.setValue((current_stages * MAX) / expected_stages);373 setValue((current_stages * MAX) / expected_stages); 362 374 state = BUILD; 363 375 } … … 379 391 // One sixth complete 380 392 progress_bar.setIndeterminate(false); 381 progress_bar.setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages);393 setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages); 382 394 } 383 395 else if(value.equals(SORTANDRENUMBER_VALUE)) { 384 396 // Two sixths complete 385 397 progress_bar.setIndeterminate(false); 386 progress_bar.setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages);398 setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages); 387 399 } 388 400 else if(value.equals(PHRASEDATABASES_VALUE)) { 389 401 // Three sixths complete 390 402 progress_bar.setIndeterminate(false); 391 progress_bar.setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages);403 setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages); 392 404 } 393 405 else if(value.equals(WORDLEVELINDEXES_VALUE)) { 394 406 // Four sixths complete 395 407 progress_bar.setIndeterminate(false); 396 progress_bar.setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages);408 setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages); 397 409 } 398 410 else if(value.equals(DOCINFODATABASES_VALUE)) { 399 411 // Five sixths complete 400 412 progress_bar.setIndeterminate(false); 401 progress_bar.setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages);413 setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages); 402 414 } 403 415 else { … … 412 424 current_stages++; 413 425 progress_bar.setIndeterminate(false); 414 progress_bar.setValue((current_stages * MAX) / expected_stages);426 setValue((current_stages * MAX) / expected_stages); 415 427 state = BUILD; 416 428 } … … 429 441 current_stages++; 430 442 progress_bar.setIndeterminate(false); 431 progress_bar.setValue((current_stages * MAX) / expected_stages);443 setValue((current_stages * MAX) / expected_stages); 432 444 state = BUILD; 433 445 } … … 455 467 expected_stages = 0; 456 468 progress_bar.setIndeterminate(false); 457 progress_bar.setString( StaticStrings.SPACE_CHARACTER);458 progress_bar.setValue(MIN);469 progress_bar.setString(null); 470 setValue(MIN); 459 471 state = BASE; 460 stop = false;461 472 progress_bar.updateUI(); 462 473 } 463 474 464 475 public void saving() { 476 } 477 478 public void setSharedProgressBar(JProgressBar shared_progress_bar) { 479 this.shared_progress_bar = shared_progress_bar; 465 480 } 466 481 … … 468 483 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 469 484 */ 470 public void setStop(boolean state) {471 stop = state;485 public synchronized void setStop(boolean state) { 486 this.stop = state; 472 487 progress_bar.setIndeterminate(false); 473 488 } … … 476 491 */ 477 492 public void start() { 478 progress_bar.setValue(MIN); 493 stop = false; 494 setValue(MIN); 479 495 expected_stages = 3; // Always compress text, create info database and auxiliary creation 480 496 // Retrieve cdm. … … 507 523 public void stop() { 508 524 progress_bar.setIndeterminate(false); 509 progress_bar.setValue(MAX); 525 setValue(MAX); 526 } 527 528 private void setValue(int value) { 529 progress_bar.setValue(value); 530 // Incrementing the shared progress bar is a little more problematic as we may very well be trying to set it to MIN but instead set it to halfway if we're not careful. 531 if(value > MIN) { 532 shared_progress_bar.setValue(MAX + value); 533 } 510 534 } 511 535 } -
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r6388 r6533 72 72 /** The progress bar this monitor updates. */ 73 73 private JProgressBar progress_bar; 74 75 /** The progress bar that is shared with build monitor. */ 76 private JProgressBar shared_progress_bar; 77 74 78 /** */ 75 79 static final private String BLOCKED_ATTRIBUTE = "blocked"; … … 102 106 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 103 107 progress_bar.setMinimum(MIN); 104 progress_bar.setString( StaticStrings.SPACE_CHARACTER);108 progress_bar.setString(null); 105 109 progress_bar.setStringPainted(true); 110 next_progress_value = CALCULATION; 111 shared_progress_bar = new JProgressBar(); 112 shared_progress_bar.setIndeterminate(false); 113 shared_progress_bar.setMaximum((CALCULATION + PROCESSED + EXTRACTED) * 2); 114 shared_progress_bar.setMinimum(MIN); 115 shared_progress_bar.setString(null); // Default string 116 shared_progress_bar.setStringPainted(true); 106 117 setValue(MIN); 107 next_progress_value = CALCULATION;108 118 } 109 119 … … 143 153 } 144 154 155 public JProgressBar getSharedProgress() { 156 return shared_progress_bar; 157 } 158 145 159 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 146 160 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 147 161 */ 148 public boolean hasSignalledStop() {162 public synchronized boolean hasSignalledStop() { 149 163 return stop; 150 164 } … … 168 182 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1); 169 183 line = line.trim(); 184 ///ystem.err.println("Process: " + line); 170 185 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) { 171 186 // No original event is passed on, even in the lower modes … … 174 189 GShellElement element = new GShellElement(line); 175 190 String name = element.getElementName(); 191 ///ystem.err.println("Gatherer tag: " + name); 176 192 // 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' 177 193 if(name.equals(IMPORT_ELEMENT)) { 194 ///ystem.err.println("#Import"); 178 195 // We're into parsing output, so we don't need the 'calculating file size' etc string. 179 196 if(showing_string) { 180 progress_bar.setString( "");197 progress_bar.setString(null); 181 198 showing_string = false; 182 199 } … … 186 203 } 187 204 else if(name.equals(FILE_ELEMENT)) { 205 ///ystem.err.println("#File"); 188 206 file_count++; 189 207 // Set the next progress … … 197 215 // Or we're being told what plugin is actually processing the file 198 216 else if(name.equals(FILEPROCESSING_ELEMENT)) { 217 ///ystem.err.println("#FileProcessing"); 199 218 // If we are at lower mode settings fire a new 'dumbed down' event 200 219 if(Gatherer.config.getMode() <= threshold) { … … 243 262 num_docs = 0; 244 263 } 264 245 265 processed_str = null; 246 266 // The number of documents blocked … … 278 298 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete3"), event.getStatus())); 279 299 } 300 else { 301 // Try to set num docs 302 String processed_str = element.getAttribute(PROCESSED_ATTRIBUTE); 303 try { 304 num_docs = Integer.parseInt(processed_str); 305 } 306 catch(Exception exception) { 307 num_docs = 0; 308 } 309 } 280 310 } 281 311 else { … … 291 321 public void reset() { 292 322 setValue(MIN); 293 progress_bar.setString( StaticStrings.SPACE_CHARACTER);323 progress_bar.setString(null); 294 324 progress_bar.updateUI(); 295 325 } … … 303 333 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 304 334 */ 305 public void setStop(boolean state) {306 stop = state;335 public synchronized void setStop(boolean state) { 336 this.stop = state; 307 337 } 308 338 … … 310 340 */ 311 341 public void start() { 342 stop = false; 312 343 setValue(MIN); 313 344 progress_bar.setString(Dictionary.get("FileActions.Calculating_Size")); … … 329 360 private void setValue(int value) { 330 361 progress_bar.setValue(value); 362 shared_progress_bar.setValue(value); 331 363 if(value != 0 && value < previous_value) { 332 364 Gatherer.println("Progress is decreasing! " + previous_value + " -> " + value); -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r6388 r6533 42 42 import javax.swing.event.*; 43 43 import javax.swing.tree.*; 44 import org.greenstone.gatherer.Configuration; 44 45 import org.greenstone.gatherer.Dictionary; 45 46 import org.greenstone.gatherer.Gatherer; … … 228 229 } 229 230 } 230 231 // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream 232 while(eisr.ready()) { 233 int c = eisr.read(); 234 ///atherer.println("eisr: '" + (char) c + "'"); 235 if(c == '\n' || c == '\r') { 236 if(eline_buffer.length() > 0) { 237 String eline = eline_buffer.toString(); 238 ///atherer.println("* " + eline + " *"); 239 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 240 eline = null; 241 eline_buffer = new StringBuffer(); 242 } 243 } 244 else { 245 eline_buffer.append((char)c); 246 } 247 } 248 while(stdisr.ready()) { 249 int c = stdisr.read(); 250 ///atherer.println("eisr: '" + (char) c + "'"); 251 if(c == '\n' || c == '\r') { 252 if(stdline_buffer.length() > 0) { 253 String stdline = stdline_buffer.toString(); 254 ///atherer.println("+ " + stdline + " +"); 255 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 256 stdline = null; 257 stdline_buffer = new StringBuffer(); 258 } 259 } 260 else { 261 stdline_buffer.append((char)c); 262 } 263 } 264 265 // Ensure that any messages still remaining in the string buffers are fired off. 266 if(eline_buffer.length() > 0) { 267 String eline = eline_buffer.toString(); 268 ///atherer.println("Last bit of eline: " + eline); 269 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 270 eline = null; 271 } 272 273 if(stdline_buffer.length() > 0) { 274 String stdline = stdline_buffer.toString(); 275 ///atherer.println("Last bit of stdline: " + stdline); 276 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 277 stdline = null; 231 if(!hasSignalledStop()) { 232 // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream 233 while(eisr.ready()) { 234 int c = eisr.read(); 235 ///atherer.println("eisr: '" + (char) c + "'"); 236 if(c == '\n' || c == '\r') { 237 if(eline_buffer.length() > 0) { 238 String eline = eline_buffer.toString(); 239 ///atherer.println("* " + eline + " *"); 240 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 241 eline = null; 242 eline_buffer = new StringBuffer(); 243 } 244 } 245 else { 246 eline_buffer.append((char)c); 247 } 248 } 249 while(stdisr.ready()) { 250 int c = stdisr.read(); 251 ///atherer.println("eisr: '" + (char) c + "'"); 252 if(c == '\n' || c == '\r') { 253 if(stdline_buffer.length() > 0) { 254 String stdline = stdline_buffer.toString(); 255 ///atherer.println("+ " + stdline + " +"); 256 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 257 stdline = null; 258 stdline_buffer = new StringBuffer(); 259 } 260 } 261 else { 262 stdline_buffer.append((char)c); 263 } 264 } 265 266 // Ensure that any messages still remaining in the string buffers are fired off. 267 if(eline_buffer.length() > 0) { 268 String eline = eline_buffer.toString(); 269 ///atherer.println("Last bit of eline: " + eline); 270 fireMessage(type, typeAsString(type) + "> " + eline, status, bos); 271 eline = null; 272 } 273 274 if(stdline_buffer.length() > 0) { 275 String stdline = stdline_buffer.toString(); 276 ///atherer.println("Last bit of stdline: " + stdline); 277 fireMessage(type, typeAsString(type) + "> " + stdline, status, null); 278 stdline = null; 279 } 280 } 281 else { 282 System.err.println("We've been asked to stop."); 278 283 } 279 284 … … 312 317 fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status, null); 313 318 } 319 if(hasSignalledStop()) { 320 status = CANCELLED; 321 } 314 322 // We're done. 315 323 fireProcessComplete(type, status); … … 388 396 */ 389 397 protected void fireProcessComplete(int type, int status) { 390 // Tidy up by stopping the progress bar. 391 if(progress != null ) {398 // Tidy up by stopping the progress bar. If it was cancelled then the cancel command has arrived via the progress bars and they don't need to be told again (it actually causes problems). 399 if(progress != null && status != CANCELLED) { 392 400 progress.stop(); 401 } 402 403 // If we were cancelled, and we are lower details modes, fire off one last message. 404 if(status == CANCELLED && Gatherer.config.getMode() <= Configuration.SYSTEMS_MODE) { 405 GShellEvent current_event = new GShellEvent(this, 0, type, Dictionary.get("GShell.Build.BuildCancelled"), status); 406 Object[] concerned = listeners.getListenerList(); 407 for(int i = 0; i < concerned.length ; i++) { 408 if(concerned[i] == GShellListener.class) { 409 ((GShellListener)concerned[i+1]).message(current_event); 410 } 411 } 412 concerned = null; 393 413 } 394 414 // And firing off an event … … 408 428 boolean has_signalled_stop = false; 409 429 if(progress != null) { 410 returnprogress.hasSignalledStop();430 has_signalled_stop = progress.hasSignalledStop(); 411 431 } 412 432 return has_signalled_stop; -
trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java
r6388 r6533 66 66 public int exitValue(); 67 67 68 public JProgressBar getSharedProgress(); 69 68 70 /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later. 69 71 * @return A <strong>Component</strong> on which the progress of the process is being displayed.
Note:
See TracChangeset
for help on using the changeset viewer.