com.moneydance.awt
Class Packer

java.lang.Object
  extended by java.awt.GridBagLayout
      extended by com.moneydance.awt.Packer
All Implemented Interfaces:
PackAs, java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public class Packer
extends java.awt.GridBagLayout
implements PackAs

The Packer class extends the GridBagLayout to provide a method based interface to this class. This makes it possible to position several widgets into a GridBagLayout without resetting various values in a GridBagLayout instance. All methods return the PackAs interface which allows the reuse of a particular layout strategy for subsequent widgets via the add() method.

              Panel p = new Panel();                  // Create new Panel container

              Label l = new Label( "label: " );       // Create a label Component
              TextField t = new TextField( 30 );      // Create a TextField Component

              Packer pk = new Packer(p);              // Create Layout and setLayout on container
              pk.pack( l ).gridx(0);                  // Add to Container and layout
              pk.pack( t ).gridx(1).fillx();          // Add to Container and layout
  

Pay attention to the fact that fillx(), filly() and fillboth() change the weights of the respective axis. This is done to unify the expansion factors to equally distribute the components if you do not specify weight[xy] values. If you do not specify the weight[xy] values, they default to 1. Thus, you must always put the weight[xy]() after the fill[xy]() if you want something different than equal expansion.

When putting several buttons into a JPanel, you can use ...fillx().weightx(0) to make all of them the same width, but keep the JPanel from being any wider than the widest button.

Version:
1.0
Author:
Gregg Wonderly
See Also:
Serialized Form

Field Summary
protected  java.awt.Component comp
          The component currently being layed out.
protected  java.awt.Container container
          If the Packer( Container ) constructor is used, this member contains a reference to the container that this instance provides layout for.
protected  java.awt.GridBagConstraints gc
          The current constraints used for subsequent uses of the PackAs interface returned by the methods below.
 
Fields inherited from class java.awt.GridBagLayout
columnWeights, columnWidths, comptable, defaultConstraints, layoutInfo, MAXGRIDSIZE, MINSIZE, PREFERREDSIZE, rowHeights, rowWeights
 
Constructor Summary
Packer()
          Create a new Packer instance.
Packer(java.awt.Container cont)
          Creates a new Packer instance that is used to layout the passed container.
 
