org.j4me.ui.components
Class ProgressBar

java.lang.Object
  extended by org.j4me.ui.components.Component
      extended by org.j4me.ui.components.ProgressBar

public class ProgressBar
extends Component

Displays a progress bar that indicates the state of a background process.

Progress bars come in two flavors. There is the standard progress bar which appears as a rectangle that fills from left-to-right as progress toward some known point occurs. There is also a spinner which is animated to show constant progress and is useful when it is unknown how long the operation will last. These are differentiated by setMaxSize; when 0 it is a spinner and when positive it is a progress bar.


Field Summary
 
Fields inherited from class org.j4me.ui.components.Component
container, HIGHLIGHTED_BORDER_WIDTH
 
Constructor Summary
ProgressBar()
          Creates a progress bar component.
 
Method Summary
 java.lang.String getLabel()
           
 int getMaxValue()
          Returns the maximum amount of progress.
protected  int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
          Returns the dimensions of the progress bar.
 double getRelativeHeight()
          Returns the height of the progress bar relative to the height of the default font specified in the theme.
 double getRelativeWidth()
          Gets how far across the screen the progress bar extends.
 int getValue()
           
protected  void hideNotify()
          An event raised whenever the component is removed from the screen.
protected  void paintBar(javax.microedition.lcdui.Graphics g, Theme theme, int x, int y, int width, int height, boolean selected)
          Paints a progress bar that shows an operation with a known duration.
protected  void paintComponent(javax.microedition.lcdui.Graphics g, Theme theme, int width, int height, boolean selected)
          Paints the progress bar.
protected  void paintSpinner(javax.microedition.lcdui.Graphics g, Theme theme, int x, int y, int width, int height, boolean selected)
          Paints a spinner component used to show progress during an operation of an unknown duration.
 void setLabel(java.lang.String label)
           
 void setMaxValue(int max)
           
 void setRelativeHeight(double percentageOfFontHeight)
          Sets the height of the progress bar relative to the default font specified in the theme.
 void setRelativeWidth(double percentageOfScreen)
          Sets how far across the screen the progress bar extends.
 void setValue(int value)
          Sets the maximum amount of progress.
protected  void showNotify()
          An event raised whenever the component is made visible on the screen.
 
Methods inherited from class org.j4me.ui.components.Component
acceptsInput, getHeight, getHorizontalAlignment, getPreferredSize, getScreen, getWidth, getX, getY, invalidate, isShown, keyPressed, keyReleased, keyRepeated, paint, paintRect, pointerDragged, pointerPressed, pointerReleased, repaint, setHorizontalAlignment, visible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressBar

public ProgressBar()
Creates a progress bar component.

Method Detail

getLabel

public java.lang.String getLabel()
Returns:
The text that appears above the progess bar. If null there is no text.

setLabel

public void setLabel(java.lang.String label)
Parameters:
label - is the text that appears above the progress bar. If null there will be no text.

getValue

public int getValue()
Returns:
The amount of completed progess.

setValue

public void setValue(int value)
Sets the maximum amount of progress. If this is 0, the total progress is unknown and this component will be represented by a spinner animation.

Parameters:
value - is the amount of completed progess.

getMaxValue

public int getMaxValue()
Returns the maximum amount of progress. If this is 0, the total progress is unknown and this component will be represented by a spinner animation.

Returns:
The maximum amount of progress.

setMaxValue

public void setMaxValue(int max)
Parameters:
max - is the maximum amount of progress.

setRelativeWidth

public void setRelativeWidth(double percentageOfScreen)
Sets how far across the screen the progress bar extends. This has no effect on the size of a spinner.

Parameters:
percentageOfScreen - is the length of the progress bar relative to the width of the screen. It must be between 0.00 and 1.00.

getRelativeWidth

public double getRelativeWidth()
Gets how far across the screen the progress bar extends.

Returns:
The length of the progress bar relative to the width of the screen.

setRelativeHeight

public void setRelativeHeight(double percentageOfFontHeight)
Sets the height of the progress bar relative to the default font specified in the theme. Setting to 0 uses the default heights.

Parameters:
percentageOfFontHeight - is how tall, relative to the default font, the progress bar is. For example 1.2 is 120% the size.

getRelativeHeight

public double getRelativeHeight()
Returns the height of the progress bar relative to the height of the default font specified in the theme.

Returns:
The height of the progress bar as a percentage of the default font's height. For example 1.2 is 120% the size.

paintComponent

protected void paintComponent(javax.microedition.lcdui.Graphics g,
                              Theme theme,
                              int width,
                              int height,
                              boolean selected)
Paints the progress bar.

Specified by:
paintComponent in class Component
Parameters:
g - is the Graphics object to be used for rendering the item.
theme - is the application's theme. Use it to get fonts and colors.
width - is the width, in pixels, to paint the component.
height - is the height, in pixels, to paint the component.
selected - is true when this components is currently selected and false when it is not.
See Also:
Component.paintComponent(Graphics, Theme, int, int, boolean)

paintBar

protected void paintBar(javax.microedition.lcdui.Graphics g,
                        Theme theme,
                        int x,
                        int y,
                        int width,
                        int height,
                        boolean selected)
Paints a progress bar that shows an operation with a known duration. The bar fills in left-to-right as progress occurs. The portion on the left indicating completed progress will take up getCurrent / getMax percent of the progress bar.

Parameters:
g - is the Graphics object to be used for rendering the item.
theme - is the application's theme. Use it to get fonts and colors.
x - is the left side of the component.
y - is the top side of the component.
width - is the width, in pixels, to paint the component.
height - is the height, in pixels, to paint the component.
selected - is true when this components is currently selected and false when it is not.

paintSpinner

protected void paintSpinner(javax.microedition.lcdui.Graphics g,
                            Theme theme,
                            int x,
                            int y,
                            int width,
                            int height,
                            boolean selected)
Paints a spinner component used to show progress during an operation of an unknown duration.

Parameters:
g - is the Graphics object to be used for rendering the item.
theme - is the application's theme. Use it to get fonts and colors.
x - is the left side of the component.
y - is the top side of the component.
width - is the width, in pixels, to paint the component.
height - is the height, in pixels, to paint the component.
selected - is true when this components is currently selected and false when it is not.

getPreferredComponentSize

protected int[] getPreferredComponentSize(Theme theme,
                                          int viewportWidth,
                                          int viewportHeight)
Returns the dimensions of the progress bar.

Specified by:
getPreferredComponentSize in class Component
Parameters:
theme - is the application's Theme.
viewportWidth - is the width of the viewable area, in pixels, the component can use.
viewportHeight - is the height of the viewable area, in pixels, the component can use.
Returns:
A array with two elements where the first is the width of the component in pixels and the second is the height.
See Also:
Component.getPreferredComponentSize(org.j4me.ui.Theme, int, int)

showNotify

protected void showNotify()
An event raised whenever the component is made visible on the screen. This is called before the paintComponent method.

Overrides:
showNotify in class Component
See Also:
Component.showNotify()

hideNotify

protected void hideNotify()
An event raised whenever the component is removed from the screen.

Overrides:
hideNotify in class Component
See Also:
Component.hideNotify()