KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > testapp > interactive > testscreen > WindowPaneTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.testapp.interactive.testscreen;
31
32 import nextapp.echo2.app.Column;
33 import nextapp.echo2.app.ContentPane;
34 import nextapp.echo2.app.Extent;
35 import nextapp.echo2.app.Insets;
36 import nextapp.echo2.app.Label;
37 import nextapp.echo2.app.SplitPane;
38 import nextapp.echo2.app.WindowPane;
39 import nextapp.echo2.app.event.ActionEvent;
40 import nextapp.echo2.app.event.ActionListener;
41 import nextapp.echo2.testapp.interactive.ButtonColumn;
42 import nextapp.echo2.testapp.interactive.InteractiveApp;
43 import nextapp.echo2.testapp.interactive.StyleUtil;
44 import nextapp.echo2.testapp.interactive.Styles;
45
46 /**
47  * Interactive test module for <code>WindowPane</code>s.
48  */

49 public class WindowPaneTest extends SplitPane {
50     
51     private WindowPane windowPane;
52     private ContentPane contentPane;
53     
54     public WindowPaneTest() {
55         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
56         setStyleName("DefaultResizable");
57         
58         Column groupContainerColumn = new Column();
59         groupContainerColumn.setCellSpacing(new Extent(5));
60         groupContainerColumn.setStyleName("TestControlsColumn");
61         add(groupContainerColumn);
62         
63         contentPane = new ContentPane();
64         add(contentPane);
65         windowPane = new WindowPane();
66         contentPane.add(windowPane);
67
68         ButtonColumn controlsColumn;
69         
70         // Content
71

72         controlsColumn = new ButtonColumn();
73         controlsColumn.add(new Label("Content"));
74         groupContainerColumn.add(controlsColumn);
75         
76         controlsColumn.addButton("Set Content = Small Label", new ActionListener() {
77             public void actionPerformed(ActionEvent e) {
78                 windowPane.removeAll();
79                 windowPane.add(new Label("Hello, World!"));
80             }
81         });
82         
83         controlsColumn.addButton("Set Content = Big Label", new ActionListener() {
84             public void actionPerformed(ActionEvent e) {
85                 windowPane.removeAll();
86                 windowPane.add(new Label(StyleUtil.QUASI_LATIN_TEXT_1));
87             }
88         });
89         
90         controlsColumn.addButton("Set Content = WindowPaneTest", new ActionListener() {
91             public void actionPerformed(ActionEvent e) {
92                 windowPane.removeAll();
93                 windowPane.add(new WindowPaneTest());
94             }
95         });
96         
97         controlsColumn.addButton("Set Content = Nothing", new ActionListener() {
98             public void actionPerformed(ActionEvent e) {
99                 windowPane.removeAll();
100             }
101         });
102         
103         controlsColumn.addButton("Add-Remove-Add", new ActionListener() {
104             public void actionPerformed(ActionEvent e) {
105                 windowPane.removeAll();
106                 Label label = new Label("Hello, World!");
107                 windowPane.add(label);
108                 windowPane.remove(label);
109                 windowPane.add(label);
110             }
111         });
112         
113         // Properties
114

115         controlsColumn = new ButtonColumn();
116         controlsColumn.add(new Label("Properties"));
117         groupContainerColumn.add(controlsColumn);
118         
119         controlsColumn.addButton("Set Style Name = Default", new ActionListener() {
120             public void actionPerformed(ActionEvent e) {
121                 windowPane.setStyleName("Default");
122             }
123         });
124         controlsColumn.addButton("Clear Style Name", new ActionListener() {
125             public void actionPerformed(ActionEvent e) {
126                 windowPane.setStyleName(null);
127             }
128         });
129
130         controlsColumn.addButton("Set Foreground", new ActionListener() {
131             public void actionPerformed(ActionEvent e) {
132                 windowPane.setForeground(StyleUtil.randomColor());
133             }
134         });
135         controlsColumn.addButton("Clear Foreground", new ActionListener() {
136             public void actionPerformed(ActionEvent e) {
137                 windowPane.setForeground(null);
138             }
139         });
140         controlsColumn.addButton("Set Background", new ActionListener() {
141             public void actionPerformed(ActionEvent e) {
142                 windowPane.setBackground(StyleUtil.randomColor());
143             }
144         });
145         controlsColumn.addButton("Clear Background", new ActionListener() {
146             public void actionPerformed(ActionEvent e) {
147                 windowPane.setBackground(null);
148             }
149         });
150         controlsColumn.addButton("Set Font", new ActionListener() {
151             public void actionPerformed(ActionEvent e) {
152                 windowPane.setFont(StyleUtil.randomFont());
153             }
154         });
155         controlsColumn.addButton("Clear Font", new ActionListener() {
156             public void actionPerformed(ActionEvent e) {
157                 windowPane.setFont(null);
158             }
159         });
160         controlsColumn.addButton("Set Background Image", new ActionListener() {
161             public void actionPerformed(ActionEvent e) {
162                 windowPane.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
163             }
164         });
165         controlsColumn.addButton("Clear Background Image", new ActionListener() {
166             public void actionPerformed(ActionEvent e) {
167                 windowPane.setBackgroundImage(null);
168             }
169         });
170         controlsColumn.addButton("Set Content Insets to 0", new ActionListener() {
171             public void actionPerformed(ActionEvent e) {
172                 windowPane.setInsets(new Insets(0));
173             }
174         });
175         controlsColumn.addButton("Set Content Insets to 5", new ActionListener() {
176             public void actionPerformed(ActionEvent e) {
177                 windowPane.setInsets(new Insets(5));
178             }
179         });
180         controlsColumn.addButton("Set Content Insets to 10/20/40/80", new ActionListener() {
181             public void actionPerformed(ActionEvent e) {
182                 windowPane.setInsets(new Insets(10, 20, 40, 80));
183             }
184         });
185         controlsColumn.addButton("Clear Content Insets", new ActionListener() {
186             public void actionPerformed(ActionEvent e) {
187                 windowPane.setInsets(null);
188             }
189         });
190
191         controlsColumn.addButton("Set Position Random", new ActionListener() {
192             public void actionPerformed(ActionEvent e) {
193                 windowPane.setPositionX(new Extent((int) (Math.random() * 600)));
194                 windowPane.setPositionY(new Extent((int) (Math.random() * 500)));
195             }
196         });
197         controlsColumn.addButton("Set Size Random", new ActionListener() {
198             public void actionPerformed(ActionEvent e) {
199                 windowPane.setWidth(new Extent(100 + (int) (Math.random() * 400)));
200                 windowPane.setHeight(new Extent(100 + (int) (Math.random() * 300)));
201             }
202         });
203         controlsColumn.addButton("Set Position&Size Random", new ActionListener() {
204             public void actionPerformed(ActionEvent e) {
205                 windowPane.setPositionX(new Extent((int) (Math.random() * 600)));
206                 windowPane.setPositionY(new Extent((int) (Math.random() * 500)));
207                 windowPane.setWidth(new Extent(100 + (int) (Math.random() * 400)));
208                 windowPane.setHeight(new Extent(100 + (int) (Math.random() * 300)));
209             }
210         });
211         
212         // Title-Related Properties
213

214         controlsColumn = new ButtonColumn();
215         controlsColumn.add(new Label("Properties"));
216         groupContainerColumn.add(controlsColumn);
217         
218         controlsColumn.addButton("Set Title", new ActionListener() {
219             public void actionPerformed(ActionEvent e) {
220                 windowPane.setTitle("Window Title");
221             }
222         });
223         controlsColumn.addButton("Set Title Long", new ActionListener() {
224             public void actionPerformed(ActionEvent e) {
225                 windowPane.setTitle("This is a fairly long window title that goes on for a little to long to see if " +
226                         "wrapping is handled properly and such.");
227             }
228         });
229         controlsColumn.addButton("Clear Title", new ActionListener() {
230             public void actionPerformed(ActionEvent e) {
231                 windowPane.setTitle(null);
232             }
233         });
234         controlsColumn.addButton("Set Title Height", new ActionListener() {
235             public void actionPerformed(ActionEvent e) {
236                 windowPane.setTitleHeight(new Extent(((int) (Math.random() * 24)) + 24));
237             }
238         });
239         controlsColumn.addButton("Clear Title Height", new ActionListener() {
240             public void actionPerformed(ActionEvent e) {
241                 windowPane.setTitleHeight(null);
242             }
243         });
244         controlsColumn.addButton("Set Title Insets to 0", new ActionListener() {
245             public void actionPerformed(ActionEvent e) {
246                 windowPane.setTitleInsets(new Insets(0));
247             }
248         });
249         controlsColumn.addButton("Set Title Insets to 5", new ActionListener() {
250             public void actionPerformed(ActionEvent e) {
251                 windowPane.setTitleInsets(new Insets(5));
252             }
253         });
254         controlsColumn.addButton("Set Title Insets to 10/20/40/80", new ActionListener() {
255             public void actionPerformed(ActionEvent e) {
256                 windowPane.setTitleInsets(new Insets(10, 20, 40, 80));
257             }
258         });
259         controlsColumn.addButton("Clear Title Insets", new ActionListener() {
260             public void actionPerformed(ActionEvent e) {
261                 windowPane.setTitleInsets(null);
262             }
263         });
264         controlsColumn.addButton("Set Title Foreground", new ActionListener() {
265             public void actionPerformed(ActionEvent e) {
266                 windowPane.setTitleForeground(StyleUtil.randomColor());
267             }
268         });
269         controlsColumn.addButton("Clear Title Foreground", new ActionListener() {
270             public void actionPerformed(ActionEvent e) {
271                 windowPane.setTitleForeground(null);
272             }
273         });
274         controlsColumn.addButton("Set Title Background", new ActionListener() {
275             public void actionPerformed(ActionEvent e) {
276                 windowPane.setTitleBackground(StyleUtil.randomColor());
277             }
278         });
279         controlsColumn.addButton("Clear Title Background", new ActionListener() {
280             public void actionPerformed(ActionEvent e) {
281                 windowPane.setTitleBackground(null);
282             }
283         });
284         controlsColumn.addButton("Set Title Font", new ActionListener() {
285             public void actionPerformed(ActionEvent e) {
286                 windowPane.setTitleFont(StyleUtil.randomFont());
287             }
288         });
289         controlsColumn.addButton("Clear Title Font", new ActionListener() {
290             public void actionPerformed(ActionEvent e) {
291                 windowPane.setTitleFont(null);
292             }
293         });
294
295         // Integration Tests
296

297         controlsColumn = new ButtonColumn();
298         controlsColumn.add(new Label("Content"));
299         groupContainerColumn.add(controlsColumn);
300
301         controlsColumn.addButton("Add Component", new ActionListener() {
302             public void actionPerformed(ActionEvent e) {
303                 if (contentPane.getComponentCount() == 0) {
304                     contentPane.add(windowPane);
305                 }
306             }
307         });
308
309         controlsColumn.addButton("Remove Component", new ActionListener() {
310             public void actionPerformed(ActionEvent e) {
311                 contentPane.remove(windowPane);
312             }
313         });
314
315         controlsColumn.addButton("Enable Component", new ActionListener() {
316             public void actionPerformed(ActionEvent e) {
317                 windowPane.setEnabled(true);
318             }
319         });
320
321         controlsColumn.addButton("Disable Component", new ActionListener() {
322             public void actionPerformed(ActionEvent e) {
323                 windowPane.setEnabled(false);
324             }
325         });
326
327         controlsColumn.addButton("Add Modal WindowPane", new ActionListener() {
328             public void actionPerformed(ActionEvent e) {
329                 WindowPane modalWindow = new WindowPane();
330                 modalWindow.setTitle("Blocking Modal WindowPane");
331                 modalWindow.setModal(true);
332                 InteractiveApp.getApp().getDefaultWindow().getContent().add(modalWindow);
333             }
334         });
335     }
336 }
337
Popular Tags