KickJava   Java API By Example, From Geeks To Geeks.

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


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.Button;
33 import nextapp.echo2.app.Color;
34 import nextapp.echo2.app.ContentPane;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.FloatingPane;
37 import nextapp.echo2.app.Insets;
38 import nextapp.echo2.app.Label;
39 import nextapp.echo2.app.SplitPane;
40 import nextapp.echo2.app.WindowPane;
41 import nextapp.echo2.app.event.ActionEvent;
42 import nextapp.echo2.app.event.ActionListener;
43 import nextapp.echo2.app.layout.SplitPaneLayoutData;
44 import nextapp.echo2.testapp.interactive.ButtonColumn;
45 import nextapp.echo2.testapp.interactive.InteractiveApp;
46 import nextapp.echo2.testapp.interactive.StyleUtil;
47
48 /**
49  * Interactive test module for <code>ContentPane</code>s.
50  */

51 public class ContentPaneTest extends SplitPane {
52
53     public ContentPaneTest() {
54         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
55         setStyleName("DefaultResizable");
56         
57         final ContentPane rootContentPane = InteractiveApp.getApp().getDefaultWindow().getContent();
58         final Label contentLabel = new Label(StyleUtil.QUASI_LATIN_TEXT_1 + StyleUtil.QUASI_LATIN_TEXT_1);
59         
60         ButtonColumn controlsColumn = new ButtonColumn();
61         controlsColumn.setStyleName("TestControlsColumn");
62         add(controlsColumn);
63         
64         final ContentPane testContentPane = new ContentPane();
65         add(testContentPane);
66
67         controlsColumn.add(new Label("Root Content Pane"));
68
69         controlsColumn.addButton("Reset", new ActionListener() {
70             public void actionPerformed(ActionEvent e) {
71                 rootContentPane.setBackground(null);
72                 rootContentPane.setForeground(null);
73                 rootContentPane.setFont(null);
74             }
75         });
76         controlsColumn.addButton("Change Background", new ActionListener() {
77             public void actionPerformed(ActionEvent e) {
78                 rootContentPane.setBackground(StyleUtil.randomColor());
79             }
80         });
81         controlsColumn.addButton("Change Foreground", new ActionListener() {
82             public void actionPerformed(ActionEvent e) {
83                 rootContentPane.setForeground(StyleUtil.randomColor());
84             }
85         });
86         controlsColumn.addButton("Change Font", new ActionListener() {
87             public void actionPerformed(ActionEvent e) {
88                 rootContentPane.setFont(StyleUtil.randomFont());
89             }
90         });
91         
92         controlsColumn.add(new Label("Test Content Pane"));
93         
94         controlsColumn.addButton("Reset", new ActionListener() {
95             public void actionPerformed(ActionEvent e) {
96                 testContentPane.setBackground(null);
97                 testContentPane.setForeground(null);
98                 testContentPane.setFont(null);
99             }
100         });
101         controlsColumn.addButton("Change Background", new ActionListener() {
102             public void actionPerformed(ActionEvent e) {
103                 testContentPane.setBackground(StyleUtil.randomColor());
104             }
105         });
106         controlsColumn.addButton("Change Foreground", new ActionListener() {
107             public void actionPerformed(ActionEvent e) {
108                 testContentPane.setForeground(StyleUtil.randomColor());
109             }
110         });
111         controlsColumn.addButton("Change Font", new ActionListener() {
112             public void actionPerformed(ActionEvent e) {
113                 testContentPane.setFont(StyleUtil.randomFont());
114             }
115         });
116         
117         controlsColumn.addButton("Add Label", new ActionListener() {
118             public void actionPerformed(ActionEvent e) {
119                 removeAllContent(testContentPane);
120                 testContentPane.add(contentLabel);
121             }
122         });
123         controlsColumn.addButton("Add SplitPane", new ActionListener() {
124             public void actionPerformed(ActionEvent e) {
125                 removeAllContent(testContentPane);
126                 SplitPane splitPane = new SplitPane();
127                 splitPane.setResizable(true);
128                 
129                 Label label;
130                 SplitPaneLayoutData layoutData;
131
132                 layoutData = new SplitPaneLayoutData();
133                 layoutData.setBackground(new Color(0xafafff));
134                 label = new Label(StyleUtil.QUASI_LATIN_TEXT_1);
135                 label.setLayoutData(layoutData);
136                 splitPane.add(label);
137
138                 layoutData = new SplitPaneLayoutData();
139                 layoutData.setBackground(new Color(0xafffaf));
140                 label = new Label(StyleUtil.QUASI_LATIN_TEXT_1);
141                 label.setLayoutData(layoutData);
142                 splitPane.add(label);
143
144                 testContentPane.add(splitPane);
145             }
146         });
147         controlsColumn.addButton("Add SplitPane / ContentPane / Button", new ActionListener() {
148             public void actionPerformed(ActionEvent e) {
149                 removeAllContent(testContentPane);
150                 SplitPane splitPane = new SplitPane();
151                 splitPane.setResizable(true);
152                 
153                 Label label;
154                 SplitPaneLayoutData layoutData;
155
156                 layoutData = new SplitPaneLayoutData();
157                 layoutData.setBackground(new Color(0xafafff));
158                 ContentPane subContentPane = new ContentPane();
159                 subContentPane.setLayoutData(layoutData);
160                 splitPane.add(subContentPane);
161                 
162                 SplitPane splitPane2 = new SplitPane(SplitPane.ORIENTATION_VERTICAL);
163                 subContentPane.add(splitPane2);
164                 
165                 ContentPane subContentPane2 = new ContentPane();
166                 splitPane2.add(subContentPane2);
167                 subContentPane2.add(new Label("Test!"));
168                 
169                 ContentPane subContentPane3 = new ContentPane();
170                 splitPane2.add(subContentPane3);
171                 
172                 
173                 final Button button = new Button("Alpha");
174                 button.addActionListener(new ActionListener() {
175                     public void actionPerformed(ActionEvent e) {
176                         button.setText("Alpha".equals(button.getText()) ? "Omega" : "Alpha");
177                     }
178                 });
179                 subContentPane3.add(button);
180
181                 layoutData = new SplitPaneLayoutData();
182                 layoutData.setBackground(new Color(0xafffaf));
183                 label = new Label(StyleUtil.QUASI_LATIN_TEXT_1);
184                 label.setLayoutData(layoutData);
185                 splitPane.add(label);
186
187                 testContentPane.add(splitPane);
188             }
189         });
190         
191         controlsColumn.addButton("Add WindowPane", new ActionListener() {
192             public void actionPerformed(ActionEvent e) {
193                 testContentPane.add(new WindowPane());
194             }
195         });
196         controlsColumn.addButton("Set Horizontal Scroll = null", new ActionListener() {
197             public void actionPerformed(ActionEvent e) {
198                 testContentPane.setHorizontalScroll(null);
199             }
200         });
201         controlsColumn.addButton("Set Horizontal Scroll = 0", new ActionListener() {
202             public void actionPerformed(ActionEvent e) {
203                 testContentPane.setHorizontalScroll(new Extent(0));
204             }
205         });
206         controlsColumn.addButton("Set Horizontal Scroll = 50", new ActionListener() {
207             public void actionPerformed(ActionEvent e) {
208                 testContentPane.setHorizontalScroll(new Extent(50));
209             }
210         });
211         controlsColumn.addButton("Set Horizontal Scroll = 100", new ActionListener() {
212             public void actionPerformed(ActionEvent e) {
213                 testContentPane.setHorizontalScroll(new Extent(100));
214             }
215         });
216         controlsColumn.addButton("Set Horizontal Scroll = End (-1)", new ActionListener() {
217             public void actionPerformed(ActionEvent e) {
218                 testContentPane.setHorizontalScroll(new Extent(-1));
219             }
220         });
221
222         controlsColumn.addButton("Set Vertical Scroll = null", new ActionListener() {
223             public void actionPerformed(ActionEvent e) {
224                 testContentPane.setVerticalScroll(null);
225             }
226         });
227         controlsColumn.addButton("Set Vertical Scroll = 0", new ActionListener() {
228             public void actionPerformed(ActionEvent e) {
229                 testContentPane.setVerticalScroll(new Extent(0));
230             }
231         });
232         controlsColumn.addButton("Set Vertical Scroll = 50", new ActionListener() {
233             public void actionPerformed(ActionEvent e) {
234                 testContentPane.setVerticalScroll(new Extent(50));
235             }
236         });
237         controlsColumn.addButton("Set Vertical Scroll = 100", new ActionListener() {
238             public void actionPerformed(ActionEvent e) {
239                 testContentPane.setVerticalScroll(new Extent(100));
240             }
241         });
242         controlsColumn.addButton("Set Vertical Scroll = End (-1)", new ActionListener() {
243             public void actionPerformed(ActionEvent e) {
244                 testContentPane.setVerticalScroll(new Extent(-1));
245             }
246         });
247
248         controlsColumn.addButton("Insets -> null", new ActionListener() {
249             public void actionPerformed(ActionEvent e) {
250                 testContentPane.setInsets(null);
251             }
252         });
253         controlsColumn.addButton("Insets -> 0px", new ActionListener() {
254             public void actionPerformed(ActionEvent e) {
255                 testContentPane.setInsets(new Insets(0));
256             }
257         });
258         controlsColumn.addButton("Insets -> 5px", new ActionListener() {
259             public void actionPerformed(ActionEvent e) {
260                 testContentPane.setInsets(new Insets(5));
261             }
262         });
263         controlsColumn.addButton("Insets -> 10/20/30/40px", new ActionListener() {
264             public void actionPerformed(ActionEvent e) {
265                 testContentPane.setInsets(new Insets(10, 20, 30, 40));
266             }
267         });
268     }
269
270     private void removeAllContent(ContentPane contentPane) {
271         int count = contentPane.getComponentCount();
272         for (int i = count - 1; i >= 0; --i) {
273             if (contentPane.getComponent(i) instanceof FloatingPane) {
274                 continue;
275             }
276             contentPane.remove(i);
277         }
278     }
279 }
280
Popular Tags