[919] | 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 |
|
---|
[4] | 19 | package org.expeditee.actions;
|
---|
| 20 |
|
---|
| 21 | import java.util.List;
|
---|
| 22 |
|
---|
[1102] | 23 | import org.expeditee.gui.DisplayController;
|
---|
[4] | 24 | import org.expeditee.gui.Frame;
|
---|
| 25 | import org.expeditee.gui.FrameIO;
|
---|
| 26 | import org.expeditee.gui.FrameUtils;
|
---|
[121] | 27 | import org.expeditee.gui.MessageBay;
|
---|
[4] | 28 | import org.expeditee.items.Item;
|
---|
[570] | 29 | import org.expeditee.settings.UserSettings;
|
---|
[4] | 30 |
|
---|
| 31 | /**
|
---|
[105] | 32 | * Provides the Navigation related action procedures
|
---|
[4] | 33 | *
|
---|
| 34 | * @author jdm18
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
[306] | 37 | public class Navigation {
|
---|
[4] | 38 |
|
---|
| 39 | public static void setLastNavigationItem(Item i) {
|
---|
| 40 | _LastItemUsed = i;
|
---|
| 41 | if (i.getParent() != null) {
|
---|
[80] | 42 | _Parent = i.getParent().getName();
|
---|
[4] | 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() {
|
---|
[1102] | 51 | DisplayController.Back();
|
---|
[4] | 52 | }
|
---|
[419] | 53 |
|
---|
[176] | 54 | public static void Forward() {
|
---|
[1102] | 55 | DisplayController.Forward();
|
---|
[176] | 56 | }
|
---|
[4] | 57 |
|
---|
| 58 | /**
|
---|
| 59 | * Displays the user's home frame
|
---|
| 60 | */
|
---|
| 61 | public static void GotoHome() {
|
---|
[655] | 62 | FrameUtils.DisplayFrame(UserSettings.HomeFrame.get());
|
---|
[4] | 63 | }
|
---|
[885] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Displays the user's first settings frame - should be `username`2
|
---|
| 67 | */
|
---|
| 68 | public static void GotoSettings() {
|
---|
[1032] | 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 |
|
---|
[885] | 75 | FrameUtils.DisplayFrame(framename);
|
---|
| 76 | }
|
---|
[419] | 77 |
|
---|
[410] | 78 | public static void GotoZero() {
|
---|
[419] | 79 | FrameUtils
|
---|
[1102] | 80 | .DisplayFrame(DisplayController.getCurrentFrame().getFramesetName() + 0);
|
---|
[410] | 81 | }
|
---|
[4] | 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Displays the user's profile frame (if there is one)
|
---|
| 85 | */
|
---|
| 86 | public static void GotoProfile() {
|
---|
[655] | 87 | FrameUtils.DisplayFrame(UserSettings.ProfileName.get() + '1');
|
---|
[4] | 88 | }
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
[410] | 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) {
|
---|
[1102] | 98 | FrameUtils.DisplayFrame(DisplayController.getCurrentFrame().getFramesetName()
|
---|
[419] | 99 | + value);
|
---|
[410] | 100 | }
|
---|
[419] | 101 |
|
---|
[410] | 102 | /**
|
---|
[4] | 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 | }
|
---|
[669] | 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 | }
|
---|
[4] | 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() {
|
---|
[1102] | 134 | if (DisplayController.isTwinFramesOn())
|
---|
| 135 | DisplayController.toggleTwinFrames();
|
---|
[4] | 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() {
|
---|
[65] | 144 | NextFrame(true);
|
---|
| 145 | }
|
---|
[419] | 146 |
|
---|
[65] | 147 | public static void NextFrame(boolean addToBack) {
|
---|
[67] | 148 | addToBack = adjustAddToBack(addToBack);
|
---|
[4] | 149 | Frame next = FrameIO.LoadNext();
|
---|
[408] | 150 | FrameUtils.DisplayFrame(next, addToBack, true);
|
---|
[4] | 151 | }
|
---|
[419] | 152 |
|
---|
[4] | 153 | /**
|
---|
| 154 | * Navigates to the last frame in the frameset.
|
---|
[419] | 155 | *
|
---|
[4] | 156 | */
|
---|
| 157 | public static void LastFrame() {
|
---|
| 158 | Frame last = FrameIO.LoadLast();
|
---|
[408] | 159 | FrameUtils.DisplayFrame(last, true, true);
|
---|
[4] | 160 | }
|
---|
[419] | 161 |
|
---|
[13] | 162 | public static void ZeroFrame() {
|
---|
| 163 | Frame zeroFrame = FrameIO.LoadZero();
|
---|
[408] | 164 | FrameUtils.DisplayFrame(zeroFrame, true, true);
|
---|
[13] | 165 | }
|
---|
[4] | 166 |
|
---|
| 167 | public static void Next() {
|
---|
| 168 | NextFrame();
|
---|
| 169 | }
|
---|
[419] | 170 |
|
---|
[4] | 171 | public static void Previous() {
|
---|
| 172 | PreviousFrame();
|
---|
| 173 | }
|
---|
[419] | 174 |
|
---|
[65] | 175 | public static void PreviousFrame(boolean addToBack) {
|
---|
[67] | 176 | addToBack = adjustAddToBack(addToBack);
|
---|
[4] | 177 | Frame prev = FrameIO.LoadPrevious();
|
---|
[408] | 178 | FrameUtils.DisplayFrame(prev, addToBack, true);
|
---|
[4] | 179 | }
|
---|
[419] | 180 |
|
---|
[65] | 181 | public static void PreviousFrame() {
|
---|
| 182 | PreviousFrame(true);
|
---|
| 183 | }
|
---|
[4] | 184 |
|
---|
| 185 | private static String _Parent = null;
|
---|
| 186 |
|
---|
| 187 | private static Item _LastItemUsed = null;
|
---|
| 188 |
|
---|
| 189 | public static void NextChild(Frame source) {
|
---|
[1102] | 190 | String back = DisplayController.peekFromBackUpStack();
|
---|
[4] | 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
|
---|
[121] | 193 | MessageBay.displayMessage("No Parent Frame Found.");
|
---|
[4] | 194 | _LastItemUsed = null; // ByRob: what is reason for setting
|
---|
[70] | 195 | // this to null, who is going to use it????
|
---|
[4] | 196 | _Parent = null; // ByRob: what is reason for setting this to
|
---|
| 197 | // null, who is going to use it
|
---|
| 198 | return;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[419] | 201 | // Ensure the parent variable has been initialised
|
---|
[4] | 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 |
|
---|
[70] | 210 | Frame parent = FrameIO.LoadFrame(_Parent);
|
---|
[4] | 211 |
|
---|
[70] | 212 | // find the next item to visit
|
---|
[1415] | 213 | List<Item> items = parent.getSortedItems(); // getItems method gets us the
|
---|
[4] | 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...
|
---|
[80] | 226 | String sourceName = source.getName().toLowerCase();
|
---|
[4] | 227 |
|
---|
| 228 | // ByMike: Find the first occurence of a ParentItem linked to the source
|
---|
| 229 | while (parentItemLinkedToSource < items.size()
|
---|
[67] | 230 | && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
|
---|
[419] | 231 | .get(parentItemLinkedToSource).getAbsoluteLink()
|
---|
| 232 | .toLowerCase().equals(sourceName))) {
|
---|
[4] | 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()
|
---|
[70] | 241 | && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
|
---|
[80] | 242 | source.getName())) {
|
---|
[4] | 243 | _LastItemUsed = items.get(i);
|
---|
[419] | 244 | FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false,
|
---|
| 245 | true);
|
---|
[4] | 246 | return;
|
---|
| 247 | } // ByRob: end of if
|
---|
| 248 |
|
---|
| 249 | } // ByRob: End of For
|
---|
| 250 |
|
---|
[121] | 251 | MessageBay.displayMessage("No more child frames found.");
|
---|
[4] | 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() {
|
---|
[1102] | 261 | if (!DisplayController.isTwinFramesOn())
|
---|
| 262 | DisplayController.toggleTwinFrames();
|
---|
[4] | 263 | }
|
---|
[419] | 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 | */
|
---|
[67] | 271 | private static boolean _lastAddToBack = true;
|
---|
| 272 |
|
---|
| 273 | public static void ResetLastAddToBack() {
|
---|
| 274 | _lastAddToBack = true;
|
---|
| 275 | }
|
---|
[419] | 276 |
|
---|
[67] | 277 | private static boolean adjustAddToBack(boolean addToBack) {
|
---|
| 278 | boolean originalAddToBack = addToBack;
|
---|
[419] | 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!
|
---|
[67] | 283 | addToBack = true;
|
---|
| 284 | }
|
---|
[419] | 285 |
|
---|
[67] | 286 | _lastAddToBack = originalAddToBack;
|
---|
[419] | 287 |
|
---|
[67] | 288 | return addToBack;
|
---|
| 289 | }
|
---|
[4] | 290 | }
|
---|