001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package jsx3.chart;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * Class encapsulating behavior shared by PointSeries and BubbleSeries
024: * @author Joe Walker [joe at getahead dot org]
025: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
026: */
027: public class PlotSeries extends jsx3.chart.Series {
028: /**
029: * All reverse ajax proxies need context to work from
030: * @param scriptProxy The place we are writing scripts to
031: * @param context The script that got us to where we are now
032: */
033: public PlotSeries(Context context, String extension,
034: ScriptProxy scriptProxy) {
035: super (context, extension, scriptProxy);
036: }
037:
038: /**
039: * The instance initializer.
040: * @param name the GI name of the instance
041: * @param seriesName the name of the Series, will be displayed in the Legend for most chart types
042: */
043: public PlotSeries(String name, String seriesName) {
044: super ((Context) null, (String) null, (ScriptProxy) null);
045: ScriptBuffer script = new ScriptBuffer();
046: script.appendCall("new PlotSeries", name, seriesName);
047: setInitScript(script);
048: }
049:
050: /**
051: * Returns the x-coordinate of a data point in this series for the given record.
052: * @param record the <record/> node
053: */
054: @SuppressWarnings("unchecked")
055: public void getXValue(jsx3.xml.Node record,
056: org.directwebremoting.proxy.Callback<Integer> callback) {
057: ScriptBuffer script = new ScriptBuffer();
058: String callbackPrefix = "";
059:
060: if (callback != null) {
061: callbackPrefix = "var reply = ";
062: }
063:
064: script.appendCall(callbackPrefix + getContextPath()
065: + "getXValue", record);
066:
067: if (callback != null) {
068: String key = org.directwebremoting.extend.CallbackHelper
069: .saveCallback(callback, Integer.class);
070: script
071: .appendCall("__System.activateCallback", key,
072: "reply");
073: }
074:
075: getScriptProxy().addScript(script);
076: }
077:
078: /**
079: * Returns the y-coordinate of a data point in this series for the given record.
080: * @param record the <record/> node
081: */
082: @SuppressWarnings("unchecked")
083: public void getYValue(jsx3.xml.Node record,
084: org.directwebremoting.proxy.Callback<Integer> callback) {
085: ScriptBuffer script = new ScriptBuffer();
086: String callbackPrefix = "";
087:
088: if (callback != null) {
089: callbackPrefix = "var reply = ";
090: }
091:
092: script.appendCall(callbackPrefix + getContextPath()
093: + "getYValue", record);
094:
095: if (callback != null) {
096: String key = org.directwebremoting.extend.CallbackHelper
097: .saveCallback(callback, Integer.class);
098: script
099: .appendCall("__System.activateCallback", key,
100: "reply");
101: }
102:
103: getScriptProxy().addScript(script);
104: }
105:
106: /**
107: * Returns the xField field.
108: * @param callback xField
109: */
110: @SuppressWarnings("unchecked")
111: public void getXField(
112: org.directwebremoting.proxy.Callback<String> callback) {
113: ScriptBuffer script = new ScriptBuffer();
114: String callbackPrefix = "";
115:
116: if (callback != null) {
117: callbackPrefix = "var reply = ";
118: }
119:
120: script.appendCall(callbackPrefix + getContextPath()
121: + "getXField");
122:
123: if (callback != null) {
124: String key = org.directwebremoting.extend.CallbackHelper
125: .saveCallback(callback, String.class);
126: script
127: .appendCall("__System.activateCallback", key,
128: "reply");
129: }
130:
131: getScriptProxy().addScript(script);
132: }
133:
134: /**
135: * Sets the xField field.
136: * @param xField the new value for xField
137: */
138: public void setXField(String xField) {
139: ScriptBuffer script = new ScriptBuffer();
140: script.appendCall(getContextPath() + "setXField", xField);
141: getScriptProxy().addScript(script);
142: }
143:
144: /**
145: * Returns the yField field.
146: * @param callback yField
147: */
148: @SuppressWarnings("unchecked")
149: public void getYField(
150: org.directwebremoting.proxy.Callback<String> callback) {
151: ScriptBuffer script = new ScriptBuffer();
152: String callbackPrefix = "";
153:
154: if (callback != null) {
155: callbackPrefix = "var reply = ";
156: }
157:
158: script.appendCall(callbackPrefix + getContextPath()
159: + "getYField");
160:
161: if (callback != null) {
162: String key = org.directwebremoting.extend.CallbackHelper
163: .saveCallback(callback, String.class);
164: script
165: .appendCall("__System.activateCallback", key,
166: "reply");
167: }
168:
169: getScriptProxy().addScript(script);
170: }
171:
172: /**
173: * Sets the yField field.
174: * @param yField the new value for yField
175: */
176: public void setYField(String yField) {
177: ScriptBuffer script = new ScriptBuffer();
178: script.appendCall(getContextPath() + "setYField", yField);
179: getScriptProxy().addScript(script);
180: }
181:
182: /**
183: * Returns the renderer field.
184: * @return renderer
185: */
186: @SuppressWarnings("unchecked")
187: public jsx3.chart.PointRenderer getRenderer() {
188: String extension = "getRenderer().";
189: try {
190: java.lang.reflect.Constructor<jsx3.chart.PointRenderer> ctor = jsx3.chart.PointRenderer.class
191: .getConstructor(Context.class, String.class,
192: ScriptProxy.class);
193: return ctor.newInstance(this , extension, getScriptProxy());
194: } catch (Exception ex) {
195: throw new IllegalArgumentException("Unsupported type: "
196: + jsx3.chart.PointRenderer.class.getName());
197: }
198: }
199:
200: /**
201: * Sets the renderer field.
202: * @param renderer the new value for renderer
203: */
204: public void setRenderer(String renderer) {
205: ScriptBuffer script = new ScriptBuffer();
206: script.appendCall(getContextPath() + "setRenderer", renderer);
207: getScriptProxy().addScript(script);
208: }
209:
210: /**
211: * Returns the renderer used for the legend.
212: * @return the same renderer as used to draw the points
213: */
214: @SuppressWarnings("unchecked")
215: public jsx3.chart.PointRenderer getLegendRenderer() {
216: String extension = "getLegendRenderer().";
217: try {
218: java.lang.reflect.Constructor<jsx3.chart.PointRenderer> ctor = jsx3.chart.PointRenderer.class
219: .getConstructor(Context.class, String.class,
220: ScriptProxy.class);
221: return ctor.newInstance(this , extension, getScriptProxy());
222: } catch (Exception ex) {
223: throw new IllegalArgumentException("Unsupported type: "
224: + jsx3.chart.PointRenderer.class.getName());
225: }
226: }
227:
228: }
|