Revision: 3971
Author: [email protected]
Date: Wed Nov  3 13:56:26 2010
Log: Fixed Bug 2970: Users with view permissions can't zoom. Changes were made to accommodate a new placement system in the PlayPen. Only the top left corner of PlayPen components are persisted. The width and length are determined uniquely for each system. To use this new system, the way relationships were attached to boxes changed. Before, the entire point of connection was saved on both sides, where as now, it only persists a % of how far along or down a box side it is, and it uses the orientation bit mask and table size to figure out the rest.

Also added some debugging statements.

Also fixed another bug: When we re-factored ArchitectFolder into the library, it became an SPObject instead of a SQLObject. Thus, if you tried to select it, it would try to cast to SQLObject and give an error.
http://code.google.com/p/power-architect/source/detail?r=3971

Modified:
 /trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java
/trunk/src/main/java/ca/sqlpower/architect/layout/LineStraightenerLayout.java /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java Mon Jun 14 12:44:23 2010 +++ /trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java Wed Nov 3 13:56:26 2010
@@ -37,6 +37,7 @@

 import junit.framework.TestCase;
 import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+import ca.sqlpower.architect.swingui.BasicRelationshipUI;
 import ca.sqlpower.architect.swingui.PlayPen;
 import ca.sqlpower.architect.swingui.PlayPenComponent;
 import ca.sqlpower.architect.swingui.PlayPenContentPane;
@@ -463,25 +464,25 @@
         pp.addTablePane(tp1, new Point(0, 200));
         pp.addRelationship(rel);

-        Point oldPkCon = rel.getPkConnectionPoint();
-        Point oldFkCon = rel.getFkConnectionPoint();
-
-        rel.setPkConnectionPoint(new Point(oldPkCon.x + 20, oldPkCon.y));
-        rel.setFkConnectionPoint(new Point(oldFkCon.x - 20, oldFkCon.y));
-        Point newPkCon = rel.getPkConnectionPoint();
-        Point newFkCon = rel.getFkConnectionPoint();
+ BasicRelationshipUI.ImmutablePoint oldPkCon = rel.createPkConnectionPoint(); + BasicRelationshipUI.ImmutablePoint oldFkCon = rel.createFkConnectionPoint();
+
+ rel.setPkConnectionPoint(new Point(oldPkCon.getX() + 20, oldPkCon.getY())); + rel.setFkConnectionPoint(new Point(oldFkCon.getX() - 20, oldFkCon.getY())); + BasicRelationshipUI.ImmutablePoint newPkCon = rel.createPkConnectionPoint(); + BasicRelationshipUI.ImmutablePoint newFkCon = rel.createFkConnectionPoint();

         undoManager.undo();
         undoManager.undo();
-        assertEquals(oldFkCon, rel.getFkConnectionPoint());
+        assertEquals(oldFkCon, rel.createFkConnectionPoint());
         undoManager.undo();
         undoManager.undo();
-        assertEquals(oldPkCon, rel.getPkConnectionPoint());
+        assertEquals(oldPkCon, rel.createPkConnectionPoint());
         undoManager.redo();
         undoManager.redo();
         undoManager.redo();
-        assertEquals(newPkCon, rel.getPkConnectionPoint());
-        assertEquals(newFkCon, rel.getFkConnectionPoint());
+        assertEquals(newPkCon, rel.createPkConnectionPoint());
+        assertEquals(newFkCon, rel.createFkConnectionPoint());
     }

     public void testUndoManagerActionUpdates() throws SQLObjectException
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/layout/LineStraightenerLayout.java Wed Mar 17 14:29:59 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/layout/LineStraightenerLayout.java Wed Nov 3 13:56:26 2010
@@ -72,12 +72,8 @@
         for (LayoutEdge e : edges) {
             if (e instanceof Relationship) {
                 Relationship r = (Relationship) e;
- Point[] oldConnectionPoints = {r.getPkConnectionPoint(), r.getFkConnectionPoint()}; + BasicRelationshipUI.ImmutablePoint[] oldConnectionPoints = {r.createPkConnectionPoint(), r.createFkConnectionPoint()};
                 attemptToStraighten(r);
- // connectionPoints property no longer exists, and setting the connection points fires events,
-                // so commenting this out SHOULD be okay...
- //r.firePropertyChange(new PropertyChangeEvent(r, "connectionPoints", oldConnectionPoints, - // new Point[] {r.getPkConnectionPoint(), r.getFkConnectionPoint()}));
             }
         }
         hasRun = true;
@@ -101,8 +97,8 @@
             if (vertOverlap != null) {
                 int y = vertOverlap.getMidpoint();
                 logger.debug("Found vertical overlap at y = " + y);
- r.setPkConnectionPoint(new Point(r.getPkConnectionPoint().x, y - tp1.getY())); - r.setFkConnectionPoint(new Point(r.getFkConnectionPoint().x, y - tp2.getY())); + r.setPkConnectionPoint(new Point(r.createPkConnectionPoint().getX(), y - tp1.getY())); + r.setFkConnectionPoint(new Point(r.createFkConnectionPoint().getX(), y - tp2.getY()));
                 ((BasicRelationshipUI)(r.getUI())).fixConnectionPoints();

             }
