Package com.ms.ui Previous
Previous
Contents
Contents
Index
Index
Next
Next

Class UIScroll

Constructors , Methods , Fields

public class UIScroll extends UIPanel implements IUIScroll, IUIPosition 
{
  // Fields
  public static final int VERTICAL;
  public static final int NOHIDE;
  public static final int NOSHOW;
  public  static final int THUMB;
  public  static final int PAGE_UP;
  public  static final int PAGE_DOWN;

  // Constructors
  public UIScroll();
  public UIScroll(int style);
  public UIScroll(int style, int min, int max, int page, int line, int pos);

  // Methods
  public Component add(int index, Component comp);
  public void initGraphics();
  public boolean isScrollable();
  public Component getLayoutComponent(int index);
  public void layout();
  public Dimension minimumSize();
  public Dimension preferredSize();
  public void reshape(int x, int y, int width, int height);

  public Color getBackground();
  public Point getPosition();
  public int getRoleCode();
  public int getScrollLine();
  public int getScrollMax();
  public int getScrollMin();
  public int getScrollPage();
  public int getScrollPos();
  public int getStyle();
  public int getXPosition();
  public int getYPosition();

  public Point setPosition(Point pt);
  public Point setPosition(int x, int y);
  public int setScrollInfo(int min, int max, int page, int line, int pos);
  public int setScrollLine(int line);
  public int setScrollMax(int max);
  public int setScrollMin(int min);
  public int setScrollPage(int page);
  public int setScrollPos(int pos);
  public int setScrollRange(int min, int max);
  public void setStyle(int style);
  public int setXPosition(int x);
  public int setYPosition(int y);

  public int scrollEnd();
  public int scrollHome();
  public int scrollLineDown();
  public int scrollLineUp();
  public int scrollPageDown();
  public int scrollPageUp();

  public boolean action(Event e, Object o);
  public boolean mouseDrag(Event e, int x, int y);
  public boolean mouseDown(Event e, int x, int y);
  public boolean mouseUp(Event e, int x, int y);

}

A class that implements a scroll track control. UIScroll defines three scroll track styles: VERTICAL, NOHIDE, and NOSHOW. (By default, the scroll track is horizontal and is only displayed when its range and page values allow scrolling.) The following example shows how to construct a scroll track control using the defined styles.

// Construct a vertical scroll track that is always visible.
UIScroll sc = new UIScroll(UIScroll.VERTICAL | UIScroll.NOHIDE);

UIScroll manages three components, identified by the following layout indices.

Layout Index Component
THUMB The component used to indicate the current position of the scroll track control (by default, a UIScrollThumb object).
PAGE_UP The track area above or to the left of the thumb component (by default, a UIRepeatButton object).
PAGE_DOWN The track area below or to the right of the thumb component (by default, a UIRepeatButton object).

Note that UIScrollBar extends UIScroll to implement a scroll bar control. UIScrollBar adds the LINE_UP and LINE_DOWN components to the ends of the scroll track.


Constructors


UIScroll

public UIScroll();

Creates a horizontal scroll track control. By default, the scroll track has a range of 0 to 100.


UIScroll

public UIScroll(int style);

Creates a scroll track control with the specified style. By default, the scroll track has a range of 0 to 100.

ParameterDescription
style The style of the scroll track. Specify one of the following values:

If an undefined style is specified, an IllegalArgumentException is thrown.


UIScroll

public UIScroll(int style, int min, int max, int page, int line, int pos);

Creates a scroll track control with the specified style and scroll information.

ParameterDescription
style The style of the scroll track control. Specify one of the following values:

If an undefined style is specified, an IllegalArgumentException is thrown.

min The minimum value in the scroll track's range.
max The maximum value in the scroll track's range.
page The number of scroll positions associated with a full page. The size of the THUMB component is based on the ratio of page to range.
line The number of pixels associated with a scroll position.
pos The current position of the scroll track control within its range.


Methods


action

public boolean action(Event e, Object o);

Responds to action events sent from the scroll track control's components.

Return Value:

Returns true if the event was handled; otherwise, returns false.

ParameterDescription
event The event posted to the scroll track control.
object The object that posted the event.

Remarks:

This method updates the control's position, based on one of the following actions.


add

public Component add(int index, Component comp);

Adds the specified component at the given layout index. If a component already exists at this index, it is replaced with the specified component.

Return Value:

Returns the component that was added.

ParameterDescription
index The layout index of the component to be added. Specify either THUMB, PAGE_UP, or PAGE_DOWN. If an undefined index is passed, an IllegalArgumentException is thrown.
comp The component to be added.


getBackground

public Color getBackground();

Retrieves the background color of the scroll track control.

Return Value:

Returns a Color object containing the control's background color. The color returned is darker if the control is currently tracked.


getLayoutComponent

public Component getLayoutComponent(int index);

