Revision: 1037
Author: heuermh
Date: Thu Aug 5 15:07:40 2010
Log: adding area and path property change notification
http://code.google.com/p/piccolo2d/source/detail?r=1037
Modified:
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java
Tue Aug 3 15:03:26 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java
Thu Aug 5 15:07:40 2010
@@ -39,7 +39,7 @@
public final class PArea extends PShape {
/** Area for this area node. */
- private transient Area area;
+ private final transient Area area;
/**
@@ -74,6 +74,26 @@
this.area.add(area);
}
+
+ /**
+ * Return a copy of the area backing this area node.
+ *
+ * @return a copy of the area backing this area node
+ */
+ public Area getArea() {
+ return (Area) area.clone();
+ }
+
+ /**
+ * Return the area backing this node. The returned area must not be
+ * modified or the bounds of this node may no longer be valid and any
+ * <code>area</code> property change listeners will not be notified.
+ *
+ * @return the area backing this area node
+ */
+ public Area getAreaReference() {
+ return area;
+ }
/**
* Add the shape of the specified area to the shape of this area node.
@@ -84,8 +104,10 @@
* @throws NullPointerException if area is null
*/
public void add(final Area area) {
+ Area oldArea = (Area) this.area.clone();
this.area.add(area);
updateBoundsFromShape();
+ firePropertyChange(-1, "area", oldArea, getArea());
}
/**
@@ -98,8 +120,10 @@
* @throws NullPointerException if area is null
*/
public void exclusiveOr(final Area area) {
+ Area oldArea = (Area) this.area.clone();
this.area.exclusiveOr(area);
updateBoundsFromShape();
+ firePropertyChange(-1, "area", oldArea, getArea());
}
/**
@@ -112,8 +136,10 @@
* @throws NullPointerException if area is null
*/
public void intersect(final Area area) {
+ Area oldArea = (Area) this.area.clone();
this.area.intersect(area);
updateBoundsFromShape();
+ firePropertyChange(-1, "area", oldArea, getArea());
}
/**
@@ -125,16 +151,20 @@
* @throws NullPointerException if area is null
*/
public void subtract(final Area area) {
+ Area oldArea = (Area) this.area.clone();
this.area.subtract(area);
updateBoundsFromShape();
+ firePropertyChange(-1, "area", oldArea, getArea());
}
/**
* Removes all of the geometry from this area node and restores it to
an empty area.
*/
public void reset() {
+ Area oldArea = (Area) area.clone();
area.reset();
updateBoundsFromShape();
+ firePropertyChange(-1, "area", oldArea, getArea());
}
/**
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
Wed Aug 4 15:04:12 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
Thu Aug 5 15:07:40 2010
@@ -48,7 +48,7 @@
public abstract class PPath extends PShape {
/** Path for this path node. */
- private Path2D path;
+ private final Path2D path;
/**
@@ -499,6 +499,26 @@
return new PPath.Double(new RoundRectangle2D.Double(x, y, width,
height, arcWidth, arcHeight));
}
+
+ /**
+ * Return a copy of the path backing this path node.
+ *
+ * @return a copy of the path backing this path node
+ */
+ public Path2D getPath() {
+ return (Path2D) path.clone();
+ }
+
+ /**
+ * Return the path backing this node. The returned path must not be
+ * modified or the bounds of this node may no longer be valid and any
+ * <code>path</code> property change listeners will not be notified.
+ *
+ * @return the path backing this path node
+ */
+ public Path2D getPathReference() {
+ return path;
+ }
/**
* Append the geometry of the specified shape to this path node,
possibly
@@ -516,8 +536,10 @@
* <code>lineTo</code> segment to connect the new geometry to the
existing path
*/
public final void append(final Shape shape, final boolean connect) {
+ Path2D oldPath = (Path2D) path.clone();
path.append(shape, connect);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -534,8 +556,10 @@
* <code>lineTo</code> segment to connect the new geometry to the
existing path
*/
public final void append(final PathIterator pathIterator, final
boolean connect) {
+ Path2D oldPath = (Path2D) path.clone();
path.append(pathIterator, connect);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -558,8 +582,10 @@
final double y2,
final double x3,
final double y3) {
+ Path2D oldPath = (Path2D) path.clone();
path.curveTo(x1, y1, x2, y2, x3, y3);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -570,8 +596,10 @@
* @param y y coordinate
*/
public final void lineTo(final double x, final double y) {
+ Path2D oldPath = (Path2D) path.clone();
path.lineTo(x, y);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -582,8 +610,10 @@
* @param y y coordinate
*/
public final void moveTo(final double x, final double y) {
+ Path2D oldPath = (Path2D) path.clone();
path.moveTo(x, y);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -599,8 +629,10 @@
* @param y2 y coordinate of the final end point
*/
public final void quadTo(final double x1, final double y1, final
double x2, final double y2) {
+ Path2D oldPath = (Path2D) path.clone();
path.quadTo(x1, y1, x2, y2);
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
/**
@@ -609,12 +641,13 @@
* has no effect.
*/
public final void closePath() {
+ Path2D oldPath = (Path2D) path.clone();
path.closePath();
updateBoundsFromShape();
+ firePropertyChange(-1, "path", oldPath, getPath());
}
// todo: setPathTo...
- // path property change events
/** {...@inheritdoc} */
protected final Shape getShape() {
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Wed Aug 4 15:04:12 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Thu Aug 5 15:07:40 2010
@@ -60,7 +60,10 @@
private static final double TOLERANCE = 0.0001d;
private static final double LOW_TOLERANCE = 1.0d;
- private MockPropertyChangeListener mockListener;
+ /** {...@inheritdoc} */
+ protected void setUp() {
+ super.setUp();
+ }
/** {...@inheritdoc} */
protected PShape createShapeNode() {
@@ -73,12 +76,6 @@
* @return a new instance of a subclass of PPath to test
*/
protected abstract PPath createPathNode();
-
- /** {...@inheritdoc} */
- protected void setUp() {
- super.setUp();
- mockListener = new MockPropertyChangeListener();
- }
// todo: rewrite in terms of createPathNode()
@@ -170,14 +167,6 @@
PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
}
*/
-
- // todo: replace with commented out test methods below
- public void testChangingPathFiresPropertyChangeEvent() {
- final PPath path = new PPath.Double();
- path.addPropertyChangeListener("path", mockListener);
- path.append(new Rectangle2D.Double(0, 0, 100, 50), true);
- assertEquals(1, mockListener.getPropertyChangeCount());
- }
public void testCreateArcFloat() {
assertNotNull(PPath.createArc(0.0f, 0.0f, 50.0f, 100.0f, 25.0f,
75.0f, Arc2D.OPEN));
@@ -423,6 +412,7 @@
path.setPath(rect);
assertEquals(1, mockListener.getPropertyChangeCount());
}
+ */
public void testAppendShapeFiresPropertyChangeEvent() {
PPath path = createPathNode();
@@ -434,6 +424,7 @@
public void testAppendPathIteratorFiresPropertyChangeEvent() {
PPath path = createPathNode();
+ path.moveTo(0.0d, 0.0d);
path.addPropertyChangeListener("path", mockListener);
Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
PathIterator pathIterator = rect.getPathIterator(new
AffineTransform());
@@ -443,6 +434,7 @@
public void testCurveToFiresPropertyChangeEvent() {
PPath path = createPathNode();
+ path.moveTo(0.0d, 0.0d);
path.addPropertyChangeListener("path", mockListener);
path.curveTo(70.0d, 140.0d, 80.0d, 140.0d, 100.0d, 200.0d);
assertEquals(1, mockListener.getPropertyChangeCount());
@@ -450,6 +442,7 @@
public void testLineToFiresPropertyChangeEvent() {
PPath path = createPathNode();
+ path.moveTo(0.0d, 0.0d);
path.addPropertyChangeListener("path", mockListener);
path.lineTo(100.0d, 200.0d);
assertEquals(1, mockListener.getPropertyChangeCount());
@@ -457,6 +450,7 @@
public void testMoveToFiresPropertyChangeEvent() {
PPath path = createPathNode();
+ path.moveTo(0.0d, 0.0d);
path.addPropertyChangeListener("path", mockListener);
path.moveTo(100.0d, 200.0d);
assertEquals(1, mockListener.getPropertyChangeCount());
@@ -464,6 +458,7 @@
public void testQuadToFiresPropertyChangeEvent() {
PPath path = createPathNode();
+ path.moveTo(0.0d, 0.0d);
path.addPropertyChangeListener("path", mockListener);
path.quadTo(70.0d, 140.0d, 100.0d, 200.0d);
assertEquals(1, mockListener.getPropertyChangeCount());
@@ -471,10 +466,10 @@
public void testClosePathFiresPropertyChangeEvent() {
PPath path = createPathNode();
- path.addPropertyChangeListener("path", mockListener);
+ path.moveTo(0.0d, 0.0d);
path.lineTo(100.0d, 200.0d);
+ path.addPropertyChangeListener("path", mockListener);
path.closePath();
assertEquals(1, mockListener.getPropertyChangeCount());
}
- */
-}
+}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
Wed Aug 4 15:04:12 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
Thu Aug 5 15:07:40 2010
@@ -42,12 +42,9 @@
*/
public abstract class AbstractPShapeTest extends AbstractPNodeTest {
- private MockPropertyChangeListener mockListener;
-
/** {...@inheritdoc} */
protected void setUp() {
super.setUp();
- mockListener = new MockPropertyChangeListener();
}
/** {...@inheritdoc} */
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
Wed Aug 4 15:04:12 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
Thu Aug 5 15:07:40 2010
@@ -50,6 +50,11 @@
private static final Rectangle2D INTERSECTION_INTERIOR = new
Rectangle2D.Double(75.0, 75.0d, 2.0d, 2.0d);
private static final Rectangle2D INTERSECTION_PATH = new
Rectangle2D.Double(75.0, 100.0d, 1.0d, 1.0d);
private static final Rectangle2D EXTERIOR = new
Rectangle2D.Double(200.0, 200.0d, 2.0d, 2.0d);
+
+ /** {...@inheritdoc} */
+ protected void setUp() {
+ super.setUp();
+ }
/** {...@inheritdoc} */
protected PShape createShapeNode() {
@@ -576,6 +581,7 @@
area.setArea(rect);
assertEquals(1, mockListener.getPropertyChangeCount());
}
+ */
public void testAddFiresPropertyChangeEvent() {
PArea area = new PArea();
@@ -587,32 +593,40 @@
public void testExclusiveOrFiresPropertyChangeEvent() {
PArea area = new PArea();
- area.addPropertyChangeListener("area", mockListener);
Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
area.add(rect0);
Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.addPropertyChangeListener("area", mockListener);
area.exclusiveOr(rect1);
- assertEquals(2, mockListener.getPropertyChangeCount());
+ assertEquals(1, mockListener.getPropertyChangeCount());
}
public void testIntersectFiresPropertyChangeEvent() {
PArea area = new PArea();
- area.addPropertyChangeListener("area", mockListener);
Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
area.add(rect0);
Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.addPropertyChangeListener("area", mockListener);
area.intersect(rect1);
- assertEquals(2, mockListener.getPropertyChangeCount());
+ assertEquals(1, mockListener.getPropertyChangeCount());
}
public void testSubtractFiresPropertyChangeEvent() {
PArea area = new PArea();
- area.addPropertyChangeListener("area", mockListener);
Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
area.add(rect0);
Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.addPropertyChangeListener("area", mockListener);
area.subtract(rect1);
- assertEquals(2, mockListener.getPropertyChangeCount());
- }
- */
-}
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testResetFiresPropertyChangeEvent() {
+ PArea area = new PArea();
+ Area rect = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.add(rect);
+ area.addPropertyChangeListener("area", mockListener);
+ area.reset();
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en