@@ -114,8 +110,8 @@
             if (horizOverlap != null) {
                 int x = horizOverlap.getMidpoint();
                 logger.debug("Found horizontal overlap at x = " + x);
- r.setPkConnectionPoint(new Point(x - tp1.getX(), r.getPkConnectionPoint().y)); - r.setFkConnectionPoint(new Point(x - tp2.getX(), r.getFkConnectionPoint().y)); + r.setPkConnectionPoint(new Point(x - tp1.getX(), r.createPkConnectionPoint().getY())); + r.setFkConnectionPoint(new Point(x - tp2.getX(), r.createFkConnectionPoint().getY()));
                 ((BasicRelationshipUI)(r.getUI())).fixConnectionPoints();
             }
         } else {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Fri Oct 15 16:01:09 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Wed Nov 3 13:56:26 2010
@@ -371,6 +371,12 @@
         UserSettings sprefs = getUserSettings().getSwingSettings();
         if (sprefs != null) {
playPen.setRenderingAntialiased(sprefs.getBoolean(ArchitectSwingUserSettings.PLAYPEN_RENDER_ANTIALIASED, false));
+            Object d = sprefs.getObject("zoom", new Double(1.0));
+            if (!(d instanceof Double)) {
+ throw new RuntimeException("Your playpen zoom must be a double");
+            }
+            playPen.setZoom((Double) d);
+
         }
projectModificationWatcher = new ProjectModificationWatcher(playPen);

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java Tue Sep 7 12:32:13 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java Wed Nov 3 13:56:26 2010
@@ -45,6 +45,29 @@
  * between tables.  Subclasses decorate the ends of the lines.
  */
public class BasicRelationshipUI extends RelationshipUI implements java.io.Serializable {
+
+       /**
+ * A wrapper for a point so that when we get the points on where to draw the relationship, we don't
+        * change them.
+        */
+       public static class ImmutablePoint {
+               Point p;
+               public ImmutablePoint(Point p) {
+                       this.p = p;
+               }
+               public int getX() {
+                       return (int)p.getX();
+               }
+               public int getY() {
+                       return (int)p.getY();
+               }
+               public boolean equals(ImmutablePoint p) {
+                       return (getX() == p.getX() && getY() == p.getY());
+               }
+        public boolean equals(Point p) {
+            return equals(new ImmutablePoint(p));
+        }
+       }

private static Logger logger = Logger.getLogger(BasicRelationshipUI.class);

@@ -137,10 +160,6 @@
                childToParent.setFont(g2.getFont());
                parentToChild.setFont(g2.getFont());
                logger.debug("orientation is: " + orientation);
-               if (g2 == null)
-               {
-                       throw new NullPointerException("Graphics g2 is null");
-               }
                if (c == null)
                {
                        throw new NullPointerException("Relationship c is 
null");
@@ -157,9 +176,9 @@
                }

                try {
-                       Point pktloc = relationship.getPkConnectionPoint();
-                       Point start = new Point(pktloc.x + 
r.getPkTable().getLocation().x,
-                                               pktloc.y + 
r.getPkTable().getLocation().y);
+                   ImmutablePoint pktloc = 
relationship.createPkConnectionPoint();
+ Point start = new Point(pktloc.getX() + r.getPkTable().getLocation().x, + pktloc.getY() + r.getPkTable().getLocation().y);
             Point lineStart = new Point(start);
             if ((orientation & PARENT_FACES_LEFT) != 0) {
                 lineStart.x -= getTerminationLength();
@@ -171,9 +190,9 @@
                 lineStart.y += getTerminationLength();
             }

-                       Point fktloc = relationship.getFkConnectionPoint();
-                       Point end = new Point(fktloc.x + 
r.getFkTable().getLocation().x,
-                                             fktloc.y + 
r.getFkTable().getLocation().y);
+            ImmutablePoint fktloc = relationship.createFkConnectionPoint();
+ Point end = new Point(fktloc.getX() + r.getFkTable().getLocation().x, + fktloc.getY() + r.getFkTable().getLocation().y);
             Point lineEnd = new Point(end);
             if ((orientation & CHILD_FACES_LEFT) != 0) {
                 lineEnd.x -= getTerminationLength();
@@ -675,8 +694,8 @@
                Rectangle pktBounds = relationship.getPkTable().getBounds();
                Rectangle fktBounds = relationship.getFkTable().getBounds();

-               Point fkConnectionPoint = relationship.getFkConnectionPoint();
-               Point pkConnectionPoint = relationship.getPkConnectionPoint();
+ ImmutablePoint fkConnectionPoint = relationship.createFkConnectionPoint(); + ImmutablePoint pkConnectionPoint = relationship.createPkConnectionPoint();

                int orientation = relationship.getOrientation();

@@ -684,8 +703,8 @@
                        // self-referencing table
                    orientation = PARENT_FACES_BOTTOM | CHILD_FACES_LEFT;
                        relationship.setOrientation(orientation);
- relationship.setPkConnectionPoint(new Point(pktBounds.width/2, pktBounds.height));
-                       relationship.setFkConnectionPoint(new Point(0, 
fktBounds.height/2));
+                       relationship.setPkConnection(0.5);
+                       relationship.setFkConnection(0.5);
                        logger.debug("Self-referencing table: set connection points 
pk="
                                                 +pkConnectionPoint+"; 
fk="+fkConnectionPoint);
                } else {
@@ -767,18 +786,12 @@
Point ep; // this is the return value (edge point), set in one of the cases below Point sp; // this is the stationary point at the non-moving end of the relationship
                if (onPkTable) {
-                       sp = new Point(relationship.getFkTable().getLocation());
-                       translatePoint(sp, relationship.getFkConnectionPoint());
-                       sp.x -= relationship.getPkTable().getX();
-                       sp.y -= relationship.getPkTable().getY();
+ sp = new Point(relationship.createFkConnectionPoint().getX(), relationship.createFkConnectionPoint().getY()); ep = checkClosestPointOnTable(tpsize, sp, p, PARENT_FACES_LEFT, PARENT_FACES_RIGHT, PARENT_FACES_TOP, PARENT_FACES_BOTTOM, CHILD_MASK, true);

                } else {
-                       sp = new Point(relationship.getPkTable().getLocation());
-                       translatePoint(sp, relationship.getPkConnectionPoint());
-                       sp.x -= relationship.getFkTable().getX();
-                       sp.y -= relationship.getFkTable().getY();
- ep = checkClosestPointOnTable(tpsize, sp, p, CHILD_FACES_LEFT, CHILD_FACES_RIGHT, CHILD_FACES_TOP, CHILD_FACES_BOTTOM, PARENT_MASK, false); + sp = new Point(relationship.createPkConnectionPoint().getX(), relationship.createPkConnectionPoint().getY()); + ep = checkClosestPointOnTable(tpsize, sp, p, CHILD_FACES_LEFT, CHILD_FACES_RIGHT, CHILD_FACES_TOP, CHILD_FACES_BOTTOM, PARENT_MASK, false);
                }
                return ep;
        }
@@ -814,7 +827,7 @@
BasicRelationshipUI newRelation = new BasicRelationshipUI(this);
             if(pkTable){
                 newRelation.getRelationship().setPkConnectionPoint(ep);
-            }else{
+            } else {
                 newRelation.getRelationship().setFkConnectionPoint(ep);
             }
             if (!newRelation.isOrientationLegal()) {
@@ -986,8 +999,8 @@
         * time allows.
         */
        public boolean isOrientationLegal() {
-           Point fkConnectionPoint = relationship.getFkConnectionPoint();
-           Point pkConnectionPoint = relationship.getPkConnectionPoint();
+ ImmutablePoint fkConnectionPoint = relationship.createFkConnectionPoint(); + ImmutablePoint pkConnectionPoint = relationship.createPkConnectionPoint();

            final int orientation = relationship.getOrientation();

@@ -1049,7 +1062,7 @@
* are for the parent or child constant values since they are dependent on if they
         * are for the parent or child.
         */
- private Point checkOrientationForCorner(Point relationEndpoint, int orientation, int left, int right, int top, int bottom, int mask) + private Point checkOrientationForCorner(ImmutablePoint relationEndpoint, int orientation, int left, int right, int top, int bottom, int mask)
     {
        Point newEndpoint = new Point();
        int parentOrientation = orientation & mask;
@@ -1107,7 +1120,7 @@
         TablePane table = relationship.getPkTable();

         // the last adjusted point that was not out of bounds
- Point lastValidPoint = new Point(relationship.getPkConnectionPoint()); + ImmutablePoint lastValidPoint = relationship.createPkConnectionPoint();

// two passes: first, the setup (directly above) causes the code in the loop // to update the PK connection point. At the bottom of the loop, the setup
@@ -1136,8 +1149,8 @@
// checks for collision, r.contains() was not used because // it did not pick up collisions when the table was dragged
                         // past the illegal orientation points.
- if (r.getPkConnectionPoint().equals(lastValidPoint) || - r.getFkConnectionPoint().equals(lastValidPoint)) { + if (r.createPkConnectionPoint().equals(lastValidPoint) || + r.createFkConnectionPoint().equals(lastValidPoint)) {
                             collided = true;

// determines offset according to count in this order:
@@ -1154,7 +1167,7 @@
                                 outOfBounds[count%2] = true;
                             // saves the new adjusted point
                             } else {
- lastValidPoint = new Point(connectionPoint); + lastValidPoint = new ImmutablePoint(connectionPoint);
                             }
                             break;
                         }
@@ -1165,16 +1178,16 @@

             // actual work to adjust the connection point
             if (isPkConnectionPoint) {
-                relationship.setPkConnectionPoint(lastValidPoint);
+ relationship.setPkConnection(((double)lastValidPoint.getX() / relationship.getPkTable().getWidth()));
             } else {
-                relationship.setFkConnectionPoint(lastValidPoint);
+ relationship.setFkConnection(((double)lastValidPoint.getX() / relationship.getFkTable().getWidth()));
             }

             // sets up for the next connection point, assumes
// that there are only two: pkConnectionPoint, fkConnectionPoint
             isPkConnectionPoint = false;
             table = relationship.getFkTable();
- lastValidPoint = new Point(relationship.getFkConnectionPoint());
+            lastValidPoint = relationship.createFkConnectionPoint();
         }
        }

@@ -1192,7 +1205,7 @@
private Point adjustConnectionPoint(int orientation, boolean isPkConnectionPoint, int offset) {
            logger.debug("adjustConnectionPoint()");
            Rectangle tBounds;
-           Point connectionPoint;
+           ImmutablePoint connectionPoint;

            // sets up the corresponding orientations, bounds,
            // and point of origin to check for according to
@@ -1202,16 +1215,16 @@
                tBounds = relationship.getPkTable().getBounds();
                orientations = new int[]{PARENT_FACES_TOP, PARENT_FACES_RIGHT,
                        PARENT_FACES_BOTTOM, PARENT_FACES_LEFT};
-               connectionPoint = new 
Point(relationship.getPkConnectionPoint());
+               connectionPoint = relationship.createPkConnectionPoint();
            } else {
                tBounds = relationship.getFkTable().getBounds();
                orientations = new int[]{CHILD_FACES_TOP, CHILD_FACES_RIGHT,
                        CHILD_FACES_BOTTOM, CHILD_FACES_LEFT};
-               connectionPoint = new 
Point(relationship.getFkConnectionPoint());
+               connectionPoint = relationship.createFkConnectionPoint();
            }

-           int x = connectionPoint.x;
-           int y = connectionPoint.y;
+           int x = connectionPoint.getX();
+           int y = connectionPoint.getY();

            // adjusts the x coordinate if the table faced top or bottom
if ( ((orientation & orientations[2]) != 0) || ((orientation & orientations[0]) != 0) ) {
@@ -1242,10 +1255,10 @@
                TablePane pkTable = relationship.getPkTable();
                TablePane fkTable = relationship.getFkTable();

-               Point fkConnectionPoint = relationship.getFkConnectionPoint();
-               Point pkConnectionPoint = relationship.getPkConnectionPoint();
-
-               if (!isOrientationLegal()) {
+ ImmutablePoint fkConnectionPoint = relationship.createFkConnectionPoint(); + ImmutablePoint pkConnectionPoint = relationship.createPkConnectionPoint();
+
+               if (!isOrientationLegal() && relationship.isMagicEnabled()) {
                        // bestConnectionPoints also updates orientation as a 
side effect
                        bestConnectionPoints();
                }
@@ -1253,17 +1266,17 @@
                if (pkTable == fkTable) {
                        // hack for supporting self-referencing table
                        // assume orientation is PARENT_FACES_BOTTOM | 
CHILD_FACES_LEFT
- Point topLeft = new Point(fkConnectionPoint.x - getTerminationLength() * 2 - radius,
-                                                                         
fkConnectionPoint.y - getTerminationWidth());
- Point bottomRight = new Point(pkConnectionPoint.x + getTerminationWidth(),
-                                                                               
  pkConnectionPoint.y + radius + getTerminationLength() * 2);
+ Point topLeft = new Point(fkConnectionPoint.getX() - getTerminationLength() * 2 - radius,
+                                                                         
fkConnectionPoint.getY() - getTerminationWidth());
+ Point bottomRight = new Point(pkConnectionPoint.getX() + getTerminationWidth(), + pkConnectionPoint.getY() + radius + getTerminationLength() * 2); computedBounds = new Rectangle(topLeft.x + pkTable.getX(), topLeft.y + pkTable.getY(), bottomRight.x - topLeft.x, bottomRight.y - topLeft.y + fm.getHeight());
                } else {

-                       Point pkLimits = new Point(pkConnectionPoint);
+ Point pkLimits = new Point(pkConnectionPoint.getX(),pkConnectionPoint.getY());
                        pkLimits.translate(pkTable.getX(), pkTable.getY());
-                       Point fkLimits = new Point(fkConnectionPoint);
+ Point fkLimits = new Point(fkConnectionPoint.getX(),fkConnectionPoint.getY());
                        fkLimits.translate(fkTable.getX(), fkTable.getY());

                        final int orientation = relationship.getOrientation();
@@ -1272,50 +1285,46 @@
logger.debug("Absolute connection points: pk="+pkLimits+"; fk="+fkLimits);
                        }

-                       // make room for parent decorations
-                       if ( (orientation & (PARENT_FACES_RIGHT | 
PARENT_FACES_LEFT)) != 0) {
-                               if (pkLimits.y >= fkLimits.y) {
-                                       pkLimits.y += getTerminationWidth();
-                               } else {
-                                       pkLimits.y -= getTerminationWidth();
-                               }
-                       } else {
-                               if (pkLimits.x >= fkLimits.x) {
-                                       pkLimits.x += getTerminationWidth();
-                               } else {
-                                       pkLimits.x -= getTerminationWidth();
-                               }
-                       }
-
-                       // make room for child decorations
-                       if ( (orientation & (CHILD_FACES_RIGHT | 
CHILD_FACES_LEFT)) != 0) {
-                               if (fkLimits.y <= pkConnectionPoint.y + 
pkTable.getY()) {
-                                       fkLimits.y -= getTerminationWidth();
-                               } else {
-                                       fkLimits.y += getTerminationWidth();
-                               }
-                       } else {
-                               if (fkLimits.x <= pkConnectionPoint.x + 
pkTable.getX()) {
-                                       fkLimits.x -= getTerminationWidth();
-                               } else {
-                                       fkLimits.x += getTerminationWidth();
-                               }
-                       }
-
- if (logger.isDebugEnabled()) logger.debug("Limits: pk="+pkLimits+"; fk="+fkLimits);
-
-                       Point topLeft = new Point(Math.min(pkLimits.x,
-                                       fkLimits.x),
-                                       Math.min(pkLimits.y,
-                                                       fkLimits.y));
-                       Point bottomRight = new Point(Math.max(pkLimits.x,
-                                       fkLimits.x),
-                                       Math.max(pkLimits.y,
-                                                       fkLimits.y));
-                       computedBounds = new Rectangle(topLeft.x - 
fm.getHeight(),
-                                                      topLeft.y - 
fm.getAscent(),
- bottomRight.x - topLeft.x + 2*fm.getHeight(), - bottomRight.y - topLeft.y + fm.getHeight() + fm.getDescent());
+                       Point topLeft = new Point();
+                       Point bottomRight = new Point();
+
+ topLeft.x = (pkTable.getX() > fkTable.getX()) ? fkTable.getX() : pkTable.getX(); + topLeft.y = (pkTable.getY() > fkTable.getY()) ? fkTable.getY() : pkTable.getY();
+
+            if ((orientation & PARENT_FACES_LEFT) != 0) {
+                bottomRight.x = pkLimits.x + getTerminationLength();
+            } else if ((orientation & CHILD_FACES_LEFT) != 0) {
+                bottomRight.x = fkLimits.x + getTerminationLength();
+            } else {
+                if(pkLimits.x < fkLimits.x) {
+                    bottomRight.x = fkLimits.x + getTerminationWidth();
+                } else {
+                    bottomRight.x = pkLimits.x + getTerminationWidth();
+                }
+            }
+
+            if ((orientation & PARENT_FACES_TOP) != 0) {
+                bottomRight.y = pkLimits.y + getTerminationLength();
+            } else if ((orientation & CHILD_FACES_TOP) != 0) {
+                bottomRight.y = fkLimits.y + getTerminationLength();
+            } else {
+                if(pkLimits.y < fkLimits.y) {
+                    bottomRight.y = fkLimits.y + getTerminationWidth();
+                } else {
+                    bottomRight.y = pkLimits.y + getTerminationWidth();
+                }
+            }
+
+ int largestTermination = Math.max(getTerminationLength(), getTerminationWidth());
+            topLeft.x -= largestTermination;
+            topLeft.y -= largestTermination;
+
+            computedBounds = new Rectangle(topLeft.x,
+                    topLeft.y,
+                    bottomRight.x - topLeft.x,
+                    bottomRight.y - topLeft.y);
+
+
                        if (logger.isDebugEnabled()) {
                                logger.debug("Updating bounds to 
"+computedBounds
                                                +" (topleft="+topLeft+"; 
bottomRight="+bottomRight+")");
@@ -1352,9 +1361,9 @@
         * clicks and drags.
         */
        public boolean isOverPkDecoration(Point p) {
-               Point pkDec = new Point
- (relationship.getPkConnectionPoint().x + relationship.getPkTable().getX() - relationship.getX(), - relationship.getPkConnectionPoint().y + relationship.getPkTable().getY() - relationship.getY());
+        ImmutablePoint pkPoint = relationship.createPkConnectionPoint();
+ Point pkDec = new Point(pkPoint.getX() + relationship.getPkTable().getX() - relationship.getX(), + pkPoint.getY() + relationship.getPkTable().getY() - relationship.getY());
                final int orientation = relationship.getOrientation();
                if (logger.isDebugEnabled()) logger.debug(
                        "p="+p+"; pkDec = "+pkDec+"; 
width="+relationship.getWidth()+
@@ -1408,9 +1417,9 @@
         * clicks and drags.
         */
        public boolean isOverFkDecoration(Point p) {
-           Point fkDec = new Point
- (relationship.getFkConnectionPoint().x + relationship.getFkTable().getX() - relationship.getX(), - relationship.getFkConnectionPoint().y + relationship.getFkTable().getY() - relationship.getY());
+               ImmutablePoint fkPoint = relationship.createFkConnectionPoint();
+ Point fkDec = new Point((int)fkPoint.getX() + relationship.getFkTable().getX() - relationship.getX(), + (int)fkPoint.getY() + relationship.getFkTable().getY() - relationship.getY());
            final int orientation = relationship.getOrientation();
                if ( (orientation & (CHILD_FACES_BOTTOM | CHILD_FACES_TOP)) != 
0) {
                    if (p.x < fkDec.x + 5 && p.x > fkDec.x - 5) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Thu Aug 26 08:51:58 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Wed Nov 3 13:56:26 2010
@@ -70,6 +70,7 @@
 import ca.sqlpower.architect.swingui.dbtree.DBTreeModel;
 import ca.sqlpower.object.ObjectDependentException;
 import ca.sqlpower.object.SPListener;
+import ca.sqlpower.object.SPObject;
 import ca.sqlpower.object.SPObjectSnapshot;
 import ca.sqlpower.sql.JDBCDataSource;
 import ca.sqlpower.sql.SPDataSource;
@@ -1117,7 +1118,7 @@
     public void clearNonPlayPenSelections() {
         if (getSelectionPaths() == null) return;
         for (TreePath tp : getSelectionPaths()) {
-            SQLObject obj = (SQLObject) tp.getLastPathComponent();
+            SPObject obj = (SPObject) tp.getLastPathComponent();
if (!(obj instanceof SQLTable || obj instanceof SQLRelationship || obj instanceof SQLColumn || obj instanceof SQLRelationship.SQLImportedKey)) {
                 removeSelectionPath(tp);
             }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Thu Aug 26 08:51:58 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Wed Nov 3 13:56:26 2010
@@ -70,6 +70,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.prefs.Preferences;
 import java.util.Set;
 import java.util.WeakHashMap;

@@ -94,7 +95,9 @@

 import org.apache.log4j.Logger;

+import ca.sqlpower.architect.ArchitectSessionImpl;
 import ca.sqlpower.architect.ArchitectUtils;
+import ca.sqlpower.architect.UserSettings;
 import ca.sqlpower.architect.olap.MondrianModel;
 import ca.sqlpower.architect.olap.MondrianModel.Cube;
 import ca.sqlpower.architect.olap.MondrianModel.CubeUsage;
@@ -623,7 +626,9 @@
                if (session.isEnterpriseSession()) {
                    zoom = session.getEnterpriseSession().getPrefDouble("zoom", 
1.0);
                } else {
-                   zoom = 1.0;
+ Preferences p = Preferences.userNodeForPackage(ArchitectSessionImpl.class);
+               Preferences prefs = p.node(session.getWorkspace().getName());
+            zoom = prefs.getDouble("zoom", 1.0);
                }
         viewportPosition = new Point(0, 0);
                this.setBackground(java.awt.Color.white);
@@ -1060,6 +1065,14 @@
                if (newZoom != zoom) {
                        double oldZoom = zoom;
                        zoom = newZoom;
+                       if(session.isEnterpriseSession()) {
+                   session.getEnterpriseSession().putPref("zoom", zoom);
+                       } else {
+ UserSettings sprefs = session.getUserSettings().getSwingSettings();
+                       if (sprefs != null) {
+                           sprefs.setObject("zoom", new Double(zoom));
+                       }
+                       }
                        this.firePropertyChange("zoom", oldZoom, newZoom); 
//$NON-NLS-1$
                        this.revalidate();
                        this.repaint();
@@ -2864,7 +2877,7 @@
* @param selection A list of SQLObjects, should only have SQLColumn, SQLTable or SQLRelationship.
      * @throws SQLObjectException
      */
- public void selectObjects(List<SQLObject> selections) throws SQLObjectException { + public void selectObjects(List<? extends SPObject> selections) throws SQLObjectException {
         if (ignoreTreeSelection) return;
         ignoreTreeSelection = true;

@@ -2872,12 +2885,12 @@
         DBTree tree = session.getDBTree();

         // tables to add to select because of column selection
-        List<SQLObject> colTables = new ArrayList<SQLObject>();
+        List<SPObject> colTables = new ArrayList<SPObject>();

         // objects that were already selected, only used for debugging
-        List<SQLObject> ignoredObjs = new ArrayList<SQLObject>();
-
-        for (SQLObject obj : selections) {
+        List<SPObject> ignoredObjs = new ArrayList<SPObject>();
+
+        for (SPObject obj : selections) {
             if (obj instanceof SQLColumn){
                 //Since we cannot directly select a SQLColumn directly
                 //from the playpen, there is a special case for it
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java Fri Oct 15 16:01:09 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java Wed Nov 3 13:56:26 2010
@@ -72,7 +72,8 @@
      */
public static final List<Class<? extends SPObject>> allowedChildTypes = Collections.emptyList();

-    private Rectangle bounds = new Rectangle();
+    protected Point topLeftCorner = new Point();
+    private Dimension lengths = new Dimension();
     private Dimension minimumSize = new Dimension();
     protected Color backgroundColor;
     protected Color foregroundColor;
@@ -145,8 +146,11 @@
protected PlayPenComponent(PlayPenComponent copyMe, PlayPenContentPane parent) {
         this(copyMe.getName(), parent);
         backgroundColor = copyMe.backgroundColor;
-        if (copyMe.bounds != null) {
-            bounds = new Rectangle(copyMe.bounds);
+        if (copyMe.topLeftCorner != null) {
+            topLeftCorner = new Point(copyMe.topLeftCorner);
+        }
+        if (copyMe.lengths != null) {
+            lengths = new Dimension(copyMe.lengths);
         }
         componentPreviouslySelected = copyMe.componentPreviouslySelected;
         foregroundColor = copyMe.foregroundColor;
@@ -226,19 +230,14 @@
logger.debug("getPlayPen() returned null. Not generating repaint request."); //$NON-NLS-1$
             return;
         } else {
-            Rectangle r = new Rectangle(bounds);
+            Rectangle r = new Rectangle(topLeftCorner, lengths);
             if (isMagicEnabled()) {
                 // This temporary disabling of magic is under the
                 // assumption that this method properly revalidates
                 // the component in one pass, and does not rely
                 // on recursive calls due to magical side effects
                 setMagicEnabled(false);
-                PlayPenComponentUI ui = getUI();
-                if (ui != null) {
-                    ui.revalidate();
-                    Dimension ps = ui.getPreferredSize();
-                    if (ps != null) setSize(ps);
-                }
+                updateLengths(true);
if (logger.isDebugEnabled()) logger.debug("Scheduling repaint at "+r); //$NON-NLS-1$
                 setMagicEnabled(true);
             }
@@ -246,42 +245,23 @@
             pp.repaint(r);
         }
     }
-
+
     /**
-     * Updates the bounds of this component, then issues a repaint to the
- * PlayPen which covers the old bounds of this component. This will allow - * newly-exposed sections of the PlayPen to draw themselves in case this - * setBounds call is shrinking this component. Also ensures the new bounds - * do not remain left of or above the (0,0) point by normalizing the play pen.
-     *
- * <p>All methods that affect the bounds rectangle should do so by calling this
-     * method.
-     */
-    @Transient @Mutator
-    public void setBounds(int x, int y, int width, int height) {
-        setBounds(new Rectangle(x, y, width, height));
+     * Sets the lengths to the current correct value
+     */
+    public void updateLengths(boolean revalidate) {
+        PlayPenComponentUI ui = getUI();
+        if (ui != null) {
+            if(revalidate) ui.revalidate();
+            Dimension ps = ui.getPreferredSize();
+            if (ps != null) setLengths(ps);
+        }
     }

-    @Mutator
-    public void setBounds(Rectangle r) {
-        Rectangle oldBounds = getBounds();
-        repaint();
-
-        if (logger.isDebugEnabled()) {
-            logger.debug("Updating bounds on "+getName() //$NON-NLS-1$
- +" to ["+r.x+","+r.y+","+r.width+","+r.height+"]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-        }
-
-        bounds.setBounds(r.x,r.y,r.width,r.height);
-        firePropertyChange("bounds", oldBounds, new Rectangle(bounds));
-
-        repaint();
-    }
-
     /**
      * Returns a copy of this component's bounding rectangle.
      */
-    @Accessor
+    @NonBound
     public Rectangle getBounds() {
         return getBounds(null);
     }
@@ -320,13 +300,13 @@
     @NonBound
     public Rectangle getBounds(Rectangle r) {
         if (r == null) r = new Rectangle();
-        r.setBounds(bounds);
+        r.setBounds(getX(), getY(), getWidth(), getHeight());
         return r;
     }

     @Transient @Accessor(isInteresting=true)
     public Dimension getSize() {
-        return new Dimension(bounds.width, bounds.height);
+        return lengths;
     }

     /**
@@ -353,31 +333,10 @@
      */
     @Transient @Accessor
     public Point getLocation(Point p) {
-        if (p == null) p = new Point();
-        p.x = bounds.x;
-        p.y = bounds.y;
+        if(p == null) p = new Point();
+        p.setLocation(getTopLeftCorner());
         return p;
     }
-
-    /**
- * Updates the on-screen location of this component. If you try to move this - * component to a negative co-ordinate, it will automatically be normalized (along
-     * with everything else in the playpen) to non-negative coordinates.
-     */
-    @Transient @Mutator
-    public void setLocation(Point point) {
-        setBounds(point.x,point.y, getWidth(), getHeight());
-    }
-
-    /**
- * Updates the on-screen location of this component. If you try to move this - * component to a negative co-ordinate, it will automatically be normalized (along
-     * with everything else in the playpen) to non-negative coordinates.
-     */
-    @Transient @Mutator
-    public void setLocation(int x, int y) {
-               setBounds(x, y, getWidth(), getHeight());
-    }

     @NonBound
     public static boolean isLocationChange(PropertyChangeEvent evt) {
@@ -385,11 +344,6 @@
         Rectangle newVal = (Rectangle) evt.getNewValue();
         return (oldVal.x != newVal.x || oldVal.y != newVal.y);
     }
-
-    @Transient @Mutator
-    public void setSize(Dimension size) {
-        setBounds(getX(), getY(), size.width, size.height);
-    }

     /**
      * Forwards to {...@link #repaint(Rectangle)}.
@@ -415,22 +369,22 @@

     @Transient @Accessor
     public int getX() {
-        return bounds.x;
+        return topLeftCorner.x;
     }

     @Transient @Accessor
     public int getY() {
-        return bounds.y;
+        return topLeftCorner.y;
     }

     @Transient @Accessor
     public int getWidth() {
-        return bounds.width;
+        return lengths.width;
     }

     @Transient @Accessor
     public int getHeight() {
-        return bounds.height;
+        return lengths.height;
     }

     @Transient @Accessor
@@ -769,5 +723,72 @@
         SwingUtilities.convertPointToScreen(p, pp);
         return p;
     }
+
+    /**
+ * Updates the on-screen location of this component. If you try to move this + * component to a negative co-ordinate, it will automatically be normalized (along
+     * with everything else in the playpen) to non-negative coordinates.
+     */
+    @Mutator
+    public void setTopLeftCorner(Point topLeftCorner) {
+        repaint();
+
+        Point old = this.topLeftCorner;
+        this.topLeftCorner = topLeftCorner;
+        firePropertyChange("topLeftCorner", old, topLeftCorner);
+
+        repaint();
+    }
+
+    @Accessor
+    public Point getTopLeftCorner() {
+        return topLeftCorner;
+    }
+
+    @Transient
+    @Mutator
+    public void setLengths(Dimension lengths) {
+        Dimension old = this.lengths;
+        this.lengths = lengths;
+        firePropertyChange("lengths", old, lengths);
+    }
+
+    @Transient
+    @Mutator
+    public Dimension getLengths() {
+        return lengths;
+    }
+
+    @Transient
+    @Mutator
+    public void setBounds(Rectangle r) {
+        setTopLeftCorner(new Point(r.x,r.y));
+        setLengths(new Dimension(r.width, r.height));
+    }
+
+    @Transient
+    @Mutator
+    public void setBounds(int x, int y, int width, int height) {
+        setTopLeftCorner(new Point(x,y));
+        setLengths(new Dimension(width, height));
+    }
+
+    @Transient
+    @Mutator
+    public void setLocation(int x, int y) {
+        setTopLeftCorner(new Point(x,y));
+    }
+
+    @Transient
+    @Mutator
+    public void setLocation(Point pos) {
+        setTopLeftCorner(pos);
+    }
+
+    @Transient
+    @Mutator
+    public void setSize(Dimension size) {
+        setBounds(getX(), getY(), size.width, size.height);
+    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java Wed Nov 3 13:56:26 2010
@@ -53,6 +53,7 @@
 import ca.sqlpower.architect.swingui.event.ItemSelectionListener;
 import ca.sqlpower.architect.swingui.event.SelectionEvent;
 import ca.sqlpower.architect.swingui.event.SelectionListener;
+import ca.sqlpower.object.SPObject;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLObjectException;
@@ -308,11 +309,11 @@
             if (treePaths == null) {
                 pp.selectNone();
             } else {
-                List<SQLObject> objects = new ArrayList<SQLObject>();
+                List<SPObject> objects = new ArrayList<SPObject>();
                 for (TreePath tp : treePaths) {
if (tree.isTargetDatabaseNode(tp) | | !tree.isTargetDatabaseChild(tp))
                         continue;
-                    SQLObject obj = (SQLObject) tp.getLastPathComponent();
+                    SPObject obj = (SPObject) tp.getLastPathComponent();
                     // only select playpen represented objects.
if ((obj instanceof SQLTable || obj instanceof SQLRelationship || obj instanceof SQLColumn) &&
                             !objects.contains(obj)) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java Tue Aug 24 09:02:29 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java Wed Nov 3 13:56:26 2010
@@ -20,6 +20,7 @@

 import java.awt.Color;
 import java.awt.Cursor;
+import java.awt.Dimension;
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
@@ -90,8 +91,17 @@
        private TablePane pkTable;
        private TablePane fkTable;

-       private Point pkConnectionPoint;
-       private Point fkConnectionPoint;
+       /**
+ * This represents a percentage of how far along one of the sides the connection
+        * to the primary key table should be drawn.
+        */
+       private double pkConnection;
+
+    /**
+ * This represents a percentage of how far along one of the sides the connection
+     * to the foreign key table should be drawn.
+     */
+       private double fkConnection;

     /**
* A bitmask of the constants (PARENT|CHILD)_FACES_(LEFT|RIGHT|TOP| BOTTOM).
@@ -148,8 +158,8 @@
                setName(r.getName());
                this.pkTable = r.pkTable;
                this.fkTable = r.fkTable;
-               this.pkConnectionPoint = new Point(r.getPkConnectionPoint());
-               this.fkConnectionPoint = new Point(r.getFkConnectionPoint());
+               this.pkConnection = r.getPkConnection();
+               this.fkConnection = r.getFkConnection();
                this.selected = false;
                this.columnHighlightColour = r.columnHighlightColour;

@@ -186,7 +196,7 @@
        public Relationship(SQLRelationship model, TablePane pkTable,
                TablePane fkTable, PlayPenContentPane parent)
        throws SQLObjectException {
-           this (model, pkTable, fkTable, parent, new Point(), new Point(), 0);
+           this (model, pkTable, fkTable, parent, 0, 0, 0);
        }

        @Constructor
@@ -194,16 +204,16 @@
                @ConstructorParameter(propertyName="pkTable") TablePane pkTable,
                @ConstructorParameter(propertyName="fkTable") TablePane fkTable,
@ConstructorParameter(propertyName="parent") PlayPenContentPane parent, - @ConstructorParameter(propertyName="pkConnectionPoint") Point pkConnectionPoint, - @ConstructorParameter(propertyName="fkConnectionPoint") Point fkConnectionPoint, + @ConstructorParameter(propertyName="pkConnection") double pkConnection, + @ConstructorParameter(propertyName="fkConnection") double fkConnection,
                @ConstructorParameter(propertyName="orientation") int 
orientation)
        throws SQLObjectException {
            super(model.getName());
                this.model = model;
                setPkTable(pkTable);
                setFkTable(fkTable);
-        this.pkConnectionPoint = new Point(pkConnectionPoint);
-        this.fkConnectionPoint = new Point(fkConnectionPoint);
+        this.pkConnection = pkConnection;
+        this.fkConnection = fkConnection;
                this.orientation = orientation;
                setParent(parent);
         setup();
@@ -214,13 +224,12 @@
         */
        protected void setup() {
                updateUI();
+               //((RelationshipUI)getUI()).bestConnectionPoints();
                setOpaque(false);
                setBackgroundColor(Color.green);
                model.addSPListener(this);
                setToolTipText(model.getName());
-
-               // requires pkTable and fkTable to be initialized
-        //ui.bestConnectionPoints(); // breaks when loading a new project?
+
        }

        protected void createPopup() {
@@ -266,12 +275,12 @@

         if (logger.isDebugEnabled()) {
             popup.addSeparator();
- mi = new JMenuItem(new AbstractAction("Show Mappings") { //$NON-NLS-1$
+            mi = new JMenuItem(new AbstractAction("Show Mappings") {
                 public void actionPerformed(ActionEvent e) {
                     StringBuffer componentList = new StringBuffer();

for (ColumnMapping columnMap : getModel().getChildren(ColumnMapping.class)) { - componentList.append(columnMap).append("\n"); //$NON-NLS-1$
+                        componentList.append(columnMap).append("\n");
                     }

JOptionPane.showMessageDialog(getPlayPen(), new JScrollPane(new JTextArea(componentList.toString())));
@@ -332,6 +341,11 @@
RelationshipUI ui = (RelationshipUI) IERelationshipUI.createUI(this);
         ui.installUI(this);
                setUI(ui);
+        updateLengths(false);
+
+        if(isMagicEnabled())
+            ui.bestConnectionPoints();
+
                revalidate();
     }

@@ -413,14 +427,88 @@
        }

        @Accessor(isInteresting=true)
-       public Point getPkConnectionPoint() {
-               return new Point(pkConnectionPoint);
+       public double getPkConnection() {
+               return pkConnection;
        }

        @Accessor(isInteresting=true)
-       public Point getFkConnectionPoint() {
-               return new Point(fkConnectionPoint);
-       }
+       public double getFkConnection() {
+               return fkConnection;
+       }
+
+    /**
+ * Creates a point that tells the UI exactly where the connection should be connecting to the
+     * primary key table.
+     */
+    public BasicRelationshipUI.ImmutablePoint createPkConnectionPoint() {
+
+        Point p;
+        TablePane pane = getPkTable();
+
+        if((getOrientation() & PARENT_FACES_BOTTOM) != 0)
+ p = new Point((int)(pane.getWidth() * getPkConnection()), pane.getHeight());
+        else if((getOrientation() & PARENT_FACES_TOP) != 0)
+            p = new Point((int)(pane.getWidth() * getPkConnection()), 0);
+        else if((getOrientation() & PARENT_FACES_LEFT) != 0)
+            p = new Point(0, (int)(pane.getHeight() * getPkConnection()));
+        else
+ p = new Point(pane.getWidth(), (int)(pane.getHeight() * getPkConnection()));
+
+        return new BasicRelationshipUI.ImmutablePoint(p);
+    }
+
+    /**
+ * Creates a point that tells the UI exactly where the connection should be connecting to the
+     * foreign key table.
+     */
+    public BasicRelationshipUI.ImmutablePoint createFkConnectionPoint() {
+
+        Point p;
+        TablePane pane = getFkTable();
+
+        if((getOrientation() & CHILD_FACES_BOTTOM) != 0)
+ p = new Point((int)(pane.getWidth() * getFkConnection()), pane.getHeight());
+        else if((getOrientation() & CHILD_FACES_TOP) != 0)
+            p = new Point((int)(pane.getWidth() * getFkConnection()), 0);
+        else if((getOrientation() & CHILD_FACES_LEFT) != 0)
+            p = new Point(0, (int)(pane.getHeight() * getFkConnection()));
+        else
+ p = new Point(pane.getWidth(), (int)(pane.getHeight() * getFkConnection()));
+
+        return new BasicRelationshipUI.ImmutablePoint(p);
+    }
+
+    /**
+ * Takes the necessary info from the point and gets the percentage value we need to store
+     */
+    @Transient
+    @Mutator
+    public void setFkConnectionPoint(Point p) {
+        if((getOrientation() & CHILD_FACES_BOTTOM) != 0)
+            setFkConnection(p.getX() / getFkTable().getWidth());
+        else if((getOrientation() & CHILD_FACES_TOP) != 0)
+            setFkConnection(p.getX() / getFkTable().getWidth());
+        else if((getOrientation() & CHILD_FACES_LEFT) != 0)
+            setFkConnection(p.getY() / getFkTable().getHeight());
+        else
+            setFkConnection(p.getY() / getFkTable().getHeight());
+    }
+
+    /**
+ * Takes the necessary info from the point and gets the percentage value we need to store
+     */
+    @Transient
+    @Mutator
+    public void setPkConnectionPoint(Point p) {
+        if((getOrientation() & PARENT_FACES_BOTTOM) != 0)
+            setPkConnection(p.getX() / getPkTable().getWidth());
+        else if((getOrientation() & PARENT_FACES_TOP) != 0)
+            setPkConnection(p.getX() / getPkTable().getWidth());
+        else if((getOrientation() & PARENT_FACES_LEFT) != 0)
+            setPkConnection(p.getY() / getPkTable().getHeight());
+        else
+            setPkConnection(p.getY() / getPkTable().getHeight());
+    }

     /**
      * Returns the current orientation of this relationship; that is, which
@@ -437,21 +525,22 @@
        public void setOrientation(int orientation) {
            int oldValue = this.orientation;
            this.orientation = orientation;
-           firePropertyChange("orientation", oldValue, orientation);
-       }
-
+           firePropertyChange("orientation", oldValue, orientation);
+           repaint();
+       }
+
        @Mutator
-       public void setPkConnectionPoint(Point p) {
-           Point oldValue = new Point(pkConnectionPoint);
-           pkConnectionPoint = new Point(p);
-           firePropertyChange("pkConnectionPoint", oldValue, new Point(p));
+       public void setPkConnection(double pk) {
+           double oldValue = pkConnection;
+           pkConnection = pk;
+           firePropertyChange("pkConnection", oldValue, pk);
        }

        @Mutator
-       public void setFkConnectionPoint(Point p) {
-           Point oldValue = new Point(fkConnectionPoint);
-           fkConnectionPoint = new Point(p);
-               firePropertyChange("fkConnectionPoint", oldValue, new Point(p));
+       public void setFkConnection(double fk) {
+           double oldValue = fkConnection;
+           fkConnection = fk;
+               firePropertyChange("fkConnection", oldValue, fk);
        }

        // ---------------- Component Listener ----------------
@@ -461,24 +550,36 @@
             /* (non-Javadoc)
* @see ca.sqlpower.architect.swingui.PlayPenComponentListener#componentResized(ca.sqlpower.architect.swingui.PlayPenComponentEvent)
              */
- if (evt.getPropertyName().equals("bounds") && isMagicEnabled()) { + if ((evt.getPropertyName().equals("topLeftCorner") || (evt.getPropertyName().equals("lengths")))/* && isMagicEnabled()*/) { logger.debug("Component "+((PlayPenComponent)(evt.getSource())).getName()+" changed size"); //$NON-NLS-1$ //$NON-NLS-2$
-                if (((PlayPenComponent)(evt.getSource())) == pkTable) {
- setPkConnectionPoint(((RelationshipUI) getUI()).closestEdgePoint(true, getPkConnectionPoint())); // true == PK
+
+ Point pkPoint = new Point(createPkConnectionPoint().getX(), createPkConnectionPoint().getY()); + Point fkPoint = new Point(createFkConnectionPoint().getX(), createFkConnectionPoint().getY());
+
+                /*if (((PlayPenComponent)(evt.getSource())) == pkTable) {
+ setPkConnectionPoint(((RelationshipUI) getUI()).closestEdgePoint(true, pkPoint)); // true == PK
                 }
                 if (((PlayPenComponent)(evt.getSource())) == fkTable) {
- setFkConnectionPoint(((RelationshipUI) getUI()).closestEdgePoint(false, getFkConnectionPoint())); // false == FK
-                }
-
-                Rectangle oldVal = (Rectangle) evt.getOldValue();
-                Rectangle newVal = (Rectangle) evt.getNewValue();
+ setFkConnectionPoint(((RelationshipUI) getUI()).closestEdgePoint(false, fkPoint)); // false == FK
+                }*/
+                Point oldVal;
+                Point newVal;
+                if (evt.getPropertyName().equals("lengths")) {
+                    Dimension oldDim = (Dimension) evt.getOldValue();
+                    Dimension newDim = (Dimension) evt.getNewValue();
+                    oldVal = new Point(oldDim.width, oldDim.height);
+                    newVal = new Point(newDim.width, newDim.height);
+                } else {
+                    oldVal = (Point) evt.getOldValue();
+                    newVal = (Point) evt.getNewValue();
+                }
                 if(oldVal.x != newVal.x || oldVal.y != newVal.y) {
- logger.debug("Component "+((PlayPenComponent)(evt.getSource())).getName()+" moved"); //$NON-NLS-1$ //$NON-NLS-2$ + logger.debug("Component "+((PlayPenComponent)(evt.getSource())).getName()+" changed"); //$NON-NLS-1$ //$NON-NLS-2$ if (((PlayPenComponent)(evt.getSource())) == pkTable | | ((PlayPenComponent)(evt.getSource())) == fkTable) {
                         ((BasicRelationshipUI) getUI()).revalidate();
                     }
                 }
-            }
+            }
         }
        }

@@ -508,8 +609,8 @@
                public RelationshipDecorationMover(Relationship r, boolean 
movePk) {
                        this.r = r;
                        this.movingPk = movePk;
- this.startingPk = new Point(r.getPkConnectionPoint().x, r.getPkConnectionPoint().y); - this.startingFk = new Point(r.getFkConnectionPoint().x, r.getFkConnectionPoint().y); + this.startingPk = new Point(r.createPkConnectionPoint().getX(), r.createPkConnectionPoint().getY()); + this.startingFk = new Point(r.createFkConnectionPoint().getX(), r.createFkConnectionPoint().getY());
                        r.startedDragging();
                        r.getPlayPen().addMouseMotionListener(this);
                        r.getPlayPen().addMouseListener(this);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Wed Sep 8 15:54:12 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Wed Nov 3 13:56:26 2010
@@ -1256,10 +1256,10 @@
String rColorString = String.format("0x%02x%02x%02x", relationshipLineColor.getRed(), relationshipLineColor.getGreen(), relationshipLineColor.getBlue()); //$NON-NLS-1$

ioo.println(out, "<table-link relationship-ref="+quote(sqlObjectSaveIdMap.get(r.getModel())) //$NON-NLS-1$ - +" pk-x=\""+r.getPkConnectionPoint().x+"\"" //$NON-NLS-1$ //$NON-NLS-2$ - +" pk-y=\""+r.getPkConnectionPoint().y+"\"" //$NON-NLS-1$ //$NON-NLS-2$ - +" fk-x=\""+r.getFkConnectionPoint().x+"\"" //$NON-NLS-1$ //$NON-NLS-2$ - +" fk-y=\""+r.getFkConnectionPoint().y+"\"" //$NON-NLS-1$ //$NON-NLS-2$ + +" pk-x=\""+r.createPkConnectionPoint().getX()+"\"" //$NON-NLS-1$ //$NON-NLS-2$ + +" pk-y=\""+r.createPkConnectionPoint().getY()+"\"" //$NON-NLS-1$ //$NON-NLS-2$ + +" fk-x=\""+r.createFkConnectionPoint().getX()+"\"" //$NON-NLS-1$ //$NON-NLS-2$ + +" fk-y=\""+r.createFkConnectionPoint().getY()+"\"" //$NON-NLS-1$ //$NON-NLS-2$
                         +" rLineColor="+quote(rColorString) //$NON-NLS-1$
+" pkLabelText="+quote(r.getTextForParentLabel()) //$NON-NLS-1$ +" fkLabelText="+quote(r.getTextForChildLabel()) //$NON-NLS-1$
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Wed Sep 22 11:46:00 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Wed Nov 3 13:56:26 2010
@@ -223,6 +223,7 @@
         TablePaneUI ui = (TablePaneUI) BasicTablePaneUI.createUI(this);
         ui.installUI(this);
         setUI(ui);
+        updateLengths(false);
     }

        // ---------------------- utility methods ----------------------

Reply via email to