[934] | 1 | package org.expeditee.items.MagneticConstraint.Actions;
|
---|
| 2 |
|
---|
[1102] | 3 | import org.expeditee.core.Point;
|
---|
| 4 | import org.expeditee.gio.EcosystemManager;
|
---|
[962] | 5 | import org.expeditee.gui.FrameUtils;
|
---|
[934] | 6 | import org.expeditee.items.Item;
|
---|
[970] | 7 | import org.expeditee.items.Text;
|
---|
[934] | 8 | import org.expeditee.items.MagneticConstraint.MagneticConstraintActionWithArguments;
|
---|
| 9 | import org.expeditee.items.MagneticConstraint.MagneticConstraints;
|
---|
| 10 | import org.expeditee.items.MagneticConstraint.Utilities.BoxLogic;
|
---|
| 11 | import org.expeditee.items.MagneticConstraint.Utilities.Line;
|
---|
| 12 |
|
---|
| 13 | public class RepelTextAction extends
|
---|
| 14 | MagneticConstraintActionWithArguments<Float> {
|
---|
[974] | 15 | public static boolean Enabled = true;
|
---|
[934] | 16 |
|
---|
| 17 | @Override
|
---|
| 18 | public boolean exec(final Item item) {
|
---|
| 19 | MagneticConstraints.Log(this.getClass(), new Item[]{item},
|
---|
| 20 | Line.getLineContainingToken(item).toArray(new Item[]{}),
|
---|
| 21 | "YOU SHOULD NOT SEE THIS");
|
---|
| 22 | return exec(item, 0f);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | @Override
|
---|
| 26 | public boolean exec(final Item item, final Float... args) {
|
---|
[974] | 27 | if(!Enabled || item == null || item.getParent() == null || item.getText().startsWith("@") || !isSpIDERCodePage(item.getParent())) {
|
---|
[934] | 28 | return false;
|
---|
| 29 | }
|
---|
[962] | 30 | if(FrameUtils.getCurrentItem() == null) return false;
|
---|
| 31 | final Point selectedItemPosition = FrameUtils.getCurrentItem().getPosition();
|
---|
| 32 | if(!selectedItemPosition.equals(item.getPosition())) return false;
|
---|
| 33 |
|
---|
| 34 | if(item.getMagnetizedItemRight() == -1) {
|
---|
[963] | 35 | if(BoxLogic.boxCollision(item)) {
|
---|
| 36 | RepelTextDownAction.MergeSameLineParagraphCollisions = true;
|
---|
| 37 | final RepelTextDownAction textDownAction = new RepelTextDownAction();
|
---|
| 38 | textDownAction.setCallbackAction(this.callbackAction);
|
---|
| 39 | textDownAction.exec(item);
|
---|
| 40 | RepelTextDownAction.MergeSameLineParagraphCollisions = false;
|
---|
| 41 | }
|
---|
[962] | 42 | } else if(item.getParent().getItemWithID(item.getMagnetizedItemRight()) == null) {
|
---|
[934] | 43 | item.setMagnetizedItemRight(null);
|
---|
| 44 | return false;
|
---|
| 45 | } else {
|
---|
[1102] | 46 | final int charDistance = EcosystemManager.getTextLayoutManager().getStringWidth(((Text)item).getFont(), "X");
|
---|
[962] | 47 | final Line tokensToMove = Line.getLineFromToken(item);
|
---|
| 48 | tokensToMove.removeFirst();
|
---|
[970] | 49 | boolean afterGap = false;
|
---|
| 50 | for(int i = 1; i < tokensToMove.size();) {
|
---|
| 51 | if(afterGap) tokensToMove.remove(i);
|
---|
| 52 | else if((tokensToMove.get(i).getX() - charDistance) > (tokensToMove.get(i - 1).getX() + tokensToMove.get(i - 1).getBoundsWidth())) {
|
---|
| 53 | afterGap = true;
|
---|
| 54 | tokensToMove.remove(i);
|
---|
| 55 | } else i++;
|
---|
| 56 | }
|
---|
[962] | 57 | tokensToMove.deltaX(args[0].intValue());
|
---|
| 58 | for(final Item token : tokensToMove) {
|
---|
| 59 | if(BoxLogic.boxCollision(token)) {
|
---|
[963] | 60 | RepelTextDownAction.MergeSameLineParagraphCollisions = true;
|
---|
[962] | 61 | final RepelTextDownAction textDownAction = new RepelTextDownAction();
|
---|
| 62 | textDownAction.setCallbackAction(this.callbackAction);
|
---|
| 63 | textDownAction.exec(token);
|
---|
[963] | 64 | RepelTextDownAction.MergeSameLineParagraphCollisions = false;
|
---|
[962] | 65 | break;
|
---|
[934] | 66 | }
|
---|
[962] | 67 | }
|
---|
[934] | 68 | }
|
---|
[962] | 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | callback(item);
|
---|
| 74 |
|
---|
| 75 | return true;
|
---|
[934] | 76 | }
|
---|
| 77 |
|
---|
| 78 | @Override
|
---|
| 79 | public boolean invert(final Item item) {
|
---|
| 80 | System.err.println("Repel text action does not have a inverted implementation.");
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 | }
|
---|