FileDocCategorySizeDatePackage
ScreenLFImpl.javaAPI DocphoneME MR2 API (J2ME)14041Wed May 02 18:00:20 BST 2007javax.microedition.lcdui

ScreenLFImpl

public class ScreenLFImpl extends DisplayableLFImpl
This is the look &s; feel implementation for Screen.

Fields Summary
int[]
viewable
An array which holds the scroll location and the overall dimensions of the view being shown in the parent Displayable's viewport Note that the following is always true. 0 <= viewable[X] <= viewable[WIDTH] - viewport[WIDTH] 0 <= viewable[Y] <= viewable[HEIGHT] - viewport[HEIGHT]
boolean
resetToTop
Screens should automatically reset to the top of the when they are shown, except in cases where it is interrupted by a system menu or an off-screen editor - in which case it should be reshown exactly as it was.
private int
vScrollPosition
The vertical scroll position
private int
vScrollProportion
The vertical scroll proportion
private int
lastScrollPosition
Used in setupScroll in order to determine if scroll is needed
private int
lastScrollSize
Used in setupScroll in order to determine if scroll is needed. The value has no meaning for the actual scroll size
Constructors Summary
ScreenLFImpl(Screen screen)
Creates ScreenLF for the passed in screen.

param
screen the Screen object associated with this look&feel

        
        super(screen);
        
        viewable = new int[4];
        viewable[X] = 0;
        viewable[Y] = 0;
        viewable[WIDTH] = 0;
        viewable[HEIGHT] = 0;
    
Methods Summary
protected intgetMaxScroll()
The maximum amount of scroll needed to see all the contents

return
get the maximum scroll amount

        return viewable[HEIGHT] - viewport[HEIGHT];
    
protected intgetScrollAmount()
This is the number of pixels left from the previous "page" when a page up or down occurs. The same value is used for line by line scrolling

return
the number of pixels.

        return ScreenSkin.SCROLL_AMOUNT;
    
public intgetVerticalScrollPosition()
Get the current vertical scroll position

return
int The vertical scroll position on a scale of 0-100

        // SYNC NOTE: return of atomic value
        return vScrollPosition;
    
public intgetVerticalScrollProportion()
Get the current vertical scroll proportion

return
ing The vertical scroll proportion on a scale of 0-100

        // SYNC NOTE: return of atomic value
        return vScrollProportion;
    
voidlCallFreeze()
Override DisplayableLFImpl.lCallFreeze() to set local variables.

        if (state == SHOWN) {
            resetToTop = false;
        }
        super.lCallFreeze();
    
voidlCallHide()
Override DisplayableLFImpl.lCallHide() to set local variables.

        // NOTE that resetToTop is also set to false 
        // Display.setCurrentItem() is called.
        // Because of that just knowing current state of DisplayLF
        // is not enough to set it properly in lCallShow.
        // That is why it has to be updated in lCallHide and lCallFreeze
        super.lCallHide();
    
voidlRequestPaintItem(Item item, int x, int y, int w, int h)
Paint an Item contained in this Screen. The Item requests a paint in its own coordinate space. Screen translates those coordinates into the overall coordinate space and schedules the repaint

param
item the Item requesting the repaint
param
x the x-coordinate of the origin of the dirty region
param
y the y-coordinate of the origin of the dirty region
param
w the width of the dirty region
param
h the height of the dirty region

        
        ItemLFImpl iLF = (ItemLFImpl)item.getLF();

        lRequestPaint(iLF.bounds[X] - viewable[X] + x,
                      iLF.bounds[Y] - viewable[Y] + y,
                      w, h);
    
booleansetVerticalScroll(int scrollPosition, int scrollProportion)
Set the vertical scroll position and proportion

param
scrollPosition The vertical scroll position to set on a scale of 0-100
param
scrollProportion The vertical scroll proportion to set on a scale of 0-100. For example, if the viewport is 25 pixels high and the Displayable is 100 pixels high, then the scroll proportion would be 25, since only 25% of the Displayable can be viewed at any one time. This proportion value can be used by implementations which render scrollbars to indicate scrollability to the user.

        this.vScrollPosition = scrollPosition;
        this.vScrollProportion = scrollProportion;
            
        if (lIsShown()) {
            return currentDisplay.setVerticalScroll(scrollPosition, scrollProportion);
        }
        return false;
    
voidsetVerticalScroll()
Set the vertical scroll indicators for this Screen

        
        if (viewable[HEIGHT] <= viewport[HEIGHT]) {
            setVerticalScroll(0, 100);
        } else {
            setVerticalScroll((viewable[Y] * 100 /
                               (viewable[HEIGHT] - viewport[HEIGHT])),
                              (viewport[HEIGHT] * 100 / viewable[HEIGHT]));
        }
    
