JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.swing
Class JCElasticLayout

java.lang.Object
  |
  +--com.klg.jclass.util.swing.JCElasticLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable
Direct Known Subclasses:
JCColumnLayout, JCRowLayout

public class JCElasticLayout
extends Object
implements LayoutManager2, Serializable

A layout manager that supports JCElastic components either horizontally or vertically. A component is considered elastic if it either implements the JCElastic interface or it has a constraint object the implements the JCElastic interface.

Layout is performed in either a single row or column (depending on its orientation at creation). The preferred size is calculated in the direction of orientation. If the container is bigger than the preferred size of all the components, then the extra space is divided up between the components that are "elastic" in the direction of the orientation.

The extra space is allocated to each of the components with respect to their "elasticity". If all the elastic components have the same elasticity (in the direction of the orientation), then they are equally stretched. If there is an uneven number of pixels to allot, then the first n units of elasticity are allocated the extra pixels; where n = total_elasticity % extra_pixels.

See Also:
JCElastic, JCSpring, JCBrace, Serialized Form

Field Summary
protected  int alignment
          Alignment to use when laying out.
static com.klg.jclass.util.swing.JCElastic COMPLETELY_ELASTIC_CONSTRAINT
          Constant to use when adding an elastic constraint to this object.
static String COMPLETELY_ELASTIC_TAG
          Constant to use when adding an String constraint to this object.
protected static HashMap constraintCache
           
protected  HashMap constraintMap
          Hashtable to store components added to the layout.
static int HORIZONTAL
           
protected static int HORIZONTALLY_ELASTIC
          Returned by getElasticity().
static com.klg.jclass.util.swing.JCElastic HORIZONTALLY_ELASTIC_CONSTRAINT
          Constant to use when adding an elastic constraint to this object.
static String HORIZONTALLY_ELASTIC_TAG
          Constant to use when adding an String constraint to this object.
protected static int NOT_ELASTIC
          Returned by getElasticity().
protected  int orientation
          Orientation to lay out in.
static int VERTICAL
           
protected static int VERTICALLY_ELASTIC
          Returned by getElasticity().
static com.klg.jclass.util.swing.JCElastic VERTICALLY_ELASTIC_CONSTRAINT
          Constant to use when adding an elastic constraint to this object.
static String VERTICALLY_ELASTIC_TAG
          Constant to use when adding an String constraint to this object.
 
Constructor Summary
JCElasticLayout(int orientation)
          Creates a row layout that by default aligns components to the left of the row.
JCElasticLayout(int orientation, int alignment)
          Creates a column layout that aligns components according to the specified alignment.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Adds a component to the layout manager with the specified constraint.
 void addLayoutComponent(String name, Component comp)
          Adds a component to the layout.
protected  int calcStretch(int slice, int elasticity, int current_slice, int fatter_slice_count)
          Calculates the amount to stretch an elastic component based on the parameters passed in.
static com.klg.jclass.util.swing.JCElastic createElasticConstraint(int horizontal_elasticity, int vertical_elasticity)
          Creates a JCElastic constraint with the elasticity specified.
 int getAlignment()
          Returns the alignment for the layout.
protected  com.klg.jclass.util.swing.JCElastic getElastic(Component c)
          Returns the Elastic information for a particular component.
protected  int getElasticity(Component c)
          A component may be specified as elastic in two ways.
 float getLayoutAlignmentX(Container target)
          Returns the X layout alignment.
 float getLayoutAlignmentY(Container target)
          Returns the Y layout alignment.
protected  int getPreferredLayoutSize(Container parent, Dimension preferred_size)
          Returns the preferred layout size of the containers within their parent given this layout, and the total amount of "elasticity" in the child components.
 void invalidateLayout(Container target)
          Invalidates the current layout: deletes any information that might be cached regarding the current layout.
protected  boolean isDim1Elastic(Component c)
          Queries whether or not the dimension opposite to the current orientation is elastic or not.
protected  boolean isHorizontallyElastic(Component c)
          Queries whther the given component is horizontally elastic or not.
protected  boolean isVerticallyElastic(Component c)
          Queries whther the given component is vertically elastic or not.
 void layoutContainer(Container parent)
          Lays out the components within the specified parent.
 Dimension maximumLayoutSize(Container parent)
          Returns the maximum layout size of the component.
 Dimension minimumLayoutSize(Container parent)
          Returns the minimum layout size of the containers within their parent given this layout.
 Dimension preferredLayoutSize(Container parent)
          Returns the preferred layout size of the containers within their parent, given this layout.
 void removeLayoutComponent(Component comp)
          Removes a component from the layout.
 void setAlignment(int alignment)
          Sets the alignment for the layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
See Also:
Constant Field Values

HORIZONTALLY_ELASTIC_CONSTRAINT

public static final com.klg.jclass.util.swing.JCElastic HORIZONTALLY_ELASTIC_CONSTRAINT
Constant to use when adding an elastic constraint to this object.


VERTICALLY_ELASTIC_CONSTRAINT

public static final com.klg.jclass.util.swing.JCElastic VERTICALLY_ELASTIC_CONSTRAINT
Constant to use when adding an elastic constraint to this object.


COMPLETELY_ELASTIC_CONSTRAINT

public static final com.klg.jclass.util.swing.JCElastic COMPLETELY_ELASTIC_CONSTRAINT
Constant to use when adding an elastic constraint to this object.


HORIZONTALLY_ELASTIC_TAG

