Changeset 12825
- Timestamp:
- 2006-09-22T09:47:10+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentControl.java
r12670 r12825 11 11 import java.util.Map; 12 12 import java.util.Iterator; 13 import java.util.HashMap;14 13 15 14 import org.greenstone.gatherer.Configuration; … … 30 29 31 30 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); 34 32 /** The Argument this control will be based on. */ 35 33 private Argument argument = null; … … 44 42 public ArgumentControl(Argument argument, boolean is_enabled, String preset_value) { 45 43 this.argument = argument; 46 ///ystem.err.println("generating controls for arg "+argument.getName()); 47 String tip = "<html>" + argument.get Description() + "</html>";48 tip = Utility.formatHTMLWidth(tip, 60);44 45 String tip = "<html>" + argument.getName()+": "+argument.getDescription() + "</html>"; 46 tip = Utility.formatHTMLWidth(tip, 80); 49 47 50 48 setBackground(Configuration.getColor("coloring.collection_tree_background", false)); 51 49 setBorder(BorderFactory.createEmptyBorder(2,0,2,0)); 52 50 setLayout(new BorderLayout()); 53 //setPreferredSize(ROW_SIZE); 54 setMaximumSize(ROW_SIZE); 51 setPreferredSize(ROW_SIZE); 55 52 56 53 if (argument.isRequired()) { … … 84 81 switch(argument.getType()) { 85 82 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 98 86 ((JComboBox)value_control).addActionListener(new ToolTipUpdater()); 99 selectValue((JComboBox)value_control, initial_value);100 87 break; 101 88 … … 237 224 // Listener 238 225 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 } 240 230 add(value_control, BorderLayout.CENTER); 241 231 if (!argument.isRequired()) { … … 266 256 return ((MetadataSet) selected_item).getNamespace(); 267 257 } 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; 270 260 } 271 261 if (selected_item instanceof MetadataElement) { … … 305 295 /** Updates the enwrapped Argument using the values provided by the controls. 306 296 * @return <i>true</i> if the update was successful, <i>false</i> otherwise. 307 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument Control.ListOption297 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument.ArgumentOption 308 298 * @see org.greenstone.gatherer.cdm.Language 309 299 */ … … 314 304 switch(argument.getType()) { 315 305 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); 319 309 } 320 310 else { … … 466 456 * @param target The desired value of the selection as a <strong>String</strong>. 467 457 * @return true if the item was found and selected, false otherwise 468 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument Control.ListOption458 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.Argument.ArgumentOption 469 459 */ 470 460 public static boolean selectValue(JComboBox combobox, String target) { … … 472 462 for(int i = 0; i < combobox.getItemCount(); i++) { 473 463 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; 476 466 ///ystem.err.print("/tChecking: " + lo.getValue() + "... "); 477 if( lo.getValue().startsWith(target)) {467 if(opt.name.startsWith(target)) { 478 468 ///ystem.err.println("Match!"); 479 469 combobox.setSelectedIndex(i); 470 combobox.setToolTipText(opt.getToolTip()); 480 471 return true; 481 472 } … … 553 544 554 545 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 ListOption558 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#compareTo579 */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 619 546 /** Listener that sets the tooltip associated to a combobox to the tooltip relevant to the selected item. */ 620 547 private class ToolTipUpdater … … 626 553 JComboBox source = (JComboBox)event.getSource(); 627 554 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()); 633 559 } 634 560 else {
Note:
See TracChangeset
for help on using the changeset viewer.