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.event.*;
21: import java.util.*;
22:
23: import net.ar.webonswing.*;
24: import net.ar.webonswing.helpers.*;
25: import net.ar.webonswing.pages.*;
26: import net.ar.webonswing.remote.*;
27: import net.ar.webonswing.render.markup.*;
28: import net.ar.webonswing.render.templates.html.*;
29: import net.ar.webonswing.swing.components.*;
30: import net.ar.webonswing.wrapping.*;
31:
32: public class LinkUIContributor extends
33: AbstractSwingComponentUIContributor {
34: public void doRenderingContribution(
35: RenderingContributionContainer theContribManager) {
36: JLink aLink = (JLink) getJComponent();
37:
38: String theUrl = aLink.getUrl();
39:
40: if (theUrl == null) {
41: String theWindowName = "";
42:
43: if (aLink.getRootPaneContainer() == null)
44: theWindowName = aLink.getRootPaneContainerClass()
45: .getName();
46: else
47: theWindowName = aLink.getRootPaneContainer().getClass()
48: .getName();
49:
50: theUrl = ((DefaultHtmlPage) WosFramework.getInstance()
51: .getPageManager().getPageForWindowName(
52: theWindowName)).getUrl();
53: }
54:
55: Tag theTag = new Tag("a");
56:
57: if (!theUrl.equals(""))
58: theTag.addAttribute(new TagAttribute("href", theUrl));
59: else
60: theTag.addAttribute(new TagAttribute("style",
61: "cursor: hand"));
62:
63: theTag.addAttribute(new TagAttribute("name", theComponent
64: .getName()));
65: theTag.getTheMarkupContainer().addElement(
66: new TagContent(aLink.getLabel()));
67:
68: RemoteHelper.addMouseListeners(aLink, theComponent.getName(),
69: theTag);
70:
71: if (aLink.getListeners(MouseMotionListener.class).length > 0)
72: theTag.addAttribute(new TagAttribute("onmouseover",
73: "ed.dispatch(new MouseMovedEvent(this.name));"));
74:
75: HtmlTemplate theTemplate = (HtmlTemplate) WosSwingHelper
76: .getTemplateForComponent("JLink", aLink);
77: HtmlTemplate theLinkTemplate = theTemplate
78: .getSubTemplate("theLink");
79: theLinkTemplate.setFoundTag(theTag);
80:
81: theContribManager.doContribution(theComponent, theTemplate,
82: theTag, RemoteHelper
83: .getComponentInitScript(theComponent));
84: }
85:
86: public void dispatchEvents(List anEvents) {
87: for (Iterator i = anEvents.iterator(); i.hasNext();) {
88: RemoteEvent theEvent = (RemoteEvent) i.next();
89: JLink theLabel = (JLink) ((ComponentWrapper) theEvent
90: .getSource()).getWrappedComponent();
91:
92: if (theEvent.getType().equals("mouseClicked"))
93: RemoteHelper.fireClickEvent(theLabel);
94: }
95: }
96: }
|