de.enough.polish.ui
Class ScrollBar

java.lang.Object
  extended by de.enough.polish.ui.Item
      extended by de.enough.polish.ui.ScrollBar
All Implemented Interfaces:
Animatable, UiElement

public class ScrollBar
extends Item

Realizes a scrollbar for any J2ME Polish screens.

The scrollbar needs to be activated using the "polish.useScrollBar" variable:

    <variable name="polish.useScrollBar" value="true" />
    

If you don't want the scrollbar to handle pointer/drag events itself, you can specify "polish.ScrollBar.handlePointerEvents":

    <variable name="polish.ScrollBar.handlePointerEvents" value="false" />
   

Design the scrollbar using the predefined "scrollbar" style. You can also specify a screen specific style by defining the "scrollbar-style" CSS attribute.
Scrollbars support following additional attributes (apart from the background etc):

You can exchange the default implementation with the "polish.classes.ScrollBar" variable.

Copyright Enough Software 2006 - 2009

 history
        22-Feb-2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  boolean hideSlider
           
protected  boolean isPointerPressedHandled
           
protected  boolean isVisible
           
protected  boolean overlap
           
protected  boolean repeatSliderImage
           
protected  int repeatSliderNumber
           
protected  int scrollBarHeight
           
protected  Background sliderBackground
           
protected  int sliderColor
           
protected  int sliderHeight
           
protected  Image sliderImage
           
protected  int sliderMinHeight
           
protected  int sliderMode
           
protected  Dimension sliderWidth
           
protected  int sliderY
           
 
Fields inherited from class de.enough.polish.ui.Item
_androidView, _bbField, appearanceMode, availableHeight, availableWidth, availContentHeight, availContentWidth, background, backgroundHeight, backgroundWidth, backgroundYOffset, bgBorder, border, BUTTON, cacheItemImage, colSpan, commands, completeBackground, completeBackgroundPadding, completeBorder, contentHeight, contentWidth, contentX, contentXAdjustment, contentY, contentYAdjustment, cssHeight, cssSelector, cssWidth, defaultCommand, focusedStyle, HORIZONTAL, HYPERLINK, ignoreRepaintRequests, includeLabel, INTERACTIVE, internalHeight, internalWidth, internalX, internalY, isContentVisible, isFocused, isInlineLabel, isInvisible, isJustFocused, isLayoutCenter, isLayoutExpand, isLayoutRight, isPressed, isShown, isStyleInitialized, itemCommandListener, itemHeight, itemWidth, label, labelStyle, landscapeStyle, layout, LAYOUT_2, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_EXPAND, LAYOUT_LEFT, LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE, LAYOUT_RIGHT, LAYOUT_SHRINK, LAYOUT_TOP, LAYOUT_VCENTER, LAYOUT_VEXPAND, LAYOUT_VSHRINK, marginBottom, marginLeft, marginRight, marginTop, maximumHeight, maximumItemHeight, maximumItemWidth, maximumWidth, minimumHeight, minimumItemHeight, minimumItemWidth, minimumWidth, nativeItem, NO_POSITION_SET, opacity, opacityPaintNormally, opacityRgbData, paddingBottom, paddingHorizontal, paddingLeft, paddingRight, paddingTop, paddingVertical, parent, PLAIN, portraitStyle, preferredHeight, preferredWidth, preserveViewType, relativeX, relativeY, rowSpan, screen, setView, style, TRANSPARENT, useSingleRow, VERTICAL, view, xAdjustment, yAdjustment
 
Constructor Summary
ScrollBar()
          Creates a new default scrollbar
ScrollBar(Style style)
          Creates a new styled scrollbar
 
Method Summary
 boolean animate()
          Animates this item.
protected  String createCssSelector()
          Retrieves the CSS selector for this item.
protected  boolean handlePointerDragged(int x, int y)
          Allows to drag the scroll handle.
protected  boolean handlePointerPressed(int relX, int relY)
          Handles the event when a pointer has been pressed at the specified position.
protected  boolean handlePointerReleased(int relX, int relY)
          Handles the event when a pointer has been released at the specified position.
protected  void initContent(int firstLineWidth, int availWidth, int availHeight)
          Initialises this item.
 int initScrollBar(int screenWidth, int screenAvailableHeight, int screenContentHeight, int contentYOffset, int selectionStart, int selectionHeight, int focusedIndex, int numberOfItems)
          Initializes this scrollbar.
 void paint(int x, int y, int leftBorder, int rightBorder, Graphics g)
          Paints this item on the screen.
