com.yospace.yae.yogi
Class YogiScrollContentPane

java.lang.Object
  |
  +--com.yospace.yae.yogi.YogiComponent
        |
        +--com.yospace.yae.yogi.YogiScrollContentPane
All Implemented Interfaces:
PropertyChangeListener

public class YogiScrollContentPane
extends YogiComponent
implements PropertyChangeListener

The generic scrolling component. When asked to scroll by a number of units (eg rows) or blocks (eg screens), it relocates all its children so as to give the impression of a scrollable area.

The scrollpane can move both horizontally and vertically.

The size of a unit and a block is configurable in both directions.

Generally, if a method is working in rows and columns, then its args are in (rows, cols) order. If it is working in pixels, then they are in (x, y) order.


Field Summary
static int MODE_CONTRACTED
          Constant representing contracted mode.
static int MODE_MAXIMIZED
          Constant representing maximized mode.
static int PROPERTY_CHILD_COMPONENT
          Constant for the child component property
static int PROPERTY_SCROLL_HORIZONTAL
          Constant for the horizontal scroll property
static int PROPERTY_SCROLL_VERTICAL
          Constant for the vertical scroll property
 
Fields inherited from class com.yospace.yae.yogi.YogiComponent
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, BORDER_DOTTED, BORDER_NONE, BORDER_PLAIN, BORDER_ROUNDED, BORDER_SOLID, COLOR_BACKGROUND, COLOR_BORDER, COLOR_FOREGROUND, FOCUS_DEFAULT, FOCUS_OFF, FOCUS_ON, PROPERTY_ALIGN, PROPERTY_BORDER_STYLE, PROPERTY_BOUNDS, PROPERTY_COLOR, PROPERTY_CONTEXT_ENABLED, PROPERTY_ENABLED, PROPERTY_FOCUS, PROPERTY_FOCUS_INDEX, PROPERTY_FOCUS_TRAVERSABLE, PROPERTY_FONT, PROPERTY_HOTKEY, PROPERTY_LOCATION, PROPERTY_OPAQUE, PROPERTY_SIZE, PROPERTY_VISIBLE, PROPERTY_X_INSET, PROPERTY_Y_INSET
 
Constructor Summary
YogiScrollContentPane()
          Default constructor which initialises the scroll offset to the top-left corner, (0,0).
 
Method Summary
 void add(YogiComponent c)
          Overrides the YogiComponent.add(YogiComponent c) method, in order to notify the parent YogiScrollPane when the child component changes.
protected  void ensureVisible(YogiComponent child, int fx, int fy, int fw, int fh)
          This method ensures that the specified region is visible by scrolling as far as it can in both directions until the region is in view.
 int getColor(int index)
          Overrides YogiComponent.getColor(int) to ensure that the content pane has the same background color as the parent YogiScrollPane.
 int getHorizontalMode()
          Gets the horizontal mode of the content pane.
 int getHorizontalOffset()
          Gets the current horizontal pixel offset.
protected  int getHorizViewSize(YogiScrollPane scrollPane, YogiScrollBar horizScroller, YogiScrollBar vertScroller)
          Calculates the size of the horizontal scrollbar, expressed as a precentage of the size of the displayed component to the content pane.
protected  int getMaxComponentHeight()
          Used to calculate the maximum height of a component contained within the scroll content pane.
protected  int getMaxComponentWidth()
          Used to calculate the maximum width of a component contained within the scroll content pane.
protected  int getMaximumHorizontalScrollOffset()
          This method is used internally to discover the largest horizontal index that can be scrolled to by the ScrollPane.
protected  int getMaximumVerticalScrollOffset()
          This method is used internally to discover the largest vertical index that can be scrolled to by the ScrollPane.
 int getVerticalMode()
          Gets the vertical mode of the content pane.
 int getVerticalOffset()
          Gets the current vertical pixel offset.
