/*
 * Created on 2004/06/11
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package jp.riken.brain.ni.samuraigraph.figure.java2d;

import jp.riken.brain.ni.samuraigraph.base.SGIGraphElement;
import jp.riken.brain.ni.samuraigraph.base.SGProperties;

import org.w3c.dom.Element;



/**
 * @author kuromaru
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public abstract class SGElementGroupSetInFigureElement extends SGElementGroupSet
{

	/**
	 *
	 */
	protected String mName = null;

	
	/**
	 * 
	 */
	protected boolean mVisibleInLegendFlag = true;
	

	/**
	 * 
	 */
	public SGElementGroupSetInFigureElement()
	{
		super();
	}


	/**
	 *
	 */
	public boolean setName( final String name )
	{
		this.mName = new String( name );
		return true;
	}


	/**
	 * 
	 * @param b
	 * @return
	 */
	public boolean setVisibleInLegend( final boolean b )
	{
		this.mVisibleInLegendFlag = b;
		return true;
	}
	

	/**
	 * 
	 */
	public String getName()
	{
		return mName;
	}


	/**
	 * 
	 * @return
	 */
	public boolean isVisibleInLegend()
	{
		return this.mVisibleInLegendFlag;
	}

	
	/**
	 * 
	 */
	public boolean writeProperty( final Element el )
	{
		el.setAttribute( SGIGraphElement.KEY_DATA_NAME, this.mName );
		el.setAttribute(
			SGIGraphElement.KEY_VISIBLE_IN_LEGEND,
			Boolean.toString( this.mVisibleInLegendFlag )
		);
		return true;
	}

	

	/**
	 * 
	 */
	public SGProperties getProperties()
	{
		ElementGroupSetPropertiesInFigureElement ep = new ElementGroupSetPropertiesInFigureElement();
		if( this.getProperties(ep) == false )
		{
			return null;
		}

		return ep;
	}


	/**
	 * 
	 */
	public boolean getProperties( final SGProperties p )
	{
		if( ( p instanceof ElementGroupSetPropertiesInFigureElement ) == false ) return false;

		if( super.getProperties(p) == false ) return false;

		ElementGroupSetPropertiesInFigureElement ep = (ElementGroupSetPropertiesInFigureElement)p;

		ep.name = new String( this.mName );
		ep.visibleInLegend = this.mVisibleInLegendFlag;

		return true;
	}



	/**
	 * 
	 */
	public boolean setProperties( final SGProperties p )
	{
		if( ( p instanceof ElementGroupSetPropertiesInFigureElement ) == false ) return false;

		if( super.setProperties(p) == false ) return false;

		ElementGroupSetPropertiesInFigureElement ep = (ElementGroupSetPropertiesInFigureElement)p;

		this.mName = new String( ep.name );
		this.mVisibleInLegendFlag = ep.visibleInLegend;

		return true;
	}



	/**
	 * 
	 */
	public static class ElementGroupSetPropertiesInFigureElement
		extends ElementGroupSetProperties
	{

		// name of data
		String name;

		// visible in legend
		boolean visibleInLegend;

		
		/**
		 * 
		 *
		 */
		public ElementGroupSetPropertiesInFigureElement()
		{
			super();
		}



		/**
		 * 
		 */
		public boolean equals( final Object obj )
		{

			if( ( obj instanceof ElementGroupSetPropertiesInFigureElement ) == false )
			{
				return false;
			}

			if( super.equals(obj) == false ) return false;

			ElementGroupSetPropertiesInFigureElement p = (ElementGroupSetPropertiesInFigureElement)obj;

			if( p.name.equals(this.name) == false ) return false;
			if( p.visibleInLegend!=this.visibleInLegend ) return false;

			return true;

		}


		/**
		 * 
		 */
		public String toString()
		{
			String str = new String("[");
			str += super.toString();
			str += new String("name="+name+", ");
			str += new String("visibleInLegend="+visibleInLegend+", ");
			str += new String("]");

			return str;
		}
		
	}




}
