source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/LastItemAction.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 2.6 KB
Line 
1package org.expeditee.items.MagneticConstraint.Actions;
2
3import org.expeditee.gui.DisplayController;
4import org.expeditee.gui.FrameGraphics;
5import org.expeditee.gui.FrameUtils;
6import org.expeditee.items.Item;
7import org.expeditee.items.Text;
8import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
9import org.expeditee.items.MagneticConstraint.MagneticConstraints;
10import org.expeditee.items.MagneticConstraint.Utilities.Line;
11
12public class LastItemAction extends MagneticConstraintAction {
13
14 @Override
15 public boolean exec(final Item item) {
16 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false;
17 final int idLeft = item.getMagnetizedItemLeft();
18 final int idTop = item.getMagnetizedItemTop();
19 if(idLeft != -1) {
20 moveCursor(item.getParent().getItemWithID(idLeft), item);
21//
22// System.err.println("#Current item " + FrameUtils.getCurrentItem());
23// System.err.println("#Current items" + FrameUtils.getCurrentItems());
24
25 MagneticConstraints.Log(this.getClass(), new Item[]{item, item.getParent().getItemWithID(idLeft)},
26 Line.getLineContainingToken(item).toArray(new Item[]{}),
27 "LastItemAction does not move any items around. Only moves the cursor. Left neighbor found; second primary.");
28 return true;
29 } else if (idTop != -1) {
30 moveCursor(item.getParent().getItemWithID(idTop), item);
31 MagneticConstraints.Log(this.getClass(), new Item[]{item, item.getParent().getItemWithID(idTop)},
32 Line.getLineContainingToken(item).toArray(new Item[]{}),
33 "LastItemAction does not move any items around. Only moves the cursor. Top neighbor found; second primary.");
34 return true;
35 } else return false;
36 }
37
38 private boolean moveCursor(final Item toMoveTo, Item toMoveFrom) {
39 if(toMoveTo == null) return false;
40 if(toMoveTo instanceof Text) {
41 //System.err.println("Last item requests move to item with text: " + toMoveTo.getText());
42// final Text asText = (Text) toMoveTo;
43// final java.awt.Point position = toMoveTo.getPosition();
44// DisplayIO.setCursorPosition(position.x + asText.getPixelBoundsUnion().width, position.y, false);
45// FrameGraphics.refresh(false);
46 DisplayController.setTextCursor((Text)toMoveTo, Text.END);
47 if(FrameUtils.getCurrentItem() != toMoveTo) {
48 Line.getLineFromToken(toMoveFrom).deltaX(1);
49 moveCursor(toMoveTo, toMoveFrom);
50 }
51 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false);
52 return true;
53 }
54
55 @Override
56 public boolean invert(Item item) {
57 System.err.println("Last item action does not have a inverted implementation.");
58 return false;
59 }
60}
Note: See TracBrowser for help on using the repository browser.