01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.plaf.css;
14:
15: import org.wings.SComponent;
16: import org.wings.SDimension;
17: import org.wings.SProgressBar;
18: import org.wings.io.Device;
19: import org.wings.plaf.CGManager;
20: import java.io.IOException;
21:
22: public final class ProgressBarCG extends AbstractComponentCG implements
23: org.wings.plaf.ProgressBarCG {
24:
25: private static final long serialVersionUID = 1L;
26:
27: public void installCG(final SComponent comp) {
28: super .installCG(comp);
29: final SProgressBar component = (SProgressBar) comp;
30: final CGManager manager = component.getSession().getCGManager();
31: Object value = manager.getObject("SProgressBar.filledColor",
32: java.awt.Color.class);
33: if (value != null) {
34: component.setFilledColor((java.awt.Color) value);
35: }
36: value = manager.getObject("SProgressBar.foreground",
37: java.awt.Color.class);
38: if (value != null) {
39: component.setForeground((java.awt.Color) value);
40: }
41: value = manager.getObject("SProgressBar.preferredSize",
42: SDimension.class);
43: if (value != null) {
44: component.setPreferredSize((SDimension) value);
45: }
46: value = manager.getObject("SProgressBar.unfilledColor",
47: java.awt.Color.class);
48: if (value != null) {
49: component.setUnfilledColor((java.awt.Color) value);
50: }
51: }
52:
53: public void writeInternal(final Device device,
54: final SComponent pComp) throws IOException {
55: final SProgressBar component = (SProgressBar) pComp;
56:
57: final SDimension size = component.getProgressBarDimension();
58: int height = size != null ? size.getHeightInt() : 10;
59:
60: device.print("<table");
61: Utils.writeAllAttributes(device, component);
62: device.print("><tr class=\"bar\"");
63: Utils.optAttribute(device, "height", height);
64: device.print(">");
65:
66: final int filledWidth = (int) Math.round(100 * component
67: .getPercentComplete());
68: if (filledWidth > 0) {
69: device.print("<td");
70: Utils.optAttribute(device, "width", filledWidth + "%");
71: Utils.optAttribute(device, "bgcolor", component
72: .getFilledColor());
73: device.print("></td>");
74: }
75:
76: final int unfilledWidth = 100 - filledWidth;
77: if (unfilledWidth > 0) {
78: device.print("<td");
79: Utils.optAttribute(device, "width", unfilledWidth + "%");
80: Utils.optAttribute(device, "bgcolor", component
81: .getUnfilledColor());
82: device.print("></td>");
83: }
84:
85: device.print("</tr>");
86:
87: if (component.isStringPainted()) {
88: if (filledWidth != 0 && unfilledWidth != 0)
89: device.print("<tr class=\"text\"><td colspan=\"2\">");
90: else
91: device.print("<tr class=\"text\"><td>");
92:
93: Utils.write(device, component.getString());
94: device.print("</td></tr>");
95: }
96: device.print("</table>");
97: }
98: }
|