1 package org.informagen.echo.webcontainer;
2
3 import org.informagen.echo.app.ButtonWheel;
4 import org.informagen.echo.app.ScrollWheel;
5
6 import nextapp.echo.app.Component;
7 import nextapp.echo.app.FillImage;
8
9 import nextapp.echo.webcontainer.sync.component.AbstractButtonPeer;
10
11
12 import nextapp.echo.app.update.ClientUpdateManager;
13 import nextapp.echo.app.util.Context;
14
15 import nextapp.echo.webcontainer.AbstractComponentSynchronizePeer;
16 import nextapp.echo.webcontainer.ContentType;
17 import nextapp.echo.webcontainer.ServerMessage;
18 import nextapp.echo.webcontainer.ResourceRegistry;
19 import nextapp.echo.webcontainer.Service;
20 import nextapp.echo.webcontainer.WebContainerServlet;
21 import nextapp.echo.webcontainer.service.JavaScriptService;
22
23 public class ButtonWheelPeer extends AbstractComponentSynchronizePeer {
24
25 private static final String REGISTRY_KEY = "Informagen.ButtonWheel";
26 private static final String JAVASCRIPT_PATH = "org/informagen/echo/resource/ButtonWheel.js";
27 private static final String SCROLLER_MODEL_JAVASCRIPT_PATH = "org/informagen/echo/resource/ScrollerModel.js";
28
29 static {
30 String[] javaScriptPaths = new String[] { JAVASCRIPT_PATH, SCROLLER_MODEL_JAVASCRIPT_PATH };
31 Service service = JavaScriptService.forResources(REGISTRY_KEY, javaScriptPaths);
32 WebContainerServlet.getServiceRegistry().add(service);
33
34
35 ResourceRegistry resources = WebContainerServlet.getResourceRegistry();
36 resources.addPackage("Informagen", "org/informagen/echo/resource/");
37 resources.add("Informagen", "image/buttonWheel.gif", ContentType.IMAGE_GIF);
38 }
39
40 public ButtonWheelPeer() {
41 super();
42
43
44 addOutputProperty(ButtonWheel.PROPERTY_DIAMETER);
45 addOutputProperty(ButtonWheel.PROPERTY_MINIMUM);
46 addOutputProperty(ButtonWheel.PROPERTY_MAXIMUM);
47 addOutputProperty(ButtonWheel.PROPERTY_VALUE);
48
49 addOutputProperty(ScrollWheel.PROPERTY_SENSITIVITY);
50
51
52 addEvent(new AbstractComponentSynchronizePeer.EventPeer("action", ButtonWheel.PROPERTY_ACTION_LISTENERS_CHANGED) {
53 public boolean hasListeners(Context context, Component component) {
54 return true;
55 }
56 });
57
58 }
59
60
61
62 public void init(Context context, Component component) {
63 super.init(context, component);
64 ServerMessage serverMessage = (ServerMessage) context.get(ServerMessage.class);
65 serverMessage.addLibrary(REGISTRY_KEY);
66 }
67
68
69
70
71 public String getClientComponentType(boolean shortType) {
72 return REGISTRY_KEY;
73 }
74
75 public Class getComponentClass() {
76 return ButtonWheel.class;
77 }
78
79
80
81
82
83
84 public Object getOutputProperty(Context context, Component component, String propertyName, int propertyIndex) {
85
86 if (ButtonWheel.PROPERTY_DIAMETER.equals(propertyName))
87 return new Integer(((ButtonWheel)component).getDiameter());
88 else if (ButtonWheel.PROPERTY_MAXIMUM.equals(propertyName))
89 return new Integer(((ButtonWheel)component).getMaximum());
90 else if (ButtonWheel.PROPERTY_MINIMUM.equals(propertyName))
91 return new Integer(((ButtonWheel)component).getMinimum());
92 else if (ButtonWheel.PROPERTY_VALUE.equals(propertyName))
93 return new Integer(((ButtonWheel)component).getValue());
94
95
96 else if (ScrollWheel.PROPERTY_SENSITIVITY.equals(propertyName))
97 return new Integer(((ButtonWheel)component).getSensitivity());
98
99
100 return super.getOutputProperty(context, component, propertyName, propertyIndex);
101 }
102
103
104
105
106
107
108
109
110
111
112
113 public Class getInputPropertyClass(String propertyName) {
114
115 if (ScrollWheel.PROPERTY_ACTION_COMMAND_CHANGED.equals(propertyName))
116 return String.class;
117 else if (ScrollWheel.PROPERTY_VALUE.equals(propertyName))
118 return Integer.class;
119
120 return super.getInputPropertyClass(propertyName);
121 }
122
123
124 public void storeInputProperty(Context context, Component component,
125 String propertyName, int propertyIndex, Object newValue) {
126
127 ClientUpdateManager clientUpdateManager = (ClientUpdateManager) context.get(ClientUpdateManager.class);
128
129 if (ScrollWheel.PROPERTY_ACTION_COMMAND_CHANGED.equals(propertyName))
130 clientUpdateManager.setComponentProperty(component, ScrollWheel.PROPERTY_ACTION_COMMAND_CHANGED, newValue);
131 else if (ScrollWheel.PROPERTY_VALUE.equals(propertyName))
132 clientUpdateManager.setComponentProperty(component, ScrollWheel.PROPERTY_VALUE, newValue);
133 }
134
135
136
137 }