Revision: 3509
Author: [email protected]
Date: Thu May 6 15:50:49 2010
Log: The new approach to handling the location of the play pen components
is to store the bounds of the object even though
we only care about the xy position. In addition we are no longer caring
about what is stored for the width and height of
the component but calculate it on the fly. This is the normal SWT and Swing
approach to handling the position and size of
a component instead of splitting the bounds into a position and size.
http://code.google.com/p/power-architect/source/detail?r=3509
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPaneUI.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Thu May 6 13:40:41 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Thu May 6 15:50:49 2010
@@ -49,9 +49,7 @@
import ca.sqlpower.architect.ArchitectSessionContext;
import ca.sqlpower.architect.ArchitectSessionImpl;
import ca.sqlpower.architect.ddl.DDLGenerator;
-import
ca.sqlpower.architect.enterprise.NetworkConflictResolver.UpdateListener;
import ca.sqlpower.architect.swingui.ArchitectSwingSessionContext;
-import ca.sqlpower.architect.swingui.PlayPenComponent;
import ca.sqlpower.dao.SPPersistenceException;
import ca.sqlpower.dao.SPPersisterListener;
import ca.sqlpower.dao.json.SPJSONMessageDecoder;
@@ -131,35 +129,6 @@
static {
securitySessions = new HashMap<String,
ArchitectClientSideSession>();
}
-
- /**
- * Calls revalidate on all UI components changed in the last commit
since this
- * must be done at a point when magic is enabled again so the
revalidate
- * actually takes effect.
- */
- private final UpdateListener revalidateUIComponentsListener = new
UpdateListener() {
-
- public void workspaceDeleted() {
- //do nothing
- }
-
- @SuppressWarnings("unchecked")
- public boolean updatePerformed(NetworkConflictResolver resolver) {
- for (PlayPenComponent cp :
sessionPersister.getComponentsToRevalidate()) {
- cp.revalidate();
- }
- return false;
- }
-
- public boolean updateException(NetworkConflictResolver resolver) {
- //do nothing
- return false;
- }
-
- public void preUpdatePerformed(NetworkConflictResolver resolver) {
- //do nothing
- }
- };
public ArchitectClientSideSession(ArchitectSessionContext context,
String name, ProjectLocation projectLocation) throws SQLObjectException
{
@@ -198,8 +167,6 @@
createHttpClient(projectLocation.getServiceInfo()),
outboundHttpClient, this);
- updater.addListener(revalidateUIComponentsListener);
-
jsonPersister = new SPJSONPersister(updater);
try {
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
Thu May 6 09:12:07 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
Thu May 6 15:50:49 2010
@@ -21,7 +21,6 @@
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -92,22 +91,16 @@
super(name, root, converter);
SQLPowerUtils.listenToHierarchy(root, ppcRevalidateListener);
}
-
- /**
- * Returns a collection of components that were updated by the
- * last commit to the server. These components may need to be
revalidated as
- * they are used to display the UI.
- */
- public Set<PlayPenComponent> getComponentsToRevalidate() {
- return Collections.unmodifiableSet(componentsToRevalidate);
- }
-
@Override
public void commit() throws SPPersistenceException {
synchronized(getWorkspaceContainer().getWorkspace()) {
componentsToRevalidate.clear();
super.commit();
+ for (PlayPenComponent ppc : componentsToRevalidate) {
+ ppc.repaint();
+ }
+ componentsToRevalidate.clear();
}
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
Tue Apr 6 14:44:35 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
Thu May 6 15:50:49 2010
@@ -118,7 +118,7 @@
public void revalidate() {
Rectangle OldBounds = computedBounds;
Rectangle bounds = computeBounds();
- if (!computedBounds.equals(OldBounds)) {
+ if (computedBounds.x != OldBounds.x || computedBounds.y !=
OldBounds.y) {
relationship.setBounds(bounds.x,bounds.y,bounds.width,bounds.height);
}
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java
Thu May 6 09:12:07 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java
Thu May 6 15:50:49 2010
@@ -20,7 +20,6 @@
package ca.sqlpower.architect.swingui;
import java.awt.Color;
-import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
@@ -656,15 +655,4 @@
return getName();
}
- @Transient @Accessor
- @Override
- public Dimension getSize() {
- return super.getSize();
- }
-
- @Transient @Mutator
- @Override
- public void setSize(Dimension size) {
- super.setSize(size);
- }
-}
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Thu May 6 11:44:01 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Thu May 6 15:50:49 2010
@@ -62,13 +62,8 @@
private static final Logger logger =
Logger.getLogger(PlayPenComponent.class);
public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections.emptyList();
-
- /**
- * The top left point of the component.
- */
- private Point location = new Point();
- private Dimension size = new Dimension();
-
+
+ private Rectangle bounds = new Rectangle();
private Dimension minimumSize = new Dimension();
protected Color backgroundColor;
protected Color foregroundColor;
@@ -140,11 +135,8 @@
protected PlayPenComponent(PlayPenComponent copyMe, PlayPenContentPane
parent) {
this(copyMe.getName(), parent);
backgroundColor = copyMe.backgroundColor;
- if (copyMe.location != null) {
- location = new Point(copyMe.location);
- }
- if (copyMe.size != null) {
- size = new Dimension(copyMe.size);
+ if (copyMe.bounds != null) {
+ bounds = new Rectangle(copyMe.bounds);
}
componentPreviouslySelected = copyMe.componentPreviouslySelected;
foregroundColor = copyMe.foregroundColor;
@@ -224,7 +216,7 @@
logger.debug("getPlayPen() returned null. Not generating
repaint request."); //$NON-NLS-1$
return;
} else {
- Rectangle r = new Rectangle(location.x, location.y,
size.width, size.height);
+ Rectangle r = new Rectangle(bounds);
if (isMagicEnabled()) {
// This temporary disabling of magic is under the
// assumption that this method properly revalidates
@@ -234,8 +226,6 @@
PlayPenComponentUI ui = getUI();
if (ui != null) {
ui.revalidate();
- Dimension ps = ui.getPreferredSize();
- if (ps != null) setSize(ps);
}
if (logger.isDebugEnabled()) logger.debug("Scheduling
repaint at "+r); //$NON-NLS-1$
setMagicEnabled(true);
@@ -260,7 +250,7 @@
setBounds(new Rectangle(x, y, width, height));
}
- @Transient @Mutator
+ @Mutator
public void setBounds(Rectangle r) {
Rectangle oldBounds = getBounds();
repaint();
@@ -270,10 +260,8 @@
+" to ["+r.x+","+r.y+","+r.width+","+r.height+"]");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
- setLocation(r.x, r.y);
- setSize(new Dimension(r.width, r.height));
- firePropertyChange("bounds", oldBounds, new
Rectangle(getLocation().x, getLocation().y,
- getSize().width, getSize().height));
+ bounds.setBounds(r.x,r.y,r.width,r.height);
+ firePropertyChange("bounds", oldBounds, new Rectangle(bounds));
repaint();
}
@@ -281,7 +269,7 @@
/**
* Returns a copy of this component's bounding rectangle.
*/
- @Transient @Accessor
+ @Accessor
public Rectangle getBounds() {
return getBounds(null);
}
@@ -320,13 +308,13 @@
@NonBound
public Rectangle getBounds(Rectangle r) {
if (r == null) r = new Rectangle();
- r.setBounds(getLocation().x, getLocation().y, getSize().width,
getSize().height);
+ r.setBounds(bounds);
return r;
}
- @Accessor(isInteresting=true)
+ @Transient @Accessor(isInteresting=true)
public Dimension getSize() {
- return new Dimension(size);
+ return new Dimension(bounds.width, bounds.height);
}
/**
@@ -351,11 +339,11 @@
* create a new point for you.
* @return p if p was not null; a new point otherwise.
*/
- @Accessor
+ @Transient @Accessor
public Point getLocation(Point p) {
if (p == null) p = new Point();
- p.x = location.x;
- p.y = location.y;
+ p.x = bounds.x;
+ p.y = bounds.y;
return p;
}
@@ -364,38 +352,28 @@
* component to a negative co-ordinate, it will automatically be
normalized (along
* with everything else in the playpen) to non-negative coordinates.
*/
- @Mutator
+ @Transient @Mutator
public void setLocation(Point point) {
- Point oldLocation = location;
- repaint();
+ Point oldLocation = bounds.getLocation();
int width = getWidth();
int height = getHeight();
- Rectangle oldBounds = new Rectangle(getLocation().x,
getLocation().y,
- getSize().width, getSize().height);
-
- if (isMagicEnabled()) {
- if (getPlayPen() != null) {
- PlayPenComponentUI ui = getUI();
-
- if (ui != null) {
- ui.revalidate();
- Dimension ps = ui.getPreferredSize();
- if (ps != null) {
- width = ps.width;
- height = ps.height;
- }
+ if (getPlayPen() != null) {
+ PlayPenComponentUI ui = getUI();
+
+ if (ui != null) {
+ ui.revalidate();
+ Dimension ps = ui.getPreferredSize();
+ if (ps != null) {
+ width = ps.width;
+ height = ps.height;
}
}
- setSize(new Dimension(width, height));
}
- location = new Point(point.x, point.y);
+ setBounds(point.x,point.y, width, height);
firePropertyChange("location", oldLocation, point);
- firePropertyChange("bounds", oldBounds, new
Rectangle(getLocation().x, getLocation().y,
- getSize().width, getSize().height));
- repaint();
}
/**
@@ -415,15 +393,9 @@
return (oldVal.x != newVal.x || oldVal.y != newVal.y);
}
- @Mutator
+ @Transient @Mutator
public void setSize(Dimension size) {
- Rectangle oldBounds = new Rectangle(getLocation().x,
getLocation().y,
- getSize().width, getSize().height);
- Dimension oldSize = this.size;
- this.size = new Dimension(size);
- firePropertyChange("size", oldSize, this.size);
- firePropertyChange("bounds", oldBounds, new
Rectangle(getLocation().x, getLocation().y,
- getSize().width, getSize().height));
+ setBounds(getX(), getY(), size.width, size.height);
}
/**
@@ -450,22 +422,22 @@
@Transient @Accessor
public int getX() {
- return getLocation().x;
+ return bounds.x;
}
@Transient @Accessor
public int getY() {
- return getLocation().y;
+ return bounds.y;
}
@Transient @Accessor
public int getWidth() {
- return getSize().width;
+ return bounds.width;
}
@Transient @Accessor
public int getHeight() {
- return getSize().height;
+ return bounds.height;
}
@Transient @Accessor
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPaneUI.java
Wed Mar 17 14:29:59 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/olap/OLAPPaneUI.java
Thu May 6 15:50:49 2010
@@ -283,7 +283,6 @@
}
public void revalidate() {
- olapPane.setSize(getPreferredSize());
}
/**