001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Alignment;
033: import nextapp.echo2.app.Border;
034: import nextapp.echo2.app.Color;
035: import nextapp.echo2.app.Component;
036: import nextapp.echo2.app.Extent;
037: import nextapp.echo2.app.Insets;
038: import nextapp.echo2.app.Label;
039: import nextapp.echo2.app.Row;
040: import nextapp.echo2.app.SplitPane;
041: import nextapp.echo2.app.event.ActionEvent;
042: import nextapp.echo2.app.event.ActionListener;
043: import nextapp.echo2.app.layout.RowLayoutData;
044: import nextapp.echo2.app.layout.SplitPaneLayoutData;
045: import nextapp.echo2.testapp.interactive.ButtonColumn;
046: import nextapp.echo2.testapp.interactive.StyleUtil;
047: import nextapp.echo2.testapp.interactive.Styles;
048:
049: public class RowTest extends SplitPane {
050:
051: private int nextValue = 0;
052:
053: private static final SplitPaneLayoutData insetLayoutData;
054: static {
055: insetLayoutData = new SplitPaneLayoutData();
056: insetLayoutData.setInsets(new Insets(10));
057: }
058:
059: public RowTest() {
060: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250));
061: setStyleName("DefaultResizable");
062:
063: ButtonColumn controlsColumn = new ButtonColumn();
064: controlsColumn.setStyleName("TestControlsColumn");
065: add(controlsColumn);
066:
067: final Row testRow = new Row();
068: testRow.setBorder(new Border(new Extent(1), Color.BLUE,
069: Border.STYLE_SOLID));
070: testRow.setLayoutData(insetLayoutData);
071: add(testRow);
072:
073: controlsColumn.addButton("Add Item (at beginning)",
074: new ActionListener() {
075: public void actionPerformed(ActionEvent e) {
076: testRow.add(new Label("Added item ["
077: + nextValue++ + "]"), 0);
078: }
079: });
080: controlsColumn.addButton("Add Item (at end)",
081: new ActionListener() {
082: public void actionPerformed(ActionEvent e) {
083: testRow.add(new Label("Added item ["
084: + nextValue++ + "]"));
085: }
086: });
087: controlsColumn.addButton("Add-Remove-Add Item (at end)",
088: new ActionListener() {
089: public void actionPerformed(ActionEvent e) {
090: Label label = new Label("Added item ["
091: + nextValue++ + "]");
092: testRow.add(label);
093: testRow.remove(label);
094: testRow.add(label);
095: }
096: });
097: controlsColumn.addButton("Remove Last Item",
098: new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: if (testRow.getComponentCount() > 0) {
101: testRow
102: .remove(testRow.getComponentCount() - 1);
103: }
104: }
105: });
106: controlsColumn.addButton("Add Some Items, Remove Some Items",
107: new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: int count = 1 + ((int) (Math.random() * 10));
110: for (int i = 0; i < count; ++i) {
111: int componentCount = testRow
112: .getComponentCount();
113: if (componentCount > 0
114: && ((int) (Math.random() * 2)) == 0) {
115: // Perform remove.
116: int position = (int) (Math.random() * componentCount);
117: testRow.remove(position);
118: } else {
119: // Perform add.
120: int position = (int) (Math.random() * (componentCount + 1));
121: testRow.add(new Label("Added item ["
122: + nextValue++ + "]"), position);
123: }
124: }
125: }
126: });
127: controlsColumn.addButton("Randomly Remove and Re-insert Item",
128: new ActionListener() {
129: public void actionPerformed(ActionEvent e) {
130: int itemCount = testRow.getComponentCount();
131: if (itemCount == 0) {
132: return;
133: }
134: Component item = testRow
135: .getComponent((int) (Math.random() * itemCount));
136: testRow.remove(item);
137: testRow
138: .add(
139: item,
140: (int) (Math.random() * (itemCount - 1)));
141: }
142: });
143: controlsColumn.addButton("Set Foreground",
144: new ActionListener() {
145: public void actionPerformed(ActionEvent e) {
146: testRow.setForeground(StyleUtil.randomColor());
147: }
148: });
149: controlsColumn.addButton("Clear Foreground",
150: new ActionListener() {
151: public void actionPerformed(ActionEvent e) {
152: testRow.setForeground(null);
153: }
154: });
155: controlsColumn.addButton("Set Background",
156: new ActionListener() {
157: public void actionPerformed(ActionEvent e) {
158: testRow.setBackground(StyleUtil.randomColor());
159: }
160: });
161: controlsColumn.addButton("Clear Background",
162: new ActionListener() {
163: public void actionPerformed(ActionEvent e) {
164: testRow.setBackground(null);
165: }
166: });
167: controlsColumn.addButton("Set Border (All Attributes)",
168: new ActionListener() {
169: public void actionPerformed(ActionEvent e) {
170: testRow.setBorder(StyleUtil.randomBorder());
171: }
172: });
173: controlsColumn.addButton("Set Border Color",
174: new ActionListener() {
175: public void actionPerformed(ActionEvent e) {
176: Border border = testRow.getBorder();
177: if (border == null) {
178: border = new Border(new Extent(1),
179: Color.BLUE, Border.STYLE_SOLID);
180: }
181: testRow.setBorder(new Border(border.getSize(),
182: StyleUtil.randomColor(), border
183: .getStyle()));
184: }
185: });
186: controlsColumn.addButton("Set Border Size",
187: new ActionListener() {
188: public void actionPerformed(ActionEvent e) {
189: testRow.setBorder(StyleUtil
190: .nextBorderSize(testRow.getBorder()));
191: }
192: });
193: controlsColumn.addButton("Set Border Style",
194: new ActionListener() {
195: public void actionPerformed(ActionEvent e) {
196: testRow.setBorder(StyleUtil
197: .nextBorderStyle(testRow.getBorder()));
198: }
199: });
200: controlsColumn.addButton("Remove Border", new ActionListener() {
201: public void actionPerformed(ActionEvent e) {
202: testRow.setBorder(null);
203: }
204: });
205: controlsColumn.addButton("Cell Spacing -> 0px",
206: new ActionListener() {
207: public void actionPerformed(ActionEvent e) {
208: testRow
209: .setCellSpacing(new Extent(0, Extent.PX));
210: }
211: });
212: controlsColumn.addButton("Cell Spacing -> 2px",
213: new ActionListener() {
214: public void actionPerformed(ActionEvent e) {
215: testRow
216: .setCellSpacing(new Extent(2, Extent.PX));
217: }
218: });
219: controlsColumn.addButton("Cell Spacing -> 20px",
220: new ActionListener() {
221: public void actionPerformed(ActionEvent e) {
222: testRow
223: .setCellSpacing(new Extent(20,
224: Extent.PX));
225: }
226: });
227: controlsColumn.addButton("Insets -> null",
228: new ActionListener() {
229: public void actionPerformed(ActionEvent e) {
230: testRow.setInsets(null);
231: }
232: });
233: controlsColumn.addButton("Insets -> 0px", new ActionListener() {
234: public void actionPerformed(ActionEvent e) {
235: testRow.setInsets(new Insets(0));
236: }
237: });
238: controlsColumn.addButton("Insets -> 5px", new ActionListener() {
239: public void actionPerformed(ActionEvent e) {
240: testRow.setInsets(new Insets(5));
241: }
242: });
243: controlsColumn.addButton("Insets -> 10/20/30/40px",
244: new ActionListener() {
245: public void actionPerformed(ActionEvent e) {
246: testRow.setInsets(new Insets(10, 20, 30, 40));
247: }
248: });
249: controlsColumn.addButton("Alignment -> Leading",
250: new ActionListener() {
251: public void actionPerformed(ActionEvent e) {
252: testRow.setAlignment(new Alignment(
253: Alignment.LEADING, Alignment.DEFAULT));
254: }
255: });
256: controlsColumn.addButton("Alignment -> Trailing",
257: new ActionListener() {
258: public void actionPerformed(ActionEvent e) {
259: testRow.setAlignment(new Alignment(
260: Alignment.TRAILING, Alignment.DEFAULT));
261: }
262: });
263: controlsColumn.addButton("Alignment -> Left",
264: new ActionListener() {
265: public void actionPerformed(ActionEvent e) {
266: testRow.setAlignment(new Alignment(
267: Alignment.LEFT, Alignment.DEFAULT));
268: }
269: });
270: controlsColumn.addButton("Alignment -> Center",
271: new ActionListener() {
272: public void actionPerformed(ActionEvent e) {
273: testRow.setAlignment(new Alignment(
274: Alignment.CENTER, Alignment.DEFAULT));
275: }
276: });
277: controlsColumn.addButton("Alignment -> Right",
278: new ActionListener() {
279: public void actionPerformed(ActionEvent e) {
280: testRow.setAlignment(new Alignment(
281: Alignment.RIGHT, Alignment.DEFAULT));
282: }
283: });
284: controlsColumn.addButton("Alignment -> Default",
285: new ActionListener() {
286: public void actionPerformed(ActionEvent e) {
287: testRow.setAlignment(new Alignment(
288: Alignment.DEFAULT, Alignment.DEFAULT));
289: }
290: });
291:
292: controlsColumn.addButton("Set Layout Data (of random item)",
293: new ActionListener() {
294: public void actionPerformed(ActionEvent e) {
295: int componentCount = testRow
296: .getComponentCount();
297: if (componentCount == 0) {
298: return;
299: }
300: Component component = testRow
301: .getComponent((int) (Math.random() * componentCount));
302: RowLayoutData rowLayoutData = new RowLayoutData();
303: rowLayoutData.setAlignment(StyleUtil
304: .randomAlignmentHV());
305: rowLayoutData.setBackground(StyleUtil
306: .randomBrightColor());
307: rowLayoutData.setInsets(new Insets((int) (Math
308: .random() * 30)));
309: switch ((int) (Math.random() * 7)) {
310: case 0:
311: rowLayoutData
312: .setBackgroundImage(Styles.BG_SHADOW_DARK_BLUE);
313: break;
314: case 1:
315: rowLayoutData
316: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
317: break;
318: default:
319: rowLayoutData.setBackgroundImage(null);
320: }
321:
322: component.setLayoutData(rowLayoutData);
323: }
324: });
325: controlsColumn.addButton("Add Item, Randomize Column Insets",
326: new ActionListener() {
327: public void actionPerformed(ActionEvent e) {
328: testRow.add(new Label("Added item ["
329: + nextValue++ + "]"));
330: testRow.setInsets(new Insets((int) (Math
331: .random() * 50)));
332: }
333: });
334: controlsColumn.addButton("Toggle Test Inset",
335: new ActionListener() {
336: public void actionPerformed(ActionEvent e) {
337: if (testRow.getLayoutData() == null) {
338: testRow.setLayoutData(insetLayoutData);
339: } else {
340: testRow.setLayoutData(null);
341: }
342: }
343: });
344: }
345: }
|