KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > testapp > interactive > testscreen > TextComponentTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.testapp.interactive.testscreen;
31
32 import nextapp.echo2.app.FillImage;
33 import nextapp.echo2.app.Border;
34 import nextapp.echo2.app.Color;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.Insets;
37 import nextapp.echo2.app.PasswordField;
38 import nextapp.echo2.app.Column;
39 import nextapp.echo2.app.SplitPane;
40 import nextapp.echo2.app.TextArea;
41 import nextapp.echo2.app.TextField;
42 import nextapp.echo2.app.event.ActionEvent;
43 import nextapp.echo2.app.event.ActionListener;
44 import nextapp.echo2.app.event.DocumentEvent;
45 import nextapp.echo2.app.event.DocumentListener;
46 import nextapp.echo2.app.layout.SplitPaneLayoutData;
47 import nextapp.echo2.testapp.interactive.ButtonColumn;
48 import nextapp.echo2.testapp.interactive.InteractiveApp;
49 import nextapp.echo2.testapp.interactive.StyleUtil;
50 import nextapp.echo2.testapp.interactive.Styles;
51
52 public class TextComponentTest extends SplitPane {
53     
54     /**
55      * Writes <code>ActionEvent</code>s to console.
56      */

57     private ActionListener actionListener = new ActionListener() {
58
59         /**
60          * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
61          */

62         public void actionPerformed(ActionEvent e) {
63             ((InteractiveApp) getApplicationInstance()).consoleWrite(e.toString());
64         }
65     };
66     
67     /**
68      * Writes <code>ActionEvent</code>s to console.
69      */

70     private DocumentListener documentListener = new DocumentListener() {
71         
72         /**
73          * @see nextapp.echo2.app.event.DocumentListener#documentUpdate(nextapp.echo2.app.event.DocumentEvent)
74          */

75         public void documentUpdate(DocumentEvent e) {
76             ((InteractiveApp) getApplicationInstance()).consoleWrite(e.toString());
77         }
78     };
79     
80     public TextComponentTest() {
81         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
82         setStyleName("DefaultResizable");
83
84         SplitPaneLayoutData splitPaneLayoutData;
85         
86         ButtonColumn controlsColumn = new ButtonColumn();
87         controlsColumn.setStyleName("TestControlsColumn");
88         add(controlsColumn);
89
90         Column testColumn = new Column();
91         testColumn.setCellSpacing(new Extent(15));
92         splitPaneLayoutData = new SplitPaneLayoutData();
93         splitPaneLayoutData.setInsets(new Insets(15));
94         testColumn.setLayoutData(splitPaneLayoutData);
95         add(testColumn);
96         
97         final TextField textField = new TextField();
98         textField.setBorder(new Border(1, Color.BLUE, Border.STYLE_SOLID));
99         testColumn.add(textField);
100         
101         final PasswordField passwordField = new PasswordField();
102         passwordField.setBorder(new Border(1, Color.BLUE, Border.STYLE_SOLID));
103         testColumn.add(passwordField);
104         
105         final TextArea textArea = new TextArea();
106         textArea.setBorder(new Border(1, Color.BLUE, Border.STYLE_SOLID));
107         testColumn.add(textArea);
108         
109         controlsColumn.addButton("Set Text to Multiple Lines", new ActionListener() {
110             public void actionPerformed(ActionEvent e) {
111                 String JavaDoc text = "This\nis\na\ntest.";
112                 textField.getDocument().setText(text);
113                 passwordField.getDocument().setText(text);
114                 textArea.getDocument().setText(text);
115             }
116         });
117         
118         controlsColumn.addButton("Test HTML Encoding", new ActionListener() {
119             public void actionPerformed(ActionEvent e) {
120                 String JavaDoc text = "<b>this should NOT be bold</b>";
121                 textField.getDocument().setText(text);
122                 passwordField.getDocument().setText(text);
123                 textArea.getDocument().setText(text);
124             }
125         });
126         
127         controlsColumn.addButton("Test Whitespace Encoding", new ActionListener() {
128             public void actionPerformed(ActionEvent e) {
129                 String JavaDoc text = " There are three spaces leading, trailing, "
130                         + "and between each word. ";
131                 textField.getDocument().setText(text);
132                 passwordField.getDocument().setText(text);
133                 textArea.getDocument().setText(text);
134             }
135         });
136         controlsColumn.addButton("Toggle ToolTip Text", new ActionListener(){
137             public void actionPerformed(ActionEvent e) {
138                 if (textField.getToolTipText() == null) {
139                     textField.setToolTipText("This is a tool tip.");
140                     passwordField.setToolTipText("This is a tool tip.");
141                     textArea.setToolTipText("This is a tool tip.");
142                 } else {
143                     textField.setToolTipText(null);
144                     passwordField.setToolTipText(null);
145                     textArea.setToolTipText(null);
146                 }
147             }
148         });
149         controlsColumn.addButton("Add ActionListener", new ActionListener() {
150             public void actionPerformed(ActionEvent e) {
151                 textField.addActionListener(actionListener);
152                 passwordField.addActionListener(actionListener);
153                 textArea.addActionListener(actionListener);
154             }
155         });
156         controlsColumn.addButton("Remove ActionListener", new ActionListener() {
157             public void actionPerformed(ActionEvent e) {
158                 textField.removeActionListener(actionListener);
159                 passwordField.removeActionListener(actionListener);
160                 textArea.removeActionListener(actionListener);
161             }
162         });
163         controlsColumn.addButton("Add DocumentListener", new ActionListener() {
164             public void actionPerformed(ActionEvent e) {
165                 textField.getDocument().addDocumentListener(documentListener);
166                 passwordField.getDocument().addDocumentListener(documentListener);
167                 textArea.getDocument().addDocumentListener(documentListener);
168             }
169         });
170         controlsColumn.addButton("Remove DocumentListener", new ActionListener() {
171             public void actionPerformed(ActionEvent e) {
172                 textField.getDocument().removeDocumentListener(documentListener);
173                 passwordField.getDocument().removeDocumentListener(documentListener);
174                 textArea.getDocument().removeDocumentListener(documentListener);
175             }
176         });
177
178         controlsColumn.addButton("Horizontal Scroll = 0px", new ActionListener() {
179             public void actionPerformed(ActionEvent e) {
180                 textField.setHorizontalScroll(new Extent(0));
181                 passwordField.setHorizontalScroll(new Extent(0));
182                 textArea.setHorizontalScroll(new Extent(0));
183             }
184         });
185         
186         controlsColumn.addButton("Horizontal Scroll = 100px", new ActionListener() {
187             public void actionPerformed(ActionEvent e) {
188                 textField.setHorizontalScroll(new Extent(100));
189                 passwordField.setHorizontalScroll(new Extent(100));
190                 textArea.setHorizontalScroll(new Extent(100));
191             }
192         });
193         
194         controlsColumn.addButton("Vertical Scroll = 0px", new ActionListener() {
195             public void actionPerformed(ActionEvent e) {
196                 textField.setVerticalScroll(new Extent(0));
197                 passwordField.setVerticalScroll(new Extent(0));
198                 textArea.setVerticalScroll(new Extent(0));
199             }
200         });
201         
202         controlsColumn.addButton("Vertical Scroll = 100px", new ActionListener() {
203             public void actionPerformed(ActionEvent e) {
204                 textField.setVerticalScroll(new Extent(100));
205                 passwordField.setVerticalScroll(new Extent(100));
206                 textArea.setVerticalScroll(new Extent(100));
207             }
208         });
209         
210         controlsColumn.addButton("Change Border (All Attributes)", new ActionListener() {
211             public void actionPerformed(ActionEvent e) {
212                 Border border = StyleUtil.randomBorder();
213                 textField.setBorder(border);
214                 passwordField.setBorder(border);
215                 textArea.setBorder(border);
216             }
217         });
218         controlsColumn.addButton("Change Border Color", new ActionListener() {
219             public void actionPerformed(ActionEvent e) {
220                 Border border = textField.getBorder();
221                 if (border == null) {
222                     return;
223                 }
224                 border = new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle());
225                 textField.setBorder(border);
226                 passwordField.setBorder(border);
227                 textArea.setBorder(border);
228             }
229         });
230         controlsColumn.addButton("Change Border Size", new ActionListener() {
231             public void actionPerformed(ActionEvent e) {
232                 Border border = StyleUtil.nextBorderSize(textField.getBorder());
233                 if (border == null) {
234                     return;
235                 }
236                 textField.setBorder(border);
237                 passwordField.setBorder(border);
238                 textArea.setBorder(border);
239             }
240         });
241         controlsColumn.addButton("Change Border Style", new ActionListener() {
242             public void actionPerformed(ActionEvent e) {
243                 Border border = StyleUtil.nextBorderStyle(textField.getBorder());
244                 if (border == null) {
245                     return;
246                 }
247                 textField.setBorder(border);
248                 passwordField.setBorder(border);
249                 textArea.setBorder(border);
250             }
251         });
252         controlsColumn.addButton("Toggle Background Image", new ActionListener() {
253             public void actionPerformed(ActionEvent e) {
254                 FillImage backgroundImage = textField.getBackgroundImage();
255                 if (backgroundImage == null) {
256                     textField.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
257                     passwordField.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
258                     textArea.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
259                 } else {
260                     textField.setBackgroundImage(null);
261                     passwordField.setBackgroundImage(null);
262                     textArea.setBackgroundImage(null);
263                 }
264             }
265         });
266         controlsColumn.addButton("Set Foreground", new ActionListener() {
267             public void actionPerformed(ActionEvent e) {
268                 Color color = StyleUtil.randomColor();
269                 textField.setForeground(color);
270                 passwordField.setForeground(color);
271                 textArea.setForeground(color);
272             }
273         });
274         controlsColumn.addButton("Clear Foreground", new ActionListener() {
275             public void actionPerformed(ActionEvent e) {
276                 textField.setForeground(null);
277                 passwordField.setForeground(null);
278                 textArea.setForeground(null);
279             }
280         });
281         controlsColumn.addButton("Set Background", new ActionListener() {
282             public void actionPerformed(ActionEvent e) {
283                 Color color = StyleUtil.randomColor();
284                 textField.setBackground(color);
285                 passwordField.setBackground(color);
286                 textArea.setBackground(color);
287             }
288         });
289         controlsColumn.addButton("Clear Background", new ActionListener() {
290             public void actionPerformed(ActionEvent e) {
291                 textField.setBackground(null);
292                 passwordField.setBackground(null);
293                 textArea.setBackground(null);
294             }
295         });
296         controlsColumn.addButton("Change Disabled Border (All Attributes)", new ActionListener() {
297             public void actionPerformed(ActionEvent e) {
298                 Border border = StyleUtil.randomBorder();
299                 textField.setDisabledBorder(border);
300                 passwordField.setDisabledBorder(border);
301                 textArea.setDisabledBorder(border);
302             }
303         });
304         controlsColumn.addButton("Change Disabled Border Color", new ActionListener() {
305             public void actionPerformed(ActionEvent e) {
306                 Border border = textField.getDisabledBorder();
307                 if (border == null) {
308                     return;
309                 }
310                 border = new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle());
311                 textField.setDisabledBorder(border);
312                 passwordField.setDisabledBorder(border);
313                 textArea.setDisabledBorder(border);
314             }
315         });
316         controlsColumn.addButton("Change Disabled Border Size", new ActionListener() {
317             public void actionPerformed(ActionEvent e) {
318                 Border border = StyleUtil.nextBorderSize(textField.getDisabledBorder());
319                 if (border == null) {
320                     return;
321                 }
322                 textField.setDisabledBorder(border);
323                 passwordField.setDisabledBorder(border);
324                 textArea.setDisabledBorder(border);
325             }
326         });
327         controlsColumn.addButton("Change Disabled Border Style", new ActionListener() {
328             public void actionPerformed(ActionEvent e) {
329                 Border border = StyleUtil.nextBorderStyle(textField.getDisabledBorder());
330                 if (border == null) {
331                     return;
332                 }
333                 textField.setDisabledBorder(border);
334                 passwordField.setDisabledBorder(border);
335                 textArea.setDisabledBorder(border);
336             }
337         });
338         controlsColumn.addButton("Toggle Disabled Background Image", new ActionListener() {
339             public void actionPerformed(ActionEvent e) {
340                 FillImage backgroundImage = textField.getDisabledBackgroundImage();
341                 if (backgroundImage == null) {
342                     textField.setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
343                     passwordField.setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
344                     textArea.setDisabledBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
345                 } else {
346                     textField.setDisabledBackgroundImage(null);
347                     passwordField.setDisabledBackgroundImage(null);
348                     textArea.setDisabledBackgroundImage(null);
349                 }
350             }
351         });
352         controlsColumn.addButton("Set Disabled Foreground", new ActionListener() {
353             public void actionPerformed(ActionEvent e) {
354                 Color color = StyleUtil.randomColor();
355                 textField.setDisabledForeground(color);
356                 passwordField.setDisabledForeground(color);
357                 textArea.setDisabledForeground(color);
358             }
359         });
360         controlsColumn.addButton("Clear Disabled Foreground", new ActionListener() {
361             public void actionPerformed(ActionEvent e) {
362                 textField.setDisabledForeground(null);
363                 passwordField.setDisabledForeground(null);
364                 textArea.setDisabledForeground(null);
365             }
366         });
367         controlsColumn.addButton("Set Disabled Background", new ActionListener() {
368             public void actionPerformed(ActionEvent e) {
369                 Color color = StyleUtil.randomColor();
370                 textField.setDisabledBackground(color);
371                 passwordField.setDisabledBackground(color);
372                 textArea.setDisabledBackground(color);
373             }
374         });
375         controlsColumn.addButton("Clear Disabled Background", new ActionListener() {
376             public void actionPerformed(ActionEvent e) {
377                 textField.setDisabledBackground(null);
378                 passwordField.setDisabledBackground(null);
379                 textArea.setDisabledBackground(null);
380             }
381         });
382         controlsColumn.addButton("Set MaximumLength=10", new ActionListener() {
383             public void actionPerformed(ActionEvent e) {
384                 textField.setMaximumLength(10);
385                 passwordField.setMaximumLength(10);
386                 textArea.setMaximumLength(10);
387             }
388         });
389         controlsColumn.addButton("Clear MaximumLength", new ActionListener() {
390             public void actionPerformed(ActionEvent e) {
391                 textField.setMaximumLength(-1);
392                 passwordField.setMaximumLength(-1);
393                 textArea.setMaximumLength(-1);
394             }
395         });
396         controlsColumn.addButton("Insets -> null", new ActionListener() {
397             public void actionPerformed(ActionEvent e) {
398                 textField.setInsets(null);
399                 passwordField.setInsets(null);
400                 textArea.setInsets(null);
401             }
402         });
403         controlsColumn.addButton("Insets -> 0px", new ActionListener() {
404             public void actionPerformed(ActionEvent e) {
405                 textField.setInsets(new Insets(0));
406                 passwordField.setInsets(new Insets(0));
407                 textArea.setInsets(new Insets(0));
408             }
409         });
410         controlsColumn.addButton("Insets -> 5px", new ActionListener() {
411             public void actionPerformed(ActionEvent e) {
412                 textField.setInsets(new Insets(5));
413                 passwordField.setInsets(new Insets(5));
414                 textArea.setInsets(new Insets(5));
415             }
416         });
417         controlsColumn.addButton("Insets -> 10/20/30/40px", new ActionListener() {
418             public void actionPerformed(ActionEvent e) {
419                 textField.setInsets(new Insets(10, 20, 30, 40));
420                 passwordField.setInsets(new Insets(10, 20, 30, 40));
421                 textArea.setInsets(new Insets(10, 20, 30, 40));
422             }
423         });
424         controlsColumn.addButton("Width -> null", new ActionListener() {
425             public void actionPerformed(ActionEvent e) {
426                 textField.setWidth(null);
427                 passwordField.setWidth(null);
428                 textArea.setWidth(null);
429             }
430         });
431         controlsColumn.addButton("Width -> 500px", new ActionListener() {
432             public void actionPerformed(ActionEvent e) {
433                 textField.setWidth(new Extent(500, Extent.PX));
434                 passwordField.setWidth(new Extent(500, Extent.PX));
435                 textArea.setWidth(new Extent(500, Extent.PX));
436             }
437         });
438         controlsColumn.addButton("Width -> 100%", new ActionListener() {
439             public void actionPerformed(ActionEvent e) {
440                 textField.setWidth(new Extent(100, Extent.PERCENT));
441                 passwordField.setWidth(new Extent(100, Extent.PERCENT));
442                 textArea.setWidth(new Extent(100, Extent.PERCENT));
443             }
444         });
445         controlsColumn.addButton("Height -> null", new ActionListener() {
446             public void actionPerformed(ActionEvent e) {
447                 textField.setHeight(null);
448                 passwordField.setHeight(null);
449                 textArea.setHeight(null);
450             }
451         });
452         controlsColumn.addButton("Height -> 300px", new ActionListener() {
453             public void actionPerformed(ActionEvent e) {
454                 textField.setHeight(new Extent(300, Extent.PX));
455                 passwordField.setHeight(new Extent(300, Extent.PX));
456                 textArea.setHeight(new Extent(300, Extent.PX));
457             }
458         });
459         controlsColumn.addButton("Toggle Enabled", new ActionListener() {
460             public void actionPerformed(ActionEvent e) {
461                 boolean enabled = !textField.isEnabled();
462                 textField.setEnabled(enabled);
463                 passwordField.setEnabled(enabled);
464                 textArea.setEnabled(enabled);
465             }
466         });
467         controlsColumn.addButton("Focus TextField", new ActionListener() {
468             public void actionPerformed(ActionEvent e) {
469                 getApplicationInstance().setFocusedComponent(textField);
470             }
471         });
472         controlsColumn.addButton("Focus PasswordField", new ActionListener() {
473             public void actionPerformed(ActionEvent e) {
474                 getApplicationInstance().setFocusedComponent(passwordField);
475             }
476         });
477         controlsColumn.addButton("Focus TextArea", new ActionListener() {
478             public void actionPerformed(ActionEvent e) {
479                 getApplicationInstance().setFocusedComponent(textArea);
480             }
481         });
482     }
483 }
484
Popular Tags