Package net.xoetrope.optional.svg

Source Code of net.xoetrope.optional.svg.XSvgElementState

package net.xoetrope.optional.svg;

import com.kitfox.svg.SVGDiagram;
import com.kitfox.svg.SVGElement;
import com.kitfox.svg.SVGElementException;
import com.kitfox.svg.animation.AnimationElement;
import com.kitfox.svg.xml.StyleAttribute;
import net.xoetrope.debug.DebugLogger;

/**
* Manages the visibility of a svg element
* <p>Copyright (c) Xoetrope 2001-2006, see license.txt for more details</p>
*/
public class XSvgElementState
{
  public SVGElement element;
  public boolean hidden;
  public String elementName;
 
  /**
   * Creates a new instance of XSvgElementState
   */
  public XSvgElementState()
  {
  }
 
  /**
   * Setup the svg element wrapper
   * @param diagram the svg diagram that owns the element
   * @param id the id of the element/layer
   */
  public void setup( SVGDiagram diagram, String id )
  {
    if ( id == null )
      return;
   
    element = diagram.getElement( id );
    elementName = id;
    if ( element != null ) {
      StyleAttribute sa = element.getPresAbsolute( "visibility" );
      String visibility;
      if ( sa != null )
        hidden = "hidden".equals( sa.getStringValue());
      else {
        hidden = false;
        try {
          element.addAttribute( "visibility", AnimationElement.AT_XML, "hidden" );
        }
        catch (SVGElementException ex) {
          ex.printStackTrace();
        }
      }
    }
    else
      DebugLogger.logWarning( "Element not found: " + id );
  }
 
  /**
   * Change the visibility of the element if the requested visibility differs
   * from the current state
   * @param visible true to make the element visible
   * @return true if the visiblity state has changed
   */
  public boolean setVisible( boolean visible )
  {
    if ( element == null )
      return false;
   
    try {
      if ( !visible ) {
        if ( hidden )
          return false;
       
        element.setAttribute( "visibility", AnimationElement.AT_XML, "hidden" );
        hidden = true;
      }
      else {
        if ( !hidden )
          return false;
       
        element.setAttribute( "visibility", AnimationElement.AT_XML, "visible" );
        hidden = false;
      }
    }
    catch ( SVGElementException ex ) {
      ex.printStackTrace();
    }
    return true;
  }
}
TOP

Related Classes of net.xoetrope.optional.svg.XSvgElementState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.