example.photoalbum
Class PhotoFrame

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by example.photoalbum.PhotoFrame
All Implemented Interfaces:
java.lang.Runnable

 class PhotoFrame
extends javax.microedition.lcdui.Canvas
implements java.lang.Runnable

This PhotoFrame provides the picture frame and drives the animation of the frames and the picture. It handles the starting and stopping of the Animation and contains the Thread used to do the timing and requests that the Canvas be repainted periodically. It controls the border style and animation speed.


Field Summary
(package private)  int frameCount
          Number of frames since last frame rate report
(package private)  int frameRate
          Last reported frame rate (for re-paint)
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
PhotoFrame()
          Create a new PhotoFrame.
 
Method Summary
(package private)  int getSpeed()
          Get the speed at which animation occurs.
(package private)  int getStyle()
          Get the style being used for borders.
protected  void hideNotify()
          Notified when the Canvas is no longer visible.
(package private)  boolean intersectsClip(javax.microedition.lcdui.Graphics g, int x, int y, int w, int h)
          Return true if the specified rectangle does not intersect the clipping rectangle of the graphics object.
protected  void keyPressed(int keyCode)
          Handle key events.
protected  void keyRepeated(int keyCode)
          Handle key repeat events as regular key events.
(package private)  void next()
          Advance to the next image and wrap around if necessary.
protected  void paint(javax.microedition.lcdui.Graphics g)
          Paint is called whenever the canvas should be redrawn.
(package private)  void previous()
          Back up to the previous image.
(package private)  void reset()
          Reset the PhotoFrame so it holds minimal resources.
 void run()
          Runs the animation and makes the repaint requests.
(package private)  void setImages(java.util.Vector images)
          Set the array of images to be displayed.
(package private)  void setSpeed(int speed)
          Set the animation speed.
(package private)  void setStyle(int style)
          Set the frame style.
protected  void showNotify()
          Notified when Canvas is made visible.
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, keyReleased, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frameCount

int frameCount
Number of frames since last frame rate report


frameRate

int frameRate
Last reported frame rate (for re-paint)

Constructor Detail

PhotoFrame

PhotoFrame()
Create a new PhotoFrame. Create an offscreen mutable image into which the border is drawn. Border style is none (0). Speed is stopped (0) until set.

Method Detail

setImages

void setImages(java.util.Vector images)
Set the array of images to be displayed. Update the width and height of the image and draw the border to fit around it in the offscreen image.

Parameters:
images - a vector of images to be displayed.

next

void next()
Advance to the next image and wrap around if necessary.


previous

void previous()
Back up to the previous image. Wrap around to the end if at the beginning.


reset

void reset()
Reset the PhotoFrame so it holds minimal resources. The animation thread is stopped.


keyPressed

protected void keyPressed(int keyCode)
Handle key events. FIRE events toggle between running and stopped. LEFT and RIGHT key events when stopped show the previous or next image.

Overrides:
keyPressed in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - of the key pressed

keyRepeated

protected void keyRepeated(int keyCode)
Handle key repeat events as regular key events.

Overrides:
keyRepeated in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - of the key repeated

setSpeed

void setSpeed(int speed)
Set the animation speed. Speed:
  1. 0 = stop
  2. 1 = slow
  3. 2 = medium
  4. 3 = fast
  5. 4 = unlimited

Parameters:
speed - speedo of animation 0-3;

getSpeed

int getSpeed()
Get the speed at which animation occurs.

Returns:
the current speed.
See Also:
setSpeed

setStyle

void setStyle(int style)
Set the frame style. Recreate the photo frame image from the current style and location and size

Style:

  1. Style 0: No border is drawn.
  2. Style 1: A simple border is drawn
  3. Style 2: The border is outlined and an image is created to tile within the border.

Parameters:
style - the style of the border; 0 = none, 1 = simple, 2 = fancy.

getStyle

int getStyle()
Get the style being used for borders.

Returns:
the style.

showNotify

protected void showNotify()
Notified when Canvas is made visible. If there is more than one image to display create the thread to run the animation timing.

Overrides:
showNotify in class javax.microedition.lcdui.Canvas

hideNotify

protected void hideNotify()
Notified when the Canvas is no longer visible. Signal the running Thread that it should stop.

Overrides:
hideNotify in class javax.microedition.lcdui.Canvas

intersectsClip

boolean intersectsClip(javax.microedition.lcdui.Graphics g,
                       int x,
                       int y,
                       int w,
                       int h)
Return true if the specified rectangle does not intersect the clipping rectangle of the graphics object. If it returns true then the object must be drawn otherwise it would be clipped completely. The checks are done

Parameters:
g - the Graphics context to check.
x - the x value of the upper left corner of the rectangle
y - the y value of the upper left corner of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Returns:
true if the rectangle intersects the clipping region

run

public void run()
Runs the animation and makes the repaint requests. The thread will exit when it is no longer the current Animation thread.

Specified by:
run in interface java.lang.Runnable

paint

protected void paint(javax.microedition.lcdui.Graphics g)
Paint is called whenever the canvas should be redrawn. It clears the canvas and draws the frame and the current current frame from the animation.

Specified by:
paint in class javax.microedition.lcdui.Canvas
Parameters:
g - the Graphics context to which to draw