1 | package org.expeditee.items.MagneticConstraint.Actions;
|
---|
2 |
|
---|
3 | import org.expeditee.gui.DisplayIO;
|
---|
4 | import org.expeditee.items.Item;
|
---|
5 | import org.expeditee.items.Text;
|
---|
6 | import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
|
---|
7 | import org.expeditee.items.MagneticConstraint.MagneticConstraints;
|
---|
8 | import org.expeditee.items.MagneticConstraint.Utilities.Line;
|
---|
9 |
|
---|
10 | public class NextItemAction extends MagneticConstraintAction {
|
---|
11 |
|
---|
12 | @Override
|
---|
13 | public boolean exec(final Item item) {
|
---|
14 | if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false;
|
---|
15 | final int idRight = item.getMagnetizedItemRight();
|
---|
16 | final int idBottom = item.getMagnetizedItemBottom();
|
---|
17 | if(idRight != -1) {
|
---|
18 | moveCursor(item.getParent().getItemWithID(idRight));
|
---|
19 | MagneticConstraints.Log(this.getClass(), new Item[]{item, item.getParent().getItemWithID(idRight)},
|
---|
20 | Line.getLineContainingToken(item).toArray(new Item[]{}),
|
---|
21 | "NextItemAction does not move any items around. Only moves the cursor. Right neighbor found; second primary.");
|
---|
22 | return true;
|
---|
23 | } else if(idBottom != -1) {
|
---|
24 | moveCursor(item.getParent().getItemWithID(idBottom));
|
---|
25 | MagneticConstraints.Log(this.getClass(), new Item[]{item, item.getParent().getItemWithID(idBottom)},
|
---|
26 | Line.getLineContainingToken(item).toArray(new Item[]{}),
|
---|
27 | "NextItemAction does not move any items around. Only moves the cursor. Bottom neighbor found; second primary.");
|
---|
28 | return true;
|
---|
29 | } else return false;
|
---|
30 | }
|
---|
31 |
|
---|
32 | private boolean moveCursor(final Item toMoveTo) {
|
---|
33 | if (toMoveTo == null)
|
---|
34 | return false;
|
---|
35 | //System.err.println("Next item requests move to item with text: " + toMoveTo.getText());
|
---|
36 | DisplayIO.setTextCursor((Text)toMoveTo, Text.HOME);
|
---|
37 | return true;
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public boolean invert(Item item) {
|
---|
42 | System.err.println("Next item action does not have a inverted implementation.");
|
---|
43 | return false;
|
---|
44 | }
|
---|
45 | }
|
---|