kirk.gui.layout
Class LineLayout

java.lang.Object
  |
  +--kirk.gui.layout.LineLayout
All Implemented Interfaces:
java.awt.LayoutManager
Direct Known Subclasses:
FixedLineLayout, GridLineLayout, LargestLineLayout, VariableLineLayout

public abstract class LineLayout
extends java.lang.Object
implements java.awt.LayoutManager

A custom LayoutManager that lays out Components like a vertical FlowLayout that does not do multiple columns. Each Component is as wide as the Container minus insets minus gaps, or as wide as it prefers to be if it's maximum value is smaller. Classes that extend this class make out how high each Component is, and where they are placed (vertically). Therefore there are 3 abstract methods to override, which are also specified by the LayoutManager interface. Also provided are methods to retrieve information about the width. Note that Components are always on the left of the line. There is also only one Component per line. If you want to align your Component, or want more Components on a line, put a Panel on the line and go from there.

Version:
1
Author:
Berend "Kirk" Wouda
See Also:
FlowLayout

Field Summary
private  int horizontalgap
          The horizontal gap.
private  int verticalgap
          The vertical gap.
 
Constructor Summary
LineLayout()
          Constructs a new LineLayout.
LineLayout(int verticalgap)
          Constructs a new LineLayout with the given value for the vertical gap, and the default value for the horizontal gap.
LineLayout(int horizontalgap, int verticalgap)
          Constructs a new LineLayout with the given values for the gaps.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Called by a Container that has this LayoutManager as LayoutManager.
 int getHorizontalGap()
          Returns the horizontal gap.
 int getMinimumWidth(java.awt.Container parent)
          Returns the minimum width of the passed parent when it would be layed out by this class.
 int getPreferredWidth(java.awt.Container parent)
          Returns the preferred width of the passed parent when it would be layed out by this class.
 int getVerticalGap()
          Returns the vertical gap.
 int getWidth(java.awt.Container parent, java.awt.Component component)
          Returns the width the passed Component should have if it is layed out by this class.
abstract  void layoutContainer(java.awt.Container parent)
          Lays out the given Container.
abstract  java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Returns the minimum size of the Container if it get's layed out by this LayoutManager.
abstract  java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Returns the preferred size of the Container if it get's layed out by this LayoutManager.
 void removeLayoutComponent(java.awt.Component comp)
          Called by a Container that has this LayoutManager as LayoutManager.
 void setHorizontalGap(int horizontalgap)
          Sets the horizontal gap.
 void setVerticalGap(int verticalgap)
          Sets the vertical gap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

horizontalgap

private int horizontalgap
The horizontal gap.


verticalgap

private int verticalgap
The vertical gap.

Constructor Detail

LineLayout

public LineLayout(int horizontalgap,
                  int verticalgap)
Constructs a new LineLayout with the given values for the gaps.


LineLayout

public LineLayout(int verticalgap)
Constructs a new LineLayout with the given value for the vertical gap, and the default value for the horizontal gap.


LineLayout

public LineLayout()
Constructs a new LineLayout. Use the default values for the gaps.

Method Detail

getHorizontalGap

public final int getHorizontalGap()
Returns the horizontal gap.

Returns:
The size of the horizontal gap.

setHorizontalGap

public final void setHorizontalGap(int horizontalgap)
Sets the horizontal gap. The horizontal gap cannot be negative.


getVerticalGap

public final int getVerticalGap()
Returns the vertical gap.

Returns:
The size of the vertical gap.

setVerticalGap

public final void setVerticalGap(int verticalgap)
Sets the vertical gap. The vertical gap cannot be negative.


addLayoutComponent

public final void addLayoutComponent(java.lang.String name,
                                     java.awt.Component comp)
Called by a Container that has this LayoutManager as LayoutManager. It should add the given Component to this LayoutManager, however that is not neccesary. We use the same approach as FlowLayout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
See Also:
LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component), FlowLayout

removeLayoutComponent

public final void removeLayoutComponent(java.awt.Component comp)
Called by a Container that has this LayoutManager as LayoutManager. It should remove the given Component to this LayoutManager, however that is not neccesary. We use the same approach as FlowLayout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
See Also:
LayoutManager.removeLayoutComponent(java.awt.Component), FlowLayout

preferredLayoutSize

public abstract java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Returns the preferred size of the Container if it get's layed out by this LayoutManager.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - The Container that the preferred size is wanted of.
See Also:
LayoutManager.preferredLayoutSize(java.awt.Container)

minimumLayoutSize

public abstract java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Returns the minimum size of the Container if it get's layed out by this LayoutManager.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - The Container that the minimum size is wanted of.
See Also:
LayoutManager.minimumLayoutSize(java.awt.Container)

layoutContainer

public abstract void layoutContainer(java.awt.Container parent)
Lays out the given Container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - The Container to be layed out.
See Also:
LayoutManager.layoutContainer(java.awt.Container)

getWidth

public final int getWidth(java.awt.Container parent,
                          java.awt.Component component)
Returns the width the passed Component should have if it is layed out by this class.

Returns:
The width Component should have.

getPreferredWidth

public final int getPreferredWidth(java.awt.Container parent)
Returns the preferred width of the passed parent when it would be layed out by this class.

Returns:
The preferred width of the parent.

getMinimumWidth

public final int getMinimumWidth(java.awt.Container parent)
Returns the minimum width of the passed parent when it would be layed out by this class.

Returns:
The minimum width of the parent.