FileDocCategorySizeDatePackage
ScrollArrowLayer.javaAPI DocphoneME MR2 API (J2ME)7180Wed May 02 18:00:20 BST 2007com.sun.midp.chameleon.layers

ScrollArrowLayer

public class ScrollArrowLayer extends ScrollIndLayer
A ScrollArrowLayer is a region of the display used for showing scroll indicator status arrows.

Fields Summary
protected boolean
upViz
True if up arrow is visible
protected boolean
downViz
True if down arrow is visible
Constructors Summary
public ScrollArrowLayer(CLayer layer)
Construct a new ScrollIndLayer, visible, but transparent :)

        this(layer, null);
    
public ScrollArrowLayer(CLayer layer, ScrollListener listener)
Additional constructor.

param
layer the scrollable controlling the scrolling layer
param
listener the scrolling listener

        super(layer, listener);
    
Methods Summary
private intgetScrollType(int x, int y)
Determine he scroll type basing on the pointer coordinates

param
x - x coordinate
param
y - y coordinate
return
the scroll type The possible types of scrolling are
see
#SCROLL_NONE
see
#SCROLL_LINEUP
see
#SCROLL_LINEDOWN

        int ret = SCROLL_NONE;
        if (x >= 0 && x <= bounds[W] &&
            y >= 0 && y <= bounds[H]) {
            if (upViz && y < bounds[H] / 2) {
                ret = SCROLL_LINEUP;
            } else if (downViz && y > bounds[H] / 2) {
                ret = SCROLL_LINEDOWN;
            }
        } 
        return ret;
    
protected voidpaintBody(Graphics g)
Paint the scroll indicator. The indicator arrows may be appear individually or together, and may vary in appearance based on whether they appear in the normalsoft button region or an alert's softbutton region. The visible state is based on the state of the alertMode, upViz, and downViz variables set by the setVerticalScroll method.

param
g the graphics context to paint in

        if (upViz) {
            Image i = ScrollIndSkin.IMAGE_UP;
            if (alertMode && ScrollIndSkin.IMAGE_AU_UP != null) {
                i = ScrollIndSkin.IMAGE_AU_UP;
            }
            if (i != null) {
                g.drawImage(i, 0, 0, Graphics.LEFT| Graphics.TOP);
            }
        }
        
        if (downViz) {
            Image i = ScrollIndSkin.IMAGE_DN;
            if (alertMode && ScrollIndSkin.IMAGE_AU_DN != null) {
                i = ScrollIndSkin.IMAGE_AU_DN;
            }
            if (i != null) {
                g.drawImage(i, 0, 
                    bounds[H] - ScrollIndSkin.IMAGE_DN.getHeight(),
                    Graphics.LEFT | Graphics.TOP);
            }
        }
    
public booleanpointerInput(int type, int x, int y)
Handle input from a pen tap. Parameters describe the type of pen event and the x,y location in the layer at which the event occurred. Important : the x,y location of the pen tap will already be translated into the coordinate space of the layer.

param
type the type of pen event
param
x the x coordinate of the event
param
y the y coordinate of the event

               
        switch(type) {
        case EventConstants.PRESSED:
            // case EventConstants.HOLD:
            // no action for tap-and-hold in scrollbar
            // cancel timer for any press.
            
            int scrollType = getScrollType(x, y);
            if (scrollType == SCROLL_LINEDOWN ||
                scrollType ==  SCROLL_LINEUP) {
                listener.scrollContent(scrollType, 0);
            }
            break;
        case EventConstants.RELEASED:
            // do nothing 
            break;
        default:
            break;
        }
        
        /* we should process all of the pointer event inside scroll layer
           and don't pass it to underlying layer */
        return true;
    
public voidsetBounds()
Calculate layer bounds depending on the scrollable

        bounds[H] = SoftButtonSkin.HEIGHT;
        if (ScrollIndSkin.IMAGE_UP != null) {
            bounds[W] = ScrollIndSkin.IMAGE_UP.getWidth();
            bounds[H] = (2 * ScrollIndSkin.IMAGE_UP.getHeight());
            bounds[Y] = (SoftButtonSkin.HEIGHT - bounds[H]) / 3;
            bounds[H] += bounds[Y];
            bounds[Y] = ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT +
                bounds[Y];
        } else {
            bounds[W] = ScrollIndSkin.WIDTH;
            bounds[Y] = 3;
        }
        bounds[X] = (ScreenSkin.WIDTH - bounds[W]) / 2;
    
public booleansetScrollable(CLayer layer)
Set new scrollable

param
layer new scrollable controlling the scrolling layer
return
true if the scrollable is changed, false - otherwise

        boolean ret = super.setScrollable(layer);
        if (ret) {
            alertMode |= scrollable instanceof MenuLayer;
        }
        upViz = downViz = false;
        return ret;
    
public voidsetVerticalScroll(int scrollPosition, int scrollProportion)
Set the current vertical scroll position and proportion.

param
scrollPosition vertical scroll position.
param
scrollProportion vertical scroll proportion.

	
        boolean up = upViz;
        boolean dn = downViz;
        if ( (scrollable != null) &&
             (scrollProportion < 100)) {
            upViz = (scrollPosition > 0);
            downViz = (scrollPosition < 100);
        } else {
            upViz = downViz = false;
        }
        setVisible(upViz || downViz);
        if (up != upViz || dn != downViz) {
            requestRepaint();
        }