KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > generation > asciiart > AsciiArtPadTestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.generation.asciiart;
17
18 import java.text.NumberFormat JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Locale JavaDoc;
21
22 import junit.framework.TestCase;
23 import junit.textui.TestRunner;
24
25 /**
26  * A Simple testcase of the AsciiArtPad.
27  *
28  * @author huber.at.apache.org
29  * @since 18. December 2002
30  * @version CVS $Id: AsciiArtPadTestCase.java 230769 2005-08-08 07:51:25Z antonio $
31  */

32 public class AsciiArtPadTestCase extends TestCase {
33
34     private AsciiArtPad asciiArtPad;
35
36
37     /**
38      *Constructor for the AsciiArtPadTestCase object
39      *
40      *@param name Description of Parameter
41      *@since
42      */

43     public AsciiArtPadTestCase(String JavaDoc name) {
44         super(name);
45     }
46
47
48     /**
49      * The main program for the AsciiArtPadTestCase class
50      *
51      *@param args The command line arguments
52      *@exception Exception Description of the Exception
53      */

54     public static void main(final String JavaDoc[] args) throws Exception JavaDoc {
55         final String JavaDoc[] testCaseName = {AsciiArtPadTestCase.class.getName()};
56         TestRunner.main(testCaseName);
57     }
58
59
60     /**
61      * A unit test for JUnit
62      */

63     public void test0() {
64     }
65
66
67     /**
68      * A unit test for JUnit
69      *
70      *@exception Exception Description of the Exception
71      */

72     public void test1() throws Exception JavaDoc {
73         System.out.println("test1()");
74         String JavaDoc[] asciiArt = new String JavaDoc[]{
75         // 1
76
//01234567890123456789
77
"= =",
78                 " +--------------+ ",
79                 " | 1st quarter | ",
80                 " +------------+-+ ",
81                 " | 2nd | ",
82                 " +-----+------+ ",
83                 " | 3rd | ",
84                 " +-----+ ",
85                 "= =",
86                 " +-------------+ ",
87                 " | container | ",
88                 " | | ",
89                 " | +-------+ | ",
90                 " | | part | | ",
91                 " | +-------+ | ",
92                 " | | ",
93                 " +-------------+ ",
94                 "= =",
95                 " +==============+ ",
96                 " | Mail_Header | ",
97                 " | +========+ | ",
98                 " | | Body | | ",
99                 " | +========+ | ",
100                 " | |a |a |a | | ",
101                 " | |1 |2 |3 | | ",
102                 " | +========+ | ",
103                 " +==============+ ",
104                 "= =",
105                 " +----------------+",
106                 " | header |",
107                 " +----------------+",
108                 " + c | col2 | c +",
109                 " + o | | o +",
110                 " + l | | l +",
111                 " + 1 | | 3 +",
112                 " +----------------+",
113                 " | footer |",
114                 " +----------------+",
115                 "= =",
116                 " +---stylesheets ",
117                 " +---docs ",
118                 " | +---top_col_1 ",
119                 " | +---mid_col_1 ",
120                 " | +---mid_col_2 ",
121                 " | +---mid_col_3 ",
122                 " | +---mid_col_4 ",
123                 " | \\---bottom_col_1",
124                 " \\---resources",
125                 " |---styles",
126                 " \\---images",
127                 };
128
129         asciiArtPad = new AsciiArtPad();
130         asciiArtPad.setXGrid(10);
131         asciiArtPad.setYGrid(12);
132         AsciiArtPad.AsciiArtPadBuilder aapb = new AsciiArtPad.AsciiArtPadBuilder(asciiArtPad);
133         aapb.build(asciiArt);
134
135         Iterator JavaDoc i = asciiArtPad.iterator();
136         NumberFormat JavaDoc nf = NumberFormat.getInstance(Locale.US);
137         StringBuffer JavaDoc svg_lines = new StringBuffer JavaDoc();
138         StringBuffer JavaDoc svg_text = new StringBuffer JavaDoc();
139         while (i.hasNext()) {
140             Object JavaDoc o = i.next();
141             double x;
142             double y;
143             if (o instanceof AsciiArtPad.AsciiArtLine) {
144                 AsciiArtPad.AsciiArtLine aal = (AsciiArtPad.AsciiArtLine) o;
145                 x = aal.getXStart();
146                 y = aal.getYStart();
147                 svg_lines.append("<path d=\"");
148                 svg_lines.append("M " + nf.format(x) + " " + nf.format(y));
149
150                 x = aal.getXEnd();
151                 y = aal.getYEnd();
152                 svg_lines.append("L " + nf.format(x) + " " + nf.format(y));
153                 svg_lines.append("\"/>\n");
154
155             } else if (o instanceof AsciiArtPad.AsciiArtString) {
156                 AsciiArtPad.AsciiArtString aas = (AsciiArtPad.AsciiArtString) o;
157                 x = aas.getX();
158                 y = aas.getY();
159                 svg_text.append("<text ");
160                 svg_text.append("x=\"" + nf.format(x) + "\" y=\"" + nf.format(y) + "\">");
161                 svg_text.append("<![CDATA[" + aas.getS() + "]]>");
162                 svg_text.append("</text>\n");
163
164             } else {
165                 System.out.println("o " + o.toString());
166             }
167         }
168         System.out.println("<!-- lines --> ");
169         System.out.println(svg_lines.toString());
170         System.out.println("<!-- text --> ");
171         System.out.println(svg_text.toString());
172     }
173
174
175     /**
176      *The JUnit setup method
177      *
178      *@exception Exception Description of Exception
179      *@since
180      */

181     protected void setUp() throws Exception JavaDoc {
182         super.setUp();
183         asciiArtPad = null;
184     }
185
186
187     /**
188      * The teardown method for JUnit
189      *
190      *@exception Exception Description of the Exception
191      */

192     protected void tearDown() throws Exception JavaDoc {
193         super.tearDown();
194         asciiArtPad = null;
195     }
196 }
197
198
Popular Tags