net.xoetrope.optional.svg
Class XSvgStateHelper

java.lang.Object
  extended by net.xoetrope.optional.svg.XSvgStateHelper
Direct Known Subclasses:
XSvgButtonStateHelper

public class XSvgStateHelper
extends java.lang.Object

A class to allow a component to display its state via an XSvgPainter. The helper hides details of the state from the painter.

Copyright (c) Xoetrope 2001-2006, see license.txt for more details


Field Summary
protected  java.awt.Component component
           
protected  boolean[] containsMouse
           
protected  java.lang.String[][] defaultIds
           
protected  java.lang.String[][] ids
           
protected  com.kitfox.svg.ShapeElement[] mask
           
static int MASK_ID
           
static int NUM_IDS
           
static int PRESSED_ID
           
static int ROLLOVER_ID
           
 
Constructor Summary
XSvgStateHelper()
          Create a new state helper
 
Method Summary
 boolean contains(double x, double y)
          Check if the cursor is within the client area.
 java.lang.String getSelectedId()
          Get the ID of the selected element
 XSvgElementState[][] getStates(com.kitfox.svg.SVGDiagram diagram)
          Get the managed states in the svg diagram.
 void setComponent(javax.swing.JComponent comp)
          Set the component instance
 void setElementIds(java.lang.String[][] ids)
          Set the element ids for interactive elements
 boolean updateState(int itemIndex)
          Update the svg state to be consistent with the button's state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASK_ID

public static final int MASK_ID
See Also:
Constant Field Values

ROLLOVER_ID

public static final int ROLLOVER_ID
See Also:
Constant Field Values

PRESSED_ID

public static final int PRESSED_ID
See Also:
Constant Field Values

NUM_IDS

public static final int NUM_IDS
See Also:
Constant Field Values

component

protected java.awt.Component component

mask

protected com.kitfox.svg.ShapeElement[] mask

ids

protected java.lang.String[][] ids

defaultIds

protected java.lang.String[][] defaultIds

containsMouse

protected boolean[] containsMouse
Constructor Detail

XSvgStateHelper

public XSvgStateHelper()
Create a new state helper

Method Detail

getSelectedId

public java.lang.String getSelectedId()
Get the ID of the selected element

Returns:
a comma separated list of ids

setElementIds

public void setElementIds(java.lang.String[][] ids)
Set the element ids for interactive elements

Parameters:
ids - the SVG element id to use

setComponent

public void setComponent(javax.swing.JComponent comp)
Set the component instance

Parameters:
comp - the component instacne

getStates

public XSvgElementState[][] getStates(com.kitfox.svg.SVGDiagram diagram)
Get the managed states in the svg diagram. In the case of this button helper the managed states are 'pressed' and 'rollover'.

Parameters:
diagram - the svg diagram
Returns:
an array of state objects, or null if there are no managed states

contains

public boolean contains(double x,
                        double y)
Check if the cursor is within the client area. The method is a modification of the JComponent.contains method as it takes scaled coordinates, such that the x and y values are in the diagram's viewport coordinates.

Parameters:
x - the x viewport coordinate
y - the y viewport coordinate
Returns:
true if the cursor is within the client shape

updateState

public boolean updateState(int itemIndex)
Update the svg state to be consistent with the button's state

Parameters:
itemIndex - the item index or -1 to update all items
Returns:
true if the state has changed