Ignore:
Timestamp:
2003-07-15T13:55:22+12:00 (21 years ago)
Author:
jmt12
Message:

Major CDM rewrite so it uses DOM.

File:
1 edited

Legend:

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

    r4838 r4932  
    66 * University of Waikato, New Zealand.
    77 *
    8  * <BR><BR>
    9  *
    108 * Author: John Thompson, Greenstone Digital Library, University of Waikato
    119 *
    12  * <BR><BR>
    13  *
    1410 * Copyright (C) 1999 New Zealand Digital Library Project
    15  *
    16  * <BR><BR>
    1711 *
    1812 * This program is free software; you can redistribute it and/or modify
     
    2115 * (at your option) any later version.
    2216 *
    23  * <BR><BR>
    24  *
    2517 * This program is distributed in the hope that it will be useful,
    2618 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2719 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2820 * GNU General Public License for more details.
    29  *
    30  * <BR><BR>
    3121 *
    3222 * You should have received a copy of the GNU General Public License
     
    3525 *########################################################################
    3626 */
    37 
    38  
    39 
    40 
    41 
    42 
    43 /* GPL_HEADER */
    4427package 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
     29import java.awt.*;
     30import java.awt.event.*;
     31import java.util.*;
     32import javax.swing.*;
    8133import org.greenstone.gatherer.Gatherer;
    8234import org.greenstone.gatherer.cdm.Argument;
     
    9749 * @see org.greenstone.gatherer.cdm.PlugIn
    9850 */
    99 // ####################################################################################
    100 // Optimization                          Saving
    101 // ####################################################################################
    102 // Vector -> ArrayList                   + Processor
    103 // Hashtable -> HashMap                  + Processor
    104 // Remove several global references      + Memory (1Kb+)
    105 // ####################################################################################
    106 
    10751public class ArgumentConfiguration
    10852    extends ModalDialog
     
    11458    /** 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). */
    11559    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;
    12060    /** A button to cancel this dialog. */
    12161    private JButton cancel = null;
     
    13777    static final private Dimension SIZE = new Dimension(800, 425);
    13878    /** Constructor.
    139      * @param gatherer A reference to the <strong>Gatherer</strong>.
    140      * @param manager The <strong>CollectionDesignManager</strong> for access to other configuration managers.
    14179     * @param data The plugin or classifier whose arguments we are configuring, in the form of its supported <strong>ArgumentContainer</strong> interface.
    14280     * @see org.greenstone.gatherer.Configuration
    14381     */
    144     public ArgumentConfiguration(Gatherer gatherer, CollectionDesignManager manager, ArgumentContainer data) {
    145     super(gatherer.g_man);
     82    public ArgumentConfiguration(ArgumentContainer data) {
     83    super(Gatherer.g_man);
    14684    this.data = data;
    147     this.gatherer = gatherer;
    148     this.manager = manager;
    14985    this.self = this;
    15086    String custom_str = data.getCustom();
     
    210146
    211147    // Display on screen.
    212     Dimension screen_size = gatherer.config.screen_size;
     148    Dimension screen_size = Gatherer.config.screen_size;
    213149    setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
    214150    screen_size = null;
     
    223159    if(event.getSource() == ok) {
    224160        // 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());
    228162        // Loop through each of the controls in the central pane, updating the matching argument as necessary.
    229163        for(int i = 0; i < central_pane.getComponentCount(); i++) {
     
    248182    custom = null;
    249183    data = null;
    250     gatherer = null;
    251     manager = null;
    252184    ok = null;
    253185    self = null;
     
    285217      */
    286218    private void generateControls() {
    287     ArrayList arguments = data.getArguments();
     219    ArrayList arguments = data.getArguments(true, false);
    288220    int total_height = 250;
    289221    int size = arguments.size();
     
    317249        key = "CDM.ArgumentConfiguration." + key;
    318250    }
    319     return gatherer.dictionary.get(key, args);
     251    return Gatherer.dictionary.get(key, args);
    320252    }
    321253    /** This class encapsulates all the technical difficulty of creating a specific control based on an Argument. */
     
    324256    /** The Argument this control will be based on. */
    325257    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);
    326261    /** One of a possible two buttons available for adding to this control. */
    327262    private JButton one = null;
     
    345280    public ArgumentControl(Argument argument) {
    346281        this.argument = argument;
    347         String tip = "<html>" + argument.getDesc() + "</html>";
     282        String tip = "<html>" + argument.getDescription() + "</html>";
    348283        tip = Utility.formatHTMLWidth(tip, 60);
    349284        // If this is the first control, there is no history.
    350285        if(previous_owner == null) {
    351286        previous_owner = argument.getOwner();
    352         addHeader(previous_owner, Color.white);
     287        addHeader(previous_owner, colour_one);
    353288        }
    354289        // Otherwise if the owner of the control has changed since the last argument, toggle the colouring of the control.
     
    356291        coloured = !coloured;
    357292        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));
    359294        }
    360295        // Create
    361296        if(coloured) {
    362         setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
     297        setBackground(colour_one);
    363298        }
    364299        else {
    365         setBackground(Color.white);
     300        setBackground(colour_two);
    366301        }
    367302        JLabel owner_label = new JLabel(argument.getOwner());
     
    382317        case Argument.ENUM:
    383318        // Build an option model, wrapping each entry of the list table.
    384         HashMap arg_list = argument.getList();
     319        HashMap arg_list = argument.getOptions();
    385320        ArrayList options_model = new ArrayList();
    386321        Iterator it = arg_list.keySet().iterator();
     
    405340        break;
    406341        case Argument.HIERARCHY:
    407         value = new JComboBox(gatherer.c_man.msm.getAssignedElements(true));
     342        value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(true));
    408343        /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */
    409344        ((JComboBox)value).setEditable(true);
     
    450385        break;
    451386        case Argument.LANGUAGE:
    452         value = new JComboBox(manager.languages.getLanguageCodes().toArray());
     387        value = new JComboBox(CollectionDesignManager.language_manager.getLanguageCodes().toArray());
    453388        // Now ensure we have the existing value or default value selected if either exist.
    454389        Language selected = null;
    455390        if(existing_value != null) {
    456             selected = manager.languages.getLanguage(existing_value, false);
     391            selected = CollectionDesignManager.language_manager.getLanguage(existing_value);
    457392        }
    458393        else if(default_value != null) {
    459             selected = manager.languages.getLanguage(default_value, false);
     394            selected = CollectionDesignManager.language_manager.getLanguage(default_value);
    460395        }
    461396        if(selected != null) {
    462             ((JComboBox)value).setSelectedItem(selected);
     397            ((JComboBox)value).setSelectedItem(selected.getCode());
    463398        }
    464399        break;
    465         case Argument.METADATA:
    466         value = new JComboBox(gatherer.c_man.msm.getAssignedElements());
     400        case Argument.METADATUM:
     401        value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements());
    467402        /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */
    468403        ((JComboBox)value).setEditable(true);
     
    475410        }
    476411        break;
    477         case Argument.METADATUM:
     412        case Argument.METADATA:
    478413        // Comma separated metadata values.
    479414        ArrayList values = argument.getValues();
    480         value = new JComboBox(gatherer.c_man.msm.getAssignedElements());
     415        value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements());
    481416        DefaultListModel model = new DefaultListModel();
    482417        list = new JList(model);
     
    566501        add(inner_pane, BorderLayout.CENTER);
    567502    }
     503
    568504    public Object getValue() {
    569505        if(value instanceof JComboBox) {
     
    650586            // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
    651587            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:
    656589        case Argument.HIERARCHY:
    657590            argument.setValue(((JComboBox)value).getSelectedItem().toString());
    658591            // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
    659592            return true;
    660         case Argument.METADATUM:
     593        case Argument.METADATA:
    661594            DefaultListModel model = (DefaultListModel)list.getModel();
    662595            ArrayList values = new ArrayList();
     
    743676        this.target = target;
    744677        }
    745         /** When the add button is clicked, we attempt to add the selected metadata from the source into the target.
    746         * @param event An <strong>ActionEvent</strong> containing information about the event.
    747         * @see org.greenstone.gatherer.msm.ElementWrapper
    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                */
    749682        public void actionPerformed(ActionEvent event) {
    750683        ElementWrapper element = (ElementWrapper) source.getSelectedItem();
    751         String name = element.getName();
     684        String name = element.toString();
    752685        if(!model.contains(name)) {
    753686            boolean found = false;
Note: See TracChangeset for help on using the changeset viewer.