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.Border;
033: import nextapp.echo2.app.Color;
034: import nextapp.echo2.app.Extent;
035: import nextapp.echo2.app.Grid;
036: import nextapp.echo2.app.Insets;
037: import nextapp.echo2.app.Label;
038: import nextapp.echo2.app.Panel;
039: import nextapp.echo2.app.SplitPane;
040: import nextapp.echo2.app.event.ActionEvent;
041: import nextapp.echo2.app.event.ActionListener;
042: import nextapp.echo2.testapp.interactive.ButtonColumn;
043: import nextapp.echo2.testapp.interactive.StyleUtil;
044:
045: /**
046: * Interactive test for the <code>Panel</code> component.
047: */
048: public class PanelTest extends SplitPane {
049:
050: public PanelTest() {
051: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
052: Extent.PX));
053: setStyleName("DefaultResizable");
054:
055: ButtonColumn controlsColumn = new ButtonColumn();
056: controlsColumn.setStyleName("TestControlsColumn");
057: add(controlsColumn);
058:
059: final Panel panel = new Panel() {
060: };
061: add(panel);
062:
063: controlsColumn.addButton("Reset", new ActionListener() {
064: public void actionPerformed(ActionEvent e) {
065: panel.setBackground(null);
066: panel.setForeground(null);
067: panel.setFont(null);
068: }
069: });
070: controlsColumn.addButton("Change Background",
071: new ActionListener() {
072: public void actionPerformed(ActionEvent e) {
073: panel.setBackground(StyleUtil.randomColor());
074: }
075: });
076: controlsColumn.addButton("Change Foreground",
077: new ActionListener() {
078: public void actionPerformed(ActionEvent e) {
079: panel.setForeground(StyleUtil.randomColor());
080: }
081: });
082: controlsColumn.addButton("Change Font", new ActionListener() {
083: public void actionPerformed(ActionEvent e) {
084: panel.setFont(StyleUtil.randomFont());
085: }
086: });
087: controlsColumn.addButton("Set Content (Label)",
088: new ActionListener() {
089: public void actionPerformed(ActionEvent e) {
090: if (panel.getComponentCount() > 0) {
091: panel.removeAll();
092: }
093: panel.add(new Label("Hello, world!"));
094: }
095: });
096: controlsColumn.addButton("Set Content (Long Label)",
097: new ActionListener() {
098: public void actionPerformed(ActionEvent e) {
099: if (panel.getComponentCount() > 0) {
100: panel.removeAll();
101: }
102: panel.add(new Label(
103: StyleUtil.QUASI_LATIN_TEXT_1));
104: }
105: });
106: controlsColumn.addButton("Set Content (Grid)",
107: new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: if (panel.getComponentCount() > 0) {
110: panel.removeAll();
111: }
112: Grid grid = new Grid();
113: grid.setBorder(StyleUtil.randomBorder());
114: grid.setInsets(new Insets(StyleUtil
115: .randomExtent(8)));
116: grid.add(new Label("A label"));
117: grid.add(new Label("A label"));
118: grid.add(new Label("A label"));
119: grid.add(new Label("A label"));
120: grid.add(new Label("A label"));
121: panel.add(grid);
122: }
123: });
124: controlsColumn.addButton("Clear Content", new ActionListener() {
125: public void actionPerformed(ActionEvent e) {
126: panel.removeAll();
127: }
128: });
129: controlsColumn.addButton("Add Component", new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: if (panel.getParent() == null) {
132: PanelTest.this .add(panel);
133: }
134: }
135: });
136: controlsColumn.addButton("Remove Component",
137: new ActionListener() {
138: public void actionPerformed(ActionEvent e) {
139: if (panel.getParent() != null) {
140: PanelTest.this .remove(panel);
141: }
142: }
143: });
144: controlsColumn.addButton("Set Border (All Attributes)",
145: new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: panel.setBorder(StyleUtil.randomBorder());
148: }
149: });
150: controlsColumn.addButton("Set Border Color",
151: new ActionListener() {
152: public void actionPerformed(ActionEvent e) {
153: Border border = panel.getBorder();
154: if (border == null) {
155: border = new Border(new Extent(1),
156: Color.BLUE, Border.STYLE_SOLID);
157: }
158: panel.setBorder(new Border(border.getSize(),
159: StyleUtil.randomColor(), border
160: .getStyle()));
161: }
162: });
163: controlsColumn.addButton("Set Border Size",
164: new ActionListener() {
165: public void actionPerformed(ActionEvent e) {
166: panel.setBorder(StyleUtil.nextBorderSize(panel
167: .getBorder()));
168: }
169: });
170: controlsColumn.addButton("Set Border Style",
171: new ActionListener() {
172: public void actionPerformed(ActionEvent e) {
173: panel.setBorder(StyleUtil.nextBorderStyle(panel
174: .getBorder()));
175: }
176: });
177: controlsColumn.addButton("Remove Border", new ActionListener() {
178: public void actionPerformed(ActionEvent e) {
179: panel.setBorder(null);
180: }
181: });
182: controlsColumn.addButton("Insets -> null",
183: new ActionListener() {
184: public void actionPerformed(ActionEvent e) {
185: panel.setInsets(null);
186: }
187: });
188: controlsColumn.addButton("Insets -> 0px", new ActionListener() {
189: public void actionPerformed(ActionEvent e) {
190: panel.setInsets(new Insets(0));
191: }
192: });
193: controlsColumn.addButton("Insets -> 5px", new ActionListener() {
194: public void actionPerformed(ActionEvent e) {
195: panel.setInsets(new Insets(5));
196: }
197: });
198: controlsColumn.addButton("Insets -> 10/20/30/40px",
199: new ActionListener() {
200: public void actionPerformed(ActionEvent e) {
201: panel.setInsets(new Insets(10, 20, 30, 40));
202: }
203: });
204: }
205: }
|