source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextDownAction.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.8 KB
Line 
1package org.expeditee.items.MagneticConstraint.Actions;
2
3import org.expeditee.core.Point;
4import org.expeditee.gui.DisplayController;
5import org.expeditee.gui.FrameIO;
6import org.expeditee.gui.FrameUtils;
7import org.expeditee.items.Item;
8import org.expeditee.items.Text;
9import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
10import org.expeditee.items.MagneticConstraint.Utilities.Line;
11import org.expeditee.items.MagneticConstraint.Utilities.Paragraph;
12import org.expeditee.items.MagneticConstraint.Utilities.TextLogic;
13
14public class RepelTextDownAction extends MagneticConstraintAction {
15
16 public static boolean MergeSameLineParagraphCollisions = false;
17
18 @Override
19 public boolean exec(final Item item) {
20 if(item == null || item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false;
21 callback(item);
22 //Calculate content that needs to be moved to next line.
23 //1. Get remainder of line
24 final Line remainderOfLine = Line.getLineFromToken(item);
25 //2. Check if the current item should be included; remove it if not.
26 if(remainderOfLine.getFirst().getText().isEmpty() ||
27 (FrameUtils.getCurrentItem().getPosition().equals(item.getPosition())
28 && remainderOfLine.size() > 0
29 && TextLogic.XIsTowardsRight(DisplayController.getMouseX(), (Text) remainderOfLine.getFirst()))) {
30 remainderOfLine.removeFirst();
31 }
32
33 final Line currentLine = Line.getLineContainingToken(item);
34 final Paragraph currentParagraph = Paragraph.getParagraphFromLine(currentLine);
35 final Line nextLine = currentLine.next();
36
37 final Point newLineAt;
38 //Move content contained in 'remainderOfLine'
39
40
41 if(!remainderOfLine.isEmpty() && currentParagraph.contains(nextLine) && MergeSameLineParagraphCollisions) {
42 nextLine.prependLine(remainderOfLine);
43 DisplayController.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);
44 callback(remainderOfLine.getFirst());
45 FrameIO.SaveFrame(remainderOfLine.getLast().getParent());
46 } else if(!remainderOfLine.isEmpty()) {
47 newLineAt = currentParagraph.split(currentLine);
48 final Point first = remainderOfLine.getBoundingBox().getTopLeft();
49 for(final Item token : remainderOfLine) {
50 double newX = token.getX() - first.getX() + newLineAt.getX();
51 token.setPosition((float) newX, (float) newLineAt.getY());
52 }
53 DisplayController.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);
54 callback(remainderOfLine.getFirst());
55 FrameIO.SaveFrame(remainderOfLine.getLast().getParent());
56 }else {
57 //3a No. Move the cursor
58 newLineAt = currentParagraph.split(currentLine);
59 DisplayController.setCursorPosition(newLineAt);
60 }
61
62 return true;
63 }
64
65 @Override
66 public boolean invert(Item item) {
67 System.err.println("Repel text down action does not have a inverted implementation.");
68 return false;
69 }
70
71}
Note: See TracBrowser for help on using the repository browser.