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.
- Scroller.H_SCROLL - default scrolling option for horizontal
direction. Attach horizontal scrollbar according to the auto mode
and need. The width of managed component is set to its preferred
width.
- Scroller.H_FILL - disable horizontal scrolling. The width of
the managed component is set to the width of Scroller.
- Scroller.V_SCROLL - default scrolling option for vertical
direction. Attach vertical scrollbar according to the auto mode
and need. The height of managed component is set to its preferred
height.
- Scroller.V_FILL - disable vertical scrolling. The height of
the managed component is set to the height of Scroller.
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 Name | Property Type | Description |
Component | Component |
Managed component of scroller. |
ScrollOption | int |
Scrolling option flag, H_SCROLL and/or V_SCROLL. |
UnitIncrement | int (Indexed) |
Increment value for unit increment. |
BlockIncrement | int (Indexed) |
Increment value for block increment. |
- See Also:
- Scrollable
-
H_FILL
- H_FILL disable horizontal scrolling.
-
H_SCROLL
- H_SCROLL is the default setting.
-
V_FILL
- V_FILL disable vertical scrolling.
-
V_SCROLL
- V_SCROLL is the default setting.
-
Scroller()
- Construct an emptyer Scroller.
-
Scroller(Component)
- Attach a Scroller to a component.
-
Scroller(Component, boolean)
- Attach a Scroller to a component.
-
Scroller(Component, boolean, int, int)
- Attach a Scroller to a component.
-
doLayout()
- Layout the managed component.
-
finalize()
- Cleanup and release resource.
-
getChild()
- Get the decorated component.
-
getComponent()
- Get the managed component.
-
getPreferredSize()
- Return the preferred size.
-
getScrollOption()
- Get the scrolling option.
-
notifySync()
- Called by the scrolled component to sync the scrollbar values
to the current value.
-
notifyUpdate()
- This method can be called by the scrolled component to signal a
need to recalculate the scrollbar values.
-
setBlockIncrement(int, int)
- Set the page increment value for the specified scrollbar.
-
setBounds(int, int, int, int)
- Use reshape as the initialization function.
-
setComponent(Component)
- Set the managed component of this Scroller.
-
setScrollOption(int)
- Set the scrolling option.
-
setUnitIncrement(int, int)
- Set the line increment value for the specified scrollbar.
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.
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.
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.
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.
Scroller
public Scroller()
- Construct an emptyer Scroller. Scroller.setComponent must be
called to set the managed component of the Scroller.
Scroller
public Scroller(Component comp)
- Attach a Scroller to a component. Scrollbars are created if
necessary.
- Parameters:
- comp - component to be scrolled.
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.
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.
setComponent
public synchronized void setComponent(Component comp)
- Set the managed component of this Scroller.
- Parameters:
- comp - managed component.
getComponent
public Component getComponent()
- Get the managed component.
- Returns:
- managed component.
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.
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.
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.
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.
finalize
public void finalize()
- Cleanup and release resource.
- Overrides:
- finalize in class Object
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.
notifyUpdate
public void notifyUpdate()
- This method can be called by the scrolled component to signal a
need to recalculate the scrollbar values.
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
doLayout
public void doLayout()
- Layout the managed component.
- Overrides:
- doLayout in class Container
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
getChild
public Component getChild()
- Get the decorated component.
- Returns:
- component.
All Packages Class Hierarchy This Package Previous Next Index