com.miginfocom.ashape.shapes
Class FilterAShape

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

public abstract class FilterAShape
extends AbstractAShape

A generic base class for shapes that implements some kind of filtering algorithm to another shape. E.g. FeatherAShape. Uses a SlicedImage buffer to speed up operations if the buffer can be used.

The following attibutes is currently used by this shape:
AShape.A_SHADOW_TARGET_PAINT
A_FILTER_SLICE_SPEC
AShape.A_WRAPPED_ASHAPE
Note that any attributes used by AbstractAShape will also be adhered to.


Field Summary
static PropertyKey A_FILTER_SLICE_SPEC
          Value type: SliceSpec.
 
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 FilterAShape()
          Empty constructor for XML builders.
protected FilterAShape(java.lang.String name, AShape attrShape, java.awt.Paint targetPaint, SliceSpec sliceSpec)
          Constructor
 
Method Summary
 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 clearBuf(java.awt.image.BufferedImage b, java.awt.Paint p, int w, int h)
          Clears the buffer.
protected abstract  java.awt.image.BufferedImageOp getBufferedOp()
          Returns a filter to use.
protected abstract  java.awt.Dimension getFilterMargin()
          Returns the extra margin around the buffered image that for instance the blur filter need to not chop of the blurred outer part.
 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.
 void invalidateCachedImage()
          Invalidates the cached image of the filtered shape.
 java.awt.Shape paintShape(java.awt.Graphics2D g2, java.awt.Shape clip, java.awt.Rectangle visRect)
          Paints this shape only.
protected  boolean shouldRecreateSlicedImage(SlicedImage oldImage, java.awt.Rectangle r)
          Returns if the sliced image should be recreated.
 
Methods inherited from class com.miginfocom.ashape.shapes.AbstractAShape
addAttributes, 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_FILTER_SLICE_SPEC

public static final PropertyKey A_FILTER_SLICE_SPEC
Value type: SliceSpec. An optional specification for how to slice the shape.

Constructor Detail

FilterAShape

protected FilterAShape()
Empty constructor for XML builders.


FilterAShape

protected FilterAShape(java.lang.String name,
                       AShape attrShape,
                       java.awt.Paint targetPaint,
                       SliceSpec sliceSpec)
Constructor

Parameters:
name - The name. Not null
attrShape - The containd shape to feather. Not null.
targetPaint - The paint to feather towards. May be null.
sliceSpec - An optional specification for how to slice the shape.
Using a sliced shape caches the filtered shape as an image. This vastly increases preformance since the filter don't have to be reapplied every repaint. If the shape will be resized a lot and aren't rectangular in nature this otimizatipon can't be done though.
See Also:
SlicedImage
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

invalidateCachedImage

public void invalidateCachedImage()
Invalidates the cached image of the filtered shape.


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.

addSubShape

public void addSubShape(AShape aShape)
Description copied from interface: AShape
Add a shape to this shape as a sub-shape

Specified by:
addSubShape in interface AShape
Overrides:
addSubShape in class AbstractAShape
Parameters:
aShape - The AShape to add

addSubShape

public void addSubShape(AShape aShape,
                        int index)
Description copied from interface: AShape
Add a shape to this shape as a sub-shape at index-

Specified by:
addSubShape in interface AShape
Overrides:
addSubShape in class AbstractAShape
Parameters:
aShape - The AShape to add
index - The index to add. If larger than array it will always be added last.

shouldRecreateSlicedImage

protected boolean shouldRecreateSlicedImage(SlicedImage oldImage,
                                            java.awt.Rectangle r)
Returns if the sliced image should be recreated. Usually when:
1. oldImage == null 2. oldImage is so small that not all slices is expanded fully. That image can only be used for that size and not generally. If so, remake it if another comes along whick would produce a bigger sliced image.

Parameters:
oldImage - The sliced image in the cache right now. May be null.
r - The new bounds that the sliced image should slice the image in.
Returns:
If the sliced image should be recreated

clearBuf

protected void clearBuf(java.awt.image.BufferedImage b,
                        java.awt.Paint p,
                        int w,
                        int h)
Clears the buffer. Will use AlphaComposite.Src to fill the paint.

Parameters:
b - The buffer to clear
p - The paint to use. Not null.
w - The width to clear.
h - The hight to clear.

getBufferedOp

protected abstract java.awt.image.BufferedImageOp getBufferedOp()
Returns a filter to use.

Returns:
A filter to use. May be null in which case no filtering is done.

getFilterMargin

protected abstract java.awt.Dimension getFilterMargin()
Returns the extra margin around the buffered image that for instance the blur filter need to not chop of the blurred outer part. The margin should be an even number to avoid rounding errors at later stages.

Returns:
The extra margin around the buffered image. Not null and can be an private instance so don't change it.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.