com.miginfocom.util.gfx.geometry
Class AbsRect

java.lang.Object
  extended by com.miginfocom.util.gfx.geometry.AbsRect
All Implemented Interfaces:
PlaceRect, java.io.Serializable

public final class AbsRect
extends java.lang.Object
implements PlaceRect

Rectangle that is in some way relative to another rectangle, called "reference". Ideal as a spec for a dockable rectangle that "docks" to another rectangular shape. Since it can use relative coordinates (E.g. AtFraction or AtStart) as well as size constraints the rectangle can be really flexible.

The coordinates (E.g. x1) can even be filtered and thus constrained. All numbers (coordinates) that implements AtRefRangeNumber are decorateable (like a BufferedReader can wrap a Reader) and any constraints or arithmetics can be applied to them.

Since the rectangle that this class describes is only relative to some reference bounds it doesn't normally have coordinates of it's own that makes sence. The method getRect(java.awt.Rectangle, java.awt.Dimension) or getRect(java.awt.Rectangle) is/can be called with a reference rectangle and an optional reference size to get the resulting rectangle that this class specifies.

For instance, with this class you can specify a rectangle to docked inside the referece bounds, with a size of 10% of it's height but no less than 20 pixels and no more than 40.

If possible use the static FILL and FILL_INSIDE.

See Also:
Serialized Form

Field Summary
static AbsRect FILL
          Rectangle that fills the bounds.
static AbsRect FILL_INSIDE
          Rectangle that fills the bounds but with a 1 pixel empty boundary.
static AbsRect FILL_UPPER_LEFT
           
static AbsRect NULL
          Rectangle that set upper left corner to 0, 0.
 
Constructor Summary
AbsRect(AtRefRangeNumber x1, AtRefRangeNumber y1)
          Constructor with no min/max sizes and keep width of source rectangle.
AbsRect(AtRefRangeNumber x1, AtRefRangeNumber y1, AtRefRangeNumber x2, AtRefRangeNumber y2)
          Constructor with no min/max sizes.
AbsRect(AtRefRangeNumber x1, AtRefRangeNumber y1, AtRefRangeNumber x2, AtRefRangeNumber y2, java.awt.Insets resize)
          Constructor with no min/max sizes.
AbsRect(AtRefRangeNumber x1, AtRefRangeNumber y1, AtRefRangeNumber x2, AtRefRangeNumber y2, SizeConstraint horConstr, SizeConstraint verConstr, java.awt.Insets resize)
          Constructor.
AbsRect(java.awt.Insets border)
          Constructor that sizes to the bounds except for the insets.
Short for: new AtStart(border.left), new AtStart(border.top), new AtEnd(-border.right), new AtEnd(-border.bottom));
AbsRect(int border)
          Constructor that sizes to the bounds except for the inset all around.
Short for: new AtStart(border), new AtStart(border), new AtEnd(-border), new AtEnd(-border));
AbsRect(int dockSide, java.lang.Number size)
          Constructor that will return a relative rectangle that is "docked" inside the reference rectangle.
Min size will be 0 and max 100% of available.
AbsRect(int dockSide, java.lang.Number size, SizeConstraint refRangeConstr)
          Constructor that will return a relative rectangle that is "docked" inside the reference rectangle.
 
Method Summary
 AbsRect derive(java.awt.Insets resize)
          Creates a new relative rect by resizing this.
 boolean equals(java.lang.Object o)
           
 SizeConstraint getHorizontalSizeConstraint()
           
 java.awt.Rectangle getRect(java.awt.Rectangle r)
          Returns a rectangle that might be translated, scaled and checked for max/min bounds.
 java.awt.Rectangle getRect(java.awt.Rectangle r, java.awt.Dimension refSize)
          Returns a rectangle that might be translated, scaled and checked for max/min bounds.
 java.awt.Insets getResize()
           
 SizeConstraint getVerticalSizeConstraint()
           
 AtRefRangeNumber getX1()
           
 AtRefRangeNumber getX2()
           
 AtRefRangeNumber getY1()
           
 AtRefRangeNumber getY2()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final AbsRect NULL
Rectangle that set upper left corner to 0, 0. Normally used if the PlaceRect was null.


FILL

public static final AbsRect FILL
Rectangle that fills the bounds.


FILL_INSIDE

public static final AbsRect FILL_INSIDE
Rectangle that fills the bounds but with a 1 pixel empty boundary.


FILL_UPPER_LEFT

public static final AbsRect FILL_UPPER_LEFT
Constructor Detail

AbsRect

public AbsRect(int dockSide,
               java.lang.Number size)
Constructor that will return a relative rectangle that is "docked" inside the reference rectangle.
Min size will be 0 and max 100% of available.

Parameters:
dockSide - What side to dock on. E.g. SwingConstants.TOP. Not Center!
size - The size. If Integer it's in pixels and if it's a Float it's a percentage of the remaining size of the container.

AbsRect

public AbsRect(int dockSide,
               java.lang.Number size,
               SizeConstraint refRangeConstr)
Constructor that will return a relative rectangle that is "docked" inside the reference rectangle.

