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.FillImage;
033: import nextapp.echo2.app.Border;
034: import nextapp.echo2.app.Color;
035: import nextapp.echo2.app.Extent;
036: import nextapp.echo2.app.Insets;
037: import nextapp.echo2.app.PasswordField;
038: import nextapp.echo2.app.Column;
039: import nextapp.echo2.app.SplitPane;
040: import nextapp.echo2.app.TextArea;
041: import nextapp.echo2.app.TextField;
042: import nextapp.echo2.app.event.ActionEvent;
043: import nextapp.echo2.app.event.ActionListener;
044: import nextapp.echo2.app.event.DocumentEvent;
045: import nextapp.echo2.app.event.DocumentListener;
046: import nextapp.echo2.app.layout.SplitPaneLayoutData;
047: import nextapp.echo2.testapp.interactive.ButtonColumn;
048: import nextapp.echo2.testapp.interactive.InteractiveApp;
049: import nextapp.echo2.testapp.interactive.StyleUtil;
050: import nextapp.echo2.testapp.interactive.Styles;
051:
052: public class TextComponentTest extends SplitPane {
053:
054: /**
055: * Writes <code>ActionEvent</code>s to console.
056: */
057: private ActionListener actionListener = new ActionListener() {
058:
059: /**
060: * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
061: */
062: public void actionPerformed(ActionEvent e) {
063: ((InteractiveApp) getApplicationInstance()).consoleWrite(e
064: .toString());
065: }
066: };
067:
068: /**
069: * Writes <code>ActionEvent</code>s to console.
070: */
071: private DocumentListener documentListener = new DocumentListener() {
072:
073: /**
074: * @see nextapp.echo2.app.event.DocumentListener#documentUpdate(nextapp.echo2.app.event.DocumentEvent)
075: */
076: public void documentUpdate(DocumentEvent e) {
077: ((InteractiveApp) getApplicationInstance()).consoleWrite(e
078: .toString());
079: }
080: };
081:
082: public TextComponentTest() {
083: super (SplitPane.ORIENTATION_HORIZONTAL, new Extent(250,
084: Extent.PX));
085: setStyleName("DefaultResizable");
086:
087: SplitPaneLayoutData splitPaneLayoutData;
088:
089: ButtonColumn controlsColumn = new ButtonColumn();
090: controlsColumn.setStyleName("TestControlsColumn");
091: add(controlsColumn);
092:
093: Column testColumn = new Column();
094: testColumn.setCellSpacing(new Extent(15));
095: splitPaneLayoutData = new SplitPaneLayoutData();
096: splitPaneLayoutData.setInsets(new Insets(15));
097: testColumn.setLayoutData(splitPaneLayoutData);
098: add(testColumn);
099:
100: final TextField textField = new TextField();
101: textField.setBorder(new Border(1, Color.BLUE,
102: Border.STYLE_SOLID));
103: testColumn.add(textField);
104:
105: final PasswordField passwordField = new PasswordField();
106: passwordField.setBorder(new Border(1, Color.BLUE,
107: Border.STYLE_SOLID));
108: testColumn.add(passwordField);
109:
110: final TextArea textArea = new TextArea();
111: textArea
112: .setBorder(new Border(1, Color.BLUE, Border.STYLE_SOLID));
113: testColumn.add(textArea);
114:
115: controlsColumn.addButton("Set Text to Multiple Lines",
116: new ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: String text = "This\nis\na\ntest.";
119: textField.getDocument().setText(text);
120: passwordField.getDocument().setText(text);
121: textArea.getDocument().setText(text);
122: }
123: });
124:
125: controlsColumn.addButton("Test HTML Encoding",
126: new ActionListener() {
127: public void actionPerformed(ActionEvent e) {
128: String text = "<b>this should NOT be bold</b>";
129: textField.getDocument().setText(text);
130: passwordField.getDocument().setText(text);
131: textArea.getDocument().setText(text);
132: }
133: });
134:
135: controlsColumn.addButton("Test Whitespace Encoding",
136: new ActionListener() {
137: public void actionPerformed(ActionEvent e) {
138: String text = " There are three spaces leading, trailing, "
139: + "and between each word. ";
140: textField.getDocument().setText(text);
141: passwordField.getDocument().setText(text);
142: textArea.getDocument().setText(text);
143: }
144: });
145: controlsColumn.addButton("Toggle ToolTip Text",
146: new ActionListener() {
147: public void actionPerformed(ActionEvent e) {
148: if (textField.getToolTipText() == null) {
149: textField
150: .setToolTipText("This is a tool tip.");
151: passwordField
152: .setToolTipText("This is a tool tip.");
153: textArea
154: .setToolTipText("This is a tool tip.");
155: } else {
156: textField.setToolTipText(null);
157: passwordField.setToolTipText(null);
158: textArea.setToolTipText(null);
159: }
160: }
161: });
162: controlsColumn.addButton("Add ActionListener",
163: new ActionListener() {
164: public void actionPerformed(ActionEvent e) {
165: textField.addActionListener(actionListener);
166: passwordField.addActionListener(actionListener);
167: textArea.addActionListener(actionListener);
168: }
169: });
170: controlsColumn.addButton("Remove ActionListener",
171: new ActionListener() {
172: public void actionPerformed(ActionEvent e) {
173: textField.removeActionListener(actionListener);
174: passwordField
175: .removeActionListener(actionListener);
176: textArea.removeActionListener(actionListener);
177: }
178: });
179: controlsColumn.addButton("Add DocumentListener",
180: new ActionListener() {
181: public void actionPerformed(ActionEvent e) {
182: textField.getDocument().addDocumentListener(
183: documentListener);
184: passwordField.getDocument()
185: .addDocumentListener(documentListener);
186: textArea.getDocument().addDocumentListener(
187: documentListener);
188: }
189: });
190: controlsColumn.addButton("Remove DocumentListener",
191: new ActionListener() {
192: public void actionPerformed(ActionEvent e) {
193: textField.getDocument().removeDocumentListener(
194: documentListener);
195: passwordField.getDocument()
196: .removeDocumentListener(
197: documentListener);
198: textArea.getDocument().removeDocumentListener(
199: documentListener);
200: }
201: });
202:
203: controlsColumn.addButton("Horizontal Scroll = 0px",
204: new ActionListener() {
205: public void actionPerformed(ActionEvent e) {
206: textField.setHorizontalScroll(new Extent(0));
207: passwordField
208: .setHorizontalScroll(new Extent(0));
209: textArea.setHorizontalScroll(new Extent(0));
210: }
211: });
212:
213: controlsColumn.addButton("Horizontal Scroll = 100px",
214: new ActionListener() {
215: public void actionPerformed(ActionEvent e) {
216: textField.setHorizontalScroll(new Extent(100));
217: passwordField.setHorizontalScroll(new Extent(
218: 100));
219: textArea.setHorizontalScroll(new Extent(100));
220: }
221: });
222:
223: controlsColumn.addButton("Vertical Scroll = 0px",
224: new ActionListener() {
225: public void actionPerformed(ActionEvent e) {
226: textField.setVerticalScroll(new Extent(0));
227: passwordField.setVerticalScroll(new Extent(0));
228: textArea.setVerticalScroll(new Extent(0));
229: }
230: });
231:
232: controlsColumn.addButton("Vertical Scroll = 100px",
233: new ActionListener() {
234: public void actionPerformed(ActionEvent e) {
235: textField.setVerticalScroll(new Extent(100));
236: passwordField
237: .setVerticalScroll(new Extent(100));
238: textArea.setVerticalScroll(new Extent(100));
239: }
240: });
241:
242: controlsColumn.addButton("Change Border (All Attributes)",
243: new ActionListener() {
244: public void actionPerformed(ActionEvent e) {
245: Border border = StyleUtil.randomBorder();
246: textField.setBorder(border);
247: passwordField.setBorder(border);
248: textArea.setBorder(border);
249: }
250: });
251: controlsColumn.addButton("Change Border Color",
252: new ActionListener() {
253: public void actionPerformed(ActionEvent e) {
254: Border border = textField.getBorder();
255: if (border == null) {
256: return;
257: }
258: border = new Border(border.getSize(), StyleUtil
259: .randomColor(), border.getStyle());
260: textField.setBorder(border);
261: passwordField.setBorder(border);
262: textArea.setBorder(border);
263: }
264: });
265: controlsColumn.addButton("Change Border Size",
266: new ActionListener() {
267: public void actionPerformed(ActionEvent e) {
268: Border border = StyleUtil
269: .nextBorderSize(textField.getBorder());
270: if (border == null) {
271: return;
272: }
273: textField.setBorder(border);
274: passwordField.setBorder(border);
275: textArea.setBorder(border);
276: }
277: });
278: controlsColumn.addButton("Change Border Style",
279: new ActionListener() {
280: public void actionPerformed(ActionEvent e) {
281: Border border = StyleUtil
282: .nextBorderStyle(textField.getBorder());
283: if (border == null) {
284: return;
285: }
286: textField.setBorder(border);
287: passwordField.setBorder(border);
288: textArea.setBorder(border);
289: }
290: });
291: controlsColumn.addButton("Toggle Background Image",
292: new ActionListener() {
293: public void actionPerformed(ActionEvent e) {
294: FillImage backgroundImage = textField
295: .getBackgroundImage();
296: if (backgroundImage == null) {
297: textField
298: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
299: passwordField
300: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
301: textArea
302: .setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
303: } else {
304: textField.setBackgroundImage(null);
305: passwordField.setBackgroundImage(null);
306: textArea.setBackgroundImage(null);
307: }
308: }
309: });
310: controlsColumn.addButton("Set Foreground",
311: new ActionListener() {
312: public void actionPerformed(ActionEvent e) {
313: Color color = StyleUtil.randomColor();
314: textField.setForeground(color);
315: passwordField.setForeground(color);
316: textArea.setForeground(color);
317: }
318: });
319: controlsColumn.addButton("Clear Foreground",
320: new ActionListener() {
321: public void actionPerformed(ActionEvent e) {
322: textField.setForeground(null);
323: passwordField.setForeground(null);
324: textArea.setForeground(null);
325: }
326: });
327: controlsColumn.addButton("Set Background",
328: new ActionListener() {
329: public void actionPerformed(ActionEvent e) {
330: Color color = StyleUtil.randomColor();
331: textField.setBackground(color);
332: passwordField.setBackground(color);
333: textArea.setBackground(color);
334: }
335: });
336: controlsColumn.addButton("Clear Background",
337: new ActionListener() {
338: public void actionPerformed(ActionEvent e) {
339: textField.setBackground(null);
340: passwordField.setBackground(null);
341: textArea.setBackground(null);
342: }
343: });
344: controlsColumn.addButton(
345: "Change Disabled Border (All Attributes)",
346: new ActionListener() {
347: public void actionPerformed(ActionEvent e) {
348: Border border = StyleUtil.randomBorder();
349: textField.setDisabledBorder(border);
350: passwordField.setDisabledBorder(border);
351: textArea.setDisabledBorder(border);
352: }
353: });
354: controlsColumn.addButton("Change Disabled Border Color",
355: new ActionListener() {
356: public void actionPerformed(ActionEvent e) {
357: Border border = textField.getDisabledBorder();
358: if (border == null) {
359: return;
360: }
361: border = new Border(border.getSize(), StyleUtil
362: .randomColor(), border.getStyle());
363: textField.setDisabledBorder(border);
364: passwordField.setDisabledBorder(border);
365: textArea.setDisabledBorder(border);
366: }
367: });
368: controlsColumn.addButton("Change Disabled Border Size",
369: new ActionListener() {
370: public void actionPerformed(ActionEvent e) {
371: Border border = StyleUtil
372: .nextBorderSize(textField
373: .getDisabledBorder());
374: if (border == null) {
375: return;
376: }
377: textField.setDisabledBorder(border);
378: passwordField.setDisabledBorder(border);
379: textArea.setDisabledBorder(border);
380: }
381: });
382: controlsColumn.addButton("Change Disabled Border Style",
383: new ActionListener() {
384: public void actionPerformed(ActionEvent e) {
385: Border border = StyleUtil
386: .nextBorderStyle(textField
387: .getDisabledBorder());
388: if (border == null) {
389: return;
390: }
391: textField.setDisabledBorder(border);
392: passwordField.setDisabledBorder(border);
393: textArea.setDisabledBorder(border);
394: }
395: });
396: controlsColumn.addButton("Toggle Disabled Background Image",
397: new ActionListener() {
398: public void actionPerformed(ActionEvent e) {
399: FillImage backgroundImage = textField
400: .getDisabledBackgroundImage();
401: if (backgroundImage == null) {
402: textField
403: .setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
404: passwordField
405: .setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
406: textArea
407: .setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
408: } else {
409: textField.setDisabledBackgroundImage(null);
410: passwordField
411: .setDisabledBackgroundImage(null);
412: textArea.setDisabledBackgroundImage(null);
413: }
414: }
415: });
416: controlsColumn.addButton("Set Disabled Foreground",
417: new ActionListener() {
418: public void actionPerformed(ActionEvent e) {
419: Color color = StyleUtil.randomColor();
420: textField.setDisabledForeground(color);
421: passwordField.setDisabledForeground(color);
422: textArea.setDisabledForeground(color);
423: }
424: });
425: controlsColumn.addButton("Clear Disabled Foreground",
426: new ActionListener() {
427: public void actionPerformed(ActionEvent e) {
428: textField.setDisabledForeground(null);
429: passwordField.setDisabledForeground(null);
430: textArea.setDisabledForeground(null);
431: }
432: });
433: controlsColumn.addButton("Set Disabled Background",
434: new ActionListener() {
435: public void actionPerformed(ActionEvent e) {
436: Color color = StyleUtil.randomColor();
437: textField.setDisabledBackground(color);
438: passwordField.setDisabledBackground(color);
439: textArea.setDisabledBackground(color);
440: }
441: });
442: controlsColumn.addButton("Clear Disabled Background",
443: new ActionListener() {
444: public void actionPerformed(ActionEvent e) {
445: textField.setDisabledBackground(null);
446: passwordField.setDisabledBackground(null);
447: textArea.setDisabledBackground(null);
448: }
449: });
450: controlsColumn.addButton("Set MaximumLength=10",
451: new ActionListener() {
452: public void actionPerformed(ActionEvent e) {
453: textField.setMaximumLength(10);
454: passwordField.setMaximumLength(10);
455: textArea.setMaximumLength(10);
456: }
457: });
458: controlsColumn.addButton("Clear MaximumLength",
459: new ActionListener() {
460: public void actionPerformed(ActionEvent e) {
461: textField.setMaximumLength(-1);
462: passwordField.setMaximumLength(-1);
463: textArea.setMaximumLength(-1);
464: }
465: });
466: controlsColumn.addButton("Insets -> null",
467: new ActionListener() {
468: public void actionPerformed(ActionEvent e) {
469: textField.setInsets(null);
470: passwordField.setInsets(null);
471: textArea.setInsets(null);
472: }
473: });
474: controlsColumn.addButton("Insets -> 0px", new ActionListener() {
475: public void actionPerformed(ActionEvent e) {
476: textField.setInsets(new Insets(0));
477: passwordField.setInsets(new Insets(0));
478: textArea.setInsets(new Insets(0));
479: }
480: });
481: controlsColumn.addButton("Insets -> 5px", new ActionListener() {
482: public void actionPerformed(ActionEvent e) {
483: textField.setInsets(new Insets(5));
484: passwordField.setInsets(new Insets(5));
485: textArea.setInsets(new Insets(5));
486: }
487: });
488: controlsColumn.addButton("Insets -> 10/20/30/40px",
489: new ActionListener() {
490: public void actionPerformed(ActionEvent e) {
491: textField.setInsets(new Insets(10, 20, 30, 40));
492: passwordField.setInsets(new Insets(10, 20, 30,
493: 40));
494: textArea.setInsets(new Insets(10, 20, 30, 40));
495: }
496: });
497: controlsColumn.addButton("Width -> null", new ActionListener() {
498: public void actionPerformed(ActionEvent e) {
499: textField.setWidth(null);
500: passwordField.setWidth(null);
501: textArea.setWidth(null);
502: }
503: });
504: controlsColumn.addButton("Width -> 500px",
505: new ActionListener() {
506: public void actionPerformed(ActionEvent e) {
507: textField.setWidth(new Extent(500, Extent.PX));
508: passwordField.setWidth(new Extent(500,
509: Extent.PX));
510: textArea.setWidth(new Extent(500, Extent.PX));
511: }
512: });
513: controlsColumn.addButton("Width -> 100%", new ActionListener() {
514: public void actionPerformed(ActionEvent e) {
515: textField.setWidth(new Extent(100, Extent.PERCENT));
516: passwordField.setWidth(new Extent(100, Extent.PERCENT));
517: textArea.setWidth(new Extent(100, Extent.PERCENT));
518: }
519: });
520: controlsColumn.addButton("Height -> null",
521: new ActionListener() {
522: public void actionPerformed(ActionEvent e) {
523: textField.setHeight(null);
524: passwordField.setHeight(null);
525: textArea.setHeight(null);
526: }
527: });
528: controlsColumn.addButton("Height -> 300px",
529: new ActionListener() {
530: public void actionPerformed(ActionEvent e) {
531: textField.setHeight(new Extent(300, Extent.PX));
532: passwordField.setHeight(new Extent(300,
533: Extent.PX));
534: textArea.setHeight(new Extent(300, Extent.PX));
535: }
536: });
537: controlsColumn.addButton("Toggle Enabled",
538: new ActionListener() {
539: public void actionPerformed(ActionEvent e) {
540: boolean enabled = !textField.isEnabled();
541: textField.setEnabled(enabled);
542: passwordField.setEnabled(enabled);
543: textArea.setEnabled(enabled);
544: }
545: });
546: controlsColumn.addButton("Focus TextField",
547: new ActionListener() {
548: public void actionPerformed(ActionEvent e) {
549: getApplicationInstance().setFocusedComponent(
550: textField);
551: }
552: });
553: controlsColumn.addButton("Focus PasswordField",
554: new ActionListener() {
555: public void actionPerformed(ActionEvent e) {
556: getApplicationInstance().setFocusedComponent(
557: passwordField);
558: }
559: });
560: controlsColumn.addButton("Focus TextArea",
561: new ActionListener() {
562: public void actionPerformed(ActionEvent e) {
563: getApplicationInstance().setFocusedComponent(
564: textArea);
565: }
566: });
567: }
568: }
|