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.FillImage;
036: import nextapp.echo2.app.Button;
037: import nextapp.echo2.app.Extent;
038: import nextapp.echo2.app.Insets;
039: import nextapp.echo2.app.Label;
040: import nextapp.echo2.app.Column;
041: import nextapp.echo2.app.Row;
042: import nextapp.echo2.app.SplitPane;
043: import nextapp.echo2.app.event.ActionEvent;
044: import nextapp.echo2.app.event.ActionListener;
045: import nextapp.echo2.app.layout.SplitPaneLayoutData;
046: import nextapp.echo2.testapp.interactive.ButtonColumn;
047: import nextapp.echo2.testapp.interactive.StyleUtil;
048: import nextapp.echo2.testapp.interactive.Styles;
049:
050: /**
051: * Interactive test module for <code>SplitPane</code>s.
052: */
053: public class SplitPaneTest extends SplitPane {
054:
055: private class PaneControlsColumn extends ButtonColumn {
056:
057: private PaneControlsColumn(final int paneNumber) {
058: add(new Label("Configure Pane #" + paneNumber));
059:
060: addButton("Fill With Text", new ActionListener() {
061: public void actionPerformed(ActionEvent e) {
062: if (testPane.getComponentCount() < paneNumber + 1) {
063: return;
064: }
065: if (testPane.getComponent(paneNumber) instanceof Label) {
066: Label label = (Label) testPane
067: .getComponent(paneNumber);
068: label.setText(StyleUtil.QUASI_LATIN_TEXT_1);
069: }
070: }
071: });
072: addButton("Change Background Color", new ActionListener() {
073: public void actionPerformed(ActionEvent e) {
074: if (testPane.getComponentCount() < paneNumber + 1) {
075: return;
076: }
077: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
078: splitPaneLayoutData.setBackground(StyleUtil
079: .randomBrightColor());
080: testPane.getComponent(paneNumber).setLayoutData(
081: splitPaneLayoutData);
082: }
083: });
084: addButton("MIN Size = Default", new ActionListener() {
085: public void actionPerformed(ActionEvent e) {
086: if (testPane.getComponentCount() < paneNumber + 1) {
087: return;
088: }
089: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
090: splitPaneLayoutData.setMinimumSize(null);
091: testPane.getComponent(paneNumber).setLayoutData(
092: splitPaneLayoutData);
093: }
094: });
095: addButton("MIN Size = 30", new ActionListener() {
096: public void actionPerformed(ActionEvent e) {
097: if (testPane.getComponentCount() < paneNumber + 1) {
098: return;
099: }
100: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
101: splitPaneLayoutData.setMinimumSize(new Extent(30));
102: testPane.getComponent(paneNumber).setLayoutData(
103: splitPaneLayoutData);
104: }
105: });
106: addButton("MAX Size = Default", new ActionListener() {
107: public void actionPerformed(ActionEvent e) {
108: if (testPane.getComponentCount() < paneNumber + 1) {
109: return;
110: }
111: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
112: splitPaneLayoutData.setMaximumSize(null);
113: testPane.getComponent(paneNumber).setLayoutData(
114: splitPaneLayoutData);
115: }
116: });
117: addButton("MAX Size = 120", new ActionListener() {
118: public void actionPerformed(ActionEvent e) {
119: if (testPane.getComponentCount() < paneNumber + 1) {
120: return;
121: }
122: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
123: splitPaneLayoutData.setMaximumSize(new Extent(120));
124: testPane.getComponent(paneNumber).setLayoutData(
125: splitPaneLayoutData);
126: }
127: });
128: addButton("Toggle Background Image", new ActionListener() {
129: public void actionPerformed(ActionEvent e) {
130: if (testPane.getComponentCount() < paneNumber + 1) {
131: return;
132: }
133: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
134: FillImage backgroundImage = splitPaneLayoutData
135: .getBackgroundImage();
136: if (backgroundImage == null) {
137: splitPaneLayoutData
138: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
139: } else {
140: splitPaneLayoutData.setBackgroundImage(null);
141: }
142: testPane.getComponent(paneNumber).setLayoutData(
143: splitPaneLayoutData);
144: }
145: });
146: addButton("Insets = null", new ActionListener() {
147: public void actionPerformed(ActionEvent e) {
148: if (testPane.getComponentCount() < paneNumber + 1) {
149: return;
150: }
151: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
152: splitPaneLayoutData.setInsets(null);
153: testPane.getComponent(paneNumber).setLayoutData(
154: splitPaneLayoutData);
155: }
156: });
157: addButton("Insets = 0px", new ActionListener() {
158: public void actionPerformed(ActionEvent e) {
159: if (testPane.getComponentCount() < paneNumber + 1) {
160: return;
161: }
162: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
163: splitPaneLayoutData.setInsets(new Insets(0));
164: testPane.getComponent(paneNumber).setLayoutData(
165: splitPaneLayoutData);
166: }
167: });
168: addButton("Insets = 5px", new ActionListener() {
169: public void actionPerformed(ActionEvent e) {
170: if (testPane.getComponentCount() < paneNumber + 1) {
171: return;
172: }
173: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
174: splitPaneLayoutData.setInsets(new Insets(5));
175: testPane.getComponent(paneNumber).setLayoutData(
176: splitPaneLayoutData);
177: }
178: });
179: addButton("Insets = 10/20/30/40px", new ActionListener() {
180: public void actionPerformed(ActionEvent e) {
181: if (testPane.getComponentCount() < paneNumber + 1) {
182: return;
183: }
184: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
185: splitPaneLayoutData.setInsets(new Insets(10, 20,
186: 30, 40));
187: testPane.getComponent(paneNumber).setLayoutData(
188: splitPaneLayoutData);
189: }
190: });
191: addButton("Overflow = Auto", new ActionListener() {
192: public void actionPerformed(ActionEvent e) {
193: if (testPane.getComponentCount() < paneNumber + 1) {
194: return;
195: }
196: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
197: splitPaneLayoutData
198: .setOverflow(SplitPaneLayoutData.OVERFLOW_AUTO);
199: testPane.getComponent(paneNumber).setLayoutData(
200: splitPaneLayoutData);
201: }
202: });
203: addButton("Overflow = Hidden", new ActionListener() {
204: public void actionPerformed(ActionEvent e) {
205: if (testPane.getComponentCount() < paneNumber + 1) {
206: return;
207: }
208: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
209: splitPaneLayoutData
210: .setOverflow(SplitPaneLayoutData.OVERFLOW_HIDDEN);
211: testPane.getComponent(paneNumber).setLayoutData(
212: splitPaneLayoutData);
213: }
214: });
215: addButton("Overflow = Scroll", new ActionListener() {
216: public void actionPerformed(ActionEvent e) {
217: if (testPane.getComponentCount() < paneNumber + 1) {
218: return;
219: }
220: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
221: splitPaneLayoutData
222: .setOverflow(SplitPaneLayoutData.OVERFLOW_SCROLL);
223: testPane.getComponent(paneNumber).setLayoutData(
224: splitPaneLayoutData);
225: }
226: });
227: addButton("Alignment = Left", new ActionListener() {
228: public void actionPerformed(ActionEvent e) {
229: if (testPane.getComponentCount() < paneNumber + 1) {
230: return;
231: }
232: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
233: splitPaneLayoutData.setAlignment(new Alignment(
234: Alignment.LEFT, Alignment.DEFAULT));
235: testPane.getComponent(paneNumber).setLayoutData(
236: splitPaneLayoutData);
237: }
238: });
239: addButton("Alignment = Center", new ActionListener() {
240: public void actionPerformed(ActionEvent e) {
241: if (testPane.getComponentCount() < paneNumber + 1) {
242: return;
243: }
244: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
245: splitPaneLayoutData.setAlignment(new Alignment(
246: Alignment.CENTER, Alignment.DEFAULT));
247: testPane.getComponent(paneNumber).setLayoutData(
248: splitPaneLayoutData);
249: }
250: });
251: addButton("Alignment = Right", new ActionListener() {
252: public void actionPerformed(ActionEvent e) {
253: if (testPane.getComponentCount() < paneNumber + 1) {
254: return;
255: }
256: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
257: splitPaneLayoutData.setAlignment(new Alignment(
258: Alignment.RIGHT, Alignment.DEFAULT));
259: testPane.getComponent(paneNumber).setLayoutData(
260: splitPaneLayoutData);
261: }
262: });
263: addButton("Alignment = Default", new ActionListener() {
264: public void actionPerformed(ActionEvent e) {
265: if (testPane.getComponentCount() < paneNumber + 1) {
266: return;
267: }
268: SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
269: splitPaneLayoutData.setAlignment(new Alignment(
270: Alignment.DEFAULT, Alignment.DEFAULT));
271: testPane.getComponent(paneNumber).setLayoutData(
272: splitPaneLayoutData);
273: }
274: });
275: }
276:
277: private SplitPaneLayoutData getLayoutData(int paneNumber) {
278: SplitPaneLayoutData splitPaneLayoutData = (SplitPaneLayoutData) testPane
279: .getComponent(paneNumber).getLayoutData();
280: if (splitPaneLayoutData == null) {
281: splitPaneLayoutData = new SplitPaneLayoutData();
282: }
283: return splitPaneLayoutData;
284: }
285: }
286:
287: private SplitPane testPane;
288:
289: public SplitPaneTest() {
290: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
291: Extent.PX));
292: setStyleName("DefaultResizable");
293:
294: Column groupContainerColumn = new Column();
295: groupContainerColumn.setCellSpacing(new Extent(5));
296: groupContainerColumn.setStyleName("TestControlsColumn");
297: add(groupContainerColumn);
298:
299: ButtonColumn controlsColumn;
300:
301: controlsColumn = new ButtonColumn();
302: controlsColumn.add(new Label("Add / Remove Panes"));
303: groupContainerColumn.add(controlsColumn);
304:
305: controlsColumn.addButton("Remove Pane 0", new ActionListener() {
306: public void actionPerformed(ActionEvent e) {
307: if (testPane.getComponentCount() >= 1) {
308: testPane.remove(0);
309: }
310: }
311: });
312: controlsColumn.addButton("Remove Pane 1", new ActionListener() {
313: public void actionPerformed(ActionEvent e) {
314: if (testPane.getComponentCount() >= 2) {
315: testPane.remove(1);
316: }
317: }
318: });
319: controlsColumn.addButton("Replace Pane 0",
320: new ActionListener() {
321: public void actionPerformed(ActionEvent e) {
322: if (testPane.getComponentCount() >= 1) {
323: testPane.remove(0);
324: }
325: testPane
326: .add(
327: createPaneLabel("Replacement for Pane 0"),
328: 0);
329: }
330: });
331: controlsColumn.addButton("Replace Pane 1",
332: new ActionListener() {
333: public void actionPerformed(ActionEvent e) {
334: if (testPane.getComponentCount() >= 2) {
335: testPane.remove(1);
336: }
337: testPane
338: .add(createPaneLabel("Replacement for Pane 1"));
339: }
340: });
341: controlsColumn.addButton("Add at Beginning",
342: new ActionListener() {
343: public void actionPerformed(ActionEvent e) {
344: if (testPane.getComponentCount() < 2) {
345: testPane
346: .add(
347: createPaneLabel("Added at Beginning"),
348: 0);
349: }
350: }
351: });
352: controlsColumn.addButton("Add at End", new ActionListener() {
353: public void actionPerformed(ActionEvent e) {
354: if (testPane.getComponentCount() < 2) {
355: testPane.add(createPaneLabel("Added at End"));
356: }
357: }
358: });
359: controlsColumn.addButton("Add Row", new ActionListener() {
360: public void actionPerformed(ActionEvent e) {
361: if (testPane.getComponentCount() < 2) {
362: Row row = new Row();
363: row.setBorder(new Border(new Extent(1),
364: Color.BLACK, Border.STYLE_SOLID));
365: row.setCellSpacing(new Extent(5));
366: row.setInsets(new Insets(10, 5));
367: row.add(new Label("Alpha"));
368: row.add(new Label("Bravo"));
369: row.add(new Label("Charlie"));
370: testPane.add(row);
371: }
372: }
373: });
374: controlsColumn.addButton("Add-Remove-Add",
375: new ActionListener() {
376: public void actionPerformed(ActionEvent e) {
377: if (testPane.getComponentCount() < 2) {
378: Label label = createPaneLabel("Added at End, Removed, Re-Added");
379: testPane.add(label);
380: testPane.remove(label);
381: testPane.add(label);
382: }
383: }
384: });
385: controlsColumn.addButton("Add Button", new ActionListener() {
386: public void actionPerformed(ActionEvent e) {
387: if (testPane.getComponentCount() < 2) {
388: Button testButton = new Button("Test Button");
389: SplitPaneLayoutData layoutData = new SplitPaneLayoutData();
390: layoutData.setInsets(new Insets(10));
391: testButton.setLayoutData(layoutData);
392: testButton.setStyleName("Default");
393: testPane.add(testButton);
394: }
395: }
396: });
397:
398: controlsColumn = new ButtonColumn();
399: controlsColumn.add(new Label("Configure SplitPane"));
400: groupContainerColumn.add(controlsColumn);
401:
402: controlsColumn.addButton("Set Separator Position = null",
403: new ActionListener() {
404: public void actionPerformed(ActionEvent e) {
405: testPane.setSeparatorPosition(null);
406: }
407: });
408: controlsColumn.addButton("Set Separator Position = 300px",
409: new ActionListener() {
410: public void actionPerformed(ActionEvent e) {
411: testPane.setSeparatorPosition(new Extent(300));
412: }
413: });
414: controlsColumn.addButton("Set Orientation = Leading/Trailing",
415: new ActionListener() {
416: public void actionPerformed(ActionEvent e) {
417: testPane
418: .setOrientation(SplitPane.ORIENTATION_HORIZONTAL_LEADING_TRAILING);
419: }
420: });
421: controlsColumn.addButton("Set Orientation = Trailing/Leading",
422: new ActionListener() {
423: public void actionPerformed(ActionEvent e) {
424: testPane
425: .setOrientation(SplitPane.ORIENTATION_HORIZONTAL_TRAILING_LEADING);
426: }
427: });
428: controlsColumn.addButton("Set Orientation = Left/Right",
429: new ActionListener() {
430: public void actionPerformed(ActionEvent e) {
431: testPane
432: .setOrientation(SplitPane.ORIENTATION_HORIZONTAL_LEFT_RIGHT);
433: }
434: });
435: controlsColumn.addButton("Set Orientation = Right/Left",
436: new ActionListener() {
437: public void actionPerformed(ActionEvent e) {
438: testPane
439: .setOrientation(SplitPane.ORIENTATION_HORIZONTAL_RIGHT_LEFT);
440: }
441: });
442: controlsColumn.addButton("Set Orientation = Top/Bottom",
443: new ActionListener() {
444: public void actionPerformed(ActionEvent e) {
445: testPane
446: .setOrientation(SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM);
447: }
448: });
449: controlsColumn.addButton("Set Orientation = Bottom/Top",
450: new ActionListener() {
451: public void actionPerformed(ActionEvent e) {
452: testPane
453: .setOrientation(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP);
454: }
455: });
456: controlsColumn.addButton("Disable Resize",
457: new ActionListener() {
458: public void actionPerformed(ActionEvent e) {
459: testPane.setResizable(!testPane.isResizable());
460: ((Button) e.getSource()).setText(testPane
461: .isResizable() ? "Disable Resize"
462: : "Enable Resize");
463: }
464: });
465:
466: groupContainerColumn.add(new PaneControlsColumn(0));
467: groupContainerColumn.add(new PaneControlsColumn(1));
468:
469: testPane = new SplitPane(ORIENTATION_VERTICAL, new Extent(200,
470: Extent.PX));
471: testPane.setStyleName("DefaultResizable");
472: add(testPane);
473: }
474:
475: private Label createPaneLabel(String text) {
476: Label label = new Label(text);
477: SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
478: splitPaneLayoutData
479: .setBackground(StyleUtil.randomBrightColor());
480: label.setLayoutData(splitPaneLayoutData);
481: return label;
482: }
483: }
|