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

Last change on this file since 967 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

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