com.jgoodies.uif.util
Class Resizer

java.lang.Object
  extended by com.jgoodies.uif.util.Resizer

public final class Resizer
extends Object

Assists in getting aesthetic aspect ratios for panels and dialogs.

Version:
$Revision: 1.4 $
Author:
Karsten Lentzsch

Field Summary
static Resizer DEFAULT
          The default Resizer for an aspect ratio of 4:3.
static Resizer FIVE2FOUR
          A Resizer for an aspect ratio of 5:4.
static Resizer FOUR2THREE
          A Resizer for an aspect ratio of 4:3.
static Resizer ONE2ONE
          A Resizer for an aspect ratio of 1:1.
static Resizer REVERSE_SQRT
          A Resizer for an aspect ratio of 1:sqrt(2).
static Resizer SQRT
          A Resizer for an aspect ratio of sqrt(2):1.
 
Constructor Summary
Resizer(float aspectRatio)
          Constructs a Resizer with the specified aspect ratio.
 
Method Summary
 Dimension from(Dimension original)
          Returns a Dimension that has this Resizer's aspect ratio and has been computed by adjusting the given dimension.
 Dimension from(Dimension original, int horizontalMargin, int verticalMargin)
          Returns a Dimension that is based on this Resizer's aspect ratio and has been computed by adjusting the given dimension.
 Dimension fromHeight(int height)
          Returns a Dimension with the given height and a computed width so that the result has this Resizer's aspect ratio.
 Dimension fromWidth(int width)
          Returns a Dimension with the given width and a computed height so that the result has this Resizer's aspect ratio.
 void resize(JComponent component)
          Sets the component's preferred size to a Dimension that has this Resizer's aspect ratio.
 void resizeDialogContent(JComponent component)
          Sets the component's preferred size to a Dimension that has this Resizer's aspect ratio.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE2ONE

public static final Resizer ONE2ONE
A Resizer for an aspect ratio of 1:1.


FIVE2FOUR

public static final Resizer FIVE2FOUR
A Resizer for an aspect ratio of 5:4.


FOUR2THREE

public static final Resizer FOUR2THREE
A Resizer for an aspect ratio of 4:3.


DEFAULT

public static final Resizer DEFAULT
The default Resizer for an aspect ratio of 4:3.


SQRT

public static final Resizer SQRT
A Resizer for an aspect ratio of sqrt(2):1.


REVERSE_SQRT

public static final Resizer REVERSE_SQRT
A Resizer for an aspect ratio of 1:sqrt(2).

Constructor Detail

Resizer

public Resizer(float aspectRatio)
Constructs a Resizer with the specified aspect ratio.

Parameters:
aspectRatio - the aspect ratio used to compute Dimensions
Method Detail

from

public Dimension from(Dimension original)
Returns a Dimension that has this Resizer's aspect ratio and has been computed by adjusting the given dimension. Favors expanding the width over expanding the height.

Parameters:
original - the Dimension to be adjusted to be aesthetic
Returns:
a Dimension that has this Resizer's aspect ratio

from

public Dimension from(Dimension original,
                      int horizontalMargin,
                      int verticalMargin)
Returns a Dimension that is based on this Resizer's aspect ratio and has been computed by adjusting the given dimension. The given margins are added to the given width and height and so build a larger dimension before the new aspect ratio is achieved. This is useful if the given dimension describes only part of a larger container. For example if the dimension of a dialog's content pane is given and the larger dialog shall get an aesthetic aspect ratio.

The adjustment algorithm favors expanding the width over expanding the height.

Parameters:
original - the inner Dimension
horizontalMargin - the sum of the left and right margin to be added
verticalMargin - the sum of the top and bottom margin to be added
Returns:
a Dimension that reflects the Resizer's aspect ratio if increased by the given margins

fromHeight

public Dimension fromHeight(int height)
Returns a Dimension with the given height and a computed width so that the result has this Resizer's aspect ratio.

Parameters:
height - the height used to compute the width
Returns:
a Dimension with the given height and a width so that the result has this Resizer's aspect ratio

fromWidth

public Dimension fromWidth(int width)
Returns a Dimension with the given width and a computed height so that the result has this Resizer's aspect ratio.

Parameters:
width - the width used to compute the height
Returns:
a Dimension with the given width and a height so that the result has this Resizer's aspect ratio

resize

public void resize(JComponent component)
Sets the component's preferred size to a Dimension that has this Resizer's aspect ratio. First requests the component's current preferred sized, uses this to compute an aesthetic Dimension, which is finally set as new preferred size.

Parameters:
component - the component to be resized
See Also:
from(Dimension)

resizeDialogContent

public void resizeDialogContent(JComponent component)
Sets the component's preferred size to a Dimension that has this Resizer's aspect ratio. First requests the component's current preferred sized, uses this to compute an aesthetic Dimension, which is finally set as new preferred size.

Parameters:
component - the component to be resized
See Also:
from(Dimension, int, int)


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.