01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package jsx3.chart;
17:
18: import org.directwebremoting.ScriptBuffer;
19: import org.directwebremoting.proxy.ScriptProxy;
20: import org.directwebremoting.proxy.io.Context;
21:
22: /**
23: * A base class for every logical component of a chart. A chart component exists in the DOM tree and
24: is selectable with ctrl-click in a component editor in General InterfaceŞ Builder.
25: * @author Joe Walker [joe at getahead dot org]
26: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
27: */
28: public class ChartComponent extends jsx3.gui.Block {
29: /**
30: * All reverse ajax proxies need context to work from
31: * @param scriptProxy The place we are writing scripts to
32: * @param context The script that got us to where we are now
33: */
34: public ChartComponent(Context context, String extension,
35: ScriptProxy scriptProxy) {
36: super (context, extension, scriptProxy);
37: }
38:
39: /**
40: * The instance initializer.
41: * @param name the GI name of the instance
42: */
43: public ChartComponent(String name) {
44: super ((Context) null, (String) null, (ScriptProxy) null);
45: ScriptBuffer script = new ScriptBuffer();
46: script.appendCall("new ChartComponent", name);
47: setInitScript(script);
48: }
49:
50: /**
51: * Returns the chart of which this component is a part.
52: * @return this if this is a chart, or the first ancestor that is a chart
53: */
54: @SuppressWarnings("unchecked")
55: public jsx3.chart.Chart getChart() {
56: String extension = "getChart().";
57: try {
58: java.lang.reflect.Constructor<jsx3.chart.Chart> ctor = jsx3.chart.Chart.class
59: .getConstructor(Context.class, String.class,
60: ScriptProxy.class);
61: return ctor.newInstance(this , extension, getScriptProxy());
62: } catch (Exception ex) {
63: throw new IllegalArgumentException("Unsupported type: "
64: + jsx3.chart.Chart.class.getName());
65: }
66: }
67:
68: /**
69: * Returns the chart of which this component is a part.
70: * @param returnType The expected return type
71: * @return this if this is a chart, or the first ancestor that is a chart
72: */
73: @SuppressWarnings("unchecked")
74: public <T> T getChart(Class<T> returnType) {
75: String extension = "getChart().";
76: try {
77: java.lang.reflect.Constructor<T> ctor = returnType
78: .getConstructor(Context.class, String.class,
79: ScriptProxy.class);
80: return ctor.newInstance(this , extension, getScriptProxy());
81: } catch (Exception ex) {
82: throw new IllegalArgumentException(
83: "Unsupported return type: " + returnType.getName());
84: }
85: }
86:
87: }
|