protected  void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g)
          Paints the content of this item.
 void resetAnimation()
          Resets the animation status - when the opcaity is defined, it will be set to the start opacity again
 void setStyle(Style style)
          Sets the style of this item.
 
Methods inherited from class de.enough.polish.ui.Item
addCommand, addCommand, addCommand, addCommands, addRelativeToBackgroundRegion, addRelativeToBackgroundRegion, addRelativeToContentRegion, addRepaintArea, animate, containsCommand, defocus, destroy, fireContinueCycle, fireEvent, focus, getAbsoluteX, getAbsoluteY, getAfterWidthWithPadding, getAppearanceMode, getAttribute, getAttributes, getAvailableContentHeight, getAvailableContentWidth, getAvailableHeight, getAvailableWidth, getBackgroundHeight, getBackgroundWidth, getBackgroundX, getBackgroundY, getBeforeWidthWithPadding, getBorderWidthBottom, getBorderWidthLeft, getBorderWidthRight, getBorderWidthTop, getContentHeight, getContentWidth, getContentX, getContentY, getCycleListener, getDefaultCommand, getFocusedStyle, getInternalHeight, getInternalWidth, getInternalX, getInternalY, getItemAreaHeight, getItemAt, getItemCommandListener, getItemCommands, getItemHeight, getItemHeight, getItemStateListener, getItemWidth, getItemWidth, getLabel, getLabelItem, getLayout, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMaximumHeight, getMaximumHeight, getMaximumWidth, getMaximumWidth, getMinimumHeight, getMinimumHeight, getMinimumWidth, getMinimumWidth, getNativeItem, getPaddingBottom, getPaddingHorizontal, getPaddingLeft, getPaddingRight, getPaddingTop, getPaddingVertical, getParent, getParentRoot, getpreferredHeight, getpreferredWidth, getRgbData, getRgbData, getScreen, getStyle, getUiEventListener, getView, getView, handleCommand, handleCommand, handleGesture, handleGestureHold, handleGestureSwipeLeft, handleGestureSwipeRight, handleKeyPressed, handleKeyReleased, handleKeyRepeated, handleOnFocusSoftKeyboardDisplayBehavior, handlePointerDragged, handlePointerTouchDown, handlePointerTouchUp, hideNotify, init, initLayout, initMargin, initPadding, initStyle, isFocused, isInContentArea, isInContentWithPaddingArea, isInItemArea, isInItemArea, isInitialized, isInteractive, isLayoutBottom, isLayoutCenter, isLayoutExpand, isLayoutLeft, isLayoutNewlineAfter, isLayoutNewlineBefore, isLayoutRight, isLayoutShrink, isLayoutTop, isLayoutVerticalCenter, isLayoutVerticalExpand, isLayoutVerticalShrink, isPressed, isSameRowForContentAndLabel, isVisible, notifyItemPressedEnd, notifyItemPressedStart, notifyStateChanged, notifyUnvisited, notifyValueChanged, notifyVisited, onScreenSizeChanged, paintBackground, paintBackgroundAndBorder, paintBorder, paintCommands, paintFilter, releaseResources, removeAttribute, removeCommand, repaint, repaint, repaintFully, requestInit, resetStyle, setAbsoluteY, setAppearanceMode, setAttribute, setBackground, setBorder, setContentHeight, setContentWidth, setCycleListener, setDefaultCommand, setDefaultCommand, setInitialized, setItemCommandListener, setItemCommandListener, setItemHeight, setItemStateListener, setItemTransition, setItemWidth, setLabel, setLayout, setNativeItem, setParent, setParent, setpreferredSize, setSameRowForContentAndLabel, setStyle, setStyle, setUiEventListener, setView, setVisible, show, show, showCommands, showNotify, toImage, toRgbImage, toString, updateInternalArea
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sliderColor

protected int sliderColor

sliderWidth

protected Dimension sliderWidth

sliderImage

protected Image sliderImage

repeatSliderImage

protected boolean repeatSliderImage

repeatSliderNumber

protected int repeatSliderNumber

sliderMode

protected int sliderMode

sliderBackground

protected Background sliderBackground

hideSlider

protected boolean hideSlider

sliderY

protected int sliderY

sliderHeight

protected int sliderHeight

sliderMinHeight

protected int sliderMinHeight

scrollBarHeight

protected int scrollBarHeight

isVisible

protected boolean isVisible

overlap

protected boolean overlap

isPointerPressedHandled

protected boolean isPointerPressedHandled
Constructor Detail

ScrollBar

public ScrollBar()
Creates a new default scrollbar


ScrollBar

