// Copyright 2000-2003, FreeHEP.
package hep.graphics.heprep.ref;

import java.awt.Color;
import java.io.*;
import java.util.*;

import hep.graphics.heprep.*;
import hep.graphics.heprep.util.*;


/**
 *
 * @author M.Donszelmann
 *
 * @version $Id: DefaultHepRepAttribute.java,v 1.26 2004/07/05 22:09:46 duns Exp $
 */

public abstract class DefaultHepRepAttribute implements HepRepAttribute, Serializable {
    public static final String cvsId = "$Id: DefaultHepRepAttribute.java,v 1.26 2004/07/05 22:09:46 duns Exp $";

    private Map/*<LowerCaseName, HepRepAttValue>*/ atts;

    protected DefaultHepRepAttribute() {
    }

    private void writeObject(ObjectOutputStream stream) throws IOException {
        stream.defaultWriteObject();
//        LinkedList.writeList(stream, attValueList);
    }

    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
//        System.out.println("DHRAttribute: Deserializing "+this);
        stream.defaultReadObject();
//        attValueList = LinkedList.readList(stream);
    }

    public Set/*<HepRepAttValue>*/ getAttValuesFromNode() {
        return new ValueSet(atts);
    }

    public void addAttValue(HepRepAttValue hepRepAttValue) {
        if (atts == null) atts = new Hashtable();
        atts.put(hepRepAttValue.getLowerCaseName(), hepRepAttValue);
    }

    public void addAttValue(String key, String value) {
        addAttValue(key, value, HepRepAttValue.SHOW_NONE);
    }

    public void addAttValue(String key, int value) {
        addAttValue(key, value, HepRepAttValue.SHOW_NONE);
    }

    public void addAttValue(String key, double value) {
        addAttValue(key, value, HepRepAttValue.SHOW_NONE);
    }

    public void addAttValue(String key, boolean value) {
        addAttValue(key, value, HepRepAttValue.SHOW_NONE);
    }

    public void addAttValue(String key, Color value) {
        addAttValue(key, value, HepRepAttValue.SHOW_NONE);
    }

    public void addAttValue(String key, String value, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
    }

    public void addAttValue(String key, int value, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
    }

    public void addAttValue(String key, double value, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
    }

    public void addAttValue(String key, boolean value, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
    }

    public void addAttValue(String key, Color value, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
    }

    public void addAttColor(String key, String colorName, int showLabel) {
        // FIXME: FREEHEP-368
        addAttValue(new DefaultHepRepAttValue(key, HepRepColor.get(colorName), showLabel));
    }

    public void addAttColor(String key, double r, double g, double b, double alpha, int showLabel) {
        addAttColor(key, r+", "+g+", "+b+", "+alpha, showLabel);
    }

    public void addAttValue(String name, String value, String type, int showLabel) {
        addAttValue(new DefaultHepRepAttValue(name, value, type, showLabel));
    }

    public HepRepAttValue getAttValueFromNode(String lowerCaseName) {
        if (atts == null) return null;
        return (HepRepAttValue)atts.get(lowerCaseName);
    }

    public HepRepAttValue removeAttValue(String key) {
        if (atts == null) return null;
        return (HepRepAttValue)atts.remove(key.toLowerCase());
    }
    
/* Disabled for FREEHEP-386
    public boolean equals(Object o) {
        if (o == this) return true;
        if (o instanceof HepRepAttribute) {
            HepRepAttribute att = (HepRepAttribute)o;
            if (att.getAttValuesFromNode().equals(getAttValuesFromNode())) return true;
            return false;
        }
        return false;
    }
    
    public int hashCode() {
        return (int)getAttValuesFromNode().hashCode();
    }
*/

    public abstract HepRepAttValue getAttValue(String name);
}

