com.miginfocom.ashape.shapes
Class ImageAShape

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

public class ImageAShape
extends AbstractAShape

An image that has som additional attributes, such as x/y alignment and width/hight scaling. This Can paint an Image, Icon or ScaleableImage

The following attibutes is currently used by this shape:
AShape.A_ICON or AShape.A_IMAGE
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
ImageAShape()
          Empty constructor for XML builders.
ImageAShape(java.lang.String name, javax.swing.Icon icon, PlaceRect placeRect)
          Contructor
ImageAShape(java.lang.String name, java.awt.Image image, PlaceRect placeRect)
          Contructor
 
Method Summary
protected  void drawImage(java.awt.Graphics2D g, java.lang.Object imgOrIc, java.awt.Rectangle r)
          Draws the image in the bounds.
 java.awt.Shape getHitBounds(boolean forceCalculate)
          Returns the bounds that this attributed shape's actual content spans.
protected  java.lang.Object getImageOrIcon()
          Returns the Image, Icon or null to use for drawing.
 java.awt.Dimension getNaturalSize()
          Returns the size that the shape finds most natural.
protected  java.awt.Dimension getSize(java.lang.Object imgOrIc)
          Returns the size for the An Image, Icon or null.
protected  java.lang.Object getWrappedImage(java.lang.Object imgOrIc)
          Gives the possibility for subclasses to return a wrapped or chached image to paint instead of the original image.
 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
 

Constructor Detail

ImageAShape

public ImageAShape()
Empty constructor for XML builders.


ImageAShape

public ImageAShape(java.lang.String name,
                   javax.swing.Icon icon,
                   PlaceRect placeRect)
Contructor

Parameters:
name - The name used for referencing this shape/sub shape
icon - The image to use (as an Icon). Can for instance be an ScaleableImage
placeRect - How the shape will fill the bounds (or the parent's bounds)

ImageAShape

public ImageAShape(java.lang.String name,
                   java.awt.Image image,
                   PlaceRect placeRect)
Contructor

Parameters:
name - The name used for referencing this shape/sub shape
image - The image to use
placeRect - How the shape will fill the bounds (or the parent's bounds)
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.

getWrappedImage

protected java.lang.Object getWrappedImage(java.lang.Object imgOrIc)
Gives the possibility for subclasses to return a wrapped or chached image to paint instead of the original image.

Parameters:
imgOrIc - An Image/Icon or null in which case nothing is painted.
Returns:
Default implementation returns imgOrIc without intervention.
See Also:
SlicedImageAShape

drawImage

protected void drawImage(java.awt.Graphics2D g,
                         java.lang.Object imgOrIc,
                         java.awt.Rectangle r)
Draws the image in the bounds. If imgOrIc is an Icon it isn't scaled. If imgOrIc is a XtdImage or Image it is scaled to fit the bounds.

Parameters:
imgOrIc - An Image/Icon or null in which case nothing is painted.

getImageOrIcon

protected java.lang.Object getImageOrIcon()
Returns the Image, Icon or null to use for drawing.

Returns:
An Image, Icon or null.

getSize

protected java.awt.Dimension getSize(java.lang.Object imgOrIc)
Returns the size for the An Image, Icon or null.

Parameters:
imgOrIc - An Image/Icon or null in which case null is returned.
Returns:
The size of null if it was <= 0 in any dimension.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.