01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2003 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 java.awt.*;
21:
22: import javax.swing.*;
23:
24: import net.ar.webonswing.*;
25: import net.ar.webonswing.render.*;
26: import net.ar.webonswing.render.markup.*;
27: import net.ar.webonswing.render.templates.*;
28: import net.ar.webonswing.render.templates.html.*;
29: import net.ar.webonswing.swing.layouts.*;
30: import net.ar.webonswing.wrapping.*;
31:
32: public class ViewPortUIContributor extends
33: AbstractSwingComponentUIContributor {
34: public void doRenderingContribution(
35: RenderingContributionContainer theContribManager) {
36: JViewport aViewPort = (JViewport) getJComponent();
37:
38: Template theTemplate = aViewPort.getLayout() instanceof TemplateLayout ? ((TemplateLayout) aViewPort
39: .getLayout()).getTemplate()
40: : new HtmlDivsTemplate();
41: StringBuffer theScript = new StringBuffer();
42:
43: Tag theTag = new Tag("div");
44: theTag.setNeedsClosure(true);
45: theTag.addAttribute(new TagAttribute("name", theComponent
46: .getName()));
47: theTag.addAttribute("scrollleft", "0");
48: theTag.addAttribute("scrolltop", "0");
49: theTag.addAttribute("scrollbottom", "0");
50: TagStyleAttribute theStyle = new TagStyleAttribute();
51: theStyle.addElement("position", "relative");
52:
53: theStyle.addElement("width", aViewPort.getWidth());
54: theStyle.addElement("height", aViewPort.getHeight());
55:
56: theStyle.addElement("border", "0px solid");
57: theStyle.addElement("overflow", "auto");
58: theTag.addAttribute(theStyle);
59:
60: Component[] theComponents = aViewPort.getComponents();
61: for (int i = 0; i < theComponents.length; i++) {
62: Container theSubContainer = (Container) theComponents[i];
63:
64: if (theSubContainer.isVisible()
65: || theSubContainer instanceof JPanel) {
66: VisualComponent theChildComponent = WosFramework
67: .getInstance().getHierarchyWrapper()
68: .getComponentWrapper(theSubContainer);
69:
70: theTemplate.addElement(new IdTagTemplateElement(
71: theChildComponent, theContribManager
72: .getContainerRenderer().render(
73: theChildComponent),
74: theContribManager
75: .getComponentIdTag(theChildComponent)));
76: theScript.append(theContribManager
77: .getComponentInitScripts(theChildComponent)[0]);
78: }
79: }
80:
81: theTag.addTextToContainer(new ContentRenderer(theTemplate)
82: .getResult());
83:
84: theContribManager.doContribution(theComponent, theTag, theTag,
85: theScript.toString());
86: }
87: }
|