001: package com.technoetic.xplanner.tags;
002:
003: import javax.servlet.jsp.JspException;
004: import javax.servlet.jsp.tagext.TagSupport;
005: import java.io.IOException;
006:
007: public class ProgressBarHtmlTag extends TagSupport implements
008: ProgressBarTag {
009: private static final String UNCOMPLETED_COLOR = "#0000FF";
010: private static final String COMPLETED_COLOR = "#00FF00";
011: private static final String EXCEEDED_COLOR = "#FF0000";
012: private static final String UNWORKED_COLOR = "#C0C0C0";
013:
014: private double actual;
015: private double estimate;
016: private boolean complete = false;
017: private int width;
018: private int height;
019:
020: public void setActual(double actual) {
021: this .actual = actual;
022: }
023:
024: public void setEstimate(double estimate) {
025: this .estimate = estimate;
026: }
027:
028: public void setComplete(boolean complete) {
029: this .complete = complete;
030: }
031:
032: public void setWidth(int width) {
033: this .width = width;
034: }
035:
036: public void setHeight(int height) {
037: this .height = height;
038: }
039:
040: public int doEndTag() throws JspException {
041: try {
042: double total = Math.max(actual, estimate);
043: int workedPercent = 0;
044: if (total == 0.0) {
045: workedPercent = complete ? 100 : 0;
046: } else {
047: workedPercent = (int) (Math.round(Math.min(actual,
048: estimate)
049: / total * 100));
050: }
051: int unworkedPercent = 100 - workedPercent;
052:
053: pageContext
054: .getOut()
055: .println(
056: "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\"");
057: pageContext.getOut().println(" class=\"progressbar\"");
058: if (width > 0) {
059: pageContext.getOut()
060: .println(" width=\"" + width + "\"");
061: }
062: if (height > 0) {
063: pageContext.getOut().println(
064: " height=\"" + height + "\"");
065: }
066: pageContext.getOut().println(">");
067: pageContext.getOut().println("<tr>");
068: if (workedPercent > 0) {
069: pageContext.getOut().println(
070: "<td width=\"" + workedPercent + "%\"");
071: pageContext.getOut().println(
072: " class=\""
073: + (complete ? "progressbar_completed"
074: : "progressbar_uncompleted")
075: + "\" ");
076: pageContext.getOut().println(
077: " bgcolor=\""
078: + (complete ? COMPLETED_COLOR
079: : UNCOMPLETED_COLOR) + "\"");
080: pageContext.getOut().println("> </td>");
081: }
082: if (unworkedPercent > 0) {
083: pageContext.getOut().println(
084: "<td width=\"" + unworkedPercent + "%\"");
085: pageContext
086: .getOut()
087: .println(
088: " class=\""
089: + (actual > estimate ? "progressbar_exceeded"
090: : "progressbar_unworked")
091: + "\" ");
092: pageContext.getOut().println(
093: " bgcolor=\""
094: + (actual > estimate ? EXCEEDED_COLOR
095: : UNWORKED_COLOR) + "\"");
096: pageContext.getOut().println("> </td>");
097: }
098: pageContext.getOut().println("</tr>");
099: pageContext.getOut().println("</table>");
100:
101: } catch (IOException ex) {
102: throw new JspException("Caught IOException: "
103: + ex.getMessage());
104: } catch (NumberFormatException ex) {
105: throw new JspException("Caught NumberFormatException: "
106: + ex.getMessage());
107: }
108: return EVAL_PAGE;
109: }
110: }
|