source: trunk/src/org/expeditee/io/JavaWriter.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 3.4 KB
Line 
1/**
2 * JavaWriter.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.io.IOException;
22import java.io.Writer;
23import java.util.List;
24
25import org.expeditee.gui.Frame;
26import org.expeditee.io.flowlayout.XGroupItem;
27import org.expeditee.items.Item;
28import org.expeditee.items.Text;
29
30public class JavaWriter extends DefaultTreeWriter {
31
32
33 // may be needed for sectioning commands
34 private Text _title = null;
35
36
37
38 @Override
39 protected void initialise(Frame start, Writer writer) throws IOException {
40 _format = ".java";
41 super.initialise(start, writer);
42 }
43
44 protected String getFileName(Frame start) {
45 String start_title = start.getTitle();
46
47 String start_filename = start_title.replaceAll("\\.", "/");
48
49 return getValidFilename(start_filename);
50 }
51
52 protected void writeTitle(Text title, List<Item> items) throws IOException {
53 _title = title;
54
55 }
56
57
58
59
60 @Override
61 protected List<Item> getSortedItems(Frame frame)
62 {
63 List<Item> y_ordered_items = frame.getItems();
64
65 for (Item item: y_ordered_items) {
66 if (item instanceof Text) {
67 Text text_item = (Text)item;
68 if (text_item.getText().equalsIgnoreCase("@doImplicitBoxing")) {
69 XGroupItem.doImplicitBoxing = true;
70 }
71 }
72 }
73 XGroupItem toplevel_xgroup = new XGroupItem(frame,y_ordered_items);
74
75 // ... following on from Steps 1 and 2 in the Constructor in XGroupItem ...
76
77 // Step 3: Reposition any 'out-of-flow' XGroupItems
78 toplevel_xgroup.repositionOutOfFlowGroups(toplevel_xgroup);
79
80 // Step 4: Now add in the remaining (nested) XGroupItems
81 List<XGroupItem> grouped_item_list = toplevel_xgroup.getGroupedItemList();
82 toplevel_xgroup.mapInXGroupItemsRecursive(grouped_item_list);
83
84 // Finally, retrieve linear list of all Items, (ordered, Y by X, allowing for overlap, nested-boxing, and arrow flow)
85
86 List<Item> overlapping_y_ordered_items = toplevel_xgroup.getYXOverlappingItemList();
87
88 return overlapping_y_ordered_items;
89
90
91 /*
92 List<Text> raw_text_item_list = new ArrayList<Text>();
93 List<XGroupItem> grouped_item_list = new ArrayList<XGroupItem>();
94 List<Item> remaining_item_list = new ArrayList<Item>();
95
96 XGroupItem.separateYOverlappingItems(frame, y_ordered_items, raw_text_item_list, grouped_item_list, remaining_item_list);
97 */
98
99
100 }
101
102 @Override
103 protected String finalise() throws IOException {
104 try {
105 _writer.flush();
106 _writer.close();
107 } catch (IOException ioe) {
108 } finally {
109 _writer.close();
110 }
111
112 return " exported to " + _output;
113 }
114
115
116
117 @Override
118 protected void writeText(Text text) throws IOException {
119 for (String s : text.getTextList()) {
120 _writer.write(s);
121 _writer.write(ItemWriter.NEW_LINE);
122 }
123 }
124
125 @Override
126 protected void writeAnnotationText(Text text) throws IOException {
127
128 }
129}
130
Note: See TracBrowser for help on using the repository browser.