com.miginfocom.ashape.shapes
Class RootAShape

java.lang.Object
  extended by com.miginfocom.ashape.shapes.AbstractAShape
      extended by com.miginfocom.ashape.shapes.RootAShape
All Implemented Interfaces:
AShape, PropertyProvider

public class RootAShape
extends AbstractAShape

This is the only shape that is allowed to be the root shape. Is has extended functionality, it can hold Interactions, Interactors and Animators for instance.

A AShape must have a RootAShape before it can be used.


Field Summary
 
Fields inherited from class com.miginfocom.ashape.shapes.AbstractAShape
hitShape, RETURN_LIVE_ATTR_MAP, SIZE_CONV_MAP
 
Fields inherited from interface com.miginfocom.ashape.shapes.AShape
A_ALIGN_X, A_ALIGN_Y, A_ANTI_ALIAS, A_BORDER, A_CLIP_TYPE, A_COMPOSITE, A_CROP, A_CROP_TO_VISIBILITY_BOUNDS, A_FONT, A_HIT_AREA_Z, A_ICON, A_IMAGE, A_INHERIT, A_LAYOUT, A_MAXIMUM_HEIGHT, A_MAXIMUM_WIDTH, A_MINIMUM_HEIGHT, A_MINIMUM_WIDTH, A_MOUSE_CURSOR, A_PAINT, A_PAINT_LAYER, A_PLACE_RECT, A_PREFERRED_HEIGHT, A_PREFERRED_WIDTH, A_REPORT_HIT_AREA, A_SHADOW_TARGET_PAINT, A_SHAPE, A_SHAPES, A_STROKE, A_SUB_SHAPE_SORTER, A_TEXT, A_TEXTURE_PAINT_ANCHOR, A_UNDERLINE_HEIGHT, A_VISIBILITY, A_WRAPPED_ASHAPE, CLIP_PARENT_BOUNDS, CLIP_PARENT_SHAPE
 
Constructor Summary
RootAShape()
          Empty constructor.
RootAShape(AShape shape)
          Creates the root with one sub shape.
RootAShape(java.lang.String name)
          Creates the root with one sub shape.
 
Method Summary
 void addInteraction(Interaction iact)
          Adds an interaction to this shape.
 void addInteractions(java.util.Collection interactions)
          Adds interactions to this shape if this is the root, adds to root otherwise.
 void addInteractor(Interactor interactor)
          Adds an interactor to the array of interactors.
 void addMouseInteractionListener(MouseInteractionListener l)
          Adds a listener that listens to all mouse events on this shape and all sub shapes that has a hit area report set to true.
 void addMouseInteractionListener(MouseInteractionListener l, boolean asWeakRef)
          Adds a listener that listens to all mouse events on this shape and all sub shapes that has a hit area report set to true.
 java.awt.Shape getHitBounds(boolean forceCalculate)
          Returns the bounds that this attributed shape's actual content spans.
 java.util.ArrayList getHitShapes()
          Returns a depth-first list with NameValuePairs of the hit areas.
 Interactor[] getInstalledInteractors()
          Returns the currently installed interactors for this shape.
 java.util.Collection getInteractions()
          Returns an ArrayLists of Interactions.
 ListenerSet getMouseInteractionListeners()
          Returns the MouseInteractionListeners.
 java.awt.Dimension getNaturalSize()
          Returns the size that the shape finds most natural.
 java.awt.Insets getRepaintPadding()
          Returns the extra pixels that need to repainted around this shape.
 RootAShape getRoot()
          Returns the root shape or null if the top of the tree isn't a RootAShape.
 boolean isRoot()
           
 void paint(java.awt.Graphics2D g2, java.awt.Rectangle visBounds)
          Paints the shape in the supplied graphics object.
 java.awt.Shape paintShape(java.awt.Graphics2D g2, java.awt.Shape clip, java.awt.Rectangle visRect)
          Paints this shape only.
 boolean removeInteraction(Interaction i)
          Removes the interaction.
 void removeInteractions(java.util.Collection c)
          Removes the interactions.
 void removeInteractor(Interactor interactor)
          Removes the interactor.
 void removeMouseInteractionListener(MouseInteractionListener l)
          Removes the listener if it exists locally.
 void setInteractions(java.util.Collection interactions)
          Sets the array of interactions, discarding any old ones.
 void setInteractors(Interactor[] interactors)
          Sets the interactors that this shape should interact with.
 void setMouseInteractionListeners(ListenerSet set)
          Sets the MouseInteractionListeners.
 void setRepaintPadding(java.awt.Insets repaintPadding)
          Returns the extra pixels that need to repainted around this shape.
 