Parameters:
dockSide - What side to dock on. E.g. SwingConstants.TOP. Not CENTER! To simulate center set to some other dock side and set size to Float(1f). This way refRangeConstr can still be used for one dimension.
size - The size. If Integer it's in pixels and if it's a Float it's a percentage of the remaining size of the container.
refRangeConstr - The size constraint in the docked dimension. E.g. height for a top/bottom dock. If null then SizeConstraint.SIZE_MIN_MAX_START will be used for top/left and SizeConstraint.SIZE_MIN_MAX_END for bottom/right docks.
See Also:
SizeConstraint, RefOperFilter

AbsRect

public AbsRect(int border)
Constructor that sizes to the bounds except for the inset all around.
Short for: new AtStart(border), new AtStart(border), new AtEnd(-border), new AtEnd(-border));

Parameters:
border - How think the inset around should be.

AbsRect

public AbsRect(java.awt.Insets border)
Constructor that sizes to the bounds except for the insets.
Short for: new AtStart(border.left), new AtStart(border.top), new AtEnd(-border.right), new AtEnd(-border.bottom));

Parameters:
border - The insets. Not null. Not that this is not same as the resize insets at the other constructors.

AbsRect

public AbsRect(AtRefRangeNumber x1,
               AtRefRangeNumber y1)
Constructor with no min/max sizes and keep width of source rectangle.

Parameters:
x1 - The first x coordinate. Can be null.
y1 - The first y coordinate. Can be null.

AbsRect

public AbsRect(AtRefRangeNumber x1,
               AtRefRangeNumber y1,
               AtRefRangeNumber x2,
               AtRefRangeNumber y2)
Constructor with no min/max sizes.

Parameters:
x1 - The first x coordinate. Can be null.
y1 - The first y coordinate. Can be null.
x2 - The second x coordinate/width. Can be null.
y2 - The second y coordinate/height. Can be null.

AbsRect

public AbsRect(AtRefRangeNumber x1,
               AtRefRangeNumber y1,
               AtRefRangeNumber x2,
               AtRefRangeNumber y2,
               java.awt.Insets resize)
Constructor with no min/max sizes.

Parameters:
x1 - The first x coordinate. Can be null.
y1 - The first y coordinate. Can be null.
x2 - The second x coordinate/width. Can be null.
y2 - The second y coordinate/height. Can be null.
resize - If non-null resizes the rectangle with an absolute number of pixels at the last stage. Positive values enlarges the rectangle. Object is cloned for local storage.

AbsRect

public AbsRect(AtRefRangeNumber x1,
               AtRefRangeNumber y1,
               AtRefRangeNumber x2,
               AtRefRangeNumber y2,
               SizeConstraint horConstr,
               SizeConstraint verConstr,
               java.awt.Insets resize)
Constructor.

Parameters:
x1 - The first x coordinate. Can be null.
y1 - The first y coordinate. Can be null.
x2 - The second x coordinate/width. Can be null.
y2 - The second y coordinate/height. Can be null.
horConstr - The size and/or star/end position constraint in the horizontal dimension. No constraing if null.
verConstr - The size and/or star/end position constraint in the vertical dimension. No constraing if null.
resize - If non-null resizes the rectangle with an absolute number of pixels at the last stage. Positive values enlarges the rectangle. Object is cloned for local storage.
Method Detail

getRect

public java.awt.Rectangle getRect(java.awt.Rectangle r)
Description copied from interface: PlaceRect
Returns a rectangle that might be translated, scaled and checked for max/min bounds.

This method is normally just a transfer to PlaceRect.getRect(java.awt.Rectangle, java.awt.Dimension) with refSize set ti null.

Specified by:
getRect in interface PlaceRect
Parameters:
r - The rectangle that is to be used as the source. Not null. Will not be changed.
Returns:
A new rectangle. Never null.

getRect

public java.awt.Rectangle getRect(java.awt.Rectangle r,
                                  java.awt.Dimension refSize)
Description copied from interface: PlaceRect
Returns a rectangle that might be translated, scaled and checked for max/min bounds.

Specified by:
getRect in interface PlaceRect
Parameters:
r - The rectangle that is to be used as the source. Not null. Will not be changed.
refSize - If x1, y1, x2 and/or y2 is null (in this)) the horizontal/vertical size if taken from this dimension instead. If null the size is taken from r.
This can for instance be the size on an Image that you are trying to alighn within some bounds.
Returns:
A new rectangle. Never null.

derive

public AbsRect derive(java.awt.Insets resize)
Creates a new relative rect by resizing this.

Parameters:
resize - The resize. May be null. If both ins and this.resize are non-null they are combined (added).
Returns:
A new relative rect.

getResize

public java.awt.Insets getResize()

getX1

public AtRefRangeNumber getX1()

getY1

public AtRefRangeNumber getY1()

getX2

public AtRefRangeNumber getX2()

getY2

public AtRefRangeNumber getY2()

getHorizontalSizeConstraint

public SizeConstraint getHorizontalSizeConstraint()

getVerticalSizeConstraint

public SizeConstraint getVerticalSizeConstraint()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.