protected  int getVertViewSize(YogiScrollPane scrollPane, YogiScrollBar vertScroller, YogiScrollBar horizScroller)
          Calculates the size of the vertical scrollbar, expressed as a precentage of the size of the displayed component to the content pane.
 void propertyChanged(java.lang.Object source, int property)
          Implements the PropertyChangeListener interface.
 void remove(YogiComponent c)
          Overrides the YogiComponent.remove(YogiComponent c) method, in order to notify the parent YogiScrollPane when the child component changes.
 boolean reset()
          Resets the content pane's scroll offsets to 0, 0.
 boolean resetX()
          Resets the content pane's scroll x offset.
 boolean resetY()
          Resets the content pane's scroll y offset.
 boolean scroll(int rowUnits, int colUnits)
          Causes the scroller to scroll (relative to its current setting) by the specified number of vertical units and horizontal units.
 boolean scrollBlock(int rowBlocks, int colBlocks)
          Causes the scroller to scroll (relative to its current setting) by the specified number of vertical and horizontal blocks.
 boolean scrollToPosition(int x, int y)
          Moves the scroller so that the specified pixel coordinate is in the top left of the scroller.
 boolean scrollXProportion(int proportion)
          Moves the scroller so that the specified proportion of the width of the content pane is in the left of the scroller.
 boolean scrollYProportion(int proportion)
          Moves the scroller so that the specified proportion of the height of the content pane is in the top of the scroller.
 void setMode(YogiScrollBar horizScroller, YogiScrollBar vertScroller)
          Sets the mode of the content pane, with respect to the state of the the two scrollbars.
 
Methods inherited from class com.yospace.yae.yogi.YogiComponent
_debugPrintComponents, addPropertyChangeListener, bringForwards, bringInFrontOf, bringToFront, contains, containsComponent, ensureVisible, findComponentAt, findCurrentFocus, findFirstFocus, findFocusDomainRoot, findFocusDomainRootImpl, findHotkeyComponent, findNextFocus, fireActionPerformedEvent, firePropertyChangeEvent, getAlign, getBorderStyle, getBounds, getColors, getComponent, getComponent, getComponentCount, getComponentIndex, getComponents, getFocusBounds, getFocusIndex, getFont, getGlobalLocation, getHeight, getHotkey, getId, getParent, getParent, getTreeLock, getUI, getWidth, getX, getXInset, getY, getYInset, hasFocus, isActive, isContextEnabled, isEnabled, isFocusDomainRoot, isFocusTraversable, isOpaque, isVisible, keyPressed, keyReleased, keyRepeated, paint, paintBackground, paintBorder, paintForeground, pointerDragged, pointerPressed, pointerReleased, remove, removeAll, removePropertyChangeListener, repaint, repaint, repaintAfterRebounding, requestFocus, requestFocus, sendBackwards, sendBehind, sendToBack, setActionListener, setActive, setAlign, setBorderStyle, setBounds, setColor, setColors, setContextEnabled, setDefaultColor, setEnabled, setFocusDomainRoot, setFocusIndex, setFocusTraversable, setFont, setHotkey, setId, setLocation, setNoFocus, setOpaque, setProperty, setSize, setUI, setVisible, setXInset, setYInset, updateUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_CHILD_COMPONENT

public static final int PROPERTY_CHILD_COMPONENT
Constant for the child component property

PROPERTY_SCROLL_HORIZONTAL

public static final int PROPERTY_SCROLL_HORIZONTAL
Constant for the horizontal scroll property

PROPERTY_SCROLL_VERTICAL

public static final int PROPERTY_SCROLL_VERTICAL
Constant for the vertical scroll property

MODE_CONTRACTED

public static final int MODE_CONTRACTED
Constant representing contracted mode. In this mode, the content pane will leave space for a scrollbar to appear.

MODE_MAXIMIZED

public static final int MODE_MAXIMIZED
Constant representing maximized mode. In this mode, the content pane will leave no space for a scrollbar to appear.
Constructor Detail

YogiScrollContentPane

public YogiScrollContentPane()
Default constructor which initialises the scroll offset to the top-left corner, (0,0).
Method Detail

getColor

