001: package com.technoetic.xplanner.tags;
002:
003: import com.technoetic.xplanner.format.DecimalFormat;
004: import de.laures.cewolf.CewolfException;
005: import de.laures.cewolf.ChartImage;
006: import de.laures.cewolf.Configuration;
007: import de.laures.cewolf.Storage;
008: import de.laures.cewolf.storage.SerializableChartImage;
009: import de.laures.cewolf.taglib.tags.ChartImgTag;
010:
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.jsp.JspException;
013: import java.awt.*;
014:
015: public class ProgressBarImageTag extends ChartImgTag implements
016: ProgressBarTag {
017: private float quality = 0.75F;
018: private double actual;
019: private double estimate;
020: private boolean complete;
021:
022: public static final Color UNCOMPLETED_COLOR = new Color(0x80, 0x80,
023: 0xFF);
024: public static final Color COMPLETED_COLOR = new Color(0xA0, 0xFF,
025: 0xA0);
026: public static final Color EXCEEDED_COLOR = new Color(0xFF, 0xA0,
027: 0xA0);
028: public static final Color UNWORKED_COLOR = new Color(0xC0, 0xC0,
029: 0xC0);
030:
031: public int doStartTag() throws JspException {
032: setRenderer("/cewolf");
033: setChartid(getId());
034: Storage storage = Configuration.getInstance(
035: pageContext.getServletContext()).getStorage();
036: try {
037: this .sessionKey = storage.storeChartImage(getChartImage(),
038: pageContext);
039: } catch (CewolfException cwex) {
040: throw new JspException(cwex.getMessage());
041: }
042: return SKIP_BODY;
043: }
044:
045: private ChartImage getChartImage() throws CewolfException {
046: ProgressBarImage image = new ProgressBarImage(createModel());
047: return new SerializableChartImage(
048: new CewolfProgressBarChartImage(image));
049: }
050:
051: public void setActual(double actual) {
052: this .actual = actual;
053: }
054:
055: public void setEstimate(double estimate) {
056: this .estimate = estimate;
057: }
058:
059: public void setComplete(boolean complete) {
060: this .complete = complete;
061: }
062:
063: public void setHeight(int height) {
064: super .setHeight(13);
065: }
066:
067: public void setQuality(String quality) {
068: this .quality = Float.parseFloat(quality);
069: if ((this .quality < 0.0F) || (this .quality > 1.0F)) {
070: throw new IllegalArgumentException("quality \"" + quality
071: + "\" out of range");
072: }
073: }
074:
075: public String getQuality() {
076: return Float.toString(quality);
077: }
078:
079: private double getCaptionValue() {
080: return Math.min(actual, estimate);
081: }
082:
083: private boolean isComplete() {
084: return complete;
085: }
086:
087: public Color getForegroundColor() {
088: if (isComplete()) {
089: return PrintLinkTag.isInPrintMode(pageContext) ? Color.GRAY
090: : COMPLETED_COLOR;
091: } else {
092: return PrintLinkTag.isInPrintMode(pageContext) ? Color.DARK_GRAY
093: : UNCOMPLETED_COLOR;
094: }
095: }
096:
097: public Color getBackgroundColor() {
098:
099: if (actual > estimate) {
100: return PrintLinkTag.isInPrintMode(pageContext) ? Color.BLACK
101: : EXCEEDED_COLOR;
102: } else {
103: return UNWORKED_COLOR;
104: }
105: }
106:
107: public double getBarValue() {
108: if (actual == 0 && estimate == 0 && complete) {
109: return width;
110: }
111: return Math.min(actual, estimate);
112: }
113:
114: public double getMaxValue() {
115: if (actual == 0 && estimate == 0 && complete) {
116: return width;
117: }
118: return Math.max(actual, estimate);
119: }
120:
121: public ProgressBarImage.Model createModel() {
122: return new ProgressBarImage.Model(width, height, getBarValue(),
123: getForegroundColor(), getMaxValue(),
124: getBackgroundColor(), new DecimalFormat(
125: (HttpServletRequest) pageContext.getRequest()),
126: getCaptionValue());
127: }
128:
129: }
|