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 javax.swing.*;
24:
25: import net.ar.webonswing.helpers.*;
26: import net.ar.webonswing.remote.*;
27: import net.ar.webonswing.render.markup.*;
28: import net.ar.webonswing.render.templates.*;
29: import net.ar.webonswing.render.templates.html.*;
30: import net.ar.webonswing.wrapping.*;
31:
32: public class ButtonUIContributor extends
33: AbstractSwingComponentUIContributor {
34: public void doRenderingContribution(
35: RenderingContributionContainer theContribManager) {
36: JButton aButton = (JButton) getJComponent();
37:
38: Tag theTag = new Tag("input");
39: theTag.setNeedsClosure(false);
40:
41: theTag.addAttribute(new TagAttribute("type", "button"));
42: theTag.addAttribute(new TagAttribute("name", theComponent
43: .getName()));
44: theTag
45: .addAttribute(new TagAttribute("value", aButton
46: .getText()));
47:
48: if (aButton.getWidth() != 0 || aButton.getHeight() != 0) {
49: TagStyleAttribute theStyle = new TagStyleAttribute();
50:
51: theStyle.addElement("position", "relative");
52: if (aButton.getWidth() != 0)
53: theStyle.addElement("width", aButton.getWidth());
54: if (aButton.getHeight() != 0)
55: theStyle.addElement("height", aButton.getHeight());
56:
57: theTag.addAttribute(theStyle);
58: }
59:
60: if (aButton.getListeners(ActionListener.class).length > 0)
61: theTag.addAttribute(new TagAttribute("onclick",
62: "ed.dispatch(new ActionEvent(this.name, '"
63: + RemoteHelper.escapeSingleQuotes(aButton
64: .getActionCommand())
65: + "')); return false;"));
66:
67: if (!aButton.isEnabled())
68: theTag.addAttribute(new TagAttribute("DISABLED", ""));
69:
70: Template theTemplate = WosSwingHelper.getTemplateForComponent(
71: "JButton", aButton);
72:
73: theTemplate.addElement(new IdTagTemplateElement("theButton",
74: theTag, theTag));
75:
76: theContribManager.doContribution(theComponent, theTemplate,
77: theTag, RemoteHelper.getListenersAdds(theComponent));
78: }
79:
80: public void dispatchEvents(List anEvents) {
81: for (Iterator i = anEvents.iterator(); i.hasNext();) {
82: RemoteEvent theEvent = (RemoteEvent) i.next();
83: JButton theButton = (JButton) ((ComponentWrapper) theEvent
84: .getSource()).getWrappedComponent();
85:
86: if (theEvent.getType().equals("actionPerformed"))
87: theButton.doClick();
88: }
89: }
90: }
|