org.gwtwidgets.client.ui
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.user.client.ui.Panel
              extended by com.google.gwt.user.client.ui.ComplexPanel
                  extended by com.google.gwt.user.client.ui.CellPanel
                      extended by com.google.gwt.user.client.ui.VerticalPanel
                          extended by org.gwtwidgets.client.ui.ProgressBar
All Implemented Interfaces:
com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasAlignment, com.google.gwt.user.client.ui.HasHorizontalAlignment, com.google.gwt.user.client.ui.HasVerticalAlignment, com.google.gwt.user.client.ui.HasWidgets, com.google.gwt.user.client.ui.IndexedPanel

public class ProgressBar
extends com.google.gwt.user.client.ui.VerticalPanel

A simple progress bar that uses table elements to show progress and with a basic time remaining calculation built in.

You can optionally display some text above the progress bar and/or display time remaining underneath the progress bar. To control the display of those features, set the options in the constructor as shown in the following usage example:

        final ProgressBar progressBar = new ProgressBar(20
                                                ,ProgressBar.SHOW_TIME_REMAINING
                                                 +ProgressBar.SHOW_TEXT);
        progressBar.setText("Doing something...");
        RootPanel.get().add(progressBar);
        Timer t = new Timer() {
                public void run() {
                        int progress = progressBar.getProgress()+4;
                        if (progress>100) cancel();
                        progressBar.setProgress(progress);
                }
        };
        t.scheduleRepeating(1000);
 

How the time remaining is displayed can be controlled by setting the relevant messages using the language of your choice.

The default setting for the messages are as follows:

                setSecondsMessage("Time remaining: {0} Seconds");
                setMinutesMessage("Time remaining: {0} Minutes");
                setHoursMessage("Time remaining: {0} Hours");
 

To reset the time remaining/set the start time, simply set the progress to zero.

Some basic CSS styling is available to control the text, border around the progress bar itself and the colour of the progress bar elements.

 .progressbar-text {
     font-weight: bold;
 }
 
 .progressbar-remaining {
     font-size: 12px;
     font-style: italic;
 }
 
 .progressbar-outer {
     border: 1px solid black;
 }
 
 .progressbar-inner {
     border: 1px solid black;
     margin: 1px;
 }
 
 .progressbar-bar {
     width: 5px;
     height: 15px;
     margin: 1px;
 }
 
 .progressbar-fullbar {
     background: blue;
 }
 
 .progressbar-blankbar {
     background: #eee;
 }

You can take advantage of the default style by adding the following to the head of your HTML page.

<link rel="stylesheet" type="text/css" href="style/gwl-progressBar.css">

This style sheet also has two additional styles which you can use by adding the stye name to the widget. You can use either one of these, or use both combined.

  ProgressBar progressBar = new ProgressBar(20);
  progressBar.addStyleName("progressbar-solid");
  progressBar.addStyleName("progressbar-noborder");
 

Author:
Bjarne Matzen - Bjarne[dot]Matzen[at]gmail[dot]com

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant
 
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasVerticalAlignment
com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant
 
Field Summary
static int SHOW_TEXT
          Option to show text label above progress bar
static int SHOW_TIME_REMAINING
          Option to show time remaining
 
Fields inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT
 
Fields inherited from interface com.google.gwt.user.client.ui.HasVerticalAlignment
ALIGN_BOTTOM, ALIGN_MIDDLE, ALIGN_TOP
 
Constructor Summary
ProgressBar(int elements)
          Constructor without options
ProgressBar(int elements, int options)
          Base constructor for this widget
 
