source: trunk/src/org/expeditee/items/MagneticConstraint/Actions/AttractTextAction.java@ 974

Last change on this file since 974 was 974, checked in by bln4, 9 years ago

Publicified one of the formatter strings so we can use it for comparing dates.
Attract and Repel Text can now be turned on and off via a static field

File size: 1.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.Utilities.Line;
9
10public class AttractTextAction extends
11 MagneticConstraintActionWithArguments<Float> {
12
13 public static boolean Enabled = true;
14
15 @Override
16 public boolean exec(Item item) {
17 return exec(item, 0f);
18 }
19
20 @Override
21 public boolean exec(Item item, Float... args) {
22 if(!Enabled || item == null || item.getParent() == null || item.getText().startsWith("@") || !isSpIDERCodePage(item.getParent())) {
23 return false;
24 }
25 if(FrameUtils.getCurrentItem() == null) return false;
26 final Point selectedItemPosition = FrameUtils.getCurrentItem().getPosition();
27 if(!selectedItemPosition.equals(item.getPosition())) return false;
28
29 if(item.getMagnetizedItemRight() == -1) return false;
30 else if(item.getParent().getItemWithID(item.getMagnetizedItemRight()) == null) {
31 item.setMagnetizedItemRight(null);
32 return false;
33 } else {
34 final Item toMyRight = item.getParent().getItemWithID(item.getMagnetizedItemRight());
35 final Line toAttract = Line.getLineFromToken(toMyRight);
36 toAttract.deltaX(-args[0].intValue());
37 return true;
38 }
39 }
40
41 @Override
42 public boolean invert(Item item) {
43 System.err.println("Attract text action does not have a inverted implementation.");
44 return false;
45 }
46
47}
Note: See TracBrowser for help on using the repository browser.