KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > ProgressBarCG


1 /*
2  * $Id: ProgressBarCG.java,v 1.19 2005/06/07 12:55:59 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16
17 import org.wings.*;
18 import org.wings.io.Device;
19 import org.wings.plaf.CGManager;
20 import org.wings.session.SessionManager;
21
22 import java.io.IOException JavaDoc;
23
24 public class ProgressBarCG extends AbstractComponentCG implements
25         org.wings.plaf.ProgressBarCG {
26
27 // --- byte array converted template snippets.
28

29     public void installCG(final SComponent comp) {
30         super.installCG(comp);
31         final SProgressBar component = (SProgressBar) comp;
32         final CGManager manager = component.getSession().getCGManager();
33         Object JavaDoc value;
34         Object JavaDoc previous;
35         value = manager.getObject("SProgressBar.borderColor", java.awt.Color JavaDoc.class);
36         if (value != null) {
37             component.setBorderColor((java.awt.Color JavaDoc) value);
38         }
39         value = manager.getObject("SProgressBar.filledColor", java.awt.Color JavaDoc.class);
40         if (value != null) {
41             component.setFilledColor((java.awt.Color JavaDoc) value);
42         }
43         value = manager.getObject("SProgressBar.foreground", java.awt.Color JavaDoc.class);
44         if (value != null) {
45             component.setForeground((java.awt.Color JavaDoc) value);
46         }
47         value = manager.getObject("SProgressBar.preferredSize", SDimension.class);
48         if (value != null) {
49             component.setPreferredSize((SDimension) value);
50         }
51         value = manager.getObject("SProgressBar.unfilledColor", java.awt.Color JavaDoc.class);
52         if (value != null) {
53             component.setUnfilledColor((java.awt.Color JavaDoc) value);
54         }
55     }
56
57     public void uninstallCG(final SComponent comp) {
58     }
59
60 //--- code from common area in template.
61
private static final SIcon BLIND_ICON = (SIcon) SessionManager.getSession()
62     .getCGManager().getObject("ProgressBarCG.blindIcon", SIcon.class);
63
64 //--- end code from common area in template.
65

66
67     public void writeContent(final Device device,
68                              final SComponent _c)
69             throws IOException JavaDoc {
70         final SProgressBar component = (SProgressBar) _c;
71
72 //--- code from write-template.
73
String JavaDoc style = component.getStyle();
74
75         /* FIXME: The problem here is that the component size is used as the
76          * size for the progressbar. If text is rendered below
77          * (isStringPainted), then that text is out of the component box. So
78          * either create a distinct ProgressBar size or subtract some height.
79          * OL: created distinct height. other solution is removing string
80          * completely.
81          */

82         
83         SDimension size = component.getProgressBarDimension();
84         int width = size != null ? size.getIntWidth() : 200;
85         int height = size != null ? size.getIntHeight() : 5;
86
87         if (component.isBorderPainted()) {
88             device.print("<div style=\"width: 100%;height:100%;border: 1px solid ");
89             Utils.write(device, component.getBorderColor());
90             device.print(";\">");
91             width -= 2; //compensate for border
92
height -= 2;
93         }
94
95         device.print("<table class=\"SLayout\"><tr><td class=\"SLayout\"");
96         if (component.getFilledColor() != null) {
97             device.print(" style=\"background-color: ");
98             Utils.write(device, component.getFilledColor());
99             device.print(";\"");
100         }
101         device.print(">");
102         final String JavaDoc completeWidth = String.valueOf(Math.round(width * component.getPercentComplete()));
103         device.print("<img");
104         Utils.optAttribute(device, "src", BLIND_ICON.getURL());
105         Utils.optAttribute(device, "width", completeWidth);
106         Utils.optAttribute(device, "height", String.valueOf(height));
107         device.print(" alt=\"");
108         device.print(BLIND_ICON.getIconTitle());
109         device.print("\"/>");
110         device.print("</td>");
111         device.print("<td class=\"SLayout\"");
112         if (component.getUnfilledColor() != null) {
113             device.print(" style=\"background-color: ");
114             Utils.write(device, component.getUnfilledColor());
115            device.print(";\"");
116         }
117         device.print(">");
118         final String JavaDoc incompleteWidth = String.valueOf(Math.round(width * (1 - component.getPercentComplete())));
119         device.print("<img");
120         Utils.optAttribute(device, "src", BLIND_ICON.getURL());
121         Utils.optAttribute(device, "width", incompleteWidth);
122         Utils.optAttribute(device, "height", String.valueOf(height));
123         device.print(" alt=\"");
124         device.print(BLIND_ICON.getIconTitle());
125         device.print("\"/>");
126         device.print("</td></tr></table>");
127         if (component.isBorderPainted()) {
128             device.print("</div>");
129         }
130
131         if (component.isStringPainted()) {
132             device.print("<div style=\"width: 100%; text-align: center;\"");
133             if (style != null) {
134                 device.print(" class=\"");
135                 Utils.write(device, style);
136                 device.print("_string\"");
137             }
138             device.print(">");
139             Utils.write(device, component.getString());
140             device.print("</div>");
141         }
142 //--- end code from write-template.
143
}
144 }
145
Popular Tags