Changeset 6087


Ignore:
Timestamp:
2003-12-02T17:18:37+13:00 (20 years ago)
Author:
jmt12
Message:

Extended arguments so they could be given a minimum and maximum range. Then if they are INTEGER type controls, the spinner control generated will honour any range information. Range information is supplied via the perl -xml type mechanism, using the tag form <Range>0,3</Range>

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  
    6666    /** The type of this argument. Initially an int, but bytes are cheaper. */
    6767    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
    6874    private Element element;
    6975    /** If the argument is of type ENUM then this map holds all the various options. Each entry is an &lt;option value&gt; -&gt; &lt;description&gt; mapping. */
     
    162168    }
    163169
     170    public int getMaximum() {
     171    return maximum;
     172    }
     173
     174    public int getMinimum() {
     175    return minimum;
     176    }
     177
    164178    /** Method to retrieve the option list for this argument.
    165179     * @return A <strong>HashMap</strong> containing &lt;option value&gt; -&gt; &lt;description&gt; entries.
     
    284298    public void setElement(Element element) {
    285299    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;
    286308    }
    287309
  • trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java

    r6051 r6087  
    325325        Collections.sort(options_model);
    326326        value = new JComboBox(options_model.toArray());
    327         ((JComboBox)value).setEditable(true);
     327        ((JComboBox)value).setEditable(true);
    328328        ((JComboBox)value).addActionListener(new ToolTipUpdater());
    329329        if(existing_value != null) {
     
    353353        break;
    354354        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;
    355375        case Argument.STRING:
    356376        // Use a standard text field
     
    450470        break;
    451471        } // end of switch
     472
    452473        // Enable or disable as necessary.
    453474        if(argument.isRequired() || argument.isAssigned()) {
     
    457478            value.setBackground(Color.white);
    458479            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            }
    459490        }
    460491        }
     
    465496            value.setBackground(Color.lightGray);
    466497            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            }
    467508        }
    468509        }
     
    567608            return true;
    568609        case Argument.INTEGER:
    569             result = ((JTextField)value).getText();
     610            result = ((JSpinner)value).getValue().toString();
    570611            if(result.length() > 0) {
    571612            // Test if the value entered is a valid int.
     
    789830            target.setBackground(Color.white);
    790831            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            }
    791842            if(one != null && two != null && list != null) {
    792843            one.setEnabled(true);
     
    799850            target.setBackground(Color.lightGray);
    800851            target.setEnabled(false);
     852if(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            }
    801862            if(one != null && two != null && list != null) {
    802863            one.setEnabled(false);
  • trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java

    r6032 r6087  
    490490                }
    491491                }
     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                }
    492520            }
    493521            classifier.addArgument(argument);
  • trunk/gli/src/org/greenstone/gatherer/cdm/PlugInManager.java

    r6051 r6087  
    498498                }
    499499                }
     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) {
     504if(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                }
    500526            }
    501527            plugin.addArgument(argument);
  • trunk/gli/src/org/greenstone/gatherer/collection/BuildOptions.java

    r5581 r6087  
    99import org.greenstone.gatherer.msm.MSMUtils;
    1010import org.greenstone.gatherer.util.ArrayTools;
     11import org.greenstone.gatherer.util.Codec;
     12import org.greenstone.gatherer.util.StaticStrings;
    1113import org.greenstone.gatherer.util.Utility;
    1214import org.w3c.dom.*;
     
    4850        build_arguments_element = loadArguments("buildcol.pl");
    4951        import_arguments_element = loadArguments("import.pl");
    50                 // And if that too fails, load the default argument templates
     52        // And if that too fails, load the default argument templates
    5153        if(build_arguments_element == null || import_arguments_element == null) {
    5254        Document build_document = Utility.parse("xml/buildcol.xml", true);
     
    6163        ///atherer.println("Loaded BO arguments from scripts.");
    6264        }
    63                 // 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.
     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.
    6466        Gatherer.config.setArguments(build_arguments_element);
    6567        Gatherer.config.setArguments(import_arguments_element);
     
    248250            }
    249251            }
     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            }
    250279        }
    251280        }
     
    299328            values.add("-" + argument_element.getAttribute(NAME));
    300329            // 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);
    302331            // If there is a value, tokenize it by commas only.
    303332            if(argument_value != null && argument_value.length() > 0) {
     
    319348    Element arguments_element = null;
    320349    // 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    }
    342378    return arguments_element;
    343379    }
  • trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java

    r5873 r6087  
    311311        case Argument.INTEGER:
    312312        // 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        }
    314320        spinner.setEnabled(enable);
    315321        spinner.setPreferredSize(SPINNER_SIZE);
  • trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r6063 r6087  
    3232/** 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. */
    3333public class StaticStrings {
    34     static final public char   CLOSEBRACKET_CHAR                          = ']';
     34    static final public char   CLOSEBRACKET_CHAR                          = ']';
    3535    static final public char   DOUBLEQUOTE_CHAR                           = '\"';
    3636    static final public char   BACKSLASH_CHAR                             = '\\';
     
    7979    static final public String DEBUG_ARGUMENT                             = "-debug";
    8080    static final public String DICTIONARY_FILENAME                        = "dictionary";
     81    static final public String DIRECTORY_MAPPINGS_ELEMENT                 = "DirectoryMappings";
    8182    static final public String ETC_FOLDER                                 = "etc";
    8283    static final public String EMPTY_STR                                  = "";
     
    9293    static final public String EXTRACTED_NAMESPACE                        = "ex.";
    9394    static final public String FALSE_STR                                  = "false";
     95    static final public String FILE_ATTRIBUTE                             = "file";
    9496    static final public String FILENAME_STR                               = "Filename";
    9597    static final public String FLAG_STR                                   = "flag";
     
    104106    static final public String HELP_ARGUMENT                              = "-help";
    105107    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/";
    107110    static final public String IMPORT_FOLDER                              = "import";
    108111    static final public String INCLUDE_STR                                = "include";
     
    129132    static final public String LIBRARY_STR                                = "library";
    130133    static final public String LOAD_ARGUMENT                              = "-load";
     134    static final public String MAPPING_ELEMENT                            = "Mapping";
    131135    static final public String MARC_EXTENSION                             = ".marc";
    132136    static final public String METADATA_ARGUMENT                          = "-metadata";
     
    155159    static final public String PROPERTIES_FILE_EXTENSION                  = ".properties";
    156160    static final public String PSEUDO_COLLECTCONFIGURATION_XML            = "xml/CollectionConfig.xml";
     161    static final public String RANGE_ELEMENT                              = "Range";
    157162    static final public String RBRACKET_CHARACTER                         = "]";
    158163    static final public String RBRACKET_PATTERN                           = "\\]";
Note: See TracChangeset for help on using the changeset viewer.