org.gjt.universe.gui
Class StripLayout

java.lang.Object
  |
  +--org.gjt.universe.gui.StripLayout
All Implemented Interfaces:
java.awt.LayoutManager

public class StripLayout
extends java.lang.Object
implements java.awt.LayoutManager

This class is a layout manager which places components adjacent to each other in a horizontal or vertical strip, without attempting to standardize the size of the components like a GridLayout would, or stretch components to fill all the available space like it and other standard layouts would. As well, this layout manager will not automatically stretch components to fill all available space. Instead, components will be packed a tightly as possible based on their preferred size. Additional attributes of this layout manager allow introduction of a uniform inter-component gap and minimum size. By design, this layout manager differs from the FlowLayout in that it will not wrap and thus is a good choice for use when this is undesirable. Instead of wrapping this layout will attempt to stay within the maximum size Although the same layouts can be achieved by using nested panels with different standard layout managers assigned carefully crafted constraints objects, this layout manager is many times easier to use. Acknowledgement: Inspired by the GPL'd StackLayout class of SoftBear, Inc. TO DO: - Add parameter to allow alignment to opposite end (i.e. right in horizontal, bottom in vertical) - Add option to allow filling of all the available space by stretching the components proportionally to their relative preferred sizes - Improve handling of hitting the maximum size of parent component by shrinking the to fit while maintaining relative preferred sizes and honoring minimum sizes.

Author:
Allan Noordvyk

Field Summary
static char HORIZONTAL
           
private  int myGap
           
private  int myMinHeight
           
private  int myMinWidth
           
private  char myOrientation
           
static char VERTICAL
           
 
Constructor Summary
StripLayout()
          This constructor returns a StripLayout instance which will lay out components horizontally, with no gap between adjacent components and no minimum size for each component.
StripLayout(char orientation)
          This constructor returns a StripLayout instance which will lay out components in the given orientation with no gap between adjacent components and no minimum size for each component.
StripLayout(char orientation, int minWidth, int minHeight, int gap)
          This method is the designated constructor for instances of this class.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
           
 void layoutContainer(java.awt.Container parent)
          This method does the actual positioning of the components of the given container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          This method returns the minimum size that should be needed to arrange the components of the given container using this layout instance.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          This method returns the preferred size for laying out the given container using this layout.
 void removeLayoutComponent(java.awt.Component comp)
           
private  java.awt.Dimension totalComponentSizes(java.awt.Container parent, boolean isMinimum)
          This method returns the a summation of the sizes of all the components present in the given parent container, if they were to be laid out in our orientation and with the given gap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL

public static char HORIZONTAL

VERTICAL

public static char VERTICAL

myOrientation

private char myOrientation

myMinWidth

private int myMinWidth

myMinHeight

private int myMinHeight

myGap

private int myGap
Constructor Detail

StripLayout

public StripLayout()
This constructor returns a StripLayout instance which will lay out components horizontally, with no gap between adjacent components and no minimum size for each component.


StripLayout

public StripLayout(char orientation)
This constructor returns a StripLayout instance which will lay out components in the given orientation with no gap between adjacent components and no minimum size for each component.


StripLayout

public StripLayout(char orientation,
                   int minWidth,
                   int minHeight,
                   int gap)
This method is the designated constructor for instances of this class. It returns a layout manager which will place components in adjacent locations along a horizontal or vertical axis, leaving the given gap number of pixels between each adjacent component.

Parameters:
orientation - HORIZONTAL or VERTICAL
minWidth - The minimum width which all components should be given.
minHeight - The minimum height which all components should be given.
gap - The number of pixels to be left between adjacent components.
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Specified by:
addLayoutComponent in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
This method returns the preferred size for laying out the given container using this layout. This is computed by taking into account he preferred size of each component currently present in the container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

layoutContainer

public void layoutContainer(java.awt.Container parent)
This method does the actual positioning of the components of the given container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - The container whose components are to be laid out.

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
This method returns the minimum size that should be needed to arrange the components of the given container using this layout instance.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - The container whose oomponents would be laid out.

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

totalComponentSizes

private java.awt.Dimension totalComponentSizes(java.awt.Container parent,
                                               boolean isMinimum)
This method returns the a summation of the sizes of all the components present in the given parent container, if they were to be laid out in our orientation and with the given gap. The sizes being totalled will either be preferred or minimum sizes, depending on the second argument.

Parameters:
parent - A container whose component sizes are to be summed.
isMinimum - If true then the minimum sizes are to be used, otherwise the preferred sizes will be used.


Copyright © 2001 Universe Dev Team All Rights Reserved.