Changeset 9139
- Timestamp:
- 2005-02-22T16:14:16+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/gui
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java
r9137 r9139 52 52 import org.greenstone.gatherer.collection.Collection; 53 53 import org.greenstone.gatherer.collection.CollectionManager; 54 import org.greenstone.gatherer.metadata.MetadataSetManager;55 54 import org.greenstone.gatherer.util.AppendLineOnlyFileDocument; 56 55 import org.greenstone.gatherer.util.AppendLineOnlyFileDocumentOwner; 57 import org.greenstone.gatherer.util.Utility;58 56 59 57 /** This class serves as the data holder for all subclasses of option panes, such as Import options or All options. It also contains methods for creating each of the option lines as they would appear in the subpane. Futhermore it has a method for considering all the arguments and generating a <strong>String[]</strong> to allow you to pass them to the <strong>GShell</strong>. … … 73 71 static private int IMPORT = 1; 74 72 static private int MINIMUM_ROWS = 11; 75 static private Dimension LABEL_SIZE = new Dimension(180, 25); 76 static private Dimension ROW_SIZE = new Dimension(610, 30); 77 static private Dimension SPINNER_SIZE = new Dimension(100, 25); 78 static private String DESCRIPTION_SEP = " + "; 79 73 80 74 /** All process messages are written to this log text area. */ 81 75 public JTextArea log_textarea = null; … … 120 114 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValue 121 115 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValueEnabled 122 * @see org.greenstone.gatherer.gui.OptionsPane. ArgumentControl116 * @see org.greenstone.gatherer.gui.OptionsPane.MyArgumentControl 123 117 */ 124 118 public JPanel buildBuild(JPanel pane) { … … 138 132 boolean enabled = build_options.getValueEnabled(argument.getName()); 139 133 String value = build_options.getValue(argument.getName()); 140 ArgumentControl argument_control = newArgumentControl(BUILD, argument, enabled, value);134 MyArgumentControl argument_control = new MyArgumentControl(BUILD, argument, enabled, value); 141 135 build_arguments.add(argument_control); 142 136 } … … 198 192 boolean enabled = import_options.getValueEnabled(argument.getName()); 199 193 String value = import_options.getValue(argument.getName()); 200 ArgumentControl argument_control = newArgumentControl(IMPORT, argument, enabled, value);194 MyArgumentControl argument_control = new MyArgumentControl(IMPORT, argument, enabled, value); 201 195 import_arguments.add(argument_control); 202 196 } … … 337 331 for(int i = 0; i < panel.getComponentCount(); i++) { 338 332 Component component = panel.getComponent(i); 339 if(component instanceof ArgumentControl) {340 (( ArgumentControl)component).update();333 if(component instanceof MyArgumentControl) { 334 ((MyArgumentControl)component).update(); 341 335 } 342 336 } … … 359 353 // Loop through the controls, and if the current control is a JSpinner, commit its current editing 360 354 for(int i = 0; i < current_controls.size(); i++) { 361 ArgumentControl control = (ArgumentControl) current_controls.get(i);355 MyArgumentControl control = (MyArgumentControl) current_controls.get(i); 362 356 JComponent value_control = control.getValueControl(); 363 357 if(value_control instanceof JSpinner) { … … 385 379 public void mouseReleased(MouseEvent e) {} 386 380 387 private class ArgumentControl 388 extends JPanel { 389 private Argument argument; 381 private class MyArgumentControl 382 extends ArgumentControl { 390 383 private int type; 391 private JComponent value_control; 392 private JCheckBox enabled; 393 public ArgumentControl(int type, Argument argument, boolean enable, String value) { 394 super(); 395 this.argument = argument; 384 385 public MyArgumentControl(int type, Argument argument, boolean enable, String value) { 386 super(argument, enable, value); 396 387 this.type = type; 397 String tooltip = Utility.formatHTMLWidth("<html>" + argument.getDescription() + "</html>", 60);398 // Because of the dynamic order of component creation/connection/layout, we can't really follow that pattern here.399 setBackground(Configuration.getColor("coloring.collection_tree_background", false));400 setBorder(BorderFactory.createEmptyBorder(2,0,2,0));401 setLayout(new BorderLayout());402 setPreferredSize(ROW_SIZE);403 setMaximumSize(ROW_SIZE);404 405 // Try to determine what the value_controls value should be.406 if(value == null) {407 value = argument.getDefaultValue();408 }409 // Create a correct value control based on the argument provided.410 switch(argument.getType()) {411 case Argument.ENUM:412 case Argument.METADATUM:413 JComboBox combobox = new JComboBox();414 combobox.setEnabled(enable);415 combobox.setToolTipText(tooltip);416 combobox.setBackground(enable ? Color.white : Color.lightGray);417 418 // Build an option model, wrapping each entry of the list table419 if (argument.getType() == Argument.ENUM) {420 HashMap arg_list = argument.getOptions();421 Iterator it = arg_list.keySet().iterator();422 while (it.hasNext()) {423 combobox.addItem((String) it.next());424 }425 426 // Connect this so if a value is selected the tooltip updates accordingly427 combobox.addActionListener(new ToolTipUpdater(arg_list));428 }429 if (argument.getType() == Argument.METADATUM) {430 ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement();431 for (int i = 0; i < every_metadata_set_element.size(); i++) {432 combobox.addItem(every_metadata_set_element.get(i));433 }434 }435 436 if (value != null) {437 // Set the selected string438 for (int i = 0; i < combobox.getItemCount(); i++) {439 if (combobox.getItemAt(i).toString().equals(value)) {440 combobox.setSelectedIndex(i);441 }442 }443 }444 // Layout445 add(combobox, BorderLayout.CENTER);446 // And remember447 value_control = combobox;448 break;449 case Argument.FLAG:450 // Only need the check box.451 value_control = null;452 break;453 case Argument.INTEGER:454 // Build a spinner455 int initial_value=0;456 if (value != null) {457 try {458 initial_value = Integer.parseInt(value);459 } catch (Exception exception) {460 }461 }462 if (initial_value < argument.getMinimum()) {463 initial_value = argument.getMinimum();464 } else if (initial_value > argument.getMaximum()) {465 initial_value = argument.getMaximum();466 }467 JSpinner spinner = new JSpinner(new SpinnerNumberModel(initial_value, argument.getMinimum(), argument.getMaximum(), 1));468 spinner.setEnabled(enable);469 spinner.setPreferredSize(SPINNER_SIZE);470 spinner.setToolTipText(tooltip);471 // Set enabled472 JComponent c = spinner.getEditor();473 if ( c instanceof JSpinner.DefaultEditor ) {474 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c;475 JFormattedTextField field = editor.getTextField();476 field.setEditable(enable);477 if(enable) {478 field.setBackground(Color.white);479 }480 else {481 field.setBackground(Color.lightGray);482 }483 }484 // Layout485 add(new JLabel(), BorderLayout.CENTER);486 add(spinner, BorderLayout.EAST);487 // And remember it488 value_control = spinner;489 break;490 case Argument.STRING:491 // Use a standard text field492 JTextField textfield = new JTextField();493 textfield.setEnabled(enable);494 textfield.setToolTipText(tooltip);495 // Set enabled496 if(enable) {497 textfield.setBackground(Color.white);498 }499 else {500 textfield.setBackground(Color.lightGray);501 }502 // If there was an original value, set it.503 if(value != null) {504 textfield.setText(value);505 }506 // Layout507 add(textfield, BorderLayout.CENTER);508 // And remember it509 value_control = textfield;510 break;511 }512 513 // If the argument is required, then you don't get a choice of whether it is enabled.514 if(argument.isRequired()) {515 JLabel label = new JLabel(argument.getName());516 label.setOpaque(false);517 label.setPreferredSize(LABEL_SIZE);518 label.setToolTipText(tooltip);519 add(label, BorderLayout.WEST);520 }521 else {522 enabled = new JCheckBox(argument.getName(), enable);523 enabled.setOpaque(false);524 enabled.setPreferredSize(LABEL_SIZE);525 enabled.setToolTipText(tooltip);526 // Connect527 enabled.addActionListener(new EnabledListener(value_control));528 // Layout529 add(enabled, BorderLayout.WEST);530 }531 }532 533 /** Retrieve the control used for storing values.534 * @return JComponent535 */536 public JComponent getValueControl() {537 return value_control;538 }539 540 /** Method to ensure that a certain value is selected, if it exists within that combobox to begin with.541 * @param combobox the JComboBox whose selection we are trying to preset542 * @param target The desired value of the selection as a String543 * @return true if the item was found and selected, false otherwise544 */545 public boolean selectValue(JComboBox combobox, String target) {546 for(int i = 0; i < combobox.getItemCount(); i++) {547 if(combobox.getItemAt(i).toString().equals(target)) {548 combobox.setSelectedIndex(i);549 return true;550 }551 }552 return false;553 388 } 554 389 … … 589 424 else { 590 425 import_options.setValue(name, enable, value); 591 }592 }593 }594 }595 596 /** Listens for actions apon the enable checkbox, and if detected enables or diables control appropriately. */597 private class EnabledListener598 implements ActionListener {599 /** An editor component, such as a JComboBox or JTextField, that might have its enabled state changed by this listener. */600 private JComponent target = null;601 /** Constructor. */602 public EnabledListener(JComponent target) {603 this.target = target;604 }605 /** Any implementation of ActionListener must include this method so that we can be informed when an action has been performed on or registered check box, prompting us to change the state of the other controls as per the users request.606 * @param event An <strong>ActionEvent</strong> containing information about the click.607 */608 public void actionPerformed(ActionEvent event) {609 JCheckBox source = (JCheckBox)event.getSource();610 if(target != null) {611 if(source.isSelected()) {612 target.setBackground(Color.white);613 target.setEnabled(true);614 }615 else {616 target.setBackground(Color.lightGray);617 target.setEnabled(false);618 }619 // Special case of stupid JSpinners who don't let their backgrounds change properly.620 if(target instanceof JSpinner) {621 JSpinner spinner = (JSpinner) target;622 JComponent c = spinner.getEditor();623 if ( c instanceof JSpinner.DefaultEditor ) {624 JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) c;625 JFormattedTextField field = editor.getTextField();626 field.setEditable(source.isSelected());627 if(source.isSelected()) {628 field.setBackground(Color.white);629 }630 else {631 field.setBackground(Color.lightGray);632 }633 }634 426 } 635 427 } … … 765 557 } 766 558 767 /** Listener that sets the tooltip associated to a combobox to the tooltip relevant to the selected item. */768 private class ToolTipUpdater769 implements ActionListener {770 private HashMap arg_list;771 public ToolTipUpdater(HashMap arg_list) {772 this.arg_list = arg_list;773 }774 /** Any implementation of an ActionListener must include this method so that we can be informed when the selection in a combobox has changed and update the tooltip accordingly.775 * @param event An <strong>ActionEvent</strong> containing information about the action that fired this call.776 */777 public void actionPerformed(ActionEvent event) {778 JComboBox source = (JComboBox)event.getSource();779 String key = (String) source.getSelectedItem();780 if(arg_list != null) {781 String description = (String) arg_list.get(key);782 if(description != null) {783 description = Utility.formatHTMLWidth(DESCRIPTION_SEP + description, 60);784 String original = source.getToolTipText();785 if(original == null) {786 original = "";787 }788 // Remove any existing extra description.789 if(original.indexOf(DESCRIPTION_SEP) != -1) {790 original = original.substring(0, original.indexOf(DESCRIPTION_SEP));791 }792 source.setToolTipText(original + description);793 }794 }795 }796 }797 559 }
Note:
See TracChangeset
for help on using the changeset viewer.