001: /*
002: * Layer.java
003: *
004: * Created on 23 January 2007, 17:15
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package com.xoetrope.svg;
011:
012: import com.kitfox.svg.Group;
013: import com.kitfox.svg.SVGDiagram;
014: import com.kitfox.svg.SVGElement;
015: import com.kitfox.svg.SVGElementException;
016: import com.kitfox.svg.SVGException;
017: import com.kitfox.svg.SVGRoot;
018: import com.kitfox.svg.animation.AnimationElement;
019: import com.xoetrope.carousel.build.BuildProperties;
020: import com.xoetrope.svg.XSvgImageMap;
021:
022: /**
023: *
024: *
025: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
026: * the GNU Public License (GPL), please see license.txt for more details. If
027: * you make commercial use of this software you must purchase a commercial
028: * license from Xoetrope.</p>
029: * <p> $Revision: 1.2 $</p>
030: */
031: public class XSvgLayer extends Group {
032: protected SVGRoot root;
033: protected String name;
034:
035: /**
036: * Creates a new instance of SvgLayer
037: * @param name <CODE>String</CODE> specifying the name to be given to the layer.
038: * @param imageMap <CODE>XSvgImageMap</CODE> instance that will contain the new layer.
039: */
040: public XSvgLayer(String name, XSvgImageMap imageMap) {
041: this .name = name;
042: root = imageMap.getSvgDiagram().getRoot();
043: }
044:
045: /**
046: * Set the SVG image map for the layer.
047: * @param imageMap <CODE>XSvgImageMap</CODE> instance that will contain the new layer.
048: */
049: public void setImageMap(XSvgImageMap imageMap) {
050: root = imageMap.getSvgDiagram().getRoot();
051: }
052:
053: /**
054: * Used to add an svg element to the layer.
055: * @param element the <CODE>SVGElement</CODE> to be added to the map.
056: */
057: public void addElement(SVGElement element) {
058: try {
059: loaderAddChild(null, element);
060: updateTime(0.0);
061: } catch (Exception ex) {
062: if (BuildProperties.DEBUG)
063: ex.printStackTrace();
064: }
065: }
066:
067: /**
068: * Set this layer to be visible.
069: */
070: public void setVisible() {
071: try {
072: setAttribute("visibility", AnimationElement.AT_XML,
073: "visible");
074: updateTime(0.0);
075: } catch (Exception ex) {
076: if (BuildProperties.DEBUG)
077: ex.printStackTrace();
078: }
079: }
080:
081: /**
082: * Set this layer to be hidden from view.
083: */
084: public void setHidden() {
085: try {
086: setAttribute("visibility", AnimationElement.AT_XML,
087: "hidden");
088: updateTime(0.0);
089: } catch (Exception ex) {
090: if (BuildProperties.DEBUG)
091: ex.printStackTrace();
092: }
093: }
094:
095: /**
096: * Add the layer to the SVG image.
097: */
098: public void addToImageMap() {
099: try {
100: addAttribute("id", AnimationElement.AT_XML, name);
101: addAttribute("visibility", AnimationElement.AT_XML,
102: "visible");
103: root.loaderAddChild(null, this );
104: root.updateTime(0.0);
105: } catch (Exception ex) {
106: if (BuildProperties.DEBUG)
107: ex.printStackTrace();
108: }
109: }
110:
111: /**
112: * Remove the layer from the SVG image.
113: */
114: public void removeFromImageMap() {
115: try {
116: root.removeChild(this );
117: root.updateTime(0.0);
118: } catch (Exception ex) {
119: if (BuildProperties.DEBUG)
120: ex.printStackTrace();
121: }
122: }
123: }
|