Changeset 12825


Ignore:
Timestamp:
2006-09-22T09:47:10+12:00 (18 years ago)
Author:
kjdon
Message:

ListOption changed to Argument.ArgumentOption, options now comes from the arg in an ArrayList not a HashMap. Set initial tooltip for enums to be correct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentControl.java

    r12670 r12825  
    1111import java.util.Map;
    1212import java.util.Iterator;
    13 import java.util.HashMap;
    1413
    1514import org.greenstone.gatherer.Configuration;
     
    3029
    3130    static protected Dimension LABEL_SIZE = new Dimension(175, 25);
    32     static protected Dimension ROW_SIZE = new Dimension(800, 30);
    33 
     31    static protected Dimension ROW_SIZE = new Dimension(400, 30);
    3432    /** The Argument this control will be based on. */
    3533    private Argument argument = null;
     
    4442    public ArgumentControl(Argument argument, boolean is_enabled, String preset_value) {
    4543    this.argument = argument;
    46     ///ystem.err.println("generating controls for arg "+argument.getName());
    47     String tip = "<html>" + argument.getDescription() + "</html>";
    48     tip = Utility.formatHTMLWidth(tip, 60);
     44
     45    String tip = "<html>" + argument.getName()+": "+argument.getDescription() + "</html>";
     46    tip = Utility.formatHTMLWidth(tip, 80);
    4947
    5048    setBackground(Configuration.getColor("coloring.collection_tree_background", false));
    5149    setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
    5250    setLayout(new BorderLayout());
    53     //setPreferredSize(ROW_SIZE);
    54     setMaximumSize(ROW_SIZE);
     51    setPreferredSize(ROW_SIZE);
    5552
    5653    if (argument.isRequired()) {
     
    8481    switch(argument.getType()) {
    8582    case Argument.ENUM:
    86         // Build an option model, wrapping each entry of the list table.
    87         HashMap arg_list = argument.getOptions();
    88         ArrayList options_model = new ArrayList();
    89         Iterator it = arg_list.entrySet().iterator();
    90         while(it.hasNext()) {
    91         Map.Entry e = (Map.Entry)it.next();
    92         //String key = (String) it.next();
    93         //options_model.add(new ListOption(key, (String)arg_list.get(key)));
    94         options_model.add(new ListOption((String)e.getKey(), (String)e.getValue()));
    95         }
    96         Collections.sort(options_model);
    97         value_control = new GComboBox(options_model.toArray(), false);
     83        ArrayList option_list = argument.getOptions();
     84        value_control = new GComboBox(option_list.toArray(), false, false);
     85        selectValue((JComboBox)value_control, initial_value); // also sets the tooltip
    9886        ((JComboBox)value_control).addActionListener(new ToolTipUpdater());
    99         selectValue((JComboBox)value_control, initial_value);
    10087        break;
    10188       
     
    237224    // Listener
    238225    if(value_control != null) {
    239         value_control.setToolTipText(tip);
     226        if (argument.getType() != Argument.ENUM) {
     227        // enums have already set tooltips based on option value
     228        value_control.setToolTipText(tip);
     229        }
    240230        add(value_control, BorderLayout.CENTER);
    241231        if (!argument.isRequired()) {
     
    266256            return ((MetadataSet) selected_item).getNamespace();
    267257        }
    268         if (selected_item instanceof ListOption) {
    269             return ((ListOption)selected_item).getValue();
     258        if (selected_item instanceof Argument.ArgumentOption) {
     259            return ((Argument.ArgumentOption)selected_item).name;
    270260        }
    271261        if (selected_item instanceof MetadataElement) {
     
    305295    /** Updates the enwrapped Argument using the values provided by the controls.
    306296     * @return <i>true</i> if the update was successful, <i>false</i> otherwise.
    307      * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl.ListOption
     297     * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument.ArgumentOption
    308298     * @see org.greenstone.gatherer.cdm.Language
    309299     */
     
    314304        switch(argument.getType()) {
    315305        case Argument.ENUM:
    316         ListOption option = (ListOption)((JComboBox)value_control).getSelectedItem();
    317         if(option != null && option.getValue().length() > 0) {
    318             argument.setValue(option.getValue());
     306        Argument.ArgumentOption option = (Argument.ArgumentOption)((JComboBox)value_control).getSelectedItem();
     307        if(option != null && option.name.length() > 0) {
     308            argument.setValue(option.name);
    319309        }
    320310        else {
     
    466456     * @param target The desired value of the selection as a <strong>String</strong>.
    467457     * @return true if the item was found and selected, false otherwise
    468      * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl.ListOption
     458     * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument.ArgumentOption
    469459     */
    470460    public static boolean selectValue(JComboBox combobox, String target) {
     
    472462    for(int i = 0; i < combobox.getItemCount(); i++) {
    473463        Object object = combobox.getItemAt(i);
    474         if(object instanceof ListOption) {
    475         ListOption lo = (ListOption) object;
     464        if(object instanceof Argument.ArgumentOption) {
     465        Argument.ArgumentOption opt = (Argument.ArgumentOption) object;
    476466        ///ystem.err.print("/tChecking: " + lo.getValue() + "... ");
    477         if(lo.getValue().startsWith(target)) {
     467        if(opt.name.startsWith(target)) {
    478468            ///ystem.err.println("Match!");
    479469            combobox.setSelectedIndex(i);
     470            combobox.setToolTipText(opt.getToolTip());
    480471            return true;
    481472        }
     
    553544   
    554545
    555 
    556     /** A ListOption is a compound item which is constructed from several Strings. That magic part is that the length of screen real-estate used by the text version of this item is limited. */
    557     private class ListOption
    558     implements Comparable {
    559     /** The maximum length of this String version of this item. */
    560     private int MAX_DESC = 47;
    561     /** The description of the value for this item. */
    562     private String description = null;
    563     /** A cached value for the text value of this option, as it never changes after the first call to toString(). */
    564     private String text = null;
    565     /** The value for this item. */
    566     private String value = null;
    567     /** Constructor.
    568      * @param value The value for this item as a <strong>String</strong>.
    569      * @param description The description of the value as a <strong>String</strong>.
    570      */
    571     public ListOption(String value, String description) {
    572         this.description = description;
    573         this.value = value;
    574     }
    575     /** Compare two possible ListOption objects for ordering.
    576      * @param object The <strong>Object</strong> to compare to.
    577      * @return An <i>int</i> indicating order as explained in String.
    578      * @see java.lang.String#compareTo
    579      */
    580     public int compareTo(Object object) {
    581         return toString().compareTo(object.toString());
    582     }
    583     /** Tests two possible ListOption objects for equality. Uses the result from compareTo().
    584      * @param object The <strong>Object</strong> which may be equal.
    585      * @return <i>true</i> if the objects are equal, <i>false</i> otherwise.
    586      */
    587     public boolean equals(Object object) {
    588         return (object != null && compareTo(object) == 0);
    589     }
    590     /** Retrieve the description of this list item.
    591      * @return The description as a <strong>String</strong>.
    592      */
    593     public String getDesc() {
    594         return description;
    595     }
    596     /** Retrieve the value of this list item.
    597      * @return The value as a <strong>String</strong>.
    598      */
    599     public String getValue() {
    600         return value;
    601     }
    602     /** Convert this object into a nice readable String.
    603      * @return A <strong>String</strong> representing this object.
    604      */
    605     public String toString() {
    606         if(text == null) {
    607         if(value.length() + description.length() >= MAX_DESC) {
    608             text = value + " "+ StaticStrings.MINUS_CHARACTER + " "+ description.substring(0, MAX_DESC-value.length()) + StaticStrings.TRUNCATED_STRING;
    609         }
    610         else {
    611             text = value + " "+ StaticStrings.MINUS_CHARACTER + " "+ description;
    612         }
    613         }
    614         return text;
    615     }
    616     }
    617 
    618 
    619546    /** Listener that sets the tooltip associated to a combobox to the tooltip relevant to the selected item. */
    620547    private class ToolTipUpdater
     
    626553        JComboBox source = (JComboBox)event.getSource();
    627554        Object object = source.getSelectedItem();
    628         if(object instanceof ListOption) {
    629         ListOption lo = (ListOption)object;
    630         if(lo != null) {
    631             String description = Utility.formatHTMLWidth(lo.getDesc(), 60);
    632             source.setToolTipText(description);
     555        if(object instanceof Argument.ArgumentOption) {
     556        Argument.ArgumentOption opt = (Argument.ArgumentOption)object;
     557        if(opt != null) {
     558            source.setToolTipText(opt.getToolTip());
    633559        }
    634560        else {
Note: See TracChangeset for help on using the changeset viewer.