1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.items.Item;
|
---|
8 | import org.expeditee.items.Picture;
|
---|
9 | import org.expeditee.items.Text;
|
---|
10 |
|
---|
11 | public 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.getTextNoList();
|
---|
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.getTextNoList().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 | }
|
---|