1 | package org.expeditee.items.MagneticConstraint.Actions;
|
---|
2 |
|
---|
3 | import org.expeditee.gui.DisplayIO;
|
---|
4 | import org.expeditee.gui.FrameGraphics;
|
---|
5 | import org.expeditee.gui.FrameUtils;
|
---|
6 | import org.expeditee.items.Item;
|
---|
7 | import org.expeditee.items.Text;
|
---|
8 | import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
|
---|
9 | import org.expeditee.items.MagneticConstraint.MagneticConstraints;
|
---|
10 | import org.expeditee.items.MagneticConstraint.Utilities.Line;
|
---|
11 |
|
---|
12 | public 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 | DisplayIO.setTextCursor((Text)toMoveTo, Text.END);
|
---|
47 | if(FrameUtils.getCurrentItem() != toMoveTo) {
|
---|
48 | Line.getLineFromToken(toMoveFrom).deltaX(1);
|
---|
49 | moveCursor(toMoveTo, toMoveFrom);
|
---|
50 | }
|
---|
51 | } else DisplayIO.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 | }
|
---|