Sharkysoft home

lava.gui
Class ScaledLayout

java.lang.Object
  |
  +--lava.gui.ScaledLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2

public class ScaledLayout
extends java.lang.Object
implements java.awt.LayoutManager2

Arbitrary layout control.

Details: ScaledLayout is a constraints-based layout manager that gives you freestyle layout control over elements in a Container. ScaledLayout's constraints are Rectangles that specify the exact bounds of their associated Components. When performing layouts, ScaledLayout always attempts to make each component fit exactly in the bounds of the supplied rectangle.

When instantiating a ScaledLayout, you must specify a minimum, preferred, and maximum layout size. (If you only specify one size, these three parameters are assumed to be the same.) When laying out components, ScaledLayout checks to see how much room it has to lay them out in (i.e., by calling the container's getSize method). If that amount is different than the preferred size, then ScaledLayout automatically scales each component's boundaries so that they will retain the same relative sizes and positions. (How each individual component handles the scaling operation is up to the component.)

If components are arranged in a manner such that their bounding rectangles overlap, their Z-ordering is controlled by their parent container, not this layout manager.

Since:
1999.04.28
Author:
Sharky

Constructor Summary
ScaledLayout(java.awt.Dimension pref)
          Specifies an inflexible size.
ScaledLayout(java.awt.Dimension min, java.awt.Dimension pref, java.awt.Dimension max)
          Specifies minimum, preferred, and maximum sizes.
 
Method Summary
 void addLayoutComponent(java.awt.Component component, java.lang.Object constraints)
          Binds the added component to its rectangle.
 void addLayoutComponent(java.lang.String s, java.awt.Component component)
          Reserved.
 float getLayoutAlignmentX(java.awt.Container target)
          Returns horizontal alignment information.
 float getLayoutAlignmentY(java.awt.Container target)
          Returns vertical alignment information.
 void invalidateLayout(java.awt.Container target)
          Reserved.
 void layoutContainer(java.awt.Container target)
          Lays out the container's children.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns maximum layout size.
 java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Returns minimum layout size.
 java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Returns preferred layout size.
 void removeLayoutComponent(java.awt.Component component)
          Removes component from layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaledLayout

public ScaledLayout(java.awt.Dimension pref)
Specifies an inflexible size.

Details: This constructor initializes a new instance using pref as the reference size. The preferred, minimum, and maximum layout sizes are set to pref as well.

Parameters:
pref - the layout size

ScaledLayout

public ScaledLayout(java.awt.Dimension min,
                    java.awt.Dimension pref,
                    java.awt.Dimension max)
Specifies minimum, preferred, and maximum sizes.

Details: This constructor initializes a new instance using min, pref, and max as the minimum, preferred, and maximum sizes, respectively. pref is also taken as the reference size.

The sequence (min, pref, max) must be a non-decreasing sequence or the constructor will throw an IllegalArgumentException.

Parameters:
min - the minimum size
pref - the preferred size
max - the maximum size
Method Detail

addLayoutComponent

public void addLayoutComponent(java.awt.Component component,
                               java.lang.Object constraints)
Binds the added component to its rectangle.

Details: This method is called by the Container when a Component is added to Container with a constraint. For ScaledLayout, all constraints must be Rectangles or null. If null is used, the Rectangle returned by the component's getBounds method is used.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
component - the Component
constraints - the bounding Rectangle

addLayoutComponent

public void addLayoutComponent(java.lang.String s,
                               java.awt.Component component)
Reserved.

Details: This method is reserved and will throw an exception if used.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component component)
Removes component from layout.

Details: removeLayoutComponent is called by the target Container when its remove method is called. It removes the indicated Component from this layout mananger's cache of Component/Rectangle bindings.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
component - the component to remove

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Returns minimum layout size.

Details: minimumLayoutSize returns this layout manager's minimum layout size, as indicated at constrution time.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
target - not used

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Returns preferred layout size.

Details: preferredLayoutSize returns this layout manager's preferred layout size, as indicated at constrution time.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
target - not used

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns maximum layout size.

Details: maximumLayoutSize returns this layout manager's maximum layout size, as indicated at constrution time.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - not used

layoutContainer

public void layoutContainer(java.awt.Container target)
Lays out the container's children.

Details: This method is called by the target Container when it needs to lay out it's children. This happens when the Container is first initialized, and may also happen when the Container is resized. This method may change the sizes and positions of the Container's children.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
target - the Container

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Reserved.

Details: This method is sometimes called by the parent Container, but it has no effect.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container target)
Returns horizontal alignment information.

Details: getLayoutAlignmentX returns alignment information about the entire Container. 0.5 is returned, indicating horizontal centering.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Returns:
horizontal alignment value

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container target)
Returns vertical alignment information.

Details: getLayoutAlignmentY returns alignment information about the entire Container. 0.5 is returned, indicating vertical centering.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Returns:
vertical alignment value

Sharkysoft home