org.openbp.swing.layout
Class DeckLayout

java.lang.Object
  extended by org.openbp.swing.layout.DeckLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public class DeckLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

Deck layout. DeckLayout treats each component in the container as a card. Only one card is visible at a time, and the container acts like a deck of cards. The ordering of cards is determined by the container's own internal ordering of its component objects. DeckLayout defines a set of methods that allow an application to flip through the cards sequentially, or to show a specified card. The addLayoutComponent method can be used to associate a string identifier with a given card for faster random access.

Author:
Heiko Erhardt
See Also:
Serialized Form

Constructor Summary
DeckLayout()
          Constructor.
 
Method Summary
 void addLayoutComponent(java.awt.Component c, java.lang.Object constraints)
          Adds the specified component to this deck layout's internal table, by name.
 void addLayoutComponent(java.lang.String name, java.awt.Component c)
          Deprecated. replaced by addLayoutComponent(Component, Object)
 void first(java.awt.Container parent)
          Flips to the first card of the container.
 java.awt.Component getComponentByName(java.lang.String name)
          Gets a component by its name.
 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.
 boolean isWrap()
          Gets the wrap around when flipping through the card stack.
 void last(java.awt.Container parent)
          Flips to the last card of the container.
 void layoutContainer(java.awt.Container parent)
          Lays out the specified container using this deck 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)
          Calculates the minimum size for the specified page.
 int next(java.awt.Container parent)
          Flips to the next card of the specified container.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Calculates the preferred size for the specified page.
 int previous(java.awt.Container parent)
          Flips to the previous card of the specified container.
 void removeLayoutComponent(java.awt.Component c)
          Removes the specified component from the layout.
 void setWrap(boolean wrap)
          Sets the wrap around when flipping through the card stack.
 void show(java.awt.Container parent, int index)
          Flips to the component at the numbered position.
 void show(java.awt.Container parent, java.lang.String name)
          Flips to the component that was added to this layout using the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeckLayout

public DeckLayout()
Constructor.

Method Detail

isWrap

public boolean isWrap()
Gets the wrap around when flipping through the card stack.


setWrap

public void setWrap(boolean wrap)
Sets the wrap around when flipping through the card stack.


addLayoutComponent

public void addLayoutComponent(java.awt.Component c,
                               java.lang.Object constraints)
Adds the specified component to this deck layout's internal table, by name. The object specified by constraints must be a string. The deck layout stores this string as a key-value pair that can be used for random access to a particular card. By calling the show method, an application can display the component with the specified name.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
c - The component to be added
constraints - A name that identifies the component

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component c)
Deprecated. replaced by addLayoutComponent(Component, Object)

Not used any more.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component c)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
c - The component to be removed

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Calculates the preferred size for the specified page.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - The name of the parent container
Returns:
minimum dimensions required to lay out the components

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Calculates the minimum size for the specified page.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - The name of the parent container
Returns:
minimum dimensions required to lay out the components

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the component in the specified target container.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - The component which needs to be laid out
Returns:
The layout size

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the specified container using this deck layout. Each component in the parent container is reshaped to be the same size as the container, minus insets, horizontal and vertical gaps.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - Container that owns the layout

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Parameters:
parent - Container that owns the layout
Returns:
The alignment

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Parameters:
parent - Container that owns the layout
Returns:
The alignment

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2
Parameters:
target - Container that owns the layout

first

public void first(java.awt.Container parent)
Flips to the first card of the container.

Parameters:
parent - Container that owns the layout

next

public int next(java.awt.Container parent)
Flips to the next card of the specified container. If the currently visible card is the last one, this method flips to the first card in the layout.

Parameters:
parent - Container that owns the layout
Returns:
Index of the selected component

previous

public int previous(java.awt.Container parent)
Flips to the previous card of the specified container. If the currently visible card is the first one, this method flips to the last card in the layout.

Parameters:
parent - Container that owns the layout
Returns:
Index of the selected component

last

public void last(java.awt.Container parent)
Flips to the last card of the container.

Parameters:
parent - Container that owns the layout

show

public void show(java.awt.Container parent,
                 java.lang.String name)
Flips to the component that was added to this layout using the specified name. If no such component exists, nothing happens.

Parameters:
parent - Container that owns the layout
name - The component name

show

public void show(java.awt.Container parent,
                 int index)
Flips to the component at the numbered position. If no such component exists, nothing happens.

Parameters:
parent - Container that owns the layout
index - The index (between 0 and component count - 1)

getComponentByName

public java.awt.Component getComponentByName(java.lang.String name)
Gets a component by its name.

Parameters:
name - Name of the component
Returns:
The component or null if no such component exists


Copyright © 2011. All Rights Reserved.