public int getColor(int index)
Overrides YogiComponent.getColor(int) to ensure that the content pane has the same background color as the parent YogiScrollPane.
Overrides:
getColor in class YogiComponent
Parameters:
index - the index of the color to get.
Returns:
returns the color at the index except if requesting the background color then the color is obtained from the parent.

getHorizontalMode

public int getHorizontalMode()
Gets the horizontal mode of the content pane. The mode will always be one of: MODE_CONTRACTED, MODE_MAXIMIZED.
Returns:
the content pane's current horizontal mode.

getVerticalMode

public int getVerticalMode()
Gets the vertical mode of the content pane. The mode will always be one of: MODE_CONTRACTED, MODE_MAXIMIZED.
Returns:
the content pane's current vertical mode.

scroll

public boolean scroll(int rowUnits,
                      int colUnits)
Causes the scroller to scroll (relative to its current setting) by the specified number of vertical units and horizontal units. Eg.
scroll(0, -1);
will scroll one "unit" number of pixels to the left.
Parameters:
rowUnits - the number of rows to scroll: positive values will scroll down and negative will scroll up.
colUnits - the number of columns to scroll: positive values will scroll right and negative will scroll left.
Returns:
true if the scroller moved, false otherwise.

scrollBlock

public boolean scrollBlock(int rowBlocks,
                           int colBlocks)
Causes the scroller to scroll (relative to its current setting) by the specified number of vertical and horizontal blocks. Eg.
scrollBlock(-2, 1);
will scroll one "unit" number of pixels to the right and two up.
Parameters:
rowBlocks - the number of row blocks to scroll: positive values will scroll down and negative will scroll up.
colBlocks - the number of column blocks to scroll: positive values will scroll right and negative will scroll left.
Returns:
true if the scroller moved, false otherwise.

scrollToPosition

public boolean scrollToPosition(int x,
                                int y)
Moves the scroller so that the specified pixel coordinate is in the top left of the scroller. This is an "absolute" operation, and disregards the current row/column information.
Parameters:
x - the horizontal pixel coordinate.
y - the vertical pixel coordinate.
Returns:
true if the scroller moved, false otherwise.

scrollXProportion

public boolean scrollXProportion(int proportion)
Moves the scroller so that the specified proportion of the width of the content pane is in the left of the scroller. This is an "absolute" operation, and disregards current row/column information.
Parameters:
proportion - the horizontal scroll proportion.
Returns:
true if the scroller moved, false otherwise.

scrollYProportion

public boolean scrollYProportion(int proportion)
Moves the scroller so that the specified proportion of the height of the content pane is in the top of the scroller. This is an "absolute" operation, and disregards current row/column information.
Parameters:
proportion - the vertical scroll proportion.
Returns:
true if the scroller moved, false otherwise.

reset

public boolean reset()
Resets the content pane's scroll offsets to 0, 0.
Returns:
true if the scroller moved, false otherwise.

resetX

public boolean resetX()
Resets the content pane's scroll x offset.
Returns:
true if the scroller moved, false otherwise.

resetY

public boolean resetY()
Resets the content pane's scroll y offset.
Returns:
true if the scroller moved, false otherwise.

getHorizontalOffset

public int getHorizontalOffset()
Gets the current horizontal pixel offset.
Returns:
the horizontal position of the scroller in pixels.

getVerticalOffset

public int getVerticalOffset()
Gets the current vertical pixel offset.
Returns:
the vertical position of the scroller in pixels.

getMaximumHorizontalScrollOffset

protected int getMaximumHorizontalScrollOffset()
This method is used internally to discover the largest horizontal index that can be scrolled to by the ScrollPane. The default implementation returns the right edge of the rightmost component minus the width of the content pane, which means that the scroller will scroll down until there is no more to expose on the right edge.
Returns:
the largest value to horizontally scroll to.

getMaximumVerticalScrollOffset

protected int getMaximumVerticalScrollOffset()
This method is used internally to discover the largest vertical index that can be scrolled to by the ScrollPane. The default implementation returns the bottom edge of the lowest component minus the height of the content pane, which means that the scroller will scroll down until there is no more to expose on the bottom edge.
Returns:
the largest value to vertically scroll to.

