- Timestamp:
- 2003-05-27T15:40:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r4293 r4364 46 46 */ 47 47 public class GImportProgressMonitor 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 48 implements GShellProgressMonitor { 49 /** Indicates if the GUI has asked the process this object monitors to stop. */ 50 private boolean stop = false; 51 /** The number of directories that are expected to be scanned by this import process. May not be correct for various reasons, such as a custom RecPlug setup, but its seems the most reliable for general cases. */ 52 private int num_dirs = 0; 53 /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */ 54 private int num_docs = 0; 55 /** The progress bar this monitor updates. */ 56 private JProgressBar progress_bar; 57 /** The maximum value for this progress bar. */ 58 static final private int MAX = 1000000; 59 /** The minimum value for this progress bar. */ 60 static final private int MIN = 0; 61 /** A String fragment which is used to determine if the current output process line is referring to the number of documents actually processed by the import script. */ 62 static final private String NUM_DOCS_PROCESSED = "processed and included in the collection"; 63 /** The Sentinel value is the String fragment an output process line must start with to be considered a milestone. In this case we are counting directories, so the fragment refers to a directory scan. */ 64 static final private String SENTINEL = "recplug: getting directory "; 65 public GImportProgressMonitor() { 66 progress_bar = new JProgressBar(); 67 progress_bar.setMaximum(MAX); 68 progress_bar.setMinimum(MIN); 69 progress_bar.setValue(MIN); 70 } 71 /** Method to register a new progress bar with this monitor. 72 72 * @param progress_bar The new <strong>JProgressBar</strong>. 73 73 */ 74 75 76 77 78 79 80 74 public void addProgressBar(JProgressBar progress_bar) { 75 this.progress_bar = progress_bar; 76 progress_bar.setMaximum(MAX); 77 progress_bar.setMinimum(MIN); 78 progress_bar.setValue(MIN); 79 } 80 /** Determine the script exit value according to the progress monitor. This gets around a problem where several script failures actually result with a successful exit value. 81 81 * @return A <i>int</i> with a value of zero if and only if the script was successful. 82 82 */ 83 84 85 86 87 88 89 83 public int exitValue() { 84 if(num_docs > 0) { 85 return 0; 86 } 87 return 1; 88 } 89 /** Retrieve the number of documents recorded by the import monitor during the execution of the import scripts. 90 90 * @return An <i>int</i> giving the document number. 91 91 */ 92 93 94 92 public int getNumberOfDocuments() { 93 return num_docs; 94 } 95 95 96 96 /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later. 97 97 * @return A <strong>Component</strong> on which the progress of the process is being displayed. 98 98 */ 99 100 101 102 99 public Component getProgress() { 100 return progress_bar; 101 } 102 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 103 103 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 104 104 */ 105 106 107 108 109 110 111 112 113 114 115 116 117 105 public boolean hasSignalledStop() { 106 return stop; 107 } 108 /** Inform the progress bar that it should programatically increment progress by one step. This is only called during the metadata archive extraction so each step should be (100 / 5) / num_docs. */ 109 public void increment() { 110 if(num_docs > 0) { 111 progress_bar.setValue(progress_bar.getValue() + ((MAX / 5) / num_docs)); 112 } 113 else { 114 progress_bar.setIndeterminate(true); 115 } 116 } 117 /** This method is used to 'feed in' a line of text captured from the process. 118 118 * @param line A <strong>String</strong> of text captured from either standard out or standard error. 119 119 * TODO Everthing. 120 120 */ 121 122 123 121 public void parse(String line_raw) { 122 String line = line_raw.toLowerCase(); 123 if(line.indexOf(SENTINEL) != -1) { 124 124 ///ystem.err.println("Sentinal value detected: "); 125 126 127 128 129 130 131 132 133 134 135 125 if(num_dirs > 0) { 126 ///ystem.err.println(count + " of " + num_dirs); 127 ///ystem.err.println("Value before: " + progress_bar.getValue()); 128 progress_bar.setValue(progress_bar.getValue() + ((4 * (MAX / 5)) / num_dirs)); 129 ///ystem.err.println("Value after: " + progress_bar.getValue()); 130 } 131 else { 132 progress_bar.setIndeterminate(true); 133 } 134 } 135 else if(line.indexOf(NUM_DOCS_PROCESSED) != -1) { 136 136 // Increment the import because we have finished a directory 137 137 138 139 140 141 142 143 144 145 146 147 138 num_docs = -1; 139 StringTokenizer tokenizer = new StringTokenizer(line); 140 while(num_docs == -1 && tokenizer.hasMoreTokens()) { 141 String pos_num_docs_str = tokenizer.nextToken(); 142 try { 143 num_docs = Integer.parseInt(pos_num_docs_str); 144 } 145 catch (Exception error) { 146 } 147 } 148 148 ///ystem.err.println("Parsed num_docs to be " + num_docs); 149 150 151 149 } 150 } 151 /** Since the creator of this process monitor is actually in the GUI, this class provides the simpliest way to send a cancel process message between the two. 152 152 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 153 153 */ 154 155 156 157 158 154 public void setStop(boolean state) { 155 stop = state; 156 progress_bar.setIndeterminate(false); 157 } 158 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 159 159 * TODO Everthing. 160 160 */ 161 162 163 164 165 166 161 public void start() { 162 num_dirs = Gatherer.c_man.getCollection().getFolderCount(); 163 progress_bar.setValue(MIN); 164 System.err.println("Number of directories is " + num_dirs); 165 } 166 /** This method indicates the process is complete. 167 167 * TODO Everthing. 168 168 */ 169 170 171 172 169 public void stop() { 170 progress_bar.setIndeterminate(false); 171 progress_bar.setValue(MAX); 172 } 173 173 }
Note:
See TracChangeset
for help on using the changeset viewer.