source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/DownALineAction.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.3 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 DownALineAction 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 Line currentLine = Line.getLineContainingToken(item);
16 final Item startOfThisLine = currentLine.get(0);
17 final Line nextLine = currentLine.next();
18 if(nextLine == null) return false;
19 final int nextLineLength =
20 nextLine.get(nextLine.size() - 1).getX() + nextLine.get(nextLine.size() - 1).getBoundsWidth() - nextLine.get(0).getX();
21 final int distanceThroughCurrentLine = DisplayController.getMouseX() - startOfThisLine.getX();
22 if(distanceThroughCurrentLine <= nextLineLength) {
23 Item beneith = nextLine.get(0);
24 for(final Item token : nextLine) {
25 if(token.getX() <= item.getX()) beneith = token;
26 else break;
27 }
28 moveCursor(beneith);
29 MagneticConstraints.Log(this.getClass(), new Item[]{item, beneith},
30 Line.getLineContainingToken(item).toArray(new Item[]{}),
31 "DownALineAction does not move any items around. Only moves the cursor. Item to move to detected as second primary.");
32 } else {
33 moveCursor(nextLine.get(nextLine.size() - 1));
34 MagneticConstraints.Log(this.getClass(), new Item[]{item},
35 Line.getLineContainingToken(item).toArray(new Item[]{}),
36 "DownALineAction does not move any items around. Only moves the cursor. Item to move to detected to be end of line below");
37 }
38 return true;
39 }
40
41 private boolean moveCursor(final Item toMoveTo) {
42 if(toMoveTo == null) return false;
43 if(toMoveTo instanceof Text) {
44 final Text asText = (Text) toMoveTo;
45 DisplayController.setTextCursor(asText, Text.END);
46 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false);
47 return true;
48 }
49
50 @Override
51 public boolean invert(final Item item) {
52 System.err.println("Down a line action does not have a inverted implementation.");
53 return false;
54 }
55}
Note: See TracBrowser for help on using the repository browser.