|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.networktools.proportionlayout.ProportionLayout
public class ProportionLayout
The ProportionLayout class is a flexible layout manager that aligns
components vertically and horizontally, without requiring that the components
be of the same size.
ProportionLayout class defines a grid wherein components can
be laid out. Each component managed by a ProportionLayout is
associated with an instance of ProportionConstraints. The
ProportionConstraints object specifies where a component's display
area should be located on the grid and how the component should be positioned
within its display area. In addition to its constraints object, the
ProportionLayout also considers each component's minimum and
preferred sizes in order to determine a component's size.
The following figures show six components (all buttons) managed by a proportion
layout. Figure 1 shows the layout for the components with their preferred size
and Figure 2 shows the layout for the same components resized to a larger size.
|
| Figure 1: the example with its preferred size |
|
| Figure 2: the example resized to a larger size |
import java.awt.*;
import javax.swing.*;
import net.sourceforge.networktools.proportionlayout.*;
public class LayoutTester extends JFrame {
public static void main(String[] args) {
LayoutTester currentFrame = new LayoutTester();
currentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
currentFrame.pack();
currentFrame.show();
}
public LayoutTester() {
super("LayoutTester");
Container contentPanel = getContentPane();
ProportionLayout layout = new ProportionLayout();
// First add all the columns to the ProportionLayout
layout.appendColumn(10); // column 0
// Column 0 will be an empty space of width 10
layout.appendColumn(0, ProportionLayout.NO_PROPORTION); // column 1
// Column 1 will always be the greatest preferred width of all it's components
// Column 1 will never get any of the additional width
layout.appendColumn(10); // column 2
// Column 2 will be an empty space of width 10
layout.appendColumn(0, 1.0); // column 3
// Column 3 will always be the same width as column 5
// Column 3 and 5 will devide any of the additional width between them
layout.appendColumn(10); // column 4
// Column 4 will be an empty space of width 10
layout.appendColumn(0, 1.0); // column 5
// Column 5 will always be the same width as column 3
// Column 3 and 5 will devide any of the additional width between them
layout.appendColumn(10); // column 6
// Column 6 will be an empty space of width 10
// Then add all the rows to the ProportionLayout
layout.appendRow(10); // row 0
// Row 0 will be an empty space of width 10
layout.appendRow(0, ProportionLayout.NO_PROPORTION); // row 1
// Row 1 will always be the greatest preferred height of all it's components
// Row 1 will never get any of the additional height
layout.appendRow(10); // row 2
// Row 2 will be an empty space of width 10
layout.appendRow(0, ProportionLayout.NO_PROPORTION); // row 3
// Row 3 will always be the greatest preferred height of all it's components
// Row 3 will never get any of the additional height
layout.appendRow(10); // row 4
// Row 4 will be an empty space of width 10
layout.appendRow(0, 1.0); // row 5
// Row 5 will get all of the additional height
layout.appendRow(10); // row 6
// Row 6 will be an empty space of width 10
contentPanel.setLayout(layout);
contentPanel.add(new JButton("B1"),
new ProportionConstraints(1, 1) );
// column 1, row 1
contentPanel.add(new JButton("Button 2 takes up a lot of space"),
new ProportionConstraints(3, 1) );
// column 3, row 1
contentPanel.add(new JButton("Button 3"),
new ProportionConstraints(5, 1) );
// column 5, row 1
contentPanel.add(new JButton("B4"),
new ProportionConstraints(1, 3, 3, 1) );
// column 1, row 3 with width 3, height 1
contentPanel.add(new JButton("Button 5"),
new ProportionConstraints(1, 5) );
// column 1, row 5
contentPanel.add(new JButton("B6"),
new ProportionConstraints(5, 3, 1, 3) );
// column 5, row 3 with width 1, height 3
// ProportionConstaints has additional constructors with more parameters
// that allow a more flexible control of how the component will behave
// inside it's own cell.
}
}
| Field Summary | |
|---|---|
protected java.util.TreeSet |
columnLineParts
Contains all the columnLineParts |
protected java.util.ArrayList |
columnLines
Contains all the columnLines for this ProportionLayout. |
protected double |
columnProportionTotal
Contains the total amount of columnLines for this ProportionLayout. |
protected java.util.HashMap |
linePartCouples
Contains which rowLine and columnLine belong together. |
static double |
NO_PROPORTION
Make the column or row have it's preferred width or height, without stretching. |
protected java.util.TreeSet |
rowLineParts
Contains all the rowLineParts |
protected java.util.ArrayList |
rowLines
Contains all the rowLines for this ProportionLayout. |
protected double |
rowProportionTotal
Contains the total amount of rowLines for this ProportionLayout. |
| Constructor Summary | |
|---|---|
ProportionLayout()
Creates a new instance of ProportionLayout |
|
| Method Summary | |
|---|---|
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object object)
Adds a component to the layout, using the specified ProportionConstraints of that object. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
This method isn't supported. |
int |
appendColumn()
Creates a new column at the end of the grid for this ProportionLayout. |
int |
appendColumn(int minimumWidth)
Creates a new column at the end of the grid for this ProportionLayout. |
int |
appendColumn(int minimumWidth,
double lineProportion)
Creates a new column at the end of the grid for this ProportionLayout. |
int |
appendRow()
Creates a new row at the end of the grid for this ProportionLayout. |
int |
appendRow(int minimumHeight)
Creates a new row at the end of the grid for this ProportionLayout. |
int |
appendRow(int minimumHeight,
double lineProportion)
Creates a new row at the end of the grid for this ProportionLayout. |
protected java.awt.Dimension |
arrangeGrid(java.awt.Container parent,
int sizeType)
Arranges the grid for the given container of components and specifies the sizeType of it. |
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 parent)
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 specified container using this proportion layout. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container parent)
Returns the maximum dimensions for this layout given the components in the specified target container. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Determines the minimum size of the target container using this proportion layout. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the target container using this proportion layout. |
void |
removeLayoutComponent(java.awt.Component component)
Removes a component from the ProportionLayout. |
java.lang.String |
toString()
Returns a string representation of this proportion layout's values. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final double NO_PROPORTION
protected java.util.ArrayList columnLines
protected java.util.ArrayList rowLines
protected double columnProportionTotal
protected double rowProportionTotal
protected java.util.HashMap linePartCouples
protected java.util.TreeSet columnLineParts
protected java.util.TreeSet rowLineParts
| Constructor Detail |
|---|
public ProportionLayout()
| Method Detail |
|---|
public int appendColumn()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
public int appendColumn(int minimumWidth)
throws java.lang.IllegalArgumentException
minimumWidth - Spicifies the minimum width for this column.
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
public int appendColumn(int minimumWidth,
double lineProportion)
throws java.lang.IllegalArgumentException
minimumWidth - specifies the minimum width for this column.lineProportion - specifies the proportion for this column.
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
public int appendRow()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
public int appendRow(int minimumHeight)
throws java.lang.IllegalArgumentException
minimumHeight - specifies the minimum height for this row.
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
public int appendRow(int minimumHeight,
double lineProportion)
throws java.lang.IllegalArgumentException
minimumHeight - specifies the minimum height for this row.lineProportion - specifies the proportion for this row.
java.lang.IllegalArgumentException - if one of the arguments is an illegal argument.
protected java.awt.Dimension arrangeGrid(java.awt.Container parent,
int sizeType)
parent - specified the container to be laid out.sizeType - specifies the sizeType for this container.
public void addLayoutComponent(java.awt.Component component,
java.lang.Object object)
throws java.lang.IllegalArgumentException,
java.lang.IndexOutOfBoundsException
ProportionConstraints of that object.
addLayoutComponent in interface java.awt.LayoutManager2component - specifies the component to lay out.object - specifies the cell in which the component is to be laid out.
java.lang.IllegalArgumentException - if the object used as parameter is not of the
ProportionConstraints type.
java.lang.IndexOutOfBoundsException - if the index of the object in which you are
putting the component doesn't exist.
public void addLayoutComponent(java.lang.String name,
java.awt.Component component)
addLayoutComponent in interface java.awt.LayoutManagername - the name of the component.component - the component to be added.public void removeLayoutComponent(java.awt.Component component)
removeLayoutComponent in interface java.awt.LayoutManagercomponent - specifies which component has to be removed.public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize in interface java.awt.LayoutManagerparent - the component to be laid out
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize in interface java.awt.LayoutManagerparent - the container to be laid out.
public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
maximumLayoutSize in interface java.awt.LayoutManager2parent - the component which needs to be laid out.
public float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX in interface java.awt.LayoutManager2parent - the component/container which needs to be aligned along the x axis.
public float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY in interface java.awt.LayoutManager2parent - the component/container which needs to be aligned along the y axis.
public void invalidateLayout(java.awt.Container parent)
invalidateLayout in interface java.awt.LayoutManager2parent - the container that needs to be invalidated.public void layoutContainer(java.awt.Container parent)
ProportionLayout object.
layoutContainer in interface java.awt.LayoutManagerparent - the container in which to do the layout.public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||