Retrieves the component at the specified layout index.

Return Value:

Returns the specified component, or null if no such component exists.

ParameterDescription
name The layout index of the component to be retrieved. Specify either THUMB, PAGE_UP, or PAGE_DOWN. If an undefined index is passed, an IllegalArgumentException is thrown.


getPosition

public Point getPosition();

Retrieves the position of the scroll track control.

Return Value:

Returns a Point object containing the current position.

Remarks:

If the scroll track is horizontal, the x coordinate of the returned Point is the current scroll position, and the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero and the y coordinate is the current scroll position.


getRoleCode

public int getRoleCode();

Retrieves the role of the scroll track control.

Return Value:

Returns the ROLE_SYSTEM code that best describes the role of the control.

Remarks:

This method returns the ROLE_SYSTEM_SCROLLBAR code.


getScrollLine

public int getScrollLine();

Retrieves the number of pixels associated with a scroll position.

Return Value:

Returns the number of pixels in a scroll line.


getScrollMax

public int getScrollMax();

Retrieves the maximum value in the scroll track's range.

Return Value:

Returns the maximum range value.


getScrollMin

public int getScrollMin();

Retrieves the minimum value in the scroll track's range.

Return Value:

Returns the minimum range value.


getScrollPage

public int getScrollPage();

Retrieves the number of scroll positions associated with a page.

Return Value:

Returns the number of scroll positions in a page.


getScrollPos

public int getScrollPos();

Retrieves the current position of the scroll track control.

Return Value:

Returns the control's position within its range.


getStyle

public int getStyle();

Retrieves the current style of the scroll track control.

Return Value:

Returns an integer containing the current style settings. For a list of possible styles, see setStyle.


getXPosition

public int getXPosition();

Retrieves the horizontal scroll position of the scroll track control.

Return Value:

Returns the current scroll position, if the control is horizontal; otherwise, returns 0.


getYPosition

public int getYPosition();

Retrieves the vertical scroll position of the scroll track control.

Return Value:

Returns the current scroll position, if the control is vertical; otherwise, returns 0.


initGraphics

public void initGraphics();

Called to perform initialization when the graphics context is first available.

Return Value:

No return value.

Remarks:

This method adds the THUMB, PAGE_UP, and PAGE_DOWN components to the scroll track control.


isScrollable

public boolean isScrollable();

Determines whether the control must scroll, based on its range and page specifications.

Return Value:

Returns true if the control must scroll; otherwise, returns false.

Remarks:

If the scroll track control has the NOHIDE style, it will be disabled if scrolling is not necessary. Otherwise, if the NOSHOW style is set, or if scrolling is not necessary, the control will be hidden.


layout

public void layout();

Lays out the components of the scroll track control.

Return Value:

No return value.

Remarks:

If the scroll track control has the NOHIDE style, it will be disabled if scrolling is not necessary. Otherwise, if the NOSHOW style is set, or if scrolling is not necessary, the control will be hidden.


minimumSize

public Dimension minimumSize();

Determines the minimum size (in pixels) of the scroll track control.

Return Value:

Returns a Dimension object containing the minimum size.

Remarks:

The control's minimum size is based on the minimum size of each of its components.


mouseDown

public boolean mouseDown(Event e, int x, int y);

Reacts to the mouse button being pressed by setting the pressed state of this object.

Return Value:

Returns false.

ParameterDescription
e The event posted to the control.
x The x coordinate of the event.
y The y coordinate of the event.


mouseDrag

public boolean mouseDrag(Event e, int x, int y);

Responds to mouse drag event sent from the Thumb component of the scroll track control.

ParameterDescription
event The event posted to the control.
x The x coordinate of the event.
y The x coordinate of the event.


mouseUp

public boolean mouseUp(Event e, int x, int y);

Reacts to the mouse button being released by clearing the pressed state of this object.

Return Value:

Returns false.

ParameterDescription
e The event posted to the control.
x The x coordinate of the event.
y The y coordinate of the event.


preferredSize

public Dimension preferredSize();

Determines the preferred size (in pixels) of the scroll track control.

Return Value:

Returns a Dimension object containing the preferred size.

Remarks:

The control's preferred size is based on the preferred size of each of its components.


reshape

public void reshape(int x, int y, int width, int height);

Reshapes the scroll track control to the specified dimensions within its parent's coordinate space.

Return Value:

No return value.

ParameterDescription
x The x coordinate of the control's top-left corner.
y The y coordinate of the control's top-left corner.
width The width of the control.
height The height of the control.

Remarks:

After reshaping the scroll track control, this method validates the control to update the layout of its components.


scrollEnd

public int scrollEnd();

Moves the current scroll position to the maximum range value.

Return Value:

Returns the control's new scroll position.


scrollHome

public int scrollHome();

Moves the current scroll position to the minimum range value.

Return Value:

Returns the control's new scroll position.


scrollLineDown

public int scrollLineDown();

Moves the current scroll position down or right by one line.

Return Value:

Returns the control's new scroll position.


scrollLineUp

public int scrollLineUp();

Moves the current scroll position up or left by one line.

Return Value:

Returns the control's new scroll position.


scrollPageDown

public int scrollPageDown();

Moves the current scroll position down or right by one scroll position less than a full page.

Return Value:

Returns the control's new scroll position.


scrollPageUp

public int scrollPageUp();

Moves the current scroll position up or left by one scroll position less than a full page.

Return Value:

Returns the control's new scroll position.


setPosition

public Point setPosition(Point pt);

Repositions the scroll track control, based on the specified Point.

Return Value:

Returns a Point object containing the new position.

ParameterDescription
pt The requested position for the scroll track control. The x and y coordinates specify the horizontal and vertical scroll positions, respectively.

Remarks:

If the scroll track is horizontal, the x coordinate of the returned Point is the current scroll position, and the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero and the y coordinate is the current scroll position. Depending on the control's range, these coordinates may differ from those of the parameter pt.


setPosition

public Point setPosition(int x, int y);

Repositions the scroll track control, based on the specified scroll positions.

Return Value:

Returns a Point object containing the new position.

ParameterDescription
x The requested horizontal scroll position.
y The requested vertical scroll position.

Remarks:

If the scroll track is horizontal, the x coordinate of the returned Point is the current scroll position, and the y coordinate is zero. If the scroll track is vertical, the x coordinate is zero and the y coordinate is the current scroll position. Depending on the control's range, these coordinates may differ from the x and y parameters.


setScrollInfo

public int setScrollInfo(int min, int max, int page, int line, int pos);

Sets the specified scroll information and repositions the scroll track control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified values.

ParameterDescription
min The minimum value in the scroll track's range.
max The maximum value in the scroll track's range.
page The number of scroll positions associated with a full page. The size of the THUMB component is based on the ratio of page to range.
line The number of pixels associated with a scroll position.
pos The current position of the scroll track control within its range.


setScrollLine

public int setScrollLine(int line);

Sets the number of pixels associated with a scroll position, and repositions the scroll track control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified value.

ParameterDescription
line The number of pixels to be associated with a scroll position.


setScrollMax

public int setScrollMax(int max);

Sets the maximum range value and repositions the scroll track control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified value.

ParameterDescription
max The maximum value for the scroll track's range.


setScrollMin

public int setScrollMin(int min);

Sets the minimum range value and repositions the scroll track control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified value.

ParameterDescription
min The minimum value for the scroll track's range.


setScrollPage

public int setScrollPage(int page);

Sets the number of scroll positions associated with a full page, and repositions the scroll track control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified value.

ParameterDescription
page The number of scroll positions to be associated with a full page. The size of the THUMB component is based on the ratio of page to range.


setScrollPos

public int setScrollPos(int pos);

Repositions the scroll track control, based on the specified scroll position.

Return Value:

Returns the control's new scroll position after setting the specified value.

ParameterDescription
pos The position for the scroll track control.

Remarks:

Depending on the control's range, the returned position may differ from the pos parameter.


setScrollRange

public int setScrollRange(int min, int max);

Sets the scroll track control's range, and repositions the control accordingly.

Return Value:

Returns the control's new scroll position after setting the specified values.

ParameterDescription
min The minimum value for the scroll track's range.
max The maximum value for the scroll track's range.


setStyle

public void setStyle(int style);

Sets the current style for the scroll track control.

ParameterDescription
style The style of the scroll track control. Specify one of the following values:

If an undefined style is specified, an IllegalArgumentException is thrown.


setXPosition

public int setXPosition(int x);

Sets the horizontal scroll position of the control.

Return Value:

Returns the control's new scroll position, if the control is horizontal; otherwise, returns 0.

ParameterDescription
x The requested horiziontal scroll position.

Remarks:

If the scroll track is horizontal, the returned position may differ from the x parameter, depending on the control's range.


setYPosition

public int setYPosition(int y);

Sets the vertical scroll position of the control.

Return Value:

Returns the control's new scroll position, if the control is vertical; otherwise, returns 0.

ParameterDescription
y The requested vertical scroll position.

Remarks:

If the scroll track is vertical, the returned position may differ from the y parameter, depending on the control's range.


Fields

VERTICAL
Specifies that the scroll track will be vertical.
NOHIDE
Specifies that an unneeded scroll track will be disabled rather than hidden.
NOSHOW
Specifies that the scroll track will always be hidden.
THUMB
The layout index for the thumb component, which indicates the current position of the scroll track control within its range.
PAGE_UP
The layout index for the track area above or to the left of the thumb.
PAGE_DOWN
The layout index for the track area below or to the right of the thumb.


Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.