- Timestamp:
- 2004-01-09T15:08:11+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java
r6321 r6389 44 44 import javax.swing.event.*; 45 45 import javax.swing.text.*; 46 import org.greenstone.gatherer.Configuration; 46 47 import org.greenstone.gatherer.Dictionary; 47 48 import org.greenstone.gatherer.Gatherer; … … 69 70 static final public char UNKNOWN = 'x'; 70 71 72 static private int BUILD = 0; 73 static private int IMPORT = 1; 74 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 71 80 /** All process messages are written to this log text area. */ 72 81 public JTextArea log_textarea = null; … … 85 94 private Vector writing_documents; 86 95 87 static private int BUILD = 0;88 static private int IMPORT = 1;89 static private Dimension LABEL_SIZE = new Dimension(180, 25);90 static private Dimension ROW_SIZE = new Dimension(610, 25);91 static private Dimension SPINNER_SIZE = new Dimension(100, 25);92 static private String DESCRIPTION_SEP = " + ";93 94 96 95 97 /** The default constructor creates the few session length options, but either retrieves the rest from the current collection, or creates a default set of options. */ … … 105 107 106 108 /** This method creates the panel with all the build only options on it. 107 * @return A <strong>JPanel</strong> which can be used to display all the build only options. 109 * @param pane a JPanel which already has previous arguments available on it, to allow for lower moes to concatenate all of the arguments together 110 * @return a JPanel which can be used to display all the build only options 111 * @see org.greenstone.gatherer.Configuration#EXPERT_MODE 112 * @see org.greenstone.gatherer.Configuration#getColor 113 * @see org.greenstone.gatherer.Configuration#getMode 114 * @see org.greenstone.gatherer.Gatherer#config 115 * @see org.greenstone.gatherer.cdm.Argument 116 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildArgument 117 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildArgumentCount 118 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValue 119 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValueEnabled 120 * @see org.greenstone.gatherer.gui.OptionsPane#ArgumentControl 108 121 */ 109 public JPanel buildBuild() { 110 current_controls.clear(); 111 JPanel pane = new JPanel(); 112 pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); 113 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 114 int build_argument_count = build_options.getBuildArgumentCount(); 115 pane.setLayout(new GridLayout(build_argument_count, 1, 5, 5)); 116 for(int i = 0; i < build_argument_count; i++) { 122 public JPanel buildBuild(JPanel pane) { 123 // Reset the arguments 124 if(pane == null) { 125 current_controls.clear(); 126 } 127 ArrayList build_arguments = new ArrayList(); 128 int current_mode = Gatherer.config.getMode(); 129 int total_build_argument_count = build_options.getBuildArgumentCount(); 130 for(int i = 0; i < total_build_argument_count; i++) { 117 131 // Retrieve the argument so we know how to format the control. 118 132 Argument argument = build_options.getBuildArgument(i); 119 // Now attempt to retrieve any existing value for this argument. 120 boolean enabled = build_options.getBuildValueEnabled(argument.getName()); 121 String value = build_options.getBuildValue(argument.getName()); 122 ArgumentControl argument_control = new ArgumentControl(BUILD, argument, enabled, value); 123 pane.add(argument_control); 124 current_controls.add(argument_control); 133 if(!argument.isHiddenGLI() && argument.getModeLevel() <= current_mode) { 134 // Now attempt to retrieve any existing value for this argument. 135 boolean enabled = build_options.getBuildValueEnabled(argument.getName()); 136 String value = build_options.getBuildValue(argument.getName()); 137 ArgumentControl argument_control = new ArgumentControl(BUILD, argument, enabled, value); 138 build_arguments.add(argument_control); 139 } 140 } 141 current_controls.addAll(build_arguments); 142 // Now that we know how many arguments there are we can build the pane to view them on. Modes lower than EXPERT can provide a previous pane on which to add the arguments. 143 if(pane == null || current_mode >= Configuration.EXPERT_MODE) { 144 pane = new JPanel(); 145 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 146 pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); 147 int argument_count = build_arguments.size(); 148 // If in any of the higher detail modes, and assuming we don't want super phat argument controls, we better ensure there is a minimum number or lines in the grid layout 149 if(current_mode >= Configuration.EXPERT_MODE) { 150 if(argument_count < MINIMUM_ROWS) { 151 argument_count = MINIMUM_ROWS; 152 } 153 pane.setLayout(new GridLayout(argument_count, 1, 5, 5)); 154 } 155 // Otherwise we're just going to throw them on one after another and chuck it in a scroll pane anyway 156 else { 157 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); 158 } 159 } 160 for(int j = 0; j < build_arguments.size(); j++) { 161 pane.add((JComponent)build_arguments.get(j)); 125 162 } 126 163 pane.addMouseListener(this); 164 build_arguments = null; 127 165 return pane; 128 166 } 167 129 168 /** This method creates the panel with all the import only options on it. 130 * @return A <strong>JPanel</strong> which can be used to display all the import only options. 169 * @param pane a JPanel which already has previous arguments available on it, to allow for lower moes to concatenate all of the arguments together 170 * @return a JPanel which can be used to display all the build only options 171 * @see org.greenstone.gatherer.Configuration#EXPERT_MODE 172 * @see org.greenstone.gatherer.Configuration#getColor 173 * @see org.greenstone.gatherer.Configuration#getMode 174 * @see org.greenstone.gatherer.Gatherer#config 175 * @see org.greenstone.gatherer.cdm.Argument 176 * @see org.greenstone.gatherer.collection.BuildOptions#getImportArgument 177 * @see org.greenstone.gatherer.collection.BuildOptions#getImportArgumentCount 178 * @see org.greenstone.gatherer.collection.BuildOptions#getImportValue 179 * @see org.greenstone.gatherer.collection.BuildOptions#getImportValueEnabled 180 * @see org.greenstone.gatherer.gui.OptionsPane#ArgumentControl 131 181 */ 132 public JPanel buildImport() { 133 current_controls.clear(); 134 JPanel pane = new JPanel(); 135 pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); 136 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 137 int import_argument_count = build_options.getImportArgumentCount(); 138 pane.setLayout(new GridLayout(import_argument_count, 1, 5, 5)); 139 for(int i = 0; i < import_argument_count; i++) { 182 public JPanel buildImport(JPanel pane) { 183 // Reset the arguments 184 if(pane == null) { 185 current_controls.clear(); 186 } 187 ArrayList import_arguments = new ArrayList(); 188 int current_mode = Gatherer.config.getMode(); 189 int total_import_argument_count = build_options.getImportArgumentCount(); 190 for(int i = 0; i < total_import_argument_count; i++) { 140 191 // Retrieve the argument so we know how to format the control. 141 192 Argument argument = build_options.getImportArgument(i); 142 // Now attempt to retrieve any existing value for this argument. 143 boolean enabled = build_options.getImportValueEnabled(argument.getName()); 144 String value = build_options.getImportValue(argument.getName()); 145 ArgumentControl argument_control = new ArgumentControl(IMPORT, argument, enabled, value); 146 pane.add(argument_control); 147 current_controls.add(argument_control); 193 if(!argument.isHiddenGLI() && argument.getModeLevel() <= current_mode) { 194 // Now attempt to retrieve any existing value for this argument. 195 boolean enabled = build_options.getImportValueEnabled(argument.getName()); 196 String value = build_options.getImportValue(argument.getName()); 197 ArgumentControl argument_control = new ArgumentControl(IMPORT, argument, enabled, value); 198 import_arguments.add(argument_control); 199 } 200 } 201 current_controls.addAll(import_arguments); 202 // Now that we know how many arguments there are we can build the pane to view them on. Modes lower than EXPERT can provide a previous pane on which to add the arguments. 203 if(pane == null || current_mode >= Configuration.EXPERT_MODE) { 204 pane = new JPanel(); 205 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 206 pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); 207 int argument_count = import_arguments.size(); 208 // If in any of the higher detail modes, and assuming we don't want super phat argument controls, we better ensure there is a minimum number or lines in the grid layout 209 if(current_mode >= Configuration.EXPERT_MODE) { 210 if(argument_count < MINIMUM_ROWS) { 211 argument_count = MINIMUM_ROWS; 212 } 213 pane.setLayout(new GridLayout(argument_count, 1, 5, 5)); 214 } 215 // Otherwise we're just going to throw them on one after another and chuck it in a scroll pane anyway 216 else { 217 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); 218 } 219 } 220 for(int j = 0; j < import_arguments.size(); j++) { 221 pane.add((JComponent)import_arguments.get(j)); 148 222 } 149 223 pane.addMouseListener(this); 224 import_arguments = null; 150 225 return pane; 151 226 } 227 152 228 /** This method is used to build a panel based on the message log, which is nothing like any of the other panels. 153 229 * @return A <strong>JPanel</strong> containing a scrollable text area which represents the shell process message log. … … 322 398 setLayout(new BorderLayout()); 323 399 setPreferredSize(ROW_SIZE); 400 setMaximumSize(ROW_SIZE); 324 401 325 402 // Try to determine what the value_controls value should be. … … 425 502 value_control = textfield; 426 503 break; 504 case Argument.METADATUM: 505 GComboBox gcombobox = new GComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(), false); 506 gcombobox.setEnabled(enable); 507 // Now ensure we have the existing value or default value selected if either exist. 508 if(value != null) { 509 boolean found = selectValue(gcombobox, value); 510 // Its possible that this is a custom value and so doesn't exist in the combobox. If so add it and then select it 511 if(!found) { 512 gcombobox.addItem(value); 513 gcombobox.setSelectedItem(value); 514 } 515 } 516 add(gcombobox, BorderLayout.CENTER); 517 value_control = gcombobox; 518 break; 427 519 } 428 520 … … 454 546 } 455 547 548 /** Method to ensure that a certain value is selected, if it exists within that combobox to begin with. 549 * @param combobox the JComboBox whose selection we are trying to preset 550 * @param target The desired value of the selection as a String 551 * @return true if the item was found and selected, false otherwise 552 */ 553 public boolean selectValue(JComboBox combobox, String target) { 554 for(int i = 0; i < combobox.getItemCount(); i++) { 555 if(combobox.getItemAt(i).toString().equals(target)) { 556 combobox.setSelectedIndex(i); 557 return true; 558 } 559 } 560 return false; 561 } 562 456 563 /** Update the values stored in the collection so as to rememebr the current state of this argument. */ 457 564 public void update() { … … 472 579 } 473 580 else if(value_control instanceof JComboBox) { 474 value = ( String) ((JComboBox)value_control).getSelectedItem();475 } 476 581 value = (((JComboBox)value_control).getSelectedItem()).toString(); 582 } 583 // If this argument was a flag, but is now disabled, remove from the build options altogether 477 584 if(!enable && value == null) { 478 585 if(type == BUILD) { … … 483 590 } 484 591 } 485 592 // Otherwise update the argument value 486 593 else { 487 594 if(type == BUILD) { … … 638 745 public void valueChanged(ListSelectionEvent e) { 639 746 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one) 747 ///ystem.err.println("Log change detected."); 640 748 JList source = (JList)e.getSource(); 641 749 file_entry = (FileEntry) source.getSelectedValue(); 642 750 // First we determine if the old log has been completely written to file 643 751 Document document = log_textarea.getDocument(); 644 if(document instanceof AppendLineOnlyFileDocument) { 645 AppendLineOnlyFileDocument append_line_only_file_document = (AppendLineOnlyFileDocument) document; 752 ///ystem.err.println(" * current document: " + document); 753 ///ystem.err.println(" * new document: " + file_entry.getDocument()); 754 // If we are dealing with the same document don't do anything. 755 if(document != file_entry.getDocument()) { 756 if(document instanceof AppendLineOnlyFileDocument) { 757 AppendLineOnlyFileDocument append_line_only_file_document = (AppendLineOnlyFileDocument) document; 646 758 if(append_line_only_file_document.isStillWriting()) { 759 ///ystem.err.println("Current log is still active... finishing."); 647 760 writing_documents.add(append_line_only_file_document); // We have to maintain a reference until they are all done. 648 761 append_line_only_file_document.setOwner(OptionsPane.this); 649 762 append_line_only_file_document.setExit(); 650 763 } 651 } 652 // Load the new log 653 log_textarea.setDocument(file_entry.getDocument()); 764 else { 765 ///ystem.err.println("Current log is complete. Nothing to do."); 766 } 767 } 768 // Load the new log 769 log_textarea.setDocument(file_entry.getDocument()); 770 } 654 771 } 655 772 }
Note:
See TracChangeset
for help on using the changeset viewer.