com.google.gwt.widgetideas.client
Class ProgressBar

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.widgetideas.client.ProgressBar
All Implemented Interfaces:
com.google.gwt.user.client.EventListener, ResizableWidget

public class ProgressBar
extends com.google.gwt.user.client.ui.Widget
implements ResizableWidget

A widget that displays progress on an arbitrary scale.

CSS Style Rules


Nested Class Summary
static class ProgressBar.TextFormatter
          A formatter used to format the text displayed in the progress bar widget.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
ProgressBar()
          Create a progress bar with default range of 0 to 100.
ProgressBar(double curProgress)
          Create a progress bar with an initial progress and a default range of 0 to 100.
ProgressBar(double minProgress, double maxProgress)
          Create a progress bar within the given range.
ProgressBar(double minProgress, double maxProgress, double curProgress)
          Create a progress bar within the given range starting at the specified progress amount.
ProgressBar(double minProgress, double maxProgress, double curProgress, ProgressBar.TextFormatter textFormatter)
          Create a progress bar within the given range starting at the specified progress amount.
 
Method Summary
protected  java.lang.String generateText(double curProgress)
          Generate the text to display within the progress bar.
protected  com.google.gwt.user.client.Element getBarElement()
          Get the bar element.
 double getMaxProgress()
          Get the maximum progress.
 double getMinProgress()
          Get the minimum progress.
 double getPercent()
          Get the current percent complete, relative to the minimum and maximum values.
 double getProgress()
          Get the current progress.
protected  com.google.gwt.user.client.Element getTextElement()
          Get the text element.
 ProgressBar.TextFormatter getTextFormatter()
          Get the text formatter.
 boolean isTextVisible()
          Check whether the text is visible or not.
protected  void onLoad()
          This method is called immediately after a widget becomes attached to the browser's document.
 void onResize(int width, int height)
          This method is called when the dimensions of the parent element change.
 void redraw()
          Redraw the progress bar when something changes the layout.
protected  void resetProgress()
          Reset the progress text based on the current min and max progress range.
 void setMaxProgress(double maxProgress)
          Set the maximum progress.
 void setMinProgress(double minProgress)
          Set the minimum progress.
 void setProgress(double curProgress)
          Set the current progress.
 void setTextFormatter(ProgressBar.TextFormatter textFormatter)
          Set the text formatter.
 void setTextVisible(boolean isVisible)
          Sets whether the text is visible over the bar.
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onBrowserEvent, onDetach, onUnload, removeFromParent, setElement
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.widgetideas.client.ResizableWidget
getElement, isAttached
 

Constructor Detail

ProgressBar

public ProgressBar()
Create a progress bar with default range of 0 to 100.


ProgressBar

public ProgressBar(double curProgress)
Create a progress bar with an initial progress and a default range of 0 to 100.

Parameters:
curProgress - the current progress

ProgressBar

public ProgressBar(double minProgress,
                   double maxProgress)
Create a progress bar within the given range.

Parameters:
minProgress - the minimum progress
maxProgress - the maximum progress

ProgressBar

public ProgressBar(double minProgress,
                   double maxProgress,
                   double curProgress)
Create a progress bar within the given range starting at the specified progress amount.

Parameters:
minProgress - the minimum progress
maxProgress - the maximum progress
curProgress - the current progress

ProgressBar

public ProgressBar(double minProgress,
                   double maxProgress,
                   double curProgress,
                   ProgressBar.TextFormatter textFormatter)
Create a progress bar within the given range starting at the specified progress amount.

Parameters:
minProgress - the minimum progress
maxProgress - the maximum progress
curProgress - the current progress
textFormatter - the text formatter
Method Detail

getMaxProgress

public double getMaxProgress()
Get the maximum progress.

Returns:
the maximum progress

getMinProgress

public double getMinProgress()
Get the minimum progress.

Returns:
the minimum progress

getPercent

public double getPercent()
Get the current percent complete, relative to the minimum and maximum values. The percent will always be between 0.0 - 1.0.

Returns:
the current percent complete

getProgress

public double getProgress()
Get the current progress.

Returns:
the current progress

getTextFormatter

public ProgressBar.TextFormatter getTextFormatter()
Get the text formatter.

Returns:
the text formatter

isTextVisible

public boolean isTextVisible()
Check whether the text is visible or not.

Returns:
true if the text is visible

onResize

public void onResize(int width,
                     int height)
This method is called when the dimensions of the parent element change. Subclasses should override this method as needed. Move the text to the center of the progress bar.

Specified by:
onResize in interface ResizableWidget
Parameters:
width - the new client width of the element
height - the new client height of the element

redraw

public void redraw()
Redraw the progress bar when something changes the layout.


setMaxProgress

public void setMaxProgress(double maxProgress)
Set the maximum progress. If the minimum progress is more than the current progress, the current progress is adjusted to be within the new range.

Parameters:
maxProgress - the maximum progress

setMinProgress

public void setMinProgress(double minProgress)
Set the minimum progress. If the minimum progress is more than the current progress, the current progress is adjusted to be within the new range.

Parameters:
minProgress - the minimum progress

setProgress

public void setProgress(double curProgress)
Set the current progress.

Parameters:
curProgress - the current progress

setTextFormatter

public void setTextFormatter(ProgressBar.TextFormatter textFormatter)
Set the text formatter.

Parameters:
textFormatter - the text formatter

setTextVisible

public void setTextVisible(boolean isVisible)
Sets whether the text is visible over the bar.

Parameters:
isVisible - True to show text, false to hide it

generateText

protected java.lang.String generateText(double curProgress)
Generate the text to display within the progress bar. Override this function to change the default progress percent to a more informative message, such as the number of kilobytes downloaded.

Parameters:
curProgress - the current progress
Returns:
the text to display in the progress bar

getBarElement

protected com.google.gwt.user.client.Element getBarElement()
Get the bar element.

Returns:
the bar element

getTextElement

protected com.google.gwt.user.client.Element getTextElement()
Get the text element.

Returns:
the text element

onLoad

protected void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.

Overrides:
onLoad in class com.google.gwt.user.client.ui.Widget

resetProgress

protected void resetProgress()
Reset the progress text based on the current min and max progress range.