KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > testapp > interactive > StyleUtil


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;
31
32 import nextapp.echo2.app.Alignment;
33 import nextapp.echo2.app.Border;
34 import nextapp.echo2.app.Color;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.Font;
37
38 /**
39  *
40  */

41 public class StyleUtil {
42     
43     public static final String JavaDoc QUASI_LATIN_TEXT_1 =
44             "Ymo, lobortis camur qui typicus voco. Jugis similis wisi singularis dolor suscipit. " +
45             "Fatua premo regula fatua huic, vereor dolus aptent tego, quidne vero valetudo esse enim exerci. " +
46             "Refero quae ut importunus si sit. Aliquam illum, nostrud qui duis nimis refero esse jugis " +
47             "sit jus, duis, tum vel capio. Quadrum pertineo dignissim diam in ut adipiscing magna eros " +
48             "neque exerci vulputate commodo indoles. Sed dolor, oppeto pala eu veniam. Ullamcorper typicus " +
49             "hos erat neque suscipere defui feugiat velit acsi pneum vel comis luptatum." +
50             "Zelus quidem, natu, delenit, veniam, tristique eligo transverbero. Ea, plaga vel et illum " +
51             "sed diam quia iriure. Ludus quidem, tation pecus, interdico quis sit mos cui ideo feugait nutus " +
52             "utinam at iriure. Secundum vulputate inhibeo wisi pneum fatua facilisi fatua consequat facilisi " +
53             "lucidus. Validus verto vel sudo letalis molior eum exerci epulae nostrud haero esse. Utrum " +
54             "aliquip, pneum typicus similis minim sed laoreet, quidem. Oppeto ille nutus neque veniam, et, " +
55             "abdo, conventio sit, ea wisi neo dolore. At, inhibeo laoreet validus nulla, delenit nimis et " +
56             "quis turpis neo dignissim abigo adsum. Aliquam illum, nostrud qui duis nimis refero esse jugis " +
57             "sit jus, duis, tum vel capio. Nobis vero refero valetudo huic enim nobis wisi comis haero " +
58             "validus. Consequat foras, opto torqueo illum, adipiscing nobis. Te patria, feugiat, feugiat ut " +
59             "tincidunt ventosus nisl amet lucidus, premo vel illum exerci. Exerci imputo meus ut ingenium " +
60             "tincidunt vulpes, multo ut, vindico luptatum. Duis hendrerit brevitas tristique esse abluo in " +
61             "persto praesent, in ibidem augue melior delenit quadrum. Veniam lobortis duis wisi gilvus immitto " +
62             "defui amet importunus indoles pneum odio hos minim. Olim nimis suscipere ullamcorper, utinam ut " +
63             "odio, praemitto, praesent facilisi ad consequat facilisi. Duis hendrerit brevitas tristique esse " +
64             "abluo in persto praesent, in ibidem augue melior delenit quadrum. Sudo bis, inhibeo exerci proprius " +
65             "magna macto feugiat autem vel veniam vulputate ut. Aliquip, multo tego, esse letalis similis, " +
66             "abbas abluo elit aliquam qui olim ymo, torqueo. Jus suscipit valetudo velit virtus dolore autem " +
67             "nulla imputo nostrud minim. Nisl vero sino paratus acsi similis epulae odio euismod refero " +
68             "tation. Autem conventio regula accumsan fatua virtus.";
69
70     
71     // Everyone shares the "next" constants.
72
private static int nextBorderStyle = 0;
73     private static int nextBorderSize = 0;
74
75     private static Font.Typeface[] TYPEFACES = new Font.Typeface[]{Font.COURIER_NEW, Font.VERDANA, Font.TIMES_NEW_ROMAN};
76     
77     private static int[] BORDER_SIZES = new int[]{0, 1, 2, 3, 4, 5, 10, 15, 20, 40, 80};
78     
79     private static int[] FONT_SIZES = new int[]{6, 8, 10, 12, 16, 24, 48, 72};
80     
81     private static final int[] BORDER_STYLES
82             = new int[]{Border.STYLE_NONE, Border.STYLE_INSET, Border.STYLE_OUTSET, Border.STYLE_SOLID,
83             Border.STYLE_DASHED, Border.STYLE_DOTTED, Border.STYLE_DOUBLE, Border.STYLE_RIDGE, Border.STYLE_GROOVE};
84     
85     /**
86      * Choices for random horizontal layout data. <code>Alignment.DEFAULT</code>
87      * listed multiple times to create bias.
88      */

89     private static final int[] HORIZONTAL_ALIGNMENT_VALUES = new int[] { Alignment.DEFAULT, Alignment.DEFAULT, Alignment.DEFAULT,
90             Alignment.LEADING, Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.TRAILING };
91
92     /**
93      * Choices for random vertical layout data. <code>Alignment.DEFAULT</code>
94      * listed multiple times to create bias.
95      */

96     private static final int[] VERTICAL_ALIGNMENT_VALUES = new int[] { Alignment.DEFAULT, Alignment.DEFAULT, Alignment.TOP,
97             Alignment.CENTER, Alignment.BOTTOM };
98     
99     public static Alignment randomAlignmentHV() {
100         return new Alignment(HORIZONTAL_ALIGNMENT_VALUES[(int) (Math.random() * HORIZONTAL_ALIGNMENT_VALUES.length)],
101                 VERTICAL_ALIGNMENT_VALUES[(int) (Math.random() * VERTICAL_ALIGNMENT_VALUES.length)]);
102     }
103     
104     public static Border randomBorder() {
105         return new Border(randomExtent(25), randomColor(), randomBorderStyle());
106     }
107     
108     public static int randomBorderStyle() {
109         return BORDER_STYLES[(int) (Math.random() * BORDER_STYLES.length)];
110     }
111     
112     public static Color randomBrightColor() {
113         return new Color(((int) (16777216 * Math.random())) | 0xb0b0b0);
114     }
115
116     public static Color randomColor() {
117         return new Color((int) (16777216 * Math.random()));
118     }
119     
120     public static Extent randomExtent(int max) {
121         return new Extent((int) (Math.random() * max), Extent.PX);
122     }
123     
124     public static Font randomFont() {
125         Font.Typeface typeface = TYPEFACES[(int) (Math.random() * TYPEFACES.length)];
126         Extent size = new Extent(FONT_SIZES[(int) (Math.random() * FONT_SIZES.length)]);
127         
128         // 1-in-4 chance of each style flag being set:
129
int style = 0;
130         style |= (((int) (Math.random() * 4)) == 0) ? Font.BOLD : 0;
131         style |= (((int) (Math.random() * 4)) == 0) ? Font.ITALIC : 0;
132         style |= (((int) (Math.random() * 4)) == 0) ? Font.UNDERLINE : 0;
133         style |= (((int) (Math.random() * 4)) == 0) ? Font.OVERLINE : 0;
134         style |= (((int) (Math.random() * 4)) == 0) ? Font.LINE_THROUGH : 0;
135         
136         return new Font(typeface, style, size);
137     }
138     
139     public static Border nextBorderStyle(Border border) {
140         if (border == null) {
141             return new Border(1, Color.BLACK, Border.STYLE_SOLID);
142         } else {
143             return new Border(border.getSize(), border.getColor(),
144                     BORDER_STYLES[nextBorderStyle++ % BORDER_STYLES.length]);
145         }
146     }
147     
148     public static Border nextBorderSize(Border border) {
149         if (border == null) {
150             return new Border(1, Color.BLACK, Border.STYLE_SOLID);
151         } else {
152             return new Border(BORDER_SIZES[nextBorderSize++ % BORDER_SIZES.length],
153                     border.getColor(), border.getStyle());
154         }
155     }
156 }
157
Popular Tags