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: * This class is equivalent to a tab, but uses the stack metaphor; like a tab, it has one childÑa block for its content; a jsx3.gui.Stack instance should only be contained by a jsx3.gui.StackGroup instance for proper rendering.
024: * @author Joe Walker [joe at getahead dot org]
025: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
026: */
027: public class Stack extends jsx3.gui.Block {
028: /**
029: * All reverse ajax proxies need context to work from
030: * @param scriptProxy The place we are writing scripts to
031: * @param context The script that got us to where we are now
032: */
033: public Stack(Context context, String extension,
034: ScriptProxy scriptProxy) {
035: super (context, extension, scriptProxy);
036: }
037:
038: /**
039: * instance initializer
040: * @param strName unique name distinguishing this object from all other JSX GUI objects in the JSX application
041: * @param strCaption if != null, will be set as the text property (label) for the stack
042: */
043: public Stack(String strName, String strCaption) {
044: super ((Context) null, (String) null, (ScriptProxy) null);
045: ScriptBuffer script = new ScriptBuffer();
046: script.appendCall("new Stack", strName, strCaption);
047: setInitScript(script);
048: }
049:
050: /**
051: * 0 (default)
052: */
053: public static final int ORIENTATIONV = 0;
054:
055: /**
056: * 1
057: */
058: public static final int ORIENTATIONH = 1;
059:
060: /**
061: * #aaccff
062: */
063: public static final String ACTIVECOLOR = "#aaaafe";
064:
065: /**
066: * #e8e8f5
067: */
068: public static final String INACTIVECOLOR = "#aaaacb";
069:
070: /**
071: * #ffffff
072: */
073: public static final String CHILDBGCOLOR = "#ffffff";
074:
075: /**
076: *
077: */
078: public static final String BACKGROUND = null;
079:
080: /**
081: * Makes this stack the visible (expanded) stack in the parent stack group.
082: */
083: public void doShow() {
084: ScriptBuffer script = new ScriptBuffer();
085: script.appendCall(getContextPath() + "doShow");
086: getScriptProxy().addScript(script);
087: }
088:
089: /**
090: * Returns the child of this stack that will be painted as the content of this stack. This implementation
091: returns the first child that is not a menu or a toolbar button.
092: */
093: @SuppressWarnings("unchecked")
094: public jsx3.app.Model getContentChild() {
095: String extension = "getContentChild().";
096: try {
097: java.lang.reflect.Constructor<jsx3.app.Model> ctor = jsx3.app.Model.class
098: .getConstructor(Context.class, String.class,
099: ScriptProxy.class);
100: return ctor.newInstance(this , extension, getScriptProxy());
101: } catch (Exception ex) {
102: throw new IllegalArgumentException("Unsupported type: "
103: + jsx3.app.Model.class.getName());
104: }
105: }
106:
107: /**
108: * Returns the child of this stack that will be painted as the content of this stack. This implementation
109: returns the first child that is not a menu or a toolbar button.
110: * @param returnType The expected return type
111: */
112: @SuppressWarnings("unchecked")
113: public <T> T getContentChild(Class<T> returnType) {
114: String extension = "getContentChild().";
115: try {
116: java.lang.reflect.Constructor<T> ctor = returnType
117: .getConstructor(Context.class, String.class,
118: ScriptProxy.class);
119: return ctor.newInstance(this , extension, getScriptProxy());
120: } catch (Exception ex) {
121: throw new IllegalArgumentException(
122: "Unsupported return type: " + returnType.getName());
123: }
124: }
125:
126: /**
127: * Returns valid CSS property value, (i.e., red, #ffffff) when caption bar for stack is moused over. Default: jsx3.gui.Stack.ACTIVECOLOR
128: * @param callback valid CSS property value, (i.e., red, #ffffff)
129: */
130: @SuppressWarnings("unchecked")
131: public void getActiveColor(
132: org.directwebremoting.proxy.Callback<String> callback) {
133: ScriptBuffer script = new ScriptBuffer();
134: String callbackPrefix = "";
135:
136: if (callback != null) {
137: callbackPrefix = "var reply = ";
138: }
139:
140: script.appendCall(callbackPrefix + getContextPath()
141: + "getActiveColor");
142:
143: if (callback != null) {
144: String key = org.directwebremoting.extend.CallbackHelper
145: .saveCallback(callback, String.class);
146: script
147: .appendCall("__System.activateCallback", key,
148: "reply");
149: }
150:
151: getScriptProxy().addScript(script);
152: }
153:
154: /**
155: * Sets valid CSS property value, (i.e., red, #ffffff) when caption bar for stack is moused over;
156: returns reference to self to facilitate method chaining
157: * @param strActiveColor valid CSS property value, (i.e., red, #ffffff)
158: * @return this object
159: */
160: public jsx3.gui.Stack setActiveColor(String strActiveColor) {
161: ScriptBuffer script = new ScriptBuffer();
162: script.appendCall(getContextPath() + "setActiveColor",
163: strActiveColor);
164: getScriptProxy().addScript(script);
165: return this ;
166: }
167:
168: /**
169: * Returns valid CSS property value, (i.e., red, #ffffff) when caption bar for stack is moused out. Default: jsx3.gui.Stack.INACTIVECOLOR
170: * @param callback valid CSS property value, (i.e., red, #ffffff)
171: */
172: @SuppressWarnings("unchecked")
173: public void getInactiveColor(
174: org.directwebremoting.proxy.Callback<String> callback) {
175: ScriptBuffer script = new ScriptBuffer();
176: String callbackPrefix = "";
177:
178: if (callback != null) {
179: callbackPrefix = "var reply = ";
180: }
181:
182: script.appendCall(callbackPrefix + getContextPath()
183: + "getInactiveColor");
184:
185: if (callback != null) {
186: String key = org.directwebremoting.extend.CallbackHelper
187: .saveCallback(callback, String.class);
188: script
189: .appendCall("__System.activateCallback", key,
190: "reply");
191: }
192:
193: getScriptProxy().addScript(script);
194: }
195:
196: /**
197: * Sets valid CSS property value, (i.e., red, #ffffff) when caption bar for stack is moused out;
198: returns reference to self to facilitate method chaining
199: * @param strInactiveColor valid CSS property value, (i.e., red, #ffffff)
200: * @return this object
201: */
202: public jsx3.gui.Stack setInactiveColor(String strInactiveColor) {
203: ScriptBuffer script = new ScriptBuffer();
204: script.appendCall(getContextPath() + "setInactiveColor",
205: strInactiveColor);
206: getScriptProxy().addScript(script);
207: return this ;
208: }
209:
210: /**
211: * Returns whether or not this stack is the active (expanded) stack
212: */
213: @SuppressWarnings("unchecked")
214: public void isFront(
215: org.directwebremoting.proxy.Callback<Boolean> callback) {
216: ScriptBuffer script = new ScriptBuffer();
217: String callbackPrefix = "";
218:
219: if (callback != null) {
220: callbackPrefix = "var reply = ";
221: }
222:
223: script
224: .appendCall(callbackPrefix + getContextPath()
225: + "isFront");
226:
227: if (callback != null) {
228: String key = org.directwebremoting.extend.CallbackHelper
229: .saveCallback(callback, Boolean.class);
230: script
231: .appendCall("__System.activateCallback", key,
232: "reply");
233: }
234:
235: getScriptProxy().addScript(script);
236: }
237:
238: }
|