source: trunk/src/org/expeditee/io/JAVAWriter.java@ 289

Last change on this file since 289 was 80, checked in by ra33, 16 years ago

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

File size: 1.5 KB
Line 
1package org.expeditee.io;
2
3import java.io.IOException;
4import java.util.List;
5
6import org.expeditee.gui.Frame;
7import org.expeditee.items.Item;
8import org.expeditee.items.Picture;
9import org.expeditee.items.Text;
10
11public class JAVAWriter extends DefaultTreeWriter {
12
13 private int _indent = 0;
14
15 private static final String INDENT = " ";
16
17 @Override
18 protected void initialise(Frame start) throws IOException {
19 _format = ".java";
20 super.initialise(start);
21
22 // write the package and import statements here!!
23 }
24
25 @Override
26 protected String finaliseTree() throws IOException {
27 _writer.write("}" + ItemWriter.NEW_LINE);
28 return super.finaliseTree();
29 }
30
31 @Override
32 protected void writeStartLink(Item linker) throws IOException {
33 indent();
34 _writer.write("{" + ItemWriter.NEW_LINE);
35 _indent++;
36 }
37
38 @Override
39 protected void writeEndLink(Item linker) throws IOException {
40 _indent--;
41 indent();
42 _writer.write("}" + ItemWriter.NEW_LINE);
43 }
44
45 @Override
46 protected void writeTitle(Text toWrite, List<Item> items)
47 throws IOException {
48 String heading = toWrite.getText();
49
50 _writer.write("public class " + heading + "{" + ItemWriter.NEW_LINE);
51 }
52
53 @Override
54 protected void writeText(Text text) throws IOException {
55 indent();
56 _writer.write(text.getText().replace('\n', ' '));
57 _writer.write(";" + ItemWriter.NEW_LINE);
58 }
59
60 private void indent() throws IOException {
61 for (int i = 0; i < _indent; i++)
62 _writer.write(INDENT);
63 }
64
65 @Override
66 protected void writePicture(Picture pic) throws IOException {
67 }
68}
Note: See TracBrowser for help on using the repository browser.