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: * The base class for all data series classes. In general, a chart is made up of a fixed number of
024: configured series and a variable number of categories. A series is essentially an addressing scheme
025: that defines how to get information out of each category.
026: * @author Joe Walker [joe at getahead dot org]
027: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
028: */
029: public class Series extends jsx3.chart.ChartComponent {
030: /**
031: * All reverse ajax proxies need context to work from
032: * @param scriptProxy The place we are writing scripts to
033: * @param context The script that got us to where we are now
034: */
035: public Series(Context context, String extension,
036: ScriptProxy scriptProxy) {
037: super (context, extension, scriptProxy);
038: }
039:
040: /**
041: * The instance initializer.
042: * @param name the GI name of the instance
043: * @param seriesName the name of the Series, will be displayed in the Legend for most chart types
044: */
045: public Series(String name, String seriesName) {
046: super ((Context) null, (String) null, (ScriptProxy) null);
047: ScriptBuffer script = new ScriptBuffer();
048: script.appendCall("new Series", name, seriesName);
049: setInitScript(script);
050: }
051:
052: /**
053: * Returns the seriesName field.
054: * @param callback seriesName
055: */
056: @SuppressWarnings("unchecked")
057: public void getSeriesName(
058: org.directwebremoting.proxy.Callback<String> callback) {
059: ScriptBuffer script = new ScriptBuffer();
060: String callbackPrefix = "";
061:
062: if (callback != null) {
063: callbackPrefix = "var reply = ";
064: }
065:
066: script.appendCall(callbackPrefix + getContextPath()
067: + "getSeriesName");
068:
069: if (callback != null) {
070: String key = org.directwebremoting.extend.CallbackHelper
071: .saveCallback(callback, String.class);
072: script
073: .appendCall("__System.activateCallback", key,
074: "reply");
075: }
076:
077: getScriptProxy().addScript(script);
078: }
079:
080: /**
081: * Sets the seriesName field, this name is usually displayed in a legend or as a label.
082: * @param seriesName the new value for seriesName
083: */
084: public void setSeriesName(String seriesName) {
085: ScriptBuffer script = new ScriptBuffer();
086: script.appendCall(getContextPath() + "setSeriesName",
087: seriesName);
088: getScriptProxy().addScript(script);
089: }
090:
091: /**
092: * Sets the function used to render tooltips for each area drawn by this series.
093: * @param tooltipFunction evals to a function with the signature function(series,record) : string
094: */
095: public void setTooltipFunction(String tooltipFunction) {
096: ScriptBuffer script = new ScriptBuffer();
097: script.appendCall(getContextPath() + "setTooltipFunction",
098: tooltipFunction);
099: getScriptProxy().addScript(script);
100: }
101:
102: /**
103: * Returns the function used to render tooltips for each area drawn by this series.
104: * @param callback function(series,record) : string
105: */
106: @SuppressWarnings("unchecked")
107: public void getTooltipFunction(
108: org.directwebremoting.proxy.Callback<org.directwebremoting.proxy.CodeBlock> callback) {
109: ScriptBuffer script = new ScriptBuffer();
110: String callbackPrefix = "";
111:
112: if (callback != null) {
113: callbackPrefix = "var reply = ";
114: }
115:
116: script.appendCall(callbackPrefix + getContextPath()
117: + "getTooltipFunction");
118:
119: if (callback != null) {
120: String key = org.directwebremoting.extend.CallbackHelper
121: .saveCallback(callback,
122: org.directwebremoting.proxy.CodeBlock.class);
123: script
124: .appendCall("__System.activateCallback", key,
125: "reply");
126: }
127:
128: getScriptProxy().addScript(script);
129: }
130:
131: /**
132: * Returns the stroke field.
133: * @param callback stroke
134: */
135: @SuppressWarnings("unchecked")
136: public void getStroke(
137: org.directwebremoting.proxy.Callback<String> callback) {
138: ScriptBuffer script = new ScriptBuffer();
139: String callbackPrefix = "";
140:
141: if (callback != null) {
142: callbackPrefix = "var reply = ";
143: }
144:
145: script.appendCall(callbackPrefix + getContextPath()
146: + "getStroke");
147:
148: if (callback != null) {
149: String key = org.directwebremoting.extend.CallbackHelper
150: .saveCallback(callback, String.class);
151: script
152: .appendCall("__System.activateCallback", key,
153: "reply");
154: }
155:
156: getScriptProxy().addScript(script);
157: }
158:
159: /**
160: * Sets the stroke field, string representation of a VectorStroke.
161: * @param stroke the new value for stroke
162: */
163: public void setStroke(String stroke) {
164: ScriptBuffer script = new ScriptBuffer();
165: script.appendCall(getContextPath() + "setStroke", stroke);
166: getScriptProxy().addScript(script);
167: }
168:
169: /**
170: * Returns the fill field.
171: * @param callback fill
172: */
173: @SuppressWarnings("unchecked")
174: public void getFill(
175: org.directwebremoting.proxy.Callback<String> callback) {
176: ScriptBuffer script = new ScriptBuffer();
177: String callbackPrefix = "";
178:
179: if (callback != null) {
180: callbackPrefix = "var reply = ";
181: }
182:
183: script
184: .appendCall(callbackPrefix + getContextPath()
185: + "getFill");
186:
187: if (callback != null) {
188: String key = org.directwebremoting.extend.CallbackHelper
189: .saveCallback(callback, String.class);
190: script
191: .appendCall("__System.activateCallback", key,
192: "reply");
193: }
194:
195: getScriptProxy().addScript(script);
196: }
197:
198: /**
199: * Sets the fill field, string representation of a vector fill.
200: * @param fill the new value for fill
201: */
202: public void setFill(String fill) {
203: ScriptBuffer script = new ScriptBuffer();
204: script.appendCall(getContextPath() + "setFill", fill);
205: getScriptProxy().addScript(script);
206: }
207:
208: /**
209: * Returns the fillGradient field.
210: * @param callback fillGradient
211: */
212: @SuppressWarnings("unchecked")
213: public void getFillGradient(
214: org.directwebremoting.proxy.Callback<String> callback) {
215: ScriptBuffer script = new ScriptBuffer();
216: String callbackPrefix = "";
217:
218: if (callback != null) {
219: callbackPrefix = "var reply = ";
220: }
221:
222: script.appendCall(callbackPrefix + getContextPath()
223: + "getFillGradient");
224:
225: if (callback != null) {
226: String key = org.directwebremoting.extend.CallbackHelper
227: .saveCallback(callback, String.class);
228: script
229: .appendCall("__System.activateCallback", key,
230: "reply");
231: }
232:
233: getScriptProxy().addScript(script);
234: }
235:
236: /**
237: * Sets the fillGradient field, string representation of a vector fill gradient.
238: * @param fillGradient the new value for fillGradient
239: */
240: public void setFillGradient(String fillGradient) {
241: ScriptBuffer script = new ScriptBuffer();
242: script.appendCall(getContextPath() + "setFillGradient",
243: fillGradient);
244: getScriptProxy().addScript(script);
245: }
246:
247: /**
248: * Returns the x axis that this series is plotted against.
249: * @return the x axis
250: */
251: @SuppressWarnings("unchecked")
252: public jsx3.chart.Axis getXAxis() {
253: String extension = "getXAxis().";
254: try {
255: java.lang.reflect.Constructor<jsx3.chart.Axis> ctor = jsx3.chart.Axis.class
256: .getConstructor(Context.class, String.class,
257: ScriptProxy.class);
258: return ctor.newInstance(this , extension, getScriptProxy());
259: } catch (Exception ex) {
260: throw new IllegalArgumentException("Unsupported type: "
261: + jsx3.chart.Axis.class.getName());
262: }
263: }
264:
265: /**
266: * Returns the x axis that this series is plotted against.
267: * @param returnType The expected return type
268: * @return the x axis
269: */
270: @SuppressWarnings("unchecked")
271: public <T> T getXAxis(Class<T> returnType) {
272: String extension = "getXAxis().";
273: try {
274: java.lang.reflect.Constructor<T> ctor = returnType
275: .getConstructor(Context.class, String.class,
276: ScriptProxy.class);
277: return ctor.newInstance(this , extension, getScriptProxy());
278: } catch (Exception ex) {
279: throw new IllegalArgumentException(
280: "Unsupported return type: " + returnType.getName());
281: }
282: }
283:
284: /**
285: * Returns the y axis that this series is plotted against.
286: * @return the y axis
287: */
288: @SuppressWarnings("unchecked")
289: public jsx3.chart.Axis getYAxis() {
290: String extension = "getYAxis().";
291: try {
292: java.lang.reflect.Constructor<jsx3.chart.Axis> ctor = jsx3.chart.Axis.class
293: .getConstructor(Context.class, String.class,
294: ScriptProxy.class);
295: return ctor.newInstance(this , extension, getScriptProxy());
296: } catch (Exception ex) {
297: throw new IllegalArgumentException("Unsupported type: "
298: + jsx3.chart.Axis.class.getName());
299: }
300: }
301:
302: /**
303: * Returns the y axis that this series is plotted against.
304: * @param returnType The expected return type
305: * @return the y axis
306: */
307: @SuppressWarnings("unchecked")
308: public <T> T getYAxis(Class<T> returnType) {
309: String extension = "getYAxis().";
310: try {
311: java.lang.reflect.Constructor<T> ctor = returnType
312: .getConstructor(Context.class, String.class,
313: ScriptProxy.class);
314: return ctor.newInstance(this , extension, getScriptProxy());
315: } catch (Exception ex) {
316: throw new IllegalArgumentException(
317: "Unsupported return type: " + returnType.getName());
318: }
319: }
320:
321: /**
322: * Returns the colorFunction field.
323: * @param callback colorFunction
324: */
325: @SuppressWarnings("unchecked")
326: public void getColorFunction(
327: org.directwebremoting.proxy.Callback<org.directwebremoting.proxy.CodeBlock> callback) {
328: ScriptBuffer script = new ScriptBuffer();
329: String callbackPrefix = "";
330:
331: if (callback != null) {
332: callbackPrefix = "var reply = ";
333: }
334:
335: script.appendCall(callbackPrefix + getContextPath()
336: + "getColorFunction");
337:
338: if (callback != null) {
339: String key = org.directwebremoting.extend.CallbackHelper
340: .saveCallback(callback,
341: org.directwebremoting.proxy.CodeBlock.class);
342: script
343: .appendCall("__System.activateCallback", key,
344: "reply");
345: }
346:
347: getScriptProxy().addScript(script);
348: }
349:
350: /**
351: * Sets the colorFunction field.
352: * @param colorFunction the new value for colorFunction
353: */
354: public void setColorFunction(String colorFunction) {
355: ScriptBuffer script = new ScriptBuffer();
356: script.appendCall(getContextPath() + "setColorFunction",
357: colorFunction);
358: getScriptProxy().addScript(script);
359: }
360:
361: /**
362: * Returns the optional jsx3.chart.ChartLabel child of this series.
363: */
364: @SuppressWarnings("unchecked")
365: public jsx3.chart.ChartLabel getLabel() {
366: String extension = "getLabel().";
367: try {
368: java.lang.reflect.Constructor<jsx3.chart.ChartLabel> ctor = jsx3.chart.ChartLabel.class
369: .getConstructor(Context.class, String.class,
370: ScriptProxy.class);
371: return ctor.newInstance(this , extension, getScriptProxy());
372: } catch (Exception ex) {
373: throw new IllegalArgumentException("Unsupported type: "
374: + jsx3.chart.ChartLabel.class.getName());
375: }
376: }
377:
378: }
|