JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.swing
Class ToolBarLayout

java.lang.Object
  extended by java.awt.BorderLayout
      extended by net.sf.japi.swing.ToolBarLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class ToolBarLayout
extends BorderLayout

A LayoutManager that manages a layout of a Container similar to BorderLayout but with an important difference, it is possible to add as many components to a side layout region as you want. The desired purpose is to serve as LayoutManager for containers that shall contain toolbars. So this is a LayoutManager you always were looking for.

Technically, this class is not a 100% replacement for BorderLayout. JToolBar's UI (BasicToolBarUI) directly looks for some features of the class BorderLayout, and if it is not BorderLayout, it uses some defaults. This class has been developed to make these defaults work as good as possible. Though this class doesn't technically replace BorderLayout - neither is this class a subclass of BorderLayout nor does it provide all methods BorderLayout does - it still does practically.

The constant values BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST and BorderLayout.CENTER are references to those of BorderLayout. The behaviour of BorderLayout.CENTER is that of BorderLayout: only one component can be added, subsequently added components overried all previously added.

The behaviour of BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST and BorderLayout.WEST differs from BorderLayout. The position and layout behaviour is the same, with the slight difference that this LayoutManager is able to manage more than on single component in these four regions. Subsequently added components are placed from the outer to the inner. The first added component is the outmost component of that region, the last added component is the innermost component of that region. To place a component to the innermost level, simply add it to the same region again.

Placing a component another level than the innermost of its destination region is currently not supported but might well be supported in future.

There are four possible ways of specifying a constraint:

. The constraint may be one of the String constants from this class or BorderLayout or it may be a ToolBarLayout.ToolBarConstraints.

Author:
Christian Hujer
See Also:
BorderLayout, JToolBar, Serialized Form
Todo:
support rtl containers the same way as BorderLayout does it., test ToolBarLayout.ToolBarConstraints and ToolBarLayout.ToolBarConstraints.Region

Nested Class Summary
static class ToolBarLayout.ToolBarConstraints
          Class for ToolBarLayout constraints.
 
Field Summary
 
Fields inherited from class java.awt.BorderLayout
AFTER_LAST_LINE, AFTER_LINE_ENDS, BEFORE_FIRST_LINE, BEFORE_LINE_BEGINS, CENTER, EAST, LINE_END, LINE_START, NORTH, PAGE_END, PAGE_START, SOUTH, WEST
 
Constructor Summary
ToolBarLayout()
          Create a ToolBarLayout with zero gaps.
ToolBarLayout(int hgap, int vgap)
          Create a TooLBarLayout.
 
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)
          If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
 float getLayoutAlignmentX(Container parent)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(Container parent)
          Returns the alignment along the y axis.
 void invalidateLayout(Container target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void layoutContainer(Container target)
          Lays out the container argument using this border layout.
 Dimension maximumLayoutSize(Container target)
          Returns the maximum dimensions for this layout given the components in the specified target container.
 Dimension minimumLayoutSize(Container target)
          Determines the minimum size of the target container using this layout manager.
 Dimension preferredLayoutSize(Container target)
          Determines the preferred size of the target container using this layout manager, based on the components in the container.
 void removeLayoutComponent(Component comp)
          Removes the specified component from this border layout.
 String toString()
          Returns a string representation of the state of this border layout.
 
Methods inherited from class java.awt.BorderLayout
getConstraints, getHgap, getLayoutComponent, getLayoutComponent, getVgap, setHgap, setVgap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ToolBarLayout

public ToolBarLayout()
Create a ToolBarLayout with zero gaps.


ToolBarLayout

public ToolBarLayout(int hgap,
                     int vgap)
Create a TooLBarLayout.

Parameters:
hgap - horizontal gap between components
vgap - vertical gap between components
Method Detail

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

Specified by:
addLayoutComponent in interface LayoutManager
Overrides:
addLayoutComponent in class BorderLayout
Parameters:
name - the string to be associated with the component
comp - the component to be added

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Adds the specified component to the layout, using the specified constraint object. For border layouts, the constraint must be one of the following constants: NORTH, SOUTH, EAST, WEST, or CENTER.

Most applications do not call this method directly. This method is called when a component is added to a container using the Container.add method with the same argument types.

Specified by:
addLayoutComponent in interface LayoutManager2
Overrides:
addLayoutComponent in class BorderLayout
Parameters:
comp - the component to be added.
constraints - an object that specifies how and where the component is added to the layout.
See Also:
Container.add(java.awt.Component, java.lang.Object)

getLayoutAlignmentX

public float getLayoutAlignmentX(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 LayoutManager2
Overrides:
getLayoutAlignmentX in class BorderLayout

getLayoutAlignmentY

public float getLayoutAlignmentY(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 LayoutManager2
Overrides:
getLayoutAlignmentY in class BorderLayout

invalidateLayout

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

Specified by:
invalidateLayout in interface LayoutManager2
Overrides:
invalidateLayout in class BorderLayout

layoutContainer

public void layoutContainer(Container target)
Lays out the container argument using this border layout.

This method actually reshapes the components in the specified container in order to satisfy the constraints of this BorderLayout object. The NORTH and SOUTH components, if any, are placed at the top and bottom of the container, respectively. The WEST and EAST components are then placed on the left and right, respectively. Finally, the CENTER object is placed in any remaining space in the middle.

Most applications do not call this method directly. This method is called when a container calls its doLayout method.

Specified by:
layoutContainer in interface LayoutManager
Overrides:
layoutContainer in class BorderLayout
Parameters:
target - the container in which to do the layout.
See Also:
Container, Container.doLayout()

maximumLayoutSize

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

Specified by:
maximumLayoutSize in interface LayoutManager2
Overrides:
maximumLayoutSize in class BorderLayout
Parameters:
target - the component which needs to be laid out
See Also:
Container, BorderLayout.minimumLayoutSize(java.awt.Container), BorderLayout.preferredLayoutSize(java.awt.Container)

minimumLayoutSize

public Dimension minimumLayoutSize(Container target)
Determines the minimum size of the target container using this layout manager.

This method is called when a container calls its getMinimumSize method. Most applications do not call this method directly.

Specified by:
minimumLayoutSize in interface LayoutManager
Overrides:
minimumLayoutSize in class BorderLayout
Parameters:
target - the container in which to do the layout.
Returns:
the minimum dimensions needed to lay out the subcomponents of the specified container.
See Also:
Container, BorderLayout.preferredLayoutSize(java.awt.Container), Container.getMinimumSize()

preferredLayoutSize

public Dimension preferredLayoutSize(Container target)
Determines the preferred size of the target container using this layout manager, based on the components in the container.

Most applications do not call this method directly. This method is called when a container calls its getPreferredSize method.

Specified by:
preferredLayoutSize in interface LayoutManager
Overrides:
preferredLayoutSize in class BorderLayout
Parameters:
target - the container in which to do the layout.
Returns:
the preferred dimensions to lay out the subcomponents of the specified container.
See Also:
Container, BorderLayout.minimumLayoutSize(java.awt.Container), Container.getPreferredSize()

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes the specified component from this border layout. This method is called when a container calls its remove or removeAll methods. Most applications do not call this method directly.

Specified by:
removeLayoutComponent in interface LayoutManager
Overrides:
removeLayoutComponent in class BorderLayout
Parameters:
comp - the component to be removed.
See Also:
Container.remove(java.awt.Component), Container.removeAll()

toString

public String toString()
Returns a string representation of the state of this border layout.

Overrides:
toString in class BorderLayout
Returns:
a string representation of this border layout.

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright