|
FreeHEP API Version current |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.freehep.swing.layout.ConstrainedGridLayout
The ConstrainedGridLayout
layout manager is based on
the GraphPaperLayout
layout manager written by Michael
Martak.
This layout manager divides the container into a set of equally
sized cells arranged in a grid which has nw
cells
in the horizontal direction and nh
cells in the
vertical direction. Components can occupy an rectangular subset of
these cells; the component's position and size are based on given
rectangular constraints.
This extends the functionality of the GraphPaperLayout
manager by also constraining the overall aspect ratio of the
container. It will also force a containing window to resize if
the desired size of the container isn't a size which is allowed by
the contraints. A byproduct of this is that the preferred sizes of
components controlled by this layout manager will be reset to the
largest allowed size which is smaller than the current size.
Components can overlap making this layout manager a good choice for
a JLayeredPane
. To allow the standard moveToFront and
moveToBack methods to work as expected, the constraints of a
removed component are retained so that if it is later added again
without contraints the layout manager will still arrange the
components reasonably. (The standard moveToFront implementation,
removes a component and re-adds it without taking into account the
possible constraints.)
Field Summary | |
static String |
ASPECT_RATIO_ERROR
|
static String |
CONSTRAINED_GRID_LAYOUT_CONSTRAINT
|
static String |
CONSTRAINT_ERROR
|
static String |
GRID_SIZE_ERROR
|
static int |
MINIMUM_LAYOUT
|
static int |
PREFERRED_LAYOUT
|
Constructor Summary | |
ConstrainedGridLayout(Dimension gridSize,
Dimension aspectRatio)
Creates a ConstrainedGridLayout with the given
grid size and aspect ratio. |
Method Summary | |
void |
addLayoutComponent(Component comp,
Object constraints)
Adds the specified component to the layout, using the specified constraint object. |
void |
addLayoutComponent(String name,
Component comp)
Adds the specified component with the specified name to the layout. |
boolean |
adjustSize(Container parent,
int sizeIncrement)
Change the size of the component by the given increment in the size. |
boolean |
adjustSize(Dimension trialSize)
Adjust the given size of the parent (minus the insets) to an appropriate size. |
Dimension |
getAspectRatio()
Return a new Dimension which is a copy of the
current aspect ratio. |
Rectangle |
getConstrainedBounds(Container parent,
Rectangle constrainedBounds,
Rectangle inputBounds)
Return a rectangle containing the constrained bounds for the given input bounds. |
Rectangle |
getConstraints(Component comp)
Get the constraints being used for the given component. |
Rectangle |
getConstraints(Container parent,
Rectangle constraints,
Rectangle inputBounds)
Return a rectangle containing the appropriate constraint rectangle for the given input bounds. |
Dimension |
getGridSize()
Return a new Dimension which is a copy of the
current grid size. |
float |
getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. |
protected Dimension |
getLayoutSize(Container parent,
int selectionFlag)
Calculate the largest minimum or preferred cell size. |
void |
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(Container parent)
Lays out the container in the specified container. |
Dimension |
maximumLayoutSize(Container target)
Returns the maximum size of this component. |
Dimension |
minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified panel given the components in the specified parent container. |
Dimension |
preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified panel given the components in the specified parent container. |
void |
removeLayoutComponent(Component comp)
Removes the specified component from the layout. |
void |
setAspectRatio(Dimension aspectRatio)
Set the current aspect ratio to the given Dimension . |
void |
setConstraints(Component comp,
Rectangle constraints)
Set (or reset) the constraints for the given component. |
void |
setGridSize(Dimension gridSize)
Set the current grid size to the given Dimension .
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String GRID_SIZE_ERROR
public static final String ASPECT_RATIO_ERROR
public static final String CONSTRAINT_ERROR
public static final String CONSTRAINED_GRID_LAYOUT_CONSTRAINT
public static final int MINIMUM_LAYOUT
public static final int PREFERRED_LAYOUT
Constructor Detail |
public ConstrainedGridLayout(Dimension gridSize, Dimension aspectRatio)
ConstrainedGridLayout
with the given
grid size and aspect ratio.
gridSize
- size of grid in logical units (width x height)aspectRatio
- aspect ratio of container (width x height)Method Detail |
public Dimension getGridSize()
Dimension
which is a copy of the
current grid size.
public void setGridSize(Dimension gridSize)
Dimension
.
The grid size must have horizontal and vertical components
which are positive.
gridSize
- new grid sizepublic Dimension getAspectRatio()
Dimension
which is a copy of the
current aspect ratio.
public void setAspectRatio(Dimension aspectRatio)
Dimension
. The aspect ratio must have horizontal
and vertical components which are positive.
aspectRatio
- new aspect ratio for the containerpublic Rectangle getConstraints(Component comp)
comp
- the component to lookup
Rectangle
describing the position and size
of the given componentpublic void setConstraints(Component comp, Rectangle constraints)
comp
- the component to constrainconstraints
- Rectangle
describing the
position and size of the componentpublic void addLayoutComponent(String name, Component comp)
ConstrainedGridLayout
will arrange this
component normally if a constraint has been set previously or
is set before the container is next validated. If not, then
this component will be ignored by this layout manager.
The component name is always ignored by this layout manager.
addLayoutComponent
in interface LayoutManager
name
- name of component (ignored)comp
- component to add to the layoutpublic void removeLayoutComponent(Component comp)
JLayeredPane
is called.)
removeLayoutComponent
in interface LayoutManager
comp
- the component to be removedpublic Dimension preferredLayoutSize(Container parent)
preferredLayoutSize
in interface LayoutManager
parent
- the component to be laid outminimumLayoutSize(java.awt.Container)
public Dimension minimumLayoutSize(Container parent)
minimumLayoutSize
in interface LayoutManager
parent
- the component to be laid outpreferredLayoutSize(java.awt.Container)
protected Dimension getLayoutSize(Container parent, int selectionFlag)
parent
- the container in which to do the layout.selectionFlag
- either MINIMUM_LAYOUT or PREFERRED_LAYOUT.
public boolean adjustSize(Dimension trialSize)
Dimension
is modified and returned rather than
creating a new object.
trialSize
- parent's size minus insets to adjust;
trialSize is overwritten with the adjusted size of the
component
public boolean adjustSize(Container parent, int sizeIncrement)
parent
- the component controlled by this layout managersizeIncrement
- number of increments by which to increase
the size
public void layoutContainer(Container parent)
layoutContainer
in interface LayoutManager
parent
- the component which needs to be laid outpublic Rectangle getConstrainedBounds(Container parent, Rectangle constrainedBounds, Rectangle inputBounds)
parent
- the Container which contains this componentconstrainedBounds
- the rectangle which will be
overwritten with the result (if null, new Rectangle is created)inputBounds
- the input bounds to constrain to this layout
manager's grid
public Rectangle getConstraints(Container parent, Rectangle constraints, Rectangle inputBounds)
parent
- the Container which contains this componentconstraints
- the rectangle which will be
overwritten with the result (if null, new Rectangle is created)inputBounds
- the input bounds to constrain to this layout
manager's grid
public void addLayoutComponent(Component comp, Object constraints)
addLayoutComponent
in interface LayoutManager2
comp
- the component to be addedconstraints
- where/how the component is added to the
layout; this must be a Rectangle
public Dimension maximumLayoutSize(Container target)
maximumLayoutSize
in interface LayoutManager2
Component.getMinimumSize()
,
Component.getPreferredSize()
,
LayoutManager
public float getLayoutAlignmentX(Container target)
getLayoutAlignmentX
in interface LayoutManager2
public float getLayoutAlignmentY(Container target)
getLayoutAlignmentY
in interface LayoutManager2
public void invalidateLayout(Container target)
invalidateLayout
in interface LayoutManager2
|
FreeHEP API Version current |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |