Changeset 5581
- Timestamp:
- 2003-10-06T13:32:25+13:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 50 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r5564 r5581 1 package org.greenstone.gatherer;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer; 38 38 39 import java.awt.*; 39 40 import java.io.*; … … 43 44 import javax.swing.*; 44 45 import javax.swing.plaf.*; 45 import org.greenstone.gatherer.cdm.Language;46 import org.greenstone.gatherer.gui.Coloring;47 46 import org.greenstone.gatherer.msm.MSMUtils; 48 import org.greenstone.gatherer.util.GURL;49 47 import org.greenstone.gatherer.util.Utility; 50 48 import org.w3c.dom.*; 49 51 50 /** This class stores the various configurable settings inside the Gatherer, both during a session, and between sessions in the form of XML. However not all data members are retained during xml serialization. To further improve efficiency, the property-name -> DOM Element pairs are stored in a SoftReferenced Hashtable. 52 51 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 206 205 HashMap properties = new HashMap(); 207 206 try { 208 207 // Locate the appropriate element 209 208 Element document_element = null; 210 209 if(general) { … … 306 305 try { 307 306 String raw = getString(property, general); 308 307 // Dimension is a width by height pair, comma separated (also remove whitespace) 309 308 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1); 310 309 int width = Integer.parseInt(tokenizer.nextToken()); … … 656 655 UIManager.put("ScrollBar.background", new ColorUIResource(getColor("coloring.scrollbar_background", false))); 657 656 UIManager.put("ScrollBar.thumb", new ColorUIResource(getColor("coloring.scrollbar_foreground", false))); 658 if (Gatherer.g_man != null) {657 if (Gatherer.g_man != null) { 659 658 JPanel pane = (JPanel) Gatherer.g_man.getContentPane(); 660 659 pane.updateUI(); -
trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r5571 r5581 198 198 dictionary = new Dictionary(config.getLocale("general.locale", true), config.getFont("general.font", true)); 199 199 200 if (gsdl_path == null) {200 if (gsdl_path == null) { 201 201 missingGSDL(dictionary); 202 202 } 203 203 204 204 // If we were given a server run it if neccessary. 205 if (config.exec_file != null) {205 if (config.exec_file != null) { 206 206 startServerEXE(); 207 207 } 208 208 209 209 // Having loaded the configuration (necessary to determine if certain warnings have been disabled) and dictionary, we now check if the necessary path variables have been provided. 210 if (config.exec_file == null && config.exec_address == null) {211 if (config.exec_file == null) {210 if (config.exec_file == null && config.exec_address == null) { 211 if (config.exec_file == null) { 212 212 Gatherer.println("config.exec_file is null"); 213 213 } 214 if (config.exec_address == null) {214 if (config.exec_address == null) { 215 215 Gatherer.println("config.exec_address is null"); 216 216 } 217 217 missingEXEC(dictionary); 218 218 } 219 219 220 // Perl path is a little different as it is perfectly ok to start the Gatherer without providing a perl path 220 221 boolean found_perl = false; 221 if (config.perl_path != null) {222 if (config.perl_path != null) { 222 223 // See if the file pointed to actually exists 223 224 File perl_file = new File(config.perl_path); … … 225 226 perl_file = null; 226 227 } 227 if (config.perl_path == null || !found_perl) {228 if (config.perl_path == null || !found_perl) { 228 229 // Run test to see if we can run perl as is. 229 230 PerlTest perl_test = new PerlTest(); 230 if (perl_test.found()) {231 if (perl_test.found()) { 231 232 // If so replace the perl path with the system default (or null for unix). 232 233 config.perl_path = perl_test.toString(); … … 234 235 } 235 236 } 236 if (!found_perl) {237 if (!found_perl) { 237 238 // Time for an error message. 238 239 missingPERL(dictionary); … … 399 400 return null; 400 401 } 402 401 403 /** Used to 'spawn' a new child application when a file is double clicked. 402 404 * @param command The command to run in the child process to start the application, garnered from the registry of a default associations file, and presented as a <strong>String</strong>. … … 946 948 } 947 949 } 948 949 950 951 952 -
trunk/gli/src/org/greenstone/gatherer/WGet.java
r5317 r5581 1 package org.greenstone.gatherer;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer; 38 38 39 import java.awt.*; 39 40 import java.io.*; … … 44 45 import org.greenstone.gatherer.Gatherer; 45 46 import org.greenstone.gatherer.collection.Job; 47 46 48 /** This class provides access to the functionality of the WGet program, either by calling it via a shell script or by the JNI. It maintains a queue of pending jobs, and the component for showing these tasks to the user. 47 49 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 89 91 90 92 /** Called by the WGet native code to inform us of a new download starting within the given job. 91 92 93 93 * @param url The url that is being downloaded, as a <strong>String</strong>. 94 * @see org.greenstone.gatherer.collection.Job 95 */ 94 96 public synchronized void addDownload(String url) { 95 97 job.addDownload(url); … … 97 99 98 100 /* Used to advise the Job of a newly parsed link. Its up to Job to decide if it already knows about this url, and if not to update its progress bar. 99 100 101 102 103 101 * @param url The url in question as a <strong>String</strong>. 102 * @param type <i>true</i> if this is an internal link, <i>false</i> for and external one. 103 * @return A <i>boolean</i> with a value of <i>true</i> indicating if the url was added, <i>false</i> otherwise. 104 * @see org.greenstone.gatherer.collection.Job 105 */ 104 106 public synchronized boolean addLink(String url, int type) { 105 107 return job.addLink(url, type); … … 107 109 108 110 /* Whenever files are moved into or out of the collection we need to 109 * run convertLinks on the files remaining. This ensures that we have 110 * the most efficient balance between local and absolute links. 111 * @param records A <strong>Vector</strong> containing information about the files in 112 * the current collection. From these url and file information is 113 * harvested. 114 */ 115 // public void convertLinks(Vector records) { 111 * run convertLinks on the files remaining. This ensures that we have 112 * the most efficient balance between local and absolute links. 113 * @param records A <strong>Vector</strong> containing information about the files in 114 * the current collection. From these url and file information is 115 * harvested. 116 */ 116 117 public void convertLinks() { 117 118 Vector args = new Vector(); … … 162 163 163 164 /** This method is called to delete a certain job from the queue. 164 165 166 167 168 169 165 * This job may be pending, complete or even in progress. However 166 * if it is currently downloading then the delete method must 167 * wait until the native job has cleanly exited before removing 168 * the job. 169 * @param delete_me The <strong>Job</strong> that is to be deleted. 170 */ 170 171 public void deleteJob(Job delete_me) { 171 if (delete_me == job) {172 172 if (delete_me == job) { 173 // While this seems wasteful its only for the briefest moment. 173 174 while(busy) { 174 175 } 175 176 job = null; 176 177 } 177 if (delete_me.hasSignalledStop()) {178 if (delete_me.hasSignalledStop()) { 178 179 list_pane.remove(delete_me.getProgressBar()); 179 180 job_queue.remove(delete_me); … … 199 200 200 201 /** Called by the WGet native code when the current download, 201 202 203 204 202 * for the indicated job, is completed. In turn all download 203 * listeners are informed. 204 * @see org.greenstone.gatherer.collection.Job 205 */ 205 206 public synchronized void downloadComplete() { 206 207 job.downloadComplete(); … … 208 209 209 210 /** Called by the WGet native code when the requested download returns 210 211 212 213 211 * a status code other than 200-399 for the specified download job. 212 * for. 213 * @see org.greenstone.gatherer.collection.Job 214 */ 214 215 public synchronized void downloadFailed() { 215 216 // Add the failed download as a new job if the user so requests. … … 218 219 219 220 /** Called by the WGet native code when some non-fatal error has caused 220 221 222 223 224 221 * a download to fail. An example of a warning would be if a file can't 222 * be downloaded as doing so would clobber an existing file and the -nc 223 * flag is set. 224 * @see org.greenstone.gatherer.collection.Job 225 */ 225 226 public synchronized void downloadWarning() { 226 227 job.downloadWarning(); … … 228 229 229 230 /** Used by other graphic functions to get a reference to the 230 231 231 * scroll pane containing the current list of jobs. 232 */ 232 233 public JScrollPane getJobList() { 233 234 return list_scroll; … … 235 236 236 237 /** Returns the current state of the stop flag for the job indicated. 237 238 239 240 238 * @return A boolean representing whether the user has requested to 239 * stop. 240 * @see org.greenstone.gatherer.collection.Job 241 */ 241 242 public synchronized boolean hasSignalledStop() { 242 243 return job.hasSignalledStop(); … … 244 245 245 246 /** Creates a new mirroring job on the queue given the target url and the destination (private, public). All other details are harvested from the config file, but these two must be captured from the GUI's current state. 246 247 248 249 250 251 * @see org.greenstone.gatherer.collection.Job252 253 254 247 * @param url a URL which points to the root url for the mirroring 248 * @param model the GTreeModel that any new records should be added to 249 * @param destination the destination file as a String 250 * @see org.greenstone.gatherer.Configuration 251 * @see org.greenstone.gatherer.Gatherer 252 * @see org.greenstone.gatherer.collection.Job 253 * @see org.greenstone.gatherer.gui.GProgressBar 254 * @see org.greenstone.gatherer.util.GURL 255 */ 255 256 public void newJob(TreeModel model, boolean overwrite, boolean no_parents, boolean other_hosts, boolean page_requisites, URL url, int depth, String destination) { 256 257 // Create the job and fill in the details from gatherer.config. … … 284 285 285 286 /** Called by the WGet native code to signal the current progress of 286 287 288 289 290 291 292 287 * downloading for the specified job. 288 * @param current A long representing the number of bytes that have 289 * been downloaded since the last update. 290 * @param expected A long representing the total number of bytes 291 * expected for this download. 292 * @see org.greenstone.gatherer.collection.Job 293 */ 293 294 public synchronized void updateProgress(long current, long expected) { 294 295 job.updateProgress(current, expected); … … 296 297 297 298 /* There may be times when the download thread is sleeping, but the 298 299 300 301 299 * user has indicated that a previously paused job should now begin 300 * again. The flag within the job will change, so we tell the thread 301 * to start again. 302 */ 302 303 public void resumeThread() { 303 304 synchronized(this) { … … 307 308 308 309 /* This begins the WGet thread, which simply iterates through the waiting 309 310 311 312 313 310 * jobs attempting each one. Successful downloads are removed from the 311 * waiting list. 312 * @see org.greenstone.gatherer.Gatherer 313 * @see org.greenstone.gatherer.collection.Job 314 */ 314 315 public void run() { 315 316 while(true) { … … 322 323 if(job.getState() == Job.RUNNING) { 323 324 Gatherer.println("Job " + job.toString() + " Begun."); 324 325 325 // A lock to prevent us deleting this job while its being 326 // run, unless you want things to go really wrong. 326 327 busy = true; 327 328 if(simple) { … … 358 359 359 360 /* Link to the call to the WGet Native method for downloading. 360 361 362 363 364 361 * @param argc An int representing the number of elements in argv. 362 * @param argv An array of objects passed as arguments to wget. 363 * @param debug Whether the native code should show java-only debug 364 * messages. 365 */ 365 366 public native int wget(int argc, Object argv[], boolean debug); 366 367 367 368 /* Link to the call to the WGet Native method for converting url links. 368 * @param argc An int representing the number of object elements in argv. 369 * @param argv An array of objects passed as arguments to wget. 370 * @param urlc An int representing the number of url string elements 371 * in urlv. 372 * @param urlv An array of strings representing urls. 373 * @param filec An int representing the number of file string elements 374 * in filev. 375 * @param filev An array of strings representing files. 376 */ 369 * @param argc An int representing the number of object elements in argv. 370 * @param argv An array of objects passed as arguments to wget. 371 * @param urlc An int representing the number of url string elements in urlv. 372 * @param urlv An array of strings representing urls. 373 * @param filec An int representing the number of file string elements in filev. 374 * @param filev An array of strings representing files. 375 */ 377 376 public native void wren(int argc, Object argv[], int urlc, Object urlv[], int filec, Object filev[]); 378 377 } 379 380 381 382 383 384 385 -
trunk/gli/src/org/greenstone/gatherer/checklist/CheckList.java
r5159 r5581 35 35 *######################################################################## 36 36 */ 37 38 39 40 41 42 43 /* GPL_HEADER */44 37 package org.greenstone.gatherer.checklist; 38 45 39 /************************************************************************************** 46 40 * Title: Gatherer … … 56 50 import javax.swing.border.*; 57 51 import org.greenstone.gatherer.checklist.Entry; 52 58 53 /** This class provides a visual component that has the form of a list, as provided by JList but uses JCheckBox for data selection. Thus several elements can be 'ticked' in the list, and this selection returned using the method getSelected().<BR>Parts of this code modified from Trevor Harmon's posting on www.dejanews.com. 59 54 * @author John Thompson … … 156 151 157 152 /** Retrieve the currently ticked entries from this list. 158 159 160 153 * @return An <strong>ArrayList</strong> containing only those entries from the initial list that are checked. 154 * @see org.greenstone.gatherer.checklist.CheckList.Entry 155 */ 161 156 public ArrayList getSelected() { 162 157 ArrayList result = new ArrayList(); … … 230 225 231 226 /** Checks the entries in the list whose name appear in the given array. 232 233 234 227 * @param names The name of entries to be checked as a <strong>String[]</strong>. 228 * @see org.greenstone.gatherer.checklist.CheckList.Entry 229 */ 235 230 public void setSelected(String names[]) { 236 231 DefaultListModel model = (DefaultListModel) getModel(); … … 260 255 * @param cell_has_focus <i>true</i> if and only if the specified cell has the focus. 261 256 * @return A <strong>Component</strong> whose paint() method will render the specified value. 262 257 */ 263 258 public Component getListCellRendererComponent(JList list, Object value, int index, boolean is_selected, boolean cell_has_focus) { 264 259 JCheckBox checkbox = (JCheckBox) value; … … 301 296 } 302 297 } 303 -
trunk/gli/src/org/greenstone/gatherer/collection/BuildOptions.java
r5164 r5581 5 5 import java.util.*; 6 6 import org.apache.xerces.parsers.DOMParser; 7 import org.greenstone.gatherer.Configuration;8 7 import org.greenstone.gatherer.Gatherer; 9 8 import org.greenstone.gatherer.cdm.Argument; … … 13 12 import org.w3c.dom.*; 14 13 import org.xml.sax.InputSource; 14 15 15 /** Build options uses the argument list found in config.xml and the current settings from the loaded collection configuration to represent the options the user wants to use during import and build. If there are no arguments stored in config.xml, or if the user indicates the argument are out of date, this class tries to parse new ones. */ 16 16 public class BuildOptions { … … 371 371 argument_element = null; 372 372 } 373 373 // If we haven't found an instance of this argument, but should have, then add it. 374 374 if(!found && (enable || value != null)) { 375 375 Element argument_element = document.createElement(ARGUMENT); … … 387 387 arguments = null; 388 388 document = null; 389 389 // Make sure the collection knows to save. 390 390 Gatherer.c_man.getCollection().setSaved(false); 391 391 } -
trunk/gli/src/org/greenstone/gatherer/collection/Collection.java
r5237 r5581 1 package org.greenstone.gatherer.collection;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.collection; 38 38 39 import java.io.*; 39 40 import java.util.*; … … 51 52 import org.greenstone.gatherer.util.Utility; 52 53 import org.w3c.dom.*; 54 53 55 /** Collection provides a common collection point for all the information about a certain collection build session. It keeps a record of several other managers that actually handle the content of the collection, such as metadata sets and metadata itself. 54 56 * @author John Thompson, Greenstone Digital Library, University of Waikato -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionConfiguration.java
r5298 r5581 8 8 import org.greenstone.gatherer.util.Utility; 9 9 import org.w3c.dom.*; 10 10 11 /** This class provides access to a collection configuration file. This version accepts either a valid xml document or a historical collect.cfg file. */ 11 12 public class CollectionConfiguration … … 172 173 } 173 174 174 175 176 177 178 179 175 /** Retrieve the short name for this collection which, given this current file is in <col_name>/etc/collect.cfg, is the name of this file's parent file's parent. 176 * @return the short name of this collection as a String 177 */ 178 public String getShortName() { 179 return file.getParentFile().getParentFile().getName(); 180 } 180 181 181 182 public void setName(String name) { … … 185 186 /** Display the title for this collection. */ 186 187 public String toString() { 187 188 188 return getName(); 189 } 189 190 } -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r5571 r5581 105 105 106 106 private int special_case = -1; 107 107 /** Holds a reference to the thread responsible for closing the collection. If non-null then only calls from the given thread will see the collection is non-ready. All other threads will have to wait until closing thread, and all of it consequential calls, are completely finished. */ 108 108 private Thread closing_thread = null; 109 109 … … 173 173 shell.addGShellListener(Gatherer.g_man.create_pane); 174 174 shell.start(); 175 Gatherer.println("CollectionManager.buildCollection().return"); 176 } 175 Gatherer.println("CollectionManager.buildCollection().return"); 176 } 177 177 178 /** Used to determine whether the currently active collection has been built. 178 179 * @return A boolean indicating the built status of the collection. … … 367 368 // And if that fails then we must have been asked by Satan himself to build the very digital collections of hell, because they don't match any goodly greenstone collection I have ever seen, so you can't blame me if I can't import them. 368 369 369 370 370 // Now we update our collect.cfg 371 371 Gatherer.println("Copy and update collect.cfg from base collection."); … … 381 381 progress.setProgress(3); 382 382 383 383 // Has to be done after creating metadata set manager. 384 384 File gmeta_dir_temp = new File(getCollectionMetadata()+"temp.dat"); 385 385 File gmeta_dir = gmeta_dir_temp.getParentFile(); … … 391 391 392 392 progress.setProgress(6); 393 393 // Register ourselves as being interested in what the msm has to say. 394 394 collection.msm.addMSMListener(this); 395 395 // Create a lock file. 396 396 File lock_file = new File(a_dir, LOCK_FILE); 397 397 FileOutputStream out = new FileOutputStream(lock_file); … … 465 465 } 466 466 /** Constructs the absolute filename of the collection archive directory, which should resemble "$GSDLHOME/collect/<col_name>/archive/" 467 468 469 470 471 472 467 * @return A <strong>String</strong> containing the filename. 468 * @see org.greenstone.gatherer.Configuration 469 * @see org.greenstone.gatherer.Gatherer 470 * @see org.greenstone.gatherer.collection.Collection 471 * @see org.greenstone.gatherer.util.Utility 472 */ 473 473 public String getCollectionArchive() { 474 474 return Utility.getArchiveDir(Gatherer.config.gsdl_path, collection.getName()); 475 475 } 476 476 /** Constructs the absolute filename of the collection building directory, which should resemble "$GSDLHOME/collect/<col_name>/building/" 477 478 479 480 481 482 477 * @return A <strong>String</strong> containing the filename. 478 * @see org.greenstone.gatherer.Configuration 479 * @see org.greenstone.gatherer.Gatherer 480 * @see org.greenstone.gatherer.collection.Collection 481 * @see org.greenstone.gatherer.util.Utility 482 */ 483 483 public String getCollectionBuild() { 484 484 return Utility.getBuildDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 485 485 } 486 486 /** Constructs the absolute filename of the collection cache directory, which should resemble "$GSDLHOME/collect/<col_name>/gcache/" 487 488 489 490 491 492 487 * @return A <strong>String</strong> containing the filename. 488 * @see org.greenstone.gatherer.Configuration 489 * @see org.greenstone.gatherer.Gatherer 490 * @see org.greenstone.gatherer.collection.Collection 491 * @see org.greenstone.gatherer.util.Utility 492 */ 493 493 public String getCollectionCache() { 494 494 return Utility.getCacheDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 495 495 } 496 496 /** Constructs the absolute filename of the collection config file, which should resemble "$GSDLHOME/collect/<col_name>/etc/collect.cfg" 497 498 499 500 501 502 497 * @return A <strong>String</strong> containing the filename. 498 * @see org.greenstone.gatherer.Configuration 499 * @see org.greenstone.gatherer.Gatherer 500 * @see org.greenstone.gatherer.collection.Collection 501 * @see org.greenstone.gatherer.util.Utility 502 */ 503 503 public String getCollectionConfig() { 504 504 return Utility.getConfigDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); … … 506 506 507 507 /** Constructs the absolute filename of the collection directory, which should resemble "$GSDLHOME/collect/<col_name>" 508 509 510 511 512 513 508 * @return A <strong>String</strong> containing the directory name. 509 * @see org.greenstone.gatherer.Configuration 510 * @see org.greenstone.gatherer.Gatherer 511 * @see org.greenstone.gatherer.collection.Collection 512 * @see org.greenstone.gatherer.util.Utility 513 */ 514 514 public String getCollectionDirectory() { 515 515 return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator; … … 517 517 518 518 /** Constructs the absolute filename of the collection etc directory, which should resemble "$GSDLHOME/collect/<col_name>/etc/" 519 520 521 522 523 524 519 * @return A <strong>String</strong> containing the filename. 520 * @see org.greenstone.gatherer.Configuration 521 * @see org.greenstone.gatherer.Gatherer 522 * @see org.greenstone.gatherer.collection.Collection 523 * @see org.greenstone.gatherer.util.Utility 524 */ 525 525 public String getCollectionEtc() { 526 526 return Utility.getEtcDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 527 527 } 528 528 /** Constructs the absolute filename of the collection file, which should resemble "$GSDLHOME/collect/<col_name>/<col_name>.col" 529 530 531 532 533 534 529 * @return A <strong>String</strong> containing the filename. 530 * @see org.greenstone.gatherer.Configuration 531 * @see org.greenstone.gatherer.Gatherer 532 * @see org.greenstone.gatherer.collection.Collection 533 * @see org.greenstone.gatherer.util.Utility 534 */ 535 535 public String getCollectionFilename() { 536 536 return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator + collection.getName() + ".col"; 537 537 } 538 538 /** Constructs the absolute filename of the collection import directory, which should resemble "$GSDLHOME/collect/<col_name>/import/" 539 540 541 542 543 544 539 * @return A <strong>String</strong> containing the filename. 540 * @see org.greenstone.gatherer.Configuration 541 * @see org.greenstone.gatherer.Gatherer 542 * @see org.greenstone.gatherer.collection.Collection 543 * @see org.greenstone.gatherer.util.Utility 544 */ 545 545 public String getCollectionImport() { 546 546 return Utility.getImportDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 547 547 } 548 548 /** Constructs the absolute filename of the collection index directory, which should resemble "$GSDLHOME/collect/<col_name>/index/" 549 550 551 552 553 554 549 * @return A <strong>String</strong> containing the filename. 550 * @see org.greenstone.gatherer.Configuration 551 * @see org.greenstone.gatherer.Gatherer 552 * @see org.greenstone.gatherer.collection.Collection 553 * @see org.greenstone.gatherer.util.Utility 554 */ 555 555 public String getCollectionIndex() { 556 556 return Utility.getIndexDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 557 557 } 558 558 /** Constructs the absolute filename of the collection log directory, which should resemble "$GSDLHOME/collect/<col_name>/log/" 559 560 561 562 563 564 559 * @return A <strong>String</strong> containing the filename. 560 * @see org.greenstone.gatherer.Configuration 561 * @see org.greenstone.gatherer.Gatherer 562 * @see org.greenstone.gatherer.collection.Collection 563 * @see org.greenstone.gatherer.util.Utility 564 */ 565 565 public String getCollectionLog() { 566 566 return Utility.getLogDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 567 567 } 568 568 /** Constructs the absolute filename of the collection metadata directory, which should resemble "$GSDLHOME/collect/<col_name>/metadata/" 569 570 571 572 573 574 569 * @return A <strong>String</strong> containing the filename. 570 * @see org.greenstone.gatherer.Configuration 571 * @see org.greenstone.gatherer.Gatherer 572 * @see org.greenstone.gatherer.collection.Collection 573 * @see org.greenstone.gatherer.util.Utility 574 */ 575 575 public String getCollectionMetadata() { 576 576 return Utility.getMetadataDir(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); … … 578 578 579 579 /** This method either returns the title of the current collection, or a placeholder string of 'No Collection'. 580 581 582 580 * @return A <strong>String</strong> which represents what we wish to display for a collection title. 581 * @see org.greenstone.gatherer.collection.Collection 582 */ 583 583 public String getCollectionTitle() { 584 584 if(collection != null) { … … 683 683 } 684 684 /** This method when called, creates a new GShell in order to run the import.pl script. 685 686 687 688 689 690 691 692 693 685 * @see org.greenstone.gatherer.Configuration 686 * @see org.greenstone.gatherer.Gatherer 687 * @see org.greenstone.gatherer.Message 688 * @see org.greenstone.gatherer.gui.BuildOptions 689 * @see org.greenstone.gatherer.shell.GShell 690 * @see org.greenstone.gatherer.shell.GShellListener 691 * @see org.greenstone.gatherer.shell.GShellProgressMonitor 692 * @see org.greenstone.gatherer.util.Utility 693 */ 694 694 public void importCollection() { 695 695 Gatherer.println("CollectionManager.importCollection()"); … … 739 739 } 740 740 /** Attempts to load the given collection. Currently uses simple serialization of the collection class. 741 742 743 744 745 746 747 748 749 741 * @param location The path to the collection as a <strong>String</strong>. 742 * @see org.greenstone.gatherer.Configuration 743 * @see org.greenstone.gatherer.Gatherer 744 * @see org.greenstone.gatherer.Message 745 * @see org.greenstone.gatherer.collection.Collection 746 * @see org.greenstone.gatherer.msm.MetadataSetManager 747 * @see org.greenstone.gatherer.msm.MSMListener 748 * @see org.greenstone.gatherer.util.Utility 749 */ 750 750 public boolean loadCollection(String location) { 751 751 Gatherer.println("Load Collection '" + location + "'"); … … 908 908 } 909 909 /** This call is fired whenever a process within a GShell created by this class ends. 910 911 912 913 914 910 * @param event A <strong>GShellEvent</strong> containing information about the GShell process. 911 * @see org.greenstone.gatherer.Gatherer 912 * @see org.greenstone.gatherer.gui.GUIManager 913 * @see org.greenstone.gatherer.shell.GShell 914 */ 915 915 public synchronized void processComplete(GShellEvent event) { 916 916 Gatherer.println("CollectionManager.processComplete(" + event.getType() + ")"); … … 950 950 * @return A <i>boolean</i> which is <i>true</i> to indicate a collection has been loaded and thus the collection is ready for editing, <i>false</i> otherwise. 951 951 */ 952 953 952 public synchronized boolean ready() { 954 953 if(collection != null) { … … 959 958 } 960 959 } 961 960 962 961 public synchronized boolean reallyReady() { 963 962 // If the closing thread is non-null we should only allow that thread to see the collection as closed. … … 1012 1011 } 1013 1012 /** This method associates the collection build monitor with the build monitor created in CreatePane. 1014 1015 1013 * @param monitor A <strong>GShellProgressMonitor</strong> which we will use as the build monitor. 1014 */ 1016 1015 public void registerBuildMonitor(GShellProgressMonitor monitor) { 1017 1016 build_monitor = monitor; 1018 1017 } 1019 1018 /** This method associates the collection copy monitor with the copy monitor created in CreatePane. 1020 1021 1019 * @param monitor A <strong>GShellProgressMonitor</strong> which we will use as the copy monitor. 1020 */ 1022 1021 public void registerCopyMonitor(GShellProgressMonitor monitor) { 1023 1022 copy_monitor = monitor; 1024 1023 } 1025 1024 /** This method associates the collection import monitor with the import monitor created in CreatePane. 1026 1027 1025 * @param monitor A <strong>GShellProgressMonitor</strong> which we will use as the import monitor. 1026 */ 1028 1027 public void registerImportMonitor(GShellProgressMonitor monitor) { 1029 1028 import_monitor = monitor; 1030 1029 } 1031 1030 /** Remove a previously assigned special directory mapping. 1032 1033 1034 1031 * @param name The symbolic name of the special directory mapping to remove as a <strong>String</strong>. 1032 * @return The <strong>File</strong> of the mapping removed. 1033 */ 1035 1034 public File removeDirectoryMapping(FileNode target) { 1036 1035 File file = null; 1037 1036 if(ready()) { 1038 1037 // Remove from collection, remembering file 1039 1038 file = collection.removeDirectoryMapping(target.toString()); 1040 1039 // Update tree. 1041 1040 FileSystemModel model = (FileSystemModel) Gatherer.g_man.collection_pane.getWorkspaceTree().getModel(); 1042 1041 SynchronizedTreeModelTools.removeNodeFromParent(model, target); … … 1045 1044 } 1046 1045 /** Used to check whether all open collections have a 'saved' state. 1047 1048 1049 1046 * @return A <i>boolean</i> which is <i>true</i> if the collection has been saved. 1047 * @see org.greenstone.gatherer.collection.Collection 1048 */ 1050 1049 public boolean saved() { 1051 1050 boolean result = true; … … 1056 1055 } 1057 1056 /** Saves a collection by serializing it to file. 1058 1059 1060 1061 1062 1063 1064 1065 1057 * @param close_after <i>true</i> to cause the Gatherer to close the collection once save is complete, <i>false</i> otherwise. 1058 * @param exit_after <i>true</i> to cause the Gatherer to exit once save is complete, <i>false</i> otherwise. 1059 * @see org.greenstone.gatherer.Gatherer 1060 * @see org.greenstone.gatherer.Message 1061 * @see org.greenstone.gatherer.gui.GUIManager 1062 * @see org.greenstone.gatherer.gui.GConfigPane 1063 * @see org.greenstone.gatherer.collection.Collection 1064 */ 1066 1065 public void saveCollection(boolean close_after, boolean exit_after) { 1067 1066 Gatherer.println("Save collection: " + collection.getName()); 1068 1067 try { 1069 1068 SaveCollectionTask save_task = new SaveCollectionTask(collection, close_after, exit_after); … … 1077 1076 } 1078 1077 /** Saves the current collection to a new filename, then restores the original collection. Finally opens the collection copy. 1079 1080 1078 * @param name The name collection name. 1079 */ 1081 1080 public void saveCollectionAs(String name) { 1082 1081 // We need to do this in a separate thread so create a SaveCollectionAsTask … … 1091 1090 1092 1091 /** Method that is called whenever the metadata set collection changes in some way, such as the addition of a new set or the merging of two sets. We want to mark the collection so that it needs saving again. 1093 1094 1095 1092 * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired. 1093 * @see org.greenstone.gatherer.collection.Collection 1094 */ 1096 1095 public void setChanged(MSMEvent event) { 1097 1096 // Invalidate saved … … 1113 1112 } 1114 1113 /** Called whenever the value tree of an metadata element changes in some way, such as the addition of a new value. We want to mark the collection so that it needs saving again. 1115 1116 1117 1114 * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired. 1115 * @see org.greenstone.gatherer.collection.Collection 1116 */ 1118 1117 public void valueChanged(MSMEvent event) { 1119 1118 collection.setSaved(false); -
trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java
r5536 r5581 94 94 super(Gatherer.g_man); 95 95 close_button = new JButton(); 96 Dictionary.setText(close_button, "General.Close"); 96 close_button.setMnemonic(KeyEvent.VK_C); 97 Dictionary.setBoth(close_button, "General.Close", "General.Close_Tooltip"); 97 98 confirmation = new JCheckBox(); 98 99 Dictionary.setText(confirmation, "DeleteCollectionPrompt.Confirm_Delete"); 99 100 details = new JTextArea(); 101 details.setEditable(false); 100 102 details.setFont(Gatherer.config.getFont("general.tooltip_font", false)); 101 103 Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection"); … … 107 109 list_model = new DefaultListModel(); 108 110 ok_button = new JButton(); 109 Dictionary.setText(ok_button, "General.OK"); 111 ok_button.setMnemonic(KeyEvent.VK_D); 112 Dictionary.setBoth(ok_button, "DeleteCollectionPrompt.Delete", "DeleteCollectionPrompt.Delete_Tooltip"); 110 113 prompt = this; 111 114 setModal(true); 112 115 setSize(SIZE); 113 // setTitle();114 116 Dictionary.setText(this, "DeleteCollectionPrompt.Title"); 115 117 … … 203 205 } 204 206 } 205 206 207 207 208 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections. … … 364 365 } 365 366 } 366 367 -
trunk/gli/src/org/greenstone/gatherer/collection/Job.java
r5564 r5581 196 196 197 197 if(depth < 0) { 198 198 // Infinite recursion 199 199 command = command + "-r "; 200 200 } 201 201 else if (depth == 0) { 202 202 // Just this page. 203 203 } 204 204 else if (depth > 0) { 205 205 // Recursion to the specified depth. 206 206 command = command + "-r -l" + depth + " "; 207 207 } … … 260 260 Runtime rt = Runtime.getRuntime(); 261 261 Process prcs = rt.exec(command); 262 InputStreamReader isr = 263 new InputStreamReader( prcs.getErrorStream() ); 264 BufferedReader br = new BufferedReader( isr ); 265 // Capture the standard error stream and seach for two particular 266 // occurances. 262 InputStreamReader isr = new InputStreamReader(prcs.getErrorStream()); 263 BufferedReader br = new BufferedReader(isr); 264 // Capture the standard error stream and seach for two particular occurances. 267 265 String line; 268 266 boolean ignore_for_robots = false; … … 311 309 Gatherer.println("Already there."); 312 310 String new_url = 313 line.substring(line.indexOf("`") + 1, 314 line.lastIndexOf("'")); 311 line.substring(line.indexOf("`") + 1, line.lastIndexOf("'")); 315 312 // For some strange reason this won't compile 316 313 // src/org/greenstone/gatherer/collection/Job.java:311: cannot resolve symbol … … 340 337 } 341 338 } 342 339 // Now display final message based on exit value 343 340 prcs.waitFor(); 344 } catch (Exception ioe) { 345 //message(Utility.ERROR, ioe.toString()); 341 } 342 catch (Exception ioe) { 343 //message(Utility.ERROR, ioe.toString()); 346 344 Gatherer.printStackTrace(ioe); 347 345 } … … 396 394 397 395 if(depth < 0) { 398 396 // Infinite recursion 399 397 args.add("-r"); 400 398 } 401 399 else if (depth == 0) { 402 400 // Just this page. 403 401 } 404 402 else if (depth > 0) { 405 403 // Recursion to the specified depth. 406 404 args.add("-r"); 407 405 args.add("-l"); … … 461 459 current_url = null; 462 460 } 463 461 464 462 /** Called by the WGet native code when the requested download returns 465 463 * a status code other than 200. … … 537 535 } 538 536 } 539 540 541 542 -
trunk/gli/src/org/greenstone/gatherer/collection/SaveCollectionBox.java
r5564 r5581 70 70 // Dialog setup 71 71 this.setModal(true); 72 this.setTitle(Dictionary.newget("SaveCollectionBox.Title"));73 72 this.setSize(360,100); 73 Dictionary.setText(this, "SaveCollectionBox.Title"); 74 74 } 75 75 76 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured. In this case we see what button the users clicked, set the appropriate result then dispose of the dialog. */ 76 77 public void actionPerformed(ActionEvent event) { … … 86 87 } 87 88 } 89 88 90 /** Destructor. */ 89 91 public void destroy() { … … 96 98 rootPane = null; 97 99 } 100 98 101 /** Displays the prompt by first building the controls, then waits for a user selection. 99 102 * @param name The name of the current collection as a <strong>String</strong>. … … 131 134 Dictionary.setBoth(cancel, "General.Cancel", "General.Cancel_Tooltip"); 132 135 button_pane.add(cancel); 136 133 137 // Center on screen. 134 138 Dimension dlgSize = getSize(); … … 137 141 setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); 138 142 show(); 143 139 144 // Deallocate things we allocated here. 140 145 yes.removeKeyListener(key_listener); -
trunk/gli/src/org/greenstone/gatherer/file/FileAssociation.java
r4675 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.file; 37 38 38 39 40 41 42 43 /* GPL_HEADER */44 package org.greenstone.gatherer.file;45 39 /************************************************************************************** 46 40 * Title: Gatherer -
trunk/gli/src/org/greenstone/gatherer/file/FileJob.java
r4675 r5581 1 package org.greenstone.gatherer.file;2 1 /** 3 2 *######################################################################### … … 26 25 *######################################################################## 27 26 */ 27 package org.greenstone.gatherer.file; 28 28 29 import javax.swing.tree.*; 29 30 import org.greenstone.gatherer.file.FileNode; 30 31 import org.greenstone.gatherer.file.FileSystemModel; 31 32 import org.greenstone.gatherer.util.DragComponent; 33 32 34 /** This object encapsulates all the information about a certain file movement job. This job be to create a copy of a file from one place to another, or to simply delete a file. 33 35 * @author John Thompson … … 61 63 /** An element of the job type enumeration indicating a move action. */ 62 64 static final public byte MOVE = 3; 65 63 66 /** Constructor. 64 67 * @param id A unique identifier for this job (and others created with a single gesture) as a long. … … 82 85 if(dest != null) { 83 86 this.destination_path = new TreePath(dest.getPath()); 84 87 ///ystem.err.println("Destination Path: " + destination_path); 85 88 } 86 89 if(orig != null) { 87 90 this.origin_path = new TreePath(orig.getPath()); 88 91 ///ystem.err.println("Origin Path: " + origin_path); 89 92 } 90 93 } 94 91 95 /** Retrieve the destination node. Watch out for stale versions by always attempting to load the node at destination_path first. */ 92 96 public FileNode getDestination() { … … 97 101 destination = model.getNode(destination_path); 98 102 } 99 103 // If the above fails, a stale copy may be better than nothing. 100 104 else { 101 105 destination = (FileNode) destination_path.getLastPathComponent(); … … 104 108 return destination; 105 109 } 110 106 111 /** Retrieve the origin node. Watch out for stale versions by always attempting to load the node at origin_path first. */ 107 112 public FileNode getOrigin() { … … 112 117 origin = model.getNode(origin_path); 113 118 } 114 119 // If the above fails, a stale copy may be better than nothing. 115 120 else { 116 121 origin = (FileNode) origin_path.getLastPathComponent(); … … 119 124 return origin; 120 125 } 126 121 127 /** Retrieve the id for this job. */ 122 128 public long ID() { … … 150 156 if(destination != null) { 151 157 text.append(destination.getFile().getAbsolutePath()); 152 } 158 } 153 159 else { 154 160 text.append("Recycle Bin"); -
trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
r5564 r5581 73 73 // If source and target are different 74 74 else { 75 75 // If target is the UndoManager, we're deleting 76 76 if(target instanceof UndoManager) { 77 77 // If the source is the workspace then display an error message. Workspace is read only. … … 85 85 } 86 86 } 87 87 // Otherwise we are copying 88 88 else { 89 89 type = FileJob.COPY; -
trunk/gli/src/org/greenstone/gatherer/file/FileNode.java
r5564 r5581 392 392 } 393 393 else { 394 394 ///ystem.err.println("No file for " + this + " - can't unmap."); 395 395 } 396 396 } -
trunk/gli/src/org/greenstone/gatherer/file/FileOpenActionListener.java
r4675 r5581 1 package org.greenstone.gatherer.file;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.file; 38 38 39 import java.awt.event.*; 39 40 import java.io.*; … … 43 44 import org.greenstone.gatherer.Gatherer; 44 45 import org.greenstone.gatherer.file.FileNode; 46 45 47 /** This class listens for mouse clicks and responds to double-clicks (spawn a new application to view the selected file) and right mouse button clicks (popup menu). 46 48 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 56 58 } 57 59 /** Any subclass of MouseAdapter can override this method to respond to mouse click events. In this case we want to start an external application if someone double clicks on an appropriate file record. 58 59 60 61 62 60 * @param event A <strong>MouseEvent</strong> containing further information about the mouse click performed. 61 * @see org.greenstone.gatherer.Gatherer 62 * @see org.greenstone.gatherer.collection.FileRecord 63 * @see org.greenstone.gatherer.tree.GTree 64 */ 63 65 public void mouseClicked(MouseEvent event) { 64 66 ///ystem.err.println("Mouse clicked"); … … 80 82 } 81 83 else { 82 84 ///ystem.err.println("Caused by tree expansion / collapse. Ignoring."); 83 85 ignore = false; 84 86 } 85 87 } 86 88 /** Any implementation of TreeExpansionListener must include this method so that we can be informed when a tree node has been collapsed, thus indicating that any mouse click events about to be recieved are most likely related to this event. 87 88 89 * @param event A <strong>TreeExpansionEvent</strong> containing information about the node collapsed. 90 */ 89 91 public void treeCollapsed(TreeExpansionEvent event) { 90 92 ///ystem.err.println("Tree Collapsed"); … … 92 94 } 93 95 /** Any implementation of TreeExpansionListener must include this method so that we can be informed when a tree node has been expanded, thus indicating that any mouse click events about to be recieved are most likely related to this event. 94 95 96 * @param event A <strong>TreeExpansionEvent</strong> containing information about the node expanded. 97 */ 96 98 public void treeExpanded(TreeExpansionEvent event) { 97 99 ///ystem.err.println("Tree Expanded"); -
trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
r5564 r5581 96 96 97 97 /** Requeue an existing job into the queue. 98 99 98 * @param job A previously created FileJob. 99 */ 100 100 synchronized public void addJob(FileJob job, int position) { 101 101 job.done = true; // Ensure that the requeued job is marked as done. … … 647 647 } 648 648 selection = null; 649 String args[] = new String[2];650 args[0] = "" + file_count + "";651 args[1] = "" + dir_count + "";652 // job_status.setText(get("Selected", args));653 args = null;649 // String args[] = new String[2]; 650 // args[0] = "" + file_count + ""; 651 // args[1] = "" + dir_count + ""; 652 // job_status.setText(get("Selected", args)); 653 // args = null; 654 654 } 655 655 tree = null; … … 661 661 662 662 /** Copy a file from the source location to the destination location. 663 664 665 666 663 * @param source The source File. 664 * @param destination The destination File. 665 * @see org.greenstone.gatherer.Gatherer 666 */ 667 667 public void copyFile(File source, File destination, LongProgressBar progress) 668 668 throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, UnknownFileErrorException, WriteNotPermittedException { … … 671 671 } 672 672 else { 673 673 // Check if the origin file exists. 674 674 if(!source.exists()) { 675 675 System.err.println("Couldn't find the source file."); 676 676 throw(new FileNotFoundException()); 677 677 } 678 678 // Check if the destination file does not exist. 679 679 if(destination.exists()) { 680 680 throw(new FileAlreadyExistsException()); … … 682 682 File dirs = destination.getParentFile(); 683 683 dirs.mkdirs(); 684 684 // Copy the file. 685 685 FileInputStream f_in = new FileInputStream(source); 686 686 FileOutputStream f_out = null; -
trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
r5571 r5581 53 53 import org.greenstone.gatherer.collection.Collection; 54 54 import org.greenstone.gatherer.collection.DeleteCollectionPrompt; 55 import org.greenstone.gatherer.collection.LoadCollectionBox;56 55 import org.greenstone.gatherer.collection.SaveCollectionBox; 57 56 import org.greenstone.gatherer.file.FileNode; … … 618 617 // Wait until it is closed. 619 618 try { 620 619 synchronized(this) { 621 620 while(Gatherer.c_man.reallyReady()) { 622 621 wait(10); 623 622 } 624 623 } 625 624 } 626 625 catch(Exception error) { -
trunk/gli/src/org/greenstone/gatherer/help/HelpFrame.java
r5525 r5581 35 35 *######################################################################## 36 36 */ 37 38 37 package org.greenstone.gatherer.help; 39 38 40 /**41 * @author Michael Dewsnip, NZDL Project42 */43 39 import calpa.html.*; 44 import java.awt.BorderLayout; 45 import java.awt.Dimension; 46 import java.awt.Toolkit; 47 import java.io.File; 48 import java.net.URL; 49 import java.util.Enumeration; 50 import javax.swing.JFrame; 51 import javax.swing.JPanel; 52 import javax.swing.JScrollPane; 53 import javax.swing.JSplitPane; 54 import javax.swing.JTree; 55 import javax.swing.event.TreeSelectionEvent; 56 import javax.swing.event.TreeSelectionListener; 57 import javax.swing.tree.DefaultTreeModel; 58 import javax.swing.tree.DefaultMutableTreeNode; 59 import javax.swing.tree.MutableTreeNode; 60 import javax.swing.tree.TreePath; 40 import java.awt.*; 41 import java.io.*; 42 import java.net.*; 43 import java.util.*; 44 import javax.swing.*; 45 import javax.swing.event.*; 46 import javax.swing.tree.*; 61 47 import org.apache.xerces.parsers.DOMParser; 48 import org.greenstone.gatherer.Dictionary; 62 49 import org.greenstone.gatherer.util.Utility; 63 50 import org.w3c.dom.*; 64 65 51 66 52 /** 67 53 * This class provides a nice help facility. It is a separate frame that can be positioned 68 54 * as the user wishes, and provides a contents page and the help information. 55 * @author Michael Dewsnip, NZDL Project 69 56 */ 70 57 public class HelpFrame … … 91 78 view = new CalHTMLPane(new CalHTMLPreferences(), new Observer(), "Help Pages"); 92 79 93 HelpItem rootNode = new HelpItem( "Contents", "<null>");80 HelpItem rootNode = new HelpItem(Dictionary.newget("Help.Contents"), "<null>"); 94 81 model = new ContentsModel(rootNode); 95 82 contents = new JTree((DefaultTreeModel) model); -
trunk/gli/src/org/greenstone/gatherer/msm/Declarations.java
r4674 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.msm; 37 38 38 39 40 41 42 43 /* GPL_HEADER */44 package org.greenstone.gatherer.msm;45 39 /************************************************************************************** 46 40 * Title: Gatherer -
trunk/gli/src/org/greenstone/gatherer/msm/ElementWrapper.java
r5154 r5581 36 36 */ 37 37 package org.greenstone.gatherer.msm; 38 38 39 /************************************************************************************** 39 40 * Title: Gatherer … … 47 48 import org.greenstone.gatherer.util.StaticStrings; 48 49 import org.greenstone.gatherer.util.Utility; 49 import org.w3c.dom. Element;50 import org.w3c.dom.Node; 50 import org.w3c.dom.*; 51 51 52 /** This class provides a convience wrapper around a DOM model Element to allow Components such as the MetadataTable to display this information properly. 52 53 * @author John Thompson … … 61 62 /** Constructor for elements with no namespace necessary. 62 63 * @param element The DOM <strong>Element</strong> this is to be based on. 63 64 */ 64 65 public ElementWrapper(Element element) { 65 66 this.element = element; … … 70 71 71 72 } 72 /** Constructor.73 * @param element The DOM <strong>Element</strong> this is to be based on.74 75 * @param namespace_required <i>true</i> if this element wrapper should always attempt to show a namespace prefix (retrieving it from the DOM if necessary).76 * @deprecated77 */78 // public ElementWrapper(Element element, boolean namespace_required) {79 //this(element);80 // }81 73 82 74 public void addAttribute(String name, String value) { … … 89 81 90 82 /** Create a copy of this element wrapper. 91 92 83 * @return A new <strong>ElementWrapper</strong> based on the same element as this one. 84 */ 93 85 public ElementWrapper copy() { 94 86 Element element_copy = (Element) element.cloneNode(true); … … 96 88 } 97 89 /** Compare two element wrappers for ordering. 98 99 100 90 * @param object An <strong>Object</strong> which is most likely another element wrapper to be compared with. 91 * @return An <i>int</i> indicating order, -1, 0, 1 if this element wrapper is less than, equal to or greater than the given object. 92 */ 101 93 public int compareTo(Object object) { 102 94 return toString().compareTo(object.toString()); 103 95 } 104 96 /** Decrement the number of occurances of this metadata element. 105 106 97 * @see org.greenstone.gatherer.msm.MSMUtils 98 */ 107 99 public void dec() { 108 100 MSMUtils.setOccurance(element, -1); 109 101 } 110 102 /** Test if two ElementWrappers are equal. 111 112 103 * @param object The <strong>Object</strong> to test against. 104 */ 113 105 public boolean equals(Object object) { 114 106 if(object instanceof ElementWrapper) { … … 120 112 } 121 113 /** Retrieve the attributes associated with the element this element wrapper is built around. 122 123 124 114 * @return A <strong>TreeSet</strong> of the attributes. 115 * @see org.greenstone.gatherer.msm.MSMUtils 116 */ 125 117 public TreeSet getAttributes() { 126 118 return MSMUtils.getAttributes(element); 127 119 } 128 120 /** Retrieve the element this is wrapped around. 129 130 121 * @return A DOM <strong>Element</strong> which represents a metadata element. 122 */ 131 123 public Element getElement() { 132 124 return element; 133 125 } 134 126 /** Retrieve the identity of this element (not necessary the same as this elements name). Identity is language and locale dependant. 135 136 137 127 * @return The identity as a <strong>String</strong>. 128 * @see org.greenstone.gatherer.msm.MSMUtils 129 */ 138 130 public String getIdentity() { 139 131 return MSMUtils.getIdentifier(element); 140 132 } 141 133 /** Retrieve the name of this element. Name is unique. 142 143 144 134 * @return The name as a <strong>String</strong>. 135 * @see org.greenstone.gatherer.msm.MSMUtils 136 */ 145 137 public String getName() { 146 138 return MSMUtils.getFullName(element, namespace); 147 139 } 148 140 /** Retrieve the namespace prefix for this element wrapper. 149 150 151 141 * @return A <strong>String</strong> containing the namespace or "" if there is no namespace for this element. 142 * @see org.greenstone.gatherer.msm.MSMUtils 143 */ 152 144 public String getNamespace() { 153 145 if (!namespace.equals("")) { … … 164 156 } 165 157 /** Look for the occurances 'field' of the element and return it if found. 166 167 168 158 * @return An <i>int</i> which matches the number in the occurances attribute of the element, or 0 if no such attribute. 159 * @see org.greenstone.gatherer.msm.MSMUtils 160 */ 169 161 public int getOccurances() { 170 162 return MSMUtils.getOccurances(element); 171 163 } 172 164 /** This method is essentially the same as getDescription() in that it does indeed return this metaelements description. However this method uses the Utility function formatHTMLWidth() to ensure the String can be displayed in a tool-tip window using html markup. 173 174 175 176 165 * @return A String containing the HTML formatted versions of definition and content (comment). 166 * @see org.greenstone.gatherer.msm.MSMUtils 167 * @see org.greenstone.gatherer.util.Utility 168 */ 177 169 public String getToolTip() { 178 170 // Add HTML formatting … … 194 186 return element.getAttribute(StaticStrings.HIERARCHY_ATTRIBUTE).equalsIgnoreCase(StaticStrings.TRUE_STR); 195 187 } 196 197 188 198 189 /** Removes an Attribute node from the element. */ … … 217 208 } 218 209 219 220 /** Set the value of the namespace required flag.221 * @param namespace_required The new value as a <i>boolean</i>.222 * @see org.greenstone.gatherer.msm.MSMUtils223 * @deprecated224 */225 public void setNamespaceRequired(boolean namespace_required) {226 }227 210 public String toString() { 228 211 return MSMUtils.getFullIdentifier(element, namespace); -
trunk/gli/src/org/greenstone/gatherer/msm/ExistingMetadataLoader.java
r4674 r5581 1 package org.greenstone.gatherer.msm;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.msm; 38 38 39 import java.io.*; 39 40 import java.util.*; -
trunk/gli/src/org/greenstone/gatherer/msm/ExportMDSPrompt.java
r5564 r5581 101 101 if(export) { 102 102 setSize(EXPORT_SIZE); 103 setJMenuBar(new SimpleMenuBar("selectingmetadatasets")); 103 104 Dictionary.setText(this, "MSMPrompt.Export_Title"); 105 } 106 else { 107 setSize(IMPORT_SIZE); 104 108 setJMenuBar(new SimpleMenuBar("selectingmetadatasets")); 105 }106 else {107 setSize(IMPORT_SIZE);108 109 Dictionary.setText(this, "MSMPrompt.Import_Title"); 109 setJMenuBar(new SimpleMenuBar("selectingmetadatasets"));110 110 } 111 111 JPanel content_pane = (JPanel) getContentPane(); -
trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java
r5164 r5581 49 49 import org.greenstone.gatherer.util.HashMap3D; 50 50 import org.greenstone.gatherer.util.Utility; 51 import org.greenstone.gatherer.valuetree.GValueModel; 52 import org.greenstone.gatherer.valuetree.GValueNode; 51 // import org.greenstone.gatherer.valuetree.GValueNode; 53 52 import org.w3c.dom.*; 54 53 /** This object manages the metadata attached to file records. By storing all of the metadata in one place you garner several advantages. Firstly only one copy of each metadata object is retained, all actual entries are converted to references. Next you can immediately determine what metadata is assigned to an entire directory, thus the metadata.xml files can be built more effeciently (whereas the current 'optimal' method uses recursion through the tree contents). Finally, and perhaps most importantly, it allows for dynamic 'on demand' lookup of metadata. This is especially necessary with large collections, where the raw, unconnected metadata files could range into the tens of megabytes of memory and require hundreds of megabytes to read by in using serialization. Dynamic loading allows you to connect the metadata objects on load, reducing value node paths (possibly of hundreds of characters) down to a single reference pointer! At the very worst this object uses far less memory than the current method, and given that the current method is completely incapable of handling large collections, is necessary. The trade off of course is in time needed to load metadata.xml on demand, the worst possible case being the user selecting the root node of the collection tree of a large collection immediately after opening the collection. The subsequent attempt to build the metadata table will result in the metadata being loaded for every single file. But since this process is sequential and a small cache of metadata.xml files is implemented, and given that the table will actually be build on a separate thread, the wait should not be too arduous.<BR> -
trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java
r5564 r5581 185 185 public ElementWrapper addElement(String name) { 186 186 Text text = document.createTextNode(name); 187 Element identifier = document.createElementNS("","Attribute");188 identifier.setAttribute("name","identifier");189 identifier.appendChild(text);190 Element element = document.createElementNS("","Element");191 element.setAttribute("name",name);192 element.appendChild(identifier);193 root.appendChild(element);194 ElementWrapper wrapper = new ElementWrapper(element);195 ///ystem.err.println("Added a new element " + wrapper);196 return wrapper;187 Element identifier = document.createElementNS("","Attribute"); 188 identifier.setAttribute("name","identifier"); 189 identifier.appendChild(text); 190 Element element = document.createElementNS("","Element"); 191 element.setAttribute("name",name); 192 element.appendChild(identifier); 193 root.appendChild(element); 194 ElementWrapper wrapper = new ElementWrapper(element); 195 ///ystem.err.println("Added a new element " + wrapper); 196 return wrapper; 197 197 } 198 198 -
trunk/gli/src/org/greenstone/gatherer/msm/parsers/GreenstoneMetadataParser.java
r5153 r5581 46 46 import org.greenstone.gatherer.msm.MetadataParser; 47 47 import org.greenstone.gatherer.msm.MSMUtils; 48 import org.greenstone.gatherer.util.DecodeHTMLReader;49 48 import org.greenstone.gatherer.util.StaticStrings; 50 49 import org.greenstone.gatherer.util.Utility; … … 827 826 try { 828 827 FileReader in_filereader = new FileReader((File)target); 829 //DecodeHTMLReader in_decodehtmlreader = new DecodeHTMLReader(in_filereader);830 828 BufferedReader in = new BufferedReader(in_filereader); 831 829 String line = null; … … 851 849 in.close(); 852 850 in = null; 853 //in_decodehtmlreader = null;854 851 in_filereader = null; 855 852 hfiles.put(element, result); -
trunk/gli/src/org/greenstone/gatherer/shell/GBasicProgressMonitor.java
r5034 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.shell; 37 38 38 39 40 41 42 43 package org.greenstone.gatherer.shell;44 39 /** Title: The Gatherer<br> 45 40 * Description: The Gatherer: a tool for gathering and enriching digital collections.<br> … … 51 46 * @author John Thompson, Greenstone Digital Libraries 52 47 * @version 2.1 */ 48 53 49 import java.awt.Component; 54 import javax.swing.ImageIcon;55 import javax.swing.JLabel;56 50 import javax.swing.JProgressBar; 57 51 import org.greenstone.gatherer.shell.GShellProgressMonitor; 58 import org.greenstone.gatherer.util.Utility; 52 59 53 /** This is the most basic implementation of <i>GShellProgressMonitor</i> in that it doesn't even attempt to parse the process messages. Instead it has one graphic which is displayed once the start() method is called, and another which appears after the stop(). 60 54 */ … … 67 61 public GBasicProgressMonitor() { 68 62 super(); 69 //this.setIcon(ready);70 63 } 71 64 /** Don't do anything if we are given a progress bar, we have our own. 72 73 65 * @param progress_bar A JProgressBar 66 */ 74 67 public void addProgressBar(JProgressBar progress_bar) { 75 68 } 76 69 /** 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. 77 78 70 * @return A <i>int</i> with a value of zero if and only if the script was successful. 71 */ 79 72 public int exitValue() { 80 73 // Always return true as we don't know any better. … … 82 75 } 83 76 /** As we are probably accessing this via an interface we need to gain 84 85 77 * access to the component itself. 78 */ 86 79 public Component getProgress() { 87 80 return this; 88 81 } 89 82 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 90 91 83 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 84 */ 92 85 public boolean hasSignalledStop() { 93 86 return stop; … … 98 91 } 99 92 /** The parse method is how more complex progress bars figure out how far they have progressed. However we don't. 100 101 102 93 * @param line A String representing the latest line of output from 94 * the external process we are monitoring. 95 */ 103 96 public void parse(String line) { 104 97 } … … 108 101 109 102 /** 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. 110 111 103 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 104 */ 112 105 public void setStop(boolean state) { 113 106 stop = state; 114 107 } 115 108 /** This method tells this class that the job it is showing the progress 116 117 109 * for has begun. 110 */ 118 111 public void start() { 119 //this.setIcon(busy);120 112 setIndeterminate(true); 121 113 } 122 114 /** This method tells this class that the job it is showing the progress 123 124 115 * for has come to an end. 116 */ 125 117 public void stop() { 126 //this.setIcon(ready);127 118 setIndeterminate(false); 128 119 } -
trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java
r5034 r5581 1 package org.greenstone.gatherer.shell;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.shell; 38 38 39 import java.awt.Component; 39 40 import javax.swing.JProgressBar; … … 58 59 private int state = 0; 59 60 60 61 /** The progress bar this monitor updates. */ 61 62 private JProgressBar progress_bar; 62 63 … … 106 107 107 108 /** Method to register a new progress bar with this monitor. 108 109 109 * @param progress_bar The new <strong>JProgressBar</strong>. 110 */ 110 111 public void addProgressBar(JProgressBar progress_bar) { 111 112 this.progress_bar = progress_bar; … … 114 115 progress_bar.setValue(MIN); 115 116 } 117 116 118 /** 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 118 119 * @return A <i>int</i> with a value of zero if and only if the script was successful. 120 */ 119 121 public int exitValue() { 120 122 if(state == BASE) { … … 124 126 } 125 127 /** 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 127 128 * @return A <strong>Component</strong> on which the progress of the process is being displayed. 129 */ 128 130 public Component getProgress() { 129 131 return progress_bar; 130 132 } 131 133 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 132 133 134 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. 135 */ 134 136 public boolean hasSignalledStop() { 135 137 return stop; … … 141 143 142 144 /** This method is used to 'feed in' a line of text captured from the process. 143 144 145 * @param line A <strong>String</strong> of text captured from either standard out or standard error. 146 */ 145 147 public void parse(String raw_line) { 146 148 String line = raw_line.toLowerCase(); … … 289 291 } 290 292 else { 291 292 293 ///ystem.err.println("Number of documents = " + num_docs); 294 ///ystem.err.println("Number of indexes = " + num_indexes); 293 295 progress_bar.setIndeterminate(true); 294 296 } … … 308 310 309 311 /** 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. 310 311 312 * @param state The desired state of the stop flag as a <strong>boolean</strong>. 313 */ 312 314 public void setStop(boolean state) { 313 315 stop = state; … … 315 317 } 316 318 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 317 318 319 * TODO Everthing. 320 */ 319 321 public void start() { 320 322 progress_bar.setValue(MIN); … … 323 325 } 324 326 /** This method indicates the process is complete. 325 326 327 * TODO Everthing. 328 */ 327 329 public void stop() { 328 330 progress_bar.setIndeterminate(false); -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r5564 r5581 46 46 import org.greenstone.gatherer.shell.GShellListener; 47 47 import org.greenstone.gatherer.shell.GShellProgressMonitor; 48 import org.greenstone.gatherer.util.StaticStrings; 48 49 49 /** The <strong>GShell</strong> is reponsible for running a separately threaded process in the command shell. This is necessary for executing the Perl Scripts and also for other system related funcitonality. 50 50 */ … … 179 179 if(stdinline != null) { 180 180 fireMessage(type, typeAsString(type) + "> " + stdinline, status); 181 182 181 } 183 182 } … … 190 189 status = OK; 191 190 fireMessage(type, typeAsString(type) + "> " + Dictionary.newget("GShell.Success"), status); 192 193 }else {191 } 192 else { 194 193 status = ERROR; 195 194 fireMessage(type, typeAsString(type) + "> " + Dictionary.newget("GShell.Failure"), status); 196 197 195 } 198 196 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShellEvent.java
r4364 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.shell; 37 38 38 39 40 41 42 43 package org.greenstone.gatherer.shell;44 39 /** Title: The Gatherer<br> 45 40 * Description: The Gatherer: a tool for gathering and enriching digital collections.<br> … … 52 47 * @version 2.1 */ 53 48 import java.awt.AWTEvent; 49 54 50 /** This class encapsulates all the information created by an event within a <strong>GShell</strong> process. */ 55 51 public class GShellEvent … … 61 57 /** Any message associated with this event. */ 62 58 private String message = null; 59 63 60 /* Constructor. 64 61 * @param source The <strong>GShell</strong> that fired this message. … … 67 64 * @param message A <strong>String</strong> representing any message attatched with this event. 68 65 * @param status The status of the process post event, as an <strong>int</strong>. 69 */ 70 public GShellEvent(Object source, int id, int type, String message, 71 int status) { 66 */ 67 public GShellEvent(Object source, int id, int type, String message, int status) { 72 68 super(source, id); 73 69 this.message = message; … … 75 71 this.type = type; 76 72 } 73 77 74 /** Gets the message associated with this event. 78 79 75 * @return The message as a <strong>String</strong> or <i>null</i>. 76 */ 80 77 public String getMessage() { 81 78 return message; 82 79 } 80 83 81 /** Gets the status associated with this event. This status can then be matched back to the constants in <strong>GShell</strong>. 84 85 82 * @return An <strong>int</strong> signifying the process status. 83 */ 86 84 public int getStatus() { 87 85 return status; 88 86 } 87 89 88 /** Gets the type associated with this event. This type can then be matched back to the constants in <strong>GShell</strong>. 90 91 89 * @return An <strong>int</strong> signifying the process type. 90 */ 92 91 public int getType() { 93 92 return type; -
trunk/gli/src/org/greenstone/gatherer/shell/GShellListener.java
r5571 r5581 49 49 */ 50 50 import java.util.EventListener; 51 51 52 /** This interface details the methods required of a class that wishes to listen to a <strong>GShell</strong>. 52 53 */ … … 55 56 /** All implementation of <i>GShellListener</i> must include this method so the listener can be informed of messages from the <strong>GShell</strong>. 56 57 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message. 57 58 */ 58 59 public void message(GShellEvent event); 60 59 61 /** All implementation of <i>GShellListener</i> must include this method so the listener can be informed when a <strong>GShell</strong> begins its task. 60 61 62 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement. 63 */ 62 64 public void processBegun(GShellEvent event); 65 63 66 /** All implementation of <i>GShellListener</i> must include this method so the listener can be informed when a <strong>GShell</strong> completes its task. 64 65 67 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion. 68 */ 66 69 public void processComplete(GShellEvent event); 67 70 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java
r5034 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.shell; 37 38 38 39 40 41 42 43 package org.greenstone.gatherer.shell;44 39 /** 45 40 * Title: The Gatherer<br> … … 55 50 import java.awt.Component; 56 51 import javax.swing.JProgressBar; 52 57 53 /** When implemented, this interface allows another class to monitor the progress of a <strong>GShell</strong> process. Specifically implementing classes should be designed to take the textual output from the process and then translate that message into some quanitive measure of progress which can then be shown on the progress bar. 58 54 */ … … 62 58 */ 63 59 public void addProgressBar(JProgressBar progress_bar); 60 64 61 /** 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. 65 62 * @return A <i>int</i> with a value of zero if and only if the script was successful. 66 63 */ 67 64 public int exitValue(); 65 68 66 /** 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 67 * @return A <strong>Component</strong> on which the progress of the process is being displayed. 70 68 */ 71 69 public Component getProgress(); 70 72 71 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor. 73 72 * @return A <strong>boolean</strong> indicating if the process has been asked to stop. … … 77 76 /** Inform the progress bar that it should programatically increment progress by one step. */ 78 77 public void increment(); 78 79 79 /** This method is used to 'feed in' a line of text captured from the process. 80 80 * @param line A <strong>String</strong> of text captured from either standard out or standard error. … … 88 88 */ 89 89 public void setStop(boolean state); 90 90 91 /** This method resets this monitor to the start, reseting the process parsing and progress bar. 91 92 */ 92 93 public void start(); 94 93 95 /** This method indicates the process is complete. 94 96 */ -
trunk/gli/src/org/greenstone/gatherer/undo/UndoManager.java
r4686 r5581 1 package org.greenstone.gatherer.undo;2 1 /** 3 2 *######################################################################### … … 36 35 *######################################################################## 37 36 */ 37 package org.greenstone.gatherer.undo; 38 38 39 import java.awt.*; 39 40 import java.awt.datatransfer.Transferable; … … 119 120 UndoJob undo_job = undo.pop(); 120 121 undo_job.action(true, file_queue); 121 122 // Now retrieve all other undo jobs with the same job-number and action them 122 123 while((undo_job = undo.getJob(undo_job.ID())) != null) { 123 124 undo_job.action(true, file_queue); … … 128 129 UndoJob redo_job = redo.pop(); 129 130 redo_job.action(false, file_queue); 130 131 // Now retrieve all other redo jobs with the same job-number and action them 131 132 while((redo_job = redo.getJob(redo_job.ID())) != null) { 132 133 redo_job.action(false, file_queue); … … 138 139 for(int i = 0; metadatum != null && i < metadatum.size(); i++) { 139 140 Metadata metadata = (Metadata) metadatum.get(i); 140 141 ///ystem.err.println("UndoMetadata: " + file.getAbsolutePath() + " => " + metadata); 141 142 String file_path = file.getAbsolutePath().replace('\\', '/'); 142 143 obsolete_metadata.addMetadata(file_path, metadata); … … 203 204 pt_last = pt; 204 205 if(!DragSource.isDragImageSupported()) { 205 206 // Erase the last ghost image and or cue line 206 207 paintImmediately(ra_ghost.getBounds()); 207 208 // Remember where you are about to draw the new ghost image 208 209 ra_ghost.setRect(pt.x - group.mouse_offset.x, pt.y - group.mouse_offset.y, group.image_ghost.getWidth(), group.image_ghost.getHeight()); 209 210 // Draw the ghost image 210 211 g2.drawImage(group.image_ghost, AffineTransform.getTranslateInstance(ra_ghost.getX(), ra_ghost.getY()), null); 211 212 } … … 226 227 source_nodes[i] = (FileNode) selection[i].getLastPathComponent(); 227 228 } 228 229 ///ystem.err.println("Dropped files vector contains " + new_files.size() + " files."); 229 230 event.acceptDrop(drag_action); 230 231 // Action delete 231 232 Gatherer.f_man.action(source, source_nodes, this, null); 232 233 group.setSource(null); … … 251 252 UndoJob job = new UndoJob(id, null, null, target_model, record, FILE_COPY); 252 253 if(undo_event) { 253 254 ///ystem.err.println("Add undo job"); 254 255 undo.push(job); 255 256 } 256 257 else { 257 258 ///ystem.err.println("Add redo job"); 258 259 redo.push(job); 259 260 } … … 263 264 UndoJob job = new UndoJob(id, source_model, source_parent, this, record, FILE_DELETE); 264 265 if(undo_event) { 265 266 ///ystem.err.println("Add undo job"); 266 267 undo.push(job); 267 268 } 268 269 else { 269 270 ///ystem.err.println("Add redo job"); 270 271 redo.push(job); 271 272 } … … 276 277 UndoJob job = new UndoJob(id, source_model, source_parent, target_model, record, FILE_MOVE); 277 278 if(undo_event) { 278 279 ///ystem.err.println("Add undo job"); 279 280 undo.push(job); 280 281 } 281 282 else { 282 283 ///ystem.err.println("Add redo job"); 283 284 redo.push(job); 284 285 } … … 330 331 while((undo_job = undo.pop()) != null) { 331 332 undo_job.action(true, immediate_queue); 332 333 // Now retrieve all other undo jobs with the same job-number and action them 333 334 while((undo_job = undo.getJob(undo_job.ID())) != null) { 334 335 undo_job.action(true, immediate_queue); … … 394 395 395 396 public void action(boolean is_undo, FileQueue file_queue) { 396 397 // Retrieve the lastest version of each file record 397 398 FileNode latest_record = null; 398 399 FileNode latest_source_parent = null; … … 405 406 latest_source_parent = ((FileSystemModel)source_model.getTreeModel()).getNode(source_parent_path); 406 407 } 407 408 // Of course if there are no newer versions, stick to the ones we've already got. 408 409 if(latest_record == null) { 409 410 ///ystem.err.println("Using original record."); -
trunk/gli/src/org/greenstone/gatherer/util/ApplyXSLT.java
r5564 r5581 20 20 package org.greenstone.gatherer.util; 21 21 22 // General Java classes 23 import java.io.StringReader; 24 import java.io.StringWriter; 25 import java.io.File; 26 27 // XML classes 22 import java.io.*; 28 23 import javax.xml.transform.Transformer; 29 24 import javax.xml.transform.TransformerFactory; … … 72 67 } 73 68 } 74 75 -
trunk/gli/src/org/greenstone/gatherer/util/ArrayTools.java
r4388 r5581 1 1 /* GPL_HEADER */ 2 2 package org.greenstone.gatherer.util; 3 3 4 /************************************************************************************** 4 5 * Title: Gatherer … … 15 16 import org.greenstone.gatherer.msm.Metadata; 16 17 import org.w3c.dom.*; 18 17 19 /** This utility class contains a series of static methods for common array type manipulations including appending, casting and changing between containers. 18 20 * @author John Thompson -
trunk/gli/src/org/greenstone/gatherer/util/DefaultSynchronizedTreeNode.java
r4674 r5581 6 6 7 7 public class DefaultSynchronizedTreeNode 8 9 8 extends DefaultMutableTreeNode 9 implements SynchronizedTreeNode { 10 10 11 11 private String text = null; 12 12 13 DefaultSynchronizedTreeNode(Object userObject) { 14 super(userObject); 13 DefaultSynchronizedTreeNode(Object userObject) { 14 super(userObject); 15 } 16 17 public SynchronizedTreeNode cloneNode() { 18 // Create new node with same userObject 19 SynchronizedTreeNode new_node = new DefaultSynchronizedTreeNode(userObject); 20 // Clone and add children. 21 for(int i = 0; i < getChildCount(); i++) { 22 SynchronizedTreeNode child = (SynchronizedTreeNode) getChildAt(i); 23 new_node.insert(child.cloneNode(), i); 15 24 } 25 return new_node; 26 } 16 27 17 public SynchronizedTreeNode cloneNode() { 18 // Create new node with same userObject 19 SynchronizedTreeNode new_node = new DefaultSynchronizedTreeNode(userObject); 20 // Clone and add children. 21 for(int i = 0; i < getChildCount(); i++) { 22 SynchronizedTreeNode child = (SynchronizedTreeNode) getChildAt(i); 23 new_node.insert(child.cloneNode(), i); 24 } 25 return new_node; 28 public int compareTo(Object other) { 29 if(text == null) { 30 text = userObject.toString(); 26 31 } 32 return text.compareTo(other.toString()); 33 } 27 34 28 public int compareTo(Object other) { 29 if(text == null) { 30 text = userObject.toString(); 31 } 32 return text.compareTo(other.toString()); 35 public boolean equals(Object other) { 36 if(text == null) { 37 text = userObject.toString(); 33 38 } 39 return text.equals(other.toString()); 40 } 34 41 35 public boolean equals(Object other) { 36 if(text == null) { 37 text = userObject.toString(); 38 } 39 return text.equals(other.toString()); 42 public String toString() { 43 if(text == null) { 44 text = userObject.toString(); 40 45 } 41 42 public String toString() { 43 if(text == null) { 44 text = userObject.toString(); 45 } 46 return text; 47 } 46 return text; 47 } 48 48 } -
trunk/gli/src/org/greenstone/gatherer/util/DragGroup.java
r4686 r5581 79 79 80 80 /** Register a DragComponent as begin part of this group. 81 82 81 * @param component The DragComponent to add. 82 */ 83 83 public void add(DragComponent component) { 84 84 if(!registered.contains(component)) { … … 99 99 } 100 100 /** Determines the current 'active' component, ie that component with focus. 101 102 101 * @return The DragComponent which is currently responsible for drawing the ghost, and thus is active. 102 */ 103 103 public DragComponent getActive() { 104 104 return ghost_owner; 105 105 } 106 106 /** Retrieve the nodes selected at the beginning of this drag operation. 107 108 107 * @return A TreePath[]. 108 */ 109 109 public TreePath[] getSelection() { 110 110 return selection; 111 111 } 112 112 /** Retrieve the component which served as the source of this drag action. 113 114 113 * @return The DragComponent in question. 114 */ 115 115 public DragTree getSource() { 116 116 return drag_source; 117 117 } 118 118 /** When called this method asserts that one of the registered GComponents just became the proud owner of focus, and is henceforth responsible for drawing the ghost, and acting like a component thats in focus. 119 120 119 * @param new_owner The DragComponent that has gained focus during a drag action. 120 */ 121 121 public void grabFocus(DragComponent new_owner) { 122 122 // Tell the previous owner of ghost to clear itself. … … 138 138 } 139 139 /** Sets the value of selected_nodes. 140 141 140 * @param selection The new value for selected_nodes as a TreePath[]. 141 */ 142 142 public void setSelection(TreePath[] selection) { 143 143 this.selection = selection; 144 144 } 145 145 /** Sets the value of drag_source. 146 147 146 * @param drag_source The new value for drag_source as a DragTree. 147 */ 148 148 public void setSource(DragTree drag_source) { 149 149 this.drag_source = drag_source; -
trunk/gli/src/org/greenstone/gatherer/util/ExclusiveListSelectionListener.java
r4674 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.util; 37 38 38 39 40 41 42 43 /* GPL_HEADER */44 package org.greenstone.gatherer.util;45 39 /************************************************************************************** 46 40 * Title: Gatherer … … 65 59 /** Method to register a new JList with this listener. 66 60 * @param list The new <strong>JList</strong> to register. 67 61 */ 68 62 public void add(JList list) { 69 63 list.addListSelectionListener(this); … … 80 74 } 81 75 /** Any implementation of ListSelectionListener must include this method so we can be informed when the selection changes. In this case we want to clear the selections of all other registered JLists other than the caller. 82 83 76 * @param event A <strong>ListSelectionEvent</strong> containing informaiton about the event. 77 */ 84 78 public void valueChanged(ListSelectionEvent event) { 85 79 if(!ignore) { -
trunk/gli/src/org/greenstone/gatherer/util/GURL.java
r5326 r5581 35 35 *######################################################################## 36 36 */ 37 38 39 40 41 42 43 37 package org.greenstone.gatherer.util; 44 38 45 import java.io.File; 46 import java.io.Serializable; 47 48 import java.lang.Cloneable; 49 50 import java.net.MalformedURLException; 51 import java.net.URL; 52 53 import java.util.Vector; 54 55 import javax.swing.JProgressBar; 39 import java.io.*; 40 import java.lang.*; 41 import java.net.*; 42 import java.util.*; 56 43 57 44 /** … … 110 97 } 111 98 catch (MalformedURLException e) { 112 99 // Fix it 113 100 } 114 101 } … … 176 163 private String parseFile(String raw) { 177 164 if(raw != null && !raw.equals("")) { 178 165 // Remove everything upto and including the last '/' 179 166 if(raw.indexOf("/") != -1) { 180 167 return raw.substring(raw.lastIndexOf("/") + 1); … … 186 173 private String parsePath(String raw) { 187 174 if(raw != null && !raw.equals("")) { 188 175 // Remove everything after the last "/" 189 176 if(raw.indexOf("/") != -1) { 190 177 return raw.substring(0, raw.lastIndexOf("/")); -
trunk/gli/src/org/greenstone/gatherer/util/HTMLStringTokenizer.java
r4674 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.util; 37 38 38 39 40 41 42 43 package org.greenstone.gatherer.util;44 39 /** 45 40 * Title: The Gatherer<br> … … 50 45 * @version 2.1 51 46 */ 52 import java.util.Stack;53 47 import org.greenstone.gatherer.util.Utility; 48 54 49 /** This class functions much like a <strong>StringTokenizer</strong> in that it tokenizes a long string into tokens, however this tokenizer cleverly notices HTML formatting tags. */ 55 50 public class HTMLStringTokenizer { … … 64 59 /** Constructor. 65 60 * @param source The source <strong>String</strong> to be tokenized. 66 61 */ 67 62 public HTMLStringTokenizer(String source) { 68 63 this.source = source; … … 71 66 } 72 67 /** Determines if there are still tokens remaining unparsed in the source. 73 74 68 * @return A <strong>boolean</strong> which is <i>true</i> if there are more tokens. 69 */ 75 70 public boolean hasMoreTokens() { 76 71 if(current != null && current.length() > 0) { … … 80 75 } 81 76 /** Determines if the tag currently being returned by sameToken is a tag. 82 83 77 * @return A <strong>boolean</strong> indicating if the token is a tag. 78 */ 84 79 public boolean isTag() { 85 80 if(previous.startsWith("<") && previous.endsWith(">")) { … … 89 84 } 90 85 /** Retrieves the next token. 91 92 86 * @return A <strong>String</strong> representing the token. 87 */ 93 88 public String nextToken() { 94 89 previous = current; … … 99 94 } 100 95 /** Repeats the result of the last <i>nextToken()</i>. 101 102 96 * @return A <strong>String</strong> representing the token. 97 */ 103 98 public String sameToken() { 104 99 return previous; 105 100 } 106 101 /** Parses the next token and stores it in current. 107 102 */ 108 103 private void parseToken() { 109 104 boolean found = false; … … 149 144 } 150 145 /** Method to ignore whitespace in the source. 151 146 */ 152 147 private void dumpWhiteSpace() { 153 148 while(pos < source.length() && source.charAt(pos) == ' ') { -
trunk/gli/src/org/greenstone/gatherer/util/HashMap3D.java
r5369 r5581 26 26 */ 27 27 package org.greenstone.gatherer.util; 28 28 29 /************************************************************************************** 29 30 * Written: 20/08/02 … … 33 34 import java.util.Iterator; 34 35 import org.greenstone.gatherer.msm.Metadata; 36 35 37 /** Provides a HashMap implementation that indexes by two keys. Perfect for the storage of metadata references based on their metadata element and assigned value. 36 38 * @author John Thompson, Greenstone Digital Library, University of Waikato -
trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java
r5564 r5581 30 30 import java.util.*; 31 31 import javax.swing.tree.*; 32 import org.greenstone.gatherer.Gatherer;33 32 import org.greenstone.gatherer.msm.ElementWrapper; 34 33 import org.greenstone.gatherer.msm.MetadataSetManager; -
trunk/gli/src/org/greenstone/gatherer/util/SynchronizedTreeModel.java
r4674 r5581 1 1 package org.greenstone.gatherer.util; 2 2 3 import javax.swing.*; 3 4 import javax.swing.tree.*; 4 5 5 import org.greenstone.gatherer.util.DefaultSynchronizedTreeNode; 6 6 import org.greenstone.gatherer.util.TreeModelTest; … … 20 20 */ 21 21 public class SynchronizedTreeModel 22 23 22 extends DefaultTreeModel 23 implements Runnable { 24 24 25 26 27 25 private boolean changed = false; 26 private DefaultTreeModel offscreen; 27 private TreeModelTest test = null; 28 28 29 SynchronizedTreeModel(SynchronizedTreeNode root) { 30 super(root); 31 offscreen = new DefaultTreeModel(root.cloneNode()); 29 SynchronizedTreeModel(SynchronizedTreeNode root) { 30 super(root); 31 offscreen = new DefaultTreeModel(root.cloneNode()); 32 } 33 34 SynchronizedTreeModel(SynchronizedTreeNode root, TreeModelTest test) { 35 super(root); 36 offscreen = new DefaultTreeModel(root.cloneNode()); 37 this.test = test; 38 } 39 40 /** Returns the child of parent at index index in the parent's child array. */ 41 public Object getChild(Object parent, int index) { 42 if(isEventThread()) { 43 return super.getChild(parent, index); 32 44 } 45 else { 46 return offscreen.getChild(parent, index); 47 } 48 } 33 49 34 SynchronizedTreeModel(SynchronizedTreeNode root, TreeModelTest test) { 35 super(root); 36 offscreen = new DefaultTreeModel(root.cloneNode());37 this.test = test;50 /** Returns the number of children of parent. */ 51 public int getChildCount(Object parent) { 52 if(isEventThread()) { 53 return super.getChildCount(parent); 38 54 } 55 else { 56 return offscreen.getChildCount(parent); 57 } 58 } 39 59 40 /** Returns the child of parent at index index in the parent's child array. */ 41 public Object getChild(Object parent, int index) { 42 if(isEventThread()) { 43 return super.getChild(parent, index); 44 } 45 else { 46 return offscreen.getChild(parent, index); 47 } 60 /** Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. This is probably the most 'expensive' method we make synchronized, but it isn't called often so thats ok. */ 61 public TreeNode[] getPathToRoot(TreeNode aNode) { 62 if(isEventThread()) { 63 return super.getPathToRoot(aNode); 48 64 } 65 else { 66 return offscreen.getPathToRoot(aNode); 67 } 68 } 49 69 50 /** Returns the number of children of parent. */ 51 public int getChildCount(Object parent) { 52 if(isEventThread()) { 53 return super.getChildCount(parent); 54 } 55 else { 56 return offscreen.getChildCount(parent); 57 } 70 public Object getRoot() { 71 if(isEventThread()) { 72 return super.getRoot(); 58 73 } 74 else { 75 return offscreen.getRoot(); 76 } 77 } 59 78 60 /** Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. This is probably the most 'expensive' method we make synchronized, but it isn't called often so thats ok. */ 61 public TreeNode[] getPathToRoot(TreeNode aNode) { 62 if(isEventThread()) { 63 return super.getPathToRoot(aNode); 64 } 65 else { 66 return offscreen.getPathToRoot(aNode); 67 } 79 /** Invoked this to insert newChild at location index in parents children. */ 80 public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) { 81 if(isEventThread()) { 82 if(test != null) test.debug("insertNodeInto(" + newChild + ", " + parent + ", " + index + ")"); 83 super.insertNodeInto(newChild, parent, index); 68 84 } 85 else { 86 if(test != null) test.debug("offscreen.insertNodeInto(" + newChild + ", " + parent + ", " + index + ")"); 87 offscreen.insertNodeInto(newChild, parent, index); 88 queueUpdate(); 89 } 90 } 69 91 70 public Object getRoot() { 71 if(isEventThread()) { 72 return super.getRoot(); 73 } 74 else { 75 return offscreen.getRoot(); 76 } 92 /** Message this to remove node from its parent. */ 93 public void removeNodeFromParent(MutableTreeNode node) { 94 if(isEventThread()) { 95 if(test != null) test.debug("removeNodeFromParent(" + node + ")"); 96 super.removeNodeFromParent(node); 77 97 } 98 else { 99 if(test != null) test.debug("offscreen.removeNodeFromParent(" + node + ")"); 100 offscreen.removeNodeFromParent(node); 101 queueUpdate(); 102 } 103 } 78 104 105 public void run() { 106 synchronized(this) { 107 if(changed) { 108 setRoot(((SynchronizedTreeNode)(offscreen.getRoot())). cloneNode()); 109 nodeChanged(root); 110 changed = false; 111 if(test != null) test.debug("Painted model refreshed."); 112 } 113 else { 114 if(test != null) test.debug("Painted model is current."); 115 } 116 } 117 } 79 118 80 /** Invoked this to insert newChild at location index in parents children. */ 81 public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) { 82 if(isEventThread()) { 83 if(test != null) test.debug("insertNodeInto(" + newChild + ", " + parent + ", " + index + ")"); 84 super.insertNodeInto(newChild, parent, index); 85 } 86 else { 87 if(test != null) test.debug("offscreen.insertNodeInto(" + newChild + ", " + parent + ", " + index + ")"); 88 offscreen.insertNodeInto(newChild, parent, index); 89 queueUpdate(); 90 } 91 } 119 /** Determine if this call is happening on the AWTEvent Dispatch Thread. */ 120 private boolean isEventThread() { 121 return SwingUtilities.isEventDispatchThread(); 122 } 92 123 93 /** Message this to remove node from its parent. */ 94 public void removeNodeFromParent(MutableTreeNode node) { 95 if(isEventThread()) { 96 if(test != null) test.debug("removeNodeFromParent(" + node + ")"); 97 super.removeNodeFromParent(node); 98 } 99 else { 100 if(test != null) test.debug("offscreen.removeNodeFromParent(" + node + ")"); 101 offscreen.removeNodeFromParent(node); 102 queueUpdate(); 103 } 104 } 105 106 public void run() { 107 synchronized(this) { 108 if(changed) { 109 setRoot(((SynchronizedTreeNode)(offscreen.getRoot())). cloneNode()); 110 nodeChanged(root); 111 changed = false; 112 if(test != null) test.debug("Painted model refreshed."); 113 } 114 else { 115 if(test != null) test.debug("Painted model is current."); 116 } 117 } 118 } 119 120 /** Determine if this call is happening on the AWTEvent Dispatch Thread. */ 121 private boolean isEventThread() { 122 return SwingUtilities.isEventDispatchThread(); 123 } 124 125 private synchronized void queueUpdate() { 126 changed = true; 127 SwingUtilities.invokeLater(this); 128 if(test != null) test.debug("Painted model is obsolete."); 129 } 124 private synchronized void queueUpdate() { 125 changed = true; 126 SwingUtilities.invokeLater(this); 127 if(test != null) test.debug("Painted model is obsolete."); 128 } 130 129 } -
trunk/gli/src/org/greenstone/gatherer/util/SynchronizedTreeModelTools.java
r4674 r5581 1 package org.greenstone.gatherer.util;2 1 /** 3 2 *######################################################################### … … 26 25 *######################################################################## 27 26 */ 27 package org.greenstone.gatherer.util; 28 28 29 import java.lang.Runnable; 29 30 import java.lang.Thread; -
trunk/gli/src/org/greenstone/gatherer/util/TreeModelTest.java
r4686 r5581 1 1 package org.greenstone.gatherer.util; 2 2 3 import java.awt.*; 3 4 import java.awt.event.*; … … 11 12 12 13 public class TreeModelTest 13 extends JFrame { 14 15 /** Testing - test frame size. */ 16 static final private Dimension SIZE = new Dimension(400,400); 17 18 /** Testing - should a debug file be written. */ 19 static private boolean debug = false; 20 21 /** Testing - debug output stream. */ 22 static private FileOutputStream output = null; 23 24 /** Testing - write a message to the debug file. */ 25 static void debug(String message) { 26 if(debug) { 27 try { 28 if(output == null) { 29 output = new FileOutputStream(new File("debug.txt")); 30 } 31 output.write(message.getBytes()); 32 output.flush(); 33 14 extends JFrame { 15 16 /** Testing - test frame size. */ 17 static final private Dimension SIZE = new Dimension(400,400); 18 19 /** Testing - should a debug file be written. */ 20 static private boolean debug = false; 21 22 /** Testing - debug output stream. */ 23 static private FileOutputStream output = null; 24 25 /** Testing - write a message to the debug file. */ 26 static void debug(String message) { 27 if(debug) { 28 try { 29 if(output == null) { 30 output = new FileOutputStream(new File("debug.txt")); 31 } 32 output.write(message.getBytes()); 33 output.flush(); 34 } 35 catch (Exception error) { 36 error.printStackTrace(); 37 } 38 } 39 } 40 41 /** Testing - usage message. */ 42 static void printUsage() { 43 System.out.println("Usage: java Test3 [-safe] [-debug]"); 44 System.out.println(" safe - use SynchronizedTreeModel"); 45 System.out.println(" debug - write debug messages to debug.txt file\n"); 46 System.out.println("Actions:"); 47 System.out.println(" 'Add Node' - Adds a new node to the selected node. Since this happens on the AWTEvent Thread it should always be safe."); 48 System.out.println(" 'Remove Node' - Removes the selected node. Since this happens on the AWTEvent Thread it should always be safe."); 49 System.out.println(" 'Preset Structure' - Generates a small preset structure on a seperate (dangerous) thread."); 50 System.out.println(" 'Dangerous' - The ultimate test. Hammers the model with incessant random mutations from a separate thread."); 51 System.exit(0); 52 } 53 /** Testing - creates a frame containing a JTree backed by either a normal DefaultTreeModel or a SynchronizedTreeModel depending on arguments. There are also several actions you can perform by clicking on buttons. */ 54 static public void main(String[] args) { 55 boolean safe = false; 56 if(args.length <= 2) { 57 for(int i = 0; i < args.length; i++) { 58 String arg = args[i]; 59 if(arg.equalsIgnoreCase("-safe")) { 60 safe = true; 61 } 62 else if(arg.equalsIgnoreCase("-debug")) { 63 debug = true; 64 } 65 else { 66 printUsage(); 67 } 68 } 69 } 70 else { 71 printUsage(); 72 } 73 new TreeModelTest(safe); 74 } 75 76 /** Testing - a dangerous thread which hammers the mutable tree model. */ 77 private DangerousTask task; 78 79 /** Testing - a dangerous thread which builds a preset structure. */ 80 private DangerousTask preset_task; 81 82 /** Testing - the tree model, which may be a SynchronizedTreeModel. */ 83 private DefaultTreeModel model; 84 85 /** Testing - a button for toggling the dangerous thread on and off. */ 86 private JToggleButton dangerous_button; 87 88 /** Testing - the tree used during testing. */ 89 private JTree tree; 90 91 TreeModelTest(boolean safe) { 92 super("Testing"); 93 setDefaultCloseOperation(EXIT_ON_CLOSE); 94 setSize(SIZE); 95 JPanel content_panel = (JPanel) getContentPane(); 96 97 // Creation 98 task = new DangerousTask(false); 99 preset_task = new DangerousTask(true); 100 101 if(safe) { 102 model = new SynchronizedTreeModel(new DefaultSynchronizedTreeNode("Root")); 103 } 104 else { 105 model = new DefaultTreeModel(new DefaultMutableTreeNode("Root")); 106 } 107 108 tree = new JTree(model); 109 110 JPanel button_panel = new JPanel(); 111 JButton add_button = new JButton("Add Node"); 112 dangerous_button = new JToggleButton("Dangerous!"); 113 dangerous_button.setSelected(false); 114 JButton remove_button = new JButton("Remove Node"); 115 JButton preset_button = new JButton("Preset Structure"); 116 117 // Connection 118 add_button.addActionListener(new AddListener()); 119 dangerous_button.addActionListener(new ActionListener() { 120 public void actionPerformed(ActionEvent event) { 121 if(dangerous_button.isSelected()) { 122 task.start(); 123 } 124 else { 125 task.exit = true; 126 } 127 } 128 }); 129 remove_button.addActionListener(new ActionListener() { 130 public void actionPerformed(ActionEvent event) { 131 ///ystem.err.println("*** Start Remove ***"); 132 // Get the selected node 133 TreePath selected_path = tree.getSelectionPath(); 134 if(selected_path != null) { 135 DefaultMutableTreeNode old_child = (DefaultMutableTreeNode) selected_path.getLastPathComponent(); 136 if(!old_child.isRoot()) { 137 // Remove node. 138 model.removeNodeFromParent(old_child); 34 139 } 35 catch (Exception error) { 36 error.printStackTrace(); 140 } 141 ///ystem.err.println("*** End Remove ***\n"); 142 } 143 }); 144 preset_button.addActionListener(new ActionListener() { 145 public void actionPerformed(ActionEvent event) { 146 preset_task.start(); 147 } 148 }); 149 150 // Layout 151 button_panel.setLayout(new GridLayout(2,2)); 152 button_panel.add(add_button); 153 button_panel.add(remove_button); 154 button_panel.add(preset_button); 155 button_panel.add(dangerous_button); 156 157 content_panel.setLayout(new BorderLayout()); 158 content_panel.add(new JScrollPane(tree), BorderLayout.CENTER); 159 content_panel.add(button_panel, BorderLayout.SOUTH); 160 161 // Display 162 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); 163 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 164 show(); 165 } 166 167 private class AddListener 168 implements ActionListener { 169 public void actionPerformed(ActionEvent event) { 170 ///ystem.err.println("*** Start Add ***"); 171 // Get the selected node 172 TreePath selected_path = tree.getSelectionPath(); 173 if(selected_path != null) { 174 DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected_path.getLastPathComponent(); 175 // Create a new node 176 MutableTreeNode new_child = new DefaultSynchronizedTreeNode( String.valueOf(System.currentTimeMillis())); 177 // Insert node. 178 model.insertNodeInto(new_child, parent, parent.getChildCount()); 179 } 180 ///ystem.err.println("*** End Add ***\n"); 181 } 182 } 183 184 private class DangerousTask 185 extends Thread { 186 187 private boolean exit = false; 188 private boolean preset = false; 189 190 DangerousTask(boolean preset) { 191 this.preset = preset; 192 } 193 194 public void run() { 195 if(preset) { 196 DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); 197 MutableTreeNode alpha = new DefaultSynchronizedTreeNode("Alpha"); 198 MutableTreeNode beta = new DefaultSynchronizedTreeNode("Beta"); 199 MutableTreeNode delta = new DefaultSynchronizedTreeNode("Delta"); 200 MutableTreeNode gamma = new DefaultSynchronizedTreeNode("Gamma"); 201 MutableTreeNode epsilon = new DefaultSynchronizedTreeNode("Epsilon"); 202 MutableTreeNode rho = new DefaultSynchronizedTreeNode("Rho"); 203 MutableTreeNode pi = new DefaultSynchronizedTreeNode("Pi"); 204 MutableTreeNode xhi = new DefaultSynchronizedTreeNode("Xhi"); 205 MutableTreeNode kappa = new DefaultSynchronizedTreeNode("Kappa"); 206 MutableTreeNode lambda = new DefaultSynchronizedTreeNode("Lambda"); 207 MutableTreeNode omega = new DefaultSynchronizedTreeNode("Omega");MutableTreeNode tau = new DefaultSynchronizedTreeNode("Tau"); 208 209 model.insertNodeInto(alpha, root, 0); 210 model.insertNodeInto(omega, root, 1); 211 model.insertNodeInto(pi, root, 1); 212 213 model.insertNodeInto(beta, alpha, 0); 214 model.insertNodeInto(delta, beta, 0); 215 model.insertNodeInto(epsilon, delta, 0); 216 model.insertNodeInto(gamma, delta, 0); 217 model.insertNodeInto(rho, pi, 0); 218 model.insertNodeInto(xhi, alpha, 0); 219 model.insertNodeInto(kappa, root, 1); 220 221 debug("Root has: " + model.getChildCount(model.getRoot())); 222 } 223 else { 224 exit = false; 225 while(!exit) { 226 // Find a random node 227 DefaultMutableTreeNode current = (DefaultMutableTreeNode) model.getRoot(); 228 while(Math.random() > 0.3 && model.getChildCount(current) > 0) { 229 int index = (int)(Math.random() * (model.getChildCount(current) - 1)); 230 current = (DefaultMutableTreeNode) model.getChild(current, index); 231 } 232 // Either add or remove a random node. 233 if(Math.random() > 0.9) { 234 ///ystem.err.println("<< Expand >>"); 235 TreePath path = new TreePath(model.getPathToRoot(current)); 236 tree.expandPath(path); 237 } 238 else if(Math.random() > 0.4 || current.isRoot()) { 239 if(model.getChildCount(current) < 25) { 240 ///ystem.err.println("<<< Add >>>"); 241 // Add a new node 242 MutableTreeNode new_child = new DefaultSynchronizedTreeNode(String.valueOf(System.currentTimeMillis())); 243 // Insert node. 244 model.insertNodeInto(new_child, current, model. getChildCount(current)); 245 ///ystem.err.println("<<< >>>\n"); 37 246 } 38 } 39 } 40 41 /** Testing - usage message. */ 42 static void printUsage() { 43 System.out.println("Usage: java Test3 [-safe] [-debug]"); 44 System.out.println(" safe - use SynchronizedTreeModel"); 45 System.out.println(" debug - write debug messages to debug.txt file\n"); 46 System.out.println("Actions:"); 47 System.out.println(" 'Add Node' - Adds a new node to the selected node. Since this happens on the AWTEvent Thread it should always be safe."); 48 System.out.println(" 'Remove Node' - Removes the selected node. Since this happens on the AWTEvent Thread it should always be safe."); 49 System.out.println(" 'Preset Structure' - Generates a small preset structure on a seperate (dangerous) thread."); 50 System.out.println(" 'Dangerous' - The ultimate test. Hammers the model with incessant random mutations from a separate thread."); 51 System.exit(0); 52 } 53 /** Testing - creates a frame containing a JTree backed by either a normal DefaultTreeModel or a SynchronizedTreeModel depending on arguments. There are also several actions you can perform by clicking on buttons. */ 54 static public void main(String[] args) { 55 boolean safe = false; 56 if(args.length <= 2) { 57 for(int i = 0; i < args.length; i++) { 58 String arg = args[i]; 59 if(arg.equalsIgnoreCase("-safe")) { 60 safe = true; 61 } 62 else if(arg.equalsIgnoreCase("-debug")) { 63 debug = true; 64 } 65 else { 66 printUsage(); 67 } 247 } 248 else { 249 ///ystem.err.println("<<< Remove >>>"); 250 // Remove node. 251 model.removeNodeFromParent(current); 252 ///ystem.err.println("<<< >>>\n"); 253 } 254 255 // Wait some random minute amount of time 256 try { 257 synchronized(this) { 258 wait((int)(5 * Math.random()) + 1); 68 259 } 69 } 70 else { 71 printUsage(); 72 } 73 new TreeModelTest(safe); 74 } 75 76 /** Testing - a dangerous thread which hammers the mutable tree model. */ 77 private DangerousTask task; 78 79 /** Testing - a dangerous thread which builds a preset structure. */ 80 private DangerousTask preset_task; 81 82 /** Testing - the tree model, which may be a SynchronizedTreeModel. */ 83 private DefaultTreeModel model; 84 85 /** Testing - a button for toggling the dangerous thread on and off. */ 86 private JToggleButton dangerous_button; 87 88 /** Testing - the tree used during testing. */ 89 private JTree tree; 90 91 TreeModelTest(boolean safe) { 92 super("Testing"); 93 setDefaultCloseOperation(EXIT_ON_CLOSE); 94 setSize(SIZE); 95 JPanel content_panel = (JPanel) getContentPane(); 96 // Creation 97 98 task = new DangerousTask(false); 99 preset_task = new DangerousTask(true); 100 101 if(safe) { 102 model = new SynchronizedTreeModel(new DefaultSynchronizedTreeNode("Root")); 103 } 104 else { 105 model = new DefaultTreeModel(new DefaultMutableTreeNode("Root")); 106 } 107 108 tree = new JTree(model); 109 110 JPanel button_panel = new JPanel(); 111 JButton add_button = new JButton("Add Node"); 112 dangerous_button = new JToggleButton("Dangerous!"); 113 dangerous_button.setSelected(false); 114 JButton remove_button = new JButton("Remove Node"); 115 JButton preset_button = new JButton("Preset Structure"); 116 117 // Connection 118 add_button.addActionListener(new AddListener()); 119 dangerous_button.addActionListener(new ActionListener() { 120 public void actionPerformed(ActionEvent event) { 121 if(dangerous_button.isSelected()) { 122 task.start(); 123 } 124 else { 125 task.exit = true; 126 } 127 } 128 }); 129 remove_button.addActionListener(new ActionListener() { 130 public void actionPerformed(ActionEvent event) { 131 ///ystem.err.println("*** Start Remove ***"); 132 // Get the selected node 133 TreePath selected_path = tree.getSelectionPath(); 134 if(selected_path != null) { 135 DefaultMutableTreeNode old_child = (DefaultMutableTreeNode) selected_path.getLastPathComponent(); 136 if(!old_child.isRoot()) { 137 // Remove node. 138 model.removeNodeFromParent(old_child); 139 } 140 } 141 ///ystem.err.println("*** End Remove ***\n"); 142 } 143 }); 144 preset_button.addActionListener(new ActionListener() { 145 public void actionPerformed(ActionEvent event) { 146 preset_task.start(); 147 } 148 }); 149 150 // Layout 151 button_panel.setLayout(new GridLayout(2,2)); 152 button_panel.add(add_button); 153 button_panel.add(remove_button); 154 button_panel.add(preset_button); 155 button_panel.add(dangerous_button); 156 157 content_panel.setLayout(new BorderLayout()); 158 content_panel.add(new JScrollPane(tree), BorderLayout.CENTER); 159 content_panel.add(button_panel, BorderLayout.SOUTH); 160 161 // Display 162 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); 163 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 164 show(); 165 } 166 167 private class AddListener 168 implements ActionListener { 169 public void actionPerformed(ActionEvent event) { 170 ///ystem.err.println("*** Start Add ***"); 171 // Get the selected node 172 TreePath selected_path = tree.getSelectionPath(); 173 if(selected_path != null) { 174 DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected_path.getLastPathComponent(); 175 // Create a new node 176 MutableTreeNode new_child = new DefaultSynchronizedTreeNode( String.valueOf(System.currentTimeMillis())); 177 // Insert node. 178 model.insertNodeInto(new_child, parent, parent.getChildCount()); 179 } 180 ///ystem.err.println("*** End Add ***\n"); 181 } 182 } 183 184 private class DangerousTask 185 extends Thread { 186 187 private boolean exit = false; 188 private boolean preset = false; 189 190 DangerousTask(boolean preset) { 191 this.preset = preset; 192 } 193 194 public void run() { 195 if(preset) { 196 DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); 197 MutableTreeNode alpha = new DefaultSynchronizedTreeNode("Alpha"); 198 MutableTreeNode beta = new DefaultSynchronizedTreeNode("Beta"); 199 MutableTreeNode delta = new DefaultSynchronizedTreeNode("Delta"); 200 MutableTreeNode gamma = new DefaultSynchronizedTreeNode("Gamma"); 201 MutableTreeNode epsilon = new DefaultSynchronizedTreeNode("Epsilon"); 202 MutableTreeNode rho = new DefaultSynchronizedTreeNode("Rho"); 203 MutableTreeNode pi = new DefaultSynchronizedTreeNode("Pi"); 204 MutableTreeNode xhi = new DefaultSynchronizedTreeNode("Xhi"); 205 MutableTreeNode kappa = new DefaultSynchronizedTreeNode("Kappa"); 206 MutableTreeNode lambda = new DefaultSynchronizedTreeNode("Lambda"); 207 MutableTreeNode omega = new DefaultSynchronizedTreeNode("Omega");MutableTreeNode tau = new DefaultSynchronizedTreeNode("Tau"); 208 209 model.insertNodeInto(alpha, root, 0); 210 model.insertNodeInto(omega, root, 1); 211 model.insertNodeInto(pi, root, 1); 212 213 model.insertNodeInto(beta, alpha, 0); 214 model.insertNodeInto(delta, beta, 0); 215 model.insertNodeInto(epsilon, delta, 0); 216 model.insertNodeInto(gamma, delta, 0); 217 model.insertNodeInto(rho, pi, 0); 218 model.insertNodeInto(xhi, alpha, 0); 219 model.insertNodeInto(kappa, root, 1); 220 221 222 debug("Root has: " + model.getChildCount(model.getRoot())); 223 } 224 else { 225 exit = false; 226 while(!exit) { 227 // Find a random node 228 DefaultMutableTreeNode current = (DefaultMutableTreeNode) model.getRoot(); 229 while(Math.random() > 0.3 && model.getChildCount(current) > 0) { 230 int index = (int)(Math.random() * (model.getChildCount(current) - 1)); 231 current = (DefaultMutableTreeNode) model.getChild(current, index); 232 } 233 // Either add or remove a random node. 234 if(Math.random() > 0.9) { 235 ///ystem.err.println("<< Expand >>"); 236 TreePath path = new TreePath(model.getPathToRoot(current)); 237 tree.expandPath(path); 238 } 239 else if(Math.random() > 0.4 || current.isRoot()) { 240 if(model.getChildCount(current) < 25) { 241 ///ystem.err.println("<<< Add >>>"); 242 // Add a new node 243 MutableTreeNode new_child = new DefaultSynchronizedTreeNode(String.valueOf(System.currentTimeMillis())); 244 // Insert node. 245 model.insertNodeInto(new_child, current, model. getChildCount(current)); 246 ///ystem.err.println("<<< >>>\n"); 247 } 248 } 249 else { 250 ///ystem.err.println("<<< Remove >>>"); 251 // Remove node. 252 model.removeNodeFromParent(current); 253 ///ystem.err.println("<<< >>>\n"); 254 255 } 256 // Wait some random minute amount of time 257 try { 258 synchronized(this) { 259 wait((int)(5 * Math.random()) + 1); 260 } 261 } catch (Exception exception) { 262 exception.printStackTrace(); 263 } 264 } 265 } 266 } 267 } 260 } catch (Exception exception) { 261 exception.printStackTrace(); 262 } 263 } 264 } 265 } 266 } 268 267 } -
trunk/gli/src/org/greenstone/gatherer/util/TreeSynchronizer.java
r4674 r5581 1 package org.greenstone.gatherer.util;2 1 /** 3 2 *######################################################################### … … 26 25 *######################################################################## 27 26 */ 27 package org.greenstone.gatherer.util; 28 28 29 import java.util.Vector; 29 30 import javax.swing.JTree; … … 48 49 /** Add a new tree to the synchronization list of trees to be synchronized. 49 50 * @param tree The lastest victim, a <strong>JTree</strong>. 50 51 */ 51 52 public void add(JTree tree) { 52 53 super.add(tree); … … 63 64 64 65 /** Called whenever an item in the tree has been collapsed. 65 66 66 * @param event A <strong>TreeExpansionEvent</strong> containing information about the event. 67 */ 67 68 public void treeCollapsed(TreeExpansionEvent event) { 68 69 if(!ignore) { 69 70 ignore = true; 70 71 // Collapse that path in all registered trees. 71 72 JTree tree = (JTree)event.getSource(); 72 73 TreePath path = event.getPath(); … … 81 82 } 82 83 /** Called whenever an item in the tree has been expanded. 83 84 84 * @param event A <strong>TreeExpansionEvent</strong> containing information about the event. 85 */ 85 86 public void treeExpanded(TreeExpansionEvent event) { 86 87 if(!ignore) { … … 99 100 } 100 101 /** Called whenever the one of the trees selection changes. 101 102 102 * @param event A <strong>TreeSelectionEvent</strong> containing information about the event. 103 */ 103 104 public void valueChanged(TreeSelectionEvent event) { 104 105 if(!ignore) { -
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r5564 r5581 259 259 return result; 260 260 } 261 /** Generate a depth first enumeration of a tree. */262 static public EnumeratedVector depthFirstEnumeration(TreeNode node, EnumeratedVector result) {263 result.add(node);264 for(int i = 0; i < node.getChildCount(); i++) {265 depthFirstEnumeration(node.getChildAt(i), result);266 }267 return result;268 }269 261 270 262 static public String encodeGreenstone(String raw) { … … 375 367 } 376 368 if(pos < number_char.length) { 377 369 // Print the '.' and at most two characters after it 378 370 result.append(number_char[pos]); 379 371 pos++; … … 381 373 result.append(number_char[pos]); 382 374 } 383 375 // Search through the remaining string for 'E' 384 376 while(pos < number_char.length && number_char[pos] != 'E') { 385 377 pos++; 386 378 } 387 379 // If we still have string then we found an E. Copy the remaining string. 388 380 while(pos < number_char.length) { 389 381 result.append(number_char[pos]); … … 579 571 int year = current.get(Calendar.YEAR); 580 572 581 return day_name + " " + month_name+ " " + day + " " + year + " " + Utility.pad(String.valueOf(hour), 2, '0', true) + ":" + Utility.pad(String.valueOf(minute), 2, '0', true) + ":" + Utility.pad(String.valueOf(second), 2, '0', true);573 return Dictionary.newget("Dates." + day_name) + " " + Dictionary.newget("Dates." + month_name) + " " + day + " " + year + " " + Utility.pad(String.valueOf(hour), 2, '0', true) + ":" + Utility.pad(String.valueOf(minute), 2, '0', true) + ":" + Utility.pad(String.valueOf(second), 2, '0', true); 582 574 } 583 575 -
trunk/gli/src/org/greenstone/gatherer/util/WinRegistry.java
r4674 r5581 35 35 *######################################################################## 36 36 */ 37 package org.greenstone.gatherer.util; 37 38 38 39 40 41 42 43 package org.greenstone.gatherer.util;44 39 /** 45 40 * Title: The Gatherer -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java
r5294 r5581 1 package org.greenstone.gatherer.valuetree;2 1 /** 3 2 *######################################################################### … … 26 25 *######################################################################## 27 26 */ 27 package org.greenstone.gatherer.valuetree; 28 28 29 import java.util.*; 29 30 import javax.swing.tree.*; 30 31 import org.greenstone.gatherer.Gatherer; 31 32 import org.greenstone.gatherer.msm.ElementWrapper; 32 import org.greenstone.gatherer.msm.MetadataSetManager;33 33 import org.greenstone.gatherer.msm.MSMUtils; 34 import org.greenstone.gatherer.util.Codec;35 34 import org.greenstone.gatherer.util.PatternTokenizer; 36 import org.greenstone.gatherer.util.StaticStrings;37 import org.greenstone.gatherer.util.SynchronizedTreeModelTools;38 35 import org.greenstone.gatherer.util.Utility; 39 36 import org.w3c.dom.*; -
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java
r5294 r5581 36 36 */ 37 37 package org.greenstone.gatherer.valuetree; 38 38 39 /** 39 40 * Title: The Gatherer<br> … … 46 47 * @version 2.1 47 48 */ 48 import java.util.Collections; 49 import java.util.Enumeration; 50 import java.util.HashMap; 51 import java.util.Hashtable; 52 import java.util.Vector; 49 50 import java.util.*; 53 51 import javax.swing.tree.*; 54 52 import org.greenstone.gatherer.Gatherer; 55 import org.greenstone.gatherer.msm.ElementWrapper;56 53 import org.greenstone.gatherer.msm.MSMUtils; 57 54 import org.greenstone.gatherer.util.Codec; 58 55 import org.greenstone.gatherer.util.StaticStrings; 59 56 import org.greenstone.gatherer.util.Utility; 60 import org.w3c.dom.Document; 61 import org.w3c.dom.Element; 62 import org.w3c.dom.Node; 63 import org.w3c.dom.NodeList; 57 import org.w3c.dom.*; 58 64 59 /** This class is instantiated using a metadata element. From this parent element, which refers to a specific Element in the mds DOM model, the AssignedValues child is used as the root of a tree data-structure encompassing all of the nodes within the AssignedValues tree. This class also provide methods for adding, updating and removing nodes within this tree, as well as implementing all of the methods necessary for this node to be used as the basis of a tree model. 65 60 */ … … 80 75 this.default_value = default_value; 81 76 } 77 82 78 /** Compares two GValueNodes for ordering by using the String.compareTo method. 83 79 * @param sibling The <strong>Object</strong> representing the GValueNode we are comparing ourselves to. … … 87 83 return toString().compareTo(sibling.toString()); 88 84 } 85 89 86 /** Determine if this tree node contains a child with a matching value. 90 87 * @param value The value we are attempting to match, as a <strong>String</strong>. … … 97 94 return getValue(value) != null; 98 95 } 96 99 97 /** Returns an enumeration of the child nodes. 100 98 * @return An <strong>Enumeration</strong> containing the child nodes. … … 125 123 Element element = (Element) userObject; 126 124 for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) { 127 125 // And if we find such a node 128 126 if(pos_node.getNodeName().equals("Alias")) { 129 127 // Retrieve its text node … … 158 156 return (GValueNode) children.get(index); 159 157 } 158 160 159 /** Returns the number of children <I>TreeNode</I>s the reciever contains. */ 161 160 public int getChildCount() { … … 384 383 Element element = (Element) userObject; 385 384 for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) { 386 385 // And if we find such a node 387 386 if(pos_node.getNodeName().equals(name)) { 388 387 // And the new value is non-null, retrieve its text node and change it.
Note:
See TracChangeset
for help on using the changeset viewer.