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

Last change on this file since 67 was 67, checked in by ra33, 16 years ago

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

File size: 7.2 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.FrameGraphics;
8import org.expeditee.gui.FrameIO;
9import org.expeditee.gui.FrameUtils;
10import org.expeditee.items.Item;
11
12/**
13 * Provides the Navigation related KMS 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().getFrameName();
24 }
25 }
26
27 private static void Default() {
28 System.out.println("Not Implemented");
29 }
30
31 /**
32 * Performs a back operation from the current Frame. If the back-stack is
33 * empty, then nothing happens.
34 */
35 public static void Back() {
36 DisplayIO.Back();
37 }
38
39 public static void ClearBack(Item i) {
40 Default();
41 }
42
43 public static void DeleteBack() {
44 Default();
45 }
46
47 public static void GetBack(String topFrame, int x, int y) {
48 Default();
49 }
50
51 public static void GetBackList() {
52 Default();
53 }
54
55 /**
56 * Displays the user's home frame
57 */
58 public static void GotoHome() {
59 FrameUtils.DisplayHomeFrame();
60 }
61
62 /**
63 * Displays the user's profile frame (if there is one)
64 */
65 public static void GotoProfile() {
66 FrameUtils.DisplayProfileFrame();
67 }
68
69 /**
70 * Loads the Frame with the given FrameName and displays it
71 *
72 * @param frameName
73 * The name of the Frame to load
74 */
75 public static void Goto(String frameName) {
76 FrameUtils.DisplayFrame(frameName);
77 }
78
79 /**
80 * Loads the Frame in the current frameset with the given number and
81 * displays it
82 *
83 * @param value
84 * The number of the Frame to load
85 */
86 public static void Goto(Integer value) {
87 FrameUtils.DisplayFrame(value.toString());
88 }
89
90 /**
91 * Loads the Frame linked to by the Item that has this action, if there is
92 * one
93 *
94 * @param source
95 * The Item that has a link to the Frame to load and display
96 */
97 public static void GotoLink(Item source) {
98 FrameUtils.DisplayFrame(source.getLink());
99 }
100
101 /**
102 * Turns TwinFrames off if it is on, otherwise does nothing
103 */
104 public static void Large() {
105 if (DisplayIO.isTwinFramesOn())
106 DisplayIO.ToggleTwinFrames();
107 }
108
109 /**
110 * Navigates to the Frame with the next highest frame number in the current
111 * frameset. If the current frame is the last frame in the frameset, nothing
112 * happens.
113 */
114 public static void NextFrame() {
115 NextFrame(true);
116 }
117
118 public static void NextFrame(boolean addToBack) {
119 addToBack = adjustAddToBack(addToBack);
120 Frame next = FrameIO.LoadNext();
121 FrameUtils.DisplayFrame(next, addToBack);
122 }
123
124 /**
125 * Navigates to the last frame in the frameset.
126 *
127 */
128 public static void LastFrame() {
129 Frame last = FrameIO.LoadLast();
130 FrameUtils.DisplayFrame(last, true);
131 }
132
133 public static void ZeroFrame() {
134 Frame zeroFrame = FrameIO.LoadZero();
135 FrameUtils.DisplayFrame(zeroFrame, true);
136 }
137
138
139 public static void Next() {
140 NextFrame();
141 }
142
143 public static void Previous() {
144 PreviousFrame();
145 }
146
147 public static void PreviousFrame(boolean addToBack) {
148 addToBack = adjustAddToBack(addToBack);
149 Frame prev = FrameIO.LoadPrevious();
150 FrameUtils.DisplayFrame(prev, addToBack);
151 }
152
153 public static void PreviousFrame() {
154 PreviousFrame(true);
155 }
156
157 private static String _Parent = null;
158
159 private static Item _LastItemUsed = null;
160
161 public static void NextChild(Frame source) {
162 String back = DisplayIO.peekFromBack(); // ByRob: "peekFromBack" is not
163 // an informative term, better to refer to back up stack
164 // if there is no parent frame (i.e. the user is on the home frame) //
165 // ByRob: this should say "for example, the user ...."
166 if (back == null) { // No frame was on the Backup stack
167 FrameGraphics.DisplayMessage("No Parent Frame Found.");
168 _LastItemUsed = null; // ByRob: what is reason for setting
169 // this to null, who is going to use
170 // it????
171 _Parent = null; // ByRob: what is reason for setting this to
172 // null, who is going to use it
173 return;
174 }
175
176 /*
177 * if(_Parent == null || !back.equals(_Parent.getFrameName())){ _Parent =
178 * FrameIO.LoadFrame(back); _LastItemUsed = null; }
179 */
180
181 if (_Parent == null || !back.equals(_Parent)) { // ByRob: what the heck
182 // is the code doing?
183 // What is it setting
184 // up???????
185 _Parent = back;
186 _LastItemUsed = null;
187 }
188
189 Frame parent = FrameIO.LoadFrame(_Parent); // at this point we have
190 // a parent frame (but
191 // does LoadFrame access
192 // backup stack?
193
194 // find the next item to visit // ByRob: We should NOT be trying to
195 // remember state!!! at time of Next, getNameOfCurrentFrame!!!!
196 // Actually, no. It could be situation that there is more than one item
197 // on frame linked to CurrentFr
198
199 List<Item> items = parent.getItems(); // getItems method gets us the
200 // FirstItem on the frame
201 int parentItemLinkedToSource = 0; // ByMike: Will be set to the
202 // index of the item on the parent which follows the item linked to the
203 // child frame we are currently viewing.
204
205 // ByMike: if 'Next' has been clicked previously get the index of the
206 // item FOLLOWING the ParentItem linked to the source
207 if (_LastItemUsed != null) {
208 parentItemLinkedToSource = items.indexOf(_LastItemUsed);
209 }
210
211 // ByMike: If the 'Next' child is being sought for the 1st time...
212
213 String sourceName = source.getFrameName().toLowerCase();
214
215 // ByMike: Find the first occurence of a ParentItem linked to the source
216 while (parentItemLinkedToSource < items.size()
217 && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
218 .get(parentItemLinkedToSource).getAbsoluteLink().toLowerCase()
219 .equals(sourceName))) {
220 parentItemLinkedToSource++; // ByRob: this increments to the next
221 // item
222 }
223
224 // Find the next ParentItem linked to the next frame to be displayed
225 for (int i = parentItemLinkedToSource + 1; i < items.size(); i++) {
226 if (items.get(i).isLinkValid()
227 && !items.get(i).isAnnotation()
228 && !items.get(i).getAbsoluteLink().toLowerCase().equals(
229 source.getFrameName().toLowerCase())) {
230 _LastItemUsed = items.get(i);
231 FrameUtils.DisplayFrame(_LastItemUsed.getLink(), false);
232 return;
233 } // ByRob: end of if
234
235 } // ByRob: End of For
236
237 FrameGraphics.DisplayMessage("No more child frames found.");
238 }
239
240 public static void OtherWindow() {
241 Default();
242 }
243
244 /**
245 * Turns TwinFrames on if it is off, otherwise does nothing
246 *
247 */
248 // ByRob: Rob doesn't like notion of turning TwinFrames on and off,
249 // better to say more explicitly/directly what the mode is!!!!
250 public static void Small() {
251 if (!DisplayIO.isTwinFramesOn())
252 DisplayIO.ToggleTwinFrames();
253 }
254
255 // When display frame is called with addToBack set to false multiple
256 // times...
257 // The first time we add to back but after that we dont
258 // This flag stores the state for the addToBack parameter the last time this
259 // method was called
260 private static boolean _lastAddToBack = true;
261
262 public static void ResetLastAddToBack() {
263 _lastAddToBack = true;
264 }
265
266 private static boolean adjustAddToBack(boolean addToBack) {
267 boolean originalAddToBack = addToBack;
268
269 if (!addToBack && _lastAddToBack){
270 //This adds the first frame to the backup stack when the user
271 //navigates through a bunch of frames with the keyboard!
272 addToBack = true;
273 }
274
275 _lastAddToBack = originalAddToBack;
276
277 return addToBack;
278 }
279}
Note: See TracBrowser for help on using the repository browser.