diff --git a/examples/src/build/conf/checkstyle.xml b/examples/src/build/conf/checkstyle.xml
index c04e096..2657bb4 100644
--- a/examples/src/build/conf/checkstyle.xml
+++ b/examples/src/build/conf/checkstyle.xml
@@ -92,7 +92,8 @@
-
+
+
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java
index 8fbf7ca..67a3405 100755
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/OffscreenCanvasExample.java
@@ -93,8 +93,8 @@
final PActivity toRight = canvas.getCamera().animateViewToCenterBounds(right, true, 5000);
final PActivity toLeft = canvas.getCamera().animateViewToCenterBounds(left, true, 5000);
final PActivity toStart = canvas.getCamera().animateViewToCenterBounds(start, true, 5000);
- toLeft.setStartTime(toLeft.getStartTime() + 5000);
- toStart.setStartTime(toStart.getStartTime() + 10000);
+ toLeft.startAfter(toRight);
+ toStart.startAfter(toLeft);
}
/**
@@ -125,7 +125,7 @@
final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = environment.getDefaultScreenDevice();
final OffscreenCanvasExample example = new OffscreenCanvasExample(device);
-
+
final boolean done = false;
while (!done) {
example.render();
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
index 2b1d651..906194f 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
@@ -42,6 +42,7 @@
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.Iterator;
+import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
@@ -69,9 +70,6 @@
*/
public class PrintExample extends PFrame {
- /**
- *
- */
private static final long serialVersionUID = 1L;
public PrintExample() {
@@ -89,23 +87,7 @@
final PScrollDirector windowSD = viewport.getScrollDirector();
final PScrollDirector documentSD = new DocumentScrollDirector();
- // Make some rectangles on the surface so we can see where we are
- for (int x = 0; x < 20; x++) {
- for (int y = 0; y < 20; y++) {
- if ((x + y) % 2 == 0) {
- final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- else if ((x + y) % 2 == 1) {
- final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- }
- }
+ addBackgroundShapes(canvas);
// Now, create the toolbar
final JToolBar toolBar = new JToolBar();
@@ -155,6 +137,27 @@
validate();
}
+ private void addBackgroundShapes(final PCanvas canvas) {
+ for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
+ int x = shapeCount % 21;
+ int y = (shapeCount - x) / 21;
+
+ if (shapeCount % 2 == 0) {
+ final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+ else if (shapeCount % 2 == 1) {
+ final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+
+ }
+ }
+
/**
* A modified scroll director that performs document based scroling rather
* than window based scrolling (ie. the scrollbars act in the inverse
@@ -216,54 +219,55 @@
* @param y The new y position
*/
public void setViewPosition(final double x, final double y) {
- if (camera != null) {
- // If a scroll is in progress - we ignore new scrolls -
- // if we didn't, since the scrollbars depend on the camera
- // location
- // we can end up with an infinite loop
- if (!scrollInProgress) {
- scrollInProgress = true;
+ if (camera == null)
+ return;
- // Get the union of all the layers' bounds
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
+ // If a scroll is in progress - we ignore new scrolls - if we
+ // didn't, since the scrollbars depend on the camera location
+ // we can end up with an infinite loop
+ if (scrollInProgress)
+ return;
- final PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds, layerBounds);
+ scrollInProgress = true;
- // Union the camera view bounds
- final PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates -
- // This is basically the distance from the lower right
- // corner of the window to the upper left corner of the
- // document
- // We then measure the offset from the lower right corner
- // of the document
- final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- - (y + viewBounds.getHeight()));
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
+ // Get the union of all the layers' bounds
+ final PBounds layerBounds = new PBounds();
+ final List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
}
+
+ final PAffineTransform at = camera.getViewTransform();
+ at.transform(layerBounds, layerBounds);
+
+ // Union the camera view bounds
+ final PBounds viewBounds = camera.getBoundsReference();
+ layerBounds.add(viewBounds);
+
+ // Now find the new view position in view coordinates -
+ // This is basically the distance from the lower right
+ // corner of the window to the upper left corner of the
+ // document
+ // We then measure the offset from the lower right corner
+ // of the document
+ final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
+ - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
+ - (y + viewBounds.getHeight()));
+
+ // Now transform the new view position into global coords
+ camera.localToView(newPoint);
+
+ // Compute the new matrix values to put the camera at the
+ // correct location
+ final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
+ final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
+
+ at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
+
+ // Now actually set the camera's transform
+ camera.setViewTransform(at);
+ scrollInProgress = false;
}
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
index 89d6ee3..b5b06f2 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
@@ -88,23 +88,7 @@
final PScrollDirector windowSD = viewport.getScrollDirector();
final PScrollDirector documentSD = new DocumentScrollDirector();
- // Make some rectangles on the surface so we can see where we are
- for (int x = 0; x < 20; x++) {
- for (int y = 0; y < 20; y++) {
- if ((x + y) % 2 == 0) {
- final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- else if ((x + y) % 2 == 1) {
- final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- }
- }
+ addBackgroundShapes(canvas);
// Now, create the toolbar
final JToolBar toolBar = new JToolBar();
@@ -165,32 +149,33 @@
*/
public Point getViewPosition(final Rectangle2D viewBounds) {
final Point pos = new Point();
- if (camera != null) {
- // First we compute the union of all the layers
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
+ if (camera == null)
+ return pos;
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
-
- // Rather than finding the distance from the upper left corner
- // of the window to the upper left corner of the document -
- // we instead find the distance from the lower right corner
- // of the window to the upper left corner of the document
- // THEN we measure the offset from the lower right corner
- // of the document
- pos.setLocation((int) (layerBounds.getWidth()
- - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
- .getHeight()
- - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
+ // First we compute the union of all the layers
+ final PBounds layerBounds = new PBounds();
+ final java.util.List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
}
+ // Then we put the bounds into camera coordinates and
+ // union the camera bounds
+ camera.viewToLocal(layerBounds);
+ layerBounds.add(viewBounds);
+
+ // Rather than finding the distance from the upper left corner
+ // of the window to the upper left corner of the document -
+ // we instead find the distance from the lower right corner
+ // of the window to the upper left corner of the document
+ // THEN we measure the offset from the lower right corner
+ // of the document
+ pos.setLocation((int) (layerBounds.getWidth()
+ - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
+ .getHeight()
+ - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
+
return pos;
}
@@ -203,54 +188,75 @@
* @param y The new y position
*/
public void setViewPosition(final double x, final double y) {
- if (camera != null) {
- // If a scroll is in progress - we ignore new scrolls -
- // if we didn't, since the scrollbars depend on the camera
- // location
- // we can end up with an infinite loop
- if (!scrollInProgress) {
- scrollInProgress = true;
+ if (camera == null)
+ return;
- // Get the union of all the layers' bounds
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
+ // If a scroll is in progress - we ignore new scrolls - if we
+ // didn't, since the scrollbars depend on the camera
+ // location we can end up with an infinite loop
+ if (scrollInProgress)
+ return;
- final PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds, layerBounds);
+ scrollInProgress = true;
- // Union the camera view bounds
- final PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates -
- // This is basically the distance from the lower right
- // corner of the window to the upper left corner of the
- // document
- // We then measure the offset from the lower right corner
- // of the document
- final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- - (y + viewBounds.getHeight()));
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
+ // Get the union of all the layers' bounds
+ final PBounds layerBounds = new PBounds();
+ final java.util.List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
}
+
+ final PAffineTransform at = camera.getViewTransform();
+ at.transform(layerBounds, layerBounds);
+
+ // Union the camera view bounds
+ final PBounds viewBounds = camera.getBoundsReference();
+ layerBounds.add(viewBounds);
+
+ // Now find the new view position in view coordinates -
+ // This is basically the distance from the lower right
+ // corner of the window to the upper left corner of the
+ // document. We then measure the offset from the lower right corner
+ // of the document
+ final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
+ - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
+ - (y + viewBounds.getHeight()));
+
+ // Now transform the new view position into global coords
+ camera.localToView(newPoint);
+
+ // Compute the new matrix values to put the camera at the
+ // correct location
+ final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
+ final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
+
+ at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
+
+ // Now actually set the camera's transform
+ camera.setViewTransform(at);
+ scrollInProgress = false;
+ }
+ }
+
+ private void addBackgroundShapes(final PCanvas canvas) {
+ for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
+ int x = shapeCount % 21;
+ int y = (shapeCount - x) / 21;
+
+ if (shapeCount % 2 == 0) {
+ final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+ else if (shapeCount % 2 == 1) {
+ final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+
}
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/swt/SWTBenchTest.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/swt/SWTBenchTest.java
index b54ca4a..634dfcd 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/swt/SWTBenchTest.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/swt/SWTBenchTest.java
@@ -191,8 +191,9 @@
}
Image loadImage(final Display display, final String name) {
+ InputStream stream = null;
try {
- final InputStream stream = SWTBenchTest.class.getResourceAsStream(name);
+ stream = SWTBenchTest.class.getResourceAsStream(name);
if (stream != null) {
final ImageData imageData = new ImageData(stream);
return new Image(display, imageData);
@@ -204,6 +205,7 @@
}
}
catch (final Exception e) {
+ throw new RuntimeException(e);
}
return null;
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/PApplet.java b/extras/src/main/java/edu/umd/cs/piccolox/PApplet.java
index 69efc97..bfac115 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/PApplet.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/PApplet.java
@@ -43,7 +43,7 @@
public class PApplet extends JApplet {
/** Used to allow versioned binary streams for serializations. */
private static final long serialVersionUID = 1L;
-
+
/** Canvas being displayed by this applet. */
private PCanvas canvas;
@@ -91,7 +91,7 @@
return new PCanvas();
}
- /**
+ /**
* This method will be called before the initialize() method and will be
* called on the thread that is constructing this object.
*/
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/PFrame.java b/extras/src/main/java/edu/umd/cs/piccolox/PFrame.java
index 770b52f..a7337fd 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/PFrame.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/PFrame.java
@@ -109,7 +109,8 @@
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch (final SecurityException e) {
- // expected from applets
+ // expected from Applets
+ System.out.println("Ignoring security exception. Assuming Applet Context.");
}
if (aCanvas == null) {
@@ -126,9 +127,9 @@
beforeInitialize();
// Manipulation of Piccolo's scene graph should be done from Swings
- // event dispatch thread since Piccolo is not thread safe. This code
+ // event dispatch thread since Piccolo2D is not thread safe. This code
// calls initialize() from that thread once the PFrame is initialized,
- // so you are safe to start working with Piccolo in the initialize()
+ // so you are safe to start working with Piccolo2D in the initialize()
// method.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
@@ -295,10 +296,10 @@
}
/**
- * Subclasses should override this method and add their Piccolo
+ * Subclasses should override this method and add their Piccolo2D
* initialization code there. This method will be called on the swing event
* dispatch thread. Note that the constructors of PFrame subclasses may not
- * be complete when this method is called. If you need to initailize some
+ * be complete when this method is called. If you need to initialize some
* things in your class before this method is called place that code in
* beforeInitialize();
*/