/*
 * @(#)FigureAttributes.java 5.2
 *
 */

package CH.ifa.draw.figures;

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

import CH.ifa.draw.util.*;
import CH.ifa.draw.framework.*;

/**
 * A container for a figure's attributes. The attributes are stored
 * as key/value pairs.
 *
 * @see Figure
 */

public  class   FigureAttributes
        extends Object
        implements Cloneable, Serializable {

    private Hashtable fMap;

    /*
     * Serialization support.
     */
    private static final long serialVersionUID = -6886355144423666716L;
    private int figureAttributesSerializedDataVersion = 1;

    /**
     * Constructs the FigureAttributes.
     */
    public FigureAttributes() {
        fMap = new Hashtable();
    }

    /**
     * Gets the attribute with the given name.
     * @returns attribute or null if the key is not defined
     */
    public Object get(String name) {
        return fMap.get(name);
    }

    /**
     * Sets the attribute with the given name and
     * overwrites its previous value.
     */
    public void set(String name, Object value) {
    	if (value != null) {
        	fMap.put(name, value);
        }
        else {
        	fMap.remove(name);
        }
    }

    /**
     * Tests if an attribute is defined.
     */
    public boolean hasDefined(String name) {
        return fMap.containsKey(name);
    }

    /**
     * Clones the attributes.
     */
   public Object clone() {
        try {
            FigureAttributes a = (FigureAttributes) super.clone();
            a.fMap = (Hashtable) fMap.clone();
            return a;
        } catch (CloneNotSupportedException e) {
	        throw new InternalError();
        }
    }

    /**
     * Reads the attributes from a StorableInput.
     * FigureAttributes store the following types directly:
     * Color, Boolean, String, Int. Other attribute types
     * have to implement the Storable interface or they
     * have to be wrapped by an object that implements Storable.
     * @see Storable
     * @see #write
     */
    public void read(StorableInput dr) throws IOException {
        String s = dr.readString();
        if (!s.toLowerCase().equals("attributes"))
            throw new IOException("Attributes expected");

        fMap = new Hashtable();
        int size = dr.readInt();
        for (int i=0; i 

Ads help maintain this website.