1 | package org.expeditee.items.MagneticConstraint.Actions;
|
---|
2 |
|
---|
3 | import org.expeditee.gui.DisplayIO;
|
---|
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 DeleteAction 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 = DisplayIO.getCurrentFrame().createNewText(".");
|
---|
18 | callback(temp);
|
---|
19 | if(temp.getMagnetizedItemRight() != -1)
|
---|
20 | DisplayIO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemRight()), Text.HOME);
|
---|
21 | else if(temp.getMagnetizedItemBottom() != -1)
|
---|
22 | DisplayIO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemBottom()), Text.HOME);
|
---|
23 | temp.delete();
|
---|
24 | callback(temp);
|
---|
25 | return true;
|
---|
26 | } else if(item.getMagnetizedItemRight() != -1 && TextLogic.XIsAfterCharacters((Text) item, DisplayIO.getMouseX())) {
|
---|
27 | new NextItemAction().exec(item);
|
---|
28 | return true;
|
---|
29 | } else if(item.getMagnetizedItemBottom() != -1 && TextLogic.XIsAfterCharacters((Text) item, DisplayIO.getMouseX())) {
|
---|
30 | callback(item);
|
---|
31 | final Line currentLine = Line.getLineFromToken(item);
|
---|
32 | final Line nextLine = currentLine.next();
|
---|
33 | if(nextLine != null && Paragraph.getParagraphFromLine(currentLine).contains(nextLine)) {
|
---|
34 | currentLine.appendLine(nextLine);
|
---|
35 | DisplayIO.setTextCursor((Text) item, Text.END);
|
---|
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("Delete action does not have a inverted implementation.");
|
---|
46 | return false;
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|