source: trunk/src/org/expeditee/actions/NavigationActions.java@ 121

Last change on this file since 121 was 121, checked in by bjn8, 16 years ago

Added invalidation for graphics... biiiig commit. LOts of effeciency improvements - now can animate

File size: 6.3 KB
Line 
1package org.expeditee.actions;
2
3import java.util.List;
4
5import org.expeditee.gui.DisplayIO;
6import org.expeditee.gui.Frame;
7import org.expeditee.gui.FrameIO;
8import org.expeditee.gui.FrameUtils;
9import org.expeditee.gui.MessageBay;
10import org.expeditee.items.Item;
11
12/**
13 * Provides the Navigation related action procedures
14 *
15 * @author jdm18
16 *
17 */
18public class NavigationActions {
19
20 public static void setLastNavigationItem(Item i) {
21 _LastItemUsed = i;
22 if (i.getParent() != null) {
23 _Parent = i.getParent().getName();
24 }
25 }
26
27 /**
28 * Performs a back operation from the current Frame. If the back-stack is
29 * empty, then nothing happens.
30 */
31 public static void Back() {
32 DisplayIO.Back();
33 }
34
35 /**
36 * Displays the user's home frame
37 */
38 public static void GotoHome() {
39 FrameUtils.DisplayHomeFrame();
40 }
41
42 /**
43 * Displays the user's profile frame (if there is one)
44 */
45 public static void GotoProfile() {
46 FrameUtils.DisplayProfileFrame();
47 }
48
49 /**
50 * Loads the Frame with the given FrameName and displays it
51 *
52 * @param frameName
53 * The name of the Frame to load
54 */
55 public static void Goto(String frameName) {
56 FrameUtils.DisplayFrame(frameName);
57 }
58
59 /**
60 * Loads the Frame in the current frameset with the given number and
61 * displays it
62 *
63 * @param value
64 * The number of the Frame to load
65 */
66 public static void Goto(Integer value) {
67 FrameUtils.DisplayFrame(value.toString());
68 }
69
70 /**
71 * Loads the Frame linked to by the Item that has this action, if there is
72 * one
73 *
74 * @param source
75 * The Item that has a link to the Frame to load and display
76 */
77 public static void GotoLink(Item source) {
78 FrameUtils.DisplayFrame(source.getLink());
79 }
80
81 /**
82 * Turns TwinFrames off if it is on, otherwise does nothing
83 */
84 public static void Large() {
85 if (DisplayIO.isTwinFramesOn())
86 DisplayIO.ToggleTwinFrames();
87 }
88
89 /**
90 * Navigates to the Frame with the next highest frame number in the current
91 * frameset. If the current frame is the last frame in the frameset, nothing
92 * happens.
93 */
94 public static void NextFrame() {
95 NextFrame(true);
96 }
97
98 public static void NextFrame(boolean addToBack) {
99 addToBack = adjustAddToBack(addToBack);
100 Frame next = FrameIO.LoadNext();
101 FrameUtils.DisplayFrame(next, addToBack);
102 }
103
104 /**
105 * Navigates to the last frame in the frameset.
106 *
107 */
108 public static void LastFrame() {
109 Frame last = FrameIO.LoadLast();
110 FrameUtils.DisplayFrame(last, true);
111 }
112
113 public static void ZeroFrame() {
114 Frame zeroFrame = FrameIO.LoadZero();
115 FrameUtils.DisplayFrame(zeroFrame, true);
116 }
117
118
119 public static void Next() {
120 NextFrame();
121 }
122
123 public static void Previous() {
124 PreviousFrame();
125 }
126
127 public static void PreviousFrame(boolean addToBack) {
128 addToBack = adjustAddToBack(addToBack);
129 Frame prev = FrameIO.LoadPrevious();
130 FrameUtils.DisplayFrame(prev, addToBack);
131 }
132
133 public static void PreviousFrame() {
134 PreviousFrame(true);
135 }
136
137 private static String _Parent = null;
138
139 private static Item _LastItemUsed = null;
140
141 public static void NextChild(Frame source) {
142 String back = DisplayIO.peekFromBackUpStack();
143 // if there is no parent frame (i.e. the user is on the home frame) //
144 if (back == null) { // No frame was on the Backup stack
145 MessageBay.displayMessage("No Parent Frame Found.");
146 _LastItemUsed = null; // ByRob: what is reason for setting
147 // this to null, who is going to use it????
148 _Parent = null; // ByRob: what is reason for setting this to
149 // null, who is going to use it
150 return;
151 }
152
153 //Ensure the parent variable has been initialised
154 if (_Parent == null || !back.equals(_Parent)) { // ByRob: what the heck
155 // is the code doing?
156 // What is it setting
157 // up???????
158 _Parent = back;
159 _LastItemUsed = null;
160 }
161
162 Frame parent = FrameIO.LoadFrame(_Parent);
163
164 // find the next item to visit
165 List<Item> items = parent.getItems(); // getItems method gets us the
166 // FirstItem on the frame
167 int parentItemLinkedToSource = 0; // ByMike: Will be set to the
168 // index of the item on the parent which follows the item linked to the
169 // child frame we are currently viewing.
170
171 // ByMike: if 'Next' has been clicked previously get the index of the
172 // item FOLLOWING the ParentItem linked to the source
173 if (_LastItemUsed != null) {
174 parentItemLinkedToSource = items.indexOf(_LastItemUsed);
175 }
176
177 // ByMike: If the 'Next' child is being sought for the 1st time...
178 String sourceName = source.getName().toLowerCase();
179
180 // ByMike: Find the first occurence of a ParentItem linked to the source
181 while (parentItemLinkedToSource < items.size()
182 && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
183 .get(parentItemLinkedToSource).getAbsoluteLink().toLowerCase()
184 .equals(sourceName))) {
185 parentItemLinkedToSource++; // ByRob: this increments to the next
186 // item
187 }
188
189 // Find the next ParentItem linked to the next frame to be displayed
190 for (int i = parentItemLinkedToSource + 1; i < items.size(); i++) {
191 if (items.get(i).isLinkValid()
192 && !items.get(i).isAnnotation()
193 && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
194 source.getName())) {
195 _LastItemUsed = items.get(i);
196 FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false);
197 return;
198 } // ByRob: end of if
199
200 } // ByRob: End of For
201
202 MessageBay.displayMessage("No more child frames found.");
203 }
204
205 /**
206 * Turns TwinFrames on if it is off, otherwise does nothing
207 *
208 */
209 // ByRob: Rob doesn't like notion of turning TwinFrames on and off,
210 // better to say more explicitly/directly what the mode is!!!!
211 public static void Small() {
212 if (!DisplayIO.isTwinFramesOn())
213 DisplayIO.ToggleTwinFrames();
214 }
215
216 // When display frame is called with addToBack set to false multiple
217 // times...
218 // The first time we add to back but after that we dont
219 // This flag stores the state for the addToBack parameter the last time this
220 // method was called
221 private static boolean _lastAddToBack = true;
222
223 public static void ResetLastAddToBack() {
224 _lastAddToBack = true;
225 }
226
227 private static boolean adjustAddToBack(boolean addToBack) {
228 boolean originalAddToBack = addToBack;
229
230 if (!addToBack && _lastAddToBack){
231 //This adds the first frame to the backup stack when the user
232 //navigates through a bunch of frames with the keyboard!
233 addToBack = true;
234 }
235
236 _lastAddToBack = originalAddToBack;
237
238 return addToBack;
239 }
240}
Note: See TracBrowser for help on using the repository browser.