Method Summary
 PackAs add(java.awt.Component cp)
          Reuses the previous set of constraints to layout the widget passed
 PackAs bottom()
          Add gridheight=RELATIVE to the constraints for the current component.
 java.lang.Object clone()
          Create a copy of this Packer Object.
 PackAs east()
          Add anchor=EAST to the constraints for the current component.
 PackAs fillboth()
          Add fill=BOTH, weighty=1, weightx=1 to the constraints for the current component.
 PackAs fillx()
          Add fill=HORIZONTAL, weightx=1 to the constraints for the current component.
 PackAs filly()
          Add fill=VERTICAL, weighty=1 to the constraints for the current component.
 boolean getAnchorEast()
           
 boolean getAnchorNorth()
           
 boolean getAnchorNorthEast()
           
 boolean getAnchorNorthWest()
           
 boolean getAnchorSouth()
           
 boolean getAnchorSouthEast()
           
 boolean getAnchorSouthWest()
           
 boolean getAnchorWest()
           
 java.awt.Container getContainer()
          Get the designated container for this instance.
 boolean getFillBoth()
           
 boolean getFillX()
           
 boolean getFillY()
           
 int getGridH()
           
 int getGridW()
           
 int getGridX()
           
 int getGridY()
           
 int getInsetBottom()
           
 int getInsetLeft()
           
 int getInsetRight()
           
 int getInsetTop()
           
 int getPadX()
           
 int getPadY()
           
 boolean getRemainX()
           
 boolean getRemainY()
           
 double getWeightX()
           
 double getWeightY()
           
 boolean getXLeftRelative()
           
 boolean getXRightRelative()
           
 boolean getYBottomRelative()
           
 boolean getYTopRelative()
           
 PackAs gridh(int tot)
          Add gridheight=tot to the constraints for the current component.
 PackAs gridw(int tot)
          Add gridwidth=tot to the constraints for the current component.
 PackAs gridx(int tot)
          Add gridx=tot to the constraints for the current component.
 PackAs gridy(int tot)
          Add gridy=tot to the constraints for the current component.
 PackAs inset(java.awt.Insets insets)
          Specify the insets for the component.
 PackAs inset(int top, int left, int bottom, int right)
          Specify the insets for the component.
 PackAs into(java.awt.Container cont)
          This method is used to specify the container that the next component that is added or packed will be placed in.
 PackAs left()
          Add gridx=RELATIVE to the constraints for the current component.
 PackAs north()
          Add anchor=NORTH to the constraints for the current component.
 PackAs northeast()
          Add anchor=NORTHEAST to the constraints for the current component.
 PackAs northwest()
          Add anchor=NORTHWEST to the constraints for the current component.
 PackAs pack(java.awt.Component cp)
          Establishes a new set of constraints to layout the widget passed.
 PackAs padx(int cnt)
          Add ipadx=cnt to the constraints for the current component.
 PackAs pady(int cnt)
          Add ipady=cnt to the constraints for the current component.
 PackAs remainx()
          Add gridwidth=REMAINDER to the constraints for the current component.
 PackAs remainy()
          Add gridheight=REMAINDER to the constraints for the current component.
 PackAs right()
          Add gridwidth=RELATIVE to the constraints for the current component.
 PackAs setAnchorEast(boolean how)
          Add anchor=EAST to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorNorth(boolean how)
          Add anchor=NORTH to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorNorthEast(boolean how)
          Add anchor=NORTHEAST to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorNorthWest(boolean how)
          Add anchor=NORTHWEST to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorSouth(boolean how)
          Add anchor=SOUTH to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorSouthEast(boolean how)
          Add anchor=SOUTHEAST to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorSouthWest(boolean how)
          Add anchor=SOUTHWEST to the constraints for the current component if how == true remove it if false.
 PackAs setAnchorWest(boolean how)
          Add anchor=WEST to the constraints for the current component if how == true remove it if false.
 PackAs setContainer(java.awt.Container cont)
          Set the designated container for objects packed by this instance.
 PackAs setFillBoth(boolean how)
          Add fill=BOTH, weightx=1, weighty=1 to the constraints for the current component if how == true, fill=0, weightx=0, weighty=0 if it is false.
 PackAs setFillX(boolean how)
          Add fill=HORIZONTAL, weightx=1 to the constraints for the current component if how == true.
 PackAs setFillY(boolean how)
          Add fill=VERITCAL to the constraints for the current component if how == true 1 it if false.
 PackAs setInsetBottom(int val)
          sets bottom Insets on the constraints for the current component to the value specified.
 PackAs setInsetLeft(int val)
          sets left Insets on the constraints for the current component to the value specified.
 PackAs setInsetRight(int val)
          sets right Insets on the constraints for the current component to the value specified.
 PackAs setInsetTop(int val)
          sets top Insets on the constraints for the current component to the value specified.
 PackAs setRemainX(boolean how)
          Add gridWidth=REMAINDER to the constraints for the current component if how == true 1 it if false.
 PackAs setRemainY(boolean how)
          Add gridWidth=REMAINDER to the constraints for the current component if how == true 1 it if false.
 PackAs setXLeftRelative(boolean how)
          Add gridx=RELATIVE to the constraints for the current component if how == true 0 it if false.
 PackAs setXRightRelative(boolean how)
          Add gridWidth=RELATIVE to the constraints for the current component if how == true 1 it if false.
 PackAs setYBottomRelative(boolean how)
          Add gridWidth=RELATIVE to the constraints for the current component if how == true 1 it if false.
 PackAs setYTopRelative(boolean how)
          Add gridy=RELATIVE to the constraints for the current component if how == true 0 it if false.
 PackAs south()
          Add anchor=SOUTH to the constraints for the current component.
 PackAs southeast()
          Add anchor=SOUTHEAST to the constraints for the current component.
 PackAs southwest()
          Add anchor=SOUTHWEST to the constraints for the current component.
 PackAs top()
          Add gridy=RELATIVE to the constraints for the current component.
 PackAs weightx(double wt)
          Add weightx=wt to the constraints for the current component.
 PackAs weighty(double wt)
          Add weighty=wt to the constraints for the current component.
 PackAs west()
          Add anchor=WEST to the constraints for the current component.
 