Methods inherited from class com.miginfocom.ashape.shapes.AbstractAShape
addAttributes, addSubShape, addSubShape, addToHitShapeList, containsProperty, getAttribute, getAttributes, getClipShape, getDoubleAttribute, getFloatAttribute, getHitShape, getIntAttribute, getLayout, getLayoutSize, getLongAttribute, getModCount, getName, getPaintLayer, getParent, getProperty, getReferenceBounds, getShapeBounds, getSubShapeDeep, getSubShapes, getSubShapesImpl, hasAttribute, increaseModCount, isVisible, layout, paintBorder, paintSubTree, removeAttribute, removeSubShape, setAttribute, setAttributeDeep, setAttributes, setHitShape, setName, setParent, setReferenceBounds, setReferenceBounds, setSubShapes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RootAShape

public RootAShape()
Empty constructor.


RootAShape

public RootAShape(AShape shape)
Creates the root with one sub shape.

Parameters:
shape - The single sub shape

RootAShape

public RootAShape(java.lang.String name)
Creates the root with one sub shape.

Parameters:
name - The name for this root.
Method Detail

paint

public final void paint(java.awt.Graphics2D g2,
                        java.awt.Rectangle visBounds)
Paints the shape in the supplied graphics object.

Parameters:
g2 - The object to draw in. Settings won't change
visBounds - The bounds of the container that holds this shape. Used for determining the "visual" bounds to, for instance, move text within these bounds in certain cases. Can be null.

paintShape

public java.awt.Shape paintShape(java.awt.Graphics2D g2,
                                 java.awt.Shape clip,
                                 java.awt.Rectangle visRect)
Description copied from interface: AShape
Paints this shape only. Called by AShape.paintSubTree(java.awt.Graphics2D, java.awt.Shape, java.awt.Rectangle, Integer).

Parameters:
g2 - The object to draw in. Settings won't change. May be null in which case only the hit shape should be returned. This can be ued to get the layout size/shape.
clip - The shape to clip the graphics with. This shape is not already added to the clip if the Grahpics2D object sent in since this shape will also possible reduce the interaction area (hit area) that the shape presents. The Grahpics2D object's clip will not however since it may only be repainting a part of the shape. Can be null.
The difference to AShape.paintSubTree(java.awt.Graphics2D, java.awt.Shape, java.awt.Rectangle, java.lang.Integer)'s clip is that this clip should be obeyed blindly since paintAll has already filtered it depending on the values of attreibutes AShape.A_CROP_TO_VISIBILITY_BOUNDS and AShape.A_CLIP_TYPE.
visRect - Possibly outlines what is the outer bounds that is visible to the user. This might be for instance the bounds of the component. May be null.
Returns:
The shape of the content spanned. null if nothing was spanned. The returned shape can be the one sent in as well as a privately used shape. Do not change this shape. The sub shapes of this shape will relate to this returned shape.
See Also:
AShape.A_CROP_TO_VISIBILITY_BOUNDS, AShape.A_CLIP_TYPE

getHitBounds

public java.awt.Shape getHitBounds(boolean forceCalculate)
Description copied from interface: AShape
Returns the bounds that this attributed shape's actual content spans.

For instance for a TextAShape this is the text's exact bounds. Its shape's bounds is the container in which the text is positioned.

Note that the returned rectangle might be expensive to calculate and usually means that for instance a text shape must do much if its work twise (once when calling this, which is usually during layout, and once again during paint). Caching of the bounds should be possible for implementing classes.

Parameters:
forceCalculate - If true the hit bounds will always be recaclulated and no caches used.
Returns:
A new Rectangle representing bounds that this attributed shape's actual content spans.

getRoot

public final RootAShape getRoot()
Description copied from interface: AShape
Returns the root shape or null if the top of the tree isn't a RootAShape. Iterates every time.

Specified by:
getRoot in interface AShape
Overrides:
getRoot in class AbstractAShape
Returns:
The root shape or this if the top of the tree isn't a RootAShape.

isRoot

public final boolean isRoot()
Overrides:
isRoot in class AbstractAShape

getRepaintPadding