public ScrollBar(Style style)
Creates a new styled scrollbar

Parameters:
style - the style
Method Detail

initScrollBar

public int initScrollBar(int screenWidth,
                         int screenAvailableHeight,
                         int screenContentHeight,
                         int contentYOffset,
                         int selectionStart,
                         int selectionHeight,
                         int focusedIndex,
                         int numberOfItems)
Initializes this scrollbar.

Parameters:
screenWidth - the width of the screen
screenAvailableHeight - the height available for the content within the screen
screenContentHeight - the height of the content area of the screen
contentYOffset - the y offset for the content in the range of [-(screenContentHeight-screenAvailableHeight)...0]
selectionStart - the start of the selection relative to the screenContentHeight
selectionHeight - the height of the current selection
focusedIndex - the index of currently focused item
numberOfItems - the number of available items
Returns:
the item width of the scroll bar.

resetAnimation

public void resetAnimation()
Resets the animation status - when the opcaity is defined, it will be set to the start opacity again


animate

public boolean animate()
Description copied from class: Item
Animates this item. Subclasses can override this method to create animations. The default implementation returns false

Overrides:
animate in class Item
Returns:
true when this item has been animated.
See Also:
Item.animate(long, ClippingRegion)

initContent

protected void initContent(int firstLineWidth,
                           int availWidth,
                           int availHeight)
Description copied from class: Item
Initialises this item. The implementation needs to calculate and set the contentWidth and contentHeight fields. The implementation should take the fields preferredWidth and preferredHeight into account.

Specified by:
initContent in class Item
Parameters:
firstLineWidth - the maximum width of the first line
availWidth - the available maximum width of this item in pixels
availHeight - the available maximum height of this item in pixels
See Also:
Item.contentWidth, Item.contentHeight, Item.preferredWidth, Item.preferredHeight

paint

public void paint(int x,
                  int y,
                  int leftBorder,
                  int rightBorder,
                  Graphics g)
Description copied from class: Item
Paints this item on the screen. This method should normally not be overriden. Override it only when you know what you are doing!

Overrides:
paint in class Item
Parameters:
x - the left start position of this item.
y - the top start position of this item.
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position, rightBorder > x >= leftBorder
g - the Graphics on which this item should be painted.

paintContent

protected void paintContent(int x,
                            int y,
                            int leftBorder,
                            int rightBorder,
                            Graphics g)
Description copied from class: Item
Paints the content of this item. The background has already been painted and the border will be added after this method returns.

Specified by:
paintContent in class Item
Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
g - the Graphics on which this item should be painted.

createCssSelector

protected String createCssSelector()
Description copied from class: Item
Retrieves the CSS selector for this item. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the item and not by a predefined style-name. With the #style preprocessing command styles are set fix, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "Form>p", than the selector of the item is needed.
This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles
The returned selector needs to be in lower case.

Specified by:
createCssSelector in class Item
Returns:
the appropriate CSS selector for this item. The selector needs to be in lower case.

setStyle

public void setStyle(Style style)
Description copied from class: Item
Sets the style of this item.

Specified by:
setStyle in interface UiElement
Overrides:
setStyle in class Item
Parameters:
style - the new style for this item.

handlePointerPressed

protected boolean handlePointerPressed(int relX,
                                       int relY)
Handles the event when a pointer has been pressed at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyPressed event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerPressed in class Item
Parameters:
relX - the x position of the pointer pressing relative to this item's left position
relY - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int)

handlePointerReleased

protected boolean handlePointerReleased(int relX,
                                        int relY)
Handles the event when a pointer has been released at the specified position. The default method discards this event when relX/relY is outside of the item's area. When the event took place inside of the content area, the pointer-event is translated into an artificial FIRE game-action keyPressed event, which is subsequently handled bu the handleKeyPressed(-1, Canvas.FIRE) method. This method needs should be overwritten only when the "polish.hasPointerEvents" preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".

Overrides:
handlePointerReleased in class Item
Parameters:
relX - the x position of the pointer pressing relative to this item's left position
relY - the y position of the pointer pressing relative to this item's top position
Returns:
true when the pressing of the pointer was actually handled by this item.
See Also:
this method is used for determining whether the event belongs to this item, for a helper method for determining whether the event took place into the actual content area, Item.handleKeyPressed(int, int)

handlePointerDragged

protected boolean handlePointerDragged(int x,
                                       int y)
Allows to drag the scroll handle.

Overrides:
handlePointerDragged in class Item
Parameters:
x - relative x offset
y - relative y offset
Returns:
true when the dragged event was handled