1 | package org.honours.gui;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Dimension;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.expeditee.actions.Misc;
|
---|
8 | import org.expeditee.gui.*;
|
---|
9 | import org.expeditee.items.Item;
|
---|
10 | import org.expeditee.items.Text;
|
---|
11 |
|
---|
12 | import org.honours.Main;
|
---|
13 | import org.honours.collection.*;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * This class is used for displaying the
|
---|
17 | * various different overlays/interfaces available.
|
---|
18 | * @author Korii
|
---|
19 | */
|
---|
20 | public class Interfaces {
|
---|
21 |
|
---|
22 | //various frame names for the different interface overlays.
|
---|
23 | public static final String MAIN_INTERFACE_OVERLAY = "interface-overlays1";
|
---|
24 |
|
---|
25 | public static final String LAYERS_BACK_BTN_OVERLAY = "interface-overlays3";
|
---|
26 | public static final String TOGGLE_TOOLS_OVERLAY = "interface-overlays4";
|
---|
27 |
|
---|
28 | public static final String BLANK_TOOLBAR_OVERLAY = "interface-overlays6";
|
---|
29 |
|
---|
30 | //overlay displaying toolbar with "View Notes" option DISABLED.
|
---|
31 | public static final String NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE = "interface-overlays2";
|
---|
32 |
|
---|
33 | //overlay displaying toolbar with "View Notes" option ENABLED.
|
---|
34 | public static final String NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE = "interface-overlays11";
|
---|
35 |
|
---|
36 | //public static final String DISPLAY_LAYERS_OVERLAY = "interface-overlays5";
|
---|
37 | //public static final String BLANK_DISPLAY_LAYERS_OVERLAY = "interface-overlays7";
|
---|
38 |
|
---|
39 | //TODO: Overlay for hiding notes.
|
---|
40 | public static final String BLANK_HIDE_NOTES_OVERLAY = "interface-overlays9";
|
---|
41 |
|
---|
42 | public static final String BLANK_TOGGLER_OVERLAY = "interface-overlays10";
|
---|
43 |
|
---|
44 | private static final String AO_TEXT3 = "@ao:3";
|
---|
45 | private static final String AO_TEXT4 = "@ao:4";
|
---|
46 |
|
---|
47 | //used to determine positioning of the various @ao:3/4 text items.
|
---|
48 | private static int _mainOverAoX = 1859;
|
---|
49 | private static int _mainOverAoY = 130;
|
---|
50 |
|
---|
51 | private static int _toolbarAoX = 1859;
|
---|
52 | private static int _toolbarAoY = 130;
|
---|
53 |
|
---|
54 | private static int _toggleAoX = 1859;
|
---|
55 | private static int _toggleAoY = 94;
|
---|
56 |
|
---|
57 | private static int _notesAoX = 1859;
|
---|
58 | private static int _notesAoY = 58;
|
---|
59 |
|
---|
60 | public static final String OVERLAY_TOOLBAR_DATA = "overlayToolbar";
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * This method sets up the main overlay on the profile
|
---|
64 | * frame.
|
---|
65 | * @param frame - frame to add the main overlay too.
|
---|
66 | */
|
---|
67 | public static void setUpMainOverlay(Frame frame){
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | List<Text> list = frame.getBodyTextItems(true);
|
---|
72 |
|
---|
73 | boolean found = false;
|
---|
74 | int i = 0;
|
---|
75 |
|
---|
76 | while(i < list.size() && !found){
|
---|
77 |
|
---|
78 | Text text = list.get(i);
|
---|
79 |
|
---|
80 | if(text.getText().equals(AO_TEXT3)){
|
---|
81 | if(text.hasLink()){
|
---|
82 | if(text.getLink().equals(MAIN_INTERFACE_OVERLAY)){
|
---|
83 | found = true;
|
---|
84 | }
|
---|
85 |
|
---|
86 | }
|
---|
87 | }
|
---|
88 | i++;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if(!found){
|
---|
92 | Text t = frame.addText(_mainOverAoX,_mainOverAoY,AO_TEXT3,null);
|
---|
93 | t.setLink(MAIN_INTERFACE_OVERLAY);
|
---|
94 |
|
---|
95 | frame.setSaved();
|
---|
96 | frame.setChanged(true);
|
---|
97 | }
|
---|
98 |
|
---|
99 | FrameKeyboardActions.Refresh();
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /** Method to set up overlay locations relative to the screen size. **/
|
---|
104 | public static void setUpOverlayLocations(CollectionItem cItem){
|
---|
105 |
|
---|
106 | Frame frame = cItem.getFrame();
|
---|
107 | //Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
|
---|
108 |
|
---|
109 | //Find the location of the frame name text item and use that for the overlay links.
|
---|
110 | Item nameItem = frame.getNameItem();
|
---|
111 |
|
---|
112 | int x = nameItem.getX();
|
---|
113 |
|
---|
114 | _mainOverAoX = x;
|
---|
115 | _toolbarAoX = x;
|
---|
116 | _toggleAoX = x;
|
---|
117 | _notesAoX = x;
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | public static void resetOverlayPosition(Text t) {
|
---|
122 | Dimension maxSize = FrameGraphics.getMaxFrameSize();
|
---|
123 | if (maxSize != null) {
|
---|
124 | // setMaxWidth(maxSize.width);
|
---|
125 | t.setPosition(maxSize.width - t.getBoundsWidth(), t.getBoundsHeight());
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Set up overlay which displays toolbar for collection items.
|
---|
132 | * @param cItem - the collection item to add the toolbar to (or rather its represented frame).
|
---|
133 | */
|
---|
134 | public static void setUpToolbarOverlay(CollectionItem cItem) {
|
---|
135 |
|
---|
136 | Frame ciFrame = cItem.getFrame();
|
---|
137 | List<Text> list = ciFrame.getBodyTextItems(true);
|
---|
138 |
|
---|
139 | boolean found = false;
|
---|
140 | int i = 0;
|
---|
141 |
|
---|
142 | while(i < list.size() && !found){
|
---|
143 |
|
---|
144 | Text t = list.get(i);
|
---|
145 |
|
---|
146 | if(t.getText().equals(AO_TEXT3)){
|
---|
147 |
|
---|
148 | if(t.hasLink()){
|
---|
149 | if(t.getLink().equals(NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE)){
|
---|
150 | found = true;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | i++;
|
---|
156 | }
|
---|
157 |
|
---|
158 | if(!found){
|
---|
159 |
|
---|
160 | Text newText = ciFrame.addText(_toolbarAoX,_toolbarAoY,AO_TEXT3,null);
|
---|
161 | newText.setData(OVERLAY_TOOLBAR_DATA);
|
---|
162 | newText.setLink(NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE);
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Method to set up overlay which displays a "toggle toolbar" option/button.
|
---|
170 | * @param cItem - the collection item to add the toggle toolbar option to.
|
---|
171 | */
|
---|
172 | public static void setUpToggleToolbarOverlay(CollectionItem cItem) {
|
---|
173 | Frame ciFrame = cItem.getFrame();
|
---|
174 | List<Text> list = ciFrame.getBodyTextItems(true);
|
---|
175 |
|
---|
176 | boolean found = false;
|
---|
177 | int i = 0;
|
---|
178 |
|
---|
179 | while(i < list.size() && !found){
|
---|
180 |
|
---|
181 | Text t = list.get(i);
|
---|
182 |
|
---|
183 | if(t.getText().equals(AO_TEXT3)){
|
---|
184 |
|
---|
185 | if(t.hasLink()){
|
---|
186 |
|
---|
187 | if(t.getLink().equals(TOGGLE_TOOLS_OVERLAY)){
|
---|
188 | found = true;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | i++;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if(!found){
|
---|
196 | Text newText = ciFrame.addText(_toggleAoX,_toggleAoY,AO_TEXT3,null);
|
---|
197 | newText.setData("overlayViewToolbar");
|
---|
198 | newText.setLink(TOGGLE_TOOLS_OVERLAY);
|
---|
199 | }
|
---|
200 |
|
---|
201 | }
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Method to set up an overlay for displaying notes for
|
---|
205 | * the passed collection item.
|
---|
206 | * @param cItem - collection item to add notes to.
|
---|
207 | */
|
---|
208 | public static void setUpNotesOverlay(CollectionItem cItem) {
|
---|
209 |
|
---|
210 | Frame ciFrame = cItem.getFrame();
|
---|
211 | List<Text> list = ciFrame.getBodyTextItems(true);
|
---|
212 |
|
---|
213 | boolean found = false;
|
---|
214 | String notesFrameFoundName = null;
|
---|
215 | int i = 0;
|
---|
216 |
|
---|
217 |
|
---|
218 | while(i < list.size() && !found){
|
---|
219 |
|
---|
220 | Text t = list.get(i);
|
---|
221 |
|
---|
222 | if(t.getText().equals(AO_TEXT4)){
|
---|
223 |
|
---|
224 | if(t.hasLink()){
|
---|
225 |
|
---|
226 | if(t.getLink().startsWith("notes")){
|
---|
227 | found = true;
|
---|
228 | notesFrameFoundName = t.getLink();
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | i++;
|
---|
236 | }
|
---|
237 |
|
---|
238 | if(!found){
|
---|
239 |
|
---|
240 | //check for an overlay frame in notes frameset associated with this collection item.
|
---|
241 | NoteLayer getNoteLayer = cItem.getNoteLayer();
|
---|
242 | Frame getNotesOverlayFrame = null;
|
---|
243 |
|
---|
244 | if(getNoteLayer == null){
|
---|
245 |
|
---|
246 | //Create a new notelayer and frame
|
---|
247 | getNoteLayer = new NoteLayer();
|
---|
248 | getNoteLayer.setAssociatedItem(cItem);
|
---|
249 |
|
---|
250 | //Create new frame.
|
---|
251 | int frameNumber = FrameIO.getLastNumber("notesmain") + 1;
|
---|
252 | HonoursFrameIO.generateFrame(frameNumber, "notesmain");
|
---|
253 | getNotesOverlayFrame = FrameIO.LoadFrame("notesmain"+frameNumber);
|
---|
254 | getNoteLayer.setFrame(FrameIO.LoadFrame(getNotesOverlayFrame.getName()));
|
---|
255 | cItem.setNoteLayer(getNoteLayer);
|
---|
256 |
|
---|
257 | //Add collectionItem back into collection and add collection back into collections list
|
---|
258 | Collection matchingCollection = Collection.findCollection(cItem.getFrame());
|
---|
259 | int collectionIndex = Collection.getCollectionPosition(matchingCollection);
|
---|
260 | int collectionItemPosition = CollectionItem.getPositionInCollection(cItem, matchingCollection);
|
---|
261 |
|
---|
262 | matchingCollection.getItems().remove(collectionItemPosition);
|
---|
263 | matchingCollection.getItems().add(collectionItemPosition,cItem);
|
---|
264 |
|
---|
265 | Main._collections.remove(collectionIndex);
|
---|
266 | Main._collections.add(collectionIndex, matchingCollection);
|
---|
267 |
|
---|
268 | }else{
|
---|
269 | getNotesOverlayFrame = getNoteLayer.getFrame();
|
---|
270 | }
|
---|
271 |
|
---|
272 | Text newText = ciFrame.addText(_notesAoX,_notesAoY,AO_TEXT4,null);
|
---|
273 | newText.setData("overlayNotes");
|
---|
274 | newText.setLink(getNotesOverlayFrame.getName());
|
---|
275 |
|
---|
276 | }else{
|
---|
277 |
|
---|
278 | //Obtain link to toolbar and change it.
|
---|
279 | Item toolbarLinkItem = Misc.getItemContainingData(OVERLAY_TOOLBAR_DATA, ciFrame);
|
---|
280 | String toolbarOverlayLink = toolbarLinkItem.getLink();
|
---|
281 |
|
---|
282 | if(toolbarOverlayLink.equals(NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE)){
|
---|
283 | toolbarLinkItem.setLink(NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE);
|
---|
284 | }
|
---|
285 | else if(toolbarOverlayLink.equals(NAVIGATION_OVERLAY_VIEW_NOTES_CLICKABLE)){
|
---|
286 | //Check for actual text items on the notes frame.
|
---|
287 | Frame checkOverlayFrame = FrameIO.LoadFrame(notesFrameFoundName);
|
---|
288 |
|
---|
289 | if(checkOverlayFrame.getTextItems().size() == 0){
|
---|
290 | toolbarLinkItem.setLink(NAVIGATION_OVERLAY_VIEW_NOTES_UNCLICKABLE);
|
---|
291 | System.err.println("NO NOTES for collection item: " + ciFrame.getName());
|
---|
292 | }else{
|
---|
293 | System.err.println(ciFrame.getName() + " " + checkOverlayFrame.getTextItems().size() + " ********");
|
---|
294 | }
|
---|
295 |
|
---|
296 | }
|
---|
297 |
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | }
|
---|