source: trunk/src/org/expeditee/io/DefaultTreeWriter.java@ 1415

Last change on this file since 1415 was 1415, checked in by bln4, 5 years ago

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

File size: 5.4 KB
Line 
1/**
2 * DefaultTreeWriter.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.util.List;
23import java.util.Stack;
24
25import org.expeditee.gui.Frame;
26import org.expeditee.gui.FrameIO;
27import org.expeditee.gui.MessageBay;
28import org.expeditee.io.flowlayout.XGroupItem;
29import org.expeditee.items.Item;
30import org.expeditee.items.Text;
31
32public abstract class DefaultTreeWriter extends DefaultFrameWriter implements
33 TreeWriter {
34
35 private int _indent = 0;
36
37 // the list of frames currently being processed
38 private Stack<FrameCounter> _frames = new Stack<FrameCounter>();
39
40 private int _frameCount = 0;
41
42 public int getFrameCount() {
43 return _frameCount;
44 }
45
46 public String writeTree(Frame toWrite) throws IOException {
47 try {
48 initialise(toWrite);
49 outputTree(toWrite);
50
51 } catch (IOException ioe) {
52 _running = false;
53 throw ioe;
54 } catch (Exception e) {
55 e.printStackTrace();
56 }
57 _running = false;
58 return finaliseTree();
59 }
60
61 /**
62 * This method is used to output any tags before following the Item's link
63 * when using tree writers.
64 *
65 * @param linker
66 * The linked Item that is about to be followed.
67 * @throws IOException
68 */
69 protected void writeStartLink(Item linker) throws IOException {
70 _indent++;
71 }
72
73 /**
74 * This method is called after the Frame the Item links to has been
75 * processed. This allows end tags to be written if the format requires it.
76 *
77 * @param linker
78 * The Item whose link was just followed.
79 * @throws IOException
80 */
81 protected void writeEndLink(Item linker) throws IOException {
82 _indent--;
83 }
84
85 protected void resumeFrame(Frame resuming) {
86 }
87
88 protected List<Item> getSortedItems(Frame frame)
89 {
90 List<Item> items = frame.getSortedItems();
91 return items;
92 }
93
94 protected void outputTree(Frame toWrite) throws IOException {
95 if (toWrite == null) {
96 return;
97 }
98
99 XGroupItem.doImplicitBoxing = false;
100
101 _frames.push(new FrameCounter(toWrite.getName(), -1));
102
103 // process the entire tree of frames in depth-first order
104 while (_frames.size() > 0) {
105 FrameCounter cur = _frames.pop();
106
107 if (_stop)
108 return;
109
110 Frame next = FrameIO.LoadFrame(cur.frame);
111
112 if (next == null) {
113 return;
114 }
115
116 Text title = next.getTitleItem();
117
118 // the items on the frame currently being processed.
119 List<Item> items = getSortedItems(next);
120
121 // write any information relating to the end of the link
122 if (cur.index > 0) {
123 this.writeEndLink(items.get(cur.index));
124 this.resumeFrame(next);
125 } else {
126 MessageBay.overwriteMessage("Writing: " + next.getName());
127 _frameCount++;
128 writeStartFrame(next);
129 }
130
131 boolean complete = true;
132
133 // resume from the next item in the list
134 for (int i = cur.index + 1; i < items.size(); i++) {
135 if (_stop)
136 return;
137
138 Item item = items.get(i);
139
140 // ignore annotation and framenames
141 if (item.getID() >= 0) {
142 // Only follow the links of non annotation text items
143 boolean followLink = item instanceof Text
144 && item.getLink() != null
145 && (!item.isAnnotation() /*|| item.getText()
146 .toLowerCase().equals("@next")*/);
147
148 if (followLink) {
149 cur.index = i;
150 _frames.push(cur);
151
152 // write any information relating to the start of the
153 // link
154 this.writeStartLink(item);
155
156 Frame linked = FrameIO
157 .LoadFrame(item.getAbsoluteLink());
158
159 // if the linked frame was found, then display it next
160 if (linked != null) {
161 FrameCounter fc = new FrameCounter(
162 linked.getName(), -1);
163 if (!_frames.contains(fc)) {
164 // remember what frame we are on before
165 // processing it
166 _frames.push(fc);
167
168 complete = false;
169 // process the loaded frame immediately
170 // (depth-first)
171 break;
172 }
173 }
174 // Don't write out the title here because it is written
175 // out earlier
176 } else if (item != title)
177 this.writeItem(item);
178 }
179 }
180
181 if (complete)
182 writeEndFrame(next);
183 }
184 }
185
186 protected String finaliseTree() throws IOException {
187 return "Tree" + finalise();
188 }
189
190 /**
191 * Inner class used to keep track of what frames have been seen, as well as
192 * what Item in the Frame the processing was up to. Only Frame names are
193 * stored to keep memory usage down.
194 */
195 private class FrameCounter {
196 public int index;
197
198 public String frame;
199
200 public FrameCounter(String f, int i) {
201 frame = f.toLowerCase();
202 index = i;
203 }
204
205 @Override
206 public boolean equals(Object o) {
207 if (o instanceof FrameCounter)
208 return (((FrameCounter) o).frame.equals(frame));// && fc.index
209 // == index);
210
211 return false;
212 }
213 }
214
215 protected int getIndent() {
216 return _indent;
217 }
218}
Note: See TracBrowser for help on using the repository browser.