- Timestamp:
- 2003-07-15T13:55:22+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java
r4838 r4932 6 6 * University of Waikato, New Zealand. 7 7 * 8 * <BR><BR>9 *10 8 * Author: John Thompson, Greenstone Digital Library, University of Waikato 11 9 * 12 * <BR><BR>13 *14 10 * Copyright (C) 1999 New Zealand Digital Library Project 15 *16 * <BR><BR>17 11 * 18 12 * This program is free software; you can redistribute it and/or modify … … 21 15 * (at your option) any later version. 22 16 * 23 * <BR><BR>24 *25 17 * This program is distributed in the hope that it will be useful, 26 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 27 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 20 * GNU General Public License for more details. 29 *30 * <BR><BR>31 21 * 32 22 * You should have received a copy of the GNU General Public License … … 35 25 *######################################################################## 36 26 */ 37 38 39 40 41 42 43 /* GPL_HEADER */44 27 package org.greenstone.gatherer.cdm; 45 /************************************************************************************** 46 * Title: Gatherer 47 * Description: The Gatherer: a tool for gathering and enriching a digital collection. 48 * Company: The University of Waikato 49 * Written: 01/05/02 50 * Revised: 16/08/02 Optimized and Commented. Added destructor. 51 **************************************************************************************/ 52 import java.awt.BorderLayout; 53 import java.awt.Color; 54 import java.awt.Component; 55 import java.awt.Dimension; 56 import java.awt.GridLayout; 57 import java.awt.Toolkit; 58 import java.awt.event.ActionEvent; 59 import java.awt.event.ActionListener; 60 import java.awt.event.ItemEvent; 61 import java.awt.event.ItemListener; 62 import java.awt.event.KeyEvent; 63 import java.util.ArrayList; 64 import java.util.Collections; 65 import java.util.HashMap; 66 import java.util.Iterator; 67 import javax.swing.BorderFactory; 68 import javax.swing.BoxLayout; 69 import javax.swing.DefaultListModel; 70 import javax.swing.JButton; 71 import javax.swing.JCheckBox; 72 import javax.swing.JComboBox; 73 import javax.swing.JComponent; 74 import javax.swing.JDialog; 75 import javax.swing.JLabel; 76 import javax.swing.JList; 77 import javax.swing.JOptionPane; 78 import javax.swing.JPanel; 79 import javax.swing.JScrollPane; 80 import javax.swing.JTextField; 28 29 import java.awt.*; 30 import java.awt.event.*; 31 import java.util.*; 32 import javax.swing.*; 81 33 import org.greenstone.gatherer.Gatherer; 82 34 import org.greenstone.gatherer.cdm.Argument; … … 97 49 * @see org.greenstone.gatherer.cdm.PlugIn 98 50 */ 99 // ####################################################################################100 // Optimization Saving101 // ####################################################################################102 // Vector -> ArrayList + Processor103 // Hashtable -> HashMap + Processor104 // Remove several global references + Memory (1Kb+)105 // ####################################################################################106 107 51 public class ArgumentConfiguration 108 52 extends ModalDialog … … 114 58 /** Whether we have successfully edited the arguments associated with the ArgumentContainer or if we have failed to enter required arguments and have instead cancelled (which would cause argument additions to roll back). */ 115 59 private boolean success = false; 116 /** A reference to the main CollectionDesignManager class for access to other managers. */117 private CollectionDesignManager manager = null;118 /** A reference to the Gatherer. */119 private Gatherer gatherer = null;120 60 /** A button to cancel this dialog. */ 121 61 private JButton cancel = null; … … 137 77 static final private Dimension SIZE = new Dimension(800, 425); 138 78 /** Constructor. 139 * @param gatherer A reference to the <strong>Gatherer</strong>.140 * @param manager The <strong>CollectionDesignManager</strong> for access to other configuration managers.141 79 * @param data The plugin or classifier whose arguments we are configuring, in the form of its supported <strong>ArgumentContainer</strong> interface. 142 80 * @see org.greenstone.gatherer.Configuration 143 81 */ 144 public ArgumentConfiguration( Gatherer gatherer, CollectionDesignManager manager,ArgumentContainer data) {145 super( gatherer.g_man);82 public ArgumentConfiguration(ArgumentContainer data) { 83 super(Gatherer.g_man); 146 84 this.data = data; 147 this.gatherer = gatherer;148 this.manager = manager;149 85 this.self = this; 150 86 String custom_str = data.getCustom(); … … 210 146 211 147 // Display on screen. 212 Dimension screen_size = gatherer.config.screen_size;148 Dimension screen_size = Gatherer.config.screen_size; 213 149 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 214 150 screen_size = null; … … 223 159 if(event.getSource() == ok) { 224 160 // Update the details stored in the data objects arguments. 225 if(custom.getText().length() > 0) { 226 data.setCustom(custom.getText()); 227 } 161 data.setCustom(custom.getText()); 228 162 // Loop through each of the controls in the central pane, updating the matching argument as necessary. 229 163 for(int i = 0; i < central_pane.getComponentCount(); i++) { … … 248 182 custom = null; 249 183 data = null; 250 gatherer = null;251 manager = null;252 184 ok = null; 253 185 self = null; … … 285 217 */ 286 218 private void generateControls() { 287 ArrayList arguments = data.getArguments( );219 ArrayList arguments = data.getArguments(true, false); 288 220 int total_height = 250; 289 221 int size = arguments.size(); … … 317 249 key = "CDM.ArgumentConfiguration." + key; 318 250 } 319 return gatherer.dictionary.get(key, args);251 return Gatherer.dictionary.get(key, args); 320 252 } 321 253 /** This class encapsulates all the technical difficulty of creating a specific control based on an Argument. */ … … 324 256 /** The Argument this control will be based on. */ 325 257 private Argument argument = null; 258 259 private Color colour_one = Gatherer.config.getColor("coloring.collection_heading_background", false); 260 private Color colour_two = Gatherer.config.getColor("coloring.collection_tree_background", false); 326 261 /** One of a possible two buttons available for adding to this control. */ 327 262 private JButton one = null; … … 345 280 public ArgumentControl(Argument argument) { 346 281 this.argument = argument; 347 String tip = "<html>" + argument.getDesc () + "</html>";282 String tip = "<html>" + argument.getDescription() + "</html>"; 348 283 tip = Utility.formatHTMLWidth(tip, 60); 349 284 // If this is the first control, there is no history. 350 285 if(previous_owner == null) { 351 286 previous_owner = argument.getOwner(); 352 addHeader(previous_owner, Color.white);287 addHeader(previous_owner, colour_one); 353 288 } 354 289 // Otherwise if the owner of the control has changed since the last argument, toggle the colouring of the control. … … 356 291 coloured = !coloured; 357 292 previous_owner = argument.getOwner(); 358 addHeader(previous_owner, (coloured ? Gatherer.config.getColor("coloring.collection_tree_background", false) : Color.white));293 addHeader(previous_owner, (coloured ? colour_two : colour_one)); 359 294 } 360 295 // Create 361 296 if(coloured) { 362 setBackground( Gatherer.config.getColor("coloring.collection_tree_background", false));297 setBackground(colour_one); 363 298 } 364 299 else { 365 setBackground( Color.white);300 setBackground(colour_two); 366 301 } 367 302 JLabel owner_label = new JLabel(argument.getOwner()); … … 382 317 case Argument.ENUM: 383 318 // Build an option model, wrapping each entry of the list table. 384 HashMap arg_list = argument.get List();319 HashMap arg_list = argument.getOptions(); 385 320 ArrayList options_model = new ArrayList(); 386 321 Iterator it = arg_list.keySet().iterator(); … … 405 340 break; 406 341 case Argument.HIERARCHY: 407 value = new JComboBox( gatherer.c_man.msm.getAssignedElements(true));342 value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(true)); 408 343 /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */ 409 344 ((JComboBox)value).setEditable(true); … … 450 385 break; 451 386 case Argument.LANGUAGE: 452 value = new JComboBox( manager.languages.getLanguageCodes().toArray());387 value = new JComboBox(CollectionDesignManager.language_manager.getLanguageCodes().toArray()); 453 388 // Now ensure we have the existing value or default value selected if either exist. 454 389 Language selected = null; 455 390 if(existing_value != null) { 456 selected = manager.languages.getLanguage(existing_value, false);391 selected = CollectionDesignManager.language_manager.getLanguage(existing_value); 457 392 } 458 393 else if(default_value != null) { 459 selected = manager.languages.getLanguage(default_value, false);394 selected = CollectionDesignManager.language_manager.getLanguage(default_value); 460 395 } 461 396 if(selected != null) { 462 ((JComboBox)value).setSelectedItem(selected );397 ((JComboBox)value).setSelectedItem(selected.getCode()); 463 398 } 464 399 break; 465 case Argument.METADAT A:466 value = new JComboBox( gatherer.c_man.msm.getAssignedElements());400 case Argument.METADATUM: 401 value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements()); 467 402 /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */ 468 403 ((JComboBox)value).setEditable(true); … … 475 410 } 476 411 break; 477 case Argument.METADAT UM:412 case Argument.METADATA: 478 413 // Comma separated metadata values. 479 414 ArrayList values = argument.getValues(); 480 value = new JComboBox( gatherer.c_man.msm.getAssignedElements());415 value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements()); 481 416 DefaultListModel model = new DefaultListModel(); 482 417 list = new JList(model); … … 566 501 add(inner_pane, BorderLayout.CENTER); 567 502 } 503 568 504 public Object getValue() { 569 505 if(value instanceof JComboBox) { … … 650 586 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 651 587 return true; 652 case Argument.METADATA: 653 // I feel like a cast-away 654 argument.setElementValue((ElementWrapper)((JComboBox)value).getSelectedItem()); 655 return true; 588 case Argument.METADATUM: 656 589 case Argument.HIERARCHY: 657 590 argument.setValue(((JComboBox)value).getSelectedItem().toString()); 658 591 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 659 592 return true; 660 case Argument.METADAT UM:593 case Argument.METADATA: 661 594 DefaultListModel model = (DefaultListModel)list.getModel(); 662 595 ArrayList values = new ArrayList(); … … 743 676 this.target = target; 744 677 } 745 746 747 748 678 /** When the add button is clicked, we attempt to add the selected metadata from the source into the target. 679 * @param event An <strong>ActionEvent</strong> containing information about the event. 680 * @see org.greenstone.gatherer.msm.ElementWrapper 681 */ 749 682 public void actionPerformed(ActionEvent event) { 750 683 ElementWrapper element = (ElementWrapper) source.getSelectedItem(); 751 String name = element. getName();684 String name = element.toString(); 752 685 if(!model.contains(name)) { 753 686 boolean found = false;
Note:
See TracChangeset
for help on using the changeset viewer.