KickJava   Java API By Example, From Geeks To Geeks.

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


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