Methods inherited from class java.awt.GridBagLayout
addLayoutComponent, addLayoutComponent, adjustForGravity, AdjustForGravity, arrangeGrid, ArrangeGrid, getConstraints, getLayoutAlignmentX, getLayoutAlignmentY, getLayoutDimensions, getLayoutInfo, GetLayoutInfo, getLayoutOrigin, getLayoutWeights, getMinSize, GetMinSize, invalidateLayout, layoutContainer, location, lookupConstraints, maximumLayoutSize, minimumLayoutSize, preferredLayoutSize, removeLayoutComponent, setConstraints, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gc

protected java.awt.GridBagConstraints gc
The current constraints used for subsequent uses of the PackAs interface returned by the methods below.


comp

protected java.awt.Component comp
The component currently being layed out.


container

protected java.awt.Container container
If the Packer( Container ) constructor is used, this member contains a reference to the container that this instance provides layout for.

Constructor Detail

Packer

public Packer()
Create a new Packer instance. A Packer constructed with this constructor will have no "designated" container for the elements that it packs. Thus, each will need to be added to the container individually as well as being pack()'d or add()'d with the packer.


Packer

public Packer(java.awt.Container cont)
Creates a new Packer instance that is used to layout the passed container. This version of the constructor allows for more compact code by causing this instance to automatically add() the components to the container as well as do the layout.

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a copy of this Packer Object.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException - if strange clone errors occur

setContainer

public PackAs setContainer(java.awt.Container cont)
                    throws java.lang.IllegalAccessException
Set the designated container for objects packed by this instance.

Parameters:
cont - the Container to use to add the components to when .pack() or .add() is invoked.
Throws:
java.lang.IllegalAccessException - if container already set

getContainer

public java.awt.Container getContainer()
Get the designated container for this instance.


into

public PackAs into(java.awt.Container cont)
            throws java.lang.IllegalAccessException
This method is used to specify the container that the next component that is added or packed will be placed in.

Specified by:
into in interface PackAs
Parameters:
cont - The container to place future components into.
Throws:
java.lang.IllegalAccessException - if container is already set

pack

public PackAs pack(java.awt.Component cp)
Establishes a new set of constraints to layout the widget passed. The created constraints are applied to the passed Component and if a Container is known to this object, the component is added to the known container.

Specified by:
pack in interface PackAs
Parameters:
cp - The component to layout.

add

public PackAs add(java.awt.Component cp)
Reuses the previous set of constraints to layout the widget passed

Specified by:
add in interface PackAs
Parameters:
cp - The component to layout. It must be added to the Container owning this LayoutManager by the calling code.

setAnchorNorth

public PackAs setAnchorNorth(boolean how)
Add anchor=NORTH to the constraints for the current component if how == true remove it if false.


getAnchorNorth

public boolean getAnchorNorth()

north

public PackAs north()
Add anchor=NORTH to the constraints for the current component.

Specified by:
north in interface PackAs

setAnchorSouth

public PackAs setAnchorSouth(boolean how)
Add anchor=SOUTH to the constraints for the current component if how == true remove it if false.


getAnchorSouth

public boolean getAnchorSouth()

south

public PackAs south()
Add anchor=SOUTH to the constraints for the current component.

Specified by:
south in interface PackAs

setAnchorEast

public PackAs setAnchorEast(boolean how)
Add anchor=EAST to the constraints for the current component if how == true remove it if false.


getAnchorEast

