|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.wizard.ButtonLayout
public class ButtonLayout
A layout manager for a container that lays out components in a single horizontal row, allowing components to specify the amount of space to place to the right of themselves. This space can be specified as a fixed amount (in number of pixels), a percentage of the leftover space, or the remainder of leftover space. The components are laid out according to their preferred sizes, and are centered within the container's vertical space.
After space is given to components requesting fixed space, any leftover space is divided among components requesting a percentage, and/or the remainder of this space. First, components requesting a percentage are given space, followed by the component requesting the remainder receiving the rest for placement to its right. Only one component may request the remainder.
If no component requests the remaining space, then leftover space will be used to justify the buttons to the left or right side of the container. If the buttons are right justified, then remaining space left after button spacing requests are made is placed to the far left, before any buttons are layed out. If left justified, the buttons are layed out first following the left insets, and any remaining space is placed to the far right.
The default behavior is to justify the components to the right, assuming no component requests the remainder space.
If a component has requested the remainder space, then setting the justification will have no effect. The
justification can be set by invoking the setJustification
method.
A ButtonLayout
layout manager object cannot be shared among containers.
When adding a component to a container with a button layout, use one of these alternatives:
To place a fixed amount of space to the right of the component:
Panel p = new Panel(); p.setLayout(new ButtonLayout()); p.add(new Button("Cancel"), new Integer(10));//Puts 10 pixels of space to right of this componentTo place a percentage of any remaining space to the right of the component:
Panel p = new Panel(); p.setLayout(new ButtonLayout()); p.add(new Button("Help"), new Float(.25)); //Puts 25% of leftover space to right of this componentOne component in the container may claim any remaining space to the right of the component, for example:
Panel p = new Panel(); p.setLayout(new ButtonLayout()); p.add(new Button("Quit"), ButtonLayout.REMAINDER); //Puts leftover space to right of this componentButtonLayout interprets the absence of a constraint specification the same as a request for fixed spacing of 0 pixels for placement to the right of the component:
Panel p = new Panel(); p.setLayout(new ButtonLayout()); p.add(new Button("Next")); // Same as p.add(new Button("Next"), new Integer(0) );
Field Summary | |
---|---|
protected int |
justify
An int value indicating if the components are to be justified to the left or right within the container. |
static java.lang.String |
RB_KEY
|
static java.lang.String |
REMAINDER
The remainder layout constraint. |
protected java.awt.Component |
remainderComponent
The component requesting the remainder of any leftover space |
protected float |
remainingPercentSpace
Value representing percent of remainder space left available to components. |
protected java.util.Hashtable |
rightSpaceTable
Holds a pixel value indicating how much space to layout to the right of each component depending on the current size of the parent container |
protected java.util.Hashtable |
spaceRequestTable
Holds values that reflect the spacing requests for components. |
Constructor Summary | |
---|---|
ButtonLayout()
Constructs a new button layout |
Method Summary | |
---|---|
void |
addLayoutComponent(java.awt.Component comp,
java.lang.Object constraint)
Adds the specified component to the layout, using the specified constraint object. |
void |
addLayoutComponent(java.lang.String string,
java.awt.Component comp)
Adds the specified component with the specified string to the layout. |
java.lang.Object |
getConstraint(java.awt.Component comp)
Returns the spacing constraint for a component, or null if the component is not found. |
float |
getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. |
void |
invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(java.awt.Container parent)
Lays out the container argument using this button layout. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the component in the specified target container. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Returns the minimum dimensions needed to layout the components contained in the specified panel. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Returns the preferred dimensions needed to layout the components contained in the specified panel. |
void |
removeLayoutComponent(java.awt.Component comp)
Removes the specified component from this button layout. |
void |
setConstraint(java.awt.Component comp,
java.lang.Object constraint)
Sets the spacing constraint for a component. |
void |
setJustification(int align)
Sets the Horizontal justification in the parent container. |
Field Detail |
---|
public static final java.lang.String RB_KEY
public static final java.lang.String REMAINDER
protected java.util.Hashtable spaceRequestTable
protected java.util.Hashtable rightSpaceTable
protected java.awt.Component remainderComponent
protected int justify
setJustification(int)
protected float remainingPercentSpace
Constructor Detail |
---|
public ButtonLayout()
Method Detail |
---|
public void addLayoutComponent(java.lang.String string, java.awt.Component comp)
string
is ButtonLayout.REMAINDER.
addLayoutComponent
in interface java.awt.LayoutManager
string
- a constraint specifying the amount of space to place to the right of the componentcomp
- the component to be addedpublic void addLayoutComponent(java.awt.Component comp, java.lang.Object constraint)
For components requesting fixed spacing to their right, constraint
should
be an Integer object, whose value is non-negative and represents the number of pixels to place
to the right of the component.
For components requesting a percentage of leftover space to their right, constraint
should be a Float object. The valid range is between 0 and 1.0, where the value represents the
percent of leftover space to place to the right of the component.
For components requesting the remainder of leftover space, constraint
should be a String equal to ButtonLayout.REMAINDER.
An IllegalArgumentException is thrown for values outside of the above mentioned ranges on the Float and Integer constraints.
addLayoutComponent
in interface java.awt.LayoutManager2
comp
- the component to be addedconstraint
- an Integer, Float, or String object which specifies the amount of space to place to the right of the componentpublic void removeLayoutComponent(java.awt.Component comp)
remove
or removeAll
methods.
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- the component to be removedpublic java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize
in interface java.awt.LayoutManager
parent
- the component which needs to be laid outminimumLayoutSize(java.awt.Container)
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize
in interface java.awt.LayoutManager
parent
- the component which needs to be laid outpreferredLayoutSize(java.awt.Container)
public void layoutContainer(java.awt.Container parent)
layoutContainer
in interface java.awt.LayoutManager
parent
- the specified component being laid outpublic java.awt.Dimension maximumLayoutSize(java.awt.Container target)
maximumLayoutSize
in interface java.awt.LayoutManager2
target
- The component which needs to be laid outpublic float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
parent
- the specified component being laid outpublic float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
parent
- the specified component being laid outpublic void invalidateLayout(java.awt.Container target)
invalidateLayout
in interface java.awt.LayoutManager2
public void setJustification(int align)
If a button is already requesting the remainder space, then setting the justification has no affect.
The default is set to Orientations.RIGHT.
parent
- the specified component being laid outalign
- int representation of com.sas.geometry.Orientations.
values can be either Orientations.LEFT, or Orientations.RIGHT.public void setConstraint(java.awt.Component comp, java.lang.Object constraint)
parent
- the specified component being laid outcomp
- the component in the parent container to set the spacing constraint forconstraint
- an Integer, Float, or String object which specifies the amount of space to place to the right
of the buttonpublic java.lang.Object getConstraint(java.awt.Component comp)
comp
- the component in the parent container to get the spacing constraint for
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |