2004.04.29


com.jdc.gui.html
Class ProgressBar

java.lang.Object
  |
  +--com.jdc.gui.html.ProgressBar

public class ProgressBar
extends Object

ProgressBar creates the HTML required to display the progress of a CPU-intensive task for a web application. This allows the web application to provide an indication of the progress of the task to the user at specified intervals.

The progress bar is actually an HTML table displayed in a <div>, i.e. a block-level container, on the JSP page. The container (and the progress bar it contains) are displayed in front of all other elements on the page by setting the Cascading Style Sheet (CSS) property z-index to 100.

The position and appearance of the progress bar are controlled via the following CSS styles:

To add a progress bar to a JSP page, add code similar to the following to the JSP:

In <head> section of the JSP page, add code similar to the following: <% if (progressBar != null) { %> <%= progressBar.getRefresh() %> <%= progressBar.getStyles () %> <% } %> Note: Invoking getStyles() is optional. The required styles (see above) may be contained in an external style sheet.

In <body> section of the JSP page, add code similar to the following: <% if (progressBar != null) { %> <%= progressBar //.toString() %> <% } %> This will invoke the toString() method of ProgressBar to create the required HTML.

Reference: JSP Progress Bars

Version:
1.0
Author:
Jay Damon

Field Summary
static int MAXIMUM_INCREMENT
          The maximum progress bar percentage complete increment.
static int MINIMUM_INCREMENT
          The minimum progress bar percentage complete increment.
 
Constructor Summary
ProgressBar()
          Constructs a new ProgressBar object.
 
Method Summary
 void addPercentComplete(int increment)
          Adds to (increments) the progress bar percentage complete for the task.
 String getCurrentActivity()
          Returns the current activity in progress for the task.
 String getCurrentStatus()
          Returns the current status for the activity in progress for the task.
 int getIncrement()
          Returns the progress bar percentage complete increment.
 int getPercentComplete()
          Returns the progress bar percentage complete for the task.
 String getRefresh()
          Returns the HTML meta tag that will automatically refresh, i.e.
 String getStyle()
          Returns the <div> CSS style for the progress bar.
 String getStyles()
          Returns the CSS styles for the progress bar.
 Object getTask()
          Returns a reference to the object controlling the task for this progress bar.
 boolean isComplete()
          Returns true if the progress bar is complete.
 void setColor(String barColor)
          Sets the progress bar color.
 void setCurrentActivity(String currentActivity)
          Sets the current activity in progress for the task.
 void setCurrentStatus(String currentStatus)
          Sets the current status for the activity in progress for the task.
 void setHeight(int height)
          Sets the height of the progress bar as a percentage or in pixels.
 void setIncrement(int progressIncrement)
          Sets the progress bar percentage complete increment.
 void setLeft(int left)
          Sets the position of the progress bar relative to the left-hand side of the page as a percentage or in pixels.
 void setPercentComplete(int percentComplete)
          Sets the progress bar percentage complete for the task.
 void setRefreshInterval(int refreshInterval)
          Sets the progress bar refresh interval (in seconds).
 void setRefreshURL(String refreshURL)
          Sets the Uniform Resource Locator (URL) to forward to in order to recalculate the progress of the task and refresh the progress bar.
 void setTask(Object taskObject)
          Sets the reference to the object controlling the task for this progress bar.
 void setTop(int top)
          Sets the position of the progress bar relative to the top of the page as a percentage or in pixels.
 void setWidth(int width)
          Sets the width of the progress bar as a percentage or in pixels.
 String toString()
          Returns the progress bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_INCREMENT

public static final int MINIMUM_INCREMENT
The minimum progress bar percentage complete increment. The minimum increment is 2 percent.

See Also:
Constant Field Values

MAXIMUM_INCREMENT

public static final int MAXIMUM_INCREMENT
The maximum progress bar percentage complete increment. The maximum increment is 5 percent.

See Also:
Constant Field Values
Constructor Detail

ProgressBar

public ProgressBar()
Constructs a new ProgressBar object.

Method Detail

addPercentComplete

public void addPercentComplete(int increment)
Adds to (increments) the progress bar percentage complete for the task.


getCurrentActivity

public String getCurrentActivity()
Returns the current activity in progress for the task.

Returns:
The current activity in progress for the task.

getCurrentStatus

public String getCurrentStatus()
Returns the current status for the activity in progress for the task.

Returns:
The current status for the activity in progress for the task.

getIncrement

public int getIncrement()
Returns the progress bar percentage complete increment.

Returns:
The progress bar percentage complete increment.

getPercentComplete

public int getPercentComplete()
Returns the progress bar percentage complete for the task.

Returns:
The progress bar percentage complete.

getRefresh

public String getRefresh()
Returns the HTML meta tag that will automatically refresh, i.e. reload, the page from the specified URL after the specified refresh interval.

Returns:
The HTML meta tag that will refresh the page.

getStyle

public String getStyle()
Returns the <div> CSS style for the progress bar.

Returns:
The <div> CSS style for the progress bar.

getStyles

public String getStyles()
Returns the CSS styles for the progress bar.

Returns:
The CSS styles for the progress bar.

getTask

public Object getTask()
Returns a reference to the object controlling the task for this progress bar.

Returns:
A reference to the object controlling the task for this progress bar.

isComplete

public boolean isComplete()
Returns true if the progress bar is complete.

Returns:
True if the progress bar is complete. False if the progress bar is not complete.

setColor

public void setColor(String barColor)
Sets the progress bar color.


setCurrentActivity

public void setCurrentActivity(String currentActivity)
Sets the current activity in progress for the task.

Returns:
The current activity in progress for the task.

setCurrentStatus

public void setCurrentStatus(String currentStatus)
Sets the current status for the activity in progress for the task.

Returns:
The current status for the activity in progress for the task.

setHeight

public void setHeight(int height)
Sets the height of the progress bar as a percentage or in pixels.


setIncrement

public void setIncrement(int progressIncrement)
Sets the progress bar percentage complete increment. The percentage complete increment may not exceed the minimum (2%) or maximum (5%) increment.


setLeft

public void setLeft(int left)
Sets the position of the progress bar relative to the left-hand side of the page as a percentage or in pixels.


setPercentComplete

public void setPercentComplete(int percentComplete)
Sets the progress bar percentage complete for the task. The percentage complete may not exceed the minimum (0%) or maximum (100%) percentage complete.


setRefreshInterval

public void setRefreshInterval(int refreshInterval)
Sets the progress bar refresh interval (in seconds). The recommended refresh interval is at least 2 seconds (for a smoother refresh of the display page).


setRefreshURL

public void setRefreshURL(String refreshURL)
Sets the Uniform Resource Locator (URL) to forward to in order to recalculate the progress of the task and refresh the progress bar.


setTask

public void setTask(Object taskObject)
Sets the reference to the object controlling the task for this progress bar. Typically, the task object manages one or more threads performing subtask(s) in the background.


setTop

public void setTop(int top)
Sets the position of the progress bar relative to the top of the page as a percentage or in pixels.


setWidth

public void setWidth(int width)
Sets the width of the progress bar as a percentage or in pixels.


toString

public String toString()
Returns the progress bar.

Overrides:
toString in class Object
Returns:
The progress bar.

2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.