Ignore:
Timestamp:
2003-12-02T17:18:37+13:00 (21 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/cdm
Files:
4 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);
Note: See TracChangeset for help on using the changeset viewer.