[archstudio-commits] svn commit: r7101 - /archstudio4/trunk/edu.uci.isr.archstudio4/src/edu/uci/isr/archstudio4/comp/archipelago/generic/logics/hints/ /bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/ /bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchronizers/ /utils/trunk/edu.uci.isr.sysutils/src/edu/uci/isr/sysutils/

archstudio-commits-owner at uci.edu archstudio-commits-owner at uci.edu
Wed May 7 16:05:46 PDT 2008


Author: shendric
Date: Wed May  7 16:05:46 2008
New Revision: 7101

Log:
Work towards addressing a hint bug when an imported architecture has absolu=
te but not relative hints

Added:
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/PointHintSynchronizer.java   (contents, props changed)
      - copied, changed from r7088, bna4/trunk/edu.uci.isr.bna4/src/edu/uci=
/isr/bna4/logics/hints/synchronizers/StuckPointHintSynchronizer.java
Removed:
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/MoveWithPointHintSynchronizer.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/StuckPointHintSynchronizer.java
Modified:
    archstudio4/trunk/edu.uci.isr.archstudio4/src/edu/uci/isr/archstudio4/c=
omp/archipelago/generic/logics/hints/XAdlHintRepository.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/IHintRepo=
sitory.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/Synchroni=
zeHintsLogic.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/AbstractHintSynchronizer.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/BooleanHintSynchronizer.java
    bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/PropertyHintSynchronizer.java
    utils/trunk/edu.uci.isr.sysutils/src/edu/uci/isr/sysutils/SystemUtils.j=
ava

Modified: archstudio4/trunk/edu.uci.isr.archstudio4/src/edu/uci/isr/archstu=
dio4/comp/archipelago/generic/logics/hints/XAdlHintRepository.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- archstudio4/trunk/edu.uci.isr.archstudio4/src/edu/uci/isr/archstudio4/c=
omp/archipelago/generic/logics/hints/XAdlHintRepository.java (original)
+++ archstudio4/trunk/edu.uci.isr.archstudio4/src/edu/uci/isr/archstudio4/c=
omp/archipelago/generic/logics/hints/XAdlHintRepository.java Wed May  7 16:=
05:46 2008
@@ -32,7 +32,7 @@
 import edu.uci.isr.xarchflat.utils.XArchRelativePathTracker;
 =

 public class XAdlHintRepository
-    implements IHintRepository, XArchFlatListener{
+	implements IHintRepository, XArchFlatListener{
 =

 	private static final boolean DEBUG =3D false;
 =

@@ -270,32 +270,23 @@
 		}
 	}
 =