public static final String HORIZONTALLY_ELASTIC_TAG
Constant to use when adding an String constraint to this object.

See Also:
Constant Field Values

VERTICALLY_ELASTIC_TAG

public static final String VERTICALLY_ELASTIC_TAG
Constant to use when adding an String constraint to this object.

See Also:
Constant Field Values

COMPLETELY_ELASTIC_TAG

public static final String COMPLETELY_ELASTIC_TAG
Constant to use when adding an String constraint to this object.

See Also:
Constant Field Values

NOT_ELASTIC

protected static final int NOT_ELASTIC
Returned by getElasticity().

See Also:
Constant Field Values

VERTICALLY_ELASTIC

protected static final int VERTICALLY_ELASTIC
Returned by getElasticity().

See Also:
Constant Field Values

HORIZONTALLY_ELASTIC

protected static final int HORIZONTALLY_ELASTIC
Returned by getElasticity().

See Also:
Constant Field Values

alignment

protected int alignment
Alignment to use when laying out.


orientation

protected int orientation
Orientation to lay out in. HORIZONTAL or VERTICAL.


constraintMap

protected HashMap constraintMap
Hashtable to store components added to the layout.


constraintCache

protected static HashMap constraintCache
Constructor Detail

JCElasticLayout

public JCElasticLayout(int orientation)
Creates a row layout that by default aligns components to the left of the row.

Parameters:
orientation -

JCElasticLayout

public JCElasticLayout(int orientation,
                       int alignment)
Creates a column layout that aligns components according to the specified alignment.

Parameters:
alignment - SwingConstants.LEFT, SwingConstants.TOP, SwingConstants.CENTER, SwingConstants.BOTTOM, or SwingConstants.RIGHT
orientation -
Method Detail

createElasticConstraint

public static com.klg.jclass.util.swing.JCElastic createElasticConstraint(int horizontal_elasticity,
                                                                          int vertical_elasticity)
Creates a JCElastic constraint with the elasticity specified.

Parameters:
horizontal_elasticity -
vertical_elasticity -
Returns:

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Adds a component to the layout.

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name -
comp -

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes a component from the layout.

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
comp -

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Returns the preferred layout size of the containers within their parent, given this layout.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent -
Returns:
preferred layout size

getPreferredLayoutSize

protected int getPreferredLayoutSize(Container parent,
                                     Dimension preferred_size)
Returns the preferred layout size of the containers within their parent given this layout, and the total amount of "elasticity" in the child components.

Parameters:
parent - container in which the layout is occuring
preferred_size - object to return the preferred size in
Returns:
return the sum of elasticity of the child components in the direction of orientation of the layout

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Returns the minimum layout size of the containers within their parent given this layout.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent -
Returns:
minimum layout size

layoutContainer

public void layoutContainer(Container parent)
Lays out the components within the specified parent.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent -

calcStretch

protected int calcStretch(int slice,
                          int elasticity,
                          int current_slice,
                          int fatter_slice_count)
Calculates the amount to stretch an elastic component based on the parameters passed in.

Parameters:
slice - the size of a "slice" of the extra space in the parent component
elasticity - the amount of elasticity in the current component
current_slice - the starting slice for the calculation
fatter_slice_count - the number of slices that need to be "Fatter" by a pixel because the extra space did not divide evenly into the number of slices
Returns:

isDim1Elastic

protected boolean isDim1Elastic(Component c)
Queries whether or not the dimension opposite to the current orientation is elastic or not.

Parameters:
c -
Returns:

getElastic

protected com.klg.jclass.util.swing.JCElastic getElastic(Component c)
Returns the Elastic information for a particular component. This information is found either in the component itself or in the constraint associated with the component.

Parameters:
c -
Returns:
Elastic information

isVerticallyElastic

protected boolean isVerticallyElastic(Component c)
Queries whther the given component is vertically elastic or not.

Parameters:
c -
Returns:

isHorizontallyElastic

protected boolean isHorizontallyElastic(Component c)
Queries whther the given component is horizontally elastic or not.

Parameters:
c -
Returns:

getElasticity

protected int getElasticity(Component c)
A component may be specified as elastic in two ways.
  1. It may implement the JCElastic interface.
  2. It may have specified an elastic constraint when it was added.
This method checks a particular component for either in the orientataion relevent to the current layout.

Parameters:
c -
Returns:

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Adds a component to the layout manager with the specified constraint.

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
comp -
constraints -

maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)
Returns the maximum layout size of the component.

Specified by:
maximumLayoutSize in interface LayoutManager2
Parameters:
parent -
Returns:
maximum layout size

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Returns the X layout alignment.

Specified by:
getLayoutAlignmentX in interface LayoutManager2
Parameters:
target -
Returns:
X layout alignment

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Returns the Y layout alignment.

Specified by:
getLayoutAlignmentY in interface LayoutManager2
Parameters:
target -
Returns:
Y layout alignment

getAlignment

public int getAlignment()
Returns the alignment for the layout.

Returns:
alignment for the layout

setAlignment

public void setAlignment(int alignment)
Sets the alignment for the layout.

Parameters:
alignment -

invalidateLayout

public void invalidateLayout(Container target)
Invalidates the current layout: deletes any information that might be cached regarding the current layout.

Specified by:
invalidateLayout in interface LayoutManager2
Parameters:
target -

Copyright © 2004 Quest Software Inc..
All rights reserved.