FreeHEP API
Version current

org.freehep.swing.layout
Class FlowScrollLayout

java.lang.Object
  extended byjava.awt.FlowLayout
      extended byorg.freehep.swing.layout.FlowScrollLayout
All Implemented Interfaces:
ComponentListener, EventListener, LayoutManager, LayoutManager2, Serializable

public class FlowScrollLayout
extends FlowLayout
implements ComponentListener, 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. If anyone wants to send me a patch, it would be welcome.

This software is distributed under the Berkeley Software License.

Version:
$Id: FlowScrollLayout.java,v 1.5 2003/12/09 06:59:04 tonyj Exp $
Author:
This was written by A. Chris Long (but modified for FreeHEP)
See Also:
Serialized Form
Source Code:
FlowScrollLayout.java

Field Summary
 
Fields inherited from class java.awt.FlowLayout
CENTER, LEADING, LEFT, RIGHT, TRAILING
 
Constructor Summary
FlowScrollLayout()
           
FlowScrollLayout(JScrollPane scrollPane)
           
FlowScrollLayout(JScrollPane scrollPane, boolean uniformHeight)
           
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void componentHidden(ComponentEvent e)
           
 void componentMoved(ComponentEvent e)
           
 void componentResized(ComponentEvent e)
           
 void componentShown(ComponentEvent e)
           
protected  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(Container target)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(Container target)
           
 void invalidateLayout(Container target)
           
 boolean isUniformHeight()
           
 void layoutContainer(Container c)
           
 Dimension maximumLayoutSize(Container target)
          Returns the maximum size of this component.
static void setHeights(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(JComponent comp, int height)
          Set preferredSize of comp to be Dimension(current preferredSize.width, height)
 void setScrollPane(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).
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, getHgap, getVgap, minimumLayoutSize, preferredLayoutSize, removeLayoutComponent, setAlignment, 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
 

Constructor Detail

FlowScrollLayout

public FlowScrollLayout()

FlowScrollLayout

public FlowScrollLayout(JScrollPane scrollPane)

FlowScrollLayout

public FlowScrollLayout(JScrollPane scrollPane,
                        boolean uniformHeight)
Method Detail

setScrollPane

public void setScrollPane(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()

computeDesiredSize

protected 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(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.


setPreferredHeight

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


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(Container c)
Specified by:
layoutContainer in interface LayoutManager

componentResized

public void componentResized(ComponentEvent e)
Specified by:
componentResized in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Specified by:
componentMoved in interface ComponentListener

componentShown

public void componentShown(ComponentEvent e)
Specified by:
componentShown in interface ComponentListener

componentHidden

public void componentHidden(ComponentEvent e)
Specified by:
componentHidden in interface ComponentListener

invalidateLayout

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

getLayoutAlignmentY

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

getLayoutAlignmentX

public float getLayoutAlignmentX(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 LayoutManager2

maximumLayoutSize

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

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

addLayoutComponent

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

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

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.