com.miginfocom.ashape.shapes
Class VectorAShape

java.lang.Object
  extended by com.miginfocom.ashape.shapes.AbstractAShape
      extended by com.miginfocom.ashape.shapes.VectorAShape
All Implemented Interfaces:
AShape, PropertyProvider
Direct Known Subclasses:
DrawAShape, FillAShape

public abstract class VectorAShape
extends AbstractAShape

A generic base class for vector graphics shape. For instance DrawAShape and FillAShape. A Shape will be used and scaled to fit the bounds of this AShape. This means that the actual bounds of the Shape provided is not important, it will be rescaled to fit the bounds anyway. For instance new Rectangle(0, 0, 1, 1) will be the same as new Rectangle(100, 100, 200, 200). The only thing that differ the two is the reported natural size, which might be used by AShapeLayouts.

The following attibutes is currently used by this shape:
AShape.A_SHAPE
AShape.A_SHAPES
AShape.A_PAINT
AShape.A_ANTI_ALIAS
AShape.A_CROP
AShape.A_CROP_TO_VISIBILITY_BOUNDS
Note that any attributes used by AbstractAShape will also be adhered to.


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
protected VectorAShape()
          Empty constructor for XML builders.
protected VectorAShape(java.lang.String name, java.awt.Shape shape, PlaceRect placeRect, java.awt.Paint paint, int antiAliasHint)
          Constructor.
protected VectorAShape(java.lang.String name, java.awt.Shape paper, java.awt.Shape[] shapes, PlaceRect placeRect, java.awt.Paint paint, int antiAliasHint)
          Constructor.
 
Method Summary
 java.awt.Shape getHitBounds(boolean forceCalcualte)
          Returns the bounds that this attributed shape's actual content spans.
 java.awt.Dimension getNaturalSize()
          Returns the size that the shape finds most natural.
protected abstract  boolean isDraw()
          Returns if the shape is to be drawn (as opposed to filled).
 java.awt.Shape paintShape(java.awt.Graphics2D g2, java.awt.Shape clip, java.awt.Rectangle visRect)
          Paints this shape only.
protected abstract  void paintShapeImpl(java.awt.Graphics2D g2, java.awt.Shape shape)
          Paints or draws the shape.
protected abstract  void paintShapesImpl(java.awt.Graphics2D g2, java.awt.Shape[] shape)
          Paints or draws the shapes.
 
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, getRoot, getShapeBounds, getSubShapeDeep, getSubShapes, getSubShapesImpl, hasAttribute, increaseModCount, isRoot, 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

VectorAShape

protected VectorAShape()
Empty constructor for XML builders.


VectorAShape

protected VectorAShape(java.lang.String name,
                       java.awt.Shape shape,
                       PlaceRect placeRect,
                       java.awt.Paint paint,
                       int antiAliasHint)
Constructor. Does not clone any of the objects sent in, the references is kept.

Parameters:
name - The name used for referencing this shape/sub shape
shape - The shape to paint. Not null and should be considered an immutable object since it may be shared.
placeRect - How the shape will fill the bounds (or the parent's bounds)
paint - The paint (Color is a paint) used to draw the shape. If null won't be changed (I.e. will be inhereted)
antiAliasHint - The anti alias hint to set if != null. E.g. RenderingHints.VALUE_ANTIALIAS_ON. If null the defalt value (i.e. it will not be change on the Graphics object) will be used.

For backwards compatibility it also understands Boolean.TRUE and Boolean.FALSE which turns on/off anti aliasing.


VectorAShape

protected VectorAShape(java.lang.String name,
                       java.awt.Shape paper,
                       java.awt.Shape[] shapes,
                       PlaceRect placeRect,
                       java.awt.Paint paint,
                       int antiAliasHint)
Constructor. Does not clone any of the objects sent in, the references is kept.

Parameters:
name - The name used for referencing this shape/sub shape
paper - The shape that outlines the paper, or coordinate system, to use for shapes. Will not be drawin/painted. The outline of the paper will also be the "hit area" reported by this shape. shapes will in no way change that.
shapes - The actual shapes that will be painted. They will all use the same coordinate system as is outlines with paper. They will also be clipped by the paper shape.
placeRect - How the shape will fill the bounds (or the parent's bounds)
paint - The paint (Color is a paint) used to draw the shape. If null won't be changed (I.e. will be inhereted)
antiAliasHint - The anti alias hint to set if != null. E.g. RenderingHints.VALUE_ANTIALIAS_ON. If null the defalt value (i.e. it will not be change on the Graphics object) will be used.

For backwards compatibility it also understands Boolean.TRUE and Boolean.FALSE which turns on/off anti aliasing.

Method Detail

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 forceCalcualte)
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:
forceCalcualte - 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.

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.

paintShapeImpl

protected abstract void paintShapeImpl(java.awt.Graphics2D g2,
                                       java.awt.Shape shape)
Paints or draws the shape. Override to do the actual painting of the shape

Parameters:
g2 - The object to draw in
shape - The shape to paint or draw. Not null.

paintShapesImpl

protected abstract void paintShapesImpl(java.awt.Graphics2D g2,
                                        java.awt.Shape[] shape)
Paints or draws the shapes. Should normally just setup the painting properties and call paintShapeImpl(java.awt.Graphics2D, java.awt.Shape) for every shape in the array.

Parameters:
g2 - The object to draw in
shape - The shapes to paint or draw. Not null.

isDraw

protected abstract boolean isDraw()
Returns if the shape is to be drawn (as opposed to filled). This needs to be known since draw usually draw one pixel larger and this must be accounted for when registring mouse hit area and intersection with the clip.

Returns:
If the shape is to be drawn (as opposed to filled).


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.