getVertViewSize

protected int getVertViewSize(YogiScrollPane scrollPane,
                              YogiScrollBar vertScroller,
                              YogiScrollBar horizScroller)
Calculates the size of the vertical scrollbar, expressed as a precentage of the size of the displayed component to the content pane. If the component's height is smaller than or equal to the content pane's height, or the vertical scrollbar's configuration is YogiScrollBar.APPEAR_NEVER, -1 is returned. If the vertical scrollbar's configuration has been set to YogiScrollBar.APPEAR_ALWAYS, 100 is returned.
Parameters:
scrollPane - the parent scroll pane.
vertScroller - the vertical scroller.
horizScroller - the horizontal scroller.
Returns:
the size of the scrollbar indicator as a % of the scrollbar's height.

getHorizViewSize

protected int getHorizViewSize(YogiScrollPane scrollPane,
                               YogiScrollBar horizScroller,
                               YogiScrollBar vertScroller)
Calculates the size of the horizontal scrollbar, expressed as a precentage of the size of the displayed component to the content pane. If the component's width is smaller than or equal to the content pane's width, or the horizontal scrollbar's configuration is YogiScrollBar.APPEAR_NEVER, -1 is returned. If the horizontal scrollbar's configuration has been set to YogiScrollBar.APPEAR_ALWAYS, 100 is returned.
Parameters:
scrollPane - the parent scroll pane.
horizScroller - the horizontal scroller.
vertScroller - the vertical scroller.
Returns:
the size of the scrollbar indicator as a % of the scrollbar's width.

setMode

public void setMode(YogiScrollBar horizScroller,
                    YogiScrollBar vertScroller)
Sets the mode of the content pane, with respect to the state of the the two scrollbars. So for example if the horizontal scroller is always needed then the vertical mode will be maximized.
Parameters:
horizScroller - the horizontal scrollbar.
vertScroller - the vertical scrollbar.

propertyChanged

public void propertyChanged(java.lang.Object source,
                            int property)
Implements the PropertyChangeListener interface. Notifies the parent YogiScrollPane that the child component has changed size.
Specified by:
propertyChanged in interface PropertyChangeListener
Parameters:
source - the event source.
property - the property changed.

add

public void add(YogiComponent c)
Overrides the YogiComponent.add(YogiComponent c) method, in order to notify the parent YogiScrollPane when the child component changes.
Overrides:
add in class YogiComponent
Parameters:
c - the component to add.

remove

public void remove(YogiComponent c)
Overrides the YogiComponent.remove(YogiComponent c) method, in order to notify the parent YogiScrollPane when the child component changes.
Overrides:
remove in class YogiComponent
Parameters:
c - the component to remove.

getMaxComponentHeight

protected final int getMaxComponentHeight()
Used to calculate the maximum height of a component contained within the scroll content pane.
Returns:
the maximum vertical extent of any of the child components.

getMaxComponentWidth

protected final int getMaxComponentWidth()
Used to calculate the maximum width of a component contained within the scroll content pane.
Returns:
the maximum horizontal extent of any of the child components.

ensureVisible

protected void ensureVisible(YogiComponent child,
                             int fx,
                             int fy,
                             int fw,
                             int fh)
This method ensures that the specified region is visible by scrolling as far as it can in both directions until the region is in view. Specifically, if the area is off the left side, we scroll left so the area's left side is at zero. Otherwise, if the area is off the right side, then we scroll right until its right edge is in view, but only if that doesn't move the left edge off the left. The same algorithm is applied vertically to the top and bottom. Actual movement is performed by driving the scrollbars. After that, the request is passed up the containment tree as usual.
Overrides:
ensureVisible in class YogiComponent
Parameters:
child - this argument is ignored in this implementation, as scrollers are not interested in layering.
fx - the x coordinate of the top left point of the region.
fy - the y coordinate of the top left point of the region.
fw - the width of the region.
fh - the height of the region.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.