source: trunk/src/org/expeditee/items/MagneticConstraint/MagneticConstraints.java@ 906

Last change on this file since 906 was 906, checked in by bln4, 10 years ago

Added Magnetic Constraints

Magnetic Constraints are a new type of constraint between items; particularly text. Items can have their neighbours set (for example: who is to my right) and then have custom actions run when a item and its neighbour interact in a defined way. For example: one text item grows enough for hits its right neighbour; so its right neighbour moves over to compensate.
Files changed: org.expeditee.{ gui.DisplayIO, io.DefaultFrameReader, io.DefaultFrameWriter, items.Item, items.Text }

Added ability to have 'delayed' properties on items. With the invention of Magnetic Constraints it was found that the saving and loading of properties now required (greatly benifited from) a way to set a property after all items have been loaded in; rather than as the perticular item was being loaded in. This is that ability.

Files changed: org.expeditee.io.{ DefaultFrameReader, ExpReader }

Let through some non letter characters as names of properties. The tokens ',', '', and '_' have been used as property names to describe neighbors. In order to do this the isValidLine(String) method was altered to let these through. This is not the ideal solution, and should be looked at later.

Files changed: org.expeditee.io.ExpReader

Bug fix: setting a custom title support was added previously. If a custom title had been set the title was: [Your Custom Title] ~ [Expeditee Title]. However the tildas where showing up even without a custom title set. This is now fixed.

File size: 2.4 KB
Line 
1package org.expeditee.items.MagneticConstraint;
2
3import org.expeditee.items.Item;
4
5public class MagneticConstraints {
6 private static MagneticConstraints instance = null;
7
8 private MagneticConstraintAction rightBorderHitAction = null;
9 private MagneticConstraintAction endOfLineHitAction = null;
10 private MagneticConstraintAction leftBorderHitAction = null;
11 private MagneticConstraintAction startOfLineHitAction = null;
12 private MagneticConstraintActionWithArguments<Float> textShrunkAction = null;
13 private MagneticConstraintActionWithArguments<Float> textGrownAction = null;
14
15 public static MagneticConstraints getInstance() {
16 if (instance == null) {
17 instance = new MagneticConstraints();
18 return instance;
19 } else
20 return instance;
21 }
22
23 public boolean rightBorderHit(final Item item) {
24 if (rightBorderHitAction != null)
25 return rightBorderHitAction.exec(item);
26 else
27 return false;
28 }
29
30 public void setRightBorderHitAction(final MagneticConstraintAction action) {
31 rightBorderHitAction = action;
32 }
33
34 public boolean endOfLineHit(final Item item) {
35 if (endOfLineHitAction != null)
36 return endOfLineHitAction.exec(item);
37 else
38 return false;
39 }
40
41 public void setEndOfLineHitAction(final MagneticConstraintAction action) {
42 endOfLineHitAction = action;
43 }
44
45 public boolean leftBorderHit(final Item item) {
46 if (leftBorderHitAction != null)
47 return leftBorderHitAction.exec(item);
48 else
49 return false;
50 }
51
52 public void setLeftBorderHitAction(final MagneticConstraintAction action) {
53 leftBorderHitAction = action;
54 }
55
56 public boolean startOfLineHit(final Item item) {
57 if (startOfLineHitAction != null)
58 return startOfLineHitAction.exec(item);
59 else
60 return false;
61 }
62
63 public void setStartOfLineHitAction(final MagneticConstraintAction action) {
64 startOfLineHitAction = action;
65 }
66
67 public boolean textShrunk(final Item item, final float delta) {
68 if(textShrunkAction != null)
69 return textShrunkAction.exec(item, delta);
70 else return false;
71 }
72
73 public void setTextShrunkAction(final MagneticConstraintActionWithArguments<Float> action) {
74 textShrunkAction = action;
75 }
76
77 public boolean textGrown(final Item item, final float delta) {
78 if(textGrownAction != null)
79 return textGrownAction.exec(item, delta);
80 else return false;
81 }
82
83 public void setTextGrownAction(final MagneticConstraintActionWithArguments<Float> action) {
84 textGrownAction = action;
85 }
86}
Note: See TracBrowser for help on using the repository browser.