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.gui;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * Renders a dialog window. A dialog can contain other DOM objects; usually a dialog contains one child of type
024: jsx3.gui.WindowBar and one child of type jsx3.gui.Block.
025: * @author Joe Walker [joe at getahead dot org]
026: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
027: */
028: public class Dialog extends jsx3.gui.Block {
029: /**
030: * All reverse ajax proxies need context to work from
031: * @param scriptProxy The place we are writing scripts to
032: * @param context The script that got us to where we are now
033: */
034: public Dialog(Context context, String extension,
035: ScriptProxy scriptProxy) {
036: super (context, extension, scriptProxy);
037: }
038:
039: /**
040: * instance initializer
041: * @param strName unique name distinguishing this object from all other JSX GUI objects in the JSX application
042: * @param vntWidth width in pixels
043: * @param vntHeight height in pixels
044: * @param strTitle if != null, will be set as the text property on the child captionbar
045: */
046: public Dialog(String strName, int vntWidth, int vntHeight,
047: String strTitle) {
048: super ((Context) null, (String) null, (ScriptProxy) null);
049: ScriptBuffer script = new ScriptBuffer();
050: script.appendCall("new Dialog", strName, vntWidth, vntHeight,
051: strTitle);
052: setInitScript(script);
053: }
054:
055: /**
056: * instance initializer
057: * @param strName unique name distinguishing this object from all other JSX GUI objects in the JSX application
058: * @param vntWidth width in pixels
059: * @param vntHeight height in pixels
060: * @param strTitle if != null, will be set as the text property on the child captionbar
061: */
062: public Dialog(String strName, String vntWidth, String vntHeight,
063: String strTitle) {
064: super ((Context) null, (String) null, (ScriptProxy) null);
065: ScriptBuffer script = new ScriptBuffer();
066: script.appendCall("new Dialog", strName, vntWidth, vntHeight,
067: strTitle);
068: setInitScript(script);
069: }
070:
071: /**
072: * instance initializer
073: * @param strName unique name distinguishing this object from all other JSX GUI objects in the JSX application
074: * @param vntWidth width in pixels
075: * @param vntHeight height in pixels
076: * @param strTitle if != null, will be set as the text property on the child captionbar
077: */
078: public Dialog(String strName, int vntWidth, String vntHeight,
079: String strTitle) {
080: super ((Context) null, (String) null, (ScriptProxy) null);
081: ScriptBuffer script = new ScriptBuffer();
082: script.appendCall("new Dialog", strName, vntWidth, vntHeight,
083: strTitle);
084: setInitScript(script);
085: }
086:
087: /**
088: * instance initializer
089: * @param strName unique name distinguishing this object from all other JSX GUI objects in the JSX application
090: * @param vntWidth width in pixels
091: * @param vntHeight height in pixels
092: * @param strTitle if != null, will be set as the text property on the child captionbar
093: */
094: public Dialog(String strName, String vntWidth, int vntHeight,
095: String strTitle) {
096: super ((Context) null, (String) null, (ScriptProxy) null);
097: ScriptBuffer script = new ScriptBuffer();
098: script.appendCall("new Dialog", strName, vntWidth, vntHeight,
099: strTitle);
100: setInitScript(script);
101: }
102:
103: /**
104: * Enum value for the windowState property of instances of this class indicating a minimized dialog.
105: */
106: public static final int MINIMIZED = 0;
107:
108: /**
109: * Enum value for the windowState property of instances of this class indicating a maximized dialog.
110: */
111: public static final int MAXIMIZED = 1;
112:
113: /**
114: * #e8e8f5 (default)
115: */
116: public static final String DEFAULTBACKGROUNDCOLOR = "#e8e8f5";
117:
118: /**
119: * Enum value for the resizable property of instances of this class indicating a non-resizable dialog.
120: */
121: public static final int FIXED = 0;
122:
123: /**
124: * Enum value for the resizable property of instances of this class indicating a resizable dialog.
125: */
126: public static final int RESIZABLE = 1;
127:
128: /**
129: * Enum value for the modal property of instances of this class indicating a modal dialog.
130: */
131: public static final int MODAL = 1;
132:
133: /**
134: * Enum value for the modal property of instances of this class indicating a non-modal dialog.
135: */
136: public static final int NONMODAL = 0;
137:
138: /**
139: * typically called by minimize/windowshade jsx3.gui.ToolbarButton in the dialog box's caption bar; toggles the window's state between full-size and window-shaded (where only the dialog's caption bar is visible); or fully minimized to the application task bar if one exists
140: * @param STATE if != null, window state is set to fullsize (jsx3.gui.Dialog.MAXIMIZED) and window-shade (jsx3.gui.Dialog.MINIMIZED); if no value is passed, the state is toggled
141: */
142: public void doToggleState(int STATE) {
143: ScriptBuffer script = new ScriptBuffer();
144: script.appendCall(getContextPath() + "doToggleState", STATE);
145: getScriptProxy().addScript(script);
146: }
147:
148: /**
149: * Returns whether this dialog instance is the front-most dialog among all open dialogs
150: */
151: @SuppressWarnings("unchecked")
152: public void isFront(
153: org.directwebremoting.proxy.Callback<Boolean> callback) {
154: ScriptBuffer script = new ScriptBuffer();
155: String callbackPrefix = "";
156:
157: if (callback != null) {
158: callbackPrefix = "var reply = ";
159: }
160:
161: script
162: .appendCall(callbackPrefix + getContextPath()
163: + "isFront");
164:
165: if (callback != null) {
166: String key = org.directwebremoting.extend.CallbackHelper
167: .saveCallback(callback, Boolean.class);
168: script
169: .appendCall("__System.activateCallback", key,
170: "reply");
171: }
172:
173: getScriptProxy().addScript(script);
174: }
175:
176: /**
177: * Returns object handle to the jsx3.gui.ToolbarButton instance that resides in the application (this.getServer()) task bar and is associated with this dialog instance; returns null if none found
178: * @param objTaskBar specify the task bar to search in
179: * @return or null
180: */
181: @SuppressWarnings("unchecked")
182: public jsx3.gui.ToolbarButton getTaskButton(
183: jsx3.gui.WindowBar objTaskBar) {
184: String extension = "getTaskButton(\"" + objTaskBar + "\").";
185: try {
186: java.lang.reflect.Constructor<jsx3.gui.ToolbarButton> ctor = jsx3.gui.ToolbarButton.class
187: .getConstructor(Context.class, String.class,
188: ScriptProxy.class);
189: return ctor.newInstance(this , extension, getScriptProxy());
190: } catch (Exception ex) {
191: throw new IllegalArgumentException("Unsupported type: "
192: + jsx3.gui.ToolbarButton.class.getName());
193: }
194: }
195:
196: /**
197: * removes the dialog box from the JSX DOM and removes its on-screen VIEW from the browser DOM
198: */
199: public void doClose() {
200: ScriptBuffer script = new ScriptBuffer();
201: script.appendCall(getContextPath() + "doClose");
202: getScriptProxy().addScript(script);
203: }
204:
205: /**
206: * Returns state of the window (full-size / window-shaded). Default: jsx3.gui.Dialog.MAXIMIZED
207: * @param callback one of: jsx3.gui.Dialog.MAXIMIZED or jsx3.gui.Dialog.MINIMIZED
208: */
209: @SuppressWarnings("unchecked")
210: public void getWindowState(
211: org.directwebremoting.proxy.Callback<Integer> callback) {
212: ScriptBuffer script = new ScriptBuffer();
213: String callbackPrefix = "";
214:
215: if (callback != null) {
216: callbackPrefix = "var reply = ";
217: }
218:
219: script.appendCall(callbackPrefix + getContextPath()
220: + "getWindowState");
221:
222: if (callback != null) {
223: String key = org.directwebremoting.extend.CallbackHelper
224: .saveCallback(callback, Integer.class);
225: script
226: .appendCall("__System.activateCallback", key,
227: "reply");
228: }
229:
230: getScriptProxy().addScript(script);
231: }
232:
233: /**
234: * Sets state of the window (full-size / window-shaded); returns ref to self for method chaining
235: * @param STATE one of: jsx3.gui.Dialog.MAXIMIZED or jsx3.gui.Dialog.MINIMIZED
236: * @return this object
237: */
238: public jsx3.gui.Dialog setWindowState(int STATE) {
239: ScriptBuffer script = new ScriptBuffer();
240: script.appendCall(getContextPath() + "setWindowState", STATE);
241: getScriptProxy().addScript(script);
242: return this ;
243: }
244:
245: /**
246: * Returns numeric multiplier for the dialog's z-index. If a dialog box needs to always be on top of other dialog box instances, this multiplier can be increased to assure the appropriate zIndex. For example, a value of 5 would mean that this dialog box would be stacked on top of all dialog boxes with a alwaysOnTop multiplier less than 5. Default: 1
247: * @param callback integer
248: */
249: @SuppressWarnings("unchecked")
250: public void getZMultiplier(
251: org.directwebremoting.proxy.Callback<Integer> callback) {
252: ScriptBuffer script = new ScriptBuffer();
253: String callbackPrefix = "";
254:
255: if (callback != null) {
256: callbackPrefix = "var reply = ";
257: }
258:
259: script.appendCall(callbackPrefix + getContextPath()
260: + "getZMultiplier");
261:
262: if (callback != null) {
263: String key = org.directwebremoting.extend.CallbackHelper
264: .saveCallback(callback, Integer.class);
265: script
266: .appendCall("__System.activateCallback", key,
267: "reply");
268: }
269:
270: getScriptProxy().addScript(script);
271: }
272:
273: /**
274: * Sets numeric multiplier for the dialog's z-index. If a dialog box needs to always be on top of other dialog box instances, this multiplier can be increased to assure the appropriate zIndex. For example, a value of 5 would mean that this dialog box would be stacked on top of all dialog boxes with a alwaysOnTop multiplier less than 5
275: * @param intMultiplier integer; zero is allowed, but is not recommended; passing null is equivalent to passing 1
276: * @return this object
277: */
278: public jsx3.gui.Dialog setZMultiplier(int intMultiplier) {
279: ScriptBuffer script = new ScriptBuffer();
280: script.appendCall(getContextPath() + "setZMultiplier",
281: intMultiplier);
282: getScriptProxy().addScript(script);
283: return this ;
284: }
285:
286: /**
287: * Returns whether a dialog displays as modal or not. Modal dialogs mask the rest of the container with an semi-transparent mask that blocks mouse interaction. Modal dialogs do not show up in the task bar. Default: jsx3.gui.Dialog.NONMODAL
288: * @param callback one of: jsx3.gui.Dialog.NONMODAL or jsx3.gui.Dialog.MODAL
289: */
290: @SuppressWarnings("unchecked")
291: public void getModal(
292: org.directwebremoting.proxy.Callback<Integer> callback) {
293: ScriptBuffer script = new ScriptBuffer();
294: String callbackPrefix = "";
295:
296: if (callback != null) {
297: callbackPrefix = "var reply = ";
298: }
299:
300: script.appendCall(callbackPrefix + getContextPath()
301: + "getModal");
302:
303: if (callback != null) {
304: String key = org.directwebremoting.extend.CallbackHelper
305: .saveCallback(callback, Integer.class);
306: script
307: .appendCall("__System.activateCallback", key,
308: "reply");
309: }
310:
311: getScriptProxy().addScript(script);
312: }
313:
314: /**
315: * Sets whether a dialog displays as modal or not. Modal dialogs mask the rest of the container with an semi-transparent mask that blocks mouse interaction. Modal dialogs do not show up in the task bar.
316: * @param intModal one of: jsx3.gui.Dialog.NONMODAL or jsx3.gui.Dialog.MODAL
317: * @return this object
318: */
319: public jsx3.gui.Dialog setModal(int intModal) {
320: ScriptBuffer script = new ScriptBuffer();
321: script.appendCall(getContextPath() + "setModal", intModal);
322: getScriptProxy().addScript(script);
323: return this ;
324: }
325:
326: /**
327: * Toggles the state of the dialog between 'maximized' and its 'initial state'
328: * @param objTBB toolbarbutton instance on the dialog to toggle the image/tip text for
329: */
330: public void doMaximize(jsx3.gui.ToolbarButton objTBB) {
331: ScriptBuffer script = new ScriptBuffer();
332: script.appendCall(getContextPath() + "doMaximize", objTBB);
333: getScriptProxy().addScript(script);
334: }
335:
336: /**
337: * Returns whether the dialog can be resized or not. Default: jsx3.gui.Dialog.RESIZABLE
338: * @param callback one of: jsx3.gui.Dialog.RESIZABLE jsx3.gui.Dialog.FIXED
339: */
340: @SuppressWarnings("unchecked")
341: public void getResize(
342: org.directwebremoting.proxy.Callback<Integer> callback) {
343: ScriptBuffer script = new ScriptBuffer();
344: String callbackPrefix = "";
345:
346: if (callback != null) {
347: callbackPrefix = "var reply = ";
348: }
349:
350: script.appendCall(callbackPrefix + getContextPath()
351: + "getResize");
352:
353: if (callback != null) {
354: String key = org.directwebremoting.extend.CallbackHelper
355: .saveCallback(callback, Integer.class);
356: script
357: .appendCall("__System.activateCallback", key,
358: "reply");
359: }
360:
361: getScriptProxy().addScript(script);
362: }
363:
364: /**
365: * Sets whether the dialog box's on-screen view can be resized; returns reference to self to facilitate method chaining
366: * @param RESIZE one of: jsx3.gui.Dialog.RESIZABLE jsx3.gui.Dialog.FIXED
367: * @return this object
368: */
369: public jsx3.gui.Dialog setResize(int RESIZE) {
370: ScriptBuffer script = new ScriptBuffer();
371: script.appendCall(getContextPath() + "setResize", RESIZE);
372: getScriptProxy().addScript(script);
373: return this ;
374: }
375:
376: /**
377: * Sets resize parameters such as min width, max width, etc for the dialog; returns reference to self to facilitate method chaining
378: * @param RESIZE one of: jsx3.gui.Dialog.RESIZABLE jsx3.gui.Dialog.FIXED
379: * @param intMinX min width for the dialog when being resized
380: * @param intMinY min height for the dialog when being resized
381: * @param intMaxX max width for the dialog when being resized
382: * @param intMaxY max heightfor the dialog when being resized
383: * @param strAfterResizeFunction
384: * @return this object
385: */
386: public jsx3.gui.Dialog setResizeParameters(int RESIZE, int intMinX,
387: int intMinY, int intMaxX, int intMaxY,
388: String strAfterResizeFunction) {
389: ScriptBuffer script = new ScriptBuffer();
390: script.appendCall(getContextPath() + "setResizeParameters",
391: RESIZE, intMinX, intMinY, intMaxX, intMaxY,
392: strAfterResizeFunction);
393: getScriptProxy().addScript(script);
394: return this ;
395: }
396:
397: /**
398: * Returns an object handle to the jsx3.gui.WindowBar instance associated with the jsx3.gui.Dialog instance
399: * @return jsx3.gui.WindowBar instance or null
400: */
401: @SuppressWarnings("unchecked")
402: public jsx3.gui.WindowBar getCaptionBar() {
403: String extension = "getCaptionBar().";
404: try {
405: java.lang.reflect.Constructor<jsx3.gui.WindowBar> ctor = jsx3.gui.WindowBar.class
406: .getConstructor(Context.class, String.class,
407: ScriptProxy.class);
408: return ctor.newInstance(this , extension, getScriptProxy());
409: } catch (Exception ex) {
410: throw new IllegalArgumentException("Unsupported type: "
411: + jsx3.gui.WindowBar.class.getName());
412: }
413: }
414:
415: /**
416: * Implements necessary method for the Alerts interface.
417: * @return this object.
418: */
419: @SuppressWarnings("unchecked")
420: public jsx3.gui.Block getAlertsParent() {
421: String extension = "getAlertsParent().";
422: try {
423: java.lang.reflect.Constructor<jsx3.gui.Block> ctor = jsx3.gui.Block.class
424: .getConstructor(Context.class, String.class,
425: ScriptProxy.class);
426: return ctor.newInstance(this , extension, getScriptProxy());
427: } catch (Exception ex) {
428: throw new IllegalArgumentException("Unsupported type: "
429: + jsx3.gui.Block.class.getName());
430: }
431: }
432:
433: /**
434: * Implements necessary method for the Alerts interface.
435: * @param returnType The expected return type
436: * @return this object.
437: */
438: @SuppressWarnings("unchecked")
439: public <T> T getAlertsParent(Class<T> returnType) {
440: String extension = "getAlertsParent().";
441: try {
442: java.lang.reflect.Constructor<T> ctor = returnType
443: .getConstructor(Context.class, String.class,
444: ScriptProxy.class);
445: return ctor.newInstance(this , extension, getScriptProxy());
446: } catch (Exception ex) {
447: throw new IllegalArgumentException(
448: "Unsupported return type: " + returnType.getName());
449: }
450: }
451:
452: /**
453: * Modifies the top and left properties of this dialog in order to fit it within its parent container.
454: This method ensures that at least a certain amount of the dialog shows on the East, South, and West edges
455: of the server and that the entire dialog shows on the North edge.
456:
457: This method is called by default after the user moves a dialog with the mouse. If an AFTER_MOVE
458: model event is specified, then this method is not called automatically and must be called explicitly by the
459: model event.
460: * @param arg if <code>true</code>, this dialog will be placed entirely within its container,
461: with a certain amount of padding, and this dialog will be resized if necessary. If this argument is an array,
462: it is taken as the N-E-S-W minimum pixels to show after constraining the position of the dialog. A
463: <code>null</code> value for any dimension means that the entire dimension should be shown. A negative value
464: means the number of pixels less than the size of the dialog in that dimension.
465: */
466: public void constrainPosition(boolean arg) {
467: ScriptBuffer script = new ScriptBuffer();
468: script.appendCall(getContextPath() + "constrainPosition", arg);
469: getScriptProxy().addScript(script);
470: }
471:
472: /**
473: * Modifies the top and left properties of this dialog in order to fit it within its parent container.
474: This method ensures that at least a certain amount of the dialog shows on the East, South, and West edges
475: of the server and that the entire dialog shows on the North edge.
476:
477: This method is called by default after the user moves a dialog with the mouse. If an AFTER_MOVE
478: model event is specified, then this method is not called automatically and must be called explicitly by the
479: model event.
480: * @param arg if <code>true</code>, this dialog will be placed entirely within its container,
481: with a certain amount of padding, and this dialog will be resized if necessary. If this argument is an array,
482: it is taken as the N-E-S-W minimum pixels to show after constraining the position of the dialog. A
483: <code>null</code> value for any dimension means that the entire dimension should be shown. A negative value
484: means the number of pixels less than the size of the dialog in that dimension.
485: */
486: public void constrainPosition(Object[] arg) {
487: ScriptBuffer script = new ScriptBuffer();
488: script.appendCall(getContextPath() + "constrainPosition", arg);
489: getScriptProxy().addScript(script);
490: }
491:
492: /**
493: * alerts the user's attention to the dialog box by making its caption bar 'flash' on-screen (as it typical with a windows modal dialog)
494: */
495: public void beep() {
496: ScriptBuffer script = new ScriptBuffer();
497: script.appendCall(getContextPath() + "beep");
498: getScriptProxy().addScript(script);
499: }
500:
501: /**
502: * show an alert dialog
503: * @param strTitle the title of the dialog
504: * @param strMessage the message to display
505: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
506: * @param strOk the text of the ok button, can be false to remove button from display
507: * @param objParams argument to configureAlert()
508: */
509: public void alert(String strTitle, String strMessage,
510: org.directwebremoting.proxy.CodeBlock fctOnOk,
511: String strOk, String objParams) {
512: ScriptBuffer script = new ScriptBuffer();
513: script.appendCall(getContextPath() + "alert", strTitle,
514: strMessage, fctOnOk, strOk, objParams);
515: getScriptProxy().addScript(script);
516: }
517:
518: /**
519: * configure the dialog
520: * @param objDialog the dialog
521: * @param objParams may include fields 'width', 'height', 'noTitle', and 'nonModal'.
522: */
523: public void configureAlert(java.lang.Object objDialog,
524: jsx3.lang.Object objParams) {
525: ScriptBuffer script = new ScriptBuffer();
526: script.appendCall(getContextPath() + "configureAlert",
527: objDialog, objParams);
528: getScriptProxy().addScript(script);
529: }
530:
531: /**
532: * show a confirm alert
533: * @param strTitle the title of the dialog
534: * @param strMessage the message to display
535: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
536: * @param fctOnCancel callback function on pressing cancel button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
537: * @param strOk the text of the ok button
538: * @param strCancel the text of the cancel button
539: * @param intBtnDefault the bold button that receives return key, 1:ok, 2:cancel, 3:no
540: * @param fctOnNo callback function on pressing no button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
541: * @param strNo the text of the no button
542: * @param objParams argument to configureAlert()
543: */
544: public void confirm(String strTitle, String strMessage,
545: org.directwebremoting.proxy.CodeBlock fctOnOk,
546: org.directwebremoting.proxy.CodeBlock fctOnCancel,
547: String strOk, String strCancel, int intBtnDefault,
548: org.directwebremoting.proxy.CodeBlock fctOnNo,
549: String strNo, String objParams) {
550: ScriptBuffer script = new ScriptBuffer();
551: script.appendCall(getContextPath() + "confirm", strTitle,
552: strMessage, fctOnOk, fctOnCancel, strOk, strCancel,
553: intBtnDefault, fctOnNo, strNo, objParams);
554: getScriptProxy().addScript(script);
555: }
556:
557: /**
558: * show a text box input prompt
559: * @param strTitle the title of the dialog
560: * @param strMessage the message to display
561: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument, and the value of the text input as a second argument; if null the dialog will close itself; if defined must explicitly close the dialog
562: * @param fctOnCancel callback function on pressing cancel button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
563: * @param strOk the text of the ok button
564: * @param strCancel the text of the cancel button
565: * @param objParams argument to configureAlert()
566: */
567: public void prompt(String strTitle, String strMessage,
568: org.directwebremoting.proxy.CodeBlock fctOnOk,
569: org.directwebremoting.proxy.CodeBlock fctOnCancel,
570: String strOk, String strCancel, String objParams) {
571: ScriptBuffer script = new ScriptBuffer();
572: script.appendCall(getContextPath() + "prompt", strTitle,
573: strMessage, fctOnOk, fctOnCancel, strOk, strCancel,
574: objParams);
575: getScriptProxy().addScript(script);
576: }
577:
578: }
|