001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Button;
033: import nextapp.echo2.app.CheckBox;
034: import nextapp.echo2.app.Column;
035: import nextapp.echo2.app.Component;
036: import nextapp.echo2.app.ContentPane;
037: import nextapp.echo2.app.Extent;
038: import nextapp.echo2.app.Grid;
039: import nextapp.echo2.app.IllegalChildException;
040: import nextapp.echo2.app.Label;
041: import nextapp.echo2.app.ListBox;
042: import nextapp.echo2.app.PasswordField;
043: import nextapp.echo2.app.RadioButton;
044: import nextapp.echo2.app.Row;
045: import nextapp.echo2.app.SelectField;
046: import nextapp.echo2.app.SplitPane;
047: import nextapp.echo2.app.TextArea;
048: import nextapp.echo2.app.TextField;
049: import nextapp.echo2.app.WindowPane;
050: import nextapp.echo2.app.event.ActionEvent;
051: import nextapp.echo2.app.event.ActionListener;
052: import nextapp.echo2.app.list.DefaultListModel;
053: import nextapp.echo2.app.list.ListModel;
054: import nextapp.echo2.testapp.interactive.InteractiveApp;
055:
056: /**
057: * A test to ensure proper rendering when arbitrary components are
058: * user-selected together in parent child relationships.
059: */
060: public class HierarchyTest extends SplitPane {
061:
062: private abstract class ComponentEntry {
063:
064: public abstract String getName();
065:
066: public abstract Component newInstance();
067:
068: public String toString() {
069: return getName();
070: }
071: }
072:
073: private ComponentEntry buttonEntry = new ComponentEntry() {
074: public String getName() {
075: return "Button";
076: }
077:
078: public Component newInstance() {
079: Button button = new Button("Button");
080: button.setStyleName("Default");
081: return button;
082: }
083: };
084:
085: private ComponentEntry checkBoxEntry = new ComponentEntry() {
086: public String getName() {
087: return "CheckBox";
088: }
089:
090: public Component newInstance() {
091: CheckBox checkBox = new CheckBox("CheckBox");
092: checkBox.setStyleName("Default");
093: return checkBox;
094: }
095: };
096:
097: private ComponentEntry columnEntry = new ComponentEntry() {
098: public String getName() {
099: return "Column";
100: }
101:
102: public Component newInstance() {
103: Column column = new Column();
104: return column;
105: }
106: };
107:
108: private ComponentEntry contentPaneEntry = new ComponentEntry() {
109: public String getName() {
110: return "ContentPane";
111: }
112:
113: public Component newInstance() {
114: ContentPane contentPane = new ContentPane();
115: return contentPane;
116: }
117: };
118:
119: private ComponentEntry gridEntry = new ComponentEntry() {
120: public String getName() {
121: return "Grid";
122: }
123:
124: public Component newInstance() {
125: Grid grid = new Grid();
126: return grid;
127: }
128: };
129:
130: private ComponentEntry labelEntry = new ComponentEntry() {
131: public String getName() {
132: return "Label";
133: }
134:
135: public Component newInstance() {
136: return new Label("Label");
137: }
138: };
139:
140: private ComponentEntry listBoxEntry = new ComponentEntry() {
141: public String getName() {
142: return "ListBox";
143: }
144:
145: public Component newInstance() {
146: ListBox listBox = new ListBox(new String[] { "alpha",
147: "bravo", "charlie", "delta" });
148: listBox.setStyleName("Default");
149: return listBox;
150: }
151: };
152:
153: private ComponentEntry passwordFieldEntry = new ComponentEntry() {
154: public String getName() {
155: return "PasswordField";
156: }
157:
158: public Component newInstance() {
159: PasswordField passwordField = new PasswordField();
160: passwordField.setStyleName("Default");
161: passwordField.setText("Password");
162: return passwordField;
163: }
164: };
165:
166: private ComponentEntry radioButtonEntry = new ComponentEntry() {
167: public String getName() {
168: return "RadioButton";
169: }
170:
171: public Component newInstance() {
172: RadioButton radioButton = new RadioButton("RadioButton");
173: radioButton.setStyleName("Default");
174: return radioButton;
175: }
176: };
177:
178: private ComponentEntry rowEntry = new ComponentEntry() {
179: public String getName() {
180: return "Row";
181: }
182:
183: public Component newInstance() {
184: Row row = new Row();
185: return row;
186: }
187: };
188:
189: private ComponentEntry selectFieldEntry = new ComponentEntry() {
190: public String getName() {
191: return "SelectField";
192: }
193:
194: public Component newInstance() {
195: SelectField selectField = new SelectField(new String[] {
196: "alpha", "bravo", "charlie", "delta" });
197: selectField.setStyleName("Default");
198: return selectField;
199: }
200: };
201:
202: private ComponentEntry splitPaneEntry = new ComponentEntry() {
203: public String getName() {
204: return "SplitPane";
205: }
206:
207: public Component newInstance() {
208: SplitPane splitPane = new SplitPane();
209: splitPane.setStyleName("DefaultResizable");
210: return splitPane;
211: }
212: };
213:
214: private ComponentEntry textAreaEntry = new ComponentEntry() {
215: public String getName() {
216: return "TextArea";
217: }
218:
219: public Component newInstance() {
220: TextArea textArea = new TextArea();
221: textArea.setStyleName("Default");
222: textArea.setText("TextArea");
223: return textArea;
224: }
225: };
226:
227: private ComponentEntry textFieldEntry = new ComponentEntry() {
228: public String getName() {
229: return "TextField";
230: }
231:
232: public Component newInstance() {
233: TextField textField = new TextField();
234: textField.setStyleName("Default");
235: textField.setText("TextField");
236: return textField;
237: }
238: };
239:
240: private ComponentEntry windowPaneEntry = new ComponentEntry() {
241: public String getName() {
242: return "WindowPane";
243: }
244:
245: public Component newInstance() {
246: WindowPane windowPane = new WindowPane();
247: windowPane.setStyleName("Default");
248: return windowPane;
249: }
250: };
251:
252: private ListModel componentListModel = new DefaultListModel(
253: new Object[] { "(None)", buttonEntry, checkBoxEntry,
254: columnEntry, contentPaneEntry, gridEntry,
255: labelEntry, listBoxEntry, passwordFieldEntry,
256: radioButtonEntry, rowEntry, selectFieldEntry,
257: splitPaneEntry, textAreaEntry, textFieldEntry,
258: windowPaneEntry });
259:
260: private Component parentComponentInstance;
261: private Component[] childComponentInstances;
262: private SelectField parentSelectField;
263: private SelectField[] childSelectFields;
264: private ContentPane testPane;
265:
266: public HierarchyTest() {
267: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
268: Extent.PX));
269: setStyleName("DefaultResizable");
270:
271: Column controlGroupsColumn = new Column();
272: controlGroupsColumn.setCellSpacing(new Extent(5));
273: controlGroupsColumn.setStyleName("TestControlsColumn");
274: add(controlGroupsColumn);
275:
276: Column parentSelectColumn = new Column();
277: controlGroupsColumn.add(parentSelectColumn);
278:
279: parentSelectColumn.add(new Label("Parent"));
280:
281: parentSelectField = new SelectField(componentListModel);
282: parentSelectField.addActionListener(new ActionListener() {
283: public void actionPerformed(ActionEvent e) {
284: if (parentSelectField.getSelectedItem() instanceof ComponentEntry) {
285: parentComponentInstance = ((ComponentEntry) parentSelectField
286: .getSelectedItem()).newInstance();
287: } else {
288: parentComponentInstance = null;
289: }
290: update();
291: }
292: });
293: parentSelectColumn.add(parentSelectField);
294:
295: childSelectFields = new SelectField[4];
296: childComponentInstances = new Component[4];
297: for (int i = 0; i < childSelectFields.length; ++i) {
298: Column childSelectColumn = new Column();
299: controlGroupsColumn.add(childSelectColumn);
300:
301: childSelectColumn.add(new Label("Child #" + i));
302:
303: final int childNumber = i;
304: childSelectFields[i] = new SelectField(componentListModel);
305: childSelectFields[i]
306: .addActionListener(new ActionListener() {
307: public void actionPerformed(ActionEvent e) {
308: if (childSelectFields[childNumber]
309: .getSelectedItem() instanceof ComponentEntry) {
310: childComponentInstances[childNumber] = ((ComponentEntry) childSelectFields[childNumber]
311: .getSelectedItem())
312: .newInstance();
313: } else {
314: childComponentInstances[childNumber] = null;
315: }
316: update();
317: }
318: });
319: childSelectColumn.add(childSelectFields[i]);
320: }
321:
322: testPane = new ContentPane();
323: add(testPane);
324: }
325:
326: public void update() {
327: testPane.removeAll();
328: if (parentComponentInstance == null) {
329: return;
330: }
331: parentComponentInstance.removeAll();
332: for (int i = 0; i < childComponentInstances.length; ++i) {
333: if (childComponentInstances[i] != null) {
334: try {
335: parentComponentInstance
336: .add(childComponentInstances[i]);
337: } catch (IllegalChildException ex) {
338: InteractiveApp.getApp().consoleWrite(ex.toString());
339: }
340: }
341: }
342: testPane.add(parentComponentInstance);
343: }
344: }
|