KickJava   Java API By Example, From Geeks To Geeks.

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


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.Composite;
33 import nextapp.echo2.app.Extent;
34 import nextapp.echo2.app.Grid;
35 import nextapp.echo2.app.Insets;
36 import nextapp.echo2.app.Label;
37 import nextapp.echo2.app.SplitPane;
38 import nextapp.echo2.app.event.ActionEvent;
39 import nextapp.echo2.app.event.ActionListener;
40 import nextapp.echo2.testapp.interactive.ButtonColumn;
41 import nextapp.echo2.testapp.interactive.StyleUtil;
42
43 /**
44  * Interactive test for the <code>Container</code> component.
45  */

46 public class CompositeTest extends SplitPane {
47     
48     public CompositeTest() {
49         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
50         setStyleName("DefaultResizable");
51         
52         ButtonColumn controlsColumn = new ButtonColumn();
53         controlsColumn.setStyleName("TestControlsColumn");
54         add(controlsColumn);
55         
56         final Composite container = new Composite() { };
57         add(container);
58
59         controlsColumn.addButton("Reset", new ActionListener() {
60             public void actionPerformed(ActionEvent e) {
61                 container.setBackground(null);
62                 container.setForeground(null);
63                 container.setFont(null);
64             }
65         });
66         controlsColumn.addButton("Change Background", new ActionListener() {
67             public void actionPerformed(ActionEvent e) {
68                 container.setBackground(StyleUtil.randomColor());
69             }
70         });
71         controlsColumn.addButton("Change Foreground", new ActionListener() {
72             public void actionPerformed(ActionEvent e) {
73                 container.setForeground(StyleUtil.randomColor());
74             }
75         });
76         controlsColumn.addButton("Change Font", new ActionListener() {
77             public void actionPerformed(ActionEvent e) {
78                 container.setFont(StyleUtil.randomFont());
79             }
80         });
81         controlsColumn.addButton("Set Content (Label)", new ActionListener() {
82             public void actionPerformed(ActionEvent e) {
83                 if (container.getComponentCount() > 0) {
84                     container.removeAll();
85                 }
86                 container.add(new Label("Hello, world!"));
87             }
88         });
89         controlsColumn.addButton("Set Content (Long Label)", new ActionListener() {
90             public void actionPerformed(ActionEvent e) {
91                 if (container.getComponentCount() > 0) {
92                     container.removeAll();
93                 }
94                 container.add(new Label(StyleUtil.QUASI_LATIN_TEXT_1));
95             }
96         });
97         controlsColumn.addButton("Set Content (Grid)", new ActionListener() {
98             public void actionPerformed(ActionEvent e) {
99                 if (container.getComponentCount() > 0) {
100                     container.removeAll();
101                 }
102                 Grid grid = new Grid();
103                 grid.setBorder(StyleUtil.randomBorder());
104                 grid.setInsets(new Insets(StyleUtil.randomExtent(8)));
105                 grid.add(new Label("A label"));
106                 grid.add(new Label("A label"));
107                 grid.add(new Label("A label"));
108                 grid.add(new Label("A label"));
109                 grid.add(new Label("A label"));
110                 container.add(grid);
111             }
112         });
113         controlsColumn.addButton("Clear Content", new ActionListener() {
114             public void actionPerformed(ActionEvent e) {
115                 container.removeAll();
116             }
117         });
118         controlsColumn.addButton("Add Component", new ActionListener() {
119             public void actionPerformed(ActionEvent e) {
120                 if (container.getParent() == null) {
121                     CompositeTest.this.add(container);
122                 }
123             }
124         });
125         controlsColumn.addButton("Remove Component", new ActionListener() {
126             public void actionPerformed(ActionEvent e) {
127                 if (container.getParent() != null) {
128                     CompositeTest.this.remove(container);
129                 }
130             }
131         });
132     }
133 }
134
Popular Tags