source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextAction.java@ 963

Last change on this file since 963 was 963, checked in by bln4, 9 years ago
File size: 2.5 KB
Line 
1package org.expeditee.items.MagneticConstraint.Actions;
2
3import java.awt.Point;
4
5import org.expeditee.gui.FrameUtils;
6import org.expeditee.items.Item;
7import org.expeditee.items.MagneticConstraint.MagneticConstraintActionWithArguments;
8import org.expeditee.items.MagneticConstraint.MagneticConstraints;
9import org.expeditee.items.MagneticConstraint.Utilities.BoxLogic;
10import org.expeditee.items.MagneticConstraint.Utilities.Line;
11
12public class RepelTextAction extends
13 MagneticConstraintActionWithArguments<Float> {
14
15 @Override
16 public boolean exec(final Item item) {
17 MagneticConstraints.Log(this.getClass(), new Item[]{item},
18 Line.getLineContainingToken(item).toArray(new Item[]{}),
19 "YOU SHOULD NOT SEE THIS");
20 return exec(item, 0f);
21 }
22
23 @Override
24 public boolean exec(final Item item, final Float... args) {
25 if(item == null || item.getParent() == null || item.getText().startsWith("@") || !isSpIDERCodePage(item.getParent())) {
26 return false;
27 }
28 if(FrameUtils.getCurrentItem() == null) return false;
29 final Point selectedItemPosition = FrameUtils.getCurrentItem().getPosition();
30 if(!selectedItemPosition.equals(item.getPosition())) return false;
31
32 if(item.getMagnetizedItemRight() == -1) {
33 if(BoxLogic.boxCollision(item)) {
34 RepelTextDownAction.MergeSameLineParagraphCollisions = true;
35 final RepelTextDownAction textDownAction = new RepelTextDownAction();
36 textDownAction.setCallbackAction(this.callbackAction);
37 textDownAction.exec(item);
38 RepelTextDownAction.MergeSameLineParagraphCollisions = false;
39 }
40 } else if(item.getParent().getItemWithID(item.getMagnetizedItemRight()) == null) {
41 item.setMagnetizedItemRight(null);
42 return false;
43 } else {
44 final Line tokensToMove = Line.getLineFromToken(item);
45 tokensToMove.removeFirst();
46 tokensToMove.deltaX(args[0].intValue());
47 for(final Item token : tokensToMove) {
48 if(BoxLogic.boxCollision(token)) {
49 RepelTextDownAction.MergeSameLineParagraphCollisions = true;
50 final RepelTextDownAction textDownAction = new RepelTextDownAction();
51 textDownAction.setCallbackAction(this.callbackAction);
52 textDownAction.exec(token);
53 RepelTextDownAction.MergeSameLineParagraphCollisions = false;
54 break;
55 }
56 }
57 }
58
59
60
61
62 callback(item);
63
64 return true;
65 }
66
67 @Override
68 public boolean invert(final Item item) {
69 System.err.println("Repel text action does not have a inverted implementation.");
70 return false;
71 }
72}
Note: See TracBrowser for help on using the repository browser.