source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/UpALineAction.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.8 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.Utilities.Line;
8
9public class UpALineAction extends MagneticConstraintAction {
10
11 @Override
12 public boolean exec(final Item item) {
13 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false;
14 final Line thisLine = Line.getLineContainingToken(item);
15 final Item startOfThisLine = thisLine.get(0);
16 final Item startOfLastLine = thisLine.last().get(0);
17 if(startOfLastLine == null) return false;
18 final Line lastLine = Line.getLineFromToken(startOfLastLine);
19 final int lastLineLength =
20 lastLine.get(lastLine.size() - 1).getX() + lastLine.get(lastLine.size() - 1).getBoundsWidth() - lastLine.get(0).getX();
21 final int distanceThroughCurrentLine = DisplayController.getMouseX() - startOfThisLine.getX();
22 if(distanceThroughCurrentLine <= lastLineLength) {
23 Item above = lastLine.get(0);
24 for(final Item token : lastLine) {
25 if(token.getX() <= item.getX()) above = token;
26 else break;
27 }
28 moveCursor(above);
29 } else {
30 moveCursor(lastLine.get(lastLine.size() - 1));
31 }
32 return true;
33 }
34
35 private boolean moveCursor(final Item toMoveTo) {
36 if(toMoveTo == null) return false;
37 if(toMoveTo instanceof Text) {
38 final Text asText = (Text) toMoveTo;
39 DisplayController.setTextCursor(asText, Text.END);
40 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false);
41 return true;
42 }
43
44 @Override
45 public boolean invert(final Item item) {
46 System.err.println("Up a line action does not have a inverted implementation.");
47 return false;
48 }
49}
Note: See TracBrowser for help on using the repository browser.