source: other-projects/GlamED/trunk/src/org/honours/gui/HonoursFrameIO.java@ 26739

Last change on this file since 26739 was 26739, checked in by davidb, 11 years ago

Some tidying up including removal of unneeded print statements.

File size: 6.2 KB
Line 
1package org.honours.gui;
2
3import java.io.BufferedWriter;
4import java.io.File;
5import java.io.FileWriter;
6import java.util.ArrayList;
7import java.util.List;
8
9import org.expeditee.actions.Misc;
10import org.expeditee.gui.DisplayIO;
11import org.expeditee.gui.Frame;
12import org.expeditee.gui.FrameIO;
13import org.expeditee.gui.FrameKeyboardActions;
14import org.expeditee.gui.MessageBay;
15import org.expeditee.gui.UserSettings;
16import org.expeditee.items.Item;
17import org.expeditee.items.Text;
18import org.expeditee.items.widgets.WidgetCorner;
19import org.expeditee.stats.Formatter;
20import org.honours.actions.MiscActions;
21import org.honours.collection.CollectionItem;
22import org.honours.collection.NoteLayer;
23
24public 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 on and off the display of the "Toggle
118 * Toolbar" overlay.
119 */
120 public static void toggleToggler(){
121 if(DISPLAY_TOGGLER){
122 swapLinks(Interfaces.TOGGLE_TOOLS_OVERLAY,Interfaces.BLANK_TOGGLER_OVERLAY);
123 DISPLAY_TOGGLER = false;
124 }else{
125 swapLinks(Interfaces.BLANK_TOGGLER_OVERLAY,Interfaces.TOGGLE_TOOLS_OVERLAY);
126 DISPLAY_TOGGLER = true;
127 }
128 FrameKeyboardActions.Refresh();
129 }
130
131 /**
132 * Toggles display of toolbar on and off.
133 */
134 public static void ToggleToolbar() {
135
136 Text displayText = (Text)Misc.getItemContainingData("OptionViewToolbar",FrameIO.LoadFrame(Interfaces.TOGGLE_TOOLS_OVERLAY));
137
138 if(DISPLAY_TOOLBAR){
139 displayText.setText("View Toolbar");
140 swapLinks(Interfaces.BLANK_TOOLBAR_OVERLAY,"overlayToolbar");
141 DISPLAY_TOOLBAR = false;
142
143 }else{
144
145 displayText.setText("Hide Toolbar");
146 swapLinks(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE,"overlayToolbar");
147 DISPLAY_TOOLBAR = true;
148 }
149
150 FrameKeyboardActions.Refresh();
151 }
152
153
154 public static void ToggleNotesDisplay(CollectionItem collectItem) {
155
156
157 //get link to the collection item's note frame.
158 NoteLayer nl = collectItem.getNoteLayer();
159
160 if(nl == null){
161 MessageBay.errorMessage("No notes to display");
162 return;
163 }
164
165
166 String noteFrameLink = nl.getFrame().getName();
167 System.err.println("*** link (in ToggleNotesDisplay method): " + noteFrameLink);
168
169 //Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE));
170 Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE));
171
172 if(DISPLAY_NOTES){
173 System.err.println("Notes are NOT visible");
174 displayText.setText("View Notes");
175 //swapLinks(noteFrameLink,Interfaces.BLANK_HIDE_NOTES_OVERLAY);
176 swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,"overlayNotes");
177 DISPLAY_NOTES = false;
178
179
180 }else{
181 displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE));
182 displayText.setText("Hide Notes");
183
184 swapLinks(noteFrameLink,"overlayNotes");
185 DISPLAY_NOTES = true;
186 }
187
188 FrameKeyboardActions.Refresh();
189
190 }
191
192
193
194 /**
195 * Used by toggleToolbar() and ToggleLayersDisplay() and ToggleNotesDisplay()
196 * to change the overlay annotation links. So if we want
197 * the display of these things off, the overlay will just be
198 * a blank frame. Otherwise the overlay will be the appropriate
199 * frame displaying the toolbar/layer display.
200 * @param oldLink
201 * @param newLink
202 */
203 private static void swapLinks(String newLink,String data){
204
205 //TODO: Change this code so that it finds an item containing a data value, i.e. "overlayNotes", "overlayToolbar" or "overlayViewToolbar"
206 //The item whose link we want to change
207 Text overlayLink = (Text)Misc.getItemContainingData(data, DisplayIO.getCurrentFrame());
208
209 overlayLink.setLink(newLink);
210 }
211}
Note: See TracBrowser for help on using the repository browser.