|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.wordpress.tipsforjava.swing.OverlapLayout
public class OverlapLayout extends Object
The OverlapLayout class is a layout manager that
lays out a container's components in an overlapping fashion. A
component can be painted "above" or "below" the previous component
in the container.
Like the GridLayout, each component is sized to the largest width and
height of any component in the container. The amount of overlap is
controlled by specifying the overlap postion of each component. You can
simulate, left-to-right, right-to-left, top-to-bottom, bottom-to-top and
diagonal layouts. As well you can "stack" components completely on top of
one another. In this case the components are sized to the space available
in the container.
A main usage for this layout might be in the creation of "card games". A
few features have been added that might be handy in these cases:
a) a "popup" feature - when a component is selected in can "popup" from
its regular location so it visibly stands out. To accomplish this some
extra space must be reserved in the container for the popup. This is
done by using the setPopupInsets method which allow you to control the
popup direction. In addition you can add/remove a simple constraint to
the component. POP_UP will popup the component. POP_DOWN or null
will paint the component in its regular location.
b) when a component is made "invisible" you can reserve its location in the
container so all the other components don't shift.
Note: this layout is achieved by changing the ZOrder of components in the
container. It will not work for all components as some compnents will
always paint themselves on the top of others. This seems to happen with
components like JButton as rollover effects are painted when a mouse moves
over the components.
| Field Summary | |
|---|---|
private static int |
MINIMUM
|
static Boolean |
POP_DOWN
|
static Boolean |
POP_UP
|
private static int |
PREFERRED
|
private List |
components
|
private HashMap |
constraints
|
private boolean |
includeInvisible
|
private Dimension |
maximumSize
|
private boolean |
overlapAbove
|
private Point |
overlapPosition
|
private Insets |
popupInsets
|
| Constructor Summary | |
OverlapLayout()
Convenience constructor to provide for "stacking" of components. |
|
OverlapLayout(Point overlapPosition)
Convenience constructor. |
|
OverlapLayout(Point overlapPosition, boolean overlapAbove)
Create an overlapping layout. |
|
| Method Summary | |
|---|---|
void
|
addLayoutComponent(String name, Component comp)
Adds the specified component with the specified name to the layout. |
void
|
addLayoutComponent(Component component, Object constraint)
|
int
|
convertIndex(int index)
When components are overlapped above the ZOrder of each component is changed resulting in the components position in the container being changed. |
Boolean
|
getConstraints(Component component)
Gets the constraints for the specified component. |
private Dimension
|
getDimension(Component component, int type)
|
float
|
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. |
float
|
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. |
private Dimension
|
getLayoutSize(Container parent, int type)
|
Point
|
getOverlapPosition()
Get the overlapping position of each component |
Insets
|
getPopupInsets()
Get the popup insets |
void
|
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
boolean
|
isIncludeInvisible()
Get the include invisible property |
void
|
layoutContainer(Container parent)
Lays out the specified container using this layout. |
Dimension
|
maximumLayoutSize(Container target)
There is no maximum. |
Dimension
|
minimumLayoutSize(Container parent)
Determine the minimum size on the Container |
Dimension
|
preferredLayoutSize(Container parent)
Determine the preferred size on the Container |
void
|
removeLayoutComponent(Component component)
Removes the specified component from the layout. |
void
|
setIncludeInvisible(boolean includeInvisible)
Controls whether spaces should reserved for invisible components in the container |
void
|
setOverlapPosition(Point overlapPosition)
Specify the position where the overlapped component should be painted. |
void
|
setPopupInsets(Insets popupInsets)
Define extra space to be reserved by the container. |
String
|
toString()
Returns the string representation of this column layout's values. |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
private static final int MINIMUM
public static Boolean POP_DOWN
public static Boolean POP_UP
private static final int PREFERRED
private List components
private HashMap constraints
private boolean includeInvisible
private Dimension maximumSize
private boolean overlapAbove
private Point overlapPosition
private Insets popupInsets
| Constructor Detail |
|---|
public OverlapLayout()
public OverlapLayout(Point overlapPosition)
overlapPosition - a Point defining the relative amount of overlap
public OverlapLayout(Point overlapPosition, boolean overlapAbove)
overlapPosition - a Point defining the relative amount of overlapoverlayAbove - when true components are painted above the previous
component, otherwise they are painted below.
| Method Detail |
|---|
public void addLayoutComponent(String name, Component comp)
name - the name of the componentcomp - the component to be added
public void addLayoutComponent(Component component, Object constraint)
public int convertIndex(int index)
index - the index to convert
public Boolean getConstraints(Component component)
component - the component to be queried
private Dimension getDimension(Component component, int type)
public float getLayoutAlignmentX(Container parent)
public float getLayoutAlignmentY(Container parent)
private Dimension getLayoutSize(Container parent, int type)
public Point getOverlapPosition()
public Insets getPopupInsets()
public void invalidateLayout(Container target)
public boolean isIncludeInvisible()
public void layoutContainer(Container parent)
target - the container in which to do the layout
public Dimension maximumLayoutSize(Container target)
public Dimension minimumLayoutSize(Container parent)
target - the container in which to do the layout
public Dimension preferredLayoutSize(Container parent)
parent - the container in which to do the layout
public void removeLayoutComponent(Component component)
comp - the component to be removed
public void setIncludeInvisible(boolean includeInvisible)
includeInvisible - when true, space is reserved otherwise the
component is not included in the layout sizing
public void setOverlapPosition(Point overlapPosition)
overlapPosition - the position where the next component is painted
public void setPopupInsets(Insets popupInsets)
popupInsets - Insets defining extra space for a particular side
of the container.
public String toString()
Groovy Documentation