[4] | 1 | package org.expeditee.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.AWTException;
|
---|
| 4 | import java.awt.Color;
|
---|
| 5 | import java.awt.Cursor;
|
---|
| 6 | import java.awt.Image;
|
---|
| 7 | import java.awt.Point;
|
---|
| 8 | import java.awt.Robot;
|
---|
| 9 | import java.awt.Toolkit;
|
---|
[108] | 10 | import java.awt.geom.Point2D;
|
---|
[4] | 11 | import java.awt.image.MemoryImageSource;
|
---|
[121] | 12 | import java.util.ArrayList;
|
---|
[115] | 13 | import java.util.Collection;
|
---|
[34] | 14 | import java.util.LinkedList;
|
---|
[4] | 15 | import java.util.List;
|
---|
| 16 | import java.util.Stack;
|
---|
| 17 |
|
---|
| 18 | import javax.swing.JOptionPane;
|
---|
| 19 |
|
---|
| 20 | import org.expeditee.items.Item;
|
---|
[55] | 21 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
[7] | 22 | import org.expeditee.items.Picture;
|
---|
[86] | 23 | import org.expeditee.items.Text;
|
---|
[4] | 24 | import org.expeditee.stats.SessionStats;
|
---|
[139] | 25 | import org.expeditee.taskmanagement.EntitySaveManager;
|
---|
[4] | 26 |
|
---|
| 27 | /**
|
---|
| 28 | * This Interface is used by the Frame to control all display input and output.
|
---|
| 29 | *
|
---|
| 30 | * @author jdm18
|
---|
| 31 | *
|
---|
| 32 | */
|
---|
| 33 | public class DisplayIO {
|
---|
| 34 |
|
---|
| 35 | private static final int SMALL_CURSOR_SIZE = 16;
|
---|
| 36 |
|
---|
| 37 | private static final int MEDIUM_CURSOR_SIZE = 32;
|
---|
| 38 |
|
---|
| 39 | private static final int LARGE_CURSOR_SIZE = 64;
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * The color to be used to highlight the linked parent item, when the user
|
---|
| 43 | * navigates backwards.
|
---|
| 44 | */
|
---|
| 45 | public static final Color BACK_HIGHLIGHT_COLOR = Color.MAGENTA;
|
---|
| 46 |
|
---|
| 47 | private static Browser _Browser;
|
---|
| 48 |
|
---|
| 49 | // The current Frame being displayed on the screen.
|
---|
| 50 | private static Frame _CurrentFrames[] = new Frame[2];
|
---|
| 51 |
|
---|
| 52 | // Maintains the list of frames visited thus-far for back-tracking
|
---|
| 53 | @SuppressWarnings("unchecked")
|
---|
| 54 | private static Stack<String>[] _VisitedFrames = new Stack[2];
|
---|
| 55 |
|
---|
| 56 | // used to change the mouse cursor position on the screen
|
---|
| 57 | private static Robot _Robot;
|
---|
| 58 |
|
---|
| 59 | private static boolean _TwinFrames = false;
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * The title to display in the Title bar.
|
---|
| 63 | */
|
---|
[156] | 64 | public static final String TITLE = "Exp22Jul2008A";
|
---|
[4] | 65 |
|
---|
| 66 | private DisplayIO() {
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public static void Init(Browser browser) {
|
---|
| 70 | _Browser = browser;
|
---|
| 71 | try {
|
---|
| 72 | _Robot = new Robot();
|
---|
| 73 | } catch (AWTException e) {
|
---|
| 74 | e.printStackTrace();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | Point mouse = _Browser.getMousePosition();
|
---|
| 78 | if (mouse != null) {
|
---|
| 79 | FrameMouseActions.MouseX = mouse.x;
|
---|
| 80 | FrameMouseActions.MouseY = mouse.y;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | _VisitedFrames[0] = new Stack<String>();
|
---|
| 84 | _VisitedFrames[1] = new Stack<String>();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[105] | 87 | public static void setTextCursor(Text text, int cursorMovement) {
|
---|
| 88 | setTextCursor(text, cursorMovement, false);
|
---|
[86] | 89 | }
|
---|
| 90 |
|
---|
[105] | 91 | public static void setTextCursor(Text text, int cursorMovement,
|
---|
| 92 | boolean newSize) {
|
---|
| 93 |
|
---|
[108] | 94 | int size = Math.round(text.getSize());
|
---|
[115] | 95 | Point2D.Float newMouse = text.moveCursor(cursorMovement, DisplayIO
|
---|
| 96 | .getFloatMouseX(), FrameMouseActions.MouseY);
|
---|
[105] | 97 |
|
---|
| 98 | if (!newSize && cursorType == Item.TEXT_CURSOR) {
|
---|
| 99 | if (cursorMovement != 0)
|
---|
| 100 | DisplayIO.setCursorPosition(newMouse, false);
|
---|
[4] | 101 | return;
|
---|
[105] | 102 | }
|
---|
[4] | 103 |
|
---|
| 104 | cursorType = Item.TEXT_CURSOR;
|
---|
| 105 |
|
---|
[21] | 106 | // Do some stuff to adjust the cursor size based on the font size
|
---|
[4] | 107 | final int MEDIUM_CURSOR_CUTOFF = 31;
|
---|
| 108 | final int LARGE_CURSOR_CUTOFF = 62;
|
---|
| 109 |
|
---|
| 110 | int cursorSize = LARGE_CURSOR_SIZE;
|
---|
| 111 | int hotspotPos = 0;
|
---|
| 112 | int start = 0;
|
---|
| 113 |
|
---|
| 114 | if (size < MEDIUM_CURSOR_CUTOFF) {
|
---|
| 115 | cursorSize = MEDIUM_CURSOR_SIZE;
|
---|
| 116 | start = cursorSize - size - 2;
|
---|
| 117 | hotspotPos = cursorSize - (size + 2) / 4;
|
---|
| 118 | } else if (size < LARGE_CURSOR_CUTOFF) {
|
---|
| 119 | hotspotPos = cursorSize - (size - 5) / 4;
|
---|
| 120 | start = cursorSize - size - 2;
|
---|
| 121 | } else {
|
---|
| 122 | int FIXED_CURSOR_MIN = 77;
|
---|
| 123 | if (size >= FIXED_CURSOR_MIN) {
|
---|
| 124 | hotspotPos = cursorSize - 2;
|
---|
| 125 | } else {
|
---|
| 126 | hotspotPos = size - (FIXED_CURSOR_MIN - cursorSize);
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | int[] pixels = new int[cursorSize * cursorSize];
|
---|
| 131 |
|
---|
| 132 | for (int i = start; i < cursorSize; i++)
|
---|
| 133 | pixels[i * cursorSize] = pixels[(i * cursorSize) + 1] = 0xFF000000;
|
---|
| 134 |
|
---|
| 135 | Image image = Toolkit.getDefaultToolkit().createImage(
|
---|
| 136 | new MemoryImageSource(cursorSize, cursorSize, pixels, 0,
|
---|
| 137 | cursorSize));
|
---|
| 138 | Cursor textCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
---|
| 139 | image, new Point(0, hotspotPos), "textcursor");
|
---|
| 140 | _Browser.setCursor(textCursor);
|
---|
[143] | 141 | if (cursorMovement != Text.NONE)
|
---|
| 142 | DisplayIO.setCursorPosition(newMouse, false);
|
---|
[4] | 143 | }
|
---|
| 144 |
|
---|
| 145 | /**
|
---|
| 146 | * Sets the type of cursor the display should be using
|
---|
| 147 | *
|
---|
| 148 | * @param type
|
---|
| 149 | * The type of cursor to display, using constants defined in the
|
---|
| 150 | * Cursor class.
|
---|
| 151 | */
|
---|
| 152 | public static void setCursor(int type) {
|
---|
| 153 | // avoid flicker when not changing
|
---|
| 154 | if (type == cursorType || type == Item.UNCHANGED_CURSOR)
|
---|
| 155 | return;
|
---|
| 156 |
|
---|
| 157 | cursorType = type;
|
---|
| 158 |
|
---|
| 159 | if (type == Item.HIDDEN_CURSOR) {
|
---|
| 160 | int[] pixels = new int[SMALL_CURSOR_SIZE * SMALL_CURSOR_SIZE];
|
---|
| 161 | Image image = Toolkit.getDefaultToolkit().createImage(
|
---|
| 162 | new MemoryImageSource(SMALL_CURSOR_SIZE, SMALL_CURSOR_SIZE,
|
---|
| 163 | pixels, 0, SMALL_CURSOR_SIZE));
|
---|
| 164 | Cursor transparentCursor = Toolkit.getDefaultToolkit()
|
---|
| 165 | .createCustomCursor(image, new Point(0, 0),
|
---|
| 166 | "invisiblecursor");
|
---|
| 167 | _Browser.setCursor(transparentCursor);
|
---|
| 168 | } else
|
---|
| 169 | _Browser.setCursor(new Cursor(type));
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | private static int cursorType = Item.DEFAULT_CURSOR;
|
---|
| 173 |
|
---|
| 174 | public static int getCursor() {
|
---|
| 175 | return cursorType;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /**
|
---|
| 179 | * Moves the mouse cursor to the given x,y coordinates on the screen
|
---|
| 180 | *
|
---|
| 181 | * @param x
|
---|
| 182 | * The x coordinate
|
---|
| 183 | * @param y
|
---|
| 184 | * The y coordinate
|
---|
| 185 | */
|
---|
[105] | 186 | public static void setCursorPosition(float x, float y) {
|
---|
[4] | 187 | setCursorPosition(x, y, true);
|
---|
| 188 | }
|
---|
[74] | 189 |
|
---|
[105] | 190 | public static void setCursorPosition(float x, float y, boolean forceArrow) {
|
---|
[74] | 191 | // Adjust the position to move the mouse to to account for being in
|
---|
| 192 | // TwinFramesMode
|
---|
| 193 | if (_TwinFrames) {
|
---|
| 194 | if (getCurrentSide() == 1) {
|
---|
| 195 | int middle = getMiddle();
|
---|
| 196 | x += middle;
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
[86] | 199 |
|
---|
[105] | 200 | float deltax = x - FrameMouseActions.MouseX;
|
---|
| 201 | float deltay = y - FrameMouseActions.MouseY;
|
---|
[4] | 202 |
|
---|
[74] | 203 | // When the Robot moves the cursor... a short time later a mouseMoved
|
---|
| 204 | // event is generated...
|
---|
| 205 | // We want to ignore this event by remembering the location the robot
|
---|
| 206 | // was shifted to.
|
---|
| 207 | FrameMouseActions.setLastRobotMove(x, y);
|
---|
[4] | 208 |
|
---|
[156] | 209 | if (FreeItems.itemAttachedToCursor()) {
|
---|
[121] | 210 | List<Item> toMove = FreeItems.getInstance();
|
---|
[21] | 211 | for (Item move : toMove) {
|
---|
| 212 | move.setPosition(move.getX() + deltax, move.getY() + deltay);
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | // cheat
|
---|
| 217 | FrameMouseActions.setForceArrow(forceArrow);
|
---|
[72] | 218 | int mouseX = (int) _Browser.getContentPane().getLocationOnScreen()
|
---|
[21] | 219 | .getX()
|
---|
[106] | 220 | + Math.round(x);
|
---|
[72] | 221 | int mouseY = (int) _Browser.getContentPane().getLocationOnScreen()
|
---|
[21] | 222 | .getY()
|
---|
[106] | 223 | + Math.round(y);
|
---|
[72] | 224 | _Robot.mouseMove(mouseX, mouseY);
|
---|
[74] | 225 | // System.out.println("MouseMoved: " + x + "," + y);
|
---|
[4] | 226 | }
|
---|
| 227 |
|
---|
| 228 | public static void resetCursorOffset() {
|
---|
| 229 | FrameMouseActions.resetOffset();
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[74] | 232 | /**
|
---|
| 233 | * Sets the current cursor position in the current frame
|
---|
| 234 | *
|
---|
| 235 | * @param pos
|
---|
| 236 | */
|
---|
[108] | 237 | public static void setCursorPosition(Point2D.Float pos) {
|
---|
| 238 | setCursorPosition(pos.x, pos.y);
|
---|
| 239 | }
|
---|
[115] | 240 |
|
---|
[4] | 241 | public static void setCursorPosition(Point pos) {
|
---|
| 242 | setCursorPosition(pos.x, pos.y);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | public static void setCursorPosition(Point pos, boolean forceArrow) {
|
---|
| 246 | setCursorPosition(pos.x, pos.y, forceArrow);
|
---|
| 247 | }
|
---|
[115] | 248 |
|
---|
[108] | 249 | public static void setCursorPosition(Point2D.Float pos, boolean forceArrow) {
|
---|
| 250 | setCursorPosition(pos.x, pos.y, forceArrow);
|
---|
| 251 | }
|
---|
[4] | 252 |
|
---|
[154] | 253 | // private static boolean _typed = false;
|
---|
| 254 | //
|
---|
| 255 | // public static void setKeyTyped(boolean val) {
|
---|
| 256 | // _typed = val;
|
---|
| 257 | // }
|
---|
| 258 | //
|
---|
| 259 | // public static boolean getKeyTyped() {
|
---|
| 260 | // return _typed;
|
---|
| 261 | // }
|
---|
[4] | 262 |
|
---|
| 263 | /**
|
---|
| 264 | * Returns the top item (last added) of the Back-Stack (which is popped off)
|
---|
| 265 | *
|
---|
| 266 | * @return The name of the last Frame added to the back-stack
|
---|
| 267 | */
|
---|
| 268 | public static String getLastFrame() {
|
---|
| 269 | int side = getCurrentSide();
|
---|
| 270 |
|
---|
| 271 | if (_VisitedFrames[side].size() > 0)
|
---|
| 272 | return _VisitedFrames[side].pop();
|
---|
| 273 | else
|
---|
| 274 | return null;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | /**
|
---|
| 278 | * Adds the given Frame to the back-stack
|
---|
| 279 | *
|
---|
| 280 | * @param frame
|
---|
| 281 | * The Frame to add
|
---|
| 282 | */
|
---|
| 283 | public static void addToBack(Frame toAdd) {
|
---|
| 284 | int side = getCurrentSide();
|
---|
| 285 |
|
---|
[105] | 286 | // // do not allow duplicate frames
|
---|
| 287 | // if (_VisitedFrames[side].size() > 0)
|
---|
| 288 | // if (_VisitedFrames[side].peek().equals(toAdd.getName())) {
|
---|
| 289 | // return;
|
---|
| 290 | // }
|
---|
[4] | 291 |
|
---|
[7] | 292 | Item ip = FrameUtils.getCurrentItem();
|
---|
| 293 | if (ip == null)
|
---|
[80] | 294 | _VisitedFrames[side].push(toAdd.getName());
|
---|
[4] | 295 | else
|
---|
[80] | 296 | _VisitedFrames[side].push(toAdd.getName());
|
---|
[105] | 297 |
|
---|
| 298 | // System.out.println("Added: " + _VisitedFrames[side].size());
|
---|
[4] | 299 | }
|
---|
| 300 |
|
---|
[86] | 301 | public static void removeFromBack() {
|
---|
| 302 | int side = getCurrentSide();
|
---|
| 303 |
|
---|
| 304 | // there must be a frame to go back to
|
---|
| 305 | if (_VisitedFrames[side].size() > 1) {
|
---|
| 306 | _VisitedFrames[side].pop();
|
---|
| 307 | }
|
---|
[105] | 308 | // System.out.println("Removed: " + _VisitedFrames[side].size());
|
---|
[86] | 309 | }
|
---|
| 310 |
|
---|
[4] | 311 | /**
|
---|
| 312 | * Returns a 'peek' at the end element on the back-stack of the current
|
---|
| 313 | * side. If the back-stack is empty, null is returned.
|
---|
| 314 | *
|
---|
| 315 | * @return The name of the most recent Frame added to the back-stack, or
|
---|
| 316 | * null if the back-stack is empty.
|
---|
| 317 | */
|
---|
[70] | 318 | public static String peekFromBackUpStack() {
|
---|
[4] | 319 | int side = getCurrentSide();
|
---|
| 320 |
|
---|
| 321 | // check that the stack is not empty
|
---|
| 322 | if (_VisitedFrames[side].size() > 0)
|
---|
| 323 | return _VisitedFrames[side].peek();
|
---|
| 324 |
|
---|
| 325 | // if the stack is empty, return null
|
---|
| 326 | return null;
|
---|
| 327 | }
|
---|
[154] | 328 |
|
---|
| 329 | public static void setCurrentFrame(Frame frame, boolean incrementStats) {
|
---|
[4] | 330 | if (frame == null)
|
---|
| 331 | return;
|
---|
[143] | 332 |
|
---|
[128] | 333 | // Remove any popups that are showing on the current frame
|
---|
| 334 | PopupManager.hideAllPopups();
|
---|
[143] | 335 |
|
---|
[4] | 336 | if (_TwinFrames) {
|
---|
| 337 | if (_CurrentFrames[0] == null) {
|
---|
| 338 | _CurrentFrames[0] = frame;
|
---|
| 339 | return;
|
---|
| 340 | }
|
---|
| 341 | if (_CurrentFrames[1] == null) {
|
---|
| 342 | _CurrentFrames[1] = frame;
|
---|
| 343 | return;
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | // if this is already the current frame
|
---|
| 348 | if (frame == getCurrentFrame()) {
|
---|
| 349 | FrameGraphics.Repaint();
|
---|
[121] | 350 | MessageBay.displayMessage(frame.getName()
|
---|
[4] | 351 | + " is already the current frame.");
|
---|
| 352 | return;
|
---|
[154] | 353 | } else if(incrementStats) {
|
---|
[4] | 354 | SessionStats.AccessedFrame();
|
---|
| 355 | }
|
---|
| 356 |
|
---|
[121] | 357 | // Invalidate free items
|
---|
| 358 | if (!FreeItems.getInstance().isEmpty() && getCurrentFrame() != null) {
|
---|
[143] | 359 |
|
---|
| 360 | // Empty free items temporarily so that the old frames buffer is
|
---|
| 361 | // repainted
|
---|
[121] | 362 | // without the free items.
|
---|
[143] | 363 | ArrayList<? extends Item> tmp = (ArrayList<? extends Item>) FreeItems
|
---|
| 364 | .getInstance().clone();
|
---|
| 365 | FreeItems.getInstance().clear(); // NOTE: This will invalidate
|
---|
[145] | 366 | // all the cleared free items
|
---|
[121] | 367 | FrameGraphics.refresh(true);
|
---|
| 368 | FreeItems.getInstance().addAll(tmp);
|
---|
[143] | 369 |
|
---|
[121] | 370 | }
|
---|
[145] | 371 |
|
---|
[139] | 372 | // Changing frames is a Save point for saveable entities:
|
---|
| 373 | EntitySaveManager.getInstance().saveAll();
|
---|
[4] | 374 | if (_TwinFrames) {
|
---|
| 375 | // if the same frame is being shown in both sides, load a fresh
|
---|
[115] | 376 | // copy from disk
|
---|
[4] | 377 | if (_CurrentFrames[getOppositeSide()] == frame
|
---|
[115] | 378 | || _CurrentFrames[getOppositeSide()].hasOverlay(frame)) {
|
---|
[4] | 379 | FrameIO.SuspendCache();
|
---|
[80] | 380 | frame = FrameIO.LoadFrame(frame.getName());
|
---|
[4] | 381 | FrameIO.ResumeCache();
|
---|
| 382 | }
|
---|
[21] | 383 |
|
---|
[10] | 384 | // If the frames are the same then the items for the
|
---|
| 385 | // frame that is just about to hide will still be in view
|
---|
| 386 | // so only notify items that they are hidden if the
|
---|
| 387 | // frames differ.
|
---|
[21] | 388 | if (_CurrentFrames[getCurrentSide()] != null
|
---|
| 389 | && _CurrentFrames[0] != _CurrentFrames[1]) {
|
---|
[10] | 390 | for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
|
---|
[55] | 391 | i.onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[72] | 392 | _CurrentFrames[getCurrentSide()],
|
---|
[55] | 393 | ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN));
|
---|
[10] | 394 | }
|
---|
| 395 | }
|
---|
[4] | 396 | _CurrentFrames[getCurrentSide()] = frame;
|
---|
[21] | 397 |
|
---|
[121] | 398 | // BROOK : TODO... overlays and loadable widgets
|
---|
[10] | 399 | for (Item i : _CurrentFrames[getCurrentSide()].getItems()) {
|
---|
[55] | 400 | i.onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[72] | 401 | _CurrentFrames[getCurrentSide()],
|
---|
[55] | 402 | ItemParentStateChangedEvent.EVENT_TYPE_SHOWN));
|
---|
[10] | 403 | }
|
---|
[4] | 404 | } else {
|
---|
[34] | 405 |
|
---|
[21] | 406 | // Notifying items on the frame being hidden that they
|
---|
[10] | 407 | // are about to be hidden.
|
---|
[34] | 408 | // ie. Widgets use this method to remove themselves from the JPanel
|
---|
| 409 | List<Frame> currentOnlyOverlays = new LinkedList<Frame>();
|
---|
| 410 | List<Frame> nextOnlyOverlays = new LinkedList<Frame>();
|
---|
| 411 | List<Frame> sharedOverlays = new LinkedList<Frame>();
|
---|
| 412 |
|
---|
| 413 | // Get all overlayed frames seen by the next frame
|
---|
[115] | 414 | for (Overlay o : frame.getOverlays()) {
|
---|
[34] | 415 | if (!nextOnlyOverlays.contains(o))
|
---|
| 416 | nextOnlyOverlays.add(o.Frame);
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | // Get all overlayed frames seen by the current frame
|
---|
[10] | 420 | if (_CurrentFrames[getCurrentSide()] != null) {
|
---|
[115] | 421 | for (Overlay o : _CurrentFrames[getCurrentSide()].getOverlays()) {
|
---|
[34] | 422 | if (!currentOnlyOverlays.contains(o))
|
---|
| 423 | currentOnlyOverlays.add(o.Frame);
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | // Extract shared overlays between the current and next frame
|
---|
| 428 | for (Frame of : currentOnlyOverlays) {
|
---|
| 429 | if (nextOnlyOverlays.contains(of)) {
|
---|
| 430 | sharedOverlays.add(of);
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 | // The first set, currentOnlyOverlays, must be notified that they
|
---|
| 435 | // are hidden
|
---|
[115] | 436 | Collection<Item> items = new LinkedList<Item>();
|
---|
[34] | 437 |
|
---|
| 438 | // Notify items that will not be in view any more
|
---|
| 439 | if (_CurrentFrames[getCurrentSide()] != null) {
|
---|
| 440 | List<Frame> seen = new LinkedList<Frame>();
|
---|
| 441 | seen.addAll(sharedOverlays); // Signify that seen all shared
|
---|
[72] | 442 | // overlays
|
---|
[34] | 443 | seen.remove(_CurrentFrames[getCurrentSide()]); // must ensure
|
---|
[72] | 444 | // excluded
|
---|
[34] | 445 |
|
---|
| 446 | // Get all items seen from the current frame - including all
|
---|
| 447 | // possible non-shared overlays
|
---|
[115] | 448 | items = _CurrentFrames[getCurrentSide()].getAllItems();
|
---|
| 449 | for (Frame f : seen)
|
---|
| 450 | items.removeAll(f.getAllItems());
|
---|
[34] | 451 |
|
---|
| 452 | // Notify items that they are hidden
|
---|
| 453 | for (Item i : items) {
|
---|
[55] | 454 | i.onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[72] | 455 | _CurrentFrames[getCurrentSide()],
|
---|
[55] | 456 | ItemParentStateChangedEvent.EVENT_TYPE_HIDDEN));
|
---|
[10] | 457 | }
|
---|
| 458 | }
|
---|
[21] | 459 |
|
---|
[34] | 460 | // Set the new frame
|
---|
[4] | 461 | _CurrentFrames[getCurrentSide()] = frame;
|
---|
[147] | 462 | frame.refreshSize(FrameGraphics.getMaxFrameSize());
|
---|
[21] | 463 |
|
---|
[10] | 464 | // Notify items on the frame being displayed that they are in view
|
---|
[21] | 465 | // ie. widgets use this method to add themselves to the content pane
|
---|
[34] | 466 | items.clear();
|
---|
| 467 |
|
---|
| 468 | // Notify overlay items that they are shown
|
---|
[115] | 469 | for (Item i : frame.getOverlayItems()) {
|
---|
| 470 | Overlay owner = frame.getOverlayOwner(i);
|
---|
[34] | 471 | // if (owner == null) i.onParentFameShown(false, 0);
|
---|
| 472 | // else ...
|
---|
| 473 | assert (owner != null);
|
---|
[72] | 474 | i
|
---|
| 475 | .onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[115] | 476 | frame,
|
---|
[72] | 477 | ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY,
|
---|
[115] | 478 | owner.permission));
|
---|
[10] | 479 | }
|
---|
[34] | 480 |
|
---|
[115] | 481 | for (Item i : frame.getItems()) {
|
---|
| 482 | i.onParentStateChanged(new ItemParentStateChangedEvent(frame,
|
---|
[55] | 483 | ItemParentStateChangedEvent.EVENT_TYPE_SHOWN));
|
---|
[34] | 484 | }
|
---|
[4] | 485 | }
|
---|
| 486 |
|
---|
[121] | 487 | FrameGraphics.refresh(false);
|
---|
[4] | 488 | }
|
---|
| 489 |
|
---|
| 490 | public static void UpdateTitle() {
|
---|
[72] | 491 | StringBuffer title = new StringBuffer(TITLE);
|
---|
[4] | 492 |
|
---|
| 493 | if (FrameGraphics.isAudienceMode())
|
---|
| 494 | title.append(" - Audience Mode");
|
---|
[80] | 495 | else if (FrameGraphics.isXRayMode())
|
---|
| 496 | title.append(" - X-Ray Mode");
|
---|
[7] | 497 | else
|
---|
[72] | 498 | title.append(" [").append(SessionStats.getShortStats()).append(']');
|
---|
[4] | 499 |
|
---|
| 500 | _Browser.setTitle(title.toString());
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | public static int getCurrentSide() {
|
---|
| 504 | if (_Browser == null)
|
---|
| 505 | return 0;
|
---|
[147] | 506 |
|
---|
[4] | 507 | if (_TwinFrames
|
---|
[147] | 508 | && FrameMouseActions.MouseX >= (_Browser.getWidth() / 2F)
|
---|
[4] | 509 | && _CurrentFrames[1] != null)
|
---|
| 510 | return 1;
|
---|
| 511 |
|
---|
| 512 | if (_CurrentFrames[0] == null && _CurrentFrames[1] != null)
|
---|
| 513 | return 1;
|
---|
| 514 |
|
---|
| 515 | return 0;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | private static int getOppositeSide() {
|
---|
| 519 | if (getCurrentSide() == 0)
|
---|
| 520 | return 1;
|
---|
| 521 |
|
---|
| 522 | return 0;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | public static int FrameOnSide(Frame toFind) {
|
---|
| 526 | if (_CurrentFrames[0] == toFind)
|
---|
| 527 | return 0;
|
---|
| 528 |
|
---|
| 529 | if (_CurrentFrames[1] == toFind)
|
---|
| 530 | return 1;
|
---|
| 531 |
|
---|
| 532 | return -1;
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | /**
|
---|
| 536 | * Returns the Frame currently being displayed on the screen.
|
---|
| 537 | *
|
---|
| 538 | * @return The Frame currently displayed.
|
---|
| 539 | */
|
---|
| 540 | public static Frame getCurrentFrame() {
|
---|
| 541 | return _CurrentFrames[getCurrentSide()];
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | public static Frame getOppositeFrame() {
|
---|
| 545 | return _CurrentFrames[getOppositeSide()];
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | public static Frame[] getFrames() {
|
---|
| 549 | return _CurrentFrames;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | public static int getMiddle() {
|
---|
| 553 | return _Browser.getWidth() / 2;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | public static int getHeight() {
|
---|
| 557 | return _Browser.getHeight();
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | /**
|
---|
| 561 | * Returns the current mouse X coordinate. This coordinate is relative to
|
---|
| 562 | * the left edge of the frame the mouse is in. It takes into account the
|
---|
| 563 | * user being in twin frames mode.
|
---|
| 564 | *
|
---|
| 565 | * @return The X coordinate of the mouse.
|
---|
| 566 | */
|
---|
[105] | 567 | public static float getFloatMouseX() {
|
---|
| 568 | if (_TwinFrames
|
---|
| 569 | && FrameMouseActions.MouseY < FrameGraphics.getMaxSize().height)
|
---|
[4] | 570 | return FrameMouseActions.MouseX % (_Browser.getWidth() / 2);
|
---|
| 571 |
|
---|
| 572 | return FrameMouseActions.MouseX;
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | /**
|
---|
[105] | 576 | * Returns the current mouse X coordinate. This coordinate is relative to
|
---|
| 577 | * the left edge of the frame the mouse is in. It takes into account the
|
---|
| 578 | * user being in twin frames mode.
|
---|
[4] | 579 | *
|
---|
[105] | 580 | * @return The X coordinate of the mouse.
|
---|
[4] | 581 | */
|
---|
[105] | 582 | public static int getMouseX() {
|
---|
| 583 | return Math.round(getFloatMouseX());
|
---|
[4] | 584 | }
|
---|
| 585 |
|
---|
[72] | 586 | public static void Back() {
|
---|
[4] | 587 | int side = getCurrentSide();
|
---|
| 588 |
|
---|
| 589 | // there must be a frame to go back to
|
---|
| 590 | if (_VisitedFrames[side].size() < 1) {
|
---|
[143] | 591 | MessageBay.displayMessageOnce("You are already on the home frame");
|
---|
[4] | 592 | return;
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | if (!FrameUtils.LeavingFrame(getCurrentFrame())) {
|
---|
[121] | 596 | MessageBay.displayMessage("Back operation cancelled");
|
---|
[4] | 597 | return;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[80] | 600 | String oldFrame = getCurrentFrame().getName().toLowerCase();
|
---|
[4] | 601 |
|
---|
| 602 | // do not get a cached version (in case it is in the other window)
|
---|
| 603 | if (isTwinFramesOn())
|
---|
| 604 | FrameIO.SuspendCache();
|
---|
[90] | 605 | Frame frame = FrameIO.LoadFrame(_VisitedFrames[side].pop());
|
---|
[105] | 606 | // If the top frame on the backup stack is the current frame go back
|
---|
| 607 | // again...
|
---|
| 608 | if (frame.equals(getCurrentFrame())) {
|
---|
[90] | 609 | Back();
|
---|
| 610 | return;
|
---|
| 611 | }
|
---|
[72] | 612 |
|
---|
[86] | 613 | if (isTwinFramesOn()) {
|
---|
[4] | 614 | FrameIO.ResumeCache();
|
---|
[86] | 615 | }
|
---|
[4] | 616 |
|
---|
| 617 | FrameUtils.DisplayFrame(frame, false);
|
---|
| 618 | FrameMouseActions.setHighlightHold(true);
|
---|
| 619 |
|
---|
[86] | 620 | for (Item i : frame.getItems()) {
|
---|
[4] | 621 | if (i.getLink() != null
|
---|
[7] | 622 | && i.getAbsoluteLink().toLowerCase().equals(oldFrame)) {
|
---|
[115] | 623 | if (i.getHighlightMode() != Item.HighlightMode.Normal) {
|
---|
| 624 | i.setHighlightMode(Item.HighlightMode.Normal,
|
---|
[86] | 625 | BACK_HIGHLIGHT_COLOR);
|
---|
| 626 | }
|
---|
[21] | 627 | // check if its an @f item and if so update the buffer
|
---|
[7] | 628 | if (i instanceof Picture) {
|
---|
[21] | 629 | Picture p = (Picture) i;
|
---|
[7] | 630 | p.refresh();
|
---|
| 631 | }
|
---|
[4] | 632 | }
|
---|
[86] | 633 | }
|
---|
[4] | 634 | FrameGraphics.Repaint();
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | /**
|
---|
| 638 | * Toggles the display of frames between TwinFrames mode and Single frame
|
---|
| 639 | * mode.
|
---|
| 640 | */
|
---|
| 641 | public static void ToggleTwinFrames() {
|
---|
| 642 | // determine which side is the active side
|
---|
| 643 | int opposite = getOppositeSide();
|
---|
| 644 | int current = getCurrentSide();
|
---|
| 645 | _TwinFrames = !_TwinFrames;
|
---|
| 646 |
|
---|
| 647 | // if TwinFrames is being turned on
|
---|
| 648 | if (_TwinFrames) {
|
---|
| 649 | // if this is the first time TwinFrames has been toggled on,
|
---|
[154] | 650 | // load the user's first frame
|
---|
[4] | 651 | if (_VisitedFrames[opposite].size() == 0) {
|
---|
| 652 | FrameIO.SuspendCache();
|
---|
[154] | 653 | setCurrentFrame(FrameIO.LoadFrame(UserSettings.FirstFrame), true);
|
---|
[4] | 654 | FrameIO.ResumeCache();
|
---|
| 655 | } else {
|
---|
| 656 | // otherwise, restore the frame from the side's back-stack
|
---|
| 657 | setCurrentFrame(FrameIO.LoadFrame(_VisitedFrames[opposite]
|
---|
[154] | 658 | .pop()), true);
|
---|
[4] | 659 | }
|
---|
| 660 |
|
---|
| 661 | // else, TwinFrames is being turned off
|
---|
| 662 | } else {
|
---|
| 663 | // add the frame to the back-stack
|
---|
| 664 | Frame hiding = _CurrentFrames[opposite];
|
---|
| 665 | FrameUtils.LeavingFrame(hiding);
|
---|
[80] | 666 | _VisitedFrames[opposite].add(hiding.getName());
|
---|
[4] | 667 | _CurrentFrames[opposite] = null;
|
---|
[147] | 668 | _CurrentFrames[current].refreshSize(FrameGraphics.getMaxFrameSize());
|
---|
[4] | 669 | }
|
---|
| 670 | if (_CurrentFrames[current] != null)
|
---|
[147] | 671 | _CurrentFrames[current].refreshSize(FrameGraphics.getMaxFrameSize());
|
---|
[4] | 672 | if (_CurrentFrames[opposite] != null)
|
---|
| 673 | _CurrentFrames[opposite]
|
---|
[147] | 674 | .refreshSize(FrameGraphics.getMaxFrameSize());
|
---|
[4] | 675 |
|
---|
| 676 | FrameGraphics.Clear();
|
---|
[154] | 677 | FrameGraphics.requestRefresh(false);
|
---|
[4] | 678 | FrameGraphics.Repaint();
|
---|
| 679 | }
|
---|
| 680 |
|
---|
| 681 | public static boolean isTwinFramesOn() {
|
---|
| 682 | return _TwinFrames;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | public static void Reload(int side) {
|
---|
| 686 | if (side < 0)
|
---|
| 687 | return;
|
---|
| 688 |
|
---|
| 689 | FrameIO.SuspendCache();
|
---|
[86] | 690 | _CurrentFrames[side] = FrameIO
|
---|
| 691 | .LoadFrame(_CurrentFrames[side].getName());
|
---|
[4] | 692 | FrameIO.ResumeCache();
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | public static boolean DisplayConfirmDialog(String message, String title,
|
---|
| 696 | int type, int options, int res) {
|
---|
| 697 | return JOptionPane.showConfirmDialog(_Browser, message, title, options,
|
---|
| 698 | type) == res;
|
---|
| 699 | }
|
---|
| 700 |
|
---|
| 701 | public static final int RESULT_OK = JOptionPane.OK_OPTION;
|
---|
| 702 |
|
---|
| 703 | public static final int OPTIONS_OK_CANCEL = JOptionPane.OK_CANCEL_OPTION;
|
---|
| 704 |
|
---|
| 705 | public static final int TYPE_WARNING = JOptionPane.WARNING_MESSAGE;
|
---|
| 706 |
|
---|
| 707 | public static void pressMouse(int buttons) {
|
---|
| 708 | _Robot.mousePress(buttons);
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | public static void releaseMouse(int buttons) {
|
---|
| 712 | _Robot.mouseRelease(buttons);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | public static void clickMouse(int buttons) {
|
---|
| 716 | _Robot.mousePress(buttons);
|
---|
| 717 | _Robot.mouseRelease(buttons);
|
---|
| 718 | }
|
---|
[86] | 719 |
|
---|
| 720 | /**
|
---|
| 721 | * Moves the cursor the end of this item.
|
---|
| 722 | *
|
---|
| 723 | * @param i
|
---|
| 724 | */
|
---|
| 725 | public static void MoveCursorToEndOfItem(Item i) {
|
---|
[108] | 726 | setTextCursor((Text) i, Text.END, true);
|
---|
[86] | 727 | }
|
---|
[145] | 728 |
|
---|
| 729 | public static void translateCursor(int deltaX, int deltaY) {
|
---|
| 730 | setCursorPosition(FrameMouseActions.MouseX + deltaX,
|
---|
| 731 | FrameMouseActions.MouseY + deltaY, false);
|
---|
| 732 | }
|
---|
[4] | 733 | }
|
---|