1 | package org.honours.gui;
|
---|
2 |
|
---|
3 | import java.io.BufferedWriter;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileWriter;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.expeditee.actions.Misc;
|
---|
10 | import org.expeditee.gui.DisplayIO;
|
---|
11 | import org.expeditee.gui.Frame;
|
---|
12 | import org.expeditee.gui.FrameIO;
|
---|
13 | import org.expeditee.gui.FrameKeyboardActions;
|
---|
14 | import org.expeditee.gui.MessageBay;
|
---|
15 | import org.expeditee.gui.UserSettings;
|
---|
16 | import org.expeditee.items.Item;
|
---|
17 | import org.expeditee.items.Text;
|
---|
18 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
19 | import org.expeditee.stats.Formatter;
|
---|
20 | import org.honours.actions.MiscActions;
|
---|
21 | import org.honours.collection.CollectionItem;
|
---|
22 | import org.honours.collection.NoteLayer;
|
---|
23 |
|
---|
24 | public class HonoursFrameIO {
|
---|
25 |
|
---|
26 | private static Frame _lastCopiedFrame = null;
|
---|
27 |
|
---|
28 | public static boolean DISPLAY_TOOLBAR = true;
|
---|
29 | public static boolean DISPLAY_LAYERS = true;
|
---|
30 | public static boolean DISPLAY_NOTES = false;
|
---|
31 |
|
---|
32 | public static boolean DISPLAY_TOGGLER = true;
|
---|
33 |
|
---|
34 | public static String COLLECTIONS_PATH = FrameIO.PARENT_FOLDER +
|
---|
35 | "collections" + File.separator;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Generate a new frame for a given (existing)
|
---|
39 | * frameset.
|
---|
40 | * @param frameNumber - frame number for this next item.
|
---|
41 | * @param frameset - frameset to add frame to.
|
---|
42 | */
|
---|
43 | public static void generateFrame(int frameNumber, String frameset){
|
---|
44 | String frameFileName = FrameIO.FRAME_PATH + frameset + File.separator +
|
---|
45 | frameNumber + ".exp";
|
---|
46 | Frame checkExistingFrame = FrameIO.LoadFrame(frameset + frameNumber);
|
---|
47 |
|
---|
48 | if(checkExistingFrame == null){
|
---|
49 | FileWriter fw;
|
---|
50 | BufferedWriter bw;
|
---|
51 |
|
---|
52 | try{
|
---|
53 | fw = new FileWriter(frameFileName);
|
---|
54 | bw = new BufferedWriter(fw);
|
---|
55 | writeOutFrameHeader(bw);
|
---|
56 | FrameIO.WriteINF(FrameIO.FRAME_PATH, frameset, frameset+frameNumber);
|
---|
57 | }catch(Exception e){
|
---|
58 | e.printStackTrace();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Writes out a frame header for a new frame.
|
---|
65 | * @param bw
|
---|
66 | */
|
---|
67 | public static void writeOutFrameHeader(BufferedWriter bw){
|
---|
68 | try {
|
---|
69 | StringBuffer header = new StringBuffer("");
|
---|
70 |
|
---|
71 | header.append("V 1\n");
|
---|
72 | header.append("p 44");
|
---|
73 | header.append("U " + UserSettings.UserName + "\n");
|
---|
74 | header.append("D " + Formatter.getDateTime() + "\n"); //
|
---|
75 | header.append("M " + UserSettings.UserName + "\n"); //last modified by
|
---|
76 | header.append("d " + Formatter.getDateTime() + "\n");
|
---|
77 | header.append("Z\n\n");
|
---|
78 | bw.write(header.toString());
|
---|
79 |
|
---|
80 | }catch(Exception e) {
|
---|
81 | e.printStackTrace();
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | public static Frame CopyFrame() {
|
---|
86 | _lastCopiedFrame = DisplayIO.getCurrentFrame();
|
---|
87 | MessageBay.displayMessage("Item successfully copied.");
|
---|
88 |
|
---|
89 | return _lastCopiedFrame;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public static Frame PasteFrame() {
|
---|
93 |
|
---|
94 | Frame current = DisplayIO.getCurrentFrame();
|
---|
95 | if(_lastCopiedFrame != null){
|
---|
96 |
|
---|
97 | List<Item> list = _lastCopiedFrame.getVisibleItems();
|
---|
98 | List<Item> copy = new ArrayList<Item>();
|
---|
99 |
|
---|
100 | for(Item item : list){
|
---|
101 | if(!(item instanceof WidgetCorner))
|
---|
102 | copy.add(item);
|
---|
103 | }
|
---|
104 |
|
---|
105 | current.addAllItems(copy);
|
---|
106 |
|
---|
107 | }else{
|
---|
108 | MessageBay.errorMessage("ERROR: NO FRAME/ITEM TO COPY");
|
---|
109 | return null;
|
---|
110 | }
|
---|
111 |
|
---|
112 | return _lastCopiedFrame;
|
---|
113 |
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Toggles display of toolbar on and off.
|
---|
118 | */
|
---|
119 | public static void ToggleToolbar() {
|
---|
120 |
|
---|
121 | Text displayText = (Text)Misc.getItemContainingData("OptionViewToolbar",FrameIO.LoadFrame(Interfaces.TOGGLE_TOOLS_OVERLAY));
|
---|
122 |
|
---|
123 | if(DISPLAY_TOOLBAR){
|
---|
124 | displayText.setText("View Toolbar");
|
---|
125 | swapLinks(Interfaces.BLANK_TOOLBAR_OVERLAY,"overlayToolbar");
|
---|
126 | DISPLAY_TOOLBAR = false;
|
---|
127 |
|
---|
128 | }else{
|
---|
129 |
|
---|
130 | displayText.setText("Hide Toolbar");
|
---|
131 | swapLinks(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE,"overlayToolbar");
|
---|
132 | DISPLAY_TOOLBAR = true;
|
---|
133 | }
|
---|
134 |
|
---|
135 | FrameKeyboardActions.Refresh();
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | public static void ToggleNotesDisplay(CollectionItem collectItem) {
|
---|
140 |
|
---|
141 |
|
---|
142 | //get link to the collection item's note frame.
|
---|
143 | NoteLayer nl = collectItem.getNoteLayer();
|
---|
144 |
|
---|
145 | if(nl == null){
|
---|
146 | MessageBay.errorMessage("No notes to display");
|
---|
147 | return;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | String noteFrameLink = nl.getFrame().getName();
|
---|
152 | System.err.println("*** link (in ToggleNotesDisplay method): " + noteFrameLink);
|
---|
153 |
|
---|
154 | //Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE));
|
---|
155 | Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE));
|
---|
156 |
|
---|
157 | if(DISPLAY_NOTES){
|
---|
158 | System.err.println("Notes are NOT visible");
|
---|
159 | displayText.setText("View Notes");
|
---|
160 | //swapLinks(noteFrameLink,Interfaces.BLANK_HIDE_NOTES_OVERLAY);
|
---|
161 | swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,"overlayNotes");
|
---|
162 | DISPLAY_NOTES = false;
|
---|
163 |
|
---|
164 |
|
---|
165 | }else{
|
---|
166 | displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE));
|
---|
167 | displayText.setText("Hide Notes");
|
---|
168 |
|
---|
169 | swapLinks(noteFrameLink,"overlayNotes");
|
---|
170 | DISPLAY_NOTES = true;
|
---|
171 | }
|
---|
172 |
|
---|
173 | FrameKeyboardActions.Refresh();
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 | public static void fixTextItemWidths(Frame curr){
|
---|
178 |
|
---|
179 | List<Text> textItems = curr.getBodyTextItems(true);
|
---|
180 |
|
---|
181 | int i = textItems.size() -1;
|
---|
182 |
|
---|
183 | while(i > -1){
|
---|
184 | Text t = textItems.get(i);
|
---|
185 | if(t.getAbsoluteWidth() != null){
|
---|
186 | if(t.getAbsoluteWidth() != Integer.MAX_VALUE && t.getAbsoluteWidth() > 0){
|
---|
187 | Text copy = t.copy();
|
---|
188 | curr.addItem(copy);
|
---|
189 | curr.removeItem(t);
|
---|
190 | }
|
---|
191 | }
|
---|
192 | i--;
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Used by toggleToolbar() and ToggleLayersDisplay() and ToggleNotesDisplay()
|
---|
198 | * to change the overlay annotation links. So if we want
|
---|
199 | * the display of these things off, the overlay will just be
|
---|
200 | * a blank frame. Otherwise the overlay will be the appropriate
|
---|
201 | * frame displaying the toolbar/layer display.
|
---|
202 | * @param oldLink
|
---|
203 | * @param newLink
|
---|
204 | */
|
---|
205 | private static void swapLinks(String newLink,String data){
|
---|
206 |
|
---|
207 | //TODO: Change this code so that it finds an item containing a data value, i.e. "overlayNotes", "overlayToolbar" or "overlayViewToolbar"
|
---|
208 | //The item whose link we want to change
|
---|
209 | Text overlayLink = (Text)Misc.getItemContainingData(data, DisplayIO.getCurrentFrame());
|
---|
210 | System.err.println(data);
|
---|
211 |
|
---|
212 | if(overlayLink != null)
|
---|
213 | overlayLink.setLink(newLink);
|
---|
214 | }
|
---|
215 | }
|
---|