public java.awt.Insets getRepaintPadding()
Returns the extra pixels that need to repainted around this shape. This will only need to return a non-null value if the shape will paint outside the bounds that is given to it during repaint. One pixel around the edges may have to be returned if anti aliasing or a wide outline is used.

Returns:
The extra pixels that need to repainted around this shape.

setRepaintPadding

public void setRepaintPadding(java.awt.Insets repaintPadding)
Returns the extra pixels that need to repainted around this shape. This will only need to return a non-null value if the shape will paint outside the bounds that is given to it during repaint. One pixel around the edges may have to be returned if anti aliasing or a wide outline is used.

Parameters:
repaintPadding - The padding of null if no padding.

getNaturalSize

public java.awt.Dimension getNaturalSize()
Description copied from interface: AShape
Returns the size that the shape finds most natural. For instance an image shape would return the size of the image and a vector shape would return the bound's size of the Shape it has.

Returns:
The size or if indeteminable null.

setInteractors

public void setInteractors(Interactor[] interactors)
Sets the interactors that this shape should interact with.

Parameters:
interactors - The interactors that the shape should ask for overridden attributes and register hit areas to. Can be null and will if so be replaced by an static empty array (preferred).

getInstalledInteractors

public Interactor[] getInstalledInteractors()
Returns the currently installed interactors for this shape. The contained live array, so READ-ONLY!

Returns:
The currently installed interactors for this shape. Never null but may be of length 0.

addInteractor

public void addInteractor(Interactor interactor)
Adds an interactor to the array of interactors.

Parameters:
interactor - The interactor to add. Not null.

removeInteractor

public void removeInteractor(Interactor interactor)
Removes the interactor.

Parameters:
interactor - The interactor to remove.

addInteraction

public void addInteraction(Interaction iact)
Adds an interaction to this shape. Interactions should normally only be added to the root shape! This is because otherwise a full tree traversal would be necessary every time an interaction needed to e checked.

Parameters:
iact - The interaction to add.

addInteractions

public void addInteractions(java.util.Collection interactions)
Adds interactions to this shape if this is the root, adds to root otherwise.

Parameters:
interactions - A list (not null) of Interactions.

getInteractions

public java.util.Collection getInteractions()
Returns an ArrayLists of Interactions.

Note that this is the LIVE collection and it should not be changed.

Returns:
An ArrayLists of Interactions. Can be null.

removeInteractions

public void removeInteractions(java.util.Collection c)
Removes the interactions.

Parameters:
c - A collection of Interactions.
Since:
6.0

removeInteraction

public boolean removeInteraction(Interaction i)
Removes the interaction.

Parameters:
i - The interaction to remove.
Returns:
If it was found and thus removed.
Since:
6.0

setInteractions

public void setInteractions(java.util.Collection interactions)
Sets the array of interactions, discarding any old ones.

Parameters:
interactions - The new list of interactions. List cloned for storage. May be null.

getHitShapes

public java.util.ArrayList getHitShapes()
Returns a depth-first list with NameValuePairs of the hit areas. name is the shape's name and the value is a Shape object that denotes the hit shape.

Returns:
A breath-first list with NameValuePairs of the hit areas. Never null.
See Also:
getHitShapes()

addMouseInteractionListener

public void addMouseInteractionListener(MouseInteractionListener l)
Adds a listener that listens to all mouse events on this shape and all sub shapes that has a hit area report set to true.

Parameters:
l - The listener
Since:
6.0
See Also:
AShape.A_REPORT_HIT_AREA, addMouseInteractionListener(MouseInteractionListener, boolean)

addMouseInteractionListener

public void addMouseInteractionListener(MouseInteractionListener l,
                                        boolean asWeakRef)
Adds a listener that listens to all mouse events on this shape and all sub shapes that has a hit area report set to true.

Parameters:
l - The listener
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.

Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

Since:
6.0
See Also:
AShape.A_REPORT_HIT_AREA

removeMouseInteractionListener

public void removeMouseInteractionListener(MouseInteractionListener l)
Removes the listener if it exists locally.

Parameters:
l - The listener.
Since:
6.0

getMouseInteractionListeners

public ListenerSet getMouseInteractionListeners()
Returns the MouseInteractionListeners.

Returns:
A set with MouseInteractionListener.
Since:
6.0

setMouseInteractionListeners

public void setMouseInteractionListeners(ListenerSet set)
Sets the MouseInteractionListeners.

Parameters:
set - A set with MouseInteractionListener. Will be overtaken.
Since:
6.5


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.