source: trunk/src/org/expeditee/actions/Navigation.java@ 813

Last change on this file since 813 was 669, checked in by jts21, 10 years ago

generateSettingsTree() now uses FrameCreator, and also now uses a single column of settings with info alongside instead of multiple columns with tooltips.

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