[4] | 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;
|
---|
[121] | 9 | import org.expeditee.gui.MessageBay;
|
---|
[4] | 10 | import org.expeditee.items.Item;
|
---|
[570] | 11 | import org.expeditee.settings.UserSettings;
|
---|
[4] | 12 |
|
---|
| 13 | /**
|
---|
[105] | 14 | * Provides the Navigation related action procedures
|
---|
[4] | 15 | *
|
---|
| 16 | * @author jdm18
|
---|
| 17 | *
|
---|
| 18 | */
|
---|
[306] | 19 | public class Navigation {
|
---|
[4] | 20 |
|
---|
| 21 | public static void setLastNavigationItem(Item i) {
|
---|
| 22 | _LastItemUsed = i;
|
---|
| 23 | if (i.getParent() != null) {
|
---|
[80] | 24 | _Parent = i.getParent().getName();
|
---|
[4] | 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 | }
|
---|
[419] | 35 |
|
---|
[176] | 36 | public static void Forward() {
|
---|
| 37 | DisplayIO.Forward();
|
---|
| 38 | }
|
---|
[4] | 39 |
|
---|
| 40 | /**
|
---|
| 41 | * Displays the user's home frame
|
---|
| 42 | */
|
---|
| 43 | public static void GotoHome() {
|
---|
[410] | 44 | FrameUtils.DisplayFrame(UserSettings.HomeFrame);
|
---|
[4] | 45 | }
|
---|
[419] | 46 |
|
---|
[410] | 47 | public static void GotoZero() {
|
---|
[419] | 48 | FrameUtils
|
---|
| 49 | .DisplayFrame(DisplayIO.getCurrentFrame().getFramesetName() + 0);
|
---|
[410] | 50 | }
|
---|
[4] | 51 |
|
---|
| 52 | /**
|
---|
| 53 | * Displays the user's profile frame (if there is one)
|
---|
| 54 | */
|
---|
| 55 | public static void GotoProfile() {
|
---|
[410] | 56 | FrameUtils.DisplayFrame(UserSettings.ProfileName + '1');
|
---|
[4] | 57 | }
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
[410] | 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) {
|
---|
[419] | 67 | FrameUtils.DisplayFrame(DisplayIO.getCurrentFrame().getFramesetName()
|
---|
| 68 | + value);
|
---|
[410] | 69 | }
|
---|
[419] | 70 |
|
---|
[410] | 71 | /**
|
---|
[4] | 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() {
|
---|
[65] | 106 | NextFrame(true);
|
---|
| 107 | }
|
---|
[419] | 108 |
|
---|
[65] | 109 | public static void NextFrame(boolean addToBack) {
|
---|
[67] | 110 | addToBack = adjustAddToBack(addToBack);
|
---|
[4] | 111 | Frame next = FrameIO.LoadNext();
|
---|
[408] | 112 | FrameUtils.DisplayFrame(next, addToBack, true);
|
---|
[4] | 113 | }
|
---|
[419] | 114 |
|
---|
[4] | 115 | /**
|
---|
| 116 | * Navigates to the last frame in the frameset.
|
---|
[419] | 117 | *
|
---|
[4] | 118 | */
|
---|
| 119 | public static void LastFrame() {
|
---|
| 120 | Frame last = FrameIO.LoadLast();
|
---|
[408] | 121 | FrameUtils.DisplayFrame(last, true, true);
|
---|
[4] | 122 | }
|
---|
[419] | 123 |
|
---|
[13] | 124 | public static void ZeroFrame() {
|
---|
| 125 | Frame zeroFrame = FrameIO.LoadZero();
|
---|
[408] | 126 | FrameUtils.DisplayFrame(zeroFrame, true, true);
|
---|
[13] | 127 | }
|
---|
[4] | 128 |
|
---|
| 129 | public static void Next() {
|
---|
| 130 | NextFrame();
|
---|
| 131 | }
|
---|
[419] | 132 |
|
---|
[4] | 133 | public static void Previous() {
|
---|
| 134 | PreviousFrame();
|
---|
| 135 | }
|
---|
[419] | 136 |
|
---|
[65] | 137 | public static void PreviousFrame(boolean addToBack) {
|
---|
[67] | 138 | addToBack = adjustAddToBack(addToBack);
|
---|
[4] | 139 | Frame prev = FrameIO.LoadPrevious();
|
---|
[408] | 140 | FrameUtils.DisplayFrame(prev, addToBack, true);
|
---|
[4] | 141 | }
|
---|
[419] | 142 |
|
---|
[65] | 143 | public static void PreviousFrame() {
|
---|
| 144 | PreviousFrame(true);
|
---|
| 145 | }
|
---|
[4] | 146 |
|
---|
| 147 | private static String _Parent = null;
|
---|
| 148 |
|
---|
| 149 | private static Item _LastItemUsed = null;
|
---|
| 150 |
|
---|
| 151 | public static void NextChild(Frame source) {
|
---|
[70] | 152 | String back = DisplayIO.peekFromBackUpStack();
|
---|
[4] | 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
|
---|
[121] | 155 | MessageBay.displayMessage("No Parent Frame Found.");
|
---|
[4] | 156 | _LastItemUsed = null; // ByRob: what is reason for setting
|
---|
[70] | 157 | // this to null, who is going to use it????
|
---|
[4] | 158 | _Parent = null; // ByRob: what is reason for setting this to
|
---|
| 159 | // null, who is going to use it
|
---|
| 160 | return;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[419] | 163 | // Ensure the parent variable has been initialised
|
---|
[4] | 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 |
|
---|
[70] | 172 | Frame parent = FrameIO.LoadFrame(_Parent);
|
---|
[4] | 173 |
|
---|
[70] | 174 | // find the next item to visit
|
---|
[4] | 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...
|
---|
[80] | 188 | String sourceName = source.getName().toLowerCase();
|
---|
[4] | 189 |
|
---|
| 190 | // ByMike: Find the first occurence of a ParentItem linked to the source
|
---|
| 191 | while (parentItemLinkedToSource < items.size()
|
---|
[67] | 192 | && (items.get(parentItemLinkedToSource).getAbsoluteLink() == null || !items
|
---|
[419] | 193 | .get(parentItemLinkedToSource).getAbsoluteLink()
|
---|
| 194 | .toLowerCase().equals(sourceName))) {
|
---|
[4] | 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()
|
---|
[70] | 203 | && !items.get(i).getAbsoluteLink().equalsIgnoreCase(
|
---|
[80] | 204 | source.getName())) {
|
---|
[4] | 205 | _LastItemUsed = items.get(i);
|
---|
[419] | 206 | FrameUtils.DisplayFrame(_LastItemUsed.getAbsoluteLink(), false,
|
---|
| 207 | true);
|
---|
[4] | 208 | return;
|
---|
| 209 | } // ByRob: end of if
|
---|
| 210 |
|
---|
| 211 | } // ByRob: End of For
|
---|
| 212 |
|
---|
[121] | 213 | MessageBay.displayMessage("No more child frames found.");
|
---|
[4] | 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 | }
|
---|
[419] | 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 | */
|
---|
[67] | 233 | private static boolean _lastAddToBack = true;
|
---|
| 234 |
|
---|
| 235 | public static void ResetLastAddToBack() {
|
---|
| 236 | _lastAddToBack = true;
|
---|
| 237 | }
|
---|
[419] | 238 |
|
---|
[67] | 239 | private static boolean adjustAddToBack(boolean addToBack) {
|
---|
| 240 | boolean originalAddToBack = addToBack;
|
---|
[419] | 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!
|
---|
[67] | 245 | addToBack = true;
|
---|
| 246 | }
|
---|
[419] | 247 |
|
---|
[67] | 248 | _lastAddToBack = originalAddToBack;
|
---|
[419] | 249 |
|
---|
[67] | 250 | return addToBack;
|
---|
| 251 | }
|
---|
[4] | 252 | }
|
---|