source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/NextItemAction.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: 1.9 KB
Line 
1package org.expeditee.items.MagneticConstraint.Actions;
2
3import org.expeditee.gui.DisplayController;
4import org.expeditee.items.Item;
5import org.expeditee.items.Text;
6import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
7import org.expeditee.items.MagneticConstraint.MagneticConstraints;
8import org.expeditee.items.MagneticConstraint.Utilities.Line;
9
10public 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 DisplayController.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}
Note: See TracBrowser for help on using the repository browser.