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.vector;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * Represents a vector shape element.
024:
025: The vector shape is the principal vector tag. The path field can contain an EPS-like path the defines a
026: complex vector shape.
027: * @author Joe Walker [joe at getahead dot org]
028: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
029: */
030: public class Shape extends jsx3.vector.Tag {
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 Shape(Context context, String extension,
037: ScriptProxy scriptProxy) {
038: super (context, extension, scriptProxy);
039: }
040:
041: /**
042: * The instance initializer.
043: * @param strTagName
044: * @param left left position (in pixels) of the object relative to its parent container
045: * @param top top position (in pixels) of the object relative to its parent container
046: * @param width width (in pixels) of the object
047: * @param height height (in pixels) of the object
048: */
049: public Shape(String strTagName, int left, int top, int width,
050: int height) {
051: super ((Context) null, (String) null, (ScriptProxy) null);
052: ScriptBuffer script = new ScriptBuffer();
053: script.appendCall("new Shape", strTagName, left, top, width,
054: height);
055: setInitScript(script);
056: }
057:
058: /**
059: * Returns the path field.
060: * @param callback path
061: */
062: @SuppressWarnings("unchecked")
063: public void getPath(
064: org.directwebremoting.proxy.Callback<String> callback) {
065: ScriptBuffer script = new ScriptBuffer();
066: String callbackPrefix = "";
067:
068: if (callback != null) {
069: callbackPrefix = "var reply = ";
070: }
071:
072: script
073: .appendCall(callbackPrefix + getContextPath()
074: + "getPath");
075:
076: if (callback != null) {
077: String key = org.directwebremoting.extend.CallbackHelper
078: .saveCallback(callback, String.class);
079: script
080: .appendCall("__System.activateCallback", key,
081: "reply");
082: }
083:
084: getScriptProxy().addScript(script);
085: }
086:
087: /**
088: * Sets the path field.
089: * @param path the new value for path
090: */
091: public void setPath(String path) {
092: ScriptBuffer script = new ScriptBuffer();
093: script.appendCall(getContextPath() + "setPath", path);
094: getScriptProxy().addScript(script);
095: }
096:
097: /**
098: *
099: * @param x
100: * @param y
101: * @param bRel
102: * @return this object.
103: */
104: @SuppressWarnings("unchecked")
105: public jsx3.vector.Shape pathMoveTo(int x, int y, boolean bRel) {
106: String extension = "pathMoveTo(\"" + x + "\", \"" + y
107: + "\", \"" + bRel + "\").";
108: try {
109: java.lang.reflect.Constructor<jsx3.vector.Shape> ctor = jsx3.vector.Shape.class
110: .getConstructor(Context.class, String.class,
111: ScriptProxy.class);
112: return ctor.newInstance(this , extension, getScriptProxy());
113: } catch (Exception ex) {
114: throw new IllegalArgumentException("Unsupported type: "
115: + jsx3.vector.Shape.class.getName());
116: }
117: }
118:
119: /**
120: *
121: * @param x
122: * @param y
123: * @param bRel
124: * @param returnType The expected return type
125: * @return this object.
126: */
127: @SuppressWarnings("unchecked")
128: public <T> T pathMoveTo(int x, int y, boolean bRel,
129: Class<T> returnType) {
130: String extension = "pathMoveTo(\"" + x + "\", \"" + y
131: + "\", \"" + bRel + "\").";
132: try {
133: java.lang.reflect.Constructor<T> ctor = returnType
134: .getConstructor(Context.class, String.class,
135: ScriptProxy.class);
136: return ctor.newInstance(this , extension, getScriptProxy());
137: } catch (Exception ex) {
138: throw new IllegalArgumentException(
139: "Unsupported return type: " + returnType.getName());
140: }
141: }
142:
143: /**
144: *
145: * @param x
146: * @param y
147: * @param bRel
148: * @return this object.
149: */
150: @SuppressWarnings("unchecked")
151: public jsx3.vector.Shape pathLineTo(int x, int y, boolean bRel) {
152: String extension = "pathLineTo(\"" + x + "\", \"" + y
153: + "\", \"" + bRel + "\").";
154: try {
155: java.lang.reflect.Constructor<jsx3.vector.Shape> ctor = jsx3.vector.Shape.class
156: .getConstructor(Context.class, String.class,
157: ScriptProxy.class);
158: return ctor.newInstance(this , extension, getScriptProxy());
159: } catch (Exception ex) {
160: throw new IllegalArgumentException("Unsupported type: "
161: + jsx3.vector.Shape.class.getName());
162: }
163: }
164:
165: /**
166: *
167: * @param x
168: * @param y
169: * @param bRel
170: * @param returnType The expected return type
171: * @return this object.
172: */
173: @SuppressWarnings("unchecked")
174: public <T> T pathLineTo(int x, int y, boolean bRel,
175: Class<T> returnType) {
176: String extension = "pathLineTo(\"" + x + "\", \"" + y
177: + "\", \"" + bRel + "\").";
178: try {
179: java.lang.reflect.Constructor<T> ctor = returnType
180: .getConstructor(Context.class, String.class,
181: ScriptProxy.class);
182: return ctor.newInstance(this , extension, getScriptProxy());
183: } catch (Exception ex) {
184: throw new IllegalArgumentException(
185: "Unsupported return type: " + returnType.getName());
186: }
187: }
188:
189: /**
190: *
191: * @param cx
192: * @param cy
193: * @param rx
194: * @param ry
195: * @param x1
196: * @param y1
197: * @param x2
198: * @param y2
199: * @param bCW
200: * @return this object.
201: */
202: @SuppressWarnings("unchecked")
203: public jsx3.vector.Shape pathArcTo(int cx, int cy, int rx, int ry,
204: int x1, int y1, int x2, int y2, boolean bCW) {
205: String extension = "pathArcTo(\"" + cx + "\", \"" + cy
206: + "\", \"" + rx + "\", \"" + ry + "\", \"" + x1
207: + "\", \"" + y1 + "\", \"" + x2 + "\", \"" + y2
208: + "\", \"" + bCW + "\").";
209: try {
210: java.lang.reflect.Constructor<jsx3.vector.Shape> ctor = jsx3.vector.Shape.class
211: .getConstructor(Context.class, String.class,
212: ScriptProxy.class);
213: return ctor.newInstance(this , extension, getScriptProxy());
214: } catch (Exception ex) {
215: throw new IllegalArgumentException("Unsupported type: "
216: + jsx3.vector.Shape.class.getName());
217: }
218: }
219:
220: /**
221: *
222: * @param cx
223: * @param cy
224: * @param rx
225: * @param ry
226: * @param x1
227: * @param y1
228: * @param x2
229: * @param y2
230: * @param bCW
231: * @param returnType The expected return type
232: * @return this object.
233: */
234: @SuppressWarnings("unchecked")
235: public <T> T pathArcTo(int cx, int cy, int rx, int ry, int x1,
236: int y1, int x2, int y2, boolean bCW, Class<T> returnType) {
237: String extension = "pathArcTo(\"" + cx + "\", \"" + cy
238: + "\", \"" + rx + "\", \"" + ry + "\", \"" + x1
239: + "\", \"" + y1 + "\", \"" + x2 + "\", \"" + y2
240: + "\", \"" + bCW + "\").";
241: try {
242: java.lang.reflect.Constructor<T> ctor = returnType
243: .getConstructor(Context.class, String.class,
244: ScriptProxy.class);
245: return ctor.newInstance(this , extension, getScriptProxy());
246: } catch (Exception ex) {
247: throw new IllegalArgumentException(
248: "Unsupported return type: " + returnType.getName());
249: }
250: }
251:
252: /**
253: *
254: * @return this object.
255: */
256: @SuppressWarnings("unchecked")
257: public jsx3.vector.Shape pathClose() {
258: String extension = "pathClose().";
259: try {
260: java.lang.reflect.Constructor<jsx3.vector.Shape> ctor = jsx3.vector.Shape.class
261: .getConstructor(Context.class, String.class,
262: ScriptProxy.class);
263: return ctor.newInstance(this , extension, getScriptProxy());
264: } catch (Exception ex) {
265: throw new IllegalArgumentException("Unsupported type: "
266: + jsx3.vector.Shape.class.getName());
267: }
268: }
269:
270: /**
271: *
272: * @param returnType The expected return type
273: * @return this object.
274: */
275: @SuppressWarnings("unchecked")
276: public <T> T pathClose(Class<T> returnType) {
277: String extension = "pathClose().";
278: try {
279: java.lang.reflect.Constructor<T> ctor = returnType
280: .getConstructor(Context.class, String.class,
281: ScriptProxy.class);
282: return ctor.newInstance(this , extension, getScriptProxy());
283: } catch (Exception ex) {
284: throw new IllegalArgumentException(
285: "Unsupported return type: " + returnType.getName());
286: }
287: }
288:
289: /**
290: * Sets the fill of this shape, other fills may be present as children of this instance.
291: * @param fill the fill value.
292: */
293: public void setFill(jsx3.vector.Fill fill) {
294: ScriptBuffer script = new ScriptBuffer();
295: script.appendCall(getContextPath() + "setFill", fill);
296: getScriptProxy().addScript(script);
297: }
298:
299: /**
300: * Sets the stroke of this shape, other strokes may be present as children of this instance.
301: * @param stroke the stroke value.
302: */
303: public void setStroke(jsx3.vector.Stroke stroke) {
304: ScriptBuffer script = new ScriptBuffer();
305: script.appendCall(getContextPath() + "setStroke", stroke);
306: getScriptProxy().addScript(script);
307: }
308:
309: /**
310: * Returns the fill of this shape.
311: */
312: public void getFill() {
313: ScriptBuffer script = new ScriptBuffer();
314: script.appendCall(getContextPath() + "getFill");
315: getScriptProxy().addScript(script);
316: }
317:
318: /**
319: * Returns the stroke of this shape.
320: */
321: public void getStroke() {
322: ScriptBuffer script = new ScriptBuffer();
323: script.appendCall(getContextPath() + "getStroke");
324: getScriptProxy().addScript(script);
325: }
326:
327: }
|