Method Summary
 java.lang.String getHoursMessage()
          Get the message used to format the time remaining text for hours
 java.lang.String getMinutesMessage()
          Get the message used to format the time remaining text for minutes
 int getProgress()
          Get the current progress as a percentage
 java.lang.String getSecondsMessage()
          Get the message used to format the time remaining text for seconds
 java.lang.String getText()
          Get the text displayed above the progress bar
 void setHoursMessage(java.lang.String hoursMessage)
          Set the message used to format the time remaining text below the progress bar.
 void setMinutesMessage(java.lang.String minutesMessage)
          Set the message used to format the time remaining text below the progress bar.
 void setProgress(int percentage)
          Set the current progress as a percentage
 void setSecondsMessage(java.lang.String secondsMessage)
          Set the message used to format the time remaining text below the progress bar.
 void setText(java.lang.String text)
          Set the text displayed above the progress bar
 
Methods inherited from class com.google.gwt.user.client.ui.VerticalPanel
add, getHorizontalAlignment, getVerticalAlignment, insert, remove, setHorizontalAlignment, setVerticalAlignment
 
Methods inherited from class com.google.gwt.user.client.ui.CellPanel
getBody, getSpacing, getTable, setBorderWidth, setCellHeight, setCellHorizontalAlignment, setCellHorizontalAlignment, setCellVerticalAlignment, setCellVerticalAlignment, setCellWidth, setSpacing
 
Methods inherited from class com.google.gwt.user.client.ui.ComplexPanel
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, insert, insert, iterator, remove
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
adopt, adopt, clear, disown, doAttachChildren, doDetachChildren, onLoad, onUnload, orphan
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setElement
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, 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
 

Field Detail

SHOW_TEXT

public static final int SHOW_TEXT
Option to show text label above progress bar

See Also:
Constant Field Values

SHOW_TIME_REMAINING

public static final int SHOW_TIME_REMAINING
Option to show time remaining

See Also:
Constant Field Values
Constructor Detail

ProgressBar

public ProgressBar(int elements,
                   int options)
Base constructor for this widget

Parameters:
elements - The number of elements (bars) to show on the progress bar
options - The display options for the progress bar

ProgressBar

public ProgressBar(int elements)
Constructor without options

Parameters:
elements - The number of elements (bars) to show on the progress bar
Method Detail

setProgress

public void setProgress(int percentage)
Set the current progress as a percentage

Parameters:
percentage - Set current percentage for the progress bar

getProgress

public int getProgress()
Get the current progress as a percentage

Returns:
Current percentage for the progress bar

getText

public java.lang.String getText()
Get the text displayed above the progress bar

Returns:
the text

setText

public void setText(java.lang.String text)
Set the text displayed above the progress bar

Parameters:
text - the text to set

getHoursMessage

public java.lang.String getHoursMessage()
Get the message used to format the time remaining text for hours

Returns:
the hours message

setHoursMessage

public void setHoursMessage(java.lang.String hoursMessage)
Set the message used to format the time remaining text below the progress bar. There are 3 messages used for hours, minutes and seconds respectively. The message must contain a placeholder for the value. The placeholder must be {0}. For example, the following is a valid message: "Hours remaining: {0}"

Parameters:
hoursMessage - the hours message to set

getMinutesMessage

public java.lang.String getMinutesMessage()
Get the message used to format the time remaining text for minutes

Returns:
the minutesMessage

setMinutesMessage

public void setMinutesMessage(java.lang.String minutesMessage)
Set the message used to format the time remaining text below the progress bar. There are 3 messages used for hours, minutes and seconds respectively. The message must contain a placeholder for the value. The placeholder must be {0}. For example, the following is a valid message: "Minutes remaining: {0}"

Parameters:
minutesMessage - the minutes message to set

getSecondsMessage

public java.lang.String getSecondsMessage()
Get the message used to format the time remaining text for seconds

Returns:
the secondsMessage

setSecondsMessage

public void setSecondsMessage(java.lang.String secondsMessage)
Set the message used to format the time remaining text below the progress bar. There are 3 messages used for hours, minutes and seconds respectively. The message must contain a placeholder for the value. The placeholder must be {0}. For example, the following is a valid message: "Seconds remaining: {0}"

Parameters:
secondsMessage - the secondsMessage to set


Copyright © 2009. All Rights Reserved.