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.gui.DisplayIO;
|
---|
10 | import org.expeditee.gui.Frame;
|
---|
11 | import org.expeditee.gui.FrameIO;
|
---|
12 | import org.expeditee.gui.FrameKeyboardActions;
|
---|
13 | import org.expeditee.gui.MessageBay;
|
---|
14 | import org.expeditee.gui.UserSettings;
|
---|
15 | import org.expeditee.items.Item;
|
---|
16 | import org.expeditee.items.Text;
|
---|
17 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
18 | import org.expeditee.stats.Formatter;
|
---|
19 | import org.honours.collection.CollectionItem;
|
---|
20 |
|
---|
21 | public class HonoursFrameIO {
|
---|
22 |
|
---|
23 | private static Frame _lastCopiedFrame = null;
|
---|
24 |
|
---|
25 | public static boolean DISPLAY_TOOLBAR = true;
|
---|
26 | public static boolean DISPLAY_LAYERS = true;
|
---|
27 | public static boolean DISPLAY_NOTES = false;
|
---|
28 |
|
---|
29 | public static boolean DISPLAY_TOGGLER = true;
|
---|
30 |
|
---|
31 | public static String COLLECTIONS_PATH = FrameIO.PARENT_FOLDER +
|
---|
32 | "collections" + File.separator;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Generate a new frame for a given (existing)
|
---|
36 | * frameset.
|
---|
37 | * @param frameNumber - frame number for this next item.
|
---|
38 | * @param frameset - frameset to add frame to.
|
---|
39 | */
|
---|
40 | public static void generateFrame(int frameNumber, String frameset){
|
---|
41 | String frameFileName = FrameIO.FRAME_PATH + frameset + File.separator +
|
---|
42 | frameNumber + ".exp";
|
---|
43 | Frame checkExistingFrame = FrameIO.LoadFrame(frameset + frameNumber);
|
---|
44 |
|
---|
45 | if(checkExistingFrame == null){
|
---|
46 | FileWriter fw;
|
---|
47 | BufferedWriter bw;
|
---|
48 |
|
---|
49 | try{
|
---|
50 | fw = new FileWriter(frameFileName);
|
---|
51 | bw = new BufferedWriter(fw);
|
---|
52 | writeOutFrameHeader(bw);
|
---|
53 | FrameIO.WriteINF(FrameIO.FRAME_PATH, frameset, frameset+frameNumber);
|
---|
54 | }catch(Exception e){
|
---|
55 | e.printStackTrace();
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Writes out a frame header for a new frame.
|
---|
62 | * @param bw
|
---|
63 | */
|
---|
64 | public static void writeOutFrameHeader(BufferedWriter bw){
|
---|
65 | try {
|
---|
66 | StringBuffer header = new StringBuffer("");
|
---|
67 |
|
---|
68 | header.append("V 1\n");
|
---|
69 | header.append("p 44");
|
---|
70 | header.append("U " + UserSettings.UserName + "\n");
|
---|
71 | header.append("D " + Formatter.getDateTime() + "\n"); //
|
---|
72 | header.append("M " + UserSettings.UserName + "\n"); //last modified by
|
---|
73 | header.append("d " + Formatter.getDateTime() + "\n");
|
---|
74 | header.append("Z\n\n");
|
---|
75 | bw.write(header.toString());
|
---|
76 |
|
---|
77 | }catch(Exception e) {
|
---|
78 | e.printStackTrace();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public static Frame CopyFrame() {
|
---|
83 | _lastCopiedFrame = DisplayIO.getCurrentFrame();
|
---|
84 | MessageBay.displayMessage("Item successfully copied.");
|
---|
85 |
|
---|
86 | return _lastCopiedFrame;
|
---|
87 | }
|
---|
88 |
|
---|
89 | public static Frame PasteFrame() {
|
---|
90 |
|
---|
91 | Frame current = DisplayIO.getCurrentFrame();
|
---|
92 | if(_lastCopiedFrame != null){
|
---|
93 |
|
---|
94 | List<Item> list = _lastCopiedFrame.getVisibleItems();
|
---|
95 | List<Item> copy = new ArrayList<Item>();
|
---|
96 |
|
---|
97 | for(Item item : list){
|
---|
98 | if(!(item instanceof WidgetCorner))
|
---|
99 | copy.add(item);
|
---|
100 | }
|
---|
101 |
|
---|
102 | current.addAllItems(copy);
|
---|
103 |
|
---|
104 | }else{
|
---|
105 | MessageBay.errorMessage("ERROR: NO FRAME/ITEM TO COPY");
|
---|
106 | return null;
|
---|
107 | }
|
---|
108 |
|
---|
109 | return _lastCopiedFrame;
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Toggles on and off the display of the "Toggle
|
---|
115 | * Toolbar" overlay.
|
---|
116 | */
|
---|
117 | public static void toggleToggler(){
|
---|
118 | if(DISPLAY_TOGGLER){
|
---|
119 | swapLinks(Interfaces.TOGGLE_TOOLS_OVERLAY,Interfaces.BLANK_TOGGLER_OVERLAY);
|
---|
120 | DISPLAY_TOGGLER = false;
|
---|
121 | }else{
|
---|
122 | swapLinks(Interfaces.BLANK_TOGGLER_OVERLAY,Interfaces.TOGGLE_TOOLS_OVERLAY);
|
---|
123 | DISPLAY_TOGGLER = true;
|
---|
124 | }
|
---|
125 | FrameKeyboardActions.Refresh();
|
---|
126 | }
|
---|
127 |
|
---|
128 | public static void ToggleToolbar() {
|
---|
129 | if(DISPLAY_TOOLBAR){
|
---|
130 |
|
---|
131 | swapLinks(Interfaces.NAVIGATION_OVERLAY,Interfaces.BLANK_TOOLBAR_OVERLAY);
|
---|
132 | DISPLAY_TOOLBAR = false;
|
---|
133 |
|
---|
134 | }else{
|
---|
135 | //make it reappear.
|
---|
136 | swapLinks(Interfaces.BLANK_TOOLBAR_OVERLAY,Interfaces.NAVIGATION_OVERLAY);
|
---|
137 | DISPLAY_TOOLBAR = true;
|
---|
138 | }
|
---|
139 |
|
---|
140 | FrameKeyboardActions.Refresh();
|
---|
141 | }
|
---|
142 |
|
---|
143 | public static void ToggleNotesDisplay(CollectionItem collectItem) {
|
---|
144 |
|
---|
145 | //get link to the collection item's note frame.
|
---|
146 | String noteFrameLink = collectItem.getNoteLayer().getFrame().getName();
|
---|
147 |
|
---|
148 | if(DISPLAY_NOTES){
|
---|
149 |
|
---|
150 | swapLinks(noteFrameLink,Interfaces.BLANK_HIDE_NOTES_OVERLAY);
|
---|
151 | DISPLAY_NOTES = false;
|
---|
152 |
|
---|
153 |
|
---|
154 | }else{
|
---|
155 | swapLinks(Interfaces.BLANK_HIDE_NOTES_OVERLAY,noteFrameLink);
|
---|
156 | DISPLAY_NOTES = true;
|
---|
157 | }
|
---|
158 | FrameKeyboardActions.Refresh();
|
---|
159 |
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Used by toggleToolbar() and ToggleLayersDisplay() and ToggleNotesDisplay()
|
---|
166 | * to change the overlay annotation links. So if we want
|
---|
167 | * the display of these things off, the overlay will just be
|
---|
168 | * a blank frame. Otherwise the overlay will be the appropriate
|
---|
169 | * frame displaying the toolbar/layer display.
|
---|
170 | * @param oldLink
|
---|
171 | * @param newLink
|
---|
172 | */
|
---|
173 | private static void swapLinks(String oldLink,String newLink){
|
---|
174 |
|
---|
175 | Frame curr = DisplayIO.getCurrentFrame();
|
---|
176 | for(Item item : curr.getItems()){
|
---|
177 |
|
---|
178 | if(item instanceof Text){
|
---|
179 | Text t = (Text)item;
|
---|
180 | if(t.getText().equals("@ao:3") || t.getText().equals("@ao:4")){
|
---|
181 | if(t.hasLink()){
|
---|
182 | if(t.getLink().equals(oldLink)){
|
---|
183 | t.setLink(newLink);
|
---|
184 | return;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | }
|
---|