Changeset 6087
- Timestamp:
- 2003-12-02T17:18:37+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/Argument.java
r5230 r6087 66 66 /** The type of this argument. Initially an int, but bytes are cheaper. */ 67 67 private byte type = STRING; 68 69 /** The maximum value an integer based control can have. */ 70 private int maximum = Integer.MAX_VALUE; 71 /** The minimum value an integer based control can have. */ 72 private int minimum = Integer.MIN_VALUE; 73 68 74 private Element element; 69 75 /** If the argument is of type ENUM then this map holds all the various options. Each entry is an <option value> -> <description> mapping. */ … … 162 168 } 163 169 170 public int getMaximum() { 171 return maximum; 172 } 173 174 public int getMinimum() { 175 return minimum; 176 } 177 164 178 /** Method to retrieve the option list for this argument. 165 179 * @return A <strong>HashMap</strong> containing <option value> -> <description> entries. … … 284 298 public void setElement(Element element) { 285 299 this.element = element; 300 } 301 302 public void setMaximum(int maximum) { 303 this.maximum = maximum; 304 } 305 306 public void setMinimum(int minimum) { 307 this.minimum = minimum; 286 308 } 287 309 -
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java
r6051 r6087 325 325 Collections.sort(options_model); 326 326 value = new JComboBox(options_model.toArray()); 327 327 ((JComboBox)value).setEditable(true); 328 328 ((JComboBox)value).addActionListener(new ToolTipUpdater()); 329 329 if(existing_value != null) { … … 353 353 break; 354 354 case Argument.INTEGER: 355 // Build a spinner 356 JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, argument.getMinimum(), argument.getMaximum(), 1)); 357 // If there was an original value, set it. 358 if(existing_value != null) { 359 try { 360 spinner.setValue(new Integer(existing_value)); 361 } 362 catch (Exception error) { 363 } 364 } 365 else if(default_value != null) { 366 try { 367 spinner.setValue(new Integer(default_value)); 368 } 369 catch (Exception error) { 370 } 371 } 372 // And remember it 373 value = spinner; 374 break; 355 375 case Argument.STRING: 356 376 // Use a standard text field … … 450 470 break; 451 471 } // end of switch 472 452 473 // Enable or disable as necessary. 453 474 if(argument.isRequired() || argument.isAssigned()) { … … 457 478 value.setBackground(Color.white); 458 479 value.setEnabled(true); 480 if(value instanceof JSpinner) { 481 // Set enabled 482 JComponent c = ((JSpinner)value).getEditor(); 483 if ( c instanceof JSpinner.DefaultEditor ) { 484 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c; 485 JFormattedTextField field = editor.getTextField(); 486 field.setEditable(true); 487 field.setBackground(Color.white); 488 } 489 } 459 490 } 460 491 } … … 465 496 value.setBackground(Color.lightGray); 466 497 value.setEnabled(false); 498 if(value instanceof JSpinner) { 499 // Set enabled 500 JComponent c = ((JSpinner)value).getEditor(); 501 if ( c instanceof JSpinner.DefaultEditor ) { 502 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c; 503 JFormattedTextField field = editor.getTextField(); 504 field.setEditable(false); 505 field.setBackground(Color.lightGray); 506 } 507 } 467 508 } 468 509 } … … 567 608 return true; 568 609 case Argument.INTEGER: 569 result = ((J TextField)value).getText();610 result = ((JSpinner)value).getValue().toString(); 570 611 if(result.length() > 0) { 571 612 // Test if the value entered is a valid int. … … 789 830 target.setBackground(Color.white); 790 831 target.setEnabled(true); 832 if(target instanceof JSpinner) { 833 // Set enabled 834 JComponent c = ((JSpinner)target).getEditor(); 835 if ( c instanceof JSpinner.DefaultEditor ) { 836 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c; 837 JFormattedTextField field = editor.getTextField(); 838 field.setEditable(true); 839 field.setBackground(Color.white); 840 } 841 } 791 842 if(one != null && two != null && list != null) { 792 843 one.setEnabled(true); … … 799 850 target.setBackground(Color.lightGray); 800 851 target.setEnabled(false); 852 if(target instanceof JSpinner) { 853 // Set enabled 854 JComponent c = ((JSpinner)target).getEditor(); 855 if ( c instanceof JSpinner.DefaultEditor ) { 856 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c; 857 JFormattedTextField field = editor.getTextField(); 858 field.setEditable(false); 859 field.setBackground(Color.lightGray); 860 } 861 } 801 862 if(one != null && two != null && list != null) { 802 863 one.setEnabled(false); -
trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java
r6032 r6087 490 490 } 491 491 } 492 else if(node_name.equals(StaticStrings.RANGE_ELEMENT)) { 493 String range_raw = MSMUtils.getValue(det); 494 int index = -1; 495 if((index = range_raw.indexOf(StaticStrings.COMMA_CHARACTER)) != -1) { 496 if(index > 0) { 497 try { 498 String first_number = range_raw.substring(0, index); 499 argument.setMinimum(Integer.parseInt(first_number)); 500 first_number = null; 501 } 502 catch(Exception exception) { 503 } 504 } 505 506 if(index + 1 < range_raw.length()) { 507 try { 508 String second_number = range_raw.substring(index + 1); 509 argument.setMaximum(Integer.parseInt(second_number)); 510 second_number = null; 511 512 } 513 catch(Exception exception) { 514 } 515 } 516 517 } 518 // Else it wasn't a valid range anyway, so ignore it 519 } 492 520 } 493 521 classifier.addArgument(argument); -
trunk/gli/src/org/greenstone/gatherer/cdm/PlugInManager.java
r6051 r6087 498 498 } 499 499 } 500 else if(node_name.equals(StaticStrings.RANGE_ELEMENT)) { 501 String range_raw = MSMUtils.getValue(det); 502 int index = -1; 503 if((index = range_raw.indexOf(StaticStrings.COMMA_CHARACTER)) != -1) { 504 if(index > 0) { 505 try { 506 String first_number = range_raw.substring(0, index); 507 argument.setMinimum(Integer.parseInt(first_number)); 508 first_number = null; 509 } 510 catch(Exception exception) { 511 } 512 } 513 514 if(index + 1 < range_raw.length()) { 515 try { 516 String second_number = range_raw.substring(index + 1); 517 argument.setMaximum(Integer.parseInt(second_number)); 518 second_number = null; 519 } 520 catch(Exception exception) { 521 } 522 } 523 } 524 // Else it wasn't a valid range anyway, so ignore it 525 } 500 526 } 501 527 plugin.addArgument(argument); -
trunk/gli/src/org/greenstone/gatherer/collection/BuildOptions.java
r5581 r6087 9 9 import org.greenstone.gatherer.msm.MSMUtils; 10 10 import org.greenstone.gatherer.util.ArrayTools; 11 import org.greenstone.gatherer.util.Codec; 12 import org.greenstone.gatherer.util.StaticStrings; 11 13 import org.greenstone.gatherer.util.Utility; 12 14 import org.w3c.dom.*; … … 48 50 build_arguments_element = loadArguments("buildcol.pl"); 49 51 import_arguments_element = loadArguments("import.pl"); 50 52 // And if that too fails, load the default argument templates 51 53 if(build_arguments_element == null || import_arguments_element == null) { 52 54 Document build_document = Utility.parse("xml/buildcol.xml", true); … … 61 63 ///atherer.println("Loaded BO arguments from scripts."); 62 64 } 63 65 // By now we should definately have the arguments. However the reason we are here is because they are not stored in the config.xml file, to make sure they are stored now. 64 66 Gatherer.config.setArguments(build_arguments_element); 65 67 Gatherer.config.setArguments(import_arguments_element); … … 248 250 } 249 251 } 252 else if(node_name.equals(StaticStrings.RANGE_ELEMENT)) { 253 String range_raw = MSMUtils.getValue(node); 254 int comma_index = -1; 255 if((comma_index = range_raw.indexOf(StaticStrings.COMMA_CHARACTER)) != -1) { 256 if(comma_index > 0) { 257 try { 258 String first_number = range_raw.substring(0, comma_index); 259 argument.setMinimum(Integer.parseInt(first_number)); 260 first_number = null; 261 } 262 catch(Exception exception) { 263 } 264 } 265 266 if(comma_index + 1 < range_raw.length()) { 267 try { 268 String second_number = range_raw.substring(comma_index + 1); 269 argument.setMaximum(Integer.parseInt(second_number)); 270 second_number = null; 271 } 272 catch(Exception exception) { 273 } 274 } 275 } 276 // Else it wasn't a valid range anyway, so ignore it 277 range_raw = null; 278 } 250 279 } 251 280 } … … 299 328 values.add("-" + argument_element.getAttribute(NAME)); 300 329 // Now retrieve the value. 301 String argument_value = MSMUtils.getValue(argument_element);330 String argument_value = Codec.transform(MSMUtils.getValue(argument_element), Codec.DOM_TO_TEXT); 302 331 // If there is a value, tokenize it by commas only. 303 332 if(argument_value != null && argument_value.length() > 0) { … … 319 348 Element arguments_element = null; 320 349 // Run the required program. 321 /** @todo - I never finished implementing this. Have to test that the perl script handles being loaded in this way. 322 try { 323 String args[] = new String[3]; 324 args[0] = Gatherer.config.perl_path; 325 args[1] = filename; 326 args[2] = "-xml"; 327 // Create the process. 328 Runtime runtime = Runtime.getRuntime(); 329 Process process = runtime.exec(args); 330 //InputStream input_stream = process.getErrorStream(); 331 InputSource source = new InputSource(new InputStreamReader(process.getErrorStream())); 332 DOMParser parser = new DOMParser(); 333 parser.parse(source); 334 Document document = parser.getDocument(); 335 arguments_element = document.getDocumentElement(); 336 } 337 catch (Exception error) { 338 Gatherer.println("Error in BuildOptions.loadArguments(): " + error); 339 Gatherer.printStackTrace(error); 340 } 341 */ 350 try { 351 String args[]; 352 if(Utility.isWindows()) { 353 args = new String[4]; 354 args[0] = Gatherer.config.perl_path; 355 args[1] = "-S"; 356 args[2] = Gatherer.config.getScriptPath() + filename; 357 args[3] = "-xml"; 358 } 359 else { 360 args = new String[2]; 361 args[0] = Gatherer.config.getScriptPath() + filename; 362 args[1] = "-xml"; 363 } 364 // Create the process. 365 Runtime runtime = Runtime.getRuntime(); 366 Process process = runtime.exec(args); 367 //InputStream input_stream = process.getErrorStream(); 368 InputSource source = new InputSource(new InputStreamReader(process.getErrorStream())); 369 DOMParser parser = new DOMParser(); 370 parser.parse(source); 371 Document document = parser.getDocument(); 372 arguments_element = document.getDocumentElement(); 373 } 374 catch (Exception error) { 375 Gatherer.println("Error in BuildOptions.loadArguments(): " + error); 376 Gatherer.printStackTrace(error); 377 } 342 378 return arguments_element; 343 379 } -
trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java
r5873 r6087 311 311 case Argument.INTEGER: 312 312 // Build a spinner 313 JSpinner spinner = new JSpinner(); 313 JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, argument.getMinimum(), argument.getMaximum(), 1)); 314 try { 315 int default_value = Integer.parseInt(argument.getDefaultValue()); 316 spinner.setValue(new Integer(default_value)); 317 } 318 catch (Exception exception) { 319 } 314 320 spinner.setEnabled(enable); 315 321 spinner.setPreferredSize(SPINNER_SIZE); -
trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java
r6063 r6087 32 32 /** Were you to guess that this is a class object choc-a-block full of static stringy goodness, you'd be right. They come in several flavours: Those ending _STR are strings you might find as values in XML, _ELEMENT are element names, _ATTRIBUTE are attribute names, _CHAR are particular characters while _CHARACTER are also characters but expressed as strings (for regex purposes ie startsWith, endsWith, indexOf and replaceAll); _PATTERN are strings which require extra escaping to put them through regex. Finally anything else is just a static string used within GLI. */ 33 33 public class StaticStrings { 34 34 static final public char CLOSEBRACKET_CHAR = ']'; 35 35 static final public char DOUBLEQUOTE_CHAR = '\"'; 36 36 static final public char BACKSLASH_CHAR = '\\'; … … 79 79 static final public String DEBUG_ARGUMENT = "-debug"; 80 80 static final public String DICTIONARY_FILENAME = "dictionary"; 81 static final public String DIRECTORY_MAPPINGS_ELEMENT = "DirectoryMappings"; 81 82 static final public String ETC_FOLDER = "etc"; 82 83 static final public String EMPTY_STR = ""; … … 92 93 static final public String EXTRACTED_NAMESPACE = "ex."; 93 94 static final public String FALSE_STR = "false"; 95 static final public String FILE_ATTRIBUTE = "file"; 94 96 static final public String FILENAME_STR = "Filename"; 95 97 static final public String FLAG_STR = "flag"; … … 104 106 static final public String HELP_ARGUMENT = "-help"; 105 107 static final public String IMAGES_FOLDER = "images"; 106 static final public String IMAGES_PATH_PREFIX = "_httpcollection_/images/"; 108 static final public String IMAGES_PATH_RELATIVE_TO_COLLECTION_PREFIX = "_httpcollection_/images/"; 109 static final public String IMAGES_PATH_RELATIVE_TO_GSDL_PREFIX = "_httpprefix_/collect/<col_name>/images/"; 107 110 static final public String IMPORT_FOLDER = "import"; 108 111 static final public String INCLUDE_STR = "include"; … … 129 132 static final public String LIBRARY_STR = "library"; 130 133 static final public String LOAD_ARGUMENT = "-load"; 134 static final public String MAPPING_ELEMENT = "Mapping"; 131 135 static final public String MARC_EXTENSION = ".marc"; 132 136 static final public String METADATA_ARGUMENT = "-metadata"; … … 155 159 static final public String PROPERTIES_FILE_EXTENSION = ".properties"; 156 160 static final public String PSEUDO_COLLECTCONFIGURATION_XML = "xml/CollectionConfig.xml"; 161 static final public String RANGE_ELEMENT = "Range"; 157 162 static final public String RBRACKET_CHARACTER = "]"; 158 163 static final public String RBRACKET_PATTERN = "\\]";
Note:
See TracChangeset
for help on using the changeset viewer.