01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2004 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package net.ar.webonswing.ui;
19:
20: import javax.swing.*;
21:
22: import net.ar.webonswing.*;
23: import net.ar.webonswing.helpers.*;
24: import net.ar.webonswing.remote.*;
25: import net.ar.webonswing.render.markup.*;
26:
27: public class ProgressBarUIContributor extends
28: AbstractSwingComponentUIContributor {
29: public void doRenderingContribution(
30: RenderingContributionContainer aRenderingContribManager) {
31: JProgressBar aProgressBar = (JProgressBar) getJComponent();
32:
33: String name = WosFramework.getInstance().getHierarchyWrapper()
34: .getComponentWrapper(aProgressBar).getName();
35: int value = (aProgressBar.getValue() * 100 / aProgressBar
36: .getMaximum());
37: int width = aProgressBar.getWidth();
38: int height = aProgressBar.getHeight();
39:
40: TagStyleAttribute textStyleAttribute = new TagStyleAttribute();
41: textStyleAttribute.addElement("position", "absolute");
42: textStyleAttribute.addElement("width", width);
43: textStyleAttribute.addElement("height", height);
44:
45: Tag textTag = new Tag("div").addAttribute(textStyleAttribute)
46: .addAttribute("align", "center").addAttribute("valign",
47: "center").addTextToContainer(
48: aProgressBar.getString());
49:
50: TagStyleAttribute barStyleAttribute = new TagStyleAttribute();
51: barStyleAttribute.addElement("width", (aProgressBar
52: .getOrientation() == SwingConstants.HORIZONTAL ? value
53: : 100)
54: + "%");
55: barStyleAttribute.addElement("height", (aProgressBar
56: .getOrientation() == SwingConstants.VERTICAL ? value
57: : 100)
58: + "%");
59: barStyleAttribute.addElement("background-color", WosSwingHelper
60: .getHTMLColorString(aProgressBar.getForeground()));
61: barStyleAttribute.addElement("left", "0px");
62: barStyleAttribute.addElement("top", "0px");
63: barStyleAttribute.addElement("position", "absolute");
64:
65: Tag progressTag = new Tag("div").addAttribute(
66: new TagAttribute("name", name)).addAttribute(
67: barStyleAttribute);
68:
69: TagStyleAttribute style = new TagStyleAttribute();
70: style.addElement("width", width);
71: style.addElement("height", height);
72: style.addElement("border", "solid 1px #999999");
73: style.addElement("position", "relative");
74: if (aProgressBar.getX() != 0)
75: style.addElement("left", aProgressBar.getX());
76: if (aProgressBar.getY() != 0)
77: style.addElement("top", aProgressBar.getY());
78:
79: Tag theTag = new Tag("div").addAttribute(
80: new TagAttribute("name", name)).addAttribute(style);
81:
82: theTag.addElementToContainer(progressTag);
83: theTag.addElementToContainer(textTag);
84:
85: aRenderingContribManager.doContribution(theComponent, theTag,
86: theTag, RemoteHelper.getListenersAdds(theComponent));
87: }
88: }
|