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

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

Added faster versions of search frameset

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