org.tbee.swing
Class FlowScrollLayout

java.lang.Object
  extended by java.awt.FlowLayout
      extended by org.tbee.swing.FlowScrollLayout
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable, java.util.EventListener

public class FlowScrollLayout
extends java.awt.FlowLayout
implements java.awt.event.ComponentListener, java.awt.LayoutManager2

This class is a replacement for a FlowLayout inside a JScrollPane. It can be used as a plain FlowLayout, but it is intended to be used on a container inside a JScrollPane. If it is the layout for a Container that is the view of a JViewport inside a JScrollPane, then it will cause the Container's children to be wrapped so that the JScrollPane only scrolls vertically.

It can optionally resize all children on each row to be as tall as the tallest one. IMHO, this often looks better, but is off by default for compatiblity with FlowLayout.

Note:Each FlowScrollLayout should be used for only one Container.

Bug:The JViewport inside the JScrollPane that you give to FlowScrollLayout must have a child during the whole time that FlowScrollLayout is used with that JScrollPane. (Typically, that child is the widget whose layout is the FlowScrollLayout.) Otherwise FlowScrollLayout will throw a NullPointerException. It should handle this condition gracefully, but I do not have time to fix it right now. TODO: take the conditionnally present scrollbar into account

See Also:
Serialized Form

Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Fields inherited from class java.awt.FlowLayout
CENTER, LEADING, LEFT, RIGHT, TRAILING
 
Constructor Summary
FlowScrollLayout()
           
FlowScrollLayout(javax.swing.JScrollPane scrollPane)
           
FlowScrollLayout(javax.swing.JScrollPane scrollPane, boolean uniformHeight, boolean uniformWidth)
           
FlowScrollLayout(javax.swing.JScrollPane scrollPane, boolean uniformHeight, boolean uniformWidth, int align)
           
FlowScrollLayout(javax.swing.JScrollPane scrollPane, boolean uniformHeight, boolean uniformWidth, int align, int hgap, int vgap)
           
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent e)
           
protected  java.awt.Dimension computeDesiredSize()
          Follow the layout algorithm that FlowLayout uses to compute how big we would like to be, given the size of the containing JScrollPane.
 float getLayoutAlignmentX(java.awt.Container target)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(java.awt.Container target)
           
 void invalidateLayout(java.awt.Container target)
           
 boolean isUniformHeight()
           
 boolean isUniformWidth()
           
 void layoutContainer(java.awt.Container c)
           
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum size of this component.
static void setHeights(java.awt.Container container, int height, int startIndex, int endIndex)
          Set the preferred size of all JComponents inside container to have height height, starting at the startIndex'th child and going up to endIndex-1.
static void setPreferredHeight(javax.swing.JComponent comp, int height)
          Set preferredSize of comp to be Dimension(current preferredSize.width, height)
static void setPreferredWidth(javax.swing.JComponent comp, int width)
           
 void setScrollPane(javax.swing.JScrollPane scrollPane)
           
 void setUniformHeight(boolean on)
          If uniformHeight is turned on, all widgets on each row will have their preferred height set to the height of the tallest one (based on preferredSize).
 void setUniformWidth(boolean on)
          If uniformWidth is turned on, all widgets on each row will have their preferred Width set to the Width of the tallest one (based on preferredSize).
static void setWidths(java.awt.Container container, int width, int startIndex, int endIndex)
           
protected  void updateLayout()
          Update the layout of the managed widget and the containing scrollbar (only if the current size doesn't match the desired size)
 
Methods inherited from class java.awt.FlowLayout
addLayoutComponent, getAlignment, getAlignOnBaseline, getHgap, getVgap, minimumLayoutSize, preferredLayoutSize, removeLayoutComponent, setAlignment, setAlignOnBaseline, setHgap, setVgap, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.LayoutManager
addLayoutComponent, minimumLayoutSize, preferredLayoutSize, removeLayoutComponent
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

FlowScrollLayout

public FlowScrollLayout()

FlowScrollLayout

public FlowScrollLayout(javax.swing.JScrollPane scrollPane)

FlowScrollLayout

public FlowScrollLayout(javax.swing.JScrollPane scrollPane,
                        boolean uniformHeight,
                        boolean uniformWidth)

FlowScrollLayout

public FlowScrollLayout(javax.swing.JScrollPane scrollPane,
                        boolean uniformHeight,
                        boolean uniformWidth,
                        int align)

FlowScrollLayout

public FlowScrollLayout(javax.swing.JScrollPane scrollPane,
                        boolean uniformHeight,
                        boolean uniformWidth,
                        int align,
                        int hgap,
                        int vgap)
Method Detail

setScrollPane

public void setScrollPane(javax.swing.JScrollPane scrollPane)

setUniformHeight

public void setUniformHeight(boolean on)
If uniformHeight is turned on, all widgets on each row will have their preferred height set to the height of the tallest one (based on preferredSize).


isUniformHeight

public boolean isUniformHeight()

setUniformWidth

public void setUniformWidth(boolean on)
If uniformWidth is turned on, all widgets on each row will have their preferred Width set to the Width of the tallest one (based on preferredSize).


isUniformWidth

public boolean isUniformWidth()

computeDesiredSize

protected java.awt.Dimension computeDesiredSize()
Follow the layout algorithm that FlowLayout uses to compute how big we would like to be, given the size of the containing JScrollPane. Should not be called unless a non-null JScrollPane has been specified in the constructor or with setScrollPane.


setHeights

public static void setHeights(java.awt.Container container,
                              int height,
                              int startIndex,
                              int endIndex)
Set the preferred size of all JComponents inside container to have height height, starting at the startIndex'th child and going up to endIndex-1.


setWidths

public static void setWidths(java.awt.Container container,
                             int width,
                             int startIndex,
                             int endIndex)

setPreferredHeight

public static void setPreferredHeight(javax.swing.JComponent comp,
                                      int height)
Set preferredSize of comp to be Dimension(current preferredSize.width, height)


setPreferredWidth

public static void setPreferredWidth(javax.swing.JComponent comp,
                                     int width)

updateLayout

protected void updateLayout()
Update the layout of the managed widget and the containing scrollbar (only if the current size doesn't match the desired size)


layoutContainer

public void layoutContainer(java.awt.Container c)
Specified by:
layoutContainer in interface java.awt.LayoutManager
Overrides:
layoutContainer in class java.awt.FlowLayout

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Specified by:
componentResized in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

invalidateLayout

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

getLayoutAlignmentY

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

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container target)
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

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum size of this component.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
See Also:
Component.getMinimumSize(), Component.getPreferredSize(), LayoutManager

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - the component to be added
constraints - where/how the component is added to the layout.


Copyright © 2010 KnowledgePlaza. All Rights Reserved.