ProgramixGenericLib v5.0.1

com.programix.gui.layout
Class ShelfLayout

java.lang.Object
  extended by com.programix.gui.layout.AbstractTableLayout
      extended by com.programix.gui.layout.ShelfLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class ShelfLayout
extends AbstractTableLayout
implements LayoutManager2

Lays out components in a single horizontal row (on a "shelf"). Each component added gets its preferred width. The column gap specifies how many pixels are between each column on the shelf (the inherited row gap has no effect on this layout as there is always only one row). The border gap specifies the distance between the laid out components and the container's own border (if any).

The AnchorPoint specified for the layout manager indicates where the contents of the container should be placed if there is extra room. See AbstractTableLayout.getAnchorPoint(), AbstractTableLayout.setAnchorPoint(com.programix.gui.AnchorPoint), and the AnchorPoint that may be specified during construction.

When components are added to this container, an optional constraint can be specified for each. If no constraint is specified (or if null is used as the constraint), the default of AnchorPoint.NORTH will be used.


Example: ShelfLayoutBasic
Could have been created from:
 public static JPanel createBasicDemoPane() {
     JPanel shelf = new JPanel(new ShelfLayout());
     shelf.setBorder(
         BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE));
     shelf.add(makeLabel("1", 50, 20, Color.RED));
     shelf.add(makeLabel("2", 20, 50, Color.YELLOW));
     shelf.add(makeLabel("3", 35, 40, Color.GREEN), AnchorPoint.SOUTH);
     shelf.add(makeLabel("4", 50, 45, Color.MAGENTA));
     shelf.add(makeLabel("5", 55, 80, Color.ORANGE));
     shelf.add(makeLabel("6", 15, 25, Color.CYAN));
     return shelf;
 }

 public static JLabel makeLabel(String text,
                                int prefWidth,
                                int prefHeight,
                                Color bgColor) {

     JLabel label = new JLabel(text, JLabel.CENTER);
     label.setOpaque(true);
     label.setBackground(bgColor);
     label.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
     label.setPreferredSize(new Dimension(prefWidth, prefHeight));
     return label;
 }
 

Author:
Paul Hyde
See Also:
AnchorTableLayout, FormLayout, ColumnButtonLayout, RowButtonLayout, StackLayout, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.programix.gui.layout.AbstractTableLayout
AbstractTableLayout.CellData
 
Field Summary
 
Fields inherited from class com.programix.gui.layout.AbstractTableLayout
anchorPoint, borderGap, colGap, columnCoordinator, DEFAULT_ANCHOR_POINT, DEFAULT_BORDER_GAP, DEFAULT_COL_GAP, DEFAULT_ROW_GAP, ignoreInvisibleComponents, rowGap
 
Constructor Summary
ShelfLayout()
          Creates a single row (shelf) layout.
ShelfLayout(AnchorPoint anchorPoint)
          Creates a single row (shelf) layout.
ShelfLayout(int borderGap)
          Creates a single row (shelf) layout.
ShelfLayout(int colGap, int borderGap)
          Creates a single row (shelf) layout.
ShelfLayout(int colGap, int borderGap, AnchorPoint anchorPoint)
          Creates a single row (shelf) layout.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Called by the graphical subsystem when a component is being added to the container with constraints.
protected  AbstractTableLayout.CellData createCellData(Container pane)
           
 AnchorPoint getDefaultCellAnchorPoint()
          Returns the current default AnchorPoint used to position a component within its cell boundaries when no constraints are specified during the add of the component.
 float getLayoutAlignmentX(Container target)
           
 float getLayoutAlignmentY(Container target)
           
 void invalidateLayout(Container target)
           
 Dimension maximumLayoutSize(Container target)
           
 void removeLayoutComponent(Component comp)
          Called by the graphical subsystem when a component is being removed from the container.
 void setDefaultCellAnchorPoint(AnchorPoint ap)
          Changes the current default AnchorPoint used to position a component within its cell boundaries when no constraints are specified during the add of the component.
 
Methods inherited from class com.programix.gui.layout.AbstractTableLayout
addLayoutComponent, getAnchorPoint, getBorderGap, getColumnCoordinator, getColumnGap, getRowGap, isIgnoreInvisibleComponents, layoutContainer, minimumLayoutSize, preferredLayoutSize, setAnchorPoint, setBorderGap, setColumnCoordinator, setColumnGap, setIgnoreInvisibleComponents, setRowGap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.LayoutManager
addLayoutComponent, layoutContainer, minimumLayoutSize, preferredLayoutSize
 

Constructor Detail

ShelfLayout

public ShelfLayout(int colGap,
                   int borderGap,
                   AnchorPoint anchorPoint)
Creates a single row (shelf) layout.

Parameters:
colGap - space between columns. See setColumnGap().
borderGap - space around the outside of the row. See setBorderGap().
anchorPoint - region to anchor to when there is extra space See setAnchorPoint().

ShelfLayout

public ShelfLayout(int colGap,
                   int borderGap)
Creates a single row (shelf) layout. Uses DEFAULT_ANCHOR_POINT.

Parameters:
colGap - space between columns. See setColumnGap().
borderGap - space around the outside of the form. See setBorderGap().

ShelfLayout

public ShelfLayout(AnchorPoint anchorPoint)
Creates a single row (shelf) layout. Uses DEFAULT_COL_GAP. Uses DEFAULT_BORDER_GAP.

Parameters:
anchorPoint - region to anchor to when there is extra space See setAnchorPoint().

ShelfLayout

public ShelfLayout(int borderGap)
Creates a single row (shelf) layout. Uses DEFAULT_COL_GAP. Uses DEFAULT_ANCHOR_POINT.

Parameters:
borderGap - space around the outside of the form. See setBorderGap().

ShelfLayout

public ShelfLayout()
Creates a single row (shelf) layout. Uses DEFAULT_COL_GAP. Uses DEFAULT_BORDER_GAP. Uses DEFAULT_ANCHOR_POINT.

Method Detail

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Called by the graphical subsystem when a component is being removed from the container.

Specified by:
removeLayoutComponent in interface LayoutManager
Overrides:
removeLayoutComponent in class AbstractTableLayout

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Called by the graphical subsystem when a component is being added to the container with constraints.

Specified by:
addLayoutComponent in interface LayoutManager2

maximumLayoutSize

public Dimension maximumLayoutSize(Container target)
Specified by:
maximumLayoutSize in interface LayoutManager2

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Specified by:
getLayoutAlignmentX in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Specified by:
getLayoutAlignmentY in interface LayoutManager2

invalidateLayout

public void invalidateLayout(Container target)
Specified by:
invalidateLayout in interface LayoutManager2

getDefaultCellAnchorPoint

public AnchorPoint getDefaultCellAnchorPoint()
Returns the current default AnchorPoint used to position a component within its cell boundaries when no constraints are specified during the add of the component.


setDefaultCellAnchorPoint

public void setDefaultCellAnchorPoint(AnchorPoint ap)
Changes the current default AnchorPoint used to position a component within its cell boundaries when no constraints are specified during the add of the component.


createCellData

protected AbstractTableLayout.CellData createCellData(Container pane)
Specified by:
createCellData in class AbstractTableLayout

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.