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 java.util.Locale;
033:
034: import nextapp.echo2.app.Alignment;
035: import nextapp.echo2.app.Color;
036: import nextapp.echo2.app.Component;
037: import nextapp.echo2.app.Extent;
038: import nextapp.echo2.app.Font;
039: import nextapp.echo2.app.Insets;
040: import nextapp.echo2.app.Label;
041: import nextapp.echo2.app.Column;
042: import nextapp.echo2.app.LayoutDirection;
043: import nextapp.echo2.app.SplitPane;
044: import nextapp.echo2.app.event.ActionEvent;
045: import nextapp.echo2.app.event.ActionListener;
046: import nextapp.echo2.app.layout.SplitPaneLayoutData;
047: import nextapp.echo2.testapp.interactive.ButtonColumn;
048: import nextapp.echo2.testapp.interactive.StyleUtil;
049: import nextapp.echo2.testapp.interactive.Styles;
050:
051: /**
052: * An interactive test for <code>Label</code>s.
053: */
054: public class LabelTest extends SplitPane {
055:
056: private interface Applicator {
057:
058: public void apply(Label label);
059: }
060:
061: private Column testColumn;
062:
063: public LabelTest() {
064: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
065: Extent.PX));
066: setStyleName("DefaultResizable");
067:
068: SplitPaneLayoutData splitPaneLayoutData;
069:
070: Column controlGroupsColumn = new Column();
071: controlGroupsColumn.setCellSpacing(new Extent(5));
072: controlGroupsColumn.setStyleName("TestControlsColumn");
073: add(controlGroupsColumn);
074:
075: testColumn = new Column();
076: testColumn.setCellSpacing(new Extent(15));
077: splitPaneLayoutData = new SplitPaneLayoutData();
078: splitPaneLayoutData.setInsets(new Insets(15));
079: testColumn.setLayoutData(splitPaneLayoutData);
080: add(testColumn);
081:
082: final Label iconLabel = new Label(Styles.ICON_LOGO);
083: testColumn.add(iconLabel);
084:
085: final Label textLabel = new Label("Test Label");
086: testColumn.add(textLabel);
087:
088: final Label iconTextLabel = new Label("Test Label",
089: Styles.ICON_LOGO);
090: testColumn.add(iconTextLabel);
091:
092: ButtonColumn controlsColumn;
093:
094: controlsColumn = new ButtonColumn();
095: controlGroupsColumn.add(controlsColumn);
096:
097: // Base Properties
098:
099: controlsColumn = new ButtonColumn();
100: controlGroupsColumn.add(controlsColumn);
101:
102: controlsColumn.add(new Label("Base Properties"));
103: controlsColumn.addButton("Toggle Container Cell Spacing",
104: new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: if (testColumn.getCellSpacing() == null) {
107: testColumn.setCellSpacing(new Extent(15));
108: } else {
109: testColumn.setCellSpacing(null);
110: }
111: }
112: });
113: controlsColumn.addButton("Set Foreground",
114: new ActionListener() {
115: public void actionPerformed(ActionEvent e) {
116: final Color color = StyleUtil.randomColor();
117: apply(new Applicator() {
118: public void apply(Label label) {
119: label.setForeground(color);
120: }
121: });
122: }
123: });
124: controlsColumn.addButton("Clear Foreground",
125: new ActionListener() {
126: public void actionPerformed(ActionEvent e) {
127: apply(new Applicator() {
128: public void apply(Label label) {
129: label.setForeground(null);
130: }
131: });
132: }
133: });
134: controlsColumn.addButton("Set Background",
135: new ActionListener() {
136: public void actionPerformed(ActionEvent e) {
137: final Color color = StyleUtil.randomColor();
138: apply(new Applicator() {
139: public void apply(Label label) {
140: label.setBackground(color);
141: }
142: });
143: }
144: });
145: controlsColumn.addButton("Clear Background",
146: new ActionListener() {
147: public void actionPerformed(ActionEvent e) {
148: apply(new Applicator() {
149: public void apply(Label label) {
150: label.setBackground(null);
151: }
152: });
153: }
154: });
155: controlsColumn.addButton("Set Font", new ActionListener() {
156: public void actionPerformed(ActionEvent e) {
157: final Font font = StyleUtil.randomFont();
158: apply(new Applicator() {
159: public void apply(Label label) {
160: label.setFont(font);
161: }
162: });
163: }
164: });
165: controlsColumn.addButton("Clear Font", new ActionListener() {
166: public void actionPerformed(ActionEvent e) {
167: apply(new Applicator() {
168: public void apply(Label label) {
169: label.setFont(null);
170: }
171: });
172: }
173: });
174: controlsColumn.addButton("Set Text = Short",
175: new ActionListener() {
176: public void actionPerformed(ActionEvent e) {
177: apply(new Applicator() {
178: public void apply(Label label) {
179: if (label.getText() != null) {
180: label.setText("Test Label");
181: }
182: }
183: });
184: }
185: });
186: controlsColumn.addButton("Set Text = Long",
187: new ActionListener() {
188: public void actionPerformed(ActionEvent e) {
189: apply(new Applicator() {
190: public void apply(Label label) {
191: if (label.getText() != null) {
192: label
193: .setText("This is a longer label. The quick brown fox jumps over the lazy brown dog.");
194: }
195: }
196: });
197: }
198: });
199: controlsColumn.addButton("Set Line Wrap = true",
200: new ActionListener() {
201: public void actionPerformed(ActionEvent e) {
202: apply(new Applicator() {
203: public void apply(Label label) {
204: label.setLineWrap(true);
205: }
206: });
207: }
208: });
209: controlsColumn.addButton("Set Line Wrap = false",
210: new ActionListener() {
211: public void actionPerformed(ActionEvent e) {
212: apply(new Applicator() {
213: public void apply(Label label) {
214: label.setLineWrap(false);
215: }
216: });
217: }
218: });
219: controlsColumn.addButton("Toggle ToolTip Text",
220: new ActionListener() {
221: public void actionPerformed(ActionEvent e) {
222: apply(new Applicator() {
223: public void apply(Label label) {
224: if (label.getToolTipText() == null) {
225: label
226: .setToolTipText("This is a tool tip.");
227: } else {
228: label.setToolTipText(null);
229: }
230: }
231: });
232: }
233: });
234:
235: // Alignment & Positioning
236:
237: controlsColumn = new ButtonColumn();
238: controlGroupsColumn.add(controlsColumn);
239:
240: controlsColumn.add(new Label("Alignment & Positioning"));
241: controlsColumn.addButton("TextPosition = Default",
242: new ActionListener() {
243: public void actionPerformed(ActionEvent e) {
244: apply(new Applicator() {
245: public void apply(Label label) {
246: label.setTextPosition(null);
247: }
248: });
249: }
250: });
251: controlsColumn.addButton("TextPosition = Top",
252: new ActionListener() {
253: public void actionPerformed(ActionEvent e) {
254: apply(new Applicator() {
255: public void apply(Label label) {
256: label.setTextPosition(new Alignment(
257: Alignment.DEFAULT,
258: Alignment.TOP));
259: }
260: });
261: }
262: });
263: controlsColumn.addButton("TextPosition = Bottom",
264: new ActionListener() {
265: public void actionPerformed(ActionEvent e) {
266: apply(new Applicator() {
267: public void apply(Label label) {
268: label.setTextPosition(new Alignment(
269: Alignment.DEFAULT,
270: Alignment.BOTTOM));
271: }
272: });
273: }
274: });
275: controlsColumn.addButton("TextPosition = Left",
276: new ActionListener() {
277: public void actionPerformed(ActionEvent e) {
278: apply(new Applicator() {
279: public void apply(Label label) {
280: label.setTextPosition(new Alignment(
281: Alignment.LEFT,
282: Alignment.DEFAULT));
283: }
284: });
285: }
286: });
287: controlsColumn.addButton("TextPosition = Right",
288: new ActionListener() {
289: public void actionPerformed(ActionEvent e) {
290: apply(new Applicator() {
291: public void apply(Label label) {
292: label.setTextPosition(new Alignment(
293: Alignment.RIGHT,
294: Alignment.DEFAULT));
295: }
296: });
297: }
298: });
299: controlsColumn.addButton("TextPosition = Leading",
300: new ActionListener() {
301: public void actionPerformed(ActionEvent e) {
302: apply(new Applicator() {
303: public void apply(Label label) {
304: label.setTextPosition(new Alignment(
305: Alignment.LEADING,
306: Alignment.DEFAULT));
307: }
308: });
309: }
310: });
311: controlsColumn.addButton("TextPosition = Trailing",
312: new ActionListener() {
313: public void actionPerformed(ActionEvent e) {
314: apply(new Applicator() {
315: public void apply(Label label) {
316: label.setTextPosition(new Alignment(
317: Alignment.TRAILING,
318: Alignment.DEFAULT));
319: }
320: });
321: }
322: });
323: controlsColumn.addButton("TextAlignment = Default",
324: new ActionListener() {
325: public void actionPerformed(ActionEvent e) {
326: apply(new Applicator() {
327: public void apply(Label label) {
328: label.setTextAlignment(null);
329: }
330: });
331: }
332: });
333: controlsColumn.addButton("TextAlignment = Top",
334: new ActionListener() {
335: public void actionPerformed(ActionEvent e) {
336: apply(new Applicator() {
337: public void apply(Label label) {
338: label.setTextAlignment(new Alignment(
339: Alignment.DEFAULT,
340: Alignment.TOP));
341: }
342: });
343: }
344: });
345: controlsColumn.addButton("TextAlignment = Center(V)",
346: new ActionListener() {
347: public void actionPerformed(ActionEvent e) {
348: apply(new Applicator() {
349: public void apply(Label label) {
350: label.setTextAlignment(new Alignment(
351: Alignment.DEFAULT,
352: Alignment.CENTER));
353: }
354: });
355: }
356: });
357: controlsColumn.addButton("TextAlignment = Bottom",
358: new ActionListener() {
359: public void actionPerformed(ActionEvent e) {
360: apply(new Applicator() {
361: public void apply(Label label) {
362: label.setTextAlignment(new Alignment(
363: Alignment.DEFAULT,
364: Alignment.BOTTOM));
365: }
366: });
367: }
368: });
369: controlsColumn.addButton("TextAlignment = Left",
370: new ActionListener() {
371: public void actionPerformed(ActionEvent e) {
372: apply(new Applicator() {
373: public void apply(Label label) {
374: label.setTextAlignment(new Alignment(
375: Alignment.LEFT,
376: Alignment.DEFAULT));
377: }
378: });
379: }
380: });
381: controlsColumn.addButton("TextAlignment = Center (H)",
382: new ActionListener() {
383: public void actionPerformed(ActionEvent e) {
384: apply(new Applicator() {
385: public void apply(Label label) {
386: label.setTextAlignment(new Alignment(
387: Alignment.CENTER,
388: Alignment.DEFAULT));
389: }
390: });
391: }
392: });
393: controlsColumn.addButton("TextAlignment = Right",
394: new ActionListener() {
395: public void actionPerformed(ActionEvent e) {
396: apply(new Applicator() {
397: public void apply(Label label) {
398: label.setTextAlignment(new Alignment(
399: Alignment.RIGHT,
400: Alignment.DEFAULT));
401: }
402: });
403: }
404: });
405: controlsColumn.addButton("TextAlignment = Leading",
406: new ActionListener() {
407: public void actionPerformed(ActionEvent e) {
408: apply(new Applicator() {
409: public void apply(Label label) {
410: label.setTextAlignment(new Alignment(
411: Alignment.LEADING,
412: Alignment.DEFAULT));
413: }
414: });
415: }
416: });
417: controlsColumn.addButton("TextAlignment = Trailing",
418: new ActionListener() {
419: public void actionPerformed(ActionEvent e) {
420: apply(new Applicator() {
421: public void apply(Label label) {
422: label.setTextAlignment(new Alignment(
423: Alignment.TRAILING,
424: Alignment.DEFAULT));
425: }
426: });
427: }
428: });
429: controlsColumn.addButton("IconTextMargin = default",
430: new ActionListener() {
431: public void actionPerformed(ActionEvent e) {
432: apply(new Applicator() {
433: public void apply(Label label) {
434: label.setIconTextMargin(null);
435: }
436: });
437: }
438: });
439: controlsColumn.addButton("IconTextMargin = 0px",
440: new ActionListener() {
441: public void actionPerformed(ActionEvent e) {
442: apply(new Applicator() {
443: public void apply(Label label) {
444: label.setIconTextMargin(new Extent(0));
445: }
446: });
447: }
448: });
449: controlsColumn.addButton("IconTextMargin = 1px",
450: new ActionListener() {
451: public void actionPerformed(ActionEvent e) {
452: apply(new Applicator() {
453: public void apply(Label label) {
454: label.setIconTextMargin(new Extent(1));
455: }
456: });
457: }
458: });
459: controlsColumn.addButton("IconTextMargin = 2px",
460: new ActionListener() {
461: public void actionPerformed(ActionEvent e) {
462: apply(new Applicator() {
463: public void apply(Label label) {
464: label.setIconTextMargin(new Extent(2));
465: }
466: });
467: }
468: });
469: controlsColumn.addButton("IconTextMargin = 3px",
470: new ActionListener() {
471: public void actionPerformed(ActionEvent e) {
472: apply(new Applicator() {
473: public void apply(Label label) {
474: label.setIconTextMargin(new Extent(3));
475: }
476: });
477: }
478: });
479: controlsColumn.addButton("IconTextMargin = 4px",
480: new ActionListener() {
481: public void actionPerformed(ActionEvent e) {
482: apply(new Applicator() {
483: public void apply(Label label) {
484: label.setIconTextMargin(new Extent(4));
485: }
486: });
487: }
488: });
489: controlsColumn.addButton("IconTextMargin = 5px",
490: new ActionListener() {
491: public void actionPerformed(ActionEvent e) {
492: apply(new Applicator() {
493: public void apply(Label label) {
494: label.setIconTextMargin(new Extent(5));
495: }
496: });
497: }
498: });
499: controlsColumn.addButton("IconTextMargin = 10px",
500: new ActionListener() {
501: public void actionPerformed(ActionEvent e) {
502: apply(new Applicator() {
503: public void apply(Label label) {
504: label.setIconTextMargin(new Extent(10));
505: }
506: });
507: }
508: });
509: controlsColumn.addButton("IconTextMargin = 1in",
510: new ActionListener() {
511: public void actionPerformed(ActionEvent e) {
512: apply(new Applicator() {
513: public void apply(Label label) {
514: label.setIconTextMargin(new Extent(1,
515: Extent.IN));
516: }
517: });
518: }
519: });
520:
521: // Localization
522:
523: controlsColumn = new ButtonColumn();
524: controlGroupsColumn.add(controlsColumn);
525:
526: controlsColumn.add(new Label("Localization"));
527:
528: controlsColumn.addButton("Locale = null", new ActionListener() {
529: public void actionPerformed(ActionEvent e) {
530: apply(new Applicator() {
531: public void apply(Label label) {
532: label.setLocale(null);
533: }
534: });
535: }
536: });
537: controlsColumn.addButton("Locale = US", new ActionListener() {
538: public void actionPerformed(ActionEvent e) {
539: apply(new Applicator() {
540: public void apply(Label label) {
541: label.setLocale(Locale.US);
542: }
543: });
544: }
545: });
546: controlsColumn.addButton("Locale = HEBREW (RTL)",
547: new ActionListener() {
548: public void actionPerformed(ActionEvent e) {
549: apply(new Applicator() {
550: public void apply(Label label) {
551: label.setLocale(new Locale("iw"));
552: }
553: });
554: }
555: });
556: controlsColumn.addButton("LayoutDirection = null",
557: new ActionListener() {
558: public void actionPerformed(ActionEvent e) {
559: apply(new Applicator() {
560: public void apply(Label label) {
561: label.setLayoutDirection(null);
562: }
563: });
564: }
565: });
566: controlsColumn.addButton("LayoutDirection = LTR",
567: new ActionListener() {
568: public void actionPerformed(ActionEvent e) {
569: apply(new Applicator() {
570: public void apply(Label label) {
571: label
572: .setLayoutDirection(LayoutDirection.LTR);
573: }
574: });
575: }
576: });
577: controlsColumn.addButton("LayoutDirection = RTL",
578: new ActionListener() {
579: public void actionPerformed(ActionEvent e) {
580: apply(new Applicator() {
581: public void apply(Label label) {
582: label
583: .setLayoutDirection(LayoutDirection.RTL);
584: }
585: });
586: }
587: });
588: }
589:
590: public void apply(Applicator applicator) {
591: Component[] components = testColumn.getComponents();
592: for (int i = 0; i < components.length; ++i) {
593: applicator.apply((Label) components[i]);
594: }
595: }
596: }
|