All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Scroller

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----tea.set.Scroller

public class Scroller
extends Panel
implements Decorator
Scroller is a decorator widget. It attaches scrollbars to a component for scrolling. If the component implements the Scrollable interface, the Scroller uses the methods provided by the Scrollable interface to set the parameter of scrollbars. When user scrolls a scrollbar, the scrollable component is notified by the setValues() method, and the scrollable component is responsible for the actual scrolling.

If the component does not implement scrollable, Scroller automatically control all scrolling of the component display area. The component is automatically resized to its preferred size, and the Scroller controls the visible portion of the component.

By default, scrollbars are only attached to the component if necessary. For scrollable component, scrollbar is deemed necessary for an orientation if the maximum value is greater than the minimum value. For non-scrollable components, scrollbar is deemed necessary for an orientation if the preferred size is greater than the actual size.

For scrollable components, Scroller calls Scrollable methods to set scrollbar parameters at initialization time. However, depending on the implementation of scrollable components, the exact value for those parameters may not be know when the Scrollable methods are first called. If this is the case, the scrollable component should arrange to call the notifyUpdate() method of Scroller when correct values are available.

If the managed component does not implement Scrollable interface, and the size of the component grows or thrinks, the owner of Scroller need to call Scroller.notifyUpdate() method to recalculate scrollbar values. The scrollbar parameter will be recalculated based on the new component size, or added or removed based on the need of scrollbar if Scroller is in auto mode.

By default, Scroller manages the scrolling for both horizontal and vertical directions. If scrolling of one direction needs to be disabled, call Scroller.setScrollOption() method and passing a bitwise or of the H_SCROLL, H_FILL, and V_SCROLL, and V_FILL. For example, to disable horizontal scrolling, call Scroller.setScrollOption(Scroller.V_SCROLL | Scroller.H_FILL). The vertical sizing and scrolling is managed as usual, but the component's width is always set to the same as the Scroller width. Therefore horizontal scrolling is never needed and horizontal scrollbar is never created. This works only for non Scrollable components. Scrollable components need to manage their own scrolling policy.

Known Bug: AWT Scrollbar is highly buggy. It exhibits different behaviors in different environment (JDK, Netscape, ...) and different versions (1.01, 1.02, ...). To make sure all area are always shown, the scrollbar value may appear to to too large, which will cause excessive scrolling at the end.

Scroller supports the following properties:
Property NameProperty TypeDescription
ComponentComponent Managed component of scroller.
ScrollOptionint Scrolling option flag, H_SCROLL and/or V_SCROLL.
UnitIncrementint (Indexed) Increment value for unit increment.
BlockIncrementint (Indexed) Increment value for block increment.

See Also:
Scrollable

Variable Index

 o H_FILL
H_FILL disable horizontal scrolling.
 o H_SCROLL
H_SCROLL is the default setting.
 o V_FILL
V_FILL disable vertical scrolling.
 o V_SCROLL
V_SCROLL is the default setting.

Constructor Index

 o Scroller()
Construct an emptyer Scroller.
 o Scroller(Component)
Attach a Scroller to a component.
 o Scroller(Component, boolean)
Attach a Scroller to a component.
 o Scroller(Component, boolean, int, int)
Attach a Scroller to a component.

Method Index

 o doLayout()
Layout the managed component.
 o finalize()
Cleanup and release resource.
 o getChild()
Get the decorated component.
 o getComponent()
Get the managed component.
 o getPreferredSize()
Return the preferred size.
 o getScrollOption()
Get the scrolling option.
 o notifySync()
Called by the scrolled component to sync the scrollbar values to the current value.
 o notifyUpdate()
This method can be called by the scrolled component to signal a need to recalculate the scrollbar values.
 o setBlockIncrement(int, int)
Set the page increment value for the specified scrollbar.
 o setBounds(int, int, int, int)
Use reshape as the initialization function.
 o setComponent(Component)
Set the managed component of this Scroller.
 o setScrollOption(int)
Set the scrolling option.
 o setUnitIncrement(int, int)
Set the line increment value for the specified scrollbar.

Variables

 o H_SCROLL
 public static final int H_SCROLL
H_SCROLL is the default setting. The managed component is sized to its preferred width, and scrollbar is attached according to the auto mode and need.

 o H_FILL
 public static final int H_FILL
H_FILL disable horizontal scrolling. The managed component is always sized to the same width as the Scroller.

 o V_SCROLL
 public static final int V_SCROLL
V_SCROLL is the default setting. The managed component is sized to its preferred height, and scrollbar is attached according to the auto mode and need.

 o V_FILL
 public static final int V_FILL
V_FILL disable vertical scrolling. The managed component is always sized to the same width as the Scroller.

Constructors

 o Scroller
 public Scroller()
Construct an emptyer Scroller. Scroller.setComponent must be called to set the managed component of the Scroller.

 o Scroller
 public Scroller(Component comp)
Attach a Scroller to a component. Scrollbars are created if necessary.

Parameters:
comp - component to be scrolled.
 o Scroller
 public Scroller(Component comp,
                 boolean auto)
Attach a Scroller to a component. If auto is true, the scrollbars are only created if necessary. Otherwise, scrollbars will be created regardless of their need.

Parameters:
comp - component to be scrolled.
auto - automatically determine if scrollbar is needed if true.
 o Scroller
 public Scroller(Component comp,
                 boolean auto,
                 int w,
                 int h)
Attach a Scroller to a component. If auto is true, the scrollbars are only created if necessary. Otherwise, scrollbars will be created regardless of their need. The width and height are used as the preferred size of the Scroller.

Parameters:
comp - component to be scrolled.
auto - automatically determine if scrollbar is needed if true.
w - preferred width.
h - preferred height.

Methods

 o setComponent
 public synchronized void setComponent(Component comp)
Set the managed component of this Scroller.

Parameters:
comp - managed component.
 o getComponent
 public Component getComponent()
Get the managed component.

Returns:
managed component.
 o getScrollOption
 public int getScrollOption()
Get the scrolling option. The returned value is a product of bitwise or of H_SCROLL, H_FILL, and V_SCROLL, V_FILL.

Returns:
scrolling option.
 o setScrollOption
 public synchronized void setScrollOption(int opt)
Set the scrolling option. Pass in a bitwise or of the scrolling options: H_SCROLL, H_FILL, and V_SCROLL, V_FILL. If H_FILL is used, the width of the managed component is always same as the width of Scroller, and no horizontal scrolling is done. The same is true for vertical scrolling option.

Parameters:
opt - a bitwise or of the scrolling options.
 o setUnitIncrement
 public void setUnitIncrement(int direction,
                              int inc)
Set the line increment value for the specified scrollbar. If the scrollbar does not exist, this call is ignored. This call is only valid if the managed component is not Scrollable. Otherwise the increment value is always gotten from the Scrollable component interface.

Parameters:
direction - specifies scrollbar, Scrollbar.HORIZONTAL or Scrollbar.VERTICAL.
inc - line increment.
 o setBlockIncrement
 public void setBlockIncrement(int direction,
                               int inc)
Set the page increment value for the specified scrollbar. If the scrollbar does not exist, this call is ignored. This call is only valid if the managed component is not Scrollable. Otherwise the increment value is always gotten from the Scrollable component interface.

Parameters:
direction - specifies scrollbar, Scrollbar.HORIZONTAL or Scrollbar.VERTICAL.
inc - page increment.
 o finalize
 public void finalize()
Cleanup and release resource.

Overrides:
finalize in class Object
 o notifySync
 public void notifySync()
Called by the scrolled component to sync the scrollbar values to the current value. This method should be called when the scrolling values are changed without using scrollbar.

 o notifyUpdate
 public void notifyUpdate()
This method can be called by the scrolled component to signal a need to recalculate the scrollbar values.

 o setBounds
 public void setBounds(int x,
                       int y,
                       int w,
                       int h)
Use reshape as the initialization function.

Parameters:
x - x coordinate.
y - y coordinate.
w - width.
h - height.
Overrides:
setBounds in class Component
 o doLayout
 public void doLayout()
Layout the managed component.

Overrides:
doLayout in class Container
 o getPreferredSize
 public Dimension getPreferredSize()
Return the preferred size. If the size if passed in constructor, it will be returned. Otherwise the size will be the preferred size of its managed component.

Returns:
preferred size.
Overrides:
getPreferredSize in class Container
 o getChild
 public Component getChild()
Get the decorated component.

Returns:
component.

All Packages  Class Hierarchy  This Package  Previous  Next  Index