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: * Objects that implement this interface may be used in Line/Area/Point/Bubble charts to render the points that appear
024: at each datapoint.
025:
026: Additionally, this interface contains several static fields that are implementors of this interface.
027: * @author Joe Walker [joe at getahead dot org]
028: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
029: */
030: public class PointRenderer extends jsx3.lang.Object {
031: /**
032: * All reverse ajax proxies need context to work from
033: * @param scriptProxy The place we are writing scripts to
034: * @param context The script that got us to where we are now
035: */
036: public PointRenderer(Context context, String extension,
037: ScriptProxy scriptProxy) {
038: super (context, extension, scriptProxy);
039: }
040:
041: /**
042: * Renders the point in the bounds specified by {x1,y1} {x2,y2}.
043: * @param x1
044: * @param y1
045: * @param x2
046: * @param y2
047: * @param fill
048: * @param stroke
049: */
050: @SuppressWarnings("unchecked")
051: public jsx3.vector.Tag render(int x1, int y1, int x2, int y2,
052: jsx3.vector.Fill fill, jsx3.vector.Stroke stroke) {
053: String extension = "render(\"" + x1 + "\", \"" + y1 + "\", \""
054: + x2 + "\", \"" + y2 + "\", \"" + fill + "\", \""
055: + stroke + "\").";
056: try {
057: java.lang.reflect.Constructor<jsx3.vector.Tag> ctor = jsx3.vector.Tag.class
058: .getConstructor(Context.class, String.class,
059: ScriptProxy.class);
060: return ctor.newInstance(this , extension, getScriptProxy());
061: } catch (Exception ex) {
062: throw new IllegalArgumentException("Unsupported type: "
063: + jsx3.vector.Tag.class.getName());
064: }
065: }
066:
067: /**
068: * Renders the point in the bounds specified by {x1,y1} {x2,y2}.
069: * @param x1
070: * @param y1
071: * @param x2
072: * @param y2
073: * @param fill
074: * @param stroke
075: * @param returnType The expected return type
076: */
077: @SuppressWarnings("unchecked")
078: public <T> T render(int x1, int y1, int x2, int y2,
079: jsx3.vector.Fill fill, jsx3.vector.Stroke stroke,
080: Class<T> returnType) {
081: String extension = "render(\"" + x1 + "\", \"" + y1 + "\", \""
082: + x2 + "\", \"" + y2 + "\", \"" + fill + "\", \""
083: + stroke + "\").";
084: try {
085: java.lang.reflect.Constructor<T> ctor = returnType
086: .getConstructor(Context.class, String.class,
087: ScriptProxy.class);
088: return ctor.newInstance(this , extension, getScriptProxy());
089: } catch (Exception ex) {
090: throw new IllegalArgumentException(
091: "Unsupported return type: " + returnType.getName());
092: }
093: }
094:
095: /**
096: * Converts the area of the point to display to the radius of the box that it should fill. Required
097: if the point renderer will be used in a plot chart.
098: * @param area
099: */
100: @SuppressWarnings("unchecked")
101: public void areaToRadius(Integer area,
102: org.directwebremoting.proxy.Callback<Integer> callback) {
103: ScriptBuffer script = new ScriptBuffer();
104: String callbackPrefix = "";
105:
106: if (callback != null) {
107: callbackPrefix = "var reply = ";
108: }
109:
110: script.appendCall(callbackPrefix + getContextPath()
111: + "areaToRadius", area);
112:
113: if (callback != null) {
114: String key = org.directwebremoting.extend.CallbackHelper
115: .saveCallback(callback, Integer.class);
116: script
117: .appendCall("__System.activateCallback", key,
118: "reply");
119: }
120:
121: getScriptProxy().addScript(script);
122: }
123:
124: }
|