source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/BackspaceAction.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.0 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;
8import org.expeditee.items.MagneticConstraint.Utilities.Paragraph;
9import org.expeditee.items.MagneticConstraint.Utilities.TextLogic;
10
11public class BackspaceAction extends MagneticConstraintAction {
12
13 @Override
14 public boolean exec(final Item item) {
15 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false;
16 if(item == null || ((Text) item).isEmpty()) {
17 final Text temp = DisplayController.getCurrentFrame().createNewText(".");
18 callback(temp);
19 if(temp.getMagnetizedItemLeft() != -1)
20 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemLeft()), Text.END);
21 else if(temp.getMagnetizedItemTop() != -1)
22 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemTop()), Text.END);
23 temp.delete();
24 callback(temp);
25 return true;
26 } else if(item.getMagnetizedItemLeft() != -1 && TextLogic.XIsBeforeCharacters((Text) item, DisplayController.getMouseX())) {
27 new LastItemAction().exec(item);
28 return true;
29 } else if(item.getMagnetizedItemTop() != -1 && TextLogic.XIsBeforeCharacters((Text) item, DisplayController.getMouseX())) {
30 callback(item);
31 final Line currentLine = Line.getLineFromToken(item);
32 final Line lastLine = currentLine.last();
33 if(lastLine != null && Paragraph.getParagraphFromLine(lastLine).contains(currentLine)) {
34 lastLine.appendLine(currentLine);
35 DisplayController.setTextCursor((Text) item, Text.HOME);
36 callback(item);
37 return true;
38 }
39 }
40 return false;
41 }
42
43 @Override
44 public boolean invert(Item item) {
45 System.err.println("Repel text up action does not have a inverted implementation.");
46 return false;
47 }
48}
Note: See TracBrowser for help on using the repository browser.