source: trunk/src/org/expeditee/io/TEXWriter.java@ 306

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

Added some HELP actions
More mail stuff... and networking stuff
Can now save frames and send messages to peers
Also version control prevent versions from being lost

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