|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.miginfocom.ashape.shapes.AbstractAShape
public abstract class AbstractAShape
Contains the framework for the attributed shapes. Extend this to construct a simple and standard AShape.
It supports serializing to XMl via the beans framework introduced in JDK 1.4.
The name is the only attribute that is not stored in the attribute map.
Note! All sub shapes need to provide an empty constructor to be serializable to XML. as long as all attributes
are stores with setAttribute(PropertyKey, Object) and getAttribute(PropertyKey) they will be handled autmatically.
| Field Summary | |
|---|---|
protected java.awt.Shape |
hitShape
After a paint this field should always represent the hit shape for mouse com.miginfocom.tests and collision com.miginfocom.tests. |
static boolean |
RETURN_LIVE_ATTR_MAP
Can be set to true to enable leading of pre 5.3 shapes. |
protected static PropertyKey[] |
SIZE_CONV_MAP
Indexed with [(type << 1) + dim] type is 0..2 and dim is 0 or 1. |
| 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 |
AbstractAShape()
Contructor for XML builder. |
protected |
AbstractAShape(java.lang.String name)
Contructor. |
| Method Summary | |
|---|---|
void |
addAttributes(java.util.Map map)
Adds all attributes to the attribute map |
void |
addSubShape(AShape aShape)
Add a shape to this shape as a sub-shape |
void |
addSubShape(AShape aShape,
int index)
Add a shape to this shape as a sub-shape at index- |
protected void |
addToHitShapeList(java.util.Collection haList)
Add this shape's hit area and name and the ask it's children to do the same. |
boolean |
containsProperty(PropertyKey property)
Return if the provider contains the property. |
java.lang.Object |
getAttribute(PropertyKey key)
Returns an attribute. |
java.util.Map |
getAttributes()
Returns a cloned map of all attributes. |
protected java.awt.Shape |
getClipShape(java.awt.Shape s)
Returns a shape that is to be used for clipping for THIS shape. |
double |
getDoubleAttribute(PropertyKey key,
double def)
Returns an attribute as an int. |
float |
getFloatAttribute(PropertyKey key,
float def)
Returns an attribute as an int. |
java.awt.Shape |
getHitShape()
Returns the current hit shape as setted by setHitShape(java.awt.Shape, java.awt.Shape) at the last repaint. |
int |
getIntAttribute(PropertyKey key,
int def)
Returns an attribute as an int. |
protected AShapeLayout |
getLayout()
Returns the current layout or DEFAULT_LAYOUT if the attribute AShape.A_LAYOUT returns null. |
java.lang.Integer |
getLayoutSize(int type,
int dim,
java.lang.Integer otherDimSizeHint)
Returns the min, max or preferred size in the horizontal or vertical dimension. |
long |
getLongAttribute(PropertyKey key,
long def)
Returns an attribute as an int. |
int |
getModCount()
How many time the shape has been changed. |
java.lang.String |
getName()
Returns the name for this shape. |
java.lang.Integer |
getPaintLayer()
Returns the attribute value for AShape.A_PAINT_LAYER but exchanges null for Integer(0). |
AShape |
getParent()
Returns the current parent. |
java.lang.Object |
getProperty(PropertyKey key)
This is a method that should be dispatched to AShape.getAttribute(PropertyKey). |
java.awt.Rectangle |
getReferenceBounds()
Returns the bounds set with AShape.setReferenceBounds(java.awt.Rectangle). |
RootAShape |
getRoot()
Returns the root shape or null if the top of the tree isn't a RootAShape. |
java.awt.Rectangle |
getShapeBounds()
Returns where on screen the shape would be painted. |
AShape |
getSubShapeDeep(java.lang.String name)
Traverses the tree of shapes and returns the first one with the name name. |
AShape[] |
getSubShapes()
Returns the live array of sub shapes. |
protected AShape[] |
getSubShapesImpl()
Returns the sub shapes and if there is a sorter ( AShape.A_SUB_SHAPE_SORTER clones the array and sorts them first. |
boolean |
hasAttribute(PropertyKey key)
Returns if the attribute exists and has a mapping. |
void |
increaseModCount()
Increases the modecount which noramlly invalidates any caches. |
boolean |
isRoot()
|
boolean |
isVisible()
Returns if THIS shape is visible. |
void |
layout()
Lays out the children, if any bu calling setBounds() on them and then call .layout(). Layout also clears the 'hit shape'. |
protected void |
paintBorder(java.awt.Graphics2D g2)
Paints the AShape.A_BORDER if one is present. |
void |
paintSubTree(java.awt.Graphics2D g2,
java.awt.Shape parentShape,
java.awt.Rectangle visBounds,
java.lang.Integer layer)
Paints the shape, if it it visible, and then the sub shapes with the appropriate clip. |
void |
removeAttribute(PropertyKey key)
Removes a attribute if it exist. |
void |
removeSubShape(AShape aShape)
removes a sub-shape if it exist. |
void |
setAttribute(PropertyKey key,
java.lang.Object value)
Sets a attribute object. |
void |
setAttributeDeep(PropertyKey key,
java.lang.Object value,
int maxLevels)
Convenience method for setting an attributeon this shape and recursively down the sub shape tree. |
void |
setAttributes(java.util.Map map)
Sets the attributes, discarding any old ones. |
protected void |
setHitShape(java.awt.Shape clip,
java.awt.Shape shape)
Set the area that this shape presents to the user. |
void |
setName(java.lang.String name)
Sets the name. |
void |
setParent(AShape parent)
Sets the parent shape. |
void |
setReferenceBounds(int x,
int y,
int w,
int h)
Sets the bounds that this shape should relate to with it's (AbsRect) placeRect. |
void |
setReferenceBounds(java.awt.Rectangle b)
Sets the bounds that this shape should relate to with it's (AbsRect) placeRect. |
void |
setSubShapes(AShape[] shapes)
Sets the array of sub shapes discarding any old ones. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.miginfocom.ashape.shapes.AShape |
|---|
getHitBounds, getNaturalSize, paintShape |
| Field Detail |
|---|
protected transient java.awt.Shape hitShape
null if no area is spanned.
setHitShape(java.awt.Shape, java.awt.Shape).protected static final PropertyKey[] SIZE_CONV_MAP
public static boolean RETURN_LIVE_ATTR_MAP
| Constructor Detail |
|---|
protected AbstractAShape()
null-
protected AbstractAShape(java.lang.String name)
name - The name. Not null!| Method Detail |
|---|
public int getModCount()
AShape
getModCount in interface AShapepublic final void increaseModCount()
AShape
increaseModCount in interface AShape
public final void paintSubTree(java.awt.Graphics2D g2,
java.awt.Shape parentShape,
java.awt.Rectangle visBounds,
java.lang.Integer layer)
AShape
paintSubTree in interface AShapeg2 - The object to draw in. Settings won't changeparentShape - The shape to clip the graphics with. This shape is not already added to the clip in the
Grahpics2D object sent in since this shape will also possibly 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.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.layer - The level that is currently being painted. May be null. Only shapes in this level should paint
themselves.AShape.A_CROP_TO_VISIBILITY_BOUNDS,
AShape.A_CLIP_TYPE,
AShape.A_PAINT_LAYERprotected void paintBorder(java.awt.Graphics2D g2)
AShape.A_BORDER if one is present. Does NOT reduce the bounds.
g2 - The object to draw in. Settings won't changepublic final java.lang.Integer getPaintLayer()
AShapeAShape.A_PAINT_LAYER but exchanges null for Integer(0).
getPaintLayer in interface AShapenull.public void setReferenceBounds(java.awt.Rectangle b)
AShape(AbsRect) placeRect.
setReferenceBounds in interface AShapeb - The bounds. Not null. The object's values are copied and the reference is not kept.
public void setReferenceBounds(int x,
int y,
int w,
int h)
AShape(AbsRect) placeRect.
setReferenceBounds in interface AShapex - Xy - Yw - Widthh - Heightpublic java.awt.Rectangle getReferenceBounds()
AShapeAShape.setReferenceBounds(java.awt.Rectangle). Note that this is just the "relative bounds", the
real on-screen shape bounds can be retrieved with AShape.getShapeBounds().
READ_ONLY! Not cloned since this might be read thousands of times per frame.
getReferenceBounds in interface AShape
public java.lang.Integer getLayoutSize(int type,
int dim,
java.lang.Integer otherDimSizeHint)
AShapeAShapeLayout.AShape.getNaturalSize()) of the shape may be returned.
getLayoutSize in interface AShapetype - The type of size to get. E.g. Distributor.MINdim - The dimension for which to return the layout size. E.g. SwingConstants.VERTICAL.otherDimSizeHint - If the width/height layout size is interconnected is any way and the size in that other
dimension is known already, that size if entered here.
null if there was no preference by any of the sub shapes.AShape.A_PREFERRED_WIDTHprotected AShapeLayout getLayout()
DEFAULT_LAYOUT if the attribute AShape.A_LAYOUT returns null.
null.public void layout()
AShape
layout in interface AShapepublic java.awt.Rectangle getShapeBounds()
getShapeBounds in interface AShapeRectangle representing the bounds or null if, for any reason, the shape
can't or wont paint itself within these bounds.getReferenceBounds(),
AShape.A_PLACE_RECTprotected java.awt.Shape getClipShape(java.awt.Shape s)
s - The most accurate shape availabe for clipping.
s, the bounds of s or null depending on the value of the attribute
AShape.A_CLIP_TYPE. Note that if s is a Rectangle and the bounds should be returned, s itself are
returned to avoid object creation. The returned value should therefore be considered read-only.public boolean isVisible()
AShapeAShape.A_VISIBILITY is non-null
that value will be returned. If null true will be returned.
isVisible in interface AShape
protected void setHitShape(java.awt.Shape clip,
java.awt.Shape shape)
clip is some cropping or the like that
is set on the shape.
This method should be called everytime the shape is repainted since the controller of this shape will after repainting get this
area to use for mouse hit detection, collisions and such.
The method is optimized to recognize Rectangle2Ds for both clip and shape but
any shape is ok, but slower since it means Area intersection calculations.
clip - An optional clip to exclude from shape. Can be null.shape - The shape to add. If null that means this shape doesn't span an area. The actual shape will be overtaken and
stored so it can't be changed by the caller anymore.public java.awt.Shape getHitShape()
setHitShape(java.awt.Shape, java.awt.Shape) at the last repaint.
null. The live object so don't change it!protected void addToHitShapeList(java.util.Collection haList)
this shape's hit area and name and the ask it's children to do the same. The object type to add must be
NameValuePair with name set to the name of this shape and value set to the hit shape,
which may be null.
haList - The list to add to. Never setHitShape(java.awt.Shape, java.awt.Shape),
RootAShape.getHitShapes()protected AShape[] getSubShapesImpl()
AShape.A_SUB_SHAPE_SORTER clones the array and sorts them first.
public java.lang.String getName()
AShape
getName in interface AShapenull !public void setName(java.lang.String name)
AShape
setName in interface AShapename - The name. Not null !public void addSubShape(AShape aShape)
AShape
addSubShape in interface AShapeaShape - The AShape to add
public void addSubShape(AShape aShape,
int index)
AShapeindex-
addSubShape in interface AShapeaShape - The AShape to addindex - The index to add. If larger than array it will always be added last.public void removeSubShape(AShape aShape)
AShape
removeSubShape in interface AShapeaShape - The shape to removepublic AShape[] getSubShapes()
AShape
getSubShapes in interface AShapenull.public void setSubShapes(AShape[] shapes)
shapes - The new list of sub shapes. Object will be overtaken and not cloned!public AShape getSubShapeDeep(java.lang.String name)
AShapename.
getSubShapeDeep in interface AShapename - The name.
null if nono found.public java.lang.Object getAttribute(PropertyKey key)
AShapeInteractors are first asked whether it has
an override for this attribute, and of so, returns that object.
getAttribute in interface AShapekey - The key/name that it was stored under. E.g. AShape.A_PAINT, but can be anything.
null if null is stored or key doesn't exist.public final java.lang.Object getProperty(PropertyKey key)
AShapeAShape.getAttribute(PropertyKey). It is called getProperty only
to satisfy the interface PropertyProvider.
getProperty in interface AShapegetProperty in interface PropertyProviderkey - The key/name that it was stored under. E.g. AShape.A_FONT but can be anything.
null if null is stored or key doesn't exist.AShape.getAttribute(PropertyKey)public boolean containsProperty(PropertyKey property)
PropertyProvider
containsProperty in interface PropertyProviderproperty - The property key. Not null.
public int getIntAttribute(PropertyKey key,
int def)
Number and .intValue() is
used to retrieve the value. If null def is returned.
key - The key/name that it was stored under. E.g. AShape.A_PREFERRED_HEIGHT but can be anything.def - The default value if the value is null.
public float getFloatAttribute(PropertyKey key,
float def)
Number and .floatValue() is
used to retrieve the value. If null def is returned.
key - The key/name that it was stored under. E.g. AShape.A_PREFERRED_HEIGHT but can be anything.def - The default value if the value is null.
public double getDoubleAttribute(PropertyKey key,
double def)
Number and .doubleValue() is
used to retrieve the value. If null def is returned.
key - The key/name that it was stored under. E.g. AShape.A_PREFERRED_HEIGHT but can be anything.def - The default value if the value is null.
public long getLongAttribute(PropertyKey key,
long def)
Number and .longValue() is
used to retrieve the value. If null def is returned.
key - The key/name that it was stored under. E.g. AShape.A_PREFERRED_HEIGHT but can be anything.def - The default value if the value is null.
public void setAttribute(PropertyKey key,
java.lang.Object value)
AShape
setAttribute in interface AShapekey - The key/name that it is to be stored under. E.g. AShape.A_PAINTvalue - The value to store.
public void setAttributeDeep(PropertyKey key,
java.lang.Object value,
int maxLevels)
AShape
setAttributeDeep in interface AShapekey - The key/name that it is to be stored under. E.g. AShape.A_PAINTvalue - The value to store.maxLevels - Only recursively add to this level. 1 will only add to this shape's sub subshapes.public void removeAttribute(PropertyKey key)
AShape
removeAttribute in interface AShapekey - The key/name that it was stored under. E.g. AShape.A_PAINTpublic boolean hasAttribute(PropertyKey key)
AShapenull.
hasAttribute in interface AShapekey - The key/name that is to be tested. E.g. AShape.A_PAINT
public void addAttributes(java.util.Map map)
map - The attributes. Keys that aren't PropertyKeys will be converted to that type.public java.util.Map getAttributes()
public void setAttributes(java.util.Map map)
map - The new attributes. The attributes are copied and the map itself is not kept.public final AShape getParent()
AShape
getParent in interface AShapenull for root parent.public RootAShape getRoot()
AShapenull if the top of the tree isn't a RootAShape. Iterates every time.
getRoot in interface AShapethis if the top of the tree isn't a RootAShape.public boolean isRoot()
public void setParent(AShape parent)
AShape
setParent in interface AShapeparent - The parent. The root shape has a null parent.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||