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

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

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