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