1 | /**
|
---|
2 | * Navigation.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.actions;
|
---|
20 |
|
---|
21 | import java.util.List;
|
---|
22 |
|
---|
23 | import org.expeditee.gui.DisplayIO;
|
---|
24 | import org.expeditee.gui.Frame;
|
---|
25 | import org.expeditee.gui.FrameIO;
|
---|
26 | import org.expeditee.gui.FrameUtils;
|
---|
27 | import org.expeditee.gui.MessageBay;
|
---|
28 | import org.expeditee.items.Item;
|
---|
29 | import org.expeditee.settings.UserSettings;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Provides the Navigation related action procedures
|
---|
33 | *
|
---|
34 | * @author jdm18
|
---|
35 | *
|
---|
36 | */
|
---|
37 | public class Navigation {
|
---|
38 |
|
---|
39 | public static void setLastNavigationItem(Item i) {
|
---|
40 | _LastItemUsed = i;
|
---|
41 | if (i.getParent() != null) {
|
---|
42 | _Parent = i.getParent().getName();
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Performs a back operation from the current Frame. If the back-stack is
|
---|
48 | * empty, then nothing happens.
|
---|
49 | */
|
---|
50 | public static void Back() {
|
---|
51 | DisplayIO.Back();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public static void Forward() {
|
---|
55 | DisplayIO.Forward();
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Displays the user's home frame
|
---|
60 | */
|
---|
61 | public static void GotoHome() {
|
---|
62 | FrameUtils.DisplayFrame(UserSettings.HomeFrame.get());
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Displays the user's first settings frame - should be `username`2
|
---|
67 | */
|
---|
68 | public static void GotoSettings() {
|
---|
69 | //String framename = UserSettings.HomeFrame.get();
|
---|
70 | //framename = framename.substring(0, framename.length() - 1) + '2';
|
---|
71 |
|
---|
72 | String userName = UserSettings.ProfileName.get();
|
---|
73 | String framename = userName + '2';
|
---|
74 |
|
---|
75 | FrameUtils.DisplayFrame(framename);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public static void GotoZero() {
|
---|
79 | FrameUtils
|
---|
80 | .DisplayFrame(DisplayIO.getCurrentFrame().getFramesetName() + 0);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Displays the user's profile frame (if there is one)
|
---|
85 | */
|
---|
86 | public static void GotoProfile() {
|
---|
87 | FrameUtils.DisplayFrame(UserSettings.ProfileName.get() + '1');
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Loads the Frame in the current frameset with the given number and
|
---|
92 | * displays it
|
---|
93 | *
|
---|
94 | * @param value
|
---|
95 | * The number of the Frame to load
|
---|
96 | */
|
---|
97 | public static void Goto(Integer value) {
|
---|
98 | FrameUtils.DisplayFrame(DisplayIO.getCurrentFrame().getFramesetName()
|
---|
99 | + value);
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Loads the Frame with the given FrameName and displays it
|
---|
104 | *
|
---|
105 | * @param frameName
|
---|
106 | * The name of the Frame to load
|
---|
107 | */
|
---|
108 | public static void Goto(String frameName) {
|
---|
109 | FrameUtils.DisplayFrame(frameName);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Goto a frame without adding it to history
|
---|
114 | */
|
---|
115 | public static void GotoQuiet(String frameName) {
|
---|
116 | FrameUtils.DisplayFrame(frameName, false, true);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Loads the Frame linked to by the Item that has this action, if there is
|
---|
121 | * one
|
---|
122 | *
|
---|
123 | * @param source
|
---|
124 | * The Item that has a link to the Frame to load and display
|
---|
125 | */
|
---|
126 | public static void GotoLink(Item source) {
|
---|
127 | FrameUtils.DisplayFrame(source.getLink());
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Turns TwinFrames off if it is on, otherwise does nothing
|
---|
132 | */
|
---|
133 | public static void Large() {
|
---|
134 | if (DisplayIO.isTwinFramesOn())
|
---|
135 | DisplayIO.ToggleTwinFrames();
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Navigates to the Frame with the next highest frame number in the current
|
---|
140 | * frameset. If the current frame is the last frame in the frameset, nothing
|
---|
141 | * happens.
|
---|
142 | */
|
---|
143 | public static void NextFrame() {
|
---|
144 | NextFrame(true);
|
---|
145 | }
|
---|
146 |
|
---|
147 | public static void NextFrame(boolean addToBack) {
|
---|
148 | addToBack = adjustAddToBack(addToBack);
|
---|
149 | Frame next = FrameIO.LoadNext();
|
---|
150 | FrameUtils.DisplayFrame(next, addToBack, true);
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Navigates to the last frame in the frameset.
|
---|
155 | *
|
---|
156 | */
|
---|
157 | public static void LastFrame() {
|
---|
158 | Frame last = FrameIO.LoadLast();
|
---|
159 | FrameUtils.DisplayFrame(last, true, true);
|
---|
160 | }
|
---|
161 |
|
---|
162 | public static void ZeroFrame() {
|
---|
163 | Frame zeroFrame = FrameIO.LoadZero();
|
---|
164 | FrameUtils.DisplayFrame(zeroFrame, true, true);
|
---|
165 | }
|
---|
166 |
|
---|
167 | public static void Next() {
|
---|
168 | NextFrame();
|
---|
169 | }
|
---|
170 |
|
---|
171 | public static void Previous() {
|
---|
172 | PreviousFrame();
|
---|
173 | }
|
---|
174 |
|
---|
175 | public static void PreviousFrame(boolean addToBack) {
|
---|
176 | addToBack = adjustAddToBack(addToBack);
|
---|
177 | Frame prev = FrameIO.LoadPrevious();
|
---|
178 | FrameUtils.DisplayFrame(prev, addToBack, true);
|
---|
179 | }
|
---|
180 |
|
---|
181 | public static void PreviousFrame() {
|
---|
182 | PreviousFrame(true);
|
---|
183 | }
|
---|
184 |
|
---|
185 | private static String _Parent = null;
|
---|
186 |
|
---|
187 | private static Item _LastItemUsed = null;
|
---|
188 |
|
---|
189 | public static void NextChild(Frame source) {
|
---|
190 | String back = DisplayIO.peekFromBackUpStack();
|
---|
191 | // if there is no parent frame (i.e. the user is on the home frame) //
|
---|
192 | if (back == null) { // No frame was on the Backup stack
|
---|
193 | MessageBay.displayMessage("No Parent Frame Found.");
|
---|
194 | _LastItemUsed = null; // ByRob: what is reason for setting
|
---|
195 | // this to null, who is going to use it????
|
---|
196 | _Parent = null; // ByRob: what is reason for setting this to
|
---|
197 | // null, who is going to use it
|
---|
198 | return;
|
---|
199 | }
|
---|
200 |
|
---|
201 | // Ensure the parent variable has been initialised
|
---|
202 | if (_Parent == null || !back.equals(_Parent)) { // ByRob: what the heck
|
---|
203 | // is the code doing?
|
---|
204 | // What is it setting
|
---|
205 | // up???????
|
---|
206 | _Parent = back;
|
---|
207 | _LastItemUsed = null;
|
---|
208 | }
|
---|
209 |
|
---|
210 | Frame parent = FrameIO.LoadFrame(_Parent);
|
---|
211 |
|
---|
212 | // find the next item to visit
|
---|
213 | List<Item> items = parent.getItems(); // getItems method gets us the
|
---|
214 | // FirstItem on the frame
|
---|
215 | int parentItemLinkedToSource = 0; // ByMike: Will be set to the
|
---|
216 | // index of the item on the parent which follows the item linked to the
|
---|
217 | // child frame we are currently viewing.
|
---|
218 |
|
---|
219 | // ByMike: if 'Next' has been clicked previously get the index of the
|
---|
220 | // item FOLLOWING the ParentItem linked to the source
|
---|
221 | if (_LastItemUsed != null) {
|
---|
222 | parentItemLinkedToSource = items.indexOf(_LastItemUsed);
|
---|
223 | }
|
---|
224 |
|
---|
225 | // ByMike: If the 'Next' child is being sought for the 1st time...
|
---|
226 | String sourceName = source.getName().toLowerCase();
|
---|
227 |
|
---|
228 | // ByMike: Find the first occurence of a ParentItem linked to the source
|
---|
229 | while (parentItemLinkedToSource < items.size()
|
---|
230 | && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
|
---|
231 | .get(parentItemLinkedToSource).getAbsoluteLink()
|
---|
232 | .toLowerCase().equals(sourceName))) {
|
---|
233 | parentItemLinkedToSource++; // ByRob: this increments to the next
|
---|
234 | // item
|
---|
235 | }
|
---|
236 |
|
---|
237 | // Find the next ParentItem linked to the next frame to be displayed
|
---|
238 | for (int i = parentItemLinkedToSource + 1; i < items.size(); i++) {
|
---|
239 | if (items.get(i).isLinkValid()
|
---|
240 | && !items.get(i).isAnnotation()
|
---|
241 | && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
|
---|
242 | source.getName())) {
|
---|
243 | _LastItemUsed = items.get(i);
|
---|
244 | FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false,
|
---|
245 | true);
|
---|
246 | return;
|
---|
247 | } // ByRob: end of if
|
---|
248 |
|
---|
249 | } // ByRob: End of For
|
---|
250 |
|
---|
251 | MessageBay.displayMessage("No more child frames found.");
|
---|
252 | }
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Turns TwinFrames on if it is off, otherwise does nothing
|
---|
256 | *
|
---|
257 | */
|
---|
258 | // ByRob: Rob doesn't like notion of turning TwinFrames on and off,
|
---|
259 | // better to say more explicitly/directly what the mode is!!!!
|
---|
260 | public static void Small() {
|
---|
261 | if (!DisplayIO.isTwinFramesOn())
|
---|
262 | DisplayIO.ToggleTwinFrames();
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*
|
---|
266 | * When display frame is called with addToBack set to false multiple
|
---|
267 | * times... Only the first frame is added to the backup stack. This flag
|
---|
268 | * stores the state for the addToBack parameter the last time this method
|
---|
269 | * was called.
|
---|
270 | */
|
---|
271 | private static boolean _lastAddToBack = true;
|
---|
272 |
|
---|
273 | public static void ResetLastAddToBack() {
|
---|
274 | _lastAddToBack = true;
|
---|
275 | }
|
---|
276 |
|
---|
277 | private static boolean adjustAddToBack(boolean addToBack) {
|
---|
278 | boolean originalAddToBack = addToBack;
|
---|
279 |
|
---|
280 | if (!addToBack && _lastAddToBack) {
|
---|
281 | // This adds the first frame to the backup stack when the user
|
---|
282 | // navigates through a bunch of frames with the keyboard!
|
---|
283 | addToBack = true;
|
---|
284 | }
|
---|
285 |
|
---|
286 | _lastAddToBack = originalAddToBack;
|
---|
287 |
|
---|
288 | return addToBack;
|
---|
289 | }
|
---|
290 | }
|
---|