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 |
|
---|
19 | package org.expeditee.io;
|
---|
20 |
|
---|
21 | import java.awt.Desktop;
|
---|
22 | import java.awt.Point;
|
---|
23 | import java.awt.Polygon;
|
---|
24 | import java.awt.Rectangle;
|
---|
25 | import java.awt.geom.Area;
|
---|
26 | import java.io.File;
|
---|
27 | import java.io.IOException;
|
---|
28 | import java.io.Writer;
|
---|
29 | import java.lang.reflect.Array;
|
---|
30 | import java.util.ArrayList;
|
---|
31 | import java.util.Collection;
|
---|
32 | import java.util.Collections;
|
---|
33 | import java.util.Comparator;
|
---|
34 | import java.util.List;
|
---|
35 |
|
---|
36 | import org.expeditee.gui.Browser;
|
---|
37 | import org.expeditee.gui.Frame;
|
---|
38 | import org.expeditee.gui.FrameUtils;
|
---|
39 | import org.expeditee.io.flowlayout.AreaPolygon;
|
---|
40 | import org.expeditee.io.flowlayout.DimensionExtent;
|
---|
41 | import org.expeditee.io.flowlayout.XGroupItem;
|
---|
42 | import org.expeditee.io.flowlayout.XItem;
|
---|
43 | import org.expeditee.io.flowlayout.XOrderedLine;
|
---|
44 | import org.expeditee.io.flowlayout.XRawItem;
|
---|
45 | import org.expeditee.io.flowlayout.YOverlappingItemsShadow;
|
---|
46 | import org.expeditee.io.flowlayout.YOverlappingItemsSpan;
|
---|
47 | import org.expeditee.io.flowlayout.YOverlappingItemsTopEdge;
|
---|
48 | import org.expeditee.items.Item;
|
---|
49 | import org.expeditee.items.ItemUtils;
|
---|
50 | import org.expeditee.items.Text;
|
---|
51 |
|
---|
52 | public class JavaWriter extends DefaultTreeWriter {
|
---|
53 |
|
---|
54 |
|
---|
55 | // may be needed for sectioning commands
|
---|
56 | private Text _title = null;
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | protected void initialise(Frame start, Writer writer) throws IOException {
|
---|
62 | _format = ".java";
|
---|
63 | super.initialise(start, writer);
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected String getFileName(Frame start) {
|
---|
67 | String start_title = start.getTitle();
|
---|
68 |
|
---|
69 | String start_filename = start_title.replaceAll("\\.", "/");
|
---|
70 |
|
---|
71 | return getValidFilename(start_filename);
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected void writeTitle(Text title, List<Item> items) throws IOException {
|
---|
75 | _title = title;
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | protected List<Item> getSortedItems(Frame frame)
|
---|
84 | {
|
---|
85 | List<Item> y_ordered_items = frame.getItems();
|
---|
86 |
|
---|
87 | for (Item item: y_ordered_items) {
|
---|
88 | if (item instanceof Text) {
|
---|
89 | Text text_item = (Text)item;
|
---|
90 | if (text_item.getText().equalsIgnoreCase("@doImplicitBoxing")) {
|
---|
91 | XGroupItem.doImplicitBoxing = true;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | XGroupItem toplevel_xgroup = new XGroupItem(frame,y_ordered_items);
|
---|
96 |
|
---|
97 | // ... following on from Steps 1 and 2 in the Constructor in XGroupItem ...
|
---|
98 |
|
---|
99 | // Step 3: Reposition any 'out-of-flow' XGroupItems
|
---|
100 | toplevel_xgroup.repositionOutOfFlowGroups(toplevel_xgroup);
|
---|
101 |
|
---|
102 | // Step 4: Now add in the remaining (nested) XGroupItems
|
---|
103 | List<XGroupItem> grouped_item_list = toplevel_xgroup.getGroupedItemList();
|
---|
104 | toplevel_xgroup.mapInXGroupItemsRecursive(grouped_item_list);
|
---|
105 |
|
---|
106 | // Finally, retrieve linear list of all Items, (ordered, Y by X, allowing for overlap, nested-boxing, and arrow flow)
|
---|
107 |
|
---|
108 | List<Item> overlapping_y_ordered_items = toplevel_xgroup.getYXOverlappingItemList();
|
---|
109 |
|
---|
110 | return overlapping_y_ordered_items;
|
---|
111 |
|
---|
112 |
|
---|
113 | /*
|
---|
114 | List<Text> raw_text_item_list = new ArrayList<Text>();
|
---|
115 | List<XGroupItem> grouped_item_list = new ArrayList<XGroupItem>();
|
---|
116 | List<Item> remaining_item_list = new ArrayList<Item>();
|
---|
117 |
|
---|
118 | XGroupItem.separateYOverlappingItems(frame, y_ordered_items, raw_text_item_list, grouped_item_list, remaining_item_list);
|
---|
119 | */
|
---|
120 |
|
---|
121 |
|
---|
122 | }
|
---|
123 |
|
---|
124 | @Override
|
---|
125 | protected String finalise() throws IOException {
|
---|
126 | try {
|
---|
127 | _writer.flush();
|
---|
128 | _writer.close();
|
---|
129 | } catch (IOException ioe) {
|
---|
130 | } finally {
|
---|
131 | _writer.close();
|
---|
132 | }
|
---|
133 |
|
---|
134 | return " exported to " + _output;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 | @Override
|
---|
140 | protected void writeText(Text text) throws IOException {
|
---|
141 | for (String s : text.getTextList()) {
|
---|
142 | _writer.write(s);
|
---|
143 | _writer.write(ItemWriter.NEW_LINE);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | @Override
|
---|
148 | protected void writeAnnotationText(Text text) throws IOException {
|
---|
149 |
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|