001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2004 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.ui;
019:
020: import java.util.*;
021:
022: import javax.swing.*;
023:
024: import net.ar.webonswing.*;
025: import net.ar.webonswing.managers.script.*;
026: import net.ar.webonswing.remote.*;
027: import net.ar.webonswing.remote.js.*;
028: import net.ar.webonswing.render.markup.*;
029: import net.ar.webonswing.wrapping.*;
030:
031: public class SpinnerUIContributor extends
032: AbstractSwingComponentUIContributor {
033: public void doRenderingContribution(
034: RenderingContributionContainer aRenderingContribManager) {
035: JSpinner spinner = (JSpinner) getJComponent();
036:
037: Tag script = new Tag("script");
038:
039: JsBuilder jsBuilder = new JsBuilder();
040: jsBuilder.add(new GenericJsStatement(
041: "var mergeTag= document.getElementById('" + getName()
042: + ".merge');"));
043: jsBuilder.add(new JsInstance(getName(), new JsConstructorCall(
044: "Spinner", new JsStatement[] {
045: new ValuesFromGetters(spinner, new String[] {
046: "width", "height", "value" }),
047: new ValuesFromGetters(spinner.getModel(),
048: new String[] { "minimum", "maximum" }),
049: new StringValue(getName()) }, false)));
050: //jsBuilder.add(new JsInstance(getName(), new JsConstructorCall("Spinner", new JsStatement[] { new GenericJsStatement("mergeTag.offsetWidth"), new GenericJsStatement("mergeTag.offsetHeight") , new ValuesFromGetters(spinner, new String[] { "value" }), new ValuesFromGetters(spinner.getModel(), new String[] { "minimum", "maximum" }), new StringValue(getName()) }, false)));
051: jsBuilder.addDynApiComponentInit(getName());
052: script.addTextToContainer(jsBuilder.renderJs());
053:
054: Tag content = new Tag("div");
055: content.addAttribute("id", getName() + ".merge");
056: content.addElementToContainer(script);
057:
058: StringBuffer initScripts = new StringBuffer(RemoteHelper
059: .getListenersAdds(theComponent));
060:
061: aRenderingContribManager.doContribution(theComponent, content,
062: content, initScripts.toString());
063: }
064:
065: private String getName() {
066: JSpinner slider = (JSpinner) getJComponent();
067: return WosFramework.getInstance().getHierarchyWrapper()
068: .getComponentWrapper(slider).getName();
069: }
070:
071: public void dispatchEvents(List anEvents) {
072: for (Iterator i = anEvents.iterator(); i.hasNext();) {
073: RemoteEvent event = (RemoteEvent) i.next();
074:
075: if (event.getName().endsWith("input")) {
076: JSpinner spinner = (JSpinner) ((ComponentWrapper) event
077: .getSource()).getWrappedComponent();
078: spinner.setValue(new Integer((String) event
079: .getParameters()[0]));
080: }
081: }
082: }
083:
084: public void doScriptContribution(
085: ScriptContributionContainer aContributionManager) {
086: RemoteHelper.addDynApiInitCode(aContributionManager);
087:
088: aContributionManager
089: .addCodeOnce("dynapi.library.include('HTMLTextBox');");
090: aContributionManager
091: .addCodeOnce("dynapi.library.include('Button');");
092: aContributionManager
093: .addCodeOnce("dynapi.library.include('ButtonFlatStyle');");
094: aContributionManager
095: .addCodeOnce("dynapi.library.include('ButtonImageStyle');");
096:
097: aContributionManager
098: .addCodeOnce("dynapi.library.add('dynapi.widgets.Spinner','spinner.js','DynLayer');");
099: aContributionManager
100: .addCodeOnce("dynapi.library.include('Spinner');");
101: }
102: }
|