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

Last change on this file since 966 was 966, 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 System.err.println("#Repeling tokens: " + tokensToMove);
46 tokensToMove.removeFirst();
47 tokensToMove.deltaX(args[0].intValue());
48 for(final Item token : tokensToMove) {
49 if(BoxLogic.boxCollision(token)) {
50 RepelTextDownAction.MergeSameLineParagraphCollisions = true;
51 final RepelTextDownAction textDownAction = new RepelTextDownAction();
52 textDownAction.setCallbackAction(this.callbackAction);
53 textDownAction.exec(token);
54 RepelTextDownAction.MergeSameLineParagraphCollisions = false;
55 break;
56 }
57 }
58 }
59
60
61
62
63 callback(item);
64
65 return true;
66 }
67
68 @Override
69 public boolean invert(final Item item) {
70 System.err.println("Repel text action does not have a inverted implementation.");
71 return false;
72 }
73}
Note: See TracBrowser for help on using the repository browser.