-	private ObjRef getPropertyRef(String id, String[] names, boolean create){
+	private ObjRef getPropertyRef(String id, String name, boolean create){
 		synchronized(hintedElementRefNameToPropertyRefs){
 			ObjRef hintedElementRef =3D getHintedElementRef(id, create);
 			if(hintedElementRef !=3D null){
-				Tuple key =3D new Tuple(hintedElementRef, names[0]);
+
+				//TODO: remove following line once synchronous flat listeners are enab=
led
+				propertyRefTracker.rescan(hintedElementRef);
+
+				Tuple key =3D new Tuple(hintedElementRef, name);
 				ObjRef propertyRef =3D hintedElementRefNameToPropertyRefs.get(key);
 				if(propertyRef !=3D null && xarch.hasAncestor(propertyRef, propertyRef=
Tracker.getRootObjRef())){
 					return propertyRef;
 				}
 =

-				/*
-				 * We check for new values since we may not have gotten the flat
-				 * event yet that would inform us that the property is
-				 * available.
-				 */
-				propertyRefTracker.rescan(hintedElementRef);
-				for(String name: names){
-					propertyRef =3D hintedElementRefNameToPropertyRefs.get(new Tuple(hint=
edElementRef, name));
-					if(propertyRef !=3D null && xarch.hasAncestor(propertyRef, propertyRe=
fTracker.getRootObjRef())){
-						return propertyRef;
-					}
-				}
-
 				if(create){
 					propertyRef =3D xarch.create(hintsContextRef, "Property");
-					xarch.set(propertyRef, "name", names[0]);
+					xarch.set(propertyRef, "name", name);
 					hintedElementRefNameToPropertyRefs.put(key, propertyRef);
 					xarch.add(hintedElementRef, "property", propertyRef);
 					return propertyRef;
@@ -305,7 +296,7 @@
 		}
 	}
 =

-	private Object getValue(String xArchID, String[] name) throws PropertyDec=
odeException{
+	private Object getValue(String xArchID, String name) throws PropertyDecod=
eException{
 		ObjRef propertyRef =3D getPropertyRef(xArchID, name, false);
 		if(propertyRef !=3D null){
 			ObjRef valueRef =3D (ObjRef)xarch.get(propertyRef, "value");
@@ -319,7 +310,7 @@
 	}
 =

 	private boolean setValue(String xArchID, String name, Object value){
-		ObjRef propertyRef =3D getPropertyRef(xArchID, new String[]{name}, true);
+		ObjRef propertyRef =3D getPropertyRef(xArchID, name, true);
 		if(propertyRef !=3D null){
 			ObjRef valueRef =3D (ObjRef)xarch.get(propertyRef, "value");
 			if(valueRef =3D=3D null){
@@ -373,10 +364,9 @@
 		return hintNames.toArray(new String[hintNames.size()]);
 	}
 =

-	@SuppressWarnings("unchecked")
-	public synchronized <T>T getHint(Object xArchID, String... hintName){
+	public synchronized Object getHint(Object xArchID, String hintName){
 		try{
-			return (T)getValue((String)xArchID, hintName);
+			return getValue((String)xArchID, hintName);
 		}
 		catch(PropertyDecodeException e){
 			e.printStackTrace();

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/IHi=
ntRepository.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/IHintRepo=
sitory.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/IHintRepo=
sitory.java Wed May  7 16:05:46 2008
@@ -13,7 +13,7 @@
 =

 	public void storeHint(Object context, String hintName, Object hintValue);
 =

-	public <T>T getHint(Object context, String... hintName);
+	public Object getHint(Object context, String hintName);
 =

 	public void addHintRepositoryChangeListener(IHintRepositoryChangeListener=
 l);
 =


Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/Syn=
chronizeHintsLogic.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/Synchroni=
zeHintsLogic.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/Synchroni=
zeHintsLogic.java Wed May  7 16:05:46 2008
@@ -31,9 +31,8 @@
 import edu.uci.isr.bna4.facets.IRelativeMovable;
 import edu.uci.isr.bna4.logics.coordinating.MaintainTagsLogic;
 import edu.uci.isr.bna4.logics.hints.synchronizers.BooleanHintSynchronizer;
-import edu.uci.isr.bna4.logics.hints.synchronizers.MoveWithPointHintSynchr=
onizer;
+import edu.uci.isr.bna4.logics.hints.synchronizers.PointHintSynchronizer;
 import edu.uci.isr.bna4.logics.hints.synchronizers.PropertyHintSynchronize=
r;
-import edu.uci.isr.bna4.logics.hints.synchronizers.StuckPointHintSynchroni=
zer;
 import edu.uci.isr.sysutils.HashBag;
 import edu.uci.isr.sysutils.ListenerList;
 import edu.uci.isr.sysutils.Tuple;
@@ -125,9 +124,9 @@
 		addHintSynchronizer(new PropertyHintSynchronizer(IHasMutableAngle.class,=
 IHasMutableAngle.ANGLE_PROPERTY_NAME, IHasMutableAngle.USER_MAY_CHANGE_ANG=
LE));
 		addHintSynchronizer(new PropertyHintSynchronizer(IHasMutableMidpoints.cl=
ass, IHasMutableMidpoints.MIDPOINTS_PROPERTY_NAME, IHasMutableMidpoints.USE=
R_MAY_MOVE_MIDPOINTS));
 		addHintSynchronizer(new BooleanHintSynchronizer(IThing.class, MaintainTa=
gsLogic.SHOW_TAG_PROPERTY_NAME, MaintainTagsLogic.USER_MAY_SHOW_TAG));
-		addHintSynchronizer(new StuckPointHintSynchronizer(IHasMutableEndpoints.=
class, IHasMutableEndpoints.ENDPOINT_1_PROPERTY_NAME, IHasMutableEndpoints.=
USER_MAY_MOVE_ENDPOINT1).addOldStuckHintName("endpoint1FractionOffset", "gl=
ass").addOldHintName("endpoint1", "glass"));
-		addHintSynchronizer(new StuckPointHintSynchronizer(IHasMutableEndpoints.=
class, IHasMutableEndpoints.ENDPOINT_2_PROPERTY_NAME, IHasMutableEndpoints.=
USER_MAY_MOVE_ENDPOINT2).addOldStuckHintName("endpoint2FractionOffset", "gl=
ass").addOldHintName("endpoint2", "glass"));
-		addHintSynchronizer(new MoveWithPointHintSynchronizer(IHasMutableAnchorP=
oint.class, IHasMutableAnchorPoint.ANCHOR_POINT_PROPERTY_NAME, IRelativeMov=
able.USER_MAY_MOVE).addOldStuckHintName("glassAnchorFractionOffset", "glass=
").addOldHintName("glassAnchorPoint", "glass"));
+		addHintSynchronizer(new PointHintSynchronizer(IHasMutableEndpoints.class=
, IHasMutableEndpoints.ENDPOINT_1_PROPERTY_NAME, IHasMutableEndpoints.USER_=
MAY_MOVE_ENDPOINT1).addOldStuckHintName("endpoint1FractionOffset", "glass")=
.addOldHintName("endpoint1", "glass"));
+		addHintSynchronizer(new PointHintSynchronizer(IHasMutableEndpoints.class=
, IHasMutableEndpoints.ENDPOINT_2_PROPERTY_NAME, IHasMutableEndpoints.USER_=
MAY_MOVE_ENDPOINT2).addOldStuckHintName("endpoint2FractionOffset", "glass")=
.addOldHintName("endpoint2", "glass"));
+		addHintSynchronizer(new PointHintSynchronizer(IHasMutableAnchorPoint.cla=
ss, IHasMutableAnchorPoint.ANCHOR_POINT_PROPERTY_NAME, IRelativeMovable.USE=
R_MAY_MOVE).addOldStuckHintName("glassAnchorFractionOffset", "glass").addOl=
dHintName("glassAnchorPoint", "glass"));
 	}
 =

 	final protected ListenerList<IHintSynchronizer> hintSynchronizers =3D new=
 ListenerList<IHintSynchronizer>(IHintSynchronizer.class);

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/syn=
chronizers/AbstractHintSynchronizer.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/AbstractHintSynchronizer.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/AbstractHintSynchronizer.java Wed May  7 16:05:46 2008
@@ -1,5 +1,6 @@
 package edu.uci.isr.bna4.logics.hints.synchronizers;
 =

+import java.util.List;
 import java.util.regex.Pattern;
 =

 import edu.uci.isr.bna4.IBNAWorld;
@@ -37,19 +38,25 @@
 		return null;
 	}
 =

-	protected boolean restoreHint(IHintRepository repository, Object context,=
 String partPath, String[] parts, IThing thing, Object propertyName, Object=
 value){
-		if(value !=3D null){
-			thing.setProperty(propertyName, value);
-			return true;
+	protected final Object getFirstHint(IHintRepository repository, Object co=
ntext, List<String> hintNames){
+		for(String hintName: hintNames){
+			Object hintValue =3D repository.getHint(context, hintName);
+			if(hintValue !=3D null){
+				return hintValue;
+			}
+		}
+		return null;
+	}
+
+	protected void restoreHint(IHintRepository repository, Object context, St=
ring partPath, String[] parts, IThing thing, Object propertyName, String hi=
ntName, Object hintValue){
+		if(hintValue !=3D null){
+			thing.setProperty(propertyName, hintValue);
 		}
-		return false;
 	}
 =

-	protected boolean storeHint(IHintRepository repository, Object context, S=
tring hintName, IThing thing, Object propertyName, Object value){
+	protected void storeHint(IHintRepository repository, Object context, Stri=
ng hintName, IThing thing, Object propertyName, Object value){
 		if(value !=3D null){
 			repository.storeHint(context, hintName, value);
-			return true;
 		}
-		return false;
 	}
 }

Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/syn=
chronizers/BooleanHintSynchronizer.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/BooleanHintSynchronizer.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/BooleanHintSynchronizer.java Wed May  7 16:05:46 2008
@@ -15,15 +15,14 @@
 	}
 =

 	@Override
-	protected boolean storeHint(IHintRepository repository, Object context, S=
tring hintName, IThing thing, Object propertyName, Object value){
+	protected void storeHint(IHintRepository repository, Object context, Stri=
ng hintName, IThing thing, Object propertyName, Object value){
 		if(Boolean.TRUE.equals(value) ^ Boolean.TRUE.equals(repository.getHint(c=
ontext, hintName))){
-			return super.storeHint(repository, context, hintName, thing, propertyNa=
me, Boolean.TRUE.equals(value));
+			super.storeHint(repository, context, hintName, thing, propertyName, Boo=
lean.TRUE.equals(value));
 		}
-		return true;
 	}
 =

 	@Override
-	protected boolean restoreHint(IHintRepository repository, Object context,=
 String partPath, String[] parts, IThing thing, Object propertyName, Object=
 value){
-		return super.restoreHint(repository, context, partPath, parts, thing, pr=
opertyName, Boolean.TRUE.equals(value));
+	protected void restoreHint(IHintRepository repository, Object context, St=
ring partPath, String[] parts, IThing thing, Object propertyName, String hi=
ntName, Object hintValue){
+		super.restoreHint(repository, context, partPath, parts, thing, propertyN=
ame, hintName, Boolean.TRUE.equals(hintValue));
 	}
 }

Copied: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synch=
ronizers/PointHintSynchronizer.java (from r7088, bna4/trunk/edu.uci.isr.bna=
4/src/edu/uci/isr/bna4/logics/hints/synchronizers/StuckPointHintSynchronize=
r.java)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/StuckPointHintSynchronizer.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/PointHintSynchronizer.java Wed May  7 16:05:46 2008
@@ -1,27 +1,28 @@
 package edu.uci.isr.bna4.logics.hints.synchronizers;
 =

 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.locks.Lock;
 =

 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 =

 import edu.uci.isr.bna4.IThing;
-import edu.uci.isr.bna4.assemblies.IAssembly;
+import edu.uci.isr.bna4.facets.IHasAnchorPoint;
 import edu.uci.isr.bna4.facets.IHasBoundingBox;
 import edu.uci.isr.bna4.logics.coordinating.MaintainStickyPointLogic;
+import edu.uci.isr.bna4.logics.coordinating.MoveWithLogic;
 import edu.uci.isr.bna4.logics.coordinating.MaintainStickyPointLogic.Stick=
yMode;
 import edu.uci.isr.bna4.logics.hints.IHintRepository;
+import edu.uci.isr.sysutils.SystemUtils;
 =

-public class StuckPointHintSynchronizer
+public class PointHintSynchronizer
 	extends PropertyHintSynchronizer{
 =

 	private static final String STUCK_INFO_HINT_SUFFIX =3D "-StuckInfo";
+	private static final String MOVE_WITH_INFO_HINT_SUFFIX =3D "-MoveWithInfo=
";
 =

-	protected static float[] getFractionOffset(Rectangle r, Point p){
+	protected static float[] getFractionOffsets(Rectangle r, Point p){
 		assert r !=3D null;
 		assert p !=3D null;
 =

@@ -44,37 +45,42 @@
 	protected final String stuckInfoHintSuffix;
 	protected final int stuckInfoHintSuffixLength;
 	protected final List<String> oldStuckHintNames =3D new ArrayList<String>(=
);
-	protected final Map<String, String> oldStuckHintNamesMap =3D new HashMap<=
String, String>();
 =

-	public StuckPointHintSynchronizer(String hintSuffix, Class<? extends IThi=
ng> thingInterface, String propertyName, String... userProperties){
+	protected final Object moveWithThingIdPropertyName;
+	protected final String moveWithInfoHintSuffix;
+	protected final int moveWithInfoHintSuffixLength;
+	protected final List<String> oldMovesWithHintNames =3D new ArrayList<Stri=
ng>();
+
+	public PointHintSynchronizer(String hintSuffix, Class<? extends IThing> t=
hingInterface, String propertyName, String... userProperties){
 		super(hintSuffix, thingInterface, propertyName, userProperties);
+
 		this.stuckToThingIdPropertyName =3D MaintainStickyPointLogic.getReferenc=
eName(propertyName);
 		this.stickyModePropertyName =3D MaintainStickyPointLogic.getStickyModeNa=
me(propertyName);
 		this.stuckInfoHintSuffix =3D this.hintSuffix + STUCK_INFO_HINT_SUFFIX;
 		this.stuckInfoHintSuffixLength =3D stuckInfoHintSuffix.length();
+
+		this.moveWithThingIdPropertyName =3D MoveWithLogic.MOVES_WITH_THING_ID_P=
ROPERTY_NAME;
+		this.moveWithInfoHintSuffix =3D this.hintSuffix + MOVE_WITH_INFO_HINT_SU=
FFIX;
+		this.moveWithInfoHintSuffixLength =3D moveWithInfoHintSuffix.length();
 	}
 =

-	public StuckPointHintSynchronizer(Class<? extends IThing> thingInterface,=
 String propertyName, String... userProperties){
+	public PointHintSynchronizer(Class<? extends IThing> thingInterface, Stri=
ng propertyName, String... userProperties){
 		this(null, thingInterface, propertyName, userProperties);
 	}
 =

-	public PropertyHintSynchronizer addOldStuckHintName(String oldStuckHintNa=
me, String oldStuckHintPath){
+	public PointHintSynchronizer addOldStuckHintName(String oldStuckHintName,=
 String oldStuckHintPath){
 		this.oldStuckHintNames.add(oldStuckHintName);
-		this.oldStuckHintNamesMap.put(oldStuckHintName, oldStuckHintPath + stuck=
InfoHintSuffix);
+		this.oldHintNamesMap.put(oldStuckHintName, oldStuckHintPath + stuckInfoH=
intSuffix);
 		return this;
 	}
 =

-	@Override
-	protected void filteredRestoreHints(IHintRepository repository, Object co=
ntext, String partPath, String[] parts, IThing thing){
-		List<String> allStuckHintNames =3D new ArrayList<String>(oldStuckHintNam=
es.size() + 1);
-		allStuckHintNames.add(partPath + stuckInfoHintSuffix);
-		allStuckHintNames.addAll(oldStuckHintNames);
-		if(!restoreHint(repository, context, partPath, parts, thing, propertyNam=
e, repository.getHint(context, allStuckHintNames.toArray(new String[allStuc=
kHintNames.size()])))){
-			super.filteredRestoreHints(repository, context, partPath, parts, thing);
-		}
+	public PointHintSynchronizer addOldMovesWithHintName(String oldMovesWithH=
intName, String oldMovesWithHintPath){
+		this.oldMovesWithHintNames.add(oldMovesWithHintName);
+		this.oldHintNamesMap.put(oldMovesWithHintName, oldMovesWithHintPath + st=
uckInfoHintSuffix);
+		return this;
 	}
 =

-	protected Object cleanupHint(Object value){
+	protected Object cleanupStuckInfoHint(Object value){
 		/*
 		 * This translates old forms of the stuck info hint to the current form
 		 */
@@ -106,17 +112,55 @@
 		return value;
 	}
 =

+	protected List<String> getStuckInfoHintNames(IHintRepository repository, =
Object context, String partPath, String[] parts, IThing thing){
+		List<String> hintNames =3D new ArrayList<String>();
+		hintNames.add(partPath + stuckInfoHintSuffix);
+		hintNames.addAll(oldStuckHintNames);
+		return hintNames;
+	}
+
+	protected List<String> getMovesWithHintNames(IHintRepository repository, =
Object context, String partPath, String[] parts, IThing thing){
+		List<String> hintNames =3D new ArrayList<String>();
+		hintNames.add(partPath + moveWithInfoHintSuffix);
+		hintNames.addAll(oldMovesWithHintNames);
+		return hintNames;
+	}
+
+	@Override
+	protected List<String> getHintNames(IHintRepository repository, Object co=
ntext, String partPath, String[] parts, IThing thing){
+		List<String> hintNames =3D new ArrayList<String>();
+		if(thing.getProperty(stuckToThingIdPropertyName) !=3D null){
+			hintNames.addAll(getStuckInfoHintNames(repository, context, partPath, p=
arts, thing));
+		}
+		else if(thing.getProperty(moveWithThingIdPropertyName) !=3D null){
+			hintNames.addAll(getMovesWithHintNames(repository, context, partPath, p=
arts, thing));
+		}
+		hintNames.addAll(super.getHintNames(repository, context, partPath, parts=
, thing));
+		return hintNames;
+	}
+
 	@Override
-	protected boolean restoreHint(IHintRepository repository, Object context,=
 String partPath, String[] parts, IThing thing, Object propertyName, Object=
 value){
-		if(value !=3D null){
+	protected String getPartPath(String hintName){
+		if(hintName.endsWith(stuckInfoHintSuffix)){
+			return hintName.substring(0, hintName.length() - stuckInfoHintSuffixLen=
gth);
+		}
+		if(hintName.endsWith(moveWithInfoHintSuffix)){
+			return hintName.substring(0, hintName.length() - moveWithInfoHintSuffix=
Length);
+		}
+		return super.getPartPath(hintName);
+	}
+
+	@Override
+	protected void restoreHint(IHintRepository repository, Object context, St=
ring partPath, String[] parts, IThing thing, Object propertyName, String hi=
ntName, Object hintValue){
+		if(hintName.endsWith(stuckInfoHintSuffix)){
 			IThing stickyThing =3D world.getBNAModel().getThing((String)thing.getPr=
operty(stuckToThingIdPropertyName));
 			if(stickyThing !=3D null){
 				Lock lock =3D thing.getPropertyLock();
 				lock.lock();
 				try{
-					value =3D cleanupHint(value);
-					if(value instanceof Object[]){
-						Object[] v =3D (Object[])value;
+					hintValue =3D cleanupStuckInfoHint(hintValue);
+					if(hintValue instanceof Object[]){
+						Object[] v =3D (Object[])hintValue;
 						if(v.length >=3D 1 && v[0] instanceof StickyMode){
 							// hint is: Object[]{ StickyMode, ... ? }
 							StickyMode sm =3D (StickyMode)v[0];
@@ -146,57 +190,67 @@
 				finally{
 					lock.unlock();
 				}
-				return true;
-			}
-			else if(value instanceof Point){
-				return super.restoreHint(repository, context, partPath, parts, thing, =
propertyName, value);
 			}
+			return;
 		}
-		return false;
-	}
-
-	@Override
-	public void repositoryChanged(IHintRepository repository, Object context,=
 IAssembly[] assemblies, String hintName){
-		if(hintName.endsWith(stuckInfoHintSuffix)){
-			filteredRepositoryChanged(repository, context, assemblies, hintName.sub=
string(0, hintName.length() - stuckInfoHintSuffixLength), hintName);
+		else if(hintName.endsWith(moveWithInfoHintSuffix)){
+			IThing moveWithThing =3D world.getBNAModel().getThing((String)thing.get=
Property(moveWithThingIdPropertyName));
+			if(moveWithThing !=3D null){
+				Lock lock =3D thing.getPropertyLock();
+				lock.lock();
+				try{
+					if(hintValue instanceof Object[]){
+						Object[] v =3D (Object[])hintValue;
+						if(v.length >=3D 1 && v[0] instanceof Point){
+							// hint is: Object[]{ Point, ... ? }
+							Point op =3D (Point)v[0];
+							Point np =3D null;
+							if(moveWithThing instanceof IHasAnchorPoint){
+								Point ap =3D ((IHasAnchorPoint)moveWithThing).getAnchorPoint();
+								np =3D new Point(ap.x + op.x, ap.y + op.y);
+							}
+							else if(moveWithThing instanceof IHasBoundingBox){
+								Rectangle r =3D ((IHasBoundingBox)moveWithThing).getBoundingBox();
+								Point ap =3D new Point(r.x + r.width / 2, r.y + r.height / 2);
+								np =3D new Point(ap.x + op.x, ap.y + op.y);
+							}
+							if(np !=3D null){
+								thing.setProperty(this.propertyName, np);
+							}
+						}
+					}
+				}
+				finally{
+					lock.unlock();
+				}
+			}
+			return;
 		}
 		else{
-			super.repositoryChanged(repository, context, assemblies, hintName);
+			super.restoreHint(repository, context, partPath, parts, thing, property=
Name, hintName, hintValue);
 		}
 	}
 =

 	@Override
 	public void filteredThingChanged(IHintRepository repository, Object conte=
xt, String partPath, String[] parts, IThing thing, Object propertyName, Obj=
ect oldValue, Object newValue){
-		if(stuckToThingIdPropertyName.equals(propertyName)){
-			// the thing has been stuck to something else, restore the stuck info
-			IThing stuckThing =3D world.getBNAModel().getThing((String)thing.getPro=
perty(stuckToThingIdPropertyName));
-			if(stuckThing !=3D null){
-				filteredRestoreHints(repository, context, partPath, parts, thing);
+		try{
+			if(stuckToThingIdPropertyName.equals(propertyName)){
+				// the thing has been stuck to something else, restore the stuck info
+				IThing stuckThing =3D world.getBNAModel().getThing((String)thing.getPr=
operty(stuckToThingIdPropertyName));
+				if(stuckThing !=3D null){
+					filteredRestoreHints(repository, context, partPath, parts, thing);
+				}
+				return;
 			}
-		}
-		else if(this.propertyName.equals(propertyName) || stickyModePropertyName=
.equals(propertyName)){
-			// the thing point has been changed or the sticky mode has changed, upd=
ate the hint
 			IThing stickyThing =3D world.getBNAModel().getThing((String)thing.getPr=
operty(stuckToThingIdPropertyName));
-			if(stickyThing !=3D null){
-				// only update the hint if it differs from what's already stored
-				List<String> allStuckHintNames =3D new ArrayList<String>(oldStuckHintN=
ames.size() + 1);
-				allStuckHintNames.add(partPath + stuckInfoHintSuffix);
-				allStuckHintNames.addAll(oldStuckHintNames);
-				Object oldHint =3D cleanupHint(repository.getHint(context, allStuckHin=
tNames.toArray(new String[allStuckHintNames.size()])));
+			if(stickyThing !=3D null && (this.propertyName.equals(propertyName) || =
stickyModePropertyName.equals(propertyName))){
+				Object oldHint =3D cleanupStuckInfoHint(getFirstHint(repository, conte=
xt, getStuckInfoHintNames(repository, context, partPath, parts, thing)));
 				Object newHint =3D null;
 =

 				StickyMode s =3D thing.getProperty(stickyModePropertyName);
 				switch(s){
 				case CENTER:
 				case EDGE_FROM_CENTER:
-					if(oldHint instanceof Object[]){
-						Object[] v =3D (Object[])oldHint;
-						if(v.length >=3D 1 && v[0] instanceof StickyMode){
-							if(s.equals(v[0])){
-								return;
-							}
-						}
-					}
 					newHint =3D new Object[]{s};
 					break;
 =

@@ -204,6 +258,7 @@
 					if(stickyThing instanceof IHasBoundingBox){
 						Rectangle r =3D ((IHasBoundingBox)stickyThing).getBoundingBox();
 						Point p =3D thing.getProperty(this.propertyName);
+						newHint =3D new Object[]{s, getFractionOffsets(r, p)};
 						if(oldHint instanceof Object[]){
 							Object[] v =3D (Object[])oldHint;
 							if(v.length >=3D 2 && v[0] instanceof StickyMode){
@@ -213,21 +268,53 @@
 										// only update the hint if it produces a change in the resulting=
 point
 										Point np =3D getPoint(r, f);
 										if(p.equals(np)){
-											return;
+											newHint =3D null;
 										}
 									}
 								}
 							}
 						}
-						newHint =3D new Object[]{s, getFractionOffset(r, p)};
 					}
 				}
 =

-				if(newHint !=3D null){
+				if(newHint !=3D null && !SystemUtils.deepEquals(oldHint, newHint)){
 					repository.storeHint(context, partPath + stuckInfoHintSuffix, newHint=
);
 				}
 			}
+
+			if(moveWithThingIdPropertyName.equals(propertyName)){
+				// the thing has been moved to something else, restore the moveWith in=
fo
+				IThing moveWithThing =3D world.getBNAModel().getThing((String)thing.ge=
tProperty(moveWithThingIdPropertyName));
+				if(moveWithThing !=3D null){
+					filteredRestoreHints(repository, context, partPath, parts, thing);
+				}
+				return;
+			}
+			IThing moveWithThing =3D world.getBNAModel().getThing((String)thing.get=
Property(moveWithThingIdPropertyName));
+			if(moveWithThing !=3D null && this.propertyName.equals(propertyName)){
+				Object oldHint =3D repository.getHint(context, partPath + moveWithInfo=
HintSuffix);
+				Object newHint =3D null;
+
+				if(moveWithThing instanceof IHasAnchorPoint){
+					Point ap =3D ((IHasAnchorPoint)moveWithThing).getAnchorPoint();
+					Point op =3D thing.getProperty(this.propertyName);
+					newHint =3D new Object[]{new Point(op.x - ap.x, op.y - ap.y)};
+				}
+				else if(moveWithThing instanceof IHasBoundingBox){
+					Rectangle r =3D ((IHasBoundingBox)moveWithThing).getBoundingBox();
+					Point ap =3D new Point(r.x + r.width / 2, r.y + r.height / 2);
+					Point op =3D thing.getProperty(this.propertyName);
+					newHint =3D new Object[]{new Point(op.x - ap.x, op.y - ap.y)};
+				}
+
+				if(newHint !=3D null && !SystemUtils.deepEquals(oldHint, newHint)){
+					repository.storeHint(context, partPath + moveWithInfoHintSuffix, newH=
int);
+				}
+			}
+		}
+		finally{
+			// we still want to store the absolute position =

+			super.filteredThingChanged(repository, context, partPath, parts, thing,=
 propertyName, oldValue, newValue);
 		}
-		super.filteredThingChanged(repository, context, partPath, parts, thing, =
propertyName, oldValue, newValue);
 	}
 }

Propchange: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/s=
ynchronizers/PointHintSynchronizer.java
---------------------------------------------------------------------------=
---
    svn:mergeinfo =3D =


Modified: bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/syn=
chronizers/PropertyHintSynchronizer.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/PropertyHintSynchronizer.java (original)
+++ bna4/trunk/edu.uci.isr.bna4/src/edu/uci/isr/bna4/logics/hints/synchroni=
zers/PropertyHintSynchronizer.java Wed May  7 16:05:46 2008
@@ -39,11 +39,28 @@
 		return this;
 	}
 =

+	protected List<String> getHintNames(IHintRepository repository, Object co=
ntext, String partPath, String[] parts, IThing thing){
+		List<String> hintNames =3D new ArrayList<String>();
+		hintNames.add(partPath + hintSuffix);
+		hintNames.addAll(oldHintNames);
+		return hintNames;
+	}
+
+	protected String getPartPath(String hintName){
+		if(hintName.endsWith(hintSuffix)){
+			return hintName.substring(0, hintName.length() - hintSuffixLength);
+		}
+		return null;
+	}
+
 	protected void filteredRestoreHints(IHintRepository repository, Object co=
ntext, String partPath, String[] parts, IThing thing){
-		List<String> allHintNames =3D new ArrayList<String>(oldHintNames.size() =
+ 1);
-		allHintNames.add(partPath + hintSuffix);
-		allHintNames.addAll(oldHintNames);
-		restoreHint(repository, context, partPath, parts, thing, propertyName, r=
epository.getHint(context, allHintNames.toArray(new String[allHintNames.siz=
e()])));
+		for(String hintName: getHintNames(repository, context, partPath, parts, =
thing)){
+			Object hintValue =3D repository.getHint(context, hintName);
+			if(hintValue !=3D null){
+				restoreHint(repository, context, partPath, parts, thing, propertyName,=
 hintName, hintValue);
+				break;
+			}
+		}
 		storeHint(repository, context, partPath + hintSuffix, thing, propertyNam=
e, thing.getProperty(propertyName));
 	}
 =

@@ -70,16 +87,18 @@
 	}
 =

 	protected void filteredRepositoryChanged(IHintRepository repository, Obje=
ct context, IAssembly[] assemblies, String partPath, String hintName){
-		List<String> allHintNames =3D new ArrayList<String>(oldHintNames.size() =
+ 1);
-		allHintNames.add(hintName);
-		allHintNames.addAll(oldHintNames);
-
 		String[] parts =3D pathSplitPattern.split(partPath);
 		for(IAssembly assembly: assemblies){
 			IThing thing =3D getThing(assembly, parts);
 			if(thingInterface.isInstance(thing)){
 				if(UserEditableUtils.hasAllEditableQualities(thing, userProperties)){
-					restoreHint(repository, context, partPath, parts, thing, propertyName=
, repository.getHint(context, allHintNames.toArray(new String[allHintNames.=
size()])));
+					for(String hn: getHintNames(repository, context, partPath, parts, thi=
ng)){
+						Object hintValue =3D repository.getHint(context, hn);
+						if(hintValue !=3D null){
+							restoreHint(repository, context, partPath, parts, thing, propertyNa=
me, hn, hintValue);
+							break;
+						}
+					}
 				}
 			}
 		}
@@ -90,8 +109,11 @@
 		if(newHintName !=3D null){
 			hintName =3D newHintName;
 		}
-		if(hintName.endsWith(hintSuffix)){
-			filteredRepositoryChanged(repository, context, assemblies, hintName.sub=
string(0, hintName.length() - hintSuffixLength), hintName);
+		if(hintName !=3D null){
+			String partPath =3D getPartPath(hintName);
+			if(partPath !=3D null){
+				filteredRepositoryChanged(repository, context, assemblies, partPath, h=
intName);
+			}
 		}
 	}
 }

Modified: utils/trunk/edu.uci.isr.sysutils/src/edu/uci/isr/sysutils/SystemU=
tils.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- utils/trunk/edu.uci.isr.sysutils/src/edu/uci/isr/sysutils/SystemUtils.j=
ava (original)
+++ utils/trunk/edu.uci.isr.sysutils/src/edu/uci/isr/sysutils/SystemUtils.j=
ava Wed May  7 16:05:46 2008
@@ -730,7 +730,7 @@
 	}
 =

 	static class ExcludingFilenameFilter
-	    implements java.io.FilenameFilter{
+		implements java.io.FilenameFilter{
 =

 		String[] extensionsToExclude;
 =

@@ -932,4 +932,63 @@
 		}
 		return diff;
 	}
+
+	public static boolean deepEquals(Object o1, Object o2){
+		return deepEquals2(o1, o2);
+	}
+
+	private static boolean deepEquals2(Object o1, Object o2){
+		if(o1 =3D=3D o2){
+			return true;
+		}
+		if(o1 =3D=3D null || o2 =3D=3D null){
+			return false;
+		}
+
+		Class<?> c1 =3D o1.getClass();
+		Class<?> c2 =3D o2.getClass();
+
+		if(!c1.equals(c2)){
+			return false;
+		}
+
+		if(c1.isArray()){
+			if(c1 =3D=3D byte[].class){
+				return Arrays.equals((byte[])o1, (byte[])o2);
+			}
+			else if(c1 =3D=3D short[].class){
+				return Arrays.equals((short[])o1, (short[])o2);
+			}
+			else if(c1 =3D=3D int[].class){
+				return Arrays.equals((int[])o1, (int[])o2);
+			}
+			else if(c1 =3D=3D long[].class){
+				return Arrays.equals((long[])o1, (long[])o2);
+			}
+			else if(c1 =3D=3D char[].class){
+				return Arrays.equals((char[])o1, (char[])o2);
+			}
+			else if(c1 =3D=3D float[].class){
+				return Arrays.equals((float[])o1, (float[])o2);
+			}
+			else if(c1 =3D=3D double[].class){
+				return Arrays.equals((double[])o1, (double[])o2);
+			}
+			else if(c1 =3D=3D boolean[].class){
+				return Arrays.equals((boolean[])o1, (boolean[])o2);
+			}
+			else{
+				int l1 =3D Array.getLength(o1);
+				int l2 =3D Array.getLength(o2);
+
+				if(l1 !=3D l2){
+					return false;
+				}
+				for(int i =3D 0; i < l1; i++){
+					return deepEquals2(Array.get(o1, i), Array.get(o2, i));
+				}
+			}
+		}
+		return o1.equals(o2);
+	}
 }




More information about the archstudio-commits mailing list