voidsetupScroll()
all scroll actions should be handled through here.

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, 
                           LogChannels.LC_HIGHUI_FORM_LAYOUT,
                           "[F] >> in FormLFImpl - setupScroll " +
                           invalidScroll +
                           "[F] >> viewable[Y] == "+viewable[Y] +
                           " lastScrollPosition] == "+lastScrollPosition +
                           "[F] >> viewable[HEIGHT] == "+viewable[HEIGHT] +
                           " lastScrollSize == "+lastScrollSize);
        }
        
        // check if scroll moves, and if so, refresh scrollbars
        if (!invalidScroll &&
            (viewable[Y] != lastScrollPosition ||
             (lastScrollSize != 0 &&
              viewable[HEIGHT] + viewport[HEIGHT] != lastScrollSize))) {
            
            lastScrollPosition = viewable[Y];
            lastScrollSize = viewport[HEIGHT] >= viewable[HEIGHT] ?
                0: viewable[HEIGHT] + viewport[HEIGHT];
            
            invalidScroll = true;
            // IMPL_NOTE: mark Items for repaint. -au
        }

        
        if (invalidScroll) {
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, 
                               LogChannels.LC_HIGHUI_FORM_LAYOUT,
                               "[F]  ## invalidScroll ");
            }
            
            // draw the scrollbars
            setVerticalScroll();
            
            invalidScroll = false;
        }
    
public voiduCallPaint(Graphics g, java.lang.Object target)
Paint the contents of this Screen

param
g the Graphics to paint to
param
target the target Object of this repaint

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                           "Screen:Clip: " +
                           g.getClipX() + "," + g.getClipY() + "," +
                           g.getClipWidth() + "," + g.getClipHeight());
        }
    
public voiduCallScrollContent(int scrollType, int thumbPosition)
Scroll content inside of the form.

param
scrollType scrollType. Scroll type can be one of the following
see
ScrollBarLayer.SCROLL_NONE
see
ScrollBarLayer.SCROLL_PAGEUP
see
ScrollBarLayer.SCROLL_PAGEDOWN
see
ScrollBarLayer.SCROLL_LINEUP
see
ScrollBarLayer.SCROLL_LINEDOWN or
see
ScrollBarLayer.SCROLL_THUMBTRACK
param
thumbPosition

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, 
                           LogChannels.LC_HIGHUI,
                           "Screen.uCallScrollContent scrollType=" + scrollType + 
                           " thumbPosition=" + thumbPosition); 
        }
        int oldY = viewable[Y]; 
        
        switch (scrollType) {
            case ScrollBarLayer.SCROLL_PAGEUP:
                uScrollViewport(Canvas.UP);
                break;
            case ScrollBarLayer.SCROLL_PAGEDOWN:
                uScrollViewport(Canvas.DOWN);
                break;
            case ScrollBarLayer.SCROLL_LINEUP:
                uScrollByLine(Canvas.UP);
                break;
            case ScrollBarLayer.SCROLL_LINEDOWN:
                uScrollByLine(Canvas.DOWN);
                break;
            case ScrollBarLayer.SCROLL_THUMBTRACK:
                uScrollAt(thumbPosition);
                break;
            default:
                break;
        }
        if (oldY != viewable[Y]) {
            uRequestPaint();
            setupScroll();
        }
    
protected voiduScrollAt(int position)
Perform a scrolling at the given position.

param
context position

        int max = getMaxScroll();
        int newY = max * position / 100 ;
        if (newY < 0) {
            newY = 0;
        } else if (newY > max) {
            newY = max;
        }
        viewable[Y] = newY;
    
protected voiduScrollByLine(int dir)
Perform a line scrolling in the given direction. This method will attempt to scroll the view to show next/previous line.

param
dir the direction of the flip, either DOWN or UP

        int newY = viewable[Y];
        if (dir == Canvas.UP) {
            newY -= getScrollAmount();
            if (newY < 0) {
                newY = 0;
            }
        } else if (dir == Canvas.DOWN) {
            newY += getScrollAmount();
            int max = getMaxScroll();
            if (newY > max) {
                newY = max;
            }
        }
        viewable[Y] = newY;
    
protected voiduScrollViewport(int dir)
Perform a page flip in the given direction. This method will attempt to scroll the view to show as much of the next page as possible.

param
dir the direction of the flip, either DOWN or UP

        int newY = viewable[Y];
        switch (dir) {
        case Canvas.UP:
            newY -= lGetHeight() - getScrollAmount();
            if (newY < 0) {
                newY = 0;
            }
            break;
        case Canvas.DOWN:
            newY += lGetHeight() - getScrollAmount();
            int max = getMaxScroll();
            if (newY > max) {
                newY = max;
            }
            break;
        default:
            break;
        }
        viewable[Y] = newY;