public boolean getAnchorEast()

east

public PackAs east()
Add anchor=EAST to the constraints for the current component.

Specified by:
east in interface PackAs

setAnchorWest

public PackAs setAnchorWest(boolean how)
Add anchor=WEST to the constraints for the current component if how == true remove it if false.


getAnchorWest

public boolean getAnchorWest()

west

public PackAs west()
Add anchor=WEST to the constraints for the current component.

Specified by:
west in interface PackAs

setAnchorNorthWest

public PackAs setAnchorNorthWest(boolean how)
Add anchor=NORTHWEST to the constraints for the current component if how == true remove it if false.


getAnchorNorthWest

public boolean getAnchorNorthWest()

northwest

public PackAs northwest()
Add anchor=NORTHWEST to the constraints for the current component.

Specified by:
northwest in interface PackAs

setAnchorSouthWest

public PackAs setAnchorSouthWest(boolean how)
Add anchor=SOUTHWEST to the constraints for the current component if how == true remove it if false.


getAnchorSouthWest

public boolean getAnchorSouthWest()

southwest

public PackAs southwest()
Add anchor=SOUTHWEST to the constraints for the current component.

Specified by:
southwest in interface PackAs

setAnchorNorthEast

public PackAs setAnchorNorthEast(boolean how)
Add anchor=NORTHEAST to the constraints for the current component if how == true remove it if false.


getAnchorNorthEast

public boolean getAnchorNorthEast()

northeast

public PackAs northeast()
Add anchor=NORTHEAST to the constraints for the current component.

Specified by:
northeast in interface PackAs

setAnchorSouthEast

public PackAs setAnchorSouthEast(boolean how)
Add anchor=SOUTHEAST to the constraints for the current component if how == true remove it if false.


getAnchorSouthEast

public boolean getAnchorSouthEast()

southeast

public PackAs southeast()
Add anchor=SOUTHEAST to the constraints for the current component.

Specified by:
southeast in interface PackAs

setXLeftRelative

public PackAs setXLeftRelative(boolean how)
Add gridx=RELATIVE to the constraints for the current component if how == true 0 it if false.


getXLeftRelative

public boolean getXLeftRelative()

left

public PackAs left()
Add gridx=RELATIVE to the constraints for the current component.

Specified by:
left in interface PackAs

setYTopRelative

public PackAs setYTopRelative(boolean how)
Add gridy=RELATIVE to the constraints for the current component if how == true 0 it if false.


getYTopRelative

public boolean getYTopRelative()

top

public PackAs top()
Add gridy=RELATIVE to the constraints for the current component.

Specified by:
top in interface PackAs

setXRightRelative

public PackAs setXRightRelative(boolean how)
Add gridWidth=RELATIVE to the constraints for the current component if how == true 1 it if false.


getXRightRelative

public boolean getXRightRelative()

right

public PackAs right()
Add gridwidth=RELATIVE to the constraints for the current component.

Specified by:
right in interface PackAs

setYBottomRelative

public PackAs setYBottomRelative(boolean how)
Add gridWidth=RELATIVE to the constraints for the current component if how == true 1 it if false.


getYBottomRelative

public boolean getYBottomRelative()

bottom

public PackAs bottom()
Add gridheight=RELATIVE to the constraints for the current component.

Specified by:
bottom in interface PackAs

gridx

public PackAs gridx(int tot)
Add gridx=tot to the constraints for the current component.

Specified by:
gridx in interface PackAs
Parameters:
tot - - the value to set gridx to.

getGridX

public int getGridX()

gridy

public PackAs gridy(int tot)
Add gridy=tot to the constraints for the current component.

Specified by:
gridy in interface PackAs
Parameters:
tot - - the value to set gridy to.

getGridY

public int getGridY()

gridw

public PackAs gridw(int tot)
Add gridwidth=tot to the constraints for the current component.

Specified by:
gridw in interface PackAs
Parameters:
tot - - the value to set gridwidth to.

getGridW

public int getGridW()

gridh

public PackAs gridh(int tot)
Add gridheight=tot to the constraints for the current component.

Specified by:
gridh in interface PackAs
Parameters:
tot - - the value to set gridheight to.

getGridH

public int getGridH()

padx

public PackAs padx(int cnt)
Add ipadx=cnt to the constraints for the current component.

Specified by:
padx in interface PackAs
Parameters:
cnt - - the value to set ipadx to.

getPadX

public int getPadX()

pady

public PackAs pady(int cnt)
Add ipady=cnt to the constraints for the current component.

Specified by:
pady in interface PackAs
Parameters:
cnt - - the value to set ipady to.

getPadY

public int getPadY()

setFillX

public PackAs setFillX(boolean how)
Add fill=HORIZONTAL, weightx=1 to the constraints for the current component if how == true. fill=0, weightx=0 if how is false.


getFillX

public boolean getFillX()

fillx

public PackAs fillx()
Add fill=HORIZONTAL, weightx=1 to the constraints for the current component.

Specified by:
fillx in interface PackAs

setFillY

public PackAs setFillY(boolean how)
Add fill=VERITCAL to the constraints for the current component if how == true 1 it if false.


getFillY

public boolean getFillY()

filly

public PackAs filly()
Add fill=VERTICAL, weighty=1 to the constraints for the current component.

Specified by:
filly in interface PackAs

setFillBoth

public PackAs setFillBoth(boolean how)
Add fill=BOTH, weightx=1, weighty=1 to the constraints for the current component if how == true, fill=0, weightx=0, weighty=0 if it is false.


getFillBoth

public boolean getFillBoth()

fillboth

public PackAs fillboth()
Add fill=BOTH, weighty=1, weightx=1 to the constraints for the current component.

Specified by:
fillboth in interface PackAs

inset

public PackAs inset(java.awt.Insets insets)
Specify the insets for the component.

Specified by:
inset in interface PackAs
Parameters:
insets - the insets to apply

setInsetTop

public PackAs setInsetTop(int val)
sets top Insets on the constraints for the current component to the value specified.


getInsetTop

public int getInsetTop()

getInsetBottom

public int getInsetBottom()

getInsetLeft

public int getInsetLeft()

getInsetRight

public int getInsetRight()

setInsetBottom

public PackAs setInsetBottom(int val)
sets bottom Insets on the constraints for the current component to the value specified.


setInsetLeft

public PackAs setInsetLeft(int val)
sets left Insets on the constraints for the current component to the value specified.


setInsetRight

public PackAs setInsetRight(int val)
sets right Insets on the constraints for the current component to the value specified.


inset

public PackAs inset(int top,
                    int left,
                    int bottom,
                    int right)
Specify the insets for the component.

Specified by:
inset in interface PackAs
Parameters:
left - the inset from the left.
top - the inset from the top.
right - the inset from the right.
bottom - the inset from the bottom.

weightx

public PackAs weightx(double wt)
Add weightx=wt to the constraints for the current component.

Specified by:
weightx in interface PackAs
Parameters:
wt - - the value to set weightx to.

getWeightX

public double getWeightX()

getWeightY

public double getWeightY()

weighty

public PackAs weighty(double wt)
Add weighty=wt to the constraints for the current component.

Specified by:
weighty in interface PackAs
Parameters:
wt - - the value to set weightx to.

setRemainX

public PackAs setRemainX(boolean how)
Add gridWidth=REMAINDER to the constraints for the current component if how == true 1 it if false.


getRemainX

public boolean getRemainX()

remainx

public PackAs remainx()
Add gridwidth=REMAINDER to the constraints for the current component.

Specified by:
remainx in interface PackAs

setRemainY

public PackAs setRemainY(boolean how)
Add gridWidth=REMAINDER to the constraints for the current component if how == true 1 it if false.


getRemainY

public boolean getRemainY()

remainy

public PackAs remainy()
Add gridheight=REMAINDER to the constraints for the current component.

Specified by:
remainy in interface PackAs