1 | package org.expeditee.actions;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import org.expeditee.gui.DisplayIO;
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.gui.FrameIO;
|
---|
8 | import org.expeditee.gui.FrameUtils;
|
---|
9 | import org.expeditee.gui.MessageBay;
|
---|
10 | import org.expeditee.items.Item;
|
---|
11 | import org.expeditee.settings.UserSettings;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Provides the Navigation related action procedures
|
---|
15 | *
|
---|
16 | * @author jdm18
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public 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);
|
---|
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 + '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 | * Loads the Frame linked to by the Item that has this action, if there is
|
---|
83 | * one
|
---|
84 | *
|
---|
85 | * @param source
|
---|
86 | * The Item that has a link to the Frame to load and display
|
---|
87 | */
|
---|
88 | public static void GotoLink(Item source) {
|
---|
89 | FrameUtils.DisplayFrame(source.getLink());
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Turns TwinFrames off if it is on, otherwise does nothing
|
---|
94 | */
|
---|
95 | public static void Large() {
|
---|
96 | if (DisplayIO.isTwinFramesOn())
|
---|
97 | DisplayIO.ToggleTwinFrames();
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Navigates to the Frame with the next highest frame number in the current
|
---|
102 | * frameset. If the current frame is the last frame in the frameset, nothing
|
---|
103 | * happens.
|
---|
104 | */
|
---|
105 | public static void NextFrame() {
|
---|
106 | NextFrame(true);
|
---|
107 | }
|
---|
108 |
|
---|
109 | public static void NextFrame(boolean addToBack) {
|
---|
110 | addToBack = adjustAddToBack(addToBack);
|
---|
111 | Frame next = FrameIO.LoadNext();
|
---|
112 | FrameUtils.DisplayFrame(next, addToBack, true);
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Navigates to the last frame in the frameset.
|
---|
117 | *
|
---|
118 | */
|
---|
119 | public static void LastFrame() {
|
---|
120 | Frame last = FrameIO.LoadLast();
|
---|
121 | FrameUtils.DisplayFrame(last, true, true);
|
---|
122 | }
|
---|
123 |
|
---|
124 | public static void ZeroFrame() {
|
---|
125 | Frame zeroFrame = FrameIO.LoadZero();
|
---|
126 | FrameUtils.DisplayFrame(zeroFrame, true, true);
|
---|
127 | }
|
---|
128 |
|
---|
129 | public static void Next() {
|
---|
130 | NextFrame();
|
---|
131 | }
|
---|
132 |
|
---|
133 | public static void Previous() {
|
---|
134 | PreviousFrame();
|
---|
135 | }
|
---|
136 |
|
---|
137 | public static void PreviousFrame(boolean addToBack) {
|
---|
138 | addToBack = adjustAddToBack(addToBack);
|
---|
139 | Frame prev = FrameIO.LoadPrevious();
|
---|
140 | FrameUtils.DisplayFrame(prev, addToBack, true);
|
---|
141 | }
|
---|
142 |
|
---|
143 | public static void PreviousFrame() {
|
---|
144 | PreviousFrame(true);
|
---|
145 | }
|
---|
146 |
|
---|
147 | private static String _Parent = null;
|
---|
148 |
|
---|
149 | private static Item _LastItemUsed = null;
|
---|
150 |
|
---|
151 | public static void NextChild(Frame source) {
|
---|
152 | String back = DisplayIO.peekFromBackUpStack();
|
---|
153 | // if there is no parent frame (i.e. the user is on the home frame) //
|
---|
154 | if (back == null) { // No frame was on the Backup stack
|
---|
155 | MessageBay.displayMessage("No Parent Frame Found.");
|
---|
156 | _LastItemUsed = null; // ByRob: what is reason for setting
|
---|
157 | // this to null, who is going to use it????
|
---|
158 | _Parent = null; // ByRob: what is reason for setting this to
|
---|
159 | // null, who is going to use it
|
---|
160 | return;
|
---|
161 | }
|
---|
162 |
|
---|
163 | // Ensure the parent variable has been initialised
|
---|
164 | if (_Parent == null || !back.equals(_Parent)) { // ByRob: what the heck
|
---|
165 | // is the code doing?
|
---|
166 | // What is it setting
|
---|
167 | // up???????
|
---|
168 | _Parent = back;
|
---|
169 | _LastItemUsed = null;
|
---|
170 | }
|
---|
171 |
|
---|
172 | Frame parent = FrameIO.LoadFrame(_Parent);
|
---|
173 |
|
---|
174 | // find the next item to visit
|
---|
175 | List<Item> items = parent.getItems(); // getItems method gets us the
|
---|
176 | // FirstItem on the frame
|
---|
177 | int parentItemLinkedToSource = 0; // ByMike: Will be set to the
|
---|
178 | // index of the item on the parent which follows the item linked to the
|
---|
179 | // child frame we are currently viewing.
|
---|
180 |
|
---|
181 | // ByMike: if 'Next' has been clicked previously get the index of the
|
---|
182 | // item FOLLOWING the ParentItem linked to the source
|
---|
183 | if (_LastItemUsed != null) {
|
---|
184 | parentItemLinkedToSource = items.indexOf(_LastItemUsed);
|
---|
185 | }
|
---|
186 |
|
---|
187 | // ByMike: If the 'Next' child is being sought for the 1st time...
|
---|
188 | String sourceName = source.getName().toLowerCase();
|
---|
189 |
|
---|
190 | // ByMike: Find the first occurence of a ParentItem linked to the source
|
---|
191 | while (parentItemLinkedToSource < items.size()
|
---|
192 | && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
|
---|
193 | .get(parentItemLinkedToSource).getAbsoluteLink()
|
---|
194 | .toLowerCase().equals(sourceName))) {
|
---|
195 | parentItemLinkedToSource++; // ByRob: this increments to the next
|
---|
196 | // item
|
---|
197 | }
|
---|
198 |
|
---|
199 | // Find the next ParentItem linked to the next frame to be displayed
|
---|
200 | for (int i = parentItemLinkedToSource + 1; i < items.size(); i++) {
|
---|
201 | if (items.get(i).isLinkValid()
|
---|
202 | && !items.get(i).isAnnotation()
|
---|
203 | && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
|
---|
204 | source.getName())) {
|
---|
205 | _LastItemUsed = items.get(i);
|
---|
206 | FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false,
|
---|
207 | true);
|
---|
208 | return;
|
---|
209 | } // ByRob: end of if
|
---|
210 |
|
---|
211 | } // ByRob: End of For
|
---|
212 |
|
---|
213 | MessageBay.displayMessage("No more child frames found.");
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Turns TwinFrames on if it is off, otherwise does nothing
|
---|
218 | *
|
---|
219 | */
|
---|
220 | // ByRob: Rob doesn't like notion of turning TwinFrames on and off,
|
---|
221 | // better to say more explicitly/directly what the mode is!!!!
|
---|
222 | public static void Small() {
|
---|
223 | if (!DisplayIO.isTwinFramesOn())
|
---|
224 | DisplayIO.ToggleTwinFrames();
|
---|
225 | }
|
---|
226 |
|
---|
227 | /*
|
---|
228 | * When display frame is called with addToBack set to false multiple
|
---|
229 | * times... Only the first frame is added to the backup stack. This flag
|
---|
230 | * stores the state for the addToBack parameter the last time this method
|
---|
231 | * was called.
|
---|
232 | */
|
---|
233 | private static boolean _lastAddToBack = true;
|
---|
234 |
|
---|
235 | public static void ResetLastAddToBack() {
|
---|
236 | _lastAddToBack = true;
|
---|
237 | }
|
---|
238 |
|
---|
239 | private static boolean adjustAddToBack(boolean addToBack) {
|
---|
240 | boolean originalAddToBack = addToBack;
|
---|
241 |
|
---|
242 | if (!addToBack && _lastAddToBack) {
|
---|
243 | // This adds the first frame to the backup stack when the user
|
---|
244 | // navigates through a bunch of frames with the keyboard!
|
---|
245 | addToBack = true;
|
---|
246 | }
|
---|
247 |
|
---|
248 | _lastAddToBack = originalAddToBack;
|
---|
249 |
|
---|
250 | return addToBack;
|
---|
251 | }
|
---|
252 | }
|
---|