|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pagelayout.PageLayout
public class PageLayout
PageLayout is a layout manager which can be used by placing the components in rows, columns, or grids of cells with specified horizontal and vertical alignment (akin to text on a page of a document, and hence the appellation). At its simplest, a cell, which is just a rectangle, may contain a single component or a gap. However, a cell may recursively contain other cells which are themselves rows, columns or grids of cells containing components or gaps. As a result, components may be arranged in relatively complex layouts with comparatively little programming effort.
In principle, it is possible to duplicate the functionality
of PageLayout
by using objects of the class javax.swing.JPanel
together with one of the many other existing layout
managers, but only at the cost of substantially increased complexity.
Conversely, the functionality of the various layout managers that
are a part of the standard Java distribution can be very simply
duplicated by using just a single layout manager,
the PageLayout
.
Here is an example of the use of PageLayout for managing the layout of the dialog box shown below.
// Main frame and its container JFrame frame=new JFrame(); Container container=frame.getContentPane(); // Create the components JLabel findWhat=new JLabel("Find What:"); JTextField textInput=new JTextField(); JButton find=new JButton("Find"); JCheckBox matchCase=new JCheckBox("Match Case"); JCheckBox wrapAround= new JCheckBox("Wrap Around"); JButton cancel=new JButton("Cancel"); JCheckBox wholeWords=new JCheckBox("Whole Words"); JCheckBox searchBackwards=new JCheckBox("Search Backwards"); // First column Column col1=new Column(findWhat); // Second column Column col2=new Column( new Row(textInput), new Row(matchCase,wrapAround), new Row(wholeWords,searchBackwards) ); // Third column Column col3=new Column(find,cancel); // Create page from columns Row row=new Row(col1,col2,col3); // Add size constraints row.linkHeight(find,new Component[]{textInput}, new double[]{1}); row.linkWidth(cancel,new Component[]{find}, new double[]{1}); row.linkWidth(wholeWords,new Component[]{matchCase}, new double[]{1}); // Construct the layout PageLayout pageLayout=row.createLayout(container); frame.pack(); frame.setSize(frame.getPreferredSize()); frame.setResizable(false); frame.show();
Note that the constructor for PageLout
is not called directly, but by calling the
createLayout
method of the class
Cell
. Finally the methods
linkHeight
and
linkHeight
are used
to impose some width and height constraints.
Cell
,
Column
,
Row
,
CellGrid
Nested Class Summary | |
---|---|
static class |
PageLayout.ContainerHeightLink
|
static class |
PageLayout.ContainerSizeLink
|
static class |
PageLayout.ContainerWidthLink
|
Constructor Summary | |
---|---|
protected |
PageLayout(java.awt.Container parent,
Cell topLevelCell)
The constructor for the Layout Manager. |
Method Summary | |
---|---|
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object constraint)
This method of the LayoutManager2 interface is not implemented. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
This method of the LayoutManager interface is not implemented. |
static PageLayout.ContainerSizeLink |
createLink(java.awt.Component[] components,
double[][] fraction,
boolean isX)
|
java.awt.Insets |
getInset()
|
float |
getLayoutAlignmentX(java.awt.Container target)
Returns the 0.f, which specifies that the component would like to be aligned along the x-axis at the origin. |
float |
getLayoutAlignmentY(java.awt.Container target)
Returns the 0.f, which specifies that the component would like to be aligned along the y-axis at the origin. |
Cell |
getTopLevelCell()
Returns the top level cell, which is the cell whose createLayout method was used to
create this layout manager. |
void |
invalidateLayout(java.awt.Container target)
Invalidates the layout. |
void |
layoutContainer(java.awt.Container parent)
This method of the LayoutManager interface is called by the container whenever it needs to layout the components within it. |
void |
linkToContainerHeight(java.awt.Component[] components,
double[][] affineConstants)
This method can be used to impose constraints on the heights of the components within the container as linear functions of the height of the container itself. |
void |
linkToContainerWidth(java.awt.Component[] components,
double[][] affineConstants)
This method can be used to impose constraints on the widths of the components within the container as linear functions of the width of the container itself. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container parent)
Returns the maximum layout size of the container. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Returns the minimum layout size of the container. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Returns the preferred layout size of the container. |
void |
removeLayoutComponent(java.awt.Component component)
This method of the LayoutManager is not implemented. |
void |
setContainerGaps(int horizontalGap,
int verticalGap)
Sets the so called container gaps so that the components are laid out, if possible, in an area that leaves out empty rectangular areas of specified size on the edges of the container. |
void |
setDimensions(java.awt.Container parent)
|
void |
setLinks(java.util.Vector<PageLayout.ContainerSizeLink> v)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected PageLayout(java.awt.Container parent, Cell topLevelCell)
createLayout
method
of the top level cell should be called to instantiate
an object of this class.
parent
- the container whose layout is to be
managed by the PageLayout object.topLevelCell
- the top-level cell which may be any of the
concrete sub-classes of the abstract class Cell.Method Detail |
---|
public void setDimensions(java.awt.Container parent)
public void setContainerGaps(int horizontalGap, int verticalGap)
horizontalGap
- the desired width of the empty strips inside the
vertical edges of the container.verticalGap
- the desired height of the empty strips inside the
horizontal edges of the container.public Cell getTopLevelCell()
createLayout
method was used to
create this layout manager.
public void addLayoutComponent(java.lang.String name, java.awt.Component component)
replaceCell
method of the
class Cell
, which can also be used to
add a new component to an existing
Row
or
Column
object.
addLayoutComponent
in interface java.awt.LayoutManager
public void addLayoutComponent(java.awt.Component component, java.lang.Object constraint)
replaceCell
method of the
class Cell
, which can also be used to
add a new component to an existing
Row
or
Column
object.
addLayoutComponent
in interface java.awt.LayoutManager2
public void layoutContainer(java.awt.Container parent)
PageLayout
calls the
layout
method of the top level cell
to actually perform the layout.
layoutContainer
in interface java.awt.LayoutManager
parent
- the container within which the components need to be
laid out.public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize
in interface java.awt.LayoutManager
parent
- the container whose minimum size is required.
public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
maximumLayoutSize
in interface java.awt.LayoutManager2
parent
- the container whose maximum size is required.
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize
in interface java.awt.LayoutManager
parent
- the container whose preferred size is required.
public void removeLayoutComponent(java.awt.Component component)
removeComponent
method
of the top level cell, which can be retrieved by using the
getTopLevelCell
method of this class.
removeLayoutComponent
in interface java.awt.LayoutManager
public float getLayoutAlignmentX(java.awt.Container target)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
public float getLayoutAlignmentY(java.awt.Container target)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
public void invalidateLayout(java.awt.Container target)
invalidateLayout
in interface java.awt.LayoutManager2
public void linkToContainerWidth(java.awt.Component[] components, double[][] affineConstants)
W
of the container, the
the width of the component components[i]
is reset to be
W*affineConstants[i][0]+affineConstants[i][1]
everytime the container is resized. Thus, for example,
with affineConstants[i][0]=0.5
and
affineConstants[i][1]=-10
, the width of the component
is restricted to be ten pixels less than half the width of the
container.
components
- the array of components whose widths are to be linked
with the width of the container.affineConstants
- the array of constraint parameters as
defined above.public void linkToContainerHeight(java.awt.Component[] components, double[][] affineConstants)
H
of the container, the
the height of the component components[i]
is reset to be
H*affineConstants[i][0]+affineConstants[i][1]
everytime the container is resized. Thus, for example,
with affineConstants[i][0]=0.5
and
affineConstants[i][1]=-10
, the height of the component
is restricted to be ten pixels less than half the height of the
container.
components
- the array of components whose heights are to be linked
with the height of the container.affineConstants
- the array of constraint parameters as
defined above.public void setLinks(java.util.Vector<PageLayout.ContainerSizeLink> v)
public static PageLayout.ContainerSizeLink createLink(java.awt.Component[] components, double[][] fraction, boolean isX)
public java.awt.Insets getInset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |