KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.Insets;
37 import nextapp.echo2.app.Label;
38 import nextapp.echo2.app.Column;
39 import nextapp.echo2.app.SplitPane;
40 import nextapp.echo2.app.event.ActionEvent;
41 import nextapp.echo2.app.event.ActionListener;
42 import nextapp.echo2.app.layout.ColumnLayoutData;
43 import nextapp.echo2.app.layout.SplitPaneLayoutData;
44 import nextapp.echo2.testapp.interactive.ButtonColumn;
45 import nextapp.echo2.testapp.interactive.StyleUtil;
46 import nextapp.echo2.testapp.interactive.Styles;
47
48 public class ColumnTest extends SplitPane {
49     
50     private static final SplitPaneLayoutData insetLayoutData;
51     static {
52         insetLayoutData = new SplitPaneLayoutData();
53         insetLayoutData.setInsets(new Insets(10));
54     }
55
56     private int nextValue = 0;
57     
58     public ColumnTest() {
59         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250));
60         setStyleName("DefaultResizable");
61         
62         ButtonColumn controlsColumn = new ButtonColumn();
63         controlsColumn.setStyleName("TestControlsColumn");
64         add(controlsColumn);
65
66         final Column testColumn = new Column();
67         testColumn.setBorder(new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID));
68         testColumn.setLayoutData(insetLayoutData);
69         add(testColumn);
70         
71         controlsColumn.addButton("Add Item (at beginning)", new ActionListener() {
72             public void actionPerformed(ActionEvent e) {
73                 testColumn.add(new Label("Added item [" + nextValue++ + "]"), 0);
74             }
75         });
76         controlsColumn.addButton("Add Item (at end)", new ActionListener() {
77             public void actionPerformed(ActionEvent e) {
78                 testColumn.add(new Label("Added item [" + nextValue++ + "]"));
79             }
80         });
81         controlsColumn.addButton("Add-Remove-Add Item (at end)", new ActionListener() {
82             public void actionPerformed(ActionEvent e) {
83                 Label label = new Label("Added item [" + nextValue++ + "]");
84                 testColumn.add(label);
85                 testColumn.remove(label);
86                 testColumn.add(label);
87             }
88         });
89         controlsColumn.addButton("Remove Last Item", new ActionListener() {
90             public void actionPerformed(ActionEvent e) {
91                 if (testColumn.getComponentCount() > 0) {
92                     testColumn.remove(testColumn.getComponentCount() - 1);
93                 }
94             }
95         });
96         controlsColumn.addButton("Add Some Items, Remove Some Items", new ActionListener() {
97             public void actionPerformed(ActionEvent e) {
98                 int count = 1 + ((int) (Math.random() * 10));
99                 for (int i = 0; i < count; ++i) {
100                     int componentCount = testColumn.getComponentCount();
101                     if (componentCount > 0 && ((int) (Math.random() * 2)) == 0) {
102                         // Perform remove.
103
int position = (int) (Math.random() * componentCount);
104                         testColumn.remove(position);
105                     } else {
106                         // Perform add.
107
int position = (int) (Math.random() * (componentCount + 1));
108                         testColumn.add(new Label("Added item [" + nextValue++ + "]"), position);
109                     }
110                 }
111             }
112         });
113         controlsColumn.addButton("Randomly Remove and Re-insert Item", new ActionListener() {
114             public void actionPerformed(ActionEvent e) {
115                 int itemCount = testColumn.getComponentCount();
116                 if (itemCount == 0) {
117                     return;
118                 }
119                 Component item = testColumn.getComponent((int) (Math.random() * itemCount));
120                 testColumn.remove(item);
121                 testColumn.add(item, (int) (Math.random() * (itemCount - 1)));
122             }
123         });
124         controlsColumn.addButton("Set Foreground", new ActionListener() {
125             public void actionPerformed(ActionEvent e) {
126                 testColumn.setForeground(StyleUtil.randomColor());
127             }
128         });
129         controlsColumn.addButton("Clear Foreground", new ActionListener() {
130             public void actionPerformed(ActionEvent e) {
131                 testColumn.setForeground(null);
132             }
133         });
134         controlsColumn.addButton("Set Background", new ActionListener() {
135             public void actionPerformed(ActionEvent e) {
136                 testColumn.setBackground(StyleUtil.randomColor());
137             }
138         });
139         controlsColumn.addButton("Clear Background", new ActionListener() {
140             public void actionPerformed(ActionEvent e) {
141                 testColumn.setBackground(null);
142             }
143         });
144         controlsColumn.addButton("Set Border (All Attributes)", new ActionListener() {
145             public void actionPerformed(ActionEvent e) {
146                 testColumn.setBorder(StyleUtil.randomBorder());
147             }
148         });
149         controlsColumn.addButton("Set Border Color", new ActionListener() {
150             public void actionPerformed(ActionEvent e) {
151                 Border border = testColumn.getBorder();
152                 if (border == null) {
153                     border = new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID);
154                 }
155                 testColumn.setBorder(new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle()));
156             }
157         });
158         controlsColumn.addButton("Set Border Size", new ActionListener() {
159             public void actionPerformed(ActionEvent e) {
160                 testColumn.setBorder(StyleUtil.nextBorderSize(testColumn.getBorder()));
161             }
162         });
163         controlsColumn.addButton("Set Border Style", new ActionListener() {
164             public void actionPerformed(ActionEvent e) {
165                 testColumn.setBorder(StyleUtil.nextBorderStyle(testColumn.getBorder()));
166             }
167         });
168         controlsColumn.addButton("Remove Border", new ActionListener() {
169             public void actionPerformed(ActionEvent e) {
170                 testColumn.setBorder(null);
171             }
172         });
173         controlsColumn.addButton("Cell Spacing -> 0px", new ActionListener() {
174             public void actionPerformed(ActionEvent e) {
175                 testColumn.setCellSpacing(new Extent(0, Extent.PX));
176             }
177         });
178         controlsColumn.addButton("Cell Spacing -> 2px", new ActionListener() {
179             public void actionPerformed(ActionEvent e) {
180                 testColumn.setCellSpacing(new Extent(2, Extent.PX));
181             }
182         });
183         controlsColumn.addButton("Cell Spacing -> 20px", new ActionListener() {
184             public void actionPerformed(ActionEvent e) {
185                 testColumn.setCellSpacing(new Extent(20, Extent.PX));
186             }
187         });
188         controlsColumn.addButton("Insets -> null", new ActionListener() {
189             public void actionPerformed(ActionEvent e) {
190                 testColumn.setInsets(null);
191             }
192         });
193         controlsColumn.addButton("Insets -> 0px", new ActionListener() {
194             public void actionPerformed(ActionEvent e) {
195                 testColumn.setInsets(new Insets(0));
196             }
197         });
198         controlsColumn.addButton("Insets -> 5px", new ActionListener() {
199             public void actionPerformed(ActionEvent e) {
200                 testColumn.setInsets(new Insets(5));
201             }
202         });
203         controlsColumn.addButton("Insets -> 10/20/30/40px", new ActionListener() {
204             public void actionPerformed(ActionEvent e) {
205                 testColumn.setInsets(new Insets(10, 20, 30, 40));
206             }
207         });
208         controlsColumn.addButton("Set Layout Data (of random item)", new ActionListener() {
209             public void actionPerformed(ActionEvent e) {
210                 int componentCount = testColumn.getComponentCount();
211                 if (componentCount == 0) {
212                     return;
213                 }
214                 Component component = testColumn.getComponent((int) (Math.random() * componentCount));
215                 ColumnLayoutData columnLayoutData = new ColumnLayoutData();
216                 columnLayoutData.setAlignment(StyleUtil.randomAlignmentHV());
217                 columnLayoutData.setBackground(StyleUtil.randomBrightColor());
218                 columnLayoutData.setInsets(new Insets((int) (Math.random() * 30)));
219                 switch((int) (Math.random() * 7)) {
220                 case 0:
221                      columnLayoutData.setBackgroundImage(Styles.BG_SHADOW_DARK_BLUE);
222                      break;
223                 case 1:
224                      columnLayoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
225                      break;
226                 default:
227                      columnLayoutData.setBackgroundImage(null);
228                 }
229                 
230                 component.setLayoutData(columnLayoutData);
231             }
232         });
233         controlsColumn.addButton("Add Item, Randomize Column Insets", new ActionListener() {
234             public void actionPerformed(ActionEvent e) {
235                 testColumn.add(new Label("Added item [" + nextValue++ + "]"));
236                 testColumn.setInsets(new Insets((int) (Math.random() * 50)));
237             }
238         });
239         controlsColumn.addButton("Toggle Test Inset", new ActionListener() {
240             public void actionPerformed(ActionEvent e) {
241                 if (testColumn.getLayoutData() == null) {
242                     testColumn.setLayoutData(insetLayoutData);
243                 } else {
244                     testColumn.setLayoutData(null);
245                 }
246             }
247         });
248     }
249 }
250
Popular Tags