com.miginfocom.ashape.shapes
Class JComponentAShape

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

public class JComponentAShape
extends AbstractAShape

This shape embeds a JComponent. Does nothing more than set it's bounds. Repaints happens automatically.

The following attibutes is currently used by this shape:
A_JCOMPONENT

Note that any attributes used by AbstractAShape will also be adhered to.

Also note that since this is a thin wrapper around a normal JComponent that component can not have several bounds at the same time, which an AShape can. This is beacause of how Swing works and you can not use JComponents as "stamps". In effect this means that a JComponentShape should only be visible on one place at a time.


Field Summary
static PropertyKey A_JCOMPONENT
           
 
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
JComponentAShape()
          Empty constructor for XML builders.
JComponentAShape(java.lang.String name, javax.swing.JComponent comp, PlaceRect placeRect)
          Constructor.
 
Method Summary
 java.awt.Shape getHitBounds(boolean forceCalculate)
          Returns the bounds that this attributed shape's actual content spans.
 java.awt.Dimension getNaturalSize()
          Returns the size that the shape finds most natural.
 java.awt.Shape paintShape(java.awt.Graphics2D g2, java.awt.Shape clip, java.awt.Rectangle visRect)
          Paints this shape only.
 
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
 

Field Detail

A_JCOMPONENT

public static final PropertyKey A_JCOMPONENT
Constructor Detail

JComponentAShape

public JComponentAShape()
Empty constructor for XML builders.


JComponentAShape

public JComponentAShape(java.lang.String name,
                        javax.swing.JComponent comp,
                        PlaceRect placeRect)
Constructor.

Parameters:
name - The name of the shape.
comp - The component to embed, or rather wrap. Must be added to a parent Container. The parent container must have the same screen coordinates as the component that this shape is painted in or comp will get the wrong x/y coordinates. Normally the parent will be the same Container/JComponent as this shape is painted in. This means the parent is notmally a DefaultDateArea.
placeRect - How to place the bounds of the component within this shape. E.g. AbsRect.FILL.
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 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.

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.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.