com.miginfocom.util.gfx.geometry
Class AspectRatioRect

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

public class AspectRatioRect
extends java.lang.Object
implements PlaceRect

A class that takes another PlaceRect and forces its aspect ratio (the relationship between with and height) to be a certain value, or range of values.

There are a currently two of ways to force a rectangle into a certain aspect ratio:

See Also:
Serialized Form

Field Summary
static int MODE_DIMENSION
           
static int MODE_SIZE
           
 
Constructor Summary
AspectRatioRect(float aspectRatio)
          Constructor for a rect that will be shrinked to fit the given rectangle.
AspectRatioRect(PlaceRect placeRect, float minAR, float maxAR, float perc, int mode, AtRefRangeNumber alignX, AtRefRangeNumber alignY)
          Constructor.
AspectRatioRect(PlaceRect placeRect, float aspectRatio, float perc, int mode)
          Constructor.
 
Method Summary
protected  void correctAspectRatio(java.awt.Rectangle r)
          Corrects the aspect ration according to the rules set up in the constructor.
 boolean equals(java.lang.Object o)
           
 AtRefRangeNumber getAlignmentX()
          Returns the horizontal alignment to apply to the resulting rectangle in reference to the original one.
 AtRefRangeNumber getAlignmentY()
          Returns the vertical alignment to apply to the resulting rectangle in reference to the original one.
 float getMaxAspectRatio()
          Returns the maximum acceptable aspect ratio.
 float getMinAspectRatio()
          Returns the minimum acceptable aspect ratio.
 int getMode()
          Returns how the rectangle should be resized to fi the target aspect ratio.
 float getPercent()
          Returns the percentage (normally 0f to 1f) between reduce/enlarge or vertical/horizontal depending on the mode.
 PlaceRect getPlaceRect()
          Returns the contained place rect that first will be quired for an rectangle.
 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.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_SIZE

public static final int MODE_SIZE
See Also:
Constant Field Values

MODE_DIMENSION

public static final int MODE_DIMENSION
See Also:
Constant Field Values
Constructor Detail

AspectRatioRect

public AspectRatioRect(float aspectRatio)
Constructor for a rect that will be shrinked to fit the given rectangle.

Parameters:
aspectRatio - The only acceptable aspect ratio. 2f means twice as wide as high.

AspectRatioRect

public AspectRatioRect(PlaceRect placeRect,
                       float aspectRatio,
                       float perc,
                       int mode)
Constructor.

Parameters:
placeRect - The contained place rect that first will be asked for a rectangle. May be null which is same as AbsRect.FILL.
aspectRatio - The only acceptable aspect ratio. 2f means twice as wide as high.
perc - The percentage (normally 0f to 1f) between reduce/enlarge or vertical/horizontal depending on the mode. 0f means reduce or keep horizontal and 1f means enlarge/keep vertical. Any value inbetween is also valid.
mode - How the rectangle should be resized to fi the target aspect ratio.
  • MODE_SIZE - The rectangle is shringed or enlarged (or somewhere in between) in one dimension to the desired aspect ratio, or aspect ration range.
  • MODE_DIMENSION - One dimension (or both, since you can set a percentage) is resize to to the desired aspect ratio, or aspect ration range.

AspectRatioRect

public AspectRatioRect(PlaceRect placeRect,
                       float minAR,
                       float maxAR,
                       float perc,
                       int mode,
                       AtRefRangeNumber alignX,
                       AtRefRangeNumber alignY)
Constructor.

Parameters:
placeRect - The contained place rect that first will be asked for a rectangle. May be null which is same as AbsRect.FILL.
minAR - The minimum acceptable aspect ratio. 2f means twice as wide as high.
maxAR - The maximum acceptable aspect ratio. 0.5f means half as wide as high.
perc - The percentage (normally 0f to 1f) between reduce/enlarge or vertical/horizontal depending on the mode. 0f means reduce or keep horizontal and 1f means enlarge/keep vertical. Any value inbetween is also valid.
mode - How the rectangle should be resized to fi the target aspect ratio.
  • MODE_SIZE - The rectangle is shringed or enlarged (or somewhere in between) in one dimension to the desired aspect ratio, or aspect ration range.
  • MODE_DIMENSION - One dimension (or both, since you can set a percentage) is resize to to the desired aspect ratio, or aspect ration range.
alignX - The horizontal alignment to apply to the resulting rectangle in reference to the original one. If null it will be center aligned.
alignY - The vertical alignment to apply to the resulting rectangle in reference to the original one. If null it will be center aligned.
See Also:
AtStart, AtEnd, AtFraction, AtFixed
Method Detail

correctAspectRatio

protected void correctAspectRatio(java.awt.Rectangle r)
Corrects the aspect ration according to the rules set up in the constructor.

Parameters:
r - The rectangle to correct. Never null.

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.

getPlaceRect

public PlaceRect getPlaceRect()
Returns the contained place rect that first will be quired for an rectangle.

Returns:
The contained place rect. May be null which is same as AbsRect.FILL.

getMinAspectRatio

public float getMinAspectRatio()
Returns the minimum acceptable aspect ratio. 2f means twice as wide as high.

Returns:
The minimum acceptable aspect ratio.

getMaxAspectRatio

public float getMaxAspectRatio()
Returns the maximum acceptable aspect ratio. 0.5f means half as wide as high.

Returns:
The maximum acceptable aspect ratio.

getPercent

public float getPercent()
Returns the percentage (normally 0f to 1f) between reduce/enlarge or vertical/horizontal depending on the mode. 0f means reduce or keep horizontal and 1f means enlarge/keep vertical. Any value inbetween is also valid.

Returns:
The percentage (normally 0f to 1f) between reduce/enlarge or vertical/horizontal depending on the mode.

getMode

public int getMode()
Returns how the rectangle should be resized to fi the target aspect ratio.

Returns:
How the rectangle should be resized to fi the target aspect ratio. E.g. AspectRatioRect.MODE_SIZE.

getAlignmentX

public AtRefRangeNumber getAlignmentX()
Returns the horizontal alignment to apply to the resulting rectangle in reference to the original one.

Returns:
The horizontal alignment to apply to the resulting rectangle in reference to the original one.
See Also:
AtStart, AtEnd, AtFraction, AtFixed

getAlignmentY

public AtRefRangeNumber getAlignmentY()
Returns the vertical alignment to apply to the resulting rectangle in reference to the original one.

Returns:
The vertical alignment to apply to the resulting rectangle in reference to the original one.
See Also:
AtStart, AtEnd, AtFraction, AtFixed

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.