1 | package org.expeditee.items.MagneticConstraint.Actions;
|
---|
2 |
|
---|
3 | import org.expeditee.gui.DisplayController;
|
---|
4 | import org.expeditee.items.Item;
|
---|
5 | import org.expeditee.items.Text;
|
---|
6 | import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
|
---|
7 | import org.expeditee.items.MagneticConstraint.Utilities.Line;
|
---|
8 | import org.expeditee.items.MagneticConstraint.Utilities.Paragraph;
|
---|
9 | import org.expeditee.items.MagneticConstraint.Utilities.TextLogic;
|
---|
10 |
|
---|
11 | public 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 | }
|
---|