- 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/GBuildProgressMonitor.java
r4293 r4364 46 46 */ 47 47 public class GBuildProgressMonitor 48 49 50 51 52 53 54 55 56 57 58 48 implements GShellProgressMonitor { 49 /** Indicates if the GUI has asked the process this object monitors to stop. */ 50 private boolean stop = false; 51 52 private GImportProgressMonitor import_progress = null; 53 54 private int num_docs = -1; 55 56 private int num_indexes = -1; 57 58 private int state = 0; 59 59 60 60 /** The progress bar this monitor updates. */ 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 61 private JProgressBar progress_bar; 62 63 static final private int MIN = 0; 64 static final private int MAX = 1000000; 65 66 static final int BASE = 0; 67 static final int CTCT = 1; // Creating the compressed text 68 static final int CTCT_CTS = 2; // Creating the compressed text - collecting text statistics 69 static final int CTCT_CTS_PS = 3; // Creating the compressed text - collecting text statistics - parsed successfully 70 static final int CTCT_CTCD = 4; // Creating the compressed text - creating the compression dictionary 71 static final int CTCT_CTT = 5; // Creating the compressed text - compressing the text 72 static final int CTCT_CTT_PS = 6; // Creating the compressed text - compressing the text - parsed successfully 73 static final int BI = 7; // Building index 74 static final int BI_CID = 8; // Building index - creating index dictionary 75 static final int BI_CID_PS = 9; // Building index - creating index dictionary - parsed successfully 76 static final int BI_ITT = 10; // Building index - inverting the text 77 static final int BI_ITT_PS = 11; // Building index - inverting the text - parsed successfully 78 static final int BI_CTWF = 12; // Building index - create the weights file 79 static final int BI_CODSD = 13; // Building index - creating 'on-disk' stemmed dictionary 80 static final int BI_CSI = 14; // Building index - creating stem indexes 81 static final int CTID = 15; // Creating the info database 82 static final int CTID_PS = 16; // Creating the info database - parsed successfully 83 static final int CAF = 17; // Creating auxiliary files 84 85 static final String BI_STR = "*** building index"; 86 static final String CTS_STR = "collecting text statistics"; 87 static final String CTT_STR = "compressing the text"; 88 static final String CTWF_STR = "create the weights file"; 89 static final String CAF_STR = "creating auxiliary files"; 90 static final String CID_STR = "creating index dictionary"; 91 static final String CSI_STR = "creating stem indexes"; 92 static final String CTCT_STR = "*** creating the compressed text"; 93 static final String CTCD_STR = "creating the compression dictionary"; 94 static final String CTID_STR = "*** creating the info database and processing associated files"; 95 static final String CODSD_STR = "creating 'on-disk' stemmed dictionary"; 96 static final String ITT_STR = "inverting the text"; 97 static final String PS_STR = "hash"; 98 99 public GBuildProgressMonitor(GImportProgressMonitor import_progress) { 100 this.import_progress = import_progress; 101 progress_bar = new JProgressBar(); 102 progress_bar.setMaximum(MAX); 103 progress_bar.setMinimum(MIN); 104 progress_bar.setValue(MIN); 105 } 106 107 /** Method to register a new progress bar with this monitor. 108 108 * @param progress_bar The new <strong>JProgressBar</strong>. 109 109 */ 110 111 112 113 114 115 116 110 public void addProgressBar(JProgressBar progress_bar) { 111 this.progress_bar = progress_bar; 112 progress_bar.setMaximum(MAX); 113 progress_bar.setMinimum(MIN); 114 progress_bar.setValue(MIN); 115 } 116 /** 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. 117 117 * @return A <i>int</i> with a value of zero if and only if the script was successful. 118 118 */ 119 120 121 122 123 124 125 119 public int exitValue() { 120 if(state == BASE) { 121 return 0; 122 } 123 return 1; 124 } 125 /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later. 126 126 * @return A <strong>Component</strong> on which the progress of the process is being displayed. 127 127 */ 128 129 130 131 128 public Component getProgress() { 129 return progress_bar; 130 } 131 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 132 132 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 133 133 */ 134 135 136 137 138 139 140 141 142 134 public boolean hasSignalledStop() { 135 return stop; 136 } 137 /** Inform the progress bar that it should programatically increment progress by one step. */ 138 public void increment() { 139 // There is no reason this should be called for a build. 140 } 141 142 /** This method is used to 'feed in' a line of text captured from the process. 143 143 * @param line A <strong>String</strong> of text captured from either standard out or standard error. 144 144 */ 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 145 public void parse(String raw_line) { 146 String line = raw_line.toLowerCase(); 147 // We first check if we can parse, which depends on num_docs > 0 and num_indexes > 0. 148 if(num_docs > 0 && num_indexes > 0) { 149 switch(state) { 150 case BASE: 151 // We are watching for the beginning of a phase 152 if(line.indexOf(CTCT_STR) != -1) { 153 // No progress really. 154 state = CTCT; 155 ///ystem.err.println("CTCT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 156 } 157 else if(line.indexOf(BI_STR) != -1) { 158 // Skip the progress up to this point. 159 progress_bar.setValue(progress_bar.getValue() + (MAX / (3 + num_indexes))); 160 state = BI; 161 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 162 } 163 else if(line.indexOf(CTID_STR) != -1) { 164 // Skip the progress up to this point 165 progress_bar.setValue(progress_bar.getValue() + (((1 + num_indexes ) * MAX) / (3 + num_indexes))); 166 state = CTID; 167 ///ystem.err.println("CTID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 168 } 169 else if(line.indexOf(CAF_STR) != -1) { 170 // Skip the progres up to this point 171 progress_bar.setValue(progress_bar.getValue() + (((2 + num_indexes ) * MAX) / (3 + num_indexes))); 172 state = CAF; 173 ///ystem.err.println("CAF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 174 } 175 break; 176 case CTCT: 177 if(line.indexOf(CTS_STR) != -1) { 178 // No progress really. 179 state = CTCT_CTS; 180 ///ystem.err.println("CTS [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 181 } 182 break; 183 case CTCT_CTS: 184 if(line.indexOf(PS_STR) != -1) { 185 // We have finally found something we can increment because of. 186 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3 * num_docs))); 187 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3 * num_docs))); 188 } 189 else if(line.indexOf(CTCD_STR) != -1) { 190 state = CTCT_CTCD; 191 ///ystem.err.println("CTCD [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 192 } 193 break; 194 case CTCT_CTCD: 195 if(line.indexOf(CTT_STR) != -1) { 196 // Finished creating the compression dictionary. 197 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3))); 198 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3))); 199 state = CTCT_CTT; 200 ///ystem.err.println("CTT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 201 } 202 break; 203 case CTCT_CTT: 204 if(line.indexOf(PS_STR) != -1) { 205 // We have finally found something we can increment because of. 206 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3 * num_docs))); 207 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3 * num_docs))); 208 } 209 else if(line.indexOf(BI_STR) != -1) { 210 state = BI; 211 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 212 } 213 break; 214 case BI: 215 if(line.indexOf(CID_STR) != -1) { 216 state = BI_CID; 217 ///ystem.err.println("CID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 218 } 219 break; 220 case BI_CID: 221 if(line.indexOf(PS_STR) != -1) { 222 // We have finally found something we can increment because of. 223 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5 * num_docs))); 224 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5 * num_docs))); 225 } 226 else if(line.indexOf(ITT_STR) != -1) { 227 state = BI_ITT; 228 ///ystem.err.println("ITT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 229 } 230 break; 231 case BI_ITT: 232 if(line.indexOf(PS_STR) != -1) { 233 // We have finally found something we can increment because of. 234 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5 * num_docs))); 235 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5 * num_docs))); 236 } 237 else if(line.indexOf(CTWF_STR) != -1) { 238 state = BI_CTWF; 239 ///ystem.err.println("CTWF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 240 } 241 break; 242 case BI_CTWF: 243 if(line.indexOf(CODSD_STR) != -1) { 244 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 245 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 246 state = BI_CODSD; 247 ///ystem.err.println("CODSD [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 248 } 249 break; 250 case BI_CODSD: 251 if(line.indexOf(CSI_STR) != -1) { 252 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 253 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 254 state = BI_CSI; 255 ///ystem.err.println("CSI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 256 } 257 break; 258 case BI_CSI: 259 if(line.indexOf(BI_STR) != -1) { 260 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 261 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 262 state = BI; 263 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 264 } 265 else if(line.indexOf(CTID_STR) != -1) { 266 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 267 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 268 state = CTID; 269 ///ystem.err.println("CTID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 270 } 271 break; 272 case CTID: 273 if(line.indexOf(PS_STR) != -1) { 274 // We have finally found something we can increment because of. 275 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * num_docs))); 276 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * num_docs))); 277 } 278 else if(line.indexOf(CAF_STR) != -1) { 279 state = CAF; 280 ///ystem.err.println("CAF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 281 } 282 break; 283 case CAF: 284 progress_bar.setValue(MAX); 285 state = BASE; 286 ///ystem.err.println("Done! 100%"); 287 break; 288 } 289 } 290 else { 291 291 ///ystem.err.println("Number of documents = " + num_docs); 292 292 ///ystem.err.println("Number of indexes = " + num_indexes); 293 294 295 296 297 298 299 300 301 302 303 304 305 306 293 progress_bar.setIndeterminate(true); 294 } 295 } 296 297 public void reset() { 298 state = BASE; 299 progress_bar.setValue(MIN); 300 num_docs = -1; 301 num_indexes = -1; 302 stop = false; 303 progress_bar.setIndeterminate(false); 304 } 305 306 /** 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. 307 307 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 308 308 */ 309 310 311 312 313 309 public void setStop(boolean state) { 310 stop = state; 311 progress_bar.setIndeterminate(false); 312 } 313 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 314 314 * TODO Everthing. 315 315 */ 316 317 318 319 320 321 316 public void start() { 317 progress_bar.setValue(MIN); 318 num_indexes = Gatherer.g_man.config_pane.getIndexes().size(); 319 num_docs = import_progress.getNumberOfDocuments(); 320 } 321 /** This method indicates the process is complete. 322 322 * TODO Everthing. 323 323 */ 324 325 326 327 324 public void stop() { 325 progress_bar.setIndeterminate(false); 326 progress_bar.setValue(MAX); // Not max, or else it won't blank properly for the next build. 327 } 328 328 } 329 330
Note:
See TracChangeset
for help on using the changeset viewer.