- Timestamp:
- 2003-08-27T14:58:06+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r5035 r5292 49 49 /** Indicates if the GUI has asked the process this object monitors to stop. */ 50 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; 51 private int file_num = 0; 52 /** The number of files expected to be scanned by this import process. */ 53 private int num_files = 0; 53 54 /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */ 54 55 private int num_docs = 0; … … 62 63 static final private String NUM_DOCS_PROCESSED = "processed and included in the collection"; 63 64 /** 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 static final private String SENTINEL = "recplug - "; 66 65 67 public GImportProgressMonitor() { 66 68 progress_bar = new JProgressBar(); … … 70 72 progress_bar.setValue(MIN); 71 73 } 74 72 75 /** Method to register a new progress bar with this monitor. 73 74 */ 76 * @param progress_bar The new <strong>JProgressBar</strong>. 77 */ 75 78 public void addProgressBar(JProgressBar progress_bar) { 76 79 this.progress_bar = progress_bar; … … 79 82 progress_bar.setValue(MIN); 80 83 } 84 81 85 /** 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. 82 83 86 * @return A <i>int</i> with a value of zero if and only if the script was successful. 87 */ 84 88 public int exitValue() { 85 89 if(num_docs > 0) { … … 88 92 return 1; 89 93 } 94 90 95 /** Retrieve the number of documents recorded by the import monitor during the execution of the import scripts. 91 92 96 * @return An <i>int</i> giving the document number. 97 */ 93 98 public int getNumberOfDocuments() { 94 99 return num_docs; … … 96 101 97 102 /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later. 98 99 103 * @return A <strong>Component</strong> on which the progress of the process is being displayed. 104 */ 100 105 public Component getProgress() { 101 106 return progress_bar; 102 107 } 108 103 109 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 104 105 110 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 111 */ 106 112 public boolean hasSignalledStop() { 107 113 return stop; 108 114 } 115 109 116 /** 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. */ 110 117 public void increment() { … … 116 123 } 117 124 } 125 118 126 /** This method is used to 'feed in' a line of text captured from the process. 119 120 121 127 * @param line A <strong>String</strong> of text captured from either standard out or standard error. 128 * TODO Everthing. 129 */ 122 130 public void parse(String line_raw) { 123 131 progress_bar.setString(""); 124 132 String line = line_raw.toLowerCase(); 125 if(line.indexOf(SENTINEL) != -1) { 126 ///ystem.err.println("Sentinal value detected: "); 127 if(num_dirs > 0) { 128 ///ystem.err.println(count + " of " + num_dirs); 129 ///ystem.err.println("Value before: " + progress_bar.getValue()); 130 progress_bar.setValue(progress_bar.getValue() + ((4 * (MAX / 5)) / num_dirs)); 131 ///ystem.err.println("Value after: " + progress_bar.getValue()); 132 } 133 else { 134 progress_bar.setIndeterminate(true); 133 if (line.indexOf(SENTINEL) == 0) { 134 file_num = file_num + 1; 135 ///ystem.err.println("Done " + file_num + " of " + num_files + "..."); 136 if (num_files > 0) { 137 progress_bar.setValue((4 * MAX * file_num) / (5 * num_files)); 135 138 } 136 139 } 137 else if(line.indexOf(NUM_DOCS_PROCESSED) != -1) { 138 // Increment the import because we have finished a directory 139 140 else if (line.indexOf(NUM_DOCS_PROCESSED) != -1) { 140 141 num_docs = -1; 141 142 StringTokenizer tokenizer = new StringTokenizer(line); … … 148 149 } 149 150 } 150 151 ///ystem.err.println("Parsed num_docs to be " + num_docs); 151 152 } 152 153 } … … 158 159 159 160 /** 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. 160 161 161 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 162 */ 162 163 public void setStop(boolean state) { 163 164 stop = state; 164 165 progress_bar.setIndeterminate(false); 165 166 } 167 166 168 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 167 169 * TODO Everthing. … … 171 173 progress_bar.setString(Gatherer.dictionary.get("FileActions.Calculating_Size", (String)null)); 172 174 progress_bar.setIndeterminate(false); 173 num_dirs = Gatherer.c_man.getCollection().getFolderCount();174 175 progress_bar.setValue(MIN); 175 Gatherer.println("Number of directories is " + num_dirs); 176 num_files = Gatherer.c_man.getCollection().getDocumentCount(); 177 ///ystem.err.println("Number of files: " + num_files); 178 file_num = 0; 176 179 } 180 177 181 /** This method indicates the process is complete. 178 182 * TODO Everthing.
Note:
See TracChangeset
for help on using the changeset viewer.