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

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

"View Toolbar" and "View Notes" will become "Hide Toolbar" and "Hide Notes" and vice versa whenever the user clicks on these options.

File size: 6.0 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,"overlayToolbar");
147 DISPLAY_TOOLBAR = true;
148 }
149
150 FrameKeyboardActions.Refresh();
151 }
152
153
154 public static void ToggleNotesDisplay(CollectionItem collectItem) {
155
156 //get link to the collection item's note frame.
157 NoteLayer nl = collectItem.getNoteLayer();
158
159 if(nl == null){
160 MessageBay.errorMessage("No notes to display");
161
162 //TODO: Create new note layer here?
163
164 return;
165 }
166
167
168 String noteFrameLink = nl.getFrame().getName();
169 System.err.println("*** link (in ToggleNotesDisplay method): " + noteFrameLink);
170
171 Text displayText = (Text)Misc.getItemContainingData("OptionViewNotes",FrameIO.LoadFrame(Interfaces.NAVIGATION_OVERLAY));
172
173 if(DISPLAY_NOTES){
174 System.err.println("Notes are NOT visible");
175 displayText.setText("View Notes");
176 //swapLinks(noteFrameLink,Interfaces.BLANK_HIDE_NOTES_OVERLAY);
177 swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,"overlayNotes");
178 DISPLAY_NOTES = false;
179
180
181 }else{
182 System.err.println("Notes are visible");
183 displayText.setText("Hide Notes");
184 //swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,noteFrameLink);
185 swapLinks(noteFrameLink,"overlayNotes");
186 DISPLAY_NOTES = true;
187 }
188
189 FrameKeyboardActions.Refresh();
190
191 }
192
193
194
195 /**
196 * Used by toggleToolbar() and ToggleLayersDisplay() and ToggleNotesDisplay()
197 * to change the overlay annotation links. So if we want
198 * the display of these things off, the overlay will just be
199 * a blank frame. Otherwise the overlay will be the appropriate
200 * frame displaying the toolbar/layer display.
201 * @param oldLink
202 * @param newLink
203 */
204 private static void swapLinks(String newLink,String data){
205
206 //TODO: Change this code so that it finds an item containing a data value, i.e. "overlayNotes", "overlayToolbar" or "overlayViewToolbar"
207 //The item whose link we want to change
208 Text overlayLink = (Text)Misc.getItemContainingData(data, DisplayIO.getCurrentFrame());
209
210 overlayLink.setLink(newLink);
211 }
212}
Note: See TracBrowser for help on using the repository browser.