1 16 package org.apache.cocoon.generation.asciiart; 17 18 import java.text.NumberFormat ; 19 import java.util.Iterator ; 20 import java.util.Locale ; 21 22 import junit.framework.TestCase; 23 import junit.textui.TestRunner; 24 25 32 public class AsciiArtPadTestCase extends TestCase { 33 34 private AsciiArtPad asciiArtPad; 35 36 37 43 public AsciiArtPadTestCase(String name) { 44 super(name); 45 } 46 47 48 54 public static void main(final String [] args) throws Exception { 55 final String [] testCaseName = {AsciiArtPadTestCase.class.getName()}; 56 TestRunner.main(testCaseName); 57 } 58 59 60 63 public void test0() { 64 } 65 66 67 72 public void test1() throws Exception { 73 System.out.println("test1()"); 74 String [] asciiArt = new String []{ 75 "= =", 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 i = asciiArtPad.iterator(); 136 NumberFormat nf = NumberFormat.getInstance(Locale.US); 137 StringBuffer svg_lines = new StringBuffer (); 138 StringBuffer svg_text = new StringBuffer (); 139 while (i.hasNext()) { 140 Object 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 181 protected void setUp() throws Exception { 182 super.setUp(); 183 asciiArtPad = null; 184 } 185 186 187 192 protected void tearDown() throws Exception { 193 super.tearDown(); 194 asciiArtPad = null; 195 } 196 } 197 198 | Popular Tags |