source: trunk/src/org/expeditee/io/TEXWriter.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: 2.3 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.ItemUtils;
9import org.expeditee.items.Text;
10
11public class TEXWriter extends DefaultTreeWriter {
12
13 // may be needed for sectioning commands
14 private Text _title = null;
15
16 @Override
17 protected void initialise(Frame start) throws IOException {
18 _format = ".tex";
19 super.initialise(start);
20 }
21
22 protected void writeTitle(Text title, List<Item> items) throws IOException {
23 _title = title;
24
25 Text text = ItemUtils.FindTag(items, "@TexSection");
26
27 if (text != null) {
28 String first = text.getFirstLine();
29 int ind = first.indexOf(":");
30
31 if (ind > 0) {
32 String command = first.substring(ind + 1).trim().toLowerCase();
33
34 _writer.write("\\" + command + "{");
35
36 List<String> titleLines = _title.getTextList();
37 for (int i = 0; i < titleLines.size() - 1; i++) {
38 _writer.write(titleLines.get(i));
39 _writer.write(ItemWriter.NEW_LINE);
40 }
41
42 _writer.write(titleLines.get(titleLines.size() - 1));
43
44 _writer.write("}" + ItemWriter.NEW_LINE);
45 }
46 }
47 }
48
49 @Override
50 protected void writeStartLink(Item linker) throws IOException {
51 // only output text items
52 if (!(linker instanceof Text))
53 return;
54
55 Text text = (Text) linker;
56 List<String> toWrite = text.getTextList();
57
58 String first = toWrite.get(0);
59 TexEnvironment te = new TexEnvironment(first);
60
61 if (te.isValid()) {
62 if (te.hasComment())
63 _writer.write("%" + te.getComment() + ItemWriter.NEW_LINE);
64 _writer.write("\\begin{" + te.getName() + "}" + ItemWriter.NEW_LINE);
65 }
66 }
67
68 @Override
69 protected void writeEndLink(Item linker) throws IOException {
70 // only output text items
71 if (!(linker instanceof Text))
72 return;
73
74 Text text = (Text) linker;
75 List<String> toWrite = text.getTextList();
76
77 String first = toWrite.get(0);
78 TexEnvironment te = new TexEnvironment(first);
79
80 if (te.isValid()) {
81 _writer.write("\\end{" + te.getName() + "}" + ItemWriter.NEW_LINE);
82 }
83
84 }
85
86 @Override
87 protected void writeText(Text text) throws IOException {
88 for (String s : text.getTextList()) {
89 _writer.write(s);
90 _writer.write(ItemWriter.NEW_LINE);
91 }
92 }
93
94 @Override
95 protected void writeAnnotationText(Text text) throws IOException {
96
97 }
98}
99
Note: See TracBrowser for help on using the repository browser.