/*
 * Created on 18.02.2005
 */
package alcatel.test;

import java.io.IOException;
import java.io.StringReader;

import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;

/**
 * @author Wolfgang Reh
 * 
 * SVGData holds the SVG data used to display in a table using the SVGTableCellRenderer
 */
public class SVGData
{
	SVGDocument DataDocument = null;
	String ToolTipText = null;
	
	/**
	 * <p>Default Constructor.</p>
	 */
	public SVGData()
	{
		;
	}
	
	/**
	 * <p>Create a SVGData object from a given String. This string must contain
	 * a valid SVG data structure.</p>
	 * 
	 * @param SVGContent String containing the SVG document.
	 */
	public SVGData(String SVGContent)
	{
		StringReader Reader = new StringReader(SVGContent);
		try
		{
			String Parser = XMLResourceDescriptor.getXMLParserClassName();
			SAXSVGDocumentFactory Factory = new SAXSVGDocumentFactory(Parser);
			DataDocument = Factory.createSVGDocument("http://alcatel.at/", Reader);
		}
		catch (Exception Exc)
		{
			Exc.printStackTrace();
		}		
	}
	
	/**
	 * <p>Creates a SVGData object with the given SVG document as content.</p>
	 *  
	 * @param NewDocument The document to use.
	 */
	public SVGData(SVGDocument NewDocument)
	{
		DataDocument = NewDocument;
	}
	
	/**
	 * <p>Retrieves the current document.</p>
	 * 
	 * @return Returns the dataDocument.
	 */
	public SVGDocument getDataDocument ()
	{
		return (DataDocument);
	}
	
	/**
	 * <p>Sets the document to display.</p>
	 * 
	 * @param dataDocument The dataDocument to set.
	 */
	public void setDataDocument (SVGDocument dataDocument)
	{
		DataDocument = dataDocument;
	}
	
	/**
	 * <p>Creates a SVG document from the string.</p>
	 *  
	 * @param SVGContent String containing the SVG document.
	 * @throws IOException if an error occurred while reading the document string.
	 */
	public void createSVGDocument(String SVGContent) throws IOException
	{
		StringReader Reader = new StringReader(SVGContent);
		String Parser = XMLResourceDescriptor.getXMLParserClassName();
		SAXSVGDocumentFactory Factory = new SAXSVGDocumentFactory(Parser);
		DataDocument = Factory.createSVGDocument("http://alcatel.at/", Reader);
	}
	
	/**
	 * <p>Change an attribute of the current document.</p>
	 * 
	 * @param TargetID The ID of the element.
	 * @param Attribute The attribute to change.
	 * @param Value The new value.
	 */
	public void changeAttribute(String TargetID, String Attribute, String Value)
	{
		if (DataDocument != null)
		{
			Element Target = DataDocument.getElementById(TargetID);
			if (Target != null)
				Target.setAttribute(Attribute, Value);
		}
	}
	
	/**
	 * <p>Retrieves the stored tooltip text.</p>
	 * @return Returns the toolTipText.
	 */
	public String getToolTipText ()
	{
		return (ToolTipText);
	}
	
	/**
	 * <p>Set the tooltip text to display for the table cell.</p>
	 * 
	 * @param toolTipText The toolTipText to set.
	 */
	public void setToolTipText (String toolTipText)
	{
		ToolTipText = toolTipText;
	}
}
