KickJava   Java API By Example, From Geeks To Geeks.

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


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

48 public class PanelTest extends SplitPane {
49     
50     public PanelTest() {
51         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
52         setStyleName("DefaultResizable");
53         
54         ButtonColumn controlsColumn = new ButtonColumn();
55         controlsColumn.setStyleName("TestControlsColumn");
56         add(controlsColumn);
57         
58         final Panel panel = new Panel() { };
59         add(panel);
60
61         controlsColumn.addButton("Reset", new ActionListener() {
62             public void actionPerformed(ActionEvent e) {
63                 panel.setBackground(null);
64                 panel.setForeground(null);
65                 panel.setFont(null);
66             }
67         });
68         controlsColumn.addButton("Change Background", new ActionListener() {
69             public void actionPerformed(ActionEvent e) {
70                 panel.setBackground(StyleUtil.randomColor());
71             }
72         });
73         controlsColumn.addButton("Change Foreground", new ActionListener() {
74             public void actionPerformed(ActionEvent e) {
75                 panel.setForeground(StyleUtil.randomColor());
76             }
77         });
78         controlsColumn.addButton("Change Font", new ActionListener() {
79             public void actionPerformed(ActionEvent e) {
80                 panel.setFont(StyleUtil.randomFont());
81             }
82         });
83         controlsColumn.addButton("Set Content (Label)", new ActionListener() {
84             public void actionPerformed(ActionEvent e) {
85                 if (panel.getComponentCount() > 0) {
86                     panel.removeAll();
87                 }
88                 panel.add(new Label("Hello, world!"));
89             }
90         });
91         controlsColumn.addButton("Set Content (Long Label)", new ActionListener() {
92             public void actionPerformed(ActionEvent e) {
93                 if (panel.getComponentCount() > 0) {
94                     panel.removeAll();
95                 }
96                 panel.add(new Label(StyleUtil.QUASI_LATIN_TEXT_1));
97             }
98         });
99         controlsColumn.addButton("Set Content (Grid)", new ActionListener() {
100             public void actionPerformed(ActionEvent e) {
101                 if (panel.getComponentCount() > 0) {
102                     panel.removeAll();
103                 }
104                 Grid grid = new Grid();
105                 grid.setBorder(StyleUtil.randomBorder());
106                 grid.setInsets(new Insets(StyleUtil.randomExtent(8)));
107                 grid.add(new Label("A label"));
108                 grid.add(new Label("A label"));
109                 grid.add(new Label("A label"));
110                 grid.add(new Label("A label"));
111                 grid.add(new Label("A label"));
112                 panel.add(grid);
113             }
114         });
115         controlsColumn.addButton("Clear Content", new ActionListener() {
116             public void actionPerformed(ActionEvent e) {
117                 panel.removeAll();
118             }
119         });
120         controlsColumn.addButton("Add Component", new ActionListener() {
121             public void actionPerformed(ActionEvent e) {
122                 if (panel.getParent() == null) {
123                     PanelTest.this.add(panel);
124                 }
125             }
126         });
127         controlsColumn.addButton("Remove Component", new ActionListener() {
128             public void actionPerformed(ActionEvent e) {
129                 if (panel.getParent() != null) {
130                     PanelTest.this.remove(panel);
131                 }
132             }
133         });
134         controlsColumn.addButton("Set Border (All Attributes)", new ActionListener() {
135             public void actionPerformed(ActionEvent e) {
136                 panel.setBorder(StyleUtil.randomBorder());
137             }
138         });
139         controlsColumn.addButton("Set Border Color", new ActionListener() {
140             public void actionPerformed(ActionEvent e) {
141                 Border border = panel.getBorder();
142                 if (border == null) {
143                     border = new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID);
144                 }
145                 panel.setBorder(new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle()));
146             }
147         });
148         controlsColumn.addButton("Set Border Size", new ActionListener() {
149             public void actionPerformed(ActionEvent e) {
150                 panel.setBorder(StyleUtil.nextBorderSize(panel.getBorder()));
151             }
152         });
153         controlsColumn.addButton("Set Border Style", new ActionListener() {
154             public void actionPerformed(ActionEvent e) {
155                 panel.setBorder(StyleUtil.nextBorderStyle(panel.getBorder()));
156             }
157         });
158         controlsColumn.addButton("Remove Border", new ActionListener() {
159             public void actionPerformed(ActionEvent e) {
160                 panel.setBorder(null);
161             }
162         });
163         controlsColumn.addButton("Insets -> null", new ActionListener() {
164             public void actionPerformed(ActionEvent e) {
165                 panel.setInsets(null);
166             }
167         });
168         controlsColumn.addButton("Insets -> 0px", new ActionListener() {
169             public void actionPerformed(ActionEvent e) {
170                 panel.setInsets(new Insets(0));
171             }
172         });
173         controlsColumn.addButton("Insets -> 5px", new ActionListener() {
174             public void actionPerformed(ActionEvent e) {
175                 panel.setInsets(new Insets(5));
176             }
177         });
178         controlsColumn.addButton("Insets -> 10/20/30/40px", new ActionListener() {
179             public void actionPerformed(ActionEvent e) {
180                 panel.setInsets(new Insets(10, 20, 30, 40));
181             }
182         });
183     }
184 }
185
Popular Tags