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.wrapping.swing;
19:
20: import javax.swing.*;
21:
22: import net.ar.webonswing.*;
23: import net.ar.webonswing.helpers.*;
24: import net.ar.webonswing.ui.*;
25: import net.ar.webonswing.walkers.*;
26: import net.ar.webonswing.wrapping.*;
27:
28: public class SwingHierarchyWrapper extends HierarchyWrapper {
29: protected ComponentWrapper createComponentWrapper(Object aComponent) {
30: return new SwingComponentWrapper((JComponent) aComponent);
31: }
32:
33: public VisitableContainer getContainerVisitable(Object aComponent) {
34: JComponent theJComponent = (JComponent) aComponent;
35: VisitableContainer theContainerVisitable = getContainerVisitableForJComponent(theJComponent);
36: theContainerVisitable.setComponent(theJComponent);
37: return theContainerVisitable;
38: }
39:
40: protected VisitableContainer getContainerVisitableOfVisualComponent(
41: VisualComponent aComponent) {
42: JComponent theJComponent = (JComponent) ((ComponentWrapper) aComponent)
43: .getWrappedComponent();
44: VisitableContainer theContainerVisitable = getContainerVisitableForJComponent(theJComponent);
45: theContainerVisitable.setComponent(theJComponent);
46: return theContainerVisitable;
47: }
48:
49: public boolean isWrapped(Object theComponent) {
50: return ((JComponent) theComponent)
51: .getClientProperty(COMPONENT_PROPERTY) != null;
52: }
53:
54: protected Object getUnwrappedRootComponent(VisualWindow aWindow) {
55: return ((RootPaneContainer) ((ComponentWrapper) aWindow)
56: .getWrappedComponent()).getRootPane();
57: }
58:
59: public WindowWrapper wrapWindow(Object aWindow) {
60: return new SwingWindowWrapper(aWindow);
61: }
62:
63: protected VisitableContainer getContainerVisitableForJComponent(
64: JComponent aComponent) {
65: ComponentUIContributor theContributor;
66:
67: theContributor = ((ComponentUIContributor) WosHelper
68: .createClassInstance(WosFramework.getInstance()
69: .getContributorManager()
70: .getDefaultComponentContributorClassName(
71: aComponent.getUIClassID())));
72:
73: return theContributor.getContainerVisitable();
74: }
75:
76: public void setComponentWrapper(Object aComponent,
77: ComponentWrapper aWrapper) {
78: ((JComponent) aComponent).putClientProperty(COMPONENT_PROPERTY,
79: aWrapper);
80: }
81:
82: public ComponentWrapper getComponentWrapper(Object component) {
83: if (!WosFramework.isActive())
84: return new SwingComponentWrapper((JComponent) component);
85:
86: Object theWrapper = ((JComponent) component)
87: .getClientProperty(COMPONENT_PROPERTY);
88:
89: if (theWrapper != null)
90: return (ComponentWrapper) theWrapper;
91: else
92: throw new WebOnSwingException(
93: "No asocciated component for: " + component);
94: }
95: }
|