diff --git a/examples/pom.xml b/examples/pom.xml
index 26df2be..996ff7f 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -1,45 +1,45 @@
- 4.0.0
-
- piccolo2d-parent
- org.piccolo2d
- 1.3-SNAPSHOT
- ../parent/pom.xml
-
- piccolo2d-examples
- Piccolo2D Examples
- http://code.google.com/p/piccolo2d/
-
- A revolutionary way to create robust, full-featured graphical
- applications in Java and C#, with striking visual effects such
- as zooming, animation and multiple representations.
-
-
-
- org.piccolo2d
- piccolo2d-extras
- ${project.version}
-
-
-
-
-
-
- maven-javadoc-plugin
-
- 1.4
- false
- package
-
-
- http://java.sun.com/j2se/1.4.2/docs/api/
-
-
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+4.0.0
+
+ piccolo2d-parent
+ org.piccolo2d
+ 1.3-SNAPSHOT
+ ../parent/pom.xml
+
+ piccolo2d-examples
+ Piccolo2D Examples
+ http://code.google.com/p/piccolo2d/
+
+ A revolutionary way to create robust, full-featured graphical
+ applications in Java and C#, with striking visual effects such
+ as zooming, animation and multiple representations.
+
+
+
+ org.piccolo2d
+ piccolo2d-extras
+ ${project.version}
+
+
+
+
+
+
+ maven-javadoc-plugin
+
+ 1.4
+ false
+ package
+
+
+ http://java.sun.com/j2se/1.4.2/docs/api/
+
+
+
+ maven-checkstyle-plugin
@@ -47,6 +47,6 @@
false
-
-
+
+
diff --git a/examples/src/build/conf/checkstyle.xml b/examples/src/build/conf/checkstyle.xml
index 446472a..c4f2ce0 100644
--- a/examples/src/build/conf/checkstyle.xml
+++ b/examples/src/build/conf/checkstyle.xml
@@ -36,10 +36,6 @@
-
-
-
-
@@ -97,7 +93,9 @@
-
+
+
+
@@ -128,7 +126,9 @@
-
+
+
+
@@ -159,10 +159,6 @@
-
-
-
-
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
index 6fcbbc2..a0a31b5 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCanvas;
@@ -13,72 +14,76 @@
*/
public class ActivityExample extends PFrame {
- public ActivityExample() {
- this(null);
- }
-
- public ActivityExample(PCanvas aCanvas) {
- super("ActivityExample", false, aCanvas);
- }
-
- public void initialize() {
- long currentTime = System.currentTimeMillis();
-
- // Create a new node that we will apply different activities to, and
- // place that node at location 200, 200.
- final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
- aNode.setOffset(200, 200);
-
- // Create a new custom "flash" activity. This activity will start running in
- // five seconds, and while it runs it will flash aNode's paint between
- // red and green every half second.
- PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- if (fRed) {
- aNode.setPaint(Color.red);
- } else {
- aNode.setPaint(Color.green);
- }
-
- fRed = !fRed;
- }
- };
-
- // An activity will not run unless it is scheduled with the root. Once
- // it has been scheduled it will be given a chance to run during the next
- // PRoot.processInputs() call.
- getCanvas().getRoot().addActivity(flash);
-
- // Use the PNode animate methods to create three activities that animate
- // the node's position. Since our node already descends from the root node the
- // animate methods will automatically schedule these activities for us.
- PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
- PActivity a4 = aNode.animateToTransparency(0.25f, 3000);
+ public ActivityExample() {
+ this(null);
+ }
- // the animate activities will start immediately (in the next call to PRoot.processInputs)
- // by default. Here we set their start times (in PRoot global time) so that they start
- // when the previous one has finished.
- a1.setStartTime(currentTime);
-
- a2.startAfter(a1);
- a3.startAfter(a2);
- a4.startAfter(a3);
-
- // or the previous three lines could be replaced with these lines for the same effect.
- //a2.setStartTime(currentTime + 5000);
- //a3.setStartTime(currentTime + 10000);
- //a4.setStartTime(currentTime + 15000);
- }
+ public ActivityExample(PCanvas aCanvas) {
+ super("ActivityExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new ActivityExample();
- }
+ public void initialize() {
+ long currentTime = System.currentTimeMillis();
+
+ // Create a new node that we will apply different activities to, and
+ // place that node at location 200, 200.
+ final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(aNode);
+ aNode.setOffset(200, 200);
+
+ // Create a new custom "flash" activity. This activity will start
+ // running in five seconds, and while it runs it will flash aNode's
+ // paint between red and green every half second.
+ PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
+ boolean fRed = true;
+
+ protected void activityStep(long elapsedTime) {
+ super.activityStep(elapsedTime);
+
+ if (fRed) {
+ aNode.setPaint(Color.red);
+ }
+ else {
+ aNode.setPaint(Color.green);
+ }
+
+ fRed = !fRed;
+ }
+ };
+
+ // An activity will not run unless it is scheduled with the root. Once
+ // it has been scheduled it will be given a chance to run during the
+ // next PRoot.processInputs() call.
+ getCanvas().getRoot().addActivity(flash);
+
+ // Use the PNode animate methods to create three activities that animate
+ // the node's position. Since our node already descends from the root
+ // node the animate methods will automatically schedule these activities
+ // for us.
+ PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
+ PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
+ PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
+ PActivity a4 = aNode.animateToTransparency(0.25f, 3000);
+
+ // the animate activities will start immediately (in the next call to
+ // PRoot.processInputs) by default. Here we set their start times (in
+ // PRoot global time) so that they start when the previous one has
+ // finished.
+ a1.setStartTime(currentTime);
+
+ a2.startAfter(a1);
+ a3.startAfter(a2);
+ a4.startAfter(a3);
+
+ // or the previous three lines could be replaced with these lines for
+ // the same effect.
+ // a2.setStartTime(currentTime + 5000);
+ // a3.setStartTime(currentTime + 10000);
+ // a4.setStartTime(currentTime + 15000);
+ }
+
+ public static void main(String[] args) {
+ new ActivityExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
index 7524a94..781cd9a 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
@@ -25,96 +25,106 @@
*/
public class AngleNodeExample extends PFrame {
- public AngleNodeExample() {
- this(null);
- }
-
- public AngleNodeExample(PCanvas aCanvas) {
- super("AngleNodeExample", false, aCanvas);
- }
+ public AngleNodeExample() {
+ this(null);
+ }
- public void initialize() {
- PCanvas c = getCanvas();
- PLayer l = c.getLayer();
- l.addChild(new AngleNode());
- }
-
- public static void main(String[] args) {
- new AngleNodeExample();
- }
+ public AngleNodeExample(PCanvas aCanvas) {
+ super("AngleNodeExample", false, aCanvas);
+ }
- // the angle node class
- public static class AngleNode extends PNode {
- protected Point2D.Double pointOne;
- protected Point2D.Double pointTwo;
- protected Stroke stroke;
-
- public AngleNode() {
- pointOne = new Point2D.Double(100, 0);
- pointTwo = new Point2D.Double(0, 100);
- stroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
- setPaint(Color.BLACK);
- updateBounds();
- addHandles();
- }
-
- public void addHandles() {
- // point one
- PLocator l = new PLocator() {
- public double locateX() { return pointOne.getX(); }
- public double locateY() { return pointOne.getY(); }
- };
- PHandle h = new PHandle(l) {
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointOne.setLocation(pointOne.getX() + aLocalDimension.getWidth(),
- pointOne.getY() + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
-
- // point two
- l = new PLocator() {
- public double locateX() { return pointTwo.getX(); }
- public double locateY() { return pointTwo.getY(); }
- };
- h = new PHandle(l) {
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointTwo.setLocation(pointTwo.getX() + aLocalDimension.getWidth(),
- pointTwo.getY() + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
- }
-
- protected void paint(PPaintContext paintContext) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setStroke(stroke);
- g2.setPaint(getPaint());
- g2.draw(getAnglePath());
- }
-
- protected void updateBounds() {
- GeneralPath p = getAnglePath();
- Rectangle2D b = stroke.createStrokedShape(p).getBounds2D();
- super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
- }
-
- public GeneralPath getAnglePath() {
- GeneralPath p = new GeneralPath();
- p.moveTo((float)pointOne.getX(), (float)pointOne.getY());
- p.lineTo(0, 0);
- p.lineTo((float)pointTwo.getX(), (float)pointTwo.getY());
- return p;
- }
-
- public boolean setBounds(double x, double y, double width, double height) {
- return false; // bounds can be set externally
- }
- }
+ public void initialize() {
+ PCanvas c = getCanvas();
+ PLayer l = c.getLayer();
+ l.addChild(new AngleNode());
+ }
+
+ public static void main(String[] args) {
+ new AngleNodeExample();
+ }
+
+ // the angle node class
+ public static class AngleNode extends PNode {
+ protected Point2D.Double pointOne;
+ protected Point2D.Double pointTwo;
+ protected Stroke stroke;
+
+ public AngleNode() {
+ pointOne = new Point2D.Double(100, 0);
+ pointTwo = new Point2D.Double(0, 100);
+ stroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
+ setPaint(Color.BLACK);
+ updateBounds();
+ addHandles();
+ }
+
+ public void addHandles() {
+ // point one
+ PLocator l = new PLocator() {
+ public double locateX() {
+ return pointOne.getX();
+ }
+
+ public double locateY() {
+ return pointOne.getY();
+ }
+ };
+ PHandle h = new PHandle(l) {
+ public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
+ localToParent(aLocalDimension);
+ pointOne.setLocation(pointOne.getX() + aLocalDimension.getWidth(), pointOne.getY()
+ + aLocalDimension.getHeight());
+ updateBounds();
+ relocateHandle();
+ }
+ };
+ addChild(h);
+
+ // point two
+ l = new PLocator() {
+ public double locateX() {
+ return pointTwo.getX();
+ }
+
+ public double locateY() {
+ return pointTwo.getY();
+ }
+ };
+ h = new PHandle(l) {
+ public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
+ localToParent(aLocalDimension);
+ pointTwo.setLocation(pointTwo.getX() + aLocalDimension.getWidth(), pointTwo.getY()
+ + aLocalDimension.getHeight());
+ updateBounds();
+ relocateHandle();
+ }
+ };
+ addChild(h);
+ }
+
+ protected void paint(PPaintContext paintContext) {
+ Graphics2D g2 = paintContext.getGraphics();
+ g2.setStroke(stroke);
+ g2.setPaint(getPaint());
+ g2.draw(getAnglePath());
+ }
+
+ protected void updateBounds() {
+ GeneralPath p = getAnglePath();
+ Rectangle2D b = stroke.createStrokedShape(p).getBounds2D();
+ super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
+ }
+
+ public GeneralPath getAnglePath() {
+ GeneralPath p = new GeneralPath();
+ p.moveTo((float) pointOne.getX(), (float) pointOne.getY());
+ p.lineTo(0, 0);
+ p.lineTo((float) pointTwo.getX(), (float) pointTwo.getY());
+ return p;
+ }
+
+ public boolean setBounds(double x, double y, double width, double height) {
+ return false; // bounds can be set externally
+ }
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
index bc54c08..e9a76e5 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
@@ -28,405 +28,396 @@
import edu.umd.cs.piccolox.nodes.P3DRect;
/**
- * This example, contributed by Rowan Christmas, shows how to
- * create a birds-eye view window.
+ * This example, contributed by Rowan Christmas, shows how to create a birds-eye
+ * view window.
*/
public class BirdsEyeViewExample extends PFrame {
- boolean fIsPressed = false;
+ boolean fIsPressed = false;
- public BirdsEyeViewExample() {
- this(null);
- }
+ public BirdsEyeViewExample() {
+ this(null);
+ }
- public BirdsEyeViewExample(PCanvas aCanvas) {
- super("BirdsEyeViewExample", false, aCanvas);
- }
+ public BirdsEyeViewExample(PCanvas aCanvas) {
+ super("BirdsEyeViewExample", false, aCanvas);
+ }
- public void initialize() {
+ public void initialize() {
- nodeDemo();
- createNodeUsingExistingClasses();
- subclassExistingClasses();
- composeOtherNodes();
- createCustomNode();
+ nodeDemo();
+ createNodeUsingExistingClasses();
+ subclassExistingClasses();
+ composeOtherNodes();
+ createCustomNode();
- // Last of all lets remove the default pan event handler, and add a
- // drag event handler instead. This way you will be able to drag the
- // nodes around with the mouse.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
+ // Last of all lets remove the default pan event handler, and add a
+ // drag event handler instead. This way you will be able to drag the
+ // nodes around with the mouse.
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PDragEventHandler());
- // this will create the actual BirdsEyeView and put it in a JDialog
- BirdsEyeView bev = new BirdsEyeView();
- bev.connect(getCanvas(), new PLayer[]{getCanvas().getLayer()});
- JDialog bird = new JDialog();
- bird.getContentPane().add(bev);
- bird.pack();
- bird.setSize(150, 150);
- bird.setVisible(true);
+ // this will create the actual BirdsEyeView and put it in a JDialog
+ BirdsEyeView bev = new BirdsEyeView();
+ bev.connect(getCanvas(), new PLayer[] { getCanvas().getLayer() });
+ JDialog bird = new JDialog();
+ bird.getContentPane().add(bev);
+ bird.pack();
+ bird.setSize(150, 150);
+ bird.setVisible(true);
- }
+ }
- // This method demonstrates the kinds of things that can be done with any
- // node.
- public void nodeDemo() {
- PLayer layer = getCanvas().getLayer();
- PNode aNode = PPath.createRectangle(0, 0, 100, 80);
+ // This method demonstrates the kinds of things that can be done with any
+ // node.
+ public void nodeDemo() {
+ PLayer layer = getCanvas().getLayer();
+ PNode aNode = PPath.createRectangle(0, 0, 100, 80);
- // A node needs to be a descendent of the root to be displayed on the
- // screen.
- layer.addChild(aNode);
+ // A node needs to be a descendent of the root to be displayed on the
+ // screen.
+ layer.addChild(aNode);
- // The default color for a node is blue, but you can change that with
- // the setPaint method.
- aNode.setPaint(Color.red);
+ // The default color for a node is blue, but you can change that with
+ // the setPaint method.
+ aNode.setPaint(Color.red);
- // A node can have children nodes added to it.
- aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
+ // A node can have children nodes added to it.
+ aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
- // The base bounds of a node is easy to change. Note that changing the
- // base
- // bounds of a node will not change it's children.
- aNode.setBounds(-10, -10, 200, 110);
+ // The base bounds of a node is easy to change. Note that changing the
+ // base bounds of a node will not change it's children.
+ aNode.setBounds(-10, -10, 200, 110);
- // Each node has a transform that can be used to transform the node, and
- // all its children on the screen.
- aNode.translate(100, 100);
- aNode.scale(1.5);
- aNode.rotate(45);
+ // Each node has a transform that can be used to transform the node, and
+ // all its children on the screen.
+ aNode.translate(100, 100);
+ aNode.scale(1.5);
+ aNode.rotate(45);
- // The transparency of any node can be set, this transparency will be
- // applied to any of the nodes children as well.
- aNode.setTransparency(0.75f);
+ // The transparency of any node can be set, this transparency will be
+ // applied to any of the nodes children as well.
+ aNode.setTransparency(0.75f);
- // Its easy to copy nodes.
- PNode aCopy = (PNode) aNode.clone();
+ // Its easy to copy nodes.
+ PNode aCopy = (PNode) aNode.clone();
- // Make is so that the copies children are not pickable. For this
- // example
- // that means you will not be able to grab the child and remove it from
- // its parent.
- aNode.setChildrenPickable(false);
+ // Make is so that the copies children are not pickable. For this
+ // example that means you will not be able to grab the child and remove
+ // it from its parent.
+ aNode.setChildrenPickable(false);
- // Change the look of the copy
- aNode.setPaint(Color.GREEN);
- aNode.setTransparency(1.0f);
+ // Change the look of the copy
+ aNode.setPaint(Color.GREEN);
+ aNode.setTransparency(1.0f);
- // Let's add the copy to the root, and translate it so that it does not
- // cover the original node.
- layer.addChild(aCopy);
- aCopy.setOffset(0, 0);
- aCopy.rotate(-45);
- }
+ // Let's add the copy to the root, and translate it so that it does not
+ // cover the original node.
+ layer.addChild(aCopy);
+ aCopy.setOffset(0, 0);
+ aCopy.rotate(-45);
+ }
- // So far we have just been using PNode, but of course PNode has many
- // subclasses that you can try out to.
- public void createNodeUsingExistingClasses() {
- PLayer layer = getCanvas().getLayer();
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
+ // So far we have just been using PNode, but of course PNode has many
+ // subclasses that you can try out to.
+ public void createNodeUsingExistingClasses() {
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(PPath.createEllipse(0, 0, 100, 100));
+ layer.addChild(PPath.createRectangle(0, 100, 100, 100));
+ layer.addChild(new PText("Hello World"));
- // Here we create an image node that displays a thumbnail
- // image of the root node. Note that you can easily get a thumbnail
- // of any node by using PNode.toImage().
- layer.addChild(new PImage(layer.toImage(300, 300, Color.YELLOW)));
- }
+ // Here we create an image node that displays a thumbnail
+ // image of the root node. Note that you can easily get a thumbnail
+ // of any node by using PNode.toImage().
+ layer.addChild(new PImage(layer.toImage(300, 300, Color.YELLOW)));
+ }
- // Another way to create nodes is to customize other nodes that already
- // exist. Here we create an ellipse, except when you press the mouse on
- // this ellipse it turns into a square, when you release the mouse it
- // goes back to being an ellipse.
- public void subclassExistingClasses() {
- final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
+ // Another way to create nodes is to customize other nodes that already
+ // exist. Here we create an ellipse, except when you press the mouse on
+ // this ellipse it turns into a square, when you release the mouse it
+ // goes back to being an ellipse.
+ public void subclassExistingClasses() {
+ final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
- public void paint(PPaintContext aPaintContext) {
- if (fIsPressed) {
- // if mouse is pressed draw self as a square.
- Graphics2D g2 = aPaintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- // if mouse is not pressed draw self normally.
- super.paint(aPaintContext);
- }
- }
- };
+ public void paint(PPaintContext aPaintContext) {
+ if (fIsPressed) {
+ // if mouse is pressed draw self as a square.
+ Graphics2D g2 = aPaintContext.getGraphics();
+ g2.setPaint(getPaint());
+ g2.fill(getBoundsReference());
+ }
+ else {
+ // if mouse is not pressed draw self normally.
+ super.paint(aPaintContext);
+ }
+ }
+ };
- n.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = true;
- n.invalidatePaint(); // this tells the framework that the node
- // needs to be redisplayed.
- }
+ n.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent aEvent) {
+ super.mousePressed(aEvent);
+ fIsPressed = true;
+ n.invalidatePaint(); // this tells the framework that the node
+ // needs to be redisplayed.
+ }
- public void mouseReleased(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = false;
- n.invalidatePaint(); // this tells the framework that the node
- // needs to be redisplayed.
- }
- });
+ public void mouseReleased(PInputEvent aEvent) {
+ super.mousePressed(aEvent);
+ fIsPressed = false;
+ n.invalidatePaint(); // this tells the framework that the node
+ // needs to be redisplayed.
+ }
+ });
- n.setPaint(Color.ORANGE);
- getCanvas().getLayer().addChild(n);
- }
+ n.setPaint(Color.ORANGE);
+ getCanvas().getLayer().addChild(n);
+ }
- // Here a new "face" node is created. But instead of drawing the face
- // directly
- // using Graphics2D we compose the face from other nodes.
- public void composeOtherNodes() {
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
+ // Here a new "face" node is created. But instead of drawing the face
+ // directly using Graphics2D we compose the face from other nodes.
+ public void composeOtherNodes() {
+ PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
- // create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
+ // create parts for the face.
+ PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
+ eye1.setPaint(Color.YELLOW);
+ PNode eye2 = (PNode) eye1.clone();
+ PNode mouth = PPath.createRectangle(0, 0, 40, 20);
+ mouth.setPaint(Color.BLACK);
- // add the face parts
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
+ // add the face parts
+ myCompositeFace.addChild(eye1);
+ myCompositeFace.addChild(eye2);
+ myCompositeFace.addChild(mouth);
- // don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
+ // don't want anyone grabbing out our eye's.
+ myCompositeFace.setChildrenPickable(false);
- // position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
+ // position the face parts.
+ eye2.translate(25, 0);
+ mouth.translate(0, 30);
- // set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- myCompositeFace.setBounds(b.inset(-5, -5));
+ // set the face bounds so that it neatly contains the face parts.
+ PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
+ myCompositeFace.setBounds(b.inset(-5, -5));
- // opps it to small, so scale it up.
- myCompositeFace.scale(1.5);
+ // opps it to small, so scale it up.
+ myCompositeFace.scale(1.5);
- getCanvas().getLayer().addChild(myCompositeFace);
- }
+ getCanvas().getLayer().addChild(myCompositeFace);
+ }
- // Here a completely new kind of node, a grid node" is created. We do
- // all the drawing ourselves here instead of passing the work off to
- // other parts of the framework.
- public void createCustomNode() {
- PNode n = new PNode() {
- public void paint(PPaintContext aPaintContext) {
- double bx = getX();
- double by = getY();
- double rightBorder = bx + getWidth();
- double bottomBorder = by + getHeight();
+ // Here a completely new kind of node, a grid node" is created. We do
+ // all the drawing ourselves here instead of passing the work off to
+ // other parts of the framework.
+ public void createCustomNode() {
+ PNode n = new PNode() {
+ public void paint(PPaintContext aPaintContext) {
+ double bx = getX();
+ double by = getY();
+ double rightBorder = bx + getWidth();
+ double bottomBorder = by + getHeight();
- Line2D line = new Line2D.Double();
- Graphics2D g2 = aPaintContext.getGraphics();
+ Line2D line = new Line2D.Double();
+ Graphics2D g2 = aPaintContext.getGraphics();
- g2.setStroke(new BasicStroke(0));
- g2.setPaint(getPaint());
+ g2.setStroke(new BasicStroke(0));
+ g2.setPaint(getPaint());
- // draw vertical lines
- for (double x = bx; x < rightBorder; x += 5) {
- line.setLine(x, by, x, bottomBorder);
- g2.draw(line);
- }
+ // draw vertical lines
+ for (double x = bx; x < rightBorder; x += 5) {
+ line.setLine(x, by, x, bottomBorder);
+ g2.draw(line);
+ }
- for (double y = by; y < bottomBorder; y += 5) {
- line.setLine(bx, y, rightBorder, y);
- g2.draw(line);
- }
- }
- };
- n.setBounds(0, 0, 100, 80);
- n.setPaint(Color.black);
- getCanvas().getLayer().addChild(n);
- }
+ for (double y = by; y < bottomBorder; y += 5) {
+ line.setLine(bx, y, rightBorder, y);
+ g2.draw(line);
+ }
+ }
+ };
+ n.setBounds(0, 0, 100, 80);
+ n.setPaint(Color.black);
+ getCanvas().getLayer().addChild(n);
+ }
- public static void main(String[] args) {
- new BirdsEyeViewExample();
- }
+ public static void main(String[] args) {
+ new BirdsEyeViewExample();
+ }
- /**
- * The Birds Eye View Class
- */
- public class BirdsEyeView extends PCanvas implements PropertyChangeListener {
+ /**
+ * The Birds Eye View Class
+ */
+ public class BirdsEyeView extends PCanvas implements PropertyChangeListener {
- /**
- * This is the node that shows the viewed area.
- */
- PNode areaVisiblePNode;
+ /**
+ * This is the node that shows the viewed area.
+ */
+ PNode areaVisiblePNode;
- /**
- * This is the canvas that is being viewed
- */
- PCanvas viewedCanvas;
+ /**
+ * This is the canvas that is being viewed
+ */
+ PCanvas viewedCanvas;
- /**
- * The change listener to know when to update the birds eye view.
- */
- PropertyChangeListener changeListener;
+ /**
+ * The change listener to know when to update the birds eye view.
+ */
+ PropertyChangeListener changeListener;
- int layerCount;
+ int layerCount;
- /**
- * Creates a new instance of a BirdsEyeView
- */
- public BirdsEyeView() {
+ /**
+ * Creates a new instance of a BirdsEyeView
+ */
+ public BirdsEyeView() {
- // create the PropertyChangeListener for listening to the viewed
- // canvas
- changeListener = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- updateFromViewed();
- }
- };
+ // create the PropertyChangeListener for listening to the viewed
+ // canvas
+ changeListener = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ updateFromViewed();
+ }
+ };
- // create the coverage node
- areaVisiblePNode = new P3DRect();
- areaVisiblePNode.setPaint(new Color(128, 128, 255));
- areaVisiblePNode.setTransparency(.8f);
- areaVisiblePNode.setBounds(0, 0, 100, 100);
- getCamera().addChild(areaVisiblePNode);
+ // create the coverage node
+ areaVisiblePNode = new P3DRect();
+ areaVisiblePNode.setPaint(new Color(128, 128, 255));
+ areaVisiblePNode.setTransparency(.8f);
+ areaVisiblePNode.setBounds(0, 0, 100, 100);
+ getCamera().addChild(areaVisiblePNode);
- // add the drag event handler
- getCamera().addInputEventListener(new PDragSequenceEventHandler() {
- protected void startDrag(PInputEvent e) {
- if (e.getPickedNode() == areaVisiblePNode)
- super.startDrag(e);
- }
+ // add the drag event handler
+ getCamera().addInputEventListener(new PDragSequenceEventHandler() {
+ protected void startDrag(PInputEvent e) {
+ if (e.getPickedNode() == areaVisiblePNode)
+ super.startDrag(e);
+ }
- protected void drag(PInputEvent e) {
- PDimension dim = e.getDelta();
- viewedCanvas.getCamera().translateView(0 - dim.getWidth(),
- 0 - dim.getHeight());
- }
+ protected void drag(PInputEvent e) {
+ PDimension dim = e.getDelta();
+ viewedCanvas.getCamera().translateView(0 - dim.getWidth(), 0 - dim.getHeight());
+ }
- });
+ });
- // remove Pan and Zoom
- removeInputEventListener(getPanEventHandler());
- removeInputEventListener(getZoomEventHandler());
+ // remove Pan and Zoom
+ removeInputEventListener(getPanEventHandler());
+ removeInputEventListener(getZoomEventHandler());
- setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
+ setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- }
+ }
- public void connect(PCanvas canvas, PLayer[] viewed_layers) {
+ public void connect(PCanvas canvas, PLayer[] viewed_layers) {
- this.viewedCanvas = canvas;
- layerCount = 0;
+ this.viewedCanvas = canvas;
+ layerCount = 0;
- viewedCanvas.getCamera().addPropertyChangeListener(changeListener);
+ viewedCanvas.getCamera().addPropertyChangeListener(changeListener);
- for (layerCount = 0; layerCount < viewed_layers.length; ++layerCount) {
- getCamera().addLayer(layerCount, viewed_layers[layerCount]);
- }
+ for (layerCount = 0; layerCount < viewed_layers.length; ++layerCount) {
+ getCamera().addLayer(layerCount, viewed_layers[layerCount]);
+ }
- }
+ }
- /**
- * Add a layer to list of viewed layers
- */
- public void addLayer(PLayer new_layer) {
- getCamera().addLayer(new_layer);
- layerCount++;
- }
+ /**
+ * Add a layer to list of viewed layers
+ */
+ public void addLayer(PLayer new_layer) {
+ getCamera().addLayer(new_layer);
+ layerCount++;
+ }
- /**
- * Remove the layer from the viewed layers
- */
- public void removeLayer(PLayer old_layer) {
- getCamera().removeLayer(old_layer);
- layerCount--;
- }
+ /**
+ * Remove the layer from the viewed layers
+ */
+ public void removeLayer(PLayer old_layer) {
+ getCamera().removeLayer(old_layer);
+ layerCount--;
+ }
- /**
- * Stop the birds eye view from receiving events from the viewed canvas
- * and remove all layers
- */
- public void disconnect() {
- viewedCanvas.getCamera().removePropertyChangeListener(
- changeListener);
+ /**
+ * Stop the birds eye view from receiving events from the viewed canvas
+ * and remove all layers
+ */
+ public void disconnect() {
+ viewedCanvas.getCamera().removePropertyChangeListener(changeListener);
- for (int i = 0; i < getCamera().getLayerCount(); ++i) {
- getCamera().removeLayer(i);
- }
+ for (int i = 0; i < getCamera().getLayerCount(); ++i) {
+ getCamera().removeLayer(i);
+ }
- }
+ }
- /**
- * This method will get called when the viewed canvas changes
- */
- public void propertyChange(PropertyChangeEvent event) {
- updateFromViewed();
- }
+ /**
+ * This method will get called when the viewed canvas changes
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ updateFromViewed();
+ }
- /**
- * This method gets the state of the viewed canvas and updates the
- * BirdsEyeViewer This can be called from outside code
- */
- public void updateFromViewed() {
+ /**
+ * This method gets the state of the viewed canvas and updates the
+ * BirdsEyeViewer This can be called from outside code
+ */
+ public void updateFromViewed() {
- double viewedX;
- double viewedY;
- double viewedHeight;
- double viewedWidth;
+ double viewedX;
+ double viewedY;
+ double viewedHeight;
+ double viewedWidth;
- double ul_camera_x = viewedCanvas.getCamera().getViewBounds()
- .getX();
- double ul_camera_y = viewedCanvas.getCamera().getViewBounds()
- .getY();
- double lr_camera_x = ul_camera_x
- + viewedCanvas.getCamera().getViewBounds().getWidth();
- double lr_camera_y = ul_camera_y
- + viewedCanvas.getCamera().getViewBounds().getHeight();
+ double ul_camera_x = viewedCanvas.getCamera().getViewBounds().getX();
+ double ul_camera_y = viewedCanvas.getCamera().getViewBounds().getY();
+ double lr_camera_x = ul_camera_x + viewedCanvas.getCamera().getViewBounds().getWidth();
+ double lr_camera_y = ul_camera_y + viewedCanvas.getCamera().getViewBounds().getHeight();
- Rectangle2D drag_bounds = getCamera().getUnionOfLayerFullBounds();
+ Rectangle2D drag_bounds = getCamera().getUnionOfLayerFullBounds();
- double ul_layer_x = drag_bounds.getX();
- double ul_layer_y = drag_bounds.getY();
- double lr_layer_x = drag_bounds.getX() + drag_bounds.getWidth();
- double lr_layer_y = drag_bounds.getY() + drag_bounds.getHeight();
+ double ul_layer_x = drag_bounds.getX();
+ double ul_layer_y = drag_bounds.getY();
+ double lr_layer_x = drag_bounds.getX() + drag_bounds.getWidth();
+ double lr_layer_y = drag_bounds.getY() + drag_bounds.getHeight();
- // find the upper left corner
+ // find the upper left corner
- // set to the lesser value
- if (ul_camera_x < ul_layer_x)
- viewedX = ul_layer_x;
- else
- viewedX = ul_camera_x;
+ // set to the lesser value
+ if (ul_camera_x < ul_layer_x)
+ viewedX = ul_layer_x;
+ else
+ viewedX = ul_camera_x;
- // same for y
- if (ul_camera_y < ul_layer_y)
- viewedY = ul_layer_y;
- else
- viewedY = ul_camera_y;
+ // same for y
+ if (ul_camera_y < ul_layer_y)
+ viewedY = ul_layer_y;
+ else
+ viewedY = ul_camera_y;
- // find the lower right corner
+ // find the lower right corner
- // set to the greater value
- if (lr_camera_x < lr_layer_x)
- viewedWidth = lr_camera_x - viewedX;
- else
- viewedWidth = lr_layer_x - viewedX;
+ // set to the greater value
+ if (lr_camera_x < lr_layer_x)
+ viewedWidth = lr_camera_x - viewedX;
+ else
+ viewedWidth = lr_layer_x - viewedX;
- // same for height
- if (lr_camera_y < lr_layer_y)
- viewedHeight = lr_camera_y - viewedY;
- else
- viewedHeight = lr_layer_y - viewedY;
+ // same for height
+ if (lr_camera_y < lr_layer_y)
+ viewedHeight = lr_camera_y - viewedY;
+ else
+ viewedHeight = lr_layer_y - viewedY;
- Rectangle2D bounds = new Rectangle2D.Double(viewedX, viewedY,
- viewedWidth, viewedHeight);
- bounds = getCamera().viewToLocal(bounds);
- areaVisiblePNode.setBounds(bounds);
+ Rectangle2D bounds = new Rectangle2D.Double(viewedX, viewedY, viewedWidth, viewedHeight);
+ bounds = getCamera().viewToLocal(bounds);
+ areaVisiblePNode.setBounds(bounds);
- // keep the birds eye view centered
- getCamera().animateViewToCenterBounds(drag_bounds, true, 0);
+ // keep the birds eye view centered
+ getCamera().animateViewToCenterBounds(drag_bounds, true, 0);
- }
+ }
- } // class BirdsEyeView
+ } // class BirdsEyeView
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
index 8a7fb78..cf0befa 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCamera;
@@ -13,35 +14,35 @@
*/
public class CameraExample extends PFrame {
- public CameraExample() {
- this(null);
- }
-
- public CameraExample(PCanvas aCanvas) {
- super("CameraExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer l = new PLayer();
- PPath n = PPath.createEllipse(0, 0, 100, 80);
- n.setPaint(Color.red);
- n.setStroke(null);
- PBoundsHandle.addBoundsHandlesTo(n);
- l.addChild(n);
- n.translate(200, 200);
-
- PCamera c = new PCamera();
- c.setBounds(0, 0, 100, 80);
- c.scaleView(0.1);
- c.addLayer(l);
- PBoundsHandle.addBoundsHandlesTo(c);
- c.setPaint(Color.yellow);
+ public CameraExample() {
+ this(null);
+ }
- getCanvas().getLayer().addChild(l);
- getCanvas().getLayer().addChild(c);
- }
-
- public static void main(String[] args) {
- new CameraExample();
- }
+ public CameraExample(PCanvas aCanvas) {
+ super("CameraExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PLayer l = new PLayer();
+ PPath n = PPath.createEllipse(0, 0, 100, 80);
+ n.setPaint(Color.red);
+ n.setStroke(null);
+ PBoundsHandle.addBoundsHandlesTo(n);
+ l.addChild(n);
+ n.translate(200, 200);
+
+ PCamera c = new PCamera();
+ c.setBounds(0, 0, 100, 80);
+ c.scaleView(0.1);
+ c.addLayer(l);
+ PBoundsHandle.addBoundsHandlesTo(c);
+ c.setPaint(Color.yellow);
+
+ getCanvas().getLayer().addChild(l);
+ getCanvas().getLayer().addChild(c);
+ }
+
+ public static void main(String[] args) {
+ new CameraExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
index 20aadd5..8ad0bb4 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
@@ -8,29 +8,29 @@
public class CenterExample extends PFrame {
- public CenterExample() {
- this(null);
- }
-
- public CenterExample(PCanvas aCanvas) {
- super("CenterExample", false, aCanvas);
- }
+ public CenterExample() {
+ this(null);
+ }
- public void initialize() {
- PCanvas c = getCanvas();
- PLayer l = c.getLayer();
- PCamera cam = c.getCamera();
-
- cam.scaleView(2.0);
- PPath path = PPath.createRectangle(0, 0, 100, 100);
-
- l.addChild(path);
- path.translate(100, 10);
- path.scale(0.2);
- cam.animateViewToCenterBounds(path.getGlobalFullBounds(), true, 1000);
- }
+ public CenterExample(PCanvas aCanvas) {
+ super("CenterExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new CenterExample();
- }
+ public void initialize() {
+ PCanvas c = getCanvas();
+ PLayer l = c.getLayer();
+ PCamera cam = c.getCamera();
+
+ cam.scaleView(2.0);
+ PPath path = PPath.createRectangle(0, 0, 100, 100);
+
+ l.addChild(path);
+ path.translate(100, 10);
+ path.scale(0.2);
+ cam.animateViewToCenterBounds(path.getGlobalFullBounds(), true, 1000);
+ }
+
+ public static void main(String[] args) {
+ new CenterExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
index 52a1e7c..8d9c4c8 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
@@ -18,78 +18,75 @@
* @author Tao
*/
public class ChartLabelExample extends PFrame {
- final int nodeHeight = 15;
- final int nodeWidth = 30;
+ final int nodeHeight = 15;
+ final int nodeWidth = 30;
- //Row Bar
- PLayer rowBarLayer;
+ // Row Bar
+ PLayer rowBarLayer;
- //Colume Bar
- PLayer colBarLayer;
+ // Colume Bar
+ PLayer colBarLayer;
- public ChartLabelExample() {
- this(null);
- }
+ public ChartLabelExample() {
+ this(null);
+ }
- public ChartLabelExample(PCanvas aCanvas) {
- super("ChartLabelExample", false, aCanvas);
- }
+ public ChartLabelExample(PCanvas aCanvas) {
+ super("ChartLabelExample", false, aCanvas);
+ }
- public void initialize() {
- //create bar layers
- rowBarLayer = new PLayer();
- colBarLayer = new PLayer();
+ public void initialize() {
+ // create bar layers
+ rowBarLayer = new PLayer();
+ colBarLayer = new PLayer();
- //create bar nodes
- for (int i = 0; i < 10; i++) {
- //create row bar with node row1, row2,...row10
- PText p = new PText("Row " + i);
- p.setX(0);
- p.setY(nodeHeight * i + nodeHeight);
- p.setPaint(Color.white);
- colBarLayer.addChild(p);
+ // create bar nodes
+ for (int i = 0; i < 10; i++) {
+ // create row bar with node row1, row2,...row10
+ PText p = new PText("Row " + i);
+ p.setX(0);
+ p.setY(nodeHeight * i + nodeHeight);
+ p.setPaint(Color.white);
+ colBarLayer.addChild(p);
- //create col bar with node col1, col2,...col10
- p = new PText("Col " + i);
- p.setX(nodeWidth * i + nodeWidth);
- p.setY(0);
- p.setPaint(Color.white);
- rowBarLayer.addChild(p);
- }
+ // create col bar with node col1, col2,...col10
+ p = new PText("Col " + i);
+ p.setX(nodeWidth * i + nodeWidth);
+ p.setY(0);
+ p.setPaint(Color.white);
+ rowBarLayer.addChild(p);
+ }
- //add bar layers to camera
- getCanvas().getCamera().addChild(rowBarLayer);
- getCanvas().getCamera().addChild(colBarLayer);
+ // add bar layers to camera
+ getCanvas().getCamera().addChild(rowBarLayer);
+ getCanvas().getCamera().addChild(colBarLayer);
- //create matrix nodes
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- PPath path = PPath.createRectangle(nodeWidth * j + nodeWidth,
- nodeHeight * i + nodeHeight, nodeWidth - 1,
- nodeHeight - 1);
- getCanvas().getLayer().addChild(path);
- }
- }
+ // create matrix nodes
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ PPath path = PPath.createRectangle(nodeWidth * j + nodeWidth, nodeHeight * i + nodeHeight,
+ nodeWidth - 1, nodeHeight - 1);
+ getCanvas().getLayer().addChild(path);
+ }
+ }
- //catch drag event and move bars corresponding
- getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
- Point2D oldP, newP;
+ // catch drag event and move bars corresponding
+ getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
+ Point2D oldP, newP;
- public void mousePressed(PInputEvent aEvent) {
- oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
- }
+ public void mousePressed(PInputEvent aEvent) {
+ oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
+ }
- public void mouseReleased(PInputEvent aEvent) {
- newP = getCanvas().getCamera().getViewBounds().getCenter2D();
- colBarLayer.translate(0, (oldP.getY() - newP.getY())
- / getCanvas().getLayer().getScale());
- rowBarLayer.translate((oldP.getX() - newP.getX())
- / getCanvas().getLayer().getScale(), 0);
- }
- });
- }
+ public void mouseReleased(PInputEvent aEvent) {
+ newP = getCanvas().getCamera().getViewBounds().getCenter2D();
+ colBarLayer.translate(0, (oldP.getY() - newP.getY()) / getCanvas().getLayer().getScale());
+ rowBarLayer.translate((oldP.getX() - newP.getX()) / getCanvas().getLayer().getScale(), 0);
+ }
+ });
+ }
- public static void main(String[] args) {
- new ChartLabelExample();
- }
+ public static void main(String[] args) {
+ new ChartLabelExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
index 950a3ab..a2450cc 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
@@ -13,27 +13,27 @@
*/
public class ClipExample extends PFrame {
- public ClipExample() {
- this(null);
- }
-
- public ClipExample(PCanvas aCanvas) {
- super("ClipExample", false, aCanvas);
- }
-
- public void initialize() {
- PClip clip = new PClip();
- clip.setPathToEllipse(0, 0, 100, 100);
- clip.setPaint(Color.red);
-
- clip.addChild(PPath.createRectangle(20, 20, 100, 50));
- getCanvas().getLayer().addChild(clip);
+ public ClipExample() {
+ this(null);
+ }
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new ClipExample();
- }
+ public ClipExample(PCanvas aCanvas) {
+ super("ClipExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PClip clip = new PClip();
+ clip.setPathToEllipse(0, 0, 100, 100);
+ clip.setPaint(Color.red);
+
+ clip.addChild(PPath.createRectangle(20, 20, 100, 50));
+ getCanvas().getLayer().addChild(clip);
+
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PDragEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new ClipExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
index 368d9fa..2443ea7 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
@@ -11,43 +11,43 @@
import edu.umd.cs.piccolox.nodes.PComposite;
/**
- * This example shows how to create a composite node. A composite node is
- * a group of nodes that behave as a single node when interacted with.
+ * This example shows how to create a composite node. A composite node is a
+ * group of nodes that behave as a single node when interacted with.
*/
public class CompositeExample extends PFrame {
- public CompositeExample() {
- this(null);
- }
-
- public CompositeExample(PCanvas aCanvas) {
- super("CompositeExample", false, aCanvas);
- }
-
- public void initialize() {
- PComposite composite = new PComposite();
+ public CompositeExample() {
+ this(null);
+ }
- PNode circle = PPath.createEllipse(0, 0, 100, 100);
- PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
- PNode text = new PText("Hello world!");
-
- composite.addChild(circle);
- composite.addChild(rectangle);
- composite.addChild(text);
+ public CompositeExample(PCanvas aCanvas) {
+ super("CompositeExample", false, aCanvas);
+ }
- rectangle.rotate(Math.toRadians(45));
- rectangle.setPaint(Color.RED);
+ public void initialize() {
+ PComposite composite = new PComposite();
- text.scale(2.0);
- text.setPaint(Color.GREEN);
-
- getCanvas().getLayer().addChild(composite);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new CompositeExample();
- }
+ PNode circle = PPath.createEllipse(0, 0, 100, 100);
+ PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
+ PNode text = new PText("Hello world!");
+
+ composite.addChild(circle);
+ composite.addChild(rectangle);
+ composite.addChild(text);
+
+ rectangle.rotate(Math.toRadians(45));
+ rectangle.setPaint(Color.RED);
+
+ text.scale(2.0);
+ text.setPaint(Color.GREEN);
+
+ getCanvas().getLayer().addChild(composite);
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PDragEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new CompositeExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
index b7ea44e..37558c1 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Iterator;
@@ -14,57 +15,59 @@
import edu.umd.cs.piccolox.util.PFixedWidthStroke;
/**
- * 1000 nodes rotated continuously. Note that if you zoom to a portion of the screen where
- * you can't see any nodes the CPU usage goes down to 1%, even though all the objects are
- * still getting rotated continuously (every 20 milliseconds). This shows that the cost
- * of repainting and bounds caches is very cheap compared to the cost of drawing.
+ * 1000 nodes rotated continuously. Note that if you zoom to a portion of the
+ * screen where you can't see any nodes the CPU usage goes down to 1%, even
+ * though all the objects are still getting rotated continuously (every 20
+ * milliseconds). This shows that the cost of repainting and bounds caches is
+ * very cheap compared to the cost of drawing.
*/
public class DynamicExample extends PFrame {
- public DynamicExample() {
- this(null);
- }
-
- public DynamicExample(PCanvas aCanvas) {
- super("DynamicExample", false, aCanvas);
- }
-
- public void initialize() {
- final PLayer layer = getCanvas().getLayer();
- PRoot root = getCanvas().getRoot();
- Random r = new Random();
- for (int i = 0; i < 1000; i++) {
- final PNode n = PPath.createRectangle(0, 0, 100, 80);
- n.translate(10000 * r.nextFloat(), 10000 * r.nextFloat());
- n.setPaint(new Color(r.nextFloat(), r.nextFloat(),r.nextFloat()));
- layer.addChild(n);
- }
- getCanvas().getCamera().animateViewToCenterBounds(layer.getGlobalFullBounds(), true, 0);
- PActivity a = new PActivity(-1, 20) {
- public void activityStep(long currentTime) {
- super.activityStep(currentTime);
- rotateNodes();
- }
- };
- root.addActivity(a);
-
- PPath p = new PPath();
- p.moveTo(0, 0);
- p.lineTo(0, 1000);
- PFixedWidthStroke stroke = new PFixedWidthStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, new float[] {5, 2}, 0);
- p.setStroke(stroke);
- layer.addChild(p);
- }
+ public DynamicExample() {
+ this(null);
+ }
- public void rotateNodes() {
- Iterator i = getCanvas().getLayer().getChildrenReference().iterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- each.rotate(Math.toRadians(2));
- }
- }
+ public DynamicExample(PCanvas aCanvas) {
+ super("DynamicExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new DynamicExample();
- }
+ public void initialize() {
+ final PLayer layer = getCanvas().getLayer();
+ PRoot root = getCanvas().getRoot();
+ Random r = new Random();
+ for (int i = 0; i < 1000; i++) {
+ final PNode n = PPath.createRectangle(0, 0, 100, 80);
+ n.translate(10000 * r.nextFloat(), 10000 * r.nextFloat());
+ n.setPaint(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat()));
+ layer.addChild(n);
+ }
+ getCanvas().getCamera().animateViewToCenterBounds(layer.getGlobalFullBounds(), true, 0);
+ PActivity a = new PActivity(-1, 20) {
+ public void activityStep(long currentTime) {
+ super.activityStep(currentTime);
+ rotateNodes();
+ }
+ };
+ root.addActivity(a);
+
+ PPath p = new PPath();
+ p.moveTo(0, 0);
+ p.lineTo(0, 1000);
+ PFixedWidthStroke stroke = new PFixedWidthStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10,
+ new float[] { 5, 2 }, 0);
+ p.setStroke(stroke);
+ layer.addChild(p);
+ }
+
+ public void rotateNodes() {
+ Iterator i = getCanvas().getLayer().getChildrenReference().iterator();
+ while (i.hasNext()) {
+ PNode each = (PNode) i.next();
+ each.rotate(Math.toRadians(2));
+ }
+ }
+
+ public static void main(String[] args) {
+ new DynamicExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
index b0c3cd2..987b05f 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.event.InputEvent;
import java.awt.geom.Point2D;
@@ -13,104 +14,106 @@
import edu.umd.cs.piccolo.util.PBounds;
/**
- * This example shows how to create and install a custom event listener that draws
- * rectangles.
+ * This example shows how to create and install a custom event listener that
+ * draws rectangles.
*/
public class EventHandlerExample extends PFrame {
- public EventHandlerExample() {
- this(null);
- }
+ public EventHandlerExample() {
+ this(null);
+ }
- public EventHandlerExample(PCanvas aCanvas) {
- super("EventHandlerExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
-
- // Create a new event handler the creates new rectangles on
- // mouse pressed, dragged, release.
- PBasicInputEventHandler rectEventHandler = createRectangleEventHandler();
-
- // Make the event handler only work with BUTTON1 events, so that it does
- // not conflict with the zoom event handler that is installed by default.
- rectEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
-
- // Remove the pan event handler that is installed by default so that it
- // does not conflict with our new rectangle creation event handler.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
-
- // Register our new event handler.
- getCanvas().addInputEventListener(rectEventHandler);
- }
+ public EventHandlerExample(PCanvas aCanvas) {
+ super("EventHandlerExample", false, aCanvas);
+ }
- public PBasicInputEventHandler createRectangleEventHandler() {
-
- // Create a new subclass of PBasicEventHandler that creates new PPath nodes
- // on mouse pressed, dragged, and released sequences. Not that subclassing
- // PDragSequenceEventHandler would make this class easier to implement, but
- // here you can see how to do it from scratch.
- return new PBasicInputEventHandler() {
-
- // The rectangle that is currently getting created.
- protected PPath rectangle;
-
- // The mouse press location for the current pressed, drag, release sequence.
- protected Point2D pressPoint;
-
- // The current drag location.
- protected Point2D dragPoint;
-
- public void mousePressed(PInputEvent e) {
- super.mousePressed(e);
-
- PLayer layer = getCanvas().getLayer();
+ public void initialize() {
+ super.initialize();
- // Initialize the locations.
- pressPoint = e.getPosition();
- dragPoint = pressPoint;
-
- // create a new rectangle and add it to the canvas layer so that
- // we can see it.
- rectangle = new PPath();
- rectangle.setStroke(new BasicStroke((float)(1/ e.getCamera().getViewScale())));
- layer.addChild(rectangle);
-
- // update the rectangle shape.
- updateRectangle();
- }
-
- public void mouseDragged(PInputEvent e) {
- super.mouseDragged(e);
- // update the drag point location.
- dragPoint = e.getPosition();
-
- // update the rectangle shape.
- updateRectangle();
- }
-
- public void mouseReleased(PInputEvent e) {
- super.mouseReleased(e);
- // update the rectangle shape.
- updateRectangle();
- rectangle = null;
- }
-
- public void updateRectangle() {
- // create a new bounds that contains both the press and current
- // drag point.
- PBounds b = new PBounds();
- b.add(pressPoint);
- b.add(dragPoint);
-
- // Set the rectangles bounds.
- rectangle.setPathTo(b);
- }
- };
- }
-
- public static void main(String[] args) {
- new EventHandlerExample();
- }
+ // Create a new event handler the creates new rectangles on
+ // mouse pressed, dragged, release.
+ PBasicInputEventHandler rectEventHandler = createRectangleEventHandler();
+
+ // Make the event handler only work with BUTTON1 events, so that it does
+ // not conflict with the zoom event handler that is installed by
+ // default.
+ rectEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+
+ // Remove the pan event handler that is installed by default so that it
+ // does not conflict with our new rectangle creation event handler.
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+
+ // Register our new event handler.
+ getCanvas().addInputEventListener(rectEventHandler);
+ }
+
+ public PBasicInputEventHandler createRectangleEventHandler() {
+
+ // Create a new subclass of PBasicEventHandler that creates new PPath
+ // nodes on mouse pressed, dragged, and released sequences. Not that
+ // subclassing PDragSequenceEventHandler would make this class easier to
+ // implement, but here you can see how to do it from scratch.
+ return new PBasicInputEventHandler() {
+
+ // The rectangle that is currently getting created.
+ protected PPath rectangle;
+
+ // The mouse press location for the current pressed, drag, release
+ // sequence.
+ protected Point2D pressPoint;
+
+ // The current drag location.
+ protected Point2D dragPoint;
+
+ public void mousePressed(PInputEvent e) {
+ super.mousePressed(e);
+
+ PLayer layer = getCanvas().getLayer();
+
+ // Initialize the locations.
+ pressPoint = e.getPosition();
+ dragPoint = pressPoint;
+
+ // create a new rectangle and add it to the canvas layer so that
+ // we can see it.
+ rectangle = new PPath();
+ rectangle.setStroke(new BasicStroke((float) (1 / e.getCamera().getViewScale())));
+ layer.addChild(rectangle);
+
+ // update the rectangle shape.
+ updateRectangle();
+ }
+
+ public void mouseDragged(PInputEvent e) {
+ super.mouseDragged(e);
+ // update the drag point location.
+ dragPoint = e.getPosition();
+
+ // update the rectangle shape.
+ updateRectangle();
+ }
+
+ public void mouseReleased(PInputEvent e) {
+ super.mouseReleased(e);
+ // update the rectangle shape.
+ updateRectangle();
+ rectangle = null;
+ }
+
+ public void updateRectangle() {
+ // create a new bounds that contains both the press and current
+ // drag point.
+ PBounds b = new PBounds();
+ b.add(pressPoint);
+ b.add(dragPoint);
+
+ // Set the rectangles bounds.
+ rectangle.setPathTo(b);
+ }
+ };
+ }
+
+ public static void main(String[] args) {
+ new EventHandlerExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
index ab75a88..0815915 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
@@ -15,348 +16,312 @@
public class ExampleRunner extends JFrame {
- public ExampleRunner() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Piccolo Example Runner");
- setSize(426, 335);
- getContentPane().setLayout(new BorderLayout());
- createExampleButtons();
- validate();
- pack();
- setVisible(true);
- }
+ public ExampleRunner() {
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("Piccolo Example Runner");
+ setSize(426, 335);
+ getContentPane().setLayout(new BorderLayout());
+ createExampleButtons();
+ validate();
+ pack();
+ setVisible(true);
+ }
- public void createExampleButtons() {
- Container c = getContentPane();
- Container p = new JPanel();
+ public void createExampleButtons() {
+ Container c = getContentPane();
+ Container p = new JPanel();
- p = new JPanel(new GridLayout(0, 1));
- c.add(BorderLayout.NORTH, p);
+ p = new JPanel(new GridLayout(0, 1));
+ c.add(BorderLayout.NORTH, p);
- p.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate;
- }
- }));
+ p.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") {
+ public void actionPerformed(ActionEvent e) {
+ PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate;
+ }
+ }));
- p.add(new JCheckBox(new AbstractAction("Show Region Managment") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugRegionManagement = !PDebug.debugRegionManagement;
- }
- }));
+ p.add(new JCheckBox(new AbstractAction("Show Region Managment") {
+ public void actionPerformed(ActionEvent e) {
+ PDebug.debugRegionManagement = !PDebug.debugRegionManagement;
+ }
+ }));
- p.add(new JCheckBox(new AbstractAction("Show Full Bounds") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugFullBounds = !PDebug.debugFullBounds;
- }
- }));
+ p.add(new JCheckBox(new AbstractAction("Show Full Bounds") {
+ public void actionPerformed(ActionEvent e) {
+ PDebug.debugFullBounds = !PDebug.debugFullBounds;
+ }
+ }));
- p = new JPanel(new GridLayout(0, 2));
- c.add(BorderLayout.CENTER, p);
+ p = new JPanel(new GridLayout(0, 2));
+ c.add(BorderLayout.CENTER, p);
- p.add(new JButton(new AbstractAction("ActivityExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ActivityExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("ActivityExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new ActivityExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("AngleNodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new AngleNodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("AngleNodeExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new AngleNodeExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("BirdsEyeViewExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new BirdsEyeViewExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("BirdsEyeViewExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new BirdsEyeViewExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("CameraExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CameraExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("CameraExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new CameraExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("CenterExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CenterExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("ChartLabelExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ChartLabelExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("CenterExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new CenterExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("ClipExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ClipExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("ChartLabelExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new ChartLabelExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("CompositeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CompositeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("ClipExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new ClipExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("DynamicExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new DynamicExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("CompositeExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new CompositeExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("EventHandlerExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new EventHandlerExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("DynamicExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new DynamicExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("FullScreenNodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new FullScreenNodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("EventHandlerExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new EventHandlerExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("GraphEditorExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GraphEditorExample();
- example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
- p.add(new JButton(new AbstractAction("GridExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GridExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("FullScreenNodeExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new FullScreenNodeExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("GroupExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GroupExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("GraphEditorExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new GraphEditorExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
+ p.add(new JButton(new AbstractAction("GridExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new GridExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("HandleExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new HandleExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("GroupExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new GroupExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("HierarchyZoomExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new HierarchyZoomExample();
- example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("HandleExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new HandleExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("KeyEventFocusExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new KeyEventFocusExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("HierarchyZoomExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new HierarchyZoomExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("LayoutExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new LayoutExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("KeyEventFocusExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new KeyEventFocusExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("LensExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new LensExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("LayoutExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new LayoutExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("NavigationExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NavigationExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("LensExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new LensExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("NodeCacheExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeCacheExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("NavigationExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new NavigationExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("NodeEventExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeEventExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("NodeCacheExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new NodeCacheExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("NodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("NodeEventExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new NodeEventExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("NodeLinkExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeLinkExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("NodeExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new NodeExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("PanToExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PanToExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("NodeLinkExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new NodeLinkExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("PathExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PathExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("PanToExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new PanToExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("PositionExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PositionExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("PathExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new PathExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("PositionPathActivityExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PositionPathActivityExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("PositionExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new PositionExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("PulseExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PulseExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("PositionPathActivityExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new PositionPathActivityExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("ScrollingExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ScrollingExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("PulseExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new PulseExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("SelectionExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new SelectionExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("ScrollingExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new ScrollingExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("SquiggleExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new SquiggleExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("SelectionExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new SelectionExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("StickyExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new StickyExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("SquiggleExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new SquiggleExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("StickyHandleLayerExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new StickyHandleLayerExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("StickyExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new StickyExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("TextExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TextExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("StickyHandleLayerExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new StickyHandleLayerExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("Tooltip Example") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TooltipExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("TextExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new TextExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("TwoCanvasExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TwoCanvasExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
+ p.add(new JButton(new AbstractAction("Tooltip Example") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new TooltipExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- p.add(new JButton(new AbstractAction("WaitForActivitiesExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new WaitForActivitiesExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
- }
+ p.add(new JButton(new AbstractAction("TwoCanvasExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new TwoCanvasExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
- public static void main(String[] args) {
- new ExampleRunner();
- }
+ p.add(new JButton(new AbstractAction("WaitForActivitiesExample") {
+ public void actionPerformed(ActionEvent e) {
+ PFrame example = new WaitForActivitiesExample();
+ example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ }));
+ }
+
+ public static void main(String[] args) {
+ new ExampleRunner();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
index fcabba1..8f9db0e 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
@@ -1,14 +1,13 @@
package edu.umd.cs.piccolo.examples;
-
public class FullScreenNodeExample extends NodeExample {
- public void initialize() {
- super.initialize();
- setFullScreenMode(true);
- }
+ public void initialize() {
+ super.initialize();
+ setFullScreenMode(true);
+ }
- public static void main(String[] args) {
- new FullScreenNodeExample();
- }
+ public static void main(String[] args) {
+ new FullScreenNodeExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
index 115c94f..806b0d1 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
@@ -13,124 +14,131 @@
import edu.umd.cs.piccolox.PFrame;
/**
- * Create a simple graph with some random nodes and connected edges.
- * An event handler allows users to drag nodes around, keeping the edges connected.
+ * Create a simple graph with some random nodes and connected edges. An event
+ * handler allows users to drag nodes around, keeping the edges connected.
*
* ported from .NET GraphEditorExample by Sun Hongmei.
*/
public class GraphEditorExample extends PFrame {
- public GraphEditorExample() {
- this(null);
- }
+ public GraphEditorExample() {
+ this(null);
+ }
- public GraphEditorExample(PCanvas aCanvas) {
- super("GraphEditorExample", false, aCanvas);
- }
+ public GraphEditorExample(PCanvas aCanvas) {
+ super("GraphEditorExample", false, aCanvas);
+ }
- public void initialize() {
- int numNodes = 50;
- int numEdges = 50;
+ public void initialize() {
+ int numNodes = 50;
+ int numEdges = 50;
- // Initialize, and create a layer for the edges (always underneath the nodes)
- PLayer nodeLayer = getCanvas().getLayer();
- PLayer edgeLayer = new PLayer();
- getCanvas().getCamera().addLayer(0, edgeLayer);
- Random rnd = new Random();
- ArrayList tmp;
- for (int i = 0; i < numNodes; i++) {
- float x = (float) (300. * rnd.nextDouble());
- float y = (float) (400. * rnd.nextDouble());
- PPath path = PPath.createEllipse(x, y, 20, 20);
- tmp = new ArrayList();
- path.addAttribute("edges", tmp);
- nodeLayer.addChild(path);
- }
+ // Initialize, and create a layer for the edges (always underneath the
+ // nodes)
+ PLayer nodeLayer = getCanvas().getLayer();
+ PLayer edgeLayer = new PLayer();
+ getCanvas().getCamera().addLayer(0, edgeLayer);
+ Random rnd = new Random();
+ ArrayList tmp;
+ for (int i = 0; i < numNodes; i++) {
+ float x = (float) (300. * rnd.nextDouble());
+ float y = (float) (400. * rnd.nextDouble());
+ PPath path = PPath.createEllipse(x, y, 20, 20);
+ tmp = new ArrayList();
+ path.addAttribute("edges", tmp);
+ nodeLayer.addChild(path);
+ }
- // Create some random edges
- // Each edge's Tag has an ArrayList used to store associated nodes
- for (int i = 0; i < numEdges; i++) {
- int n1 = rnd.nextInt(numNodes);
- int n2 = rnd.nextInt(numNodes);
- PNode node1 = nodeLayer.getChild(n1);
- PNode node2 = nodeLayer.getChild(n2);
+ // Create some random edges
+ // Each edge's Tag has an ArrayList used to store associated nodes
+ for (int i = 0; i < numEdges; i++) {
+ int n1 = rnd.nextInt(numNodes);
+ int n2 = rnd.nextInt(numNodes);
+ PNode node1 = nodeLayer.getChild(n1);
+ PNode node2 = nodeLayer.getChild(n2);
- Point2D.Double bound1 = (Point2D.Double) node1.getBounds().getCenter2D();
- Point2D.Double bound2 = (Point2D.Double) node2.getBounds().getCenter2D();
+ Point2D.Double bound1 = (Point2D.Double) node1.getBounds().getCenter2D();
+ Point2D.Double bound2 = (Point2D.Double) node2.getBounds().getCenter2D();
- PPath edge = new PPath();
- edge.moveTo((float) bound1.getX(), (float) bound1.getY());
- edge.lineTo((float) bound2.getX(), (float) bound2.getY());
+ PPath edge = new PPath();
+ edge.moveTo((float) bound1.getX(), (float) bound1.getY());
+ edge.lineTo((float) bound2.getX(), (float) bound2.getY());
- tmp = (ArrayList) node1.getAttribute("edges");
- tmp.add(edge);
- tmp = (ArrayList) node2.getAttribute("edges");
- tmp.add(edge);
+ tmp = (ArrayList) node1.getAttribute("edges");
+ tmp.add(edge);
+ tmp = (ArrayList) node2.getAttribute("edges");
+ tmp.add(edge);
- tmp = new ArrayList();
- tmp.add(node1);
- tmp.add(node2);
- edge.addAttribute("nodes", tmp);
+ tmp = new ArrayList();
+ tmp.add(node1);
+ tmp.add(node2);
+ edge.addAttribute("nodes", tmp);
- edgeLayer.addChild(edge);
- }
+ edgeLayer.addChild(edge);
+ }
- // Create event handler to move nodes and update edges
- nodeLayer.addInputEventListener(new NodeDragHandler());
- }
+ // Create event handler to move nodes and update edges
+ nodeLayer.addInputEventListener(new NodeDragHandler());
+ }
- public static void main(String[] args) {
- new GraphEditorExample();
- }
+ public static void main(String[] args) {
+ new GraphEditorExample();
+ }
- ///
- /// Simple event handler which applies the following actions to every node it is called on:
- /// * Turn node red when the mouse goes over the node
- /// * Turn node white when the mouse exits the node
- /// * Drag the node, and associated edges on mousedrag
- /// It assumes that the node's Tag references an ArrayList with a list of associated
- /// edges where each edge is a PPath which each have a Tag that references an ArrayList
- /// with a list of associated nodes.
- ///
- class NodeDragHandler extends PDragSequenceEventHandler {
- public NodeDragHandler() {
- getEventFilter().setMarksAcceptedEventsAsHandled(true);
- }
- public void mouseEntered(PInputEvent e) {
- if (e.getButton() == 0) {
- e.getPickedNode().setPaint(Color.red);
- }
- }
+ // TODO eclipse formatter made this ugly
+ // /
+ // / Simple event handler which applies the following actions to every node
+ // it is called on:
+ // / * Turn node red when the mouse goes over the node
+ // / * Turn node white when the mouse exits the node
+ // / * Drag the node, and associated edges on mousedrag
+ // / It assumes that the node's Tag references an ArrayList with a list of
+ // associated
+ // / edges where each edge is a PPath which each have a Tag that references
+ // an ArrayList
+ // / with a list of associated nodes.
+ // /
+ class NodeDragHandler extends PDragSequenceEventHandler {
+ public NodeDragHandler() {
+ getEventFilter().setMarksAcceptedEventsAsHandled(true);
+ }
- public void mouseExited(PInputEvent e) {
- if (e.getButton() == 0) {
- e.getPickedNode().setPaint(Color.white);
- }
- }
+ public void mouseEntered(PInputEvent e) {
+ if (e.getButton() == 0) {
+ e.getPickedNode().setPaint(Color.red);
+ }
+ }
- public void drag(PInputEvent e) {
- PNode node = e.getPickedNode();
- node.translate(e.getDelta().width, e.getDelta().height);
+ public void mouseExited(PInputEvent e) {
+ if (e.getButton() == 0) {
+ e.getPickedNode().setPaint(Color.white);
+ }
+ }
- ArrayList edges = (ArrayList) e.getPickedNode().getAttribute("edges");
+ public void drag(PInputEvent e) {
+ PNode node = e.getPickedNode();
+ node.translate(e.getDelta().width, e.getDelta().height);
- int i;
- for (i = 0; i < edges.size(); i++) {
- PPath edge = (PPath) edges.get(i);
- ArrayList nodes = (ArrayList) edge.getAttribute("nodes");
- PNode node1 = (PNode) nodes.get(0);
- PNode node2 = (PNode) nodes.get(1);
+ ArrayList edges = (ArrayList) e.getPickedNode().getAttribute("edges");
- edge.reset();
- // Note that the node's "FullBounds" must be used (instead of just the "Bound")
- // because the nodes have non-identity transforms which must be included when
- // determining their position.
- Point2D.Double bound1 = (Point2D.Double) node1.getFullBounds().getCenter2D();
- Point2D.Double bound2 = (Point2D.Double) node2.getFullBounds().getCenter2D();
+ int i;
+ for (i = 0; i < edges.size(); i++) {
+ PPath edge = (PPath) edges.get(i);
+ ArrayList nodes = (ArrayList) edge.getAttribute("nodes");
+ PNode node1 = (PNode) nodes.get(0);
+ PNode node2 = (PNode) nodes.get(1);
- edge.moveTo((float) bound1.getX(), (float) bound1.getY());
- edge.lineTo((float) bound2.getX(), (float) bound2.getY());
- }
- }
- }
+ edge.reset();
+ // Note that the node's "FullBounds" must be used (instead of
+ // just the "Bound") because the nodes have non-identity
+ // transforms which must be included when determining their
+ // position.
+ Point2D.Double bound1 = (Point2D.Double) node1.getFullBounds().getCenter2D();
+ Point2D.Double bound2 = (Point2D.Double) node2.getFullBounds().getCenter2D();
+
+ edge.moveTo((float) bound1.getX(), (float) bound1.getY());
+ edge.lineTo((float) bound2.getX(), (float) bound2.getY());
+ }
+ }
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java
index e19d9dc..a915606 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java
@@ -25,121 +25,120 @@
*/
public class GridExample extends PFrame {
- static protected Line2D gridLine = new Line2D.Double();
- static protected Stroke gridStroke = new BasicStroke(1);
- static protected Color gridPaint = Color.BLACK;
- static protected double gridSpacing = 20;
+ static protected Line2D gridLine = new Line2D.Double();
+ static protected Stroke gridStroke = new BasicStroke(1);
+ static protected Color gridPaint = Color.BLACK;
+ static protected double gridSpacing = 20;
- public GridExample() {
- this(null);
- }
+ public GridExample() {
+ this(null);
+ }
- public GridExample(PCanvas aCanvas) {
- super("GridExample", false, aCanvas);
- }
+ public GridExample(PCanvas aCanvas) {
+ super("GridExample", false, aCanvas);
+ }
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- final PCamera camera = getCanvas().getCamera();
- final PLayer gridLayer = new PLayer() {
- protected void paint(PPaintContext paintContext) {
- // make sure grid gets drawn on snap to grid boundaries. And
- // expand a little to make sure that entire view is filled.
- double bx = (getX() - (getX() % gridSpacing)) - gridSpacing;
- double by = (getY() - (getY() % gridSpacing)) - gridSpacing;
- double rightBorder = getX() + getWidth() + gridSpacing;
- double bottomBorder = getY() + getHeight() + gridSpacing;
+ public void initialize() {
+ PRoot root = getCanvas().getRoot();
+ final PCamera camera = getCanvas().getCamera();
+ final PLayer gridLayer = new PLayer() {
+ protected void paint(PPaintContext paintContext) {
+ // make sure grid gets drawn on snap to grid boundaries. And
+ // expand a little to make sure that entire view is filled.
+ double bx = (getX() - (getX() % gridSpacing)) - gridSpacing;
+ double by = (getY() - (getY() % gridSpacing)) - gridSpacing;
+ double rightBorder = getX() + getWidth() + gridSpacing;
+ double bottomBorder = getY() + getHeight() + gridSpacing;
- Graphics2D g2 = paintContext.getGraphics();
- Rectangle2D clip = paintContext.getLocalClip();
+ Graphics2D g2 = paintContext.getGraphics();
+ Rectangle2D clip = paintContext.getLocalClip();
- g2.setStroke(gridStroke);
- g2.setPaint(gridPaint);
+ g2.setStroke(gridStroke);
+ g2.setPaint(gridPaint);
- for (double x = bx; x < rightBorder; x += gridSpacing) {
- gridLine.setLine(x, by, x, bottomBorder);
- if (clip.intersectsLine(gridLine)) {
- g2.draw(gridLine);
- }
- }
+ for (double x = bx; x < rightBorder; x += gridSpacing) {
+ gridLine.setLine(x, by, x, bottomBorder);
+ if (clip.intersectsLine(gridLine)) {
+ g2.draw(gridLine);
+ }
+ }
- for (double y = by; y < bottomBorder; y += gridSpacing) {
- gridLine.setLine(bx, y, rightBorder, y);
- if (clip.intersectsLine(gridLine)) {
- g2.draw(gridLine);
- }
- }
- }
- };
-
- // replace standar layer with grid layer.
- root.removeChild(camera.getLayer(0));
- camera.removeLayer(0);
- root.addChild(gridLayer);
- camera.addLayer(gridLayer);
+ for (double y = by; y < bottomBorder; y += gridSpacing) {
+ gridLine.setLine(bx, y, rightBorder, y);
+ if (clip.intersectsLine(gridLine)) {
+ g2.draw(gridLine);
+ }
+ }
+ }
+ };
- // add constrains so that grid layers bounds always match cameras view bounds. This makes
- // it look like an infinite grid.
- camera.addPropertyChangeListener(PNode.PROPERTY_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- gridLayer.setBounds(camera.getViewBounds());
- }
- });
+ // replace standar layer with grid layer.
+ root.removeChild(camera.getLayer(0));
+ camera.removeLayer(0);
+ root.addChild(gridLayer);
+ camera.addLayer(gridLayer);
- camera.addPropertyChangeListener(PCamera.PROPERTY_VIEW_TRANSFORM, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- gridLayer.setBounds(camera.getViewBounds());
- }
- });
+ // add constrains so that grid layers bounds always match cameras view
+ // bounds. This makes it look like an infinite grid.
+ camera.addPropertyChangeListener(PNode.PROPERTY_BOUNDS, new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ gridLayer.setBounds(camera.getViewBounds());
+ }
+ });
- gridLayer.setBounds(camera.getViewBounds());
+ camera.addPropertyChangeListener(PCamera.PROPERTY_VIEW_TRANSFORM, new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ gridLayer.setBounds(camera.getViewBounds());
+ }
+ });
- PNode n = new PNode();
- n.setPaint(Color.BLUE);
- n.setBounds(0, 0, 100, 80);
-
- getCanvas().getLayer().addChild(n);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
-
- // add a drag event handler that supports snap to grid.
- getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
-
- protected PNode draggedNode;
- protected Point2D nodeStartPosition;
-
- protected boolean shouldStartDragInteraction(PInputEvent event) {
- if (super.shouldStartDragInteraction(event)) {
- return event.getPickedNode() != event.getTopCamera() && !(event.getPickedNode() instanceof PLayer);
- }
- return false;
- }
+ gridLayer.setBounds(camera.getViewBounds());
- protected void startDrag(PInputEvent event) {
- super.startDrag(event);
- draggedNode = event.getPickedNode();
- draggedNode.moveToFront();
- nodeStartPosition = draggedNode.getOffset();
- }
+ PNode n = new PNode();
+ n.setPaint(Color.BLUE);
+ n.setBounds(0, 0, 100, 80);
- protected void drag(PInputEvent event) {
- super.drag(event);
-
- Point2D start = getCanvas().getCamera().localToView((Point2D)getMousePressedCanvasPoint().clone());
- Point2D current = event.getPositionRelativeTo(getCanvas().getLayer());
- Point2D dest = new Point2D.Double();
+ getCanvas().getLayer().addChild(n);
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- dest.setLocation(nodeStartPosition.getX() + (current.getX() - start.getX()),
- nodeStartPosition.getY() + (current.getY() - start.getY()));
-
- dest.setLocation(dest.getX() - (dest.getX() % gridSpacing),
- dest.getY() - (dest.getY() % gridSpacing));
+ // add a drag event handler that supports snap to grid.
+ getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
- draggedNode.setOffset(dest.getX(), dest.getY());
- }
- });
- }
-
- public static void main(String[] args) {
- new GridExample();
- }
+ protected PNode draggedNode;
+ protected Point2D nodeStartPosition;
+
+ protected boolean shouldStartDragInteraction(PInputEvent event) {
+ if (super.shouldStartDragInteraction(event)) {
+ return event.getPickedNode() != event.getTopCamera() && !(event.getPickedNode() instanceof PLayer);
+ }
+ return false;
+ }
+
+ protected void startDrag(PInputEvent event) {
+ super.startDrag(event);
+ draggedNode = event.getPickedNode();
+ draggedNode.moveToFront();
+ nodeStartPosition = draggedNode.getOffset();
+ }
+
+ protected void drag(PInputEvent event) {
+ super.drag(event);
+
+ Point2D start = getCanvas().getCamera().localToView((Point2D) getMousePressedCanvasPoint().clone());
+ Point2D current = event.getPositionRelativeTo(getCanvas().getLayer());
+ Point2D dest = new Point2D.Double();
+
+ dest.setLocation(nodeStartPosition.getX() + (current.getX() - start.getX()), nodeStartPosition.getY()
+ + (current.getY() - start.getY()));
+
+ dest.setLocation(dest.getX() - (dest.getX() % gridSpacing), dest.getY() - (dest.getY() % gridSpacing));
+
+ draggedNode.setOffset(dest.getX(), dest.getY());
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+ new GridExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java
index 9ccc469..5645f02 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
@@ -14,179 +15,191 @@
import edu.umd.cs.piccolox.event.PSelectionEventHandler;
/**
- * An example of how to implement decorator groups. Decorator groups are nodes that base their bounds and rendering on their children.
- * This seems to be a common type of visual node that requires some potentially non-obvious subclassing to get right.
+ * An example of how to implement decorator groups. Decorator groups are nodes
+ * that base their bounds and rendering on their children. This seems to be a
+ * common type of visual node that requires some potentially non-obvious
+ * subclassing to get right.
*
- * Both a volatile and a non-volatile implementation are shown. The volatile implementation might be used in cases where you want to
- * keep a scale-independent pen width border around a group of objects. The non-volatile implementation can be used in more standard
- * cases where the decorator's bounds are stable during zooming.
+ * Both a volatile and a non-volatile implementation are shown. The volatile
+ * implementation might be used in cases where you want to keep a
+ * scale-independent pen width border around a group of objects. The
+ * non-volatile implementation can be used in more standard cases where the
+ * decorator's bounds are stable during zooming.
*
* @author Lance Good
*/
public class GroupExample extends PFrame {
- public GroupExample() {
- this(null);
- }
+ public GroupExample() {
+ this(null);
+ }
- public GroupExample(PCanvas aCanvas) {
- super("GroupExample", false, aCanvas);
- }
+ public GroupExample(PCanvas aCanvas) {
+ super("GroupExample", false, aCanvas);
+ }
- public void initialize() {
- super.initialize();
-
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ public void initialize() {
+ super.initialize();
- // Create a decorator group that is NOT volatile
- DecoratorGroup dg = new DecoratorGroup();
- dg.setPaint(Color.magenta);
-
- // Put some nodes under the group for it to decorate
- PPath p1 = PPath.createEllipse(25,25,75,75);
- p1.setPaint(Color.red);
- PPath p2 = PPath.createRectangle(125,75,50,50);
- p2.setPaint(Color.blue);
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- // Add everything to the Piccolo hierarchy
- dg.addChild(p1);
- dg.addChild(p2);
- getCanvas().getLayer().addChild(dg);
+ // Create a decorator group that is NOT volatile
+ DecoratorGroup dg = new DecoratorGroup();
+ dg.setPaint(Color.magenta);
- // Create a decorator group that IS volatile
- VolatileDecoratorGroup vdg = new VolatileDecoratorGroup(getCanvas().getCamera());
- vdg.setPaint(Color.cyan);
-
- // Put some nodes under the group for it to decorate
- PPath p3 = PPath.createEllipse(275,175,50,50);
- p3.setPaint(Color.blue);
- PPath p4 = PPath.createRectangle(175,175,75,75);
- p4.setPaint(Color.green);
-
- // Add everything to the Piccolo hierarchy
- vdg.addChild(p3);
- vdg.addChild(p4);
- getCanvas().getLayer().addChild(vdg);
+ // Put some nodes under the group for it to decorate
+ PPath p1 = PPath.createEllipse(25, 25, 75, 75);
+ p1.setPaint(Color.red);
+ PPath p2 = PPath.createRectangle(125, 75, 50, 50);
+ p2.setPaint(Color.blue);
- // Create a selection handler so we can see that the decorator actually works
- ArrayList selectableParents = new ArrayList();
- selectableParents.add(dg);
- selectableParents.add(vdg);
-
- PSelectionEventHandler ps = new PSelectionEventHandler(getCanvas().getLayer(),selectableParents);
- getCanvas().addInputEventListener(ps);
- }
-
- public static void main(String[] args) {
- new GroupExample();
- }
+ // Add everything to the Piccolo hierarchy
+ dg.addChild(p1);
+ dg.addChild(p2);
+ getCanvas().getLayer().addChild(dg);
+
+ // Create a decorator group that IS volatile
+ VolatileDecoratorGroup vdg = new VolatileDecoratorGroup(getCanvas().getCamera());
+ vdg.setPaint(Color.cyan);
+
+ // Put some nodes under the group for it to decorate
+ PPath p3 = PPath.createEllipse(275, 175, 50, 50);
+ p3.setPaint(Color.blue);
+ PPath p4 = PPath.createRectangle(175, 175, 75, 75);
+ p4.setPaint(Color.green);
+
+ // Add everything to the Piccolo hierarchy
+ vdg.addChild(p3);
+ vdg.addChild(p4);
+ getCanvas().getLayer().addChild(vdg);
+
+ // Create a selection handler so we can see that the decorator actually
+ // works
+ ArrayList selectableParents = new ArrayList();
+ selectableParents.add(dg);
+ selectableParents.add(vdg);
+
+ PSelectionEventHandler ps = new PSelectionEventHandler(getCanvas().getLayer(), selectableParents);
+ getCanvas().addInputEventListener(ps);
+ }
+
+ public static void main(String[] args) {
+ new GroupExample();
+ }
}
-
+
/**
- * This is the non-volatile implementation of a decorator group that paints a background rectangle based
- * on the bounds of its children.
+ * This is the non-volatile implementation of a decorator group that paints a
+ * background rectangle based on the bounds of its children.
*/
class DecoratorGroup extends PNode {
- int INDENT = 10;
+ int INDENT = 10;
- PBounds cachedChildBounds = new PBounds();
- PBounds comparisonBounds = new PBounds();
-
- public DecoratorGroup() {
- super();
- }
-
- /**
- * Change the default paint to fill an expanded bounding box based on its children's bounds
- */
- public void paint(PPaintContext ppc) {
- Paint paint = getPaint();
- if (paint != null) {
- Graphics2D g2 = ppc.getGraphics();
- g2.setPaint(paint);
-
- PBounds bounds = getUnionOfChildrenBounds(null);
- bounds.setRect(bounds.getX()-INDENT,bounds.getY()-INDENT,bounds.getWidth()+2*INDENT,bounds.getHeight()+2*INDENT);
- g2.fill(bounds);
- }
- }
-
- /**
- * Change the full bounds computation to take into account that we are expanding the children's bounds
- * Do this instead of overriding getBoundsReference() since the node is not volatile
- */
- public PBounds computeFullBounds(PBounds dstBounds) {
- PBounds result = getUnionOfChildrenBounds(dstBounds);
-
- cachedChildBounds.setRect(result);
- result.setRect(result.getX()-INDENT,result.getY()-INDENT,result.getWidth()+2*INDENT,result.getHeight()+2*INDENT);
- localToParent(result);
- return result;
- }
-
- /**
- * This is a crucial step. We have to override this method to invalidate the paint each time the bounds are changed so
- * we repaint the correct region
- */
- public boolean validateFullBounds() {
- comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
-
- if (!cachedChildBounds.equals(comparisonBounds)) {
- setPaintInvalid(true);
- }
- return super.validateFullBounds();
- }
+ PBounds cachedChildBounds = new PBounds();
+ PBounds comparisonBounds = new PBounds();
+
+ public DecoratorGroup() {
+ super();
+ }
+
+ /**
+ * Change the default paint to fill an expanded bounding box based on its
+ * children's bounds
+ */
+ public void paint(PPaintContext ppc) {
+ Paint paint = getPaint();
+ if (paint != null) {
+ Graphics2D g2 = ppc.getGraphics();
+ g2.setPaint(paint);
+
+ PBounds bounds = getUnionOfChildrenBounds(null);
+ bounds.setRect(bounds.getX() - INDENT, bounds.getY() - INDENT, bounds.getWidth() + 2 * INDENT, bounds
+ .getHeight()
+ + 2 * INDENT);
+ g2.fill(bounds);
+ }
+ }
+
+ /**
+ * Change the full bounds computation to take into account that we are
+ * expanding the children's bounds Do this instead of overriding
+ * getBoundsReference() since the node is not volatile
+ */
+ public PBounds computeFullBounds(PBounds dstBounds) {
+ PBounds result = getUnionOfChildrenBounds(dstBounds);
+
+ cachedChildBounds.setRect(result);
+ result.setRect(result.getX() - INDENT, result.getY() - INDENT, result.getWidth() + 2 * INDENT, result
+ .getHeight()
+ + 2 * INDENT);
+ localToParent(result);
+ return result;
+ }
+
+ /**
+ * This is a crucial step. We have to override this method to invalidate the
+ * paint each time the bounds are changed so we repaint the correct region
+ */
+ public boolean validateFullBounds() {
+ comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
+
+ if (!cachedChildBounds.equals(comparisonBounds)) {
+ setPaintInvalid(true);
+ }
+ return super.validateFullBounds();
+ }
}
-
+
/**
- * This is the volatile implementation of a decorator group that paints a background rectangle based
- * on the bounds of its children.
+ * This is the volatile implementation of a decorator group that paints a
+ * background rectangle based on the bounds of its children.
*/
class VolatileDecoratorGroup extends PNode {
- int INDENT = 10;
+ int INDENT = 10;
- PBounds cachedChildBounds = new PBounds();
- PBounds comparisonBounds = new PBounds();
- PCamera renderCamera;
+ PBounds cachedChildBounds = new PBounds();
+ PBounds comparisonBounds = new PBounds();
+ PCamera renderCamera;
- public VolatileDecoratorGroup(PCamera camera) {
- super();
- renderCamera = camera;
- }
-
- /**
- * Indicate that the bounds are volatile for this group
- */
- public boolean getBoundsVolatile() {
- return true;
- }
-
- /**
- * Since our bounds are volatile, we can override this method to indicate that we are expanding our bounds beyond our children
- */
- public PBounds getBoundsReference() {
- PBounds bds = super.getBoundsReference();
- getUnionOfChildrenBounds(bds);
+ public VolatileDecoratorGroup(PCamera camera) {
+ super();
+ renderCamera = camera;
+ }
- cachedChildBounds.setRect(bds);
- double scaledIndent = INDENT/renderCamera.getViewScale();
- bds.setRect(bds.getX()-scaledIndent,bds.getY()-scaledIndent,bds.getWidth()+2*scaledIndent,bds.getHeight()+2*scaledIndent);
-
- return bds;
- }
-
- /**
- * This is a crucial step. We have to override this method to invalidate the paint each time the bounds are changed so
- * we repaint the correct region
- */
- public boolean validateFullBounds() {
- comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
-
- if (!cachedChildBounds.equals(comparisonBounds)) {
- setPaintInvalid(true);
- }
- return super.validateFullBounds();
- }
+ /**
+ * Indicate that the bounds are volatile for this group
+ */
+ public boolean getBoundsVolatile() {
+ return true;
+ }
+
+ /**
+ * Since our bounds are volatile, we can override this method to indicate
+ * that we are expanding our bounds beyond our children
+ */
+ public PBounds getBoundsReference() {
+ PBounds bds = super.getBoundsReference();
+ getUnionOfChildrenBounds(bds);
+
+ cachedChildBounds.setRect(bds);
+ double scaledIndent = INDENT / renderCamera.getViewScale();
+ bds.setRect(bds.getX() - scaledIndent, bds.getY() - scaledIndent, bds.getWidth() + 2 * scaledIndent, bds
+ .getHeight()
+ + 2 * scaledIndent);
+
+ return bds;
+ }
+
+ /**
+ * This is a crucial step. We have to override this method to invalidate the
+ * paint each time the bounds are changed so we repaint the correct region
+ */
+ public boolean validateFullBounds() {
+ comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
+
+ if (!cachedChildBounds.equals(comparisonBounds)) {
+ setPaintInvalid(true);
+ }
+ return super.validateFullBounds();
+ }
}
-
-
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java
index 7430fec..da407c8 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.Color;
@@ -13,70 +14,76 @@
import edu.umd.cs.piccolox.util.PNodeLocator;
/**
- * This example show how to add the default handles to a node, and also how
- * to create your own custom handles.
+ * This example show how to add the default handles to a node, and also how to
+ * create your own custom handles.
*/
public class HandleExample extends PFrame {
-
- public HandleExample() {
- this(null);
- }
-
- public HandleExample(PCanvas aCanvas) {
- super("HandleExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath n = PPath.createRectangle(0, 0, 100, 80);
-
- // add another node the the root as a reference point so that we can
- // tell that our node is getting dragged, as opposed the the canvas
- // view being panned.
- getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
-
- getCanvas().getLayer().addChild(n);
-
- // tell the node to show its default handles.
- PBoundsHandle.addBoundsHandlesTo(n);
-
- // The default PBoundsHandle implementation doesn't work well with PPaths that have strokes. The reason
- // for this is that the default PBoundsHandle modifies the bounds of an PNode, but when adding handles to
- // a PPath we really want it to be modifying the underlying geometry of the PPath, the shape without the
- // stroke. The solution is that we need to create handles specific to PPaths that locate themselves on the
- // paths internal geometry, not the external bounds geometry...
-
- n.setStroke(new BasicStroke(10));
- n.setPaint(Color.green);
-
- // Here we create our own custom handle. This handle is located in the center of its parent
- // node and you can use it to drag the parent around. This handle also updates its color when
- // the is pressed/released in it.
- final PHandle h = new PHandle(new PNodeLocator(n)) { // the default locator locates the center of a node.
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- getParent().translate(aLocalDimension.getWidth(), aLocalDimension.getHeight());
- }
- };
-
- h.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- h.setPaint(Color.YELLOW);
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- h.setPaint(Color.RED);
- }
- });
-
- // make this handle appear a bit different then the default handle appearance.
- h.setPaint(Color.RED);
- h.setBounds(-10, -10, 20, 20);
-
- // also add our new custom handle to the node.
- n.addChild(h);
- }
- public static void main(String[] args) {
- new HandleExample();
- }
+ public HandleExample() {
+ this(null);
+ }
+
+ public HandleExample(PCanvas aCanvas) {
+ super("HandleExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PPath n = PPath.createRectangle(0, 0, 100, 80);
+
+ // add another node the the root as a reference point so that we can
+ // tell that our node is getting dragged, as opposed the the canvas
+ // view being panned.
+ getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
+
+ getCanvas().getLayer().addChild(n);
+
+ // tell the node to show its default handles.
+ PBoundsHandle.addBoundsHandlesTo(n);
+
+ // The default PBoundsHandle implementation doesn't work well with
+ // PPaths that have strokes. The reason for this is that the default
+ // PBoundsHandle modifies the bounds of an PNode, but when adding
+ // handles to a PPath we really want it to be modifying the underlying
+ // geometry of the PPath, the shape without the stroke. The solution is
+ // that we need to create handles specific to PPaths that locate
+ // themselves on the paths internal geometry, not the external bounds
+ // geometry...
+
+ n.setStroke(new BasicStroke(10));
+ n.setPaint(Color.green);
+
+ // Here we create our own custom handle. This handle is located in the
+ // center of its parent node and you can use it to drag the parent
+ // around. This handle also updates its color when the is
+ // pressed/released in it.
+ final PHandle h = new PHandle(new PNodeLocator(n)) {
+ // the default locator locates the center of a node.
+ public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
+ localToParent(aLocalDimension);
+ getParent().translate(aLocalDimension.getWidth(), aLocalDimension.getHeight());
+ }
+ };
+
+ h.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent aEvent) {
+ h.setPaint(Color.YELLOW);
+ }
+
+ public void mouseReleased(PInputEvent aEvent) {
+ h.setPaint(Color.RED);
+ }
+ });
+
+ // make this handle appear a bit different then the default handle
+ // appearance.
+ h.setPaint(Color.RED);
+ h.setBounds(-10, -10, 20, 20);
+
+ // also add our new custom handle to the node.
+ n.addChild(h);
+ }
+
+ public static void main(String[] args) {
+ new HandleExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java
index 75967aa..292027c 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java
@@ -5,21 +5,21 @@
import edu.umd.cs.piccolox.PFrame;
public class HelloWorldExample extends PFrame {
-
- public HelloWorldExample() {
- this(null);
- }
-
- public HelloWorldExample(PCanvas aCanvas) {
- super("HelloWorldExample", false, aCanvas);
- }
- public void initialize() {
- PText text = new PText("Hello World");
- getCanvas().getLayer().addChild(text);
- }
+ public HelloWorldExample() {
+ this(null);
+ }
- public static void main(String[] args) {
- new HelloWorldExample();
- }
+ public HelloWorldExample(PCanvas aCanvas) {
+ super("HelloWorldExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PText text = new PText("Hello World");
+ getCanvas().getLayer().addChild(text);
+ }
+
+ public static void main(String[] args) {
+ new HelloWorldExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java
index d7ec773..59b0ba7 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java
@@ -12,39 +12,39 @@
*/
public class HierarchyZoomExample extends PFrame {
- public HierarchyZoomExample() {
- this(null);
- }
-
- public HierarchyZoomExample(PCanvas aCanvas) {
- super("HierarchyZoomExample", false, aCanvas);
- }
-
- public void initialize() {
- PNode root = createHierarchy(10);
- getCanvas().getLayer().addChild(root);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- getCanvas().getCamera().animateViewToCenterBounds(event.getPickedNode().getGlobalBounds(), true, 500);
- }
- });
- }
+ public HierarchyZoomExample() {
+ this(null);
+ }
- public PNode createHierarchy(int level) {
- PPath result = PPath.createRectangle(0, 0, 100, 100);
-
- if (level > 0) {
- PNode child = createHierarchy(level - 1);
- child.scale(0.5);
- result.addChild(child);
- child.offset(25, 25);
- }
-
- return result;
- }
+ public HierarchyZoomExample(PCanvas aCanvas) {
+ super("HierarchyZoomExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new HierarchyZoomExample();
- }
+ public void initialize() {
+ PNode root = createHierarchy(10);
+ getCanvas().getLayer().addChild(root);
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent event) {
+ getCanvas().getCamera().animateViewToCenterBounds(event.getPickedNode().getGlobalBounds(), true, 500);
+ }
+ });
+ }
+
+ public PNode createHierarchy(int level) {
+ PPath result = PPath.createRectangle(0, 0, 100, 100);
+
+ if (level > 0) {
+ PNode child = createHierarchy(level - 1);
+ child.scale(0.5);
+ result.addChild(child);
+ child.offset(25, 25);
+ }
+
+ return result;
+ }
+
+ public static void main(String[] args) {
+ new HierarchyZoomExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java
index f2c6d0d..31e3a50 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCanvas;
@@ -13,74 +14,79 @@
*/
public class KeyEventFocusExample extends PFrame {
- public KeyEventFocusExample() {
- this(null);
- }
+ public KeyEventFocusExample() {
+ this(null);
+ }
- public KeyEventFocusExample(PCanvas aCanvas) {
- super("KeyEventFocusExample", false, aCanvas);
- }
-
- public void initialize() {
- // Create a green and red node and add them to canvas layer.
- PCanvas canvas = getCanvas();
- PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
- PNode nodeRed = PPath.createRectangle(0, 0, 100, 100);
- nodeRed.translate(200, 0);
- nodeGreen.setPaint(Color.green);
- nodeRed.setPaint(Color.red);
- canvas.getLayer().addChild(nodeGreen);
- canvas.getLayer().addChild(nodeRed);
-
- // Add an event handler to the green node the prints "green mousepressed"
- // when the mouse is pressed on the green node, and "green keypressed" when
- // the key is pressed and the event listener has keyboard focus.
- nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
- public void keyPressed(PInputEvent event) {
- System.out.println("green keypressed");
- }
+ public KeyEventFocusExample(PCanvas aCanvas) {
+ super("KeyEventFocusExample", false, aCanvas);
+ }
- // Key board focus is managed by the PInputManager, accessible from
- // the root object, or from an incoming PInputEvent. In this case when
- // the mouse is pressed in the green node, then the event handler associated
- // with it will set the keyfocus to itself. Now it will receive key events
- // until someone else gets the focus.
- public void mousePressed(PInputEvent event) {
- event.getInputManager().setKeyboardFocus(event.getPath());
- System.out.println("green mousepressed");
- }
-
- public void keyboardFocusGained(PInputEvent event) {
- System.out.println("green focus gained");
- }
+ public void initialize() {
+ // Create a green and red node and add them to canvas layer.
+ PCanvas canvas = getCanvas();
+ PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
+ PNode nodeRed = PPath.createRectangle(0, 0, 100, 100);
+ nodeRed.translate(200, 0);
+ nodeGreen.setPaint(Color.green);
+ nodeRed.setPaint(Color.red);
+ canvas.getLayer().addChild(nodeGreen);
+ canvas.getLayer().addChild(nodeRed);
- public void keyboardFocusLost(PInputEvent event) {
- System.out.println("green focus lost");
- }
- });
-
- // do the same thing with the red node.
- nodeRed.addInputEventListener(new PBasicInputEventHandler() {
- public void keyPressed(PInputEvent event) {
- System.out.println("red keypressed");
- }
+ // Add an event handler to the green node the prints
+ // "green mousepressed"
+ // when the mouse is pressed on the green node, and "green keypressed"
+ // when
+ // the key is pressed and the event listener has keyboard focus.
+ nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
+ public void keyPressed(PInputEvent event) {
+ System.out.println("green keypressed");
+ }
- public void mousePressed(PInputEvent event) {
- event.getInputManager().setKeyboardFocus(event.getPath());
- System.out.println("red mousepressed");
- }
+ // Key board focus is managed by the PInputManager, accessible from
+ // the root object, or from an incoming PInputEvent. In this case
+ // when
+ // the mouse is pressed in the green node, then the event handler
+ // associated
+ // with it will set the keyfocus to itself. Now it will receive key
+ // events
+ // until someone else gets the focus.
+ public void mousePressed(PInputEvent event) {
+ event.getInputManager().setKeyboardFocus(event.getPath());
+ System.out.println("green mousepressed");
+ }
- public void keyboardFocusGained(PInputEvent event) {
- System.out.println("red focus gained");
- }
+ public void keyboardFocusGained(PInputEvent event) {
+ System.out.println("green focus gained");
+ }
- public void keyboardFocusLost(PInputEvent event) {
- System.out.println("red focus lost");
- }
- });
- }
+ public void keyboardFocusLost(PInputEvent event) {
+ System.out.println("green focus lost");
+ }
+ });
- public static void main(String[] args) {
- new KeyEventFocusExample();
- }
+ // do the same thing with the red node.
+ nodeRed.addInputEventListener(new PBasicInputEventHandler() {
+ public void keyPressed(PInputEvent event) {
+ System.out.println("red keypressed");
+ }
+
+ public void mousePressed(PInputEvent event) {
+ event.getInputManager().setKeyboardFocus(event.getPath());
+ System.out.println("red mousepressed");
+ }
+
+ public void keyboardFocusGained(PInputEvent event) {
+ System.out.println("red focus gained");
+ }
+
+ public void keyboardFocusLost(PInputEvent event) {
+ System.out.println("red focus lost");
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+ new KeyEventFocusExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java
index d5652ae..63d2d77 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import java.util.Iterator;
@@ -9,56 +10,55 @@
import edu.umd.cs.piccolox.handles.PBoundsHandle;
/**
- * This example shows how to create a node that will automatically
- * layout its children.
+ * This example shows how to create a node that will automatically layout its
+ * children.
*/
public class LayoutExample extends PFrame {
- public LayoutExample() {
- this(null);
- }
-
- public LayoutExample(PCanvas aCanvas) {
- super("LayoutExample", false, aCanvas);
- }
-
- public void initialize() {
- // Create a new node and override its validateLayoutAfterChildren method so
- // that it lays out its children in a row from left to
- // right.
-
- final PNode layoutNode = new PNode() {
- public void layoutChildren() {
- double xOffset = 0;
- double yOffset = 0;
+ public LayoutExample() {
+ this(null);
+ }
- Iterator i = getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- each.setOffset(xOffset - each.getX(), yOffset);
- xOffset += each.getWidth();
- }
- }
- };
-
- layoutNode.setPaint(Color.red);
+ public LayoutExample(PCanvas aCanvas) {
+ super("LayoutExample", false, aCanvas);
+ }
- // add some children to the layout node.
- for (int i = 0; i < 1000; i++) {
- // create child to add to the layout node.
- PNode each = PPath.createRectangle(0, 0, 100, 80);
+ public void initialize() {
+ // Create a new node and override its validateLayoutAfterChildren method
+ // so that it lays out its children in a row from left to right.
- // add the child to the layout node.
- layoutNode.addChild(each);
- }
-
- PBoundsHandle.addBoundsHandlesTo(layoutNode.getChild(0));
-
- // add layoutNode to the root so it will be displayed.
- getCanvas().getLayer().addChild(layoutNode);
- }
+ final PNode layoutNode = new PNode() {
+ public void layoutChildren() {
+ double xOffset = 0;
+ double yOffset = 0;
- public static void main(String[] args) {
- new LayoutExample();
- }
+ Iterator i = getChildrenIterator();
+ while (i.hasNext()) {
+ PNode each = (PNode) i.next();
+ each.setOffset(xOffset - each.getX(), yOffset);
+ xOffset += each.getWidth();
+ }
+ }
+ };
+
+ layoutNode.setPaint(Color.red);
+
+ // add some children to the layout node.
+ for (int i = 0; i < 1000; i++) {
+ // create child to add to the layout node.
+ PNode each = PPath.createRectangle(0, 0, 100, 80);
+
+ // add the child to the layout node.
+ layoutNode.addChild(each);
+ }
+
+ PBoundsHandle.addBoundsHandlesTo(layoutNode.getChild(0));
+
+ // add layoutNode to the root so it will be displayed.
+ getCanvas().getLayer().addChild(layoutNode);
+ }
+
+ public static void main(String[] args) {
+ new LayoutExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java
index 17374c2..a092103 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java
@@ -23,109 +23,118 @@
*/
public class LensExample extends PFrame {
- public LensExample() {
- this(null);
- }
-
- public LensExample(PCanvas aCanvas) {
- super("LensExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PCamera camera = getCanvas().getCamera();
- PLayer mainLayer = getCanvas().getLayer(); // viewed by the PCanvas camera, the lens is added to this layer.
- PLayer sharedLayer = new PLayer(); // viewed by both the lens camera and the PCanvas camera
- final PLayer lensOnlyLayer = new PLayer(); // viewed by only the lens camera
-
- root.addChild(lensOnlyLayer);
- root.addChild(sharedLayer);
- camera.addLayer(0, sharedLayer);
-
- final PLens lens = new PLens();
- lens.setBounds(10, 10, 100, 130);
- lens.addLayer(0, lensOnlyLayer);
- lens.addLayer(1, sharedLayer);
- mainLayer.addChild(lens);
- PBoundsHandle.addBoundsHandlesTo(lens);
-
- // Create an event handler that draws squiggles on the first layer of the bottom
- // most camera.
- PDragSequenceEventHandler squiggleEventHandler = new PDragSequenceEventHandler() {
- protected PPath squiggle;
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
- Point2D p = e.getPosition();
- squiggle = new PPath();
- squiggle.moveTo((float)p.getX(), (float)p.getY());
-
- // add squiggles to the first layer of the bottom camera. In the case of the
- // lens these squiggles will be added to the layer that is only visible by the lens,
- // In the case of the canvas camera the squiggles will be added to the shared layer
- // viewed by both the canvas camera and the lens.
- e.getCamera().getLayer(0).addChild(squiggle);
- }
-
- public void drag(PInputEvent e) {
- super.drag(e);
- updateSquiggle(e);
- }
-
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(PInputEvent aEvent) {
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float)p.getX(), (float)p.getY());
- }
- };
-
- // add the squiggle event handler to both the lens and the
- // canvas camera.
- lens.getCamera().addInputEventListener(squiggleEventHandler);
- camera.addInputEventListener(squiggleEventHandler);
+ public LensExample() {
+ this(null);
+ }
- // make sure that the event handler consumes events so that it doesn't
- // conflic with other event handlers or with itself (since its added to two
- // event sources).
- squiggleEventHandler.getEventFilter().setMarksAcceptedEventsAsHandled(true);
-
- // remove default event handlers, not really nessessary since the squiggleEventHandler
- // consumes everything anyway, but still good to do.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
-
- // create a node that is viewed both by the main camera and by the
- // lens. Note that in its paint method it checks to see which camera
- // is painting it, and if its the lens uses a different color.
- PNode sharedNode = new PNode() {
- protected void paint(PPaintContext paintContext) {
- if (paintContext.getCamera() == lens.getCamera()) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(Color.RED);
- g2.fill(getBoundsReference());
- } else {
- super.paint(paintContext);
- }
- }
- };
- sharedNode.setPaint(Color.GREEN);
- sharedNode.setBounds(0, 0, 100, 200);
- sharedNode.translate(200, 200);
- sharedLayer.addChild(sharedNode);
-
- PText label = new PText("Move the lens \n (by dragging title bar) over the green rectangle, and it will appear red. press and drag the mouse on the canvas and it will draw squiggles. press and drag the mouse over the lens and drag squiggles that are only visible through the lens.");
- label.setConstrainWidthToTextWidth(false);
- label.setConstrainHeightToTextHeight(false);
- label.setBounds(200, 100, 200, 200);
-
- sharedLayer.addChild(label);
- }
-
- public static void main(String[] args) {
- new LensExample();
- }
+ public LensExample(PCanvas aCanvas) {
+ super("LensExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PRoot root = getCanvas().getRoot();
+ PCamera camera = getCanvas().getCamera();
+ // viewed by the PCanvas camera, the lens is added to this layer.
+ PLayer mainLayer = getCanvas().getLayer();
+ // viewed by both the lens camera and the PCanvas camera
+ PLayer sharedLayer = new PLayer();
+ // viewed by only the lens camera
+ final PLayer lensOnlyLayer = new PLayer();
+
+ root.addChild(lensOnlyLayer);
+ root.addChild(sharedLayer);
+ camera.addLayer(0, sharedLayer);
+
+ final PLens lens = new PLens();
+ lens.setBounds(10, 10, 100, 130);
+ lens.addLayer(0, lensOnlyLayer);
+ lens.addLayer(1, sharedLayer);
+ mainLayer.addChild(lens);
+ PBoundsHandle.addBoundsHandlesTo(lens);
+
+ // Create an event handler that draws squiggles on the first layer of
+ // the bottom most camera.
+ PDragSequenceEventHandler squiggleEventHandler = new PDragSequenceEventHandler() {
+ protected PPath squiggle;
+
+ public void startDrag(PInputEvent e) {
+ super.startDrag(e);
+ Point2D p = e.getPosition();
+ squiggle = new PPath();
+ squiggle.moveTo((float) p.getX(), (float) p.getY());
+
+ // add squiggles to the first layer of the bottom camera. In the
+ // case of the lens these squiggles will be added to the layer
+ // that is only visible by the lens,
+ // In the case of the canvas camera the squiggles will be added
+ // to the shared layer viewed by both the canvas camera and the
+ // lens.
+ e.getCamera().getLayer(0).addChild(squiggle);
+ }
+
+ public void drag(PInputEvent e) {
+ super.drag(e);
+ updateSquiggle(e);
+ }
+
+ public void endDrag(PInputEvent e) {
+ super.endDrag(e);
+ updateSquiggle(e);
+ squiggle = null;
+ }
+
+ public void updateSquiggle(PInputEvent aEvent) {
+ Point2D p = aEvent.getPosition();
+ squiggle.lineTo((float) p.getX(), (float) p.getY());
+ }
+ };
+
+ // add the squiggle event handler to both the lens and the
+ // canvas camera.
+ lens.getCamera().addInputEventListener(squiggleEventHandler);
+ camera.addInputEventListener(squiggleEventHandler);
+
+ // make sure that the event handler consumes events so that it doesn't
+ // conflic with other event handlers or with itself (since its added to
+ // two event sources).
+ squiggleEventHandler.getEventFilter().setMarksAcceptedEventsAsHandled(true);
+
+ // remove default event handlers, not really nessessary since the
+ // squiggleEventHandler consumes everything anyway, but still good to
+ // do.
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
+
+ // create a node that is viewed both by the main camera and by the
+ // lens. Note that in its paint method it checks to see which camera
+ // is painting it, and if its the lens uses a different color.
+ PNode sharedNode = new PNode() {
+ protected void paint(PPaintContext paintContext) {
+ if (paintContext.getCamera() == lens.getCamera()) {
+ Graphics2D g2 = paintContext.getGraphics();
+ g2.setPaint(Color.RED);
+ g2.fill(getBoundsReference());
+ }
+ else {
+ super.paint(paintContext);
+ }
+ }
+ };
+ sharedNode.setPaint(Color.GREEN);
+ sharedNode.setBounds(0, 0, 100, 200);
+ sharedNode.translate(200, 200);
+ sharedLayer.addChild(sharedNode);
+
+ PText label = new PText(
+ "Move the lens \n (by dragging title bar) over the green rectangle, and it will appear red. press and drag the mouse on the canvas and it will draw squiggles. press and drag the mouse over the lens and drag squiggles that are only visible through the lens.");
+ label.setConstrainWidthToTextWidth(false);
+ label.setConstrainHeightToTextHeight(false);
+ label.setBounds(200, 100, 200, 200);
+
+ sharedLayer.addChild(label);
+ }
+
+ public static void main(String[] args) {
+ new LensExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java
index cb7ef22..090c490 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Random;
@@ -11,32 +12,32 @@
public class NavigationExample extends PFrame {
- public NavigationExample() {
- this(null);
- }
-
- public NavigationExample(PCanvas aCanvas) {
- super("NavigationExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- PPath each = PPath.createRectangle(0, 0, 100, 80);
- each.scale(random.nextFloat() * 2);
- each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
- each.setPaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
- each.setStrokePaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- layer.addChild(each);
- }
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PNavigationEventHandler());
- }
+ public NavigationExample() {
+ this(null);
+ }
- public static void main(String[] args) {
- new NavigationExample();
- }
+ public NavigationExample(PCanvas aCanvas) {
+ super("NavigationExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PLayer layer = getCanvas().getLayer();
+
+ Random random = new Random();
+ for (int i = 0; i < 1000; i++) {
+ PPath each = PPath.createRectangle(0, 0, 100, 80);
+ each.scale(random.nextFloat() * 2);
+ each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
+ each.setPaint(new Color(random.nextFloat(), random.nextFloat(), random.nextFloat()));
+ each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
+ each.setStrokePaint(new Color(random.nextFloat(), random.nextFloat(), random.nextFloat()));
+ layer.addChild(each);
+ }
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PNavigationEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new NavigationExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java
index 744fe06..0ddb3db 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java
@@ -11,37 +11,37 @@
public class NodeCacheExample extends PFrame {
- public NodeCacheExample() {
- this(null);
- }
-
- public NodeCacheExample(PCanvas aCanvas) {
- super("NodeCacheExample", false, aCanvas);
- }
+ public NodeCacheExample() {
+ this(null);
+ }
- public void initialize() {
- PCanvas canvas = getCanvas();
-
- PPath circle = PPath.createEllipse(0, 0, 100, 100);
- circle.setStroke(new BasicStroke(10));
- circle.setPaint(Color.YELLOW);
-
- PPath rectangle = PPath.createRectangle(-100, -50, 100, 100);
- rectangle.setStroke(new BasicStroke(15));
- rectangle.setPaint(Color.ORANGE);
-
- PNodeCache cache = new PNodeCache();
- cache.addChild(circle);
- cache.addChild(rectangle);
-
- cache.invalidateCache();
-
- canvas.getLayer().addChild(cache);
- canvas.removeInputEventListener(canvas.getPanEventHandler());
- canvas.addInputEventListener(new PDragEventHandler());
- }
+ public NodeCacheExample(PCanvas aCanvas) {
+ super("NodeCacheExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new NodeCacheExample();
- }
+ public void initialize() {
+ PCanvas canvas = getCanvas();
+
+ PPath circle = PPath.createEllipse(0, 0, 100, 100);
+ circle.setStroke(new BasicStroke(10));
+ circle.setPaint(Color.YELLOW);
+
+ PPath rectangle = PPath.createRectangle(-100, -50, 100, 100);
+ rectangle.setStroke(new BasicStroke(15));
+ rectangle.setPaint(Color.ORANGE);
+
+ PNodeCache cache = new PNodeCache();
+ cache.addChild(circle);
+ cache.addChild(rectangle);
+
+ cache.invalidateCache();
+
+ canvas.getLayer().addChild(cache);
+ canvas.removeInputEventListener(canvas.getPanEventHandler());
+ canvas.addInputEventListener(new PDragEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new NodeCacheExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java
index 10369d1..293dfa6 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import java.awt.geom.Dimension2D;
@@ -15,85 +16,89 @@
*/
public class NodeEventExample extends PFrame {
- public NodeEventExample() {
- this(null);
- }
+ public NodeEventExample() {
+ this(null);
+ }
- public NodeEventExample(PCanvas aCanvas) {
- super("NodeEventExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- // create a new node and override some of the event handling
- // methods so that the node changes to orange when the mouse (Button 1) is
- // pressed on the node, and changes back to green when the mouse
- // is released. Also when the mouse is dragged the node updates its
- // position so that the node is "dragged". Note that this only serves
- // as a simple example, most of the time dragging nodes is best done
- // with the PDragEventHandler, but this shows another way to do it.
- //
- // Note that each of these methods marks the event as handled. This is so that
- // when the node is being dragged the zoom and pan event handles
- // (that are installed by default) do not also operate, but they will
- // still respond to events that are not handled by the node. (try to uncomment
- // the aEvent.setHandled() calls and see what happens.
- final PNode aNode = new PNode();
- aNode.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- aNode.setPaint(Color.orange);
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- public void mouseDragged(PInputEvent aEvent) {
- Dimension2D delta = aEvent.getDeltaRelativeTo(aNode);
- aNode.translate(delta.getWidth(), delta.getHeight());
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- aNode.setPaint(Color.green);
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- // Note this slows things down a lot, comment it out to see how the normal
- // speed of things is.
- //
- // For fun the coords of each event that the node handles are printed out.
- // This can help to understand how coordinate systems work. Notice that when
- // the example first starts all the values for (canvas, global, and local) are
- // equal. But once you drag the node then the local coordinates become different
- // then the screen and global coordinates. When you pan or zoom then the screen
- // coordinates become different from the global coordinates.
- public void printEventCoords(PInputEvent aEvent) {
- System.out.println("Canvas Location: " + aEvent.getCanvasPosition());
- //System.out.println("Global Location: " + aEvent.getGlobalLocation());
- System.out.println("Local Location: " + aEvent.getPositionRelativeTo(aNode));
- System.out.println("Canvas Delta: " + aEvent.getCanvasDelta());
- //System.out.println("Global Delta: " + aEvent.getGlobalDelta());
- System.out.println("Local Delta: " + aEvent.getDeltaRelativeTo(aNode));
- }
- });
- aNode.setBounds(0, 0, 200, 200);
- aNode.setPaint(Color.green);
+ public NodeEventExample(PCanvas aCanvas) {
+ super("NodeEventExample", false, aCanvas);
+ }
- // By default the filter accepts all events, but here we constrain the kinds of
- // events that aNode receives to button 1 events. Comment this line out and then
- // you will be able to drag the node with any mouse button.
- //aNode.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+ public void initialize() {
+ PLayer layer = getCanvas().getLayer();
- // add another node to the canvas that does not handle events as a reference
- // point, so that we can make sure that our green node is getting dragged.
- layer.addChild(PPath.createRectangle(0, 0, 100, 80));
- layer.addChild(aNode);
- }
+ // create a new node and override some of the event handling
+ // methods so that the node changes to orange when the mouse (Button 1)
+ // is pressed on the node, and changes back to green when the mouse
+ // is released. Also when the mouse is dragged the node updates its
+ // position so that the node is "dragged". Note that this only serves
+ // as a simple example, most of the time dragging nodes is best done
+ // with the PDragEventHandler, but this shows another way to do it.
+ //
+ // Note that each of these methods marks the event as handled. This is
+ // so that when the node is being dragged the zoom and pan event handles
+ // (that are installed by default) do not also operate, but they will
+ // still respond to events that are not handled by the node. (try to
+ // uncomment the aEvent.setHandled() calls and see what happens.
+ final PNode aNode = new PNode();
+ aNode.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent aEvent) {
+ aNode.setPaint(Color.orange);
+ printEventCoords(aEvent);
+ aEvent.setHandled(true);
+ }
- public static void main(String[] args) {
- new NodeEventExample();
- }
+ public void mouseDragged(PInputEvent aEvent) {
+ Dimension2D delta = aEvent.getDeltaRelativeTo(aNode);
+ aNode.translate(delta.getWidth(), delta.getHeight());
+ printEventCoords(aEvent);
+ aEvent.setHandled(true);
+ }
+
+ public void mouseReleased(PInputEvent aEvent) {
+ aNode.setPaint(Color.green);
+ printEventCoords(aEvent);
+ aEvent.setHandled(true);
+ }
+
+ // Note this slows things down a lot, comment it out to see how the
+ // normal speed of things is.
+ //
+ // For fun the coords of each event that the node handles are
+ // printed out. This can help to understand how coordinate systems
+ // work. Notice that when the example first starts all the values
+ // for (canvas, global, and local) are equal. But once you drag the
+ // node then the local coordinates become different then the screen
+ // and global coordinates. When you pan or zoom then the screen
+ // coordinates become different from the global coordinates.
+ public void printEventCoords(PInputEvent aEvent) {
+ System.out.println("Canvas Location: " + aEvent.getCanvasPosition());
+ // System.out.println("Global Location: " +
+ // aEvent.getGlobalLocation());
+ System.out.println("Local Location: " + aEvent.getPositionRelativeTo(aNode));
+ System.out.println("Canvas Delta: " + aEvent.getCanvasDelta());
+ // System.out.println("Global Delta: " +
+ // aEvent.getGlobalDelta());
+ System.out.println("Local Delta: " + aEvent.getDeltaRelativeTo(aNode));
+ }
+ });
+ aNode.setBounds(0, 0, 200, 200);
+ aNode.setPaint(Color.green);
+
+ // By default the filter accepts all events, but here we constrain the
+ // kinds of events that aNode receives to button 1 events. Comment this
+ // line out and then you will be able to drag the node with any mouse
+ // button.
+ // aNode.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+
+ // add another node to the canvas that does not handle events as a
+ // reference point, so that we can make sure that our green node is
+ // getting dragged.
+ layer.addChild(PPath.createRectangle(0, 0, 100, 80));
+ layer.addChild(aNode);
+ }
+
+ public static void main(String[] args) {
+ new NodeEventExample();
+ }
}
-
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java
index 033467e..c1c8240 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
@@ -23,200 +24,208 @@
*/
public class NodeExample extends PFrame {
- boolean fIsPressed = false;
-
- public NodeExample() {
- this(null);
- }
-
- public NodeExample(PCanvas aCanvas) {
- super("NodeExample", false, aCanvas);
- }
-
- public void initialize() {
- nodeDemo();
- createNodeUsingExistingClasses();
- subclassExistingClasses();
- composeOtherNodes();
- createCustomNode();
-
- // Last of all lets remove the default pan event handler, and add a
- // drag event handler instead. This way you will be able to drag the
- // nodes around with the mouse.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- // This method demonstrates the kinds of things that can be done with any node.
- public void nodeDemo() {
- PLayer layer = getCanvas().getLayer();
- PNode aNode = PPath.createRectangle(0, 0, 100, 80);
-
- // A node needs to be a descendent of the root to be displayed on the screen.
- layer.addChild(aNode);
-
- // The default color for a node is blue, but you can change that with
- // the setPaint method.
- aNode.setPaint(Color.red);
-
- // A node can have children nodes added to it.
- aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
-
- // The base bounds of a node is easy to change. Note that changing the base
- // bounds of a node will not change it's children.
- aNode.setBounds(-10, -10, 200, 110);
-
- // Each node has a transform that can be used to transform the node, and
- // all its children on the screen.
- aNode.translate(100, 100);
- aNode.scale(1.5);
- aNode.rotate(45);
-
- // The transparency of any node can be set, this transparency will be
- // applied to any of the nodes children as well.
- aNode.setTransparency(0.75f);
-
- // Its easy to copy nodes.
- PNode aCopy = (PNode) aNode.clone();
+ boolean fIsPressed = false;
- // Make is so that the copies children are not pickable. For this example
- // that means you will not be able to grab the child and remove it from
- // its parent.
- aNode.setChildrenPickable(false);
+ public NodeExample() {
+ this(null);
+ }
- // Change the look of the copy
- aNode.setPaint(Color.GREEN);
- aNode.setTransparency(1.0f);
-
- // Let's add the copy to the root, and translate it so that it does not
- // cover the original node.
- layer.addChild(aCopy);
- aCopy.setOffset(0, 0);
- aCopy.rotate(-45);
- }
-
- // So far we have just been using PNode, but of course PNode has many
- // subclasses that you can try out to.
- public void createNodeUsingExistingClasses() {
- PLayer layer = getCanvas().getLayer();
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
-
- // Here we create an image node that displays a thumbnail
- // image of the root node. Note that you can easily get a thumbnail
- // of any node by using PNode.toImage().
- PImage image = new PImage(layer.toImage(300, 300, null));
- layer.addChild(image);
- }
-
- // Another way to create nodes is to customize other nodes that already
- // exist. Here we create an ellipse, except when you press the mouse on
- // this ellipse it turns into a square, when you release the mouse it
- // goes back to being an ellipse.
- public void subclassExistingClasses() {
- final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
-
- public void paint(PPaintContext aPaintContext) {
- if (fIsPressed) {
- // if mouse is pressed draw self as a square.
- Graphics2D g2 = aPaintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- // if mouse is not pressed draw self normally.
- super.paint(aPaintContext);
- }
- }
- };
-
- n.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = true;
- n.invalidatePaint(); // this tells the framework that the node needs to be redisplayed.
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = false;
- n.invalidatePaint(); // this tells the framework that the node needs to be redisplayed.
- }
- });
-
- n.setPaint(Color.ORANGE);
- getCanvas().getLayer().addChild(n);
- }
-
- // Here a new "face" node is created. But instead of drawing the face directly
- // using Graphics2D we compose the face from other nodes.
- public void composeOtherNodes() {
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
-
- // add the face parts
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
-
- // don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
-
- // position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
-
- // set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- myCompositeFace.setBounds(b.inset(-5, -5));
-
- // opps it to small, so scale it up.
- myCompositeFace.scale(1.5);
-
- getCanvas().getLayer().addChild(myCompositeFace);
- }
-
- // Here a completely new kind of node, a grid node" is created. We do
- // all the drawing ourselves here instead of passing the work off to
- // other parts of the framework.
- public void createCustomNode() {
- PNode n = new PNode() {
- public void paint(PPaintContext aPaintContext) {
- double bx = getX();
- double by = getY();
- double rightBorder = bx + getWidth();
- double bottomBorder = by + getHeight();
-
- Line2D line = new Line2D.Double();
- Graphics2D g2 = aPaintContext.getGraphics();
-
- g2.setStroke(new BasicStroke(0));
- g2.setPaint(getPaint());
-
- // draw vertical lines
- for (double x = bx; x < rightBorder; x += 5) {
- line.setLine(x, by, x, bottomBorder);
- g2.draw(line);
- }
-
- for (double y = by; y < bottomBorder; y += 5) {
- line.setLine(bx, y, rightBorder, y);
- g2.draw(line);
- }
- }
- };
- n.setBounds(0, 0, 100, 80);
- n.setPaint(Color.black);
- getCanvas().getLayer().addChild(n);
- }
-
- public static void main(String[] args) {
- new NodeExample();
- }
+ public NodeExample(PCanvas aCanvas) {
+ super("NodeExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ nodeDemo();
+ createNodeUsingExistingClasses();
+ subclassExistingClasses();
+ composeOtherNodes();
+ createCustomNode();
+
+ // Last of all lets remove the default pan event handler, and add a
+ // drag event handler instead. This way you will be able to drag the
+ // nodes around with the mouse.
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PDragEventHandler());
+ }
+
+ // This method demonstrates the kinds of things that can be done with any
+ // node.
+ public void nodeDemo() {
+ PLayer layer = getCanvas().getLayer();
+ PNode aNode = PPath.createRectangle(0, 0, 100, 80);
+
+ // A node needs to be a descendent of the root to be displayed on the
+ // screen.
+ layer.addChild(aNode);
+
+ // The default color for a node is blue, but you can change that with
+ // the setPaint method.
+ aNode.setPaint(Color.red);
+
+ // A node can have children nodes added to it.
+ aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
+
+ // The base bounds of a node is easy to change. Note that changing the
+ // base
+ // bounds of a node will not change it's children.
+ aNode.setBounds(-10, -10, 200, 110);
+
+ // Each node has a transform that can be used to transform the node, and
+ // all its children on the screen.
+ aNode.translate(100, 100);
+ aNode.scale(1.5);
+ aNode.rotate(45);
+
+ // The transparency of any node can be set, this transparency will be
+ // applied to any of the nodes children as well.
+ aNode.setTransparency(0.75f);
+
+ // Its easy to copy nodes.
+ PNode aCopy = (PNode) aNode.clone();
+
+ // Make is so that the copies children are not pickable. For this
+ // example
+ // that means you will not be able to grab the child and remove it from
+ // its parent.
+ aNode.setChildrenPickable(false);
+
+ // Change the look of the copy
+ aNode.setPaint(Color.GREEN);
+ aNode.setTransparency(1.0f);
+
+ // Let's add the copy to the root, and translate it so that it does not
+ // cover the original node.
+ layer.addChild(aCopy);
+ aCopy.setOffset(0, 0);
+ aCopy.rotate(-45);
+ }
+
+ // So far we have just been using PNode, but of course PNode has many
+ // subclasses that you can try out to.
+ public void createNodeUsingExistingClasses() {
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(PPath.createEllipse(0, 0, 100, 100));
+ layer.addChild(PPath.createRectangle(0, 100, 100, 100));
+ layer.addChild(new PText("Hello World"));
+
+ // Here we create an image node that displays a thumbnail
+ // image of the root node. Note that you can easily get a thumbnail
+ // of any node by using PNode.toImage().
+ PImage image = new PImage(layer.toImage(300, 300, null));
+ layer.addChild(image);
+ }
+
+ // Another way to create nodes is to customize other nodes that already
+ // exist. Here we create an ellipse, except when you press the mouse on
+ // this ellipse it turns into a square, when you release the mouse it
+ // goes back to being an ellipse.
+ public void subclassExistingClasses() {
+ final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
+
+ public void paint(PPaintContext aPaintContext) {
+ if (fIsPressed) {
+ // if mouse is pressed draw self as a square.
+ Graphics2D g2 = aPaintContext.getGraphics();
+ g2.setPaint(getPaint());
+ g2.fill(getBoundsReference());
+ }
+ else {
+ // if mouse is not pressed draw self normally.
+ super.paint(aPaintContext);
+ }
+ }
+ };
+
+ n.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent aEvent) {
+ super.mousePressed(aEvent);
+ fIsPressed = true;
+ n.invalidatePaint(); // this tells the framework that the node
+ // needs to be redisplayed.
+ }
+
+ public void mouseReleased(PInputEvent aEvent) {
+ super.mousePressed(aEvent);
+ fIsPressed = false;
+ n.invalidatePaint(); // this tells the framework that the node
+ // needs to be redisplayed.
+ }
+ });
+
+ n.setPaint(Color.ORANGE);
+ getCanvas().getLayer().addChild(n);
+ }
+
+ // Here a new "face" node is created. But instead of drawing the face
+ // directly
+ // using Graphics2D we compose the face from other nodes.
+ public void composeOtherNodes() {
+ PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
+
+ // create parts for the face.
+ PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
+ eye1.setPaint(Color.YELLOW);
+ PNode eye2 = (PNode) eye1.clone();
+ PNode mouth = PPath.createRectangle(0, 0, 40, 20);
+ mouth.setPaint(Color.BLACK);
+
+ // add the face parts
+ myCompositeFace.addChild(eye1);
+ myCompositeFace.addChild(eye2);
+ myCompositeFace.addChild(mouth);
+
+ // don't want anyone grabbing out our eye's.
+ myCompositeFace.setChildrenPickable(false);
+
+ // position the face parts.
+ eye2.translate(25, 0);
+ mouth.translate(0, 30);
+
+ // set the face bounds so that it neatly contains the face parts.
+ PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
+ myCompositeFace.setBounds(b.inset(-5, -5));
+
+ // opps it to small, so scale it up.
+ myCompositeFace.scale(1.5);
+
+ getCanvas().getLayer().addChild(myCompositeFace);
+ }
+
+ // Here a completely new kind of node, a grid node" is created. We do
+ // all the drawing ourselves here instead of passing the work off to
+ // other parts of the framework.
+ public void createCustomNode() {
+ PNode n = new PNode() {
+ public void paint(PPaintContext aPaintContext) {
+ double bx = getX();
+ double by = getY();
+ double rightBorder = bx + getWidth();
+ double bottomBorder = by + getHeight();
+
+ Line2D line = new Line2D.Double();
+ Graphics2D g2 = aPaintContext.getGraphics();
+
+ g2.setStroke(new BasicStroke(0));
+ g2.setPaint(getPaint());
+
+ // draw vertical lines
+ for (double x = bx; x < rightBorder; x += 5) {
+ line.setLine(x, by, x, bottomBorder);
+ g2.draw(line);
+ }
+
+ for (double y = by; y < bottomBorder; y += 5) {
+ line.setLine(bx, y, rightBorder, y);
+ g2.draw(line);
+ }
+ }
+ };
+ n.setBounds(0, 0, 100, 80);
+ n.setPaint(Color.black);
+ getCanvas().getLayer().addChild(n);
+ }
+
+ public static void main(String[] args) {
+ new NodeExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java
index d22df55..01ade04 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java
@@ -17,58 +17,58 @@
* @author Jesse Grosjean
*/
public class NodeLinkExample extends PFrame {
-
- PNode node1;
- PNode node2;
- PPath link;
-
- public NodeLinkExample() {
- this(null);
- }
-
- public NodeLinkExample(PCanvas aCanvas) {
- super("NodeLinkExample", false, aCanvas);
- }
- public void initialize() {
- PCanvas canvas = getCanvas();
-
- canvas.removeInputEventListener(canvas.getPanEventHandler());
- canvas.addInputEventListener(new PDragEventHandler());
-
- PNode layer = canvas.getLayer();
-
- node1 = PPath.createEllipse(0, 0, 100, 100);
- node2 = PPath.createEllipse(0, 0, 100, 100);
- link = PPath.createLine(50, 50, 50, 50);
- link.setPickable(false);
- layer.addChild(node1);
- layer.addChild(node2);
- layer.addChild(link);
-
- node2.translate(200, 200);
-
- node1.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- updateLink();
- }
- });
-
- node2.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- updateLink();
- }
- });
- }
+ PNode node1;
+ PNode node2;
+ PPath link;
- public void updateLink() {
- Point2D p1 = node1.getFullBoundsReference().getCenter2D();
- Point2D p2 = node2.getFullBoundsReference().getCenter2D();
- Line2D line = new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY());
- link.setPathTo(line);
- }
-
- public static void main(String[] args) {
- new NodeLinkExample();
- }
+ public NodeLinkExample() {
+ this(null);
+ }
+
+ public NodeLinkExample(PCanvas aCanvas) {
+ super("NodeLinkExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PCanvas canvas = getCanvas();
+
+ canvas.removeInputEventListener(canvas.getPanEventHandler());
+ canvas.addInputEventListener(new PDragEventHandler());
+
+ PNode layer = canvas.getLayer();
+
+ node1 = PPath.createEllipse(0, 0, 100, 100);
+ node2 = PPath.createEllipse(0, 0, 100, 100);
+ link = PPath.createLine(50, 50, 50, 50);
+ link.setPickable(false);
+ layer.addChild(node1);
+ layer.addChild(node2);
+ layer.addChild(link);
+
+ node2.translate(200, 200);
+
+ node1.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent arg0) {
+ updateLink();
+ }
+ });
+
+ node2.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent arg0) {
+ updateLink();
+ }
+ });
+ }
+
+ public void updateLink() {
+ Point2D p1 = node1.getFullBoundsReference().getCenter2D();
+ Point2D p2 = node2.getFullBoundsReference().getCenter2D();
+ Line2D line = new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY());
+ link.setPathTo(line);
+ }
+
+ public static void main(String[] args) {
+ new NodeLinkExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
index 8dd7ba7..c2ff662 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
@@ -17,32 +17,32 @@
public class PSwingExample extends PFrame {
public PSwingExample() {
- this( new PSwingCanvas() );
+ this(new PSwingCanvas());
}
- public PSwingExample( PCanvas aCanvas ) {
- super( "PSwingExample", false, aCanvas );
+ public PSwingExample(PCanvas aCanvas) {
+ super("PSwingExample", false, aCanvas);
}
public void initialize() {
- PSwingCanvas pswingCanvas = (PSwingCanvas)getCanvas();
+ PSwingCanvas pswingCanvas = (PSwingCanvas) getCanvas();
PLayer l = pswingCanvas.getLayer();
- JSlider js = new JSlider( 0, 100 );
- js.addChangeListener( new ChangeListener() {
- public void stateChanged( ChangeEvent e ) {
- System.out.println( "e = " + e );
+ JSlider js = new JSlider(0, 100);
+ js.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ System.out.println("e = " + e);
}
- } );
- js.setBorder( BorderFactory.createTitledBorder( "Test JSlider" ) );
- PSwing pSwing = new PSwing( js );
- pSwing.translate( 100, 100 );
- l.addChild( pSwing );
+ });
+ js.setBorder(BorderFactory.createTitledBorder("Test JSlider"));
+ PSwing pSwing = new PSwing(js);
+ pSwing.translate(100, 100);
+ l.addChild(pSwing);
- pswingCanvas.setPanEventHandler( null );
+ pswingCanvas.setPanEventHandler(null);
}
- public static void main( String[] args ) {
+ public static void main(String[] args) {
new PSwingExample();
}
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
index 24a738f..8476663 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
@@ -13,61 +13,59 @@
import edu.umd.cs.piccolox.PFrame;
/**
- * Click on a node and the camera will pan the minimum distance to bring that node fully into
- * the cameras view.
+ * Click on a node and the camera will pan the minimum distance to bring that
+ * node fully into the cameras view.
*/
public class PanToExample extends PFrame {
- public PanToExample() {
- this(null);
- }
-
- public PanToExample(PCanvas aCanvas) {
- super("PanToExample", false, aCanvas);
- }
-
- public void initialize() {
-
- PPath eacha = PPath.createRectangle(50, 50, 300, 300);
- eacha.setPaint(Color.red);
- getCanvas().getLayer().addChild(eacha);
-
- eacha = PPath.createRectangle(-50, -50, 100, 100);
- eacha.setPaint(Color.green);
- getCanvas().getLayer().addChild(eacha);
+ public PanToExample() {
+ this(null);
+ }
- eacha = PPath.createRectangle(350, 350, 100, 100);
- eacha.setPaint(Color.green);
- getCanvas().getLayer().addChild(eacha);
+ public PanToExample(PCanvas aCanvas) {
+ super("PanToExample", false, aCanvas);
+ }
-
- getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- if (!(event.getPickedNode() instanceof PCamera)) {
- event.setHandled(true);
- getCanvas().getCamera().animateViewToPanToBounds(event.getPickedNode().getGlobalFullBounds(), 500);
- }
- }
- });
-
- PLayer layer = getCanvas().getLayer();
-
- Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- PPath each = PPath.createRectangle(0, 0, 100, 80);
- each.scale(random.nextFloat() * 2);
- each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
- each.setPaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
- each.setStrokePaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- layer.addChild(each);
- }
-
-
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
- }
-
- public static void main(String[] args) {
- new PanToExample();
- }
+ public void initialize() {
+
+ PPath eacha = PPath.createRectangle(50, 50, 300, 300);
+ eacha.setPaint(Color.red);
+ getCanvas().getLayer().addChild(eacha);
+
+ eacha = PPath.createRectangle(-50, -50, 100, 100);
+ eacha.setPaint(Color.green);
+ getCanvas().getLayer().addChild(eacha);
+
+ eacha = PPath.createRectangle(350, 350, 100, 100);
+ eacha.setPaint(Color.green);
+ getCanvas().getLayer().addChild(eacha);
+
+ getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent event) {
+ if (!(event.getPickedNode() instanceof PCamera)) {
+ event.setHandled(true);
+ getCanvas().getCamera().animateViewToPanToBounds(event.getPickedNode().getGlobalFullBounds(), 500);
+ }
+ }
+ });
+
+ PLayer layer = getCanvas().getLayer();
+
+ Random random = new Random();
+ for (int i = 0; i < 1000; i++) {
+ PPath each = PPath.createRectangle(0, 0, 100, 80);
+ each.scale(random.nextFloat() * 2);
+ each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
+ each.setPaint(new Color(random.nextFloat(), random.nextFloat(), random.nextFloat()));
+ each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
+ each.setStrokePaint(new Color(random.nextFloat(), random.nextFloat(), random.nextFloat()));
+ layer.addChild(each);
+ }
+
+ getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new PanToExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
index 14e5b95..1fc34a5 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.Color;
@@ -11,44 +12,44 @@
public class PathExample extends PFrame {
- public PathExample() {
- this(null);
- }
-
- public PathExample(PCanvas aCanvas) {
- super("PathExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath n1 = PPath.createRectangle(0, 0, 100, 80);
- PPath n2 = PPath.createEllipse(100, 100, 200, 34);
- PPath n3 = new PPath();
- n3.moveTo(0, 0);
- n3.lineTo(20, 40);
- n3.lineTo(10, 200);
- n3.lineTo(155.444f, 33.232f);
- n3.closePath();
- n3.setPaint(Color.yellow);
-
- n1.setStroke(new BasicStroke(5));
- n1.setStrokePaint(Color.red);
- n2.setStroke(new PFixedWidthStroke());
- n3.setStroke(new PFixedWidthStroke());
-// n3.setStroke(null);
-
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
- getCanvas().getLayer().addChild(n3);
-
- // create a set of bounds handles for reshaping n3, and make them
- // sticky relative to the getCanvas().getCamera().
- new PStickyHandleManager(getCanvas().getCamera(), n3);
-
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
+ public PathExample() {
+ this(null);
+ }
- public static void main(String[] args) {
- new PathExample();
- }
+ public PathExample(PCanvas aCanvas) {
+ super("PathExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PPath n1 = PPath.createRectangle(0, 0, 100, 80);
+ PPath n2 = PPath.createEllipse(100, 100, 200, 34);
+ PPath n3 = new PPath();
+ n3.moveTo(0, 0);
+ n3.lineTo(20, 40);
+ n3.lineTo(10, 200);
+ n3.lineTo(155.444f, 33.232f);
+ n3.closePath();
+ n3.setPaint(Color.yellow);
+
+ n1.setStroke(new BasicStroke(5));
+ n1.setStrokePaint(Color.red);
+ n2.setStroke(new PFixedWidthStroke());
+ n3.setStroke(new PFixedWidthStroke());
+ // n3.setStroke(null);
+
+ getCanvas().getLayer().addChild(n1);
+ getCanvas().getLayer().addChild(n2);
+ getCanvas().getLayer().addChild(n3);
+
+ // create a set of bounds handles for reshaping n3, and make them
+ // sticky relative to the getCanvas().getCamera().
+ new PStickyHandleManager(getCanvas().getCamera(), n3);
+
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(new PDragEventHandler());
+ }
+
+ public static void main(String[] args) {
+ new PathExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
index 94d698a..8798ca7 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCanvas;
@@ -8,33 +9,33 @@
public class PositionExample extends PFrame {
- public PositionExample() {
- this(null);
- }
-
- public PositionExample(PCanvas aCanvas) {
- super("PositionExample", false, aCanvas);
- }
-
- public void initialize() {
- PNode n1 = PPath.createRectangle(0, 0, 100, 80);
- PNode n2 = PPath.createRectangle(0, 0, 100, 80);
-
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
-
- n2.scale(2.0);
- n2.rotate(Math.toRadians(90));
- //n2.setScale(2.0);
- //n2.setScale(1.0);
- n2.scale(0.5);
- n2.setPaint(Color.red);
-
- n1.offset(100, 0);
- n2.offset(100, 0);
- }
+ public PositionExample() {
+ this(null);
+ }
- public static void main(String[] args) {
- new PositionExample();
- }
+ public PositionExample(PCanvas aCanvas) {
+ super("PositionExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PNode n1 = PPath.createRectangle(0, 0, 100, 80);
+ PNode n2 = PPath.createRectangle(0, 0, 100, 80);
+
+ getCanvas().getLayer().addChild(n1);
+ getCanvas().getLayer().addChild(n2);
+
+ n2.scale(2.0);
+ n2.rotate(Math.toRadians(90));
+ // n2.setScale(2.0);
+ // n2.setScale(1.0);
+ n2.scale(0.5);
+ n2.setPaint(Color.red);
+
+ n1.offset(100, 0);
+ n2.offset(100, 0);
+ }
+
+ public static void main(String[] args) {
+ new PositionExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
index 9f6dfdc..47c3f60 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
@@ -15,42 +15,43 @@
*/
public class PositionPathActivityExample extends PFrame {
- public PositionPathActivityExample() {
- super();
- }
+ public PositionPathActivityExample() {
+ super();
+ }
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
- final PNode animatedNode = PPath.createRectangle(0, 0, 100, 80);
- layer.addChild(animatedNode);
-
- // create animation path
- GeneralPath path = new GeneralPath();
- path.moveTo(0, 0);
- path.lineTo(300, 300);
- path.lineTo(300, 0);
- path.append(new Arc2D.Float(0, 0, 300, 300, 90, -90, Arc2D.OPEN), true);
- path.closePath();
+ public void initialize() {
+ PLayer layer = getCanvas().getLayer();
+ final PNode animatedNode = PPath.createRectangle(0, 0, 100, 80);
+ layer.addChild(animatedNode);
- // create node to display animation path
- PPath ppath = new PPath(path);
- layer.addChild(ppath);
+ // create animation path
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+ path.lineTo(300, 300);
+ path.lineTo(300, 0);
+ path.append(new Arc2D.Float(0, 0, 300, 300, 90, -90, Arc2D.OPEN), true);
+ path.closePath();
- // create activity to run animation.
- PPositionPathActivity positionPathActivity = new PPositionPathActivity(5000, 0, new PPositionPathActivity.Target() {
- public void setPosition(double x, double y) {
- animatedNode.setOffset(x, y);
- }
- });
-// positionPathActivity.setSlowInSlowOut(false);
- positionPathActivity.setPositions(path);
- positionPathActivity.setLoopCount(Integer.MAX_VALUE);
-
- // add the activity.
- animatedNode.addActivity(positionPathActivity);
- }
+ // create node to display animation path
+ PPath ppath = new PPath(path);
+ layer.addChild(ppath);
- public static void main(String[] args) {
- new PositionPathActivityExample();
- }
+ // create activity to run animation.
+ PPositionPathActivity positionPathActivity = new PPositionPathActivity(5000, 0,
+ new PPositionPathActivity.Target() {
+ public void setPosition(double x, double y) {
+ animatedNode.setOffset(x, y);
+ }
+ });
+ // positionPathActivity.setSlowInSlowOut(false);
+ positionPathActivity.setPositions(path);
+ positionPathActivity.setLoopCount(Integer.MAX_VALUE);
+
+ // add the activity.
+ animatedNode.addActivity(positionPathActivity);
+ }
+
+ public static void main(String[] args) {
+ new PositionPathActivityExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
index 1b1fee4..fefa3b7 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
@@ -20,63 +20,70 @@
*/
public class PulseExample extends PFrame {
- public PulseExample() {
- this(null);
- }
+ public PulseExample() {
+ this(null);
+ }
- public PulseExample(PCanvas aCanvas) {
- super("PulseExample", false, aCanvas);
- }
+ public PulseExample(PCanvas aCanvas) {
+ super("PulseExample", false, aCanvas);
+ }
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PLayer layer = getCanvas().getLayer();
- PActivityScheduler scheduler = root.getActivityScheduler();
-
- final PNode singlePulse = PPath.createRectangle(0, 0, 100, 80);
- final PPath repeatePulse = PPath.createRectangle(100, 80, 100, 80);
- final PNode repeateReversePulse = PPath.createRectangle(200, 160, 100, 80);
+ public void initialize() {
+ PRoot root = getCanvas().getRoot();
+ PLayer layer = getCanvas().getLayer();
+ PActivityScheduler scheduler = root.getActivityScheduler();
- layer.addChild(singlePulse);
- layer.addChild(repeatePulse);
- layer.addChild(repeateReversePulse);
-
- // animate from source to destination color in one second,
- PColorActivity singlePulseActivity = new PColorActivity(1000, 0, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) singlePulse.getPaint();
- }
- public void setColor(Color color) {
- singlePulse.setPaint(color);
- }
- }, Color.ORANGE);
+ final PNode singlePulse = PPath.createRectangle(0, 0, 100, 80);
+ final PPath repeatePulse = PPath.createRectangle(100, 80, 100, 80);
+ final PNode repeateReversePulse = PPath.createRectangle(200, 160, 100, 80);
- // animate from source to destination color in one second, loop 5 times
- PColorActivity repeatPulseActivity = new PColorActivity(1000, 0, 5, PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) repeatePulse.getPaint();
- }
- public void setColor(Color color) {
- repeatePulse.setPaint(color);
- }
- }, Color.BLUE);
+ layer.addChild(singlePulse);
+ layer.addChild(repeatePulse);
+ layer.addChild(repeateReversePulse);
- // animate from source to destination to source color in one second, loop 10 times
- PColorActivity repeatReversePulseActivity = new PColorActivity(500, 0, 10, PInterpolatingActivity.SOURCE_TO_DESTINATION_TO_SOURCE, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) repeateReversePulse.getPaint();
- }
- public void setColor(Color color) {
- repeateReversePulse.setPaint(color);
- }
- }, Color.GREEN);
+ // animate from source to destination color in one second,
+ PColorActivity singlePulseActivity = new PColorActivity(1000, 0, 1,
+ PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
+ public Color getColor() {
+ return (Color) singlePulse.getPaint();
+ }
- scheduler.addActivity(singlePulseActivity);
- scheduler.addActivity(repeatPulseActivity);
- scheduler.addActivity(repeatReversePulseActivity);
- }
+ public void setColor(Color color) {
+ singlePulse.setPaint(color);
+ }
+ }, Color.ORANGE);
- public static void main(String[] args) {
- new PulseExample();
- }
+ // animate from source to destination color in one second, loop 5 times
+ PColorActivity repeatPulseActivity = new PColorActivity(1000, 0, 5,
+ PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
+ public Color getColor() {
+ return (Color) repeatePulse.getPaint();
+ }
+
+ public void setColor(Color color) {
+ repeatePulse.setPaint(color);
+ }
+ }, Color.BLUE);
+
+ // animate from source to destination to source color in one second,
+ // loop 10 times
+ PColorActivity repeatReversePulseActivity = new PColorActivity(500, 0, 10,
+ PInterpolatingActivity.SOURCE_TO_DESTINATION_TO_SOURCE, new PColorActivity.Target() {
+ public Color getColor() {
+ return (Color) repeateReversePulse.getPaint();
+ }
+
+ public void setColor(Color color) {
+ repeateReversePulse.setPaint(color);
+ }
+ }, Color.GREEN);
+
+ scheduler.addActivity(singlePulseActivity);
+ scheduler.addActivity(repeatPulseActivity);
+ scheduler.addActivity(repeatReversePulseActivity);
+ }
+
+ public static void main(String[] args) {
+ new PulseExample();
+ }
}
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 1d3a0a5..ed4c652 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
@@ -25,199 +25,199 @@
import edu.umd.cs.piccolox.swing.PViewport;
/**
- * This creates a simple scene and allows switching between
- * traditional scrolling where the scrollbars control the view
- * and alternate scrolling where the scrollbars control the
- * document. In laymans terms - in traditional window scrolling the stuff
- * in the window moves in the opposite direction of the scroll bars and in
- * document scrolling the stuff moves in the same direction as the scrollbars.
- *
- * Toggle buttons are provided to toggle between these two types
- * of scrolling.
- *
+ * This creates a simple scene and allows switching between traditional
+ * scrolling where the scrollbars control the view and alternate scrolling where
+ * the scrollbars control the document. In laymans terms - in traditional window
+ * scrolling the stuff in the window moves in the opposite direction of the
+ * scroll bars and in document scrolling the stuff moves in the same direction
+ * as the scrollbars.
+ *
+ * Toggle buttons are provided to toggle between these two types of scrolling.
+ *
* @author Lance Good
* @author Ben Bederson
*/
public class ScrollingExample extends PFrame {
- public ScrollingExample() {
- this(null);
- }
+ public ScrollingExample() {
+ this(null);
+ }
- public ScrollingExample(PCanvas aCanvas) {
- super("ScrollingExample", false, aCanvas);
- }
+ public ScrollingExample(PCanvas aCanvas) {
+ super("ScrollingExample", false, aCanvas);
+ }
- public void initialize() {
- final PCanvas canvas = getCanvas();
+ public void initialize() {
+ final PCanvas canvas = getCanvas();
- final PScrollPane scrollPane = new PScrollPane(canvas);
- getContentPane().add(scrollPane);
-
- final PViewport viewport = (PViewport) scrollPane.getViewport();
- final PScrollDirector windowSD = viewport.getScrollDirector();
- final PScrollDirector documentSD = new DocumentScrollDirector();
+ final PScrollPane scrollPane = new PScrollPane(canvas);
+ getContentPane().add(scrollPane);
- // 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) {
- 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) {
- PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- }
- }
-
- // Now, create the toolbar
- JToolBar toolBar = new JToolBar();
- JToggleButton window = new JToggleButton("Window Scrolling");
- JToggleButton document = new JToggleButton("Document Scrolling");
- ButtonGroup bg = new ButtonGroup();
- bg.add(window);
- bg.add(document);
- toolBar.add(window);
- toolBar.add(document);
- toolBar.setFloatable(false);
- window.setSelected(true);
- window.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- viewport.setScrollDirector(windowSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- }
- });
- document.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- viewport.setScrollDirector(documentSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- }
- });
- getContentPane().add(toolBar, BorderLayout.NORTH);
-
- getContentPane().validate();
- }
+ final PViewport viewport = (PViewport) scrollPane.getViewport();
+ final PScrollDirector windowSD = viewport.getScrollDirector();
+ final PScrollDirector documentSD = new DocumentScrollDirector();
- /**
- * A modified scroll director that performs document based scroling
- * rather than window based scrolling (ie. the scrollbars act in
- * the inverse direction as normal)
- */
- public class DocumentScrollDirector extends PDefaultScrollDirector {
+ // 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) {
+ 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) {
+ PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+ }
+ }
- /**
- * Get the View position given the specified camera bounds - modified
- * such that:
- *
- * 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 subtract that value from total document width so
- * that the position is inverted
- *
- * @param viewBounds The bounds for which the view position will be computed
- * @return The view position
- */
- public Point getViewPosition(Rectangle2D viewBounds) {
- Point pos = new Point();
- if (camera != null) {
- // First we compute the union of all the layers
- PBounds layerBounds = new PBounds();
- java.util.List layers = camera.getLayersReference();
- for (Iterator i = layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
+ // Now, create the toolbar
+ JToolBar toolBar = new JToolBar();
+ JToggleButton window = new JToggleButton("Window Scrolling");
+ JToggleButton document = new JToggleButton("Document Scrolling");
+ ButtonGroup bg = new ButtonGroup();
+ bg.add(window);
+ bg.add(document);
+ toolBar.add(window);
+ toolBar.add(document);
+ toolBar.setFloatable(false);
+ window.setSelected(true);
+ window.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ viewport.setScrollDirector(windowSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ }
+ });
+ document.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ viewport.setScrollDirector(documentSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ }
+ });
+ getContentPane().add(toolBar, BorderLayout.NORTH);
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
+ getContentPane().validate();
+ }
- // 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));
- }
+ /**
+ * A modified scroll director that performs document based scroling rather
+ * than window based scrolling (ie. the scrollbars act in the inverse
+ * direction as normal)
+ */
+ public class DocumentScrollDirector extends PDefaultScrollDirector {
- return pos;
+ /**
+ * Get the View position given the specified camera bounds - modified
+ * such that:
+ *
+ * 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 subtract that value from total
+ * document width so that the position is inverted
+ *
+ * @param viewBounds The bounds for which the view position will be
+ * computed
+ * @return The view position
+ */
+ public Point getViewPosition(Rectangle2D viewBounds) {
+ Point pos = new Point();
+ if (camera != null) {
+ // First we compute the union of all the layers
+ PBounds layerBounds = new PBounds();
+ java.util.List layers = camera.getLayersReference();
+ for (Iterator i = layers.iterator(); i.hasNext();) {
+ 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);
- /**
- * We do the same thing we did in getViewPosition above to flip the
- * document-window position relationship
- *
- * @param x The new x position
- * @param y The new y position
- */
- public void setViewPosition(double x, 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;
+ // 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));
+ }
- // Get the union of all the layers' bounds
- PBounds layerBounds = new PBounds();
- java.util.List layers = camera.getLayersReference();
- for (Iterator i = layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
+ return pos;
- PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds,layerBounds);
+ }
- // Union the camera view bounds
- PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
+ /**
+ * We do the same thing we did in getViewPosition above to flip the
+ * document-window position relationship
+ *
+ * @param x The new x position
+ * @param y The new y position
+ */
+ public void setViewPosition(double x, 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;
- // 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
- Point2D newPoint =
- new Point2D.Double(
- layerBounds.getX() + layerBounds.getWidth() - (x + viewBounds.getWidth()),
- layerBounds.getY() + layerBounds.getHeight() - (y + viewBounds.getHeight()));
+ // Get the union of all the layers' bounds
+ PBounds layerBounds = new PBounds();
+ java.util.List layers = camera.getLayersReference();
+ for (Iterator i = layers.iterator(); i.hasNext();) {
+ PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
+ }
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
+ PAffineTransform at = camera.getViewTransform();
+ at.transform(layerBounds, layerBounds);
- // Compute the new matrix values to put the camera at the
- // correct location
- double newX = - (at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- double newY = - (at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
+ // Union the camera view bounds
+ PBounds viewBounds = camera.getBoundsReference();
+ layerBounds.add(viewBounds);
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
+ // 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
+ Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
+ - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
+ - (y + viewBounds.getHeight()));
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
- }
- }
- }
-
- public static void main(String[] args) {
- new ScrollingExample();
- }
+ // 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
+ double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
+ 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;
+ }
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ new ScrollingExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
index 5e120eb..4a4c334 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
@@ -11,48 +11,47 @@
import edu.umd.cs.piccolox.event.PSelectionEventHandler;
/**
- * This example shows how the selection event handler works.
- * It creates a bunch of objects that can be selected.
+ * This example shows how the selection event handler works. It creates a bunch
+ * of objects that can be selected.
*/
public class SelectionExample extends PFrame {
-
- public SelectionExample() {
- this(null);
- }
- public SelectionExample(PCanvas aCanvas) {
- super("SelectionExample", false, aCanvas);
- }
-
- public void initialize() {
- for (int i=0; i<5; i++) {
- for (int j=0; j<5; j++) {
- PNode rect = PPath.createRectangle(i*60, j*60, 50, 50);
- rect.setPaint(Color.blue);
- getCanvas().getLayer().addChild(rect);
- }
- }
-
- // Turn off default navigation event handlers
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
-
- // Create a selection event handler
- PSelectionEventHandler selectionEventHandler = new PSelectionEventHandler(getCanvas().getLayer(), getCanvas().getLayer());
- getCanvas().addInputEventListener(selectionEventHandler);
- getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(selectionEventHandler);
-
- PNotificationCenter.defaultCenter().addListener(this,
- "selectionChanged",
- PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION,
- selectionEventHandler);
- }
+ public SelectionExample() {
+ this(null);
+ }
- public void selectionChanged(PNotification notfication) {
- System.out.println("selection changed");
- }
+ public SelectionExample(PCanvas aCanvas) {
+ super("SelectionExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new SelectionExample();
- }
+ public void initialize() {
+ for (int i = 0; i < 5; i++) {
+ for (int j = 0; j < 5; j++) {
+ PNode rect = PPath.createRectangle(i * 60, j * 60, 50, 50);
+ rect.setPaint(Color.blue);
+ getCanvas().getLayer().addChild(rect);
+ }
+ }
+
+ // Turn off default navigation event handlers
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
+
+ // Create a selection event handler
+ PSelectionEventHandler selectionEventHandler = new PSelectionEventHandler(getCanvas().getLayer(), getCanvas()
+ .getLayer());
+ getCanvas().addInputEventListener(selectionEventHandler);
+ getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(selectionEventHandler);
+
+ PNotificationCenter.defaultCenter().addListener(this, "selectionChanged",
+ PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, selectionEventHandler);
+ }
+
+ public void selectionChanged(PNotification notfication) {
+ System.out.println("selection changed");
+ }
+
+ public static void main(String[] args) {
+ new SelectionExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
index fbfa5ed..b72bda8 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
@@ -10,10 +10,9 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-
/**
* Tests a set of Sliders and Checkboxes in panels.
- *
+ *
* @author Martin Clifford
*/
public class SliderExample extends JFrame {
@@ -24,112 +23,112 @@
public SliderExample() {
// Create main panel
- JPanel mainPanel = new JPanel( false );
+ JPanel mainPanel = new JPanel(false);
// Create a tabbed pane
tabbedPane = new JTabbedPane();
- tabbedPane.setPreferredSize( new Dimension( 700, 700 ) );
+ tabbedPane.setPreferredSize(new Dimension(700, 700));
// Add tabbed pane to main panel
- mainPanel.add( tabbedPane );
+ mainPanel.add(tabbedPane);
// Set the frame contents
- getContentPane().add( mainPanel );
+ getContentPane().add(mainPanel);
// Create a canvas
canvas = new PSwingCanvas();
- canvas.setPreferredSize( new Dimension( 700, 700 ) );
+ canvas.setPreferredSize(new Dimension(700, 700));
// Create a scroll pane for the canvas
- scrollPane = new PScrollPane( canvas );
+ scrollPane = new PScrollPane(canvas);
// Create a new tab for the tabbed pane
- tabbedPane.add( "Tab 1", scrollPane );
+ tabbedPane.add("Tab 1", scrollPane);
// Create the contents for "Tab 1"
- JPanel tabPanel = new JPanel( false );
- tabPanel.setLayout( null );
- tabPanel.setPreferredSize( new Dimension( 700, 700 ) );
+ JPanel tabPanel = new JPanel(false);
+ tabPanel.setLayout(null);
+ tabPanel.setPreferredSize(new Dimension(700, 700));
// Populate the tab panel with four instances of nested panel.
JPanel panel;
panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 0, 0 );
- tabPanel.add( panel );
+ panel.setSize(new Dimension(250, 250));
+ panel.setLocation(0, 0);
+ tabPanel.add(panel);
panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 0, 350 );
- tabPanel.add( panel );
+ panel.setSize(new Dimension(250, 250));
+ panel.setLocation(0, 350);
+ tabPanel.add(panel);
panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 350, 0 );
- tabPanel.add( panel );
+ panel.setSize(new Dimension(250, 250));
+ panel.setLocation(350, 0);
+ tabPanel.add(panel);
panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 350, 350 );
- tabPanel.add( panel );
+ panel.setSize(new Dimension(250, 250));
+ panel.setLocation(350, 350);
+ tabPanel.add(panel);
// Add the default zoom button
- JButton buttonPreset = new JButton( "Zoom = 100%" );
- buttonPreset.addActionListener( new ActionListener() {
- public void actionPerformed( ActionEvent e ) {
- canvas.getCamera().setViewScale( 1.0 );
- canvas.getCamera().setViewOffset( 0, 0 );
+ JButton buttonPreset = new JButton("Zoom = 100%");
+ buttonPreset.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ canvas.getCamera().setViewScale(1.0);
+ canvas.getCamera().setViewOffset(0, 0);
}
- } );
- buttonPreset.setSize( new Dimension( 120, 25 ) );
- buttonPreset.setLocation( 240, 285 );
- tabPanel.add( buttonPreset );
+ });
+ buttonPreset.setSize(new Dimension(120, 25));
+ buttonPreset.setLocation(240, 285);
+ tabPanel.add(buttonPreset);
// Create a pswing object for the tab panel
- swing = new PSwing( tabPanel );
- swing.translate( 0, 0 );
+ swing = new PSwing(tabPanel);
+ swing.translate(0, 0);
// Add the pswing object to the canvas
- canvas.getLayer().addChild( swing );
+ canvas.getLayer().addChild(swing);
// Turn off default pan event handling
- canvas.setPanEventHandler( null );
+ canvas.setPanEventHandler(null);
// Set up basic frame
- setDefaultCloseOperation( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
- setTitle( "Slider Example" );
- setResizable( true );
- setBackground( null );
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Slider Example");
+ setResizable(true);
+ setBackground(null);
pack();
- setVisible( true );
+ setVisible(true);
}
private JPanel createNestedPanel() {
// A panel MUST be created with double buffering off
JPanel panel;
JLabel label;
- panel = new JPanel( false );
- panel.setLayout( new BorderLayout() );
- label = new JLabel( "A Panel within a panel" );
- label.setHorizontalAlignment( SwingConstants.CENTER );
- label.setForeground( Color.white );
- JLabel label2 = new JLabel( "A Panel within a panel" );
- label2.setHorizontalAlignment( SwingConstants.CENTER );
+ panel = new JPanel(false);
+ panel.setLayout(new BorderLayout());
+ label = new JLabel("A Panel within a panel");
+ label.setHorizontalAlignment(SwingConstants.CENTER);
+ label.setForeground(Color.white);
+ JLabel label2 = new JLabel("A Panel within a panel");
+ label2.setHorizontalAlignment(SwingConstants.CENTER);
JSlider slider = new JSlider();
- JCheckBox cbox1 = new JCheckBox( "Checkbox 1" );
- JCheckBox cbox2 = new JCheckBox( "Checkbox 2" );
- JPanel panel3 = new JPanel( false );
- panel3.setLayout( new BoxLayout( panel3, BoxLayout.PAGE_AXIS ) );
- panel3.setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
- panel3.add( label2 );
- panel3.add( slider );
- panel3.add( cbox1 );
- panel3.add( cbox2 );
- JPanel panel2 = new JPanel( false );
- panel2.setBackground( Color.blue );
- panel.setBorder( new EmptyBorder( 1, 1, 1, 1 ) );
- panel2.add( label );
- panel2.add( panel3 );
- panel.setBackground( Color.red );
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setBorder( new EmptyBorder( 5, 5, 5, 5 ) );
- panel.add( panel2, "Center" );
+ JCheckBox cbox1 = new JCheckBox("Checkbox 1");
+ JCheckBox cbox2 = new JCheckBox("Checkbox 2");
+ JPanel panel3 = new JPanel(false);
+ panel3.setLayout(new BoxLayout(panel3, BoxLayout.PAGE_AXIS));
+ panel3.setBorder(new EmptyBorder(3, 3, 3, 3));
+ panel3.add(label2);
+ panel3.add(slider);
+ panel3.add(cbox1);
+ panel3.add(cbox2);
+ JPanel panel2 = new JPanel(false);
+ panel2.setBackground(Color.blue);
+ panel.setBorder(new EmptyBorder(1, 1, 1, 1));
+ panel2.add(label);
+ panel2.add(panel3);
+ panel.setBackground(Color.red);
+ panel.setSize(new Dimension(250, 250));
+ panel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ panel.add(panel2, "Center");
panel.revalidate();
return panel;
}
- public static void main( String[] args ) {
- SwingUtilities.invokeLater( new Runnable() {
+ public static void main(String[] args) {
+ SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SliderExample();
}
- } );
+ });
}
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
index bfc8b77..ff2691d 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
@@ -1,5 +1,5 @@
-
package edu.umd.cs.piccolo.examples;
+
import java.awt.BasicStroke;
import java.awt.event.InputEvent;
import java.awt.geom.Point2D;
@@ -14,62 +14,61 @@
import edu.umd.cs.piccolox.PFrame;
public class SquiggleExample extends PFrame {
-
- private PLayer layer;
- public SquiggleExample() {
- this(null);
- }
+ private PLayer layer;
- public SquiggleExample(PCanvas aCanvas) {
- super("SquiggleExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
- PBasicInputEventHandler squiggleEventHandler = createSquiggleEventHandler();
- squiggleEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(squiggleEventHandler);
- layer = getCanvas().getLayer();
- }
+ public SquiggleExample() {
+ this(null);
+ }
- public PBasicInputEventHandler createSquiggleEventHandler() {
- return new PDragSequenceEventHandler() {
+ public SquiggleExample(PCanvas aCanvas) {
+ super("SquiggleExample", false, aCanvas);
+ }
- protected PPath squiggle;
-
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
-
- Point2D p = e.getPosition();
+ public void initialize() {
+ super.initialize();
+ PBasicInputEventHandler squiggleEventHandler = createSquiggleEventHandler();
+ squiggleEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(squiggleEventHandler);
+ layer = getCanvas().getLayer();
+ }
- squiggle = new PPath();
- squiggle.moveTo((float)p.getX(), (float)p.getY());
- squiggle.setStroke(new BasicStroke((float)(1/ e.getCamera().getViewScale())));
- layer.addChild(squiggle);
- }
-
- public void drag(PInputEvent e) {
- super.drag(e);
- updateSquiggle(e);
- }
-
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(PInputEvent aEvent) {
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float)p.getX(), (float)p.getY());
- }
- };
- }
-
- public static void main(String[] args) {
- new SquiggleExample();
- }
+ public PBasicInputEventHandler createSquiggleEventHandler() {
+ return new PDragSequenceEventHandler() {
+
+ protected PPath squiggle;
+
+ public void startDrag(PInputEvent e) {
+ super.startDrag(e);
+
+ Point2D p = e.getPosition();
+
+ squiggle = new PPath();
+ squiggle.moveTo((float) p.getX(), (float) p.getY());
+ squiggle.setStroke(new BasicStroke((float) (1 / e.getCamera().getViewScale())));
+ layer.addChild(squiggle);
+ }
+
+ public void drag(PInputEvent e) {
+ super.drag(e);
+ updateSquiggle(e);
+ }
+
+ public void endDrag(PInputEvent e) {
+ super.endDrag(e);
+ updateSquiggle(e);
+ squiggle = null;
+ }
+
+ public void updateSquiggle(PInputEvent aEvent) {
+ Point2D p = aEvent.getPosition();
+ squiggle.lineTo((float) p.getX(), (float) p.getY());
+ }
+ };
+ }
+
+ public static void main(String[] args) {
+ new SquiggleExample();
+ }
}
-
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
index 4de65ff..1333460 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCanvas;
@@ -8,24 +9,24 @@
public class StickyExample extends PFrame {
- public StickyExample() {
- this(null);
- }
+ public StickyExample() {
+ this(null);
+ }
- public StickyExample(PCanvas aCanvas) {
- super("StickyExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath sticky = PPath.createRectangle(0, 0, 50, 50);
- sticky.setPaint(Color.YELLOW);
- sticky.setStroke(null);
- PBoundsHandle.addBoundsHandlesTo(sticky);
- getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
- getCanvas().getCamera().addChild(sticky);
- }
+ public StickyExample(PCanvas aCanvas) {
+ super("StickyExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new StickyExample();
- }
+ public void initialize() {
+ PPath sticky = PPath.createRectangle(0, 0, 50, 50);
+ sticky.setPaint(Color.YELLOW);
+ sticky.setStroke(null);
+ PBoundsHandle.addBoundsHandlesTo(sticky);
+ getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
+ getCanvas().getCamera().addChild(sticky);
+ }
+
+ public static void main(String[] args) {
+ new StickyExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
index e22e606..839132b 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
@@ -14,7 +14,7 @@
import edu.umd.cs.piccolox.util.PBoundsLocator;
/**
-* This example shows another way to create sticky handles. These handles are
+ * This example shows another way to create sticky handles. These handles are
* not added as children to the object that they manipulate. Instead they are
* added to the camera the views that objects. This means that they will not be
* affected by the cameras view transform, and so will stay the same size when
@@ -28,50 +28,50 @@
* @author jesse
*/
public class StickyHandleLayerExample extends PFrame {
-
- public StickyHandleLayerExample() {
- this(null);
- }
- public StickyHandleLayerExample(PCanvas aCanvas) {
- super("StickyHandleLayerExample", false, aCanvas);
- }
+ public StickyHandleLayerExample() {
+ this(null);
+ }
- public void initialize() {
- PCanvas c = getCanvas();
-
- PActivity updateHandles = new PActivity(-1, 0) {
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- PRoot root = getActivityScheduler().getRoot();
+ public StickyHandleLayerExample(PCanvas aCanvas) {
+ super("StickyHandleLayerExample", false, aCanvas);
+ }
- if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
- Iterator i = getCanvas().getCamera().getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (each instanceof PHandle) {
- PHandle handle = (PHandle) each;
- handle.relocateHandle();
- }
- }
- }
- }
- };
-
- PPath rect = PPath.createRectangle(0, 0, 100, 100);
- rect.setPaint(Color.RED);
- c.getLayer().addChild(rect);
+ public void initialize() {
+ PCanvas c = getCanvas();
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(rect)));
-
- c.getRoot().getActivityScheduler().addActivity(updateHandles, true);
- }
-
- public static void main(String[] args) {
- new StickyHandleLayerExample();
- }
+ PActivity updateHandles = new PActivity(-1, 0) {
+ protected void activityStep(long elapsedTime) {
+ super.activityStep(elapsedTime);
+
+ PRoot root = getActivityScheduler().getRoot();
+
+ if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
+ Iterator i = getCanvas().getCamera().getChildrenIterator();
+ while (i.hasNext()) {
+ PNode each = (PNode) i.next();
+ if (each instanceof PHandle) {
+ PHandle handle = (PHandle) each;
+ handle.relocateHandle();
+ }
+ }
+ }
+ }
+ };
+
+ PPath rect = PPath.createRectangle(0, 0, 100, 100);
+ rect.setPaint(Color.RED);
+ c.getLayer().addChild(rect);
+
+ c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(rect)));
+ c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(rect)));
+ c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(rect)));
+ c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(rect)));
+
+ c.getRoot().getActivityScheduler().addActivity(updateHandles, true);
+ }
+
+ public static void main(String[] args) {
+ new StickyHandleLayerExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
index f78c650..4208811 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
@@ -9,21 +9,21 @@
*/
public class TextExample extends PFrame {
- public TextExample() {
- this(null);
- }
+ public TextExample() {
+ this(null);
+ }
- public TextExample(PCanvas aCanvas) {
- super("TextExample", false, aCanvas);
- }
-
- public void initialize() {
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- PStyledTextEventHandler textHandler = new PStyledTextEventHandler(getCanvas());
- getCanvas().addInputEventListener(textHandler);
- }
+ public TextExample(PCanvas aCanvas) {
+ super("TextExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new TextExample();
- }
+ public void initialize() {
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ PStyledTextEventHandler textHandler = new PStyledTextEventHandler(getCanvas());
+ getCanvas().addInputEventListener(textHandler);
+ }
+
+ public static void main(String[] args) {
+ new TextExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
index fad544b..c582a3b 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
@@ -17,54 +17,53 @@
* @author jesse
*/
public class TooltipExample extends PFrame {
-
- public TooltipExample() {
- this(null);
- }
- public TooltipExample(PCanvas aCanvas) {
- super("TooltipExample", false, aCanvas);
- }
+ public TooltipExample() {
+ this(null);
+ }
- public void initialize() {
- PNode n1 = PPath.createEllipse(0, 0, 100, 100);
- PNode n2 = PPath.createRectangle(300, 200, 100, 100);
-
- n1.addAttribute("tooltip", "node 1");
- n2.addAttribute("tooltip", "node 2");
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
-
- final PCamera camera = getCanvas().getCamera();
- final PText tooltipNode = new PText();
-
- tooltipNode.setPickable(false);
- camera.addChild(tooltipNode);
-
- camera.addInputEventListener(new PBasicInputEventHandler() {
- public void mouseMoved(PInputEvent event) {
- updateToolTip(event);
- }
+ public TooltipExample(PCanvas aCanvas) {
+ super("TooltipExample", false, aCanvas);
+ }
- public void mouseDragged(PInputEvent event) {
- updateToolTip(event);
- }
+ public void initialize() {
+ PNode n1 = PPath.createEllipse(0, 0, 100, 100);
+ PNode n2 = PPath.createRectangle(300, 200, 100, 100);
- public void updateToolTip(PInputEvent event) {
- PNode n = event.getInputManager().getMouseOver().getPickedNode();
- String tooltipString = (String) n.getAttribute("tooltip");
- Point2D p = event.getCanvasPosition();
-
- event.getPath().canvasToLocal(p, camera);
-
- tooltipNode.setText(tooltipString);
- tooltipNode.setOffset(p.getX() + 8,
- p.getY() - 8);
- }
- });
- }
-
- public static void main(String[] argv) {
- new TooltipExample();
- }
+ n1.addAttribute("tooltip", "node 1");
+ n2.addAttribute("tooltip", "node 2");
+ getCanvas().getLayer().addChild(n1);
+ getCanvas().getLayer().addChild(n2);
+
+ final PCamera camera = getCanvas().getCamera();
+ final PText tooltipNode = new PText();
+
+ tooltipNode.setPickable(false);
+ camera.addChild(tooltipNode);
+
+ camera.addInputEventListener(new PBasicInputEventHandler() {
+ public void mouseMoved(PInputEvent event) {
+ updateToolTip(event);
+ }
+
+ public void mouseDragged(PInputEvent event) {
+ updateToolTip(event);
+ }
+
+ public void updateToolTip(PInputEvent event) {
+ PNode n = event.getInputManager().getMouseOver().getPickedNode();
+ String tooltipString = (String) n.getAttribute("tooltip");
+ Point2D p = event.getCanvasPosition();
+
+ event.getPath().canvasToLocal(p, camera);
+
+ tooltipNode.setText(tooltipString);
+ tooltipNode.setOffset(p.getX() + 8, p.getY() - 8);
+ }
+ });
+ }
+
+ public static void main(String[] argv) {
+ new TooltipExample();
+ }
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
index 9955356..4e816d9 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import java.awt.Color;
import edu.umd.cs.piccolo.PCamera;
@@ -12,39 +13,39 @@
public class TwoCanvasExample extends PFrame {
- public TwoCanvasExample() {
- this(null);
- }
-
- public TwoCanvasExample(PCanvas aCanvas) {
- super("TwoCanvasExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PLayer layer = getCanvas().getLayer();
-
- PNode n = PPath.createRectangle(0, 0, 100, 80);
- PNode sticky = PPath.createRectangle(0, 0, 50, 50);
- PBoundsHandle.addBoundsHandlesTo(n);
- sticky.setPaint(Color.YELLOW);
- PBoundsHandle.addBoundsHandlesTo(sticky);
-
- layer.addChild(n);
- getCanvas().getCamera().addChild(sticky);
-
- PCamera otherCamera = new PCamera();
- otherCamera.addLayer(layer);
- root.addChild(otherCamera);
-
- PCanvas other = new PCanvas();
- other.setCamera(otherCamera);
- PFrame result = new PFrame("TwoCanvasExample", false, other);
- result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- result.setLocation(500, 100);
- }
+ public TwoCanvasExample() {
+ this(null);
+ }
- public static void main(String[] args) {
- new TwoCanvasExample();
- }
+ public TwoCanvasExample(PCanvas aCanvas) {
+ super("TwoCanvasExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ PRoot root = getCanvas().getRoot();
+ PLayer layer = getCanvas().getLayer();
+
+ PNode n = PPath.createRectangle(0, 0, 100, 80);
+ PNode sticky = PPath.createRectangle(0, 0, 50, 50);
+ PBoundsHandle.addBoundsHandlesTo(n);
+ sticky.setPaint(Color.YELLOW);
+ PBoundsHandle.addBoundsHandlesTo(sticky);
+
+ layer.addChild(n);
+ getCanvas().getCamera().addChild(sticky);
+
+ PCamera otherCamera = new PCamera();
+ otherCamera.addLayer(layer);
+ root.addChild(otherCamera);
+
+ PCanvas other = new PCanvas();
+ other.setCamera(otherCamera);
+ PFrame result = new PFrame("TwoCanvasExample", false, other);
+ result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ result.setLocation(500, 100);
+ }
+
+ public static void main(String[] args) {
+ new TwoCanvasExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
index 5009e14..d6155a9 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
@@ -1,4 +1,5 @@
package edu.umd.cs.piccolo.examples;
+
import edu.umd.cs.piccolo.PCanvas;
import edu.umd.cs.piccolo.PLayer;
import edu.umd.cs.piccolo.PNode;
@@ -7,35 +8,35 @@
import edu.umd.cs.piccolox.PFrame;
/**
- * This example shows how to use setTriggerTime to synchronize the start and end of
- * two activities.
+ * This example shows how to use setTriggerTime to synchronize the start and end
+ * of two activities.
*/
public class WaitForActivitiesExample extends PFrame {
- public WaitForActivitiesExample() {
- this(null);
- }
-
- public WaitForActivitiesExample(PCanvas aCanvas) {
- super("WaitForActivitiesExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- PNode a = PPath.createRectangle(0, 0, 100, 80);
- PNode b = PPath.createRectangle(0, 0, 100, 80);
-
- layer.addChild(a);
- layer.addChild(b);
-
- PActivity a1 = a.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
- PActivity a2 = b.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
+ public WaitForActivitiesExample() {
+ this(null);
+ }
- a2.startAfter(a1);
- }
+ public WaitForActivitiesExample(PCanvas aCanvas) {
+ super("WaitForActivitiesExample", false, aCanvas);
+ }
- public static void main(String[] args) {
- new WaitForActivitiesExample();
- }
+ public void initialize() {
+ PLayer layer = getCanvas().getLayer();
+
+ PNode a = PPath.createRectangle(0, 0, 100, 80);
+ PNode b = PPath.createRectangle(0, 0, 100, 80);
+
+ layer.addChild(a);
+ layer.addChild(b);
+
+ PActivity a1 = a.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
+ PActivity a2 = b.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
+
+ a2.startAfter(a1);
+ }
+
+ public static void main(String[] args) {
+ new WaitForActivitiesExample();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java
index b2a9b40..9bdd09f 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java
@@ -12,62 +12,58 @@
/**
* @author good
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
*/
public class SWTBasicExample {
- /**
- * Constructor for SWTBasicExample.
- */
- public SWTBasicExample() {
- super();
- }
+ /**
+ * Constructor for SWTBasicExample.
+ */
+ public SWTBasicExample() {
+ super();
+ }
- public static void main(String[] args) {
- Display display = new Display ();
- Shell shell = open (display);
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
- public static Shell open(Display display) {
- final Shell shell = new Shell (display);
- shell.setLayout(new FillLayout());
- PSWTCanvas canvas = new PSWTCanvas(shell,0);
-
- PSWTPath rect = PSWTPath.createRectangle(25,25,50,50);
- rect.setPaint(Color.red);
- canvas.getLayer().addChild(rect);
-
- rect = PSWTPath.createRectangle(300,25,100,50);
- rect.setPaint(Color.blue);
- canvas.getLayer().addChild(rect);
-
- PSWTPath circle = PSWTPath.createEllipse(100,200,50,50);
- circle.setPaint(Color.green);
- canvas.getLayer().addChild(circle);
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = open(display);
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
- circle = PSWTPath.createEllipse(400,400,75,150);
- circle.setPaint(Color.yellow);
- canvas.getLayer().addChild(circle);
-
- PSWTText text = new PSWTText("Hello World");
- text.translate(350,150);
- text.setPenColor(Color.gray);
- canvas.getLayer().addChild(text);
-
- text = new PSWTText("Goodbye World");
- text.translate(50,400);
- text.setPenColor(Color.magenta);
- canvas.getLayer().addChild(text);
-
- shell.open ();
- return shell;
- }
+ public static Shell open(Display display) {
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ PSWTCanvas canvas = new PSWTCanvas(shell, 0);
+
+ PSWTPath rect = PSWTPath.createRectangle(25, 25, 50, 50);
+ rect.setPaint(Color.red);
+ canvas.getLayer().addChild(rect);
+
+ rect = PSWTPath.createRectangle(300, 25, 100, 50);
+ rect.setPaint(Color.blue);
+ canvas.getLayer().addChild(rect);
+
+ PSWTPath circle = PSWTPath.createEllipse(100, 200, 50, 50);
+ circle.setPaint(Color.green);
+ canvas.getLayer().addChild(circle);
+
+ circle = PSWTPath.createEllipse(400, 400, 75, 150);
+ circle.setPaint(Color.yellow);
+ canvas.getLayer().addChild(circle);
+
+ PSWTText text = new PSWTText("Hello World");
+ text.translate(350, 150);
+ text.setPenColor(Color.gray);
+ canvas.getLayer().addChild(text);
+
+ text = new PSWTText("Goodbye World");
+ text.translate(50, 400);
+ text.setPenColor(Color.magenta);
+ canvas.getLayer().addChild(text);
+
+ shell.open();
+ return shell;
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java
index c9839ef..99e4893 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java
@@ -29,53 +29,46 @@
* Benchmarking test suite for SWT package
*/
public class SWTBenchTest extends Canvas {
-
- // Paths
+
+ // Paths
GeneralPath testShape = new GeneralPath();
-
- // Images
- Image testImageOpaque, testImageBitmask, testImageTranslucent, testImageARGB;
-
- // Transforms
- AffineTransform transform = new AffineTransform();
+
+ // Images
+ Image testImageOpaque, testImageBitmask, testImageTranslucent, testImageARGB;
+
+ // Transforms
+ AffineTransform transform = new AffineTransform();
static final AffineTransform IDENTITY = new AffineTransform();
-
- // Geometry
- double pts[] = new double[20];
- // Colors
- static final Color colors[] = {
- Color.red, Color.green, Color.blue, Color.white, Color.yellow,
- };
+ // Geometry
+ double pts[] = new double[20];
- // Flags
+ // Colors
+ static final Color colors[] = { Color.red, Color.green, Color.blue, Color.white, Color.yellow, };
+
+ // Flags
boolean offscreen;
- boolean antialiased;
+ boolean antialiased;
- // Statistics
+ // Statistics
int results[][] = new int[NUM_CONTEXTS][NUM_TESTS];
-
- // Constants
+ // Constants
static final int CTX_NORMAL = 0;
-// static final int CTX_CLIPPED = 1;
+ // static final int CTX_CLIPPED = 1;
static final int CTX_TRANSFORMED = 1;
-// static final int CTX_BLENDED = 3;
+ // static final int CTX_BLENDED = 3;
static final int NUM_CONTEXTS = 2;
-// static String contextNames[] = {
-// "normal",
-// "clip",
-// "transform",
-// "alpha",
-// };
+ // static String contextNames[] = {
+ // "normal",
+ // "clip",
+ // "transform",
+ // "alpha",
+ // };
- static String contextNames[] = {
- "normal",
- "transform"
- };
-
+ static String contextNames[] = { "normal", "transform" };
//
// TEST METHODS
@@ -96,21 +89,8 @@
static final int DRAW_IMG5 = 12;
static final int NUM_TESTS = 13;
- static String testNames[] = {
- "line",
- "rect",
- "fill rect",
- "oval",
- "fill oval",
- "poly",
- "fill poly",
- "text",
- "image",
- "scaled image",
- "mask image",
- "alpha image",
- "argb image",
- };
+ static String testNames[] = { "line", "rect", "fill rect", "oval", "fill oval", "poly", "fill poly", "text",
+ "image", "scaled image", "mask image", "alpha image", "argb image", };
void testDrawLine(SWTGraphics2D g, Random r) {
g.drawLine(rand(r), rand(r), rand(r), rand(r));
@@ -124,7 +104,7 @@
g.fillRect(rand(r), rand(r), rand(r), rand(r));
}
- void testDrawOval(SWTGraphics2D g, Random r) {
+ void testDrawOval(SWTGraphics2D g, Random r) {
g.drawOval(rand(r), rand(r), rand(r), rand(r));
}
@@ -133,9 +113,9 @@
}
void genPoly(Random r) {
- for (int i = 0; i < pts.length/2; i++) {
- pts[2*i] = rand(r);
- pts[2*i+1] = rand(r);
+ for (int i = 0; i < pts.length / 2; i++) {
+ pts[2 * i] = rand(r);
+ pts[2 * i + 1] = rand(r);
}
}
@@ -160,7 +140,7 @@
// Scaled image
void testDrawImg2(SWTGraphics2D g, Random r) {
- Rectangle rect = testImageOpaque.getBounds();
+ Rectangle rect = testImageOpaque.getBounds();
g.drawImage(testImageOpaque, 0, 0, rect.width, rect.height, rand(r), rand(r), rand(r), rand(r));
}
@@ -180,72 +160,74 @@
}
Image loadImage(Display display, String name) {
- try {
- InputStream stream = SWTBenchTest.class.getResourceAsStream(name);
- if (stream != null) {
- ImageData imageData = new ImageData(stream);
- return new Image(display,imageData);
-// if (imageData != null) {
-// ImageData mask = imageData.getTransparencyMask();
-// return new Image(display, imageData, mask);
-// }
+ try {
+ InputStream stream = SWTBenchTest.class.getResourceAsStream(name);
+ if (stream != null) {
+ ImageData imageData = new ImageData(stream);
+ return new Image(display, imageData);
+ // if (imageData != null) {
+ // ImageData mask = imageData.getTransparencyMask();
+ // return new Image(display, imageData, mask);
+ // }
- }
- } catch (Exception e) {
- }
+ }
+ }
+ catch (Exception e) {
+ }
return null;
}
SWTBenchTest(Composite parent, int style) {
- super(parent,style);
-
- testImageOpaque = loadImage(getDisplay(),"opaque.jpg");
- testImageBitmask = loadImage(getDisplay(),"bitmask.gif");
- testImageTranslucent = loadImage(getDisplay(),"translucent.png");
- testImageARGB = new Image(getDisplay(),128, 128);
-
+ super(parent, style);
+
+ testImageOpaque = loadImage(getDisplay(), "opaque.jpg");
+ testImageBitmask = loadImage(getDisplay(), "bitmask.gif");
+ testImageTranslucent = loadImage(getDisplay(), "translucent.png");
+ testImageARGB = new Image(getDisplay(), 128, 128);
+
GC tmpGC = new GC(testImageARGB);
- tmpGC.drawImage(testImageTranslucent,0,0);
+ tmpGC.drawImage(testImageTranslucent, 0, 0);
tmpGC.dispose();
-
+
addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent pe) {
- runAll(new SWTGraphics2D(pe.gc,getDisplay()));
- }
- });
+ public void paintControl(PaintEvent pe) {
+ runAll(new SWTGraphics2D(pe.gc, getDisplay()));
+ }
+ });
}
void setupTransform(Graphics2D g, Random r) {
transform.setToIdentity();
switch (abs(r.nextInt()) % 5) {
- default:
-// case 0: // UNIFORM SCALE
- double s = r.nextDouble();
- transform.scale(5*s + 0.1, 5*s + 0.1);
- break;
-// case 1: // NON-UNIFORM SCALE
-// transform.scale(5 * r.nextDouble() + 0.1, 5 * r.nextDouble() + 0.1);
-// break;
-// case 2: // ROTATION
-// transform.rotate(r.nextDouble() * Math.PI * 2);
-// break;
-// case 3: // TRANSLATION
-// transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
-// break;
-// case 4: // TRANSLATE + ROTATE + SCALE
-// s = r.nextDouble();
-// transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
-// transform.rotate(r.nextDouble() * Math.PI * 2);
-// transform.scale(5*s + 0.1, 5*s + 0.1);
-// break;
+ default:
+ // case 0: // UNIFORM SCALE
+ double s = r.nextDouble();
+ transform.scale(5 * s + 0.1, 5 * s + 0.1);
+ break;
+ // case 1: // NON-UNIFORM SCALE
+ // transform.scale(5 * r.nextDouble() + 0.1, 5 * r.nextDouble() +
+ // 0.1);
+ // break;
+ // case 2: // ROTATION
+ // transform.rotate(r.nextDouble() * Math.PI * 2);
+ // break;
+ // case 3: // TRANSLATION
+ // transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
+ // break;
+ // case 4: // TRANSLATE + ROTATE + SCALE
+ // s = r.nextDouble();
+ // transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
+ // transform.rotate(r.nextDouble() * Math.PI * 2);
+ // transform.scale(5*s + 0.1, 5*s + 0.1);
+ // break;
}
g.setTransform(transform);
}
void setupClip(Graphics2D g, Random r) {
-// g.setClip(rand(r), rand(r), rand(r), rand(r));
+ // g.setClip(rand(r), rand(r), rand(r), rand(r));
}
void setupBlend(Graphics2D g, Random r) {
@@ -254,42 +236,68 @@
void setup(int ctx, Graphics2D g, Random r) {
switch (ctx) {
- case CTX_NORMAL:
- break;
+ case CTX_NORMAL:
+ break;
- case CTX_TRANSFORMED:
- setupTransform(g, r);
- break;
+ case CTX_TRANSFORMED:
+ setupTransform(g, r);
+ break;
-// case CTX_CLIPPED:
-// setupClip(g, r);
-// break;
-//
-// case CTX_BLENDED:
-// setupBlend(g, r);
-// break;
+ // case CTX_CLIPPED:
+ // setupClip(g, r);
+ // break;
+ //
+ // case CTX_BLENDED:
+ // setupBlend(g, r);
+ // break;
}
}
void test(int testNum, SWTGraphics2D g, Random r) {
g.setColor(colors[abs(r.nextInt()) % colors.length]);
- g.setBackground(colors[abs(r.nextInt()) % colors.length]);
+ g.setBackground(colors[abs(r.nextInt()) % colors.length]);
switch (testNum) {
- case DRAW_LINE: testDrawLine(g, r); break;
- case DRAW_RECT: testDrawRect(g, r); break;
- case FILL_RECT: testFillRect(g, r); break;
- case DRAW_OVAL: testDrawOval(g, r); break;
- case FILL_OVAL: testFillOval(g, r); break;
- case DRAW_POLY: testDrawPoly(g, r); break;
- case FILL_POLY: testFillPoly(g, r); break;
- case DRAW_TEXT: testDrawText(g, r); break;
- case DRAW_IMG1: testDrawImg1(g, r); break;
- case DRAW_IMG2: testDrawImg2(g, r); break;
- case DRAW_IMG3: testDrawImg3(g, r); break;
- case DRAW_IMG4: testDrawImg4(g, r); break;
- case DRAW_IMG5: testDrawImg5(g, r); break;
+ case DRAW_LINE:
+ testDrawLine(g, r);
+ break;
+ case DRAW_RECT:
+ testDrawRect(g, r);
+ break;
+ case FILL_RECT:
+ testFillRect(g, r);
+ break;
+ case DRAW_OVAL:
+ testDrawOval(g, r);
+ break;
+ case FILL_OVAL:
+ testFillOval(g, r);
+ break;
+ case DRAW_POLY:
+ testDrawPoly(g, r);
+ break;
+ case FILL_POLY:
+ testFillPoly(g, r);
+ break;
+ case DRAW_TEXT:
+ testDrawText(g, r);
+ break;
+ case DRAW_IMG1:
+ testDrawImg1(g, r);
+ break;
+ case DRAW_IMG2:
+ testDrawImg2(g, r);
+ break;
+ case DRAW_IMG3:
+ testDrawImg3(g, r);
+ break;
+ case DRAW_IMG4:
+ testDrawImg4(g, r);
+ break;
+ case DRAW_IMG5:
+ testDrawImg5(g, r);
+ break;
}
}
@@ -297,11 +305,12 @@
Random r1 = new Random(1);
Random r2 = new Random(1);
- System.out.println("Test: " + testNames[testNum]);
+ System.out.println("Test: " + testNames[testNum]);
long t1 = System.currentTimeMillis();
int i = 0;
while (true) {
- if (i % 10 == 0) setup(ctx, g, r1);
+ if (i % 10 == 0)
+ setup(ctx, g, r1);
test(testNum, g, r2);
i++;
long t2 = System.currentTimeMillis();
@@ -309,7 +318,7 @@
break;
}
}
- results[ctx][testNum] += i / 5;
+ results[ctx][testNum] += i / 5;
System.out.println("Shapes per second: " + (results[ctx][testNum]));
}
@@ -318,10 +327,8 @@
if (antialiased) {
System.out.println("ANTIALIASED");
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
@@ -338,8 +345,10 @@
}
String fileName = g.getClass().getName().replace('.', '_');
- if (offscreen) fileName += "-offscreen";
- if (antialiased) fileName += "-antialiased";
+ if (offscreen)
+ fileName += "-offscreen";
+ if (antialiased)
+ fileName += "-antialiased";
dumpResults(fileName + ".txt");
System.exit(0);
}
@@ -364,21 +373,22 @@
}
out.close();
results = new int[NUM_CONTEXTS][NUM_TESTS];
- } catch (IOException e) {
+ }
+ catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
- public Point computeSize(int wHint, int hHint) {
- return new Point(512,512);
- }
+ public Point computeSize(int wHint, int hHint) {
+ return new Point(512, 512);
+ }
- public Point computeSize(int wHint, int hHint, boolean changed) {
- return computeSize(wHint,hHint);
- }
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ return computeSize(wHint, hHint);
+ }
- final static int abs(int x) {
+ final static int abs(int x) {
return (x < 0 ? -x : x);
}
@@ -387,14 +397,14 @@
}
public static void main(String args[]) {
- // Create frame
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
+ // Create frame
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
- // Add bench test
- SWTBenchTest m = new SWTBenchTest(shell,SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
- m.setSize(512,512);
+ // Add bench test
+ SWTBenchTest m = new SWTBenchTest(shell, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
+ m.setSize(512, 512);
for (int i = 0; i < args.length; i++) {
if (args[i].intern() == "-offscreen")
m.offscreen = true;
@@ -406,13 +416,14 @@
}
}
- shell.pack();
- shell.open();
+ shell.pack();
+ shell.open();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
}
}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java
index ca94965..9ab0697 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java
@@ -9,39 +9,35 @@
/**
* @author good
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
*/
public class SWTHelloWorld {
- /**
- * Constructor for SWTBasicExample.
- */
- public SWTHelloWorld() {
- super();
- }
+ /**
+ * Constructor for SWTBasicExample.
+ */
+ public SWTHelloWorld() {
+ super();
+ }
- public static void main(String[] args) {
- Display display = new Display ();
- Shell shell = open (display);
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
- public static Shell open(Display display) {
- final Shell shell = new Shell (display);
- shell.setLayout(new FillLayout());
- PSWTCanvas canvas = new PSWTCanvas(shell,0);
-
- PSWTText text = new PSWTText("Hello World");
- canvas.getLayer().addChild(text);
-
- shell.open ();
- return shell;
- }
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = open(display);
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ public static Shell open(Display display) {
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ PSWTCanvas canvas = new PSWTCanvas(shell, 0);
+
+ PSWTText text = new PSWTText("Hello World");
+ canvas.getLayer().addChild(text);
+
+ shell.open();
+ return shell;
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
index a142264..671bd5c 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
@@ -10,125 +10,127 @@
import edu.umd.cs.piccolox.*;
public class InterfaceFrame extends PFrame {
-
- public void initialize() {
- // Remove the Default pan event handler and add a drag event handler
- // so that we can drag the nodes around individually.
- getCanvas().setPanEventHandler(null);
- getCanvas().addInputEventListener(new PDragEventHandler());
-
- // Add Some Default Nodes
- // Create a node.
- PNode aNode = new PNode();
+ public void initialize() {
+ // Remove the Default pan event handler and add a drag event handler
+ // so that we can drag the nodes around individually.
+ getCanvas().setPanEventHandler(null);
+ getCanvas().addInputEventListener(new PDragEventHandler());
- // A node will not be visible until its bounds and brush are set.
- aNode.setBounds(0, 0, 100, 80);
- aNode.setPaint(Color.RED);
+ // Add Some Default Nodes
- // A node needs to be a descendent of the root to be displayed.
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
-
- // A node can have child nodes added to it.
- PNode anotherNode = new PNode();
- anotherNode.setBounds(0, 0, 100, 80);
- anotherNode.setPaint(Color.YELLOW);
- aNode.addChild(anotherNode);
-
- // The base bounds of a node are easy to change. Changing the bounds
- // of a node will not affect it's children.
- aNode.setBounds(-10, -10, 200, 110);
-
- // Each node has a transform that can be used to modify the position,
- // scale or rotation of a node. Changing a node's transform, will
- // transform all of its children as well.
- aNode.translate(100, 100);
- aNode.scale(1.5f);
- aNode.rotate(45);
+ // Create a node.
+ PNode aNode = new PNode();
- // Add a couple of PPath nodes and a PText node.
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
+ // A node will not be visible until its bounds and brush are set.
+ aNode.setBounds(0, 0, 100, 80);
+ aNode.setPaint(Color.RED);
- // Here we create a PImage node that displays a thumbnail image
- // of the root node. Then we add the new PImage to the main layer.
- PImage image = new PImage(layer.toImage(300, 300, null));
- layer.addChild(image);
+ // A node needs to be a descendent of the root to be displayed.
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(aNode);
- // Create a New Node using Composition
+ // A node can have child nodes added to it.
+ PNode anotherNode = new PNode();
+ anotherNode.setBounds(0, 0, 100, 80);
+ anotherNode.setPaint(Color.YELLOW);
+ aNode.addChild(anotherNode);
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // Create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
-
- // Add the face parts.
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
-
- // Don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
-
- // Position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
-
- // Set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- b.inset(-5, -5);
- myCompositeFace.setBounds(b);
-
- // Opps its to small, so scale it up.
- myCompositeFace.scale(1.5);
-
- layer.addChild(myCompositeFace);
+ // The base bounds of a node are easy to change. Changing the bounds
+ // of a node will not affect it's children.
+ aNode.setBounds(-10, -10, 200, 110);
- // Create a New Node using Inheritance.
- ToggleShape ts = new ToggleShape();
- ts.setPaint(Color.ORANGE);
- layer.addChild(ts);
- }
-
- class ToggleShape extends PPath {
-
- private boolean fIsPressed = false;
+ // Each node has a transform that can be used to modify the position,
+ // scale or rotation of a node. Changing a node's transform, will
+ // transform all of its children as well.
+ aNode.translate(100, 100);
+ aNode.scale(1.5f);
+ aNode.rotate(45);
- public ToggleShape() {
- setPathToEllipse(0, 0, 100, 80);
-
- addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- super.mousePressed(event);
- fIsPressed = true;
- repaint();
- }
- public void mouseReleased(PInputEvent event) {
- super.mouseReleased(event);
- fIsPressed = false;
- repaint();
- }
- });
- }
-
- protected void paint(PPaintContext paintContext) {
- if (fIsPressed) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- super.paint(paintContext);
- }
- }
- }
-
- public static void main(String[] args) {
- new InterfaceFrame();
- }
+ // Add a couple of PPath nodes and a PText node.
+ layer.addChild(PPath.createEllipse(0, 0, 100, 100));
+ layer.addChild(PPath.createRectangle(0, 100, 100, 100));
+ layer.addChild(new PText("Hello World"));
+
+ // Here we create a PImage node that displays a thumbnail image
+ // of the root node. Then we add the new PImage to the main layer.
+ PImage image = new PImage(layer.toImage(300, 300, null));
+ layer.addChild(image);
+
+ // Create a New Node using Composition
+
+ PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
+
+ // Create parts for the face.
+ PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
+ eye1.setPaint(Color.YELLOW);
+ PNode eye2 = (PNode) eye1.clone();
+ PNode mouth = PPath.createRectangle(0, 0, 40, 20);
+ mouth.setPaint(Color.BLACK);
+
+ // Add the face parts.
+ myCompositeFace.addChild(eye1);
+ myCompositeFace.addChild(eye2);
+ myCompositeFace.addChild(mouth);
+
+ // Don't want anyone grabbing out our eye's.
+ myCompositeFace.setChildrenPickable(false);
+
+ // Position the face parts.
+ eye2.translate(25, 0);
+ mouth.translate(0, 30);
+
+ // Set the face bounds so that it neatly contains the face parts.
+ PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
+ b.inset(-5, -5);
+ myCompositeFace.setBounds(b);
+
+ // Opps its to small, so scale it up.
+ myCompositeFace.scale(1.5);
+
+ layer.addChild(myCompositeFace);
+
+ // Create a New Node using Inheritance.
+ ToggleShape ts = new ToggleShape();
+ ts.setPaint(Color.ORANGE);
+ layer.addChild(ts);
+ }
+
+ class ToggleShape extends PPath {
+
+ private boolean fIsPressed = false;
+
+ public ToggleShape() {
+ setPathToEllipse(0, 0, 100, 80);
+
+ addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent event) {
+ super.mousePressed(event);
+ fIsPressed = true;
+ repaint();
+ }
+
+ public void mouseReleased(PInputEvent event) {
+ super.mouseReleased(event);
+ fIsPressed = false;
+ repaint();
+ }
+ });
+ }
+
+ protected void paint(PPaintContext paintContext) {
+ if (fIsPressed) {
+ Graphics2D g2 = paintContext.getGraphics();
+ g2.setPaint(getPaint());
+ g2.fill(getBoundsReference());
+ }
+ else {
+ super.paint(paintContext);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ new InterfaceFrame();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
index 3fe86d6..ef0ae72 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
@@ -13,94 +13,95 @@
import edu.umd.cs.piccolox.PFrame;
public class PiccoloPresentation extends PFrame {
-
- protected PNode slideBar;
- protected PNode currentSlide;
- protected PBasicInputEventHandler eventHandler;
- protected ArrayList slides = new ArrayList();
- public PiccoloPresentation() {
- super();
- }
+ protected PNode slideBar;
+ protected PNode currentSlide;
+ protected PBasicInputEventHandler eventHandler;
+ protected ArrayList slides = new ArrayList();
- public void initialize() {
- setFullScreenMode(true);
- loadSlides();
-
- eventHandler = new PBasicInputEventHandler() {
- public void keyReleased(PInputEvent event) {
- if (event.getKeyCode() == KeyEvent.VK_SPACE) {
- int newIndex = slides.indexOf(currentSlide) + 1;
- if (newIndex < slides.size()) {
- goToSlide((PNode)slides.get(newIndex));
- }
- }
- }
+ public PiccoloPresentation() {
+ super();
+ }
- public void mouseReleased(PInputEvent event) {
- PNode picked = event.getPickedNode();
+ public void initialize() {
+ setFullScreenMode(true);
+ loadSlides();
- if (picked.getParent() == slideBar) {
- picked.moveToFront();
- if (picked.getScale() == 1) {
- goToSlide(null);
- } else {
- goToSlide(picked);
- }
- }
- }
- };
-
- getCanvas().requestFocus();
- getCanvas().addInputEventListener(eventHandler);
- getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(eventHandler);
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- }
+ eventHandler = new PBasicInputEventHandler() {
+ public void keyReleased(PInputEvent event) {
+ if (event.getKeyCode() == KeyEvent.VK_SPACE) {
+ int newIndex = slides.indexOf(currentSlide) + 1;
+ if (newIndex < slides.size()) {
+ goToSlide((PNode) slides.get(newIndex));
+ }
+ }
+ }
- public void goToSlide(PNode slide) {
- if (currentSlide != null) {
- currentSlide.animateToTransform((AffineTransform)currentSlide.getAttribute("small"), 1000);
- }
-
- currentSlide = slide;
-
- if (currentSlide != null) {
- currentSlide.moveToFront();
- currentSlide.animateToTransform((AffineTransform)currentSlide.getAttribute("large"), 1000);
- }
- }
-
- public void loadSlides() {
- slideBar = new PNode();
- slideBar.setPaint(Color.DARK_GRAY);
- slideBar.setBounds(0, 0, getCanvas().getWidth(), 100);
- slideBar.setOffset(0, getCanvas().getHeight() - 100);
- getCanvas().getLayer().addChild(slideBar);
-
- File[] slideFiles = new File("slides").listFiles();
- for (int i = 0; i < slideFiles.length; i++) {
- PNode slide = new PImage(slideFiles[i].getPath());
-
- if (slide.getHeight() != (getHeight() - 100)) {
- slide = new PImage(slide.toImage(getWidth(), getHeight() - 100, null));
- }
- slide.offset((getWidth() - slide.getWidth()) / 2, - (getHeight() - 100));
- slide.addAttribute("large", slide.getTransform());
+ public void mouseReleased(PInputEvent event) {
+ PNode picked = event.getPickedNode();
- slide.setTransform(new AffineTransform());
- slide.scale((100 - 20) / slide.getHeight());
- slide.offset(i * (slide.getFullBoundsReference().getWidth() + 10) + 10, 10);
- slide.addAttribute("small", slide.getTransform());
+ if (picked.getParent() == slideBar) {
+ picked.moveToFront();
+ if (picked.getScale() == 1) {
+ goToSlide(null);
+ }
+ else {
+ goToSlide(picked);
+ }
+ }
+ }
+ };
- slideBar.addChild(slide);
- slides.add(slide);
- }
-
- goToSlide((PNode)slides.get(0));
- }
-
- public static void main(String[] argv) {
- new PiccoloPresentation();
- }
+ getCanvas().requestFocus();
+ getCanvas().addInputEventListener(eventHandler);
+ getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(eventHandler);
+ getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ }
+
+ public void goToSlide(PNode slide) {
+ if (currentSlide != null) {
+ currentSlide.animateToTransform((AffineTransform) currentSlide.getAttribute("small"), 1000);
+ }
+
+ currentSlide = slide;
+
+ if (currentSlide != null) {
+ currentSlide.moveToFront();
+ currentSlide.animateToTransform((AffineTransform) currentSlide.getAttribute("large"), 1000);
+ }
+ }
+
+ public void loadSlides() {
+ slideBar = new PNode();
+ slideBar.setPaint(Color.DARK_GRAY);
+ slideBar.setBounds(0, 0, getCanvas().getWidth(), 100);
+ slideBar.setOffset(0, getCanvas().getHeight() - 100);
+ getCanvas().getLayer().addChild(slideBar);
+
+ File[] slideFiles = new File("slides").listFiles();
+ for (int i = 0; i < slideFiles.length; i++) {
+ PNode slide = new PImage(slideFiles[i].getPath());
+
+ if (slide.getHeight() != (getHeight() - 100)) {
+ slide = new PImage(slide.toImage(getWidth(), getHeight() - 100, null));
+ }
+ slide.offset((getWidth() - slide.getWidth()) / 2, -(getHeight() - 100));
+ slide.addAttribute("large", slide.getTransform());
+
+ slide.setTransform(new AffineTransform());
+ slide.scale((100 - 20) / slide.getHeight());
+ slide.offset(i * (slide.getFullBoundsReference().getWidth() + 10) + 10, 10);
+ slide.addAttribute("small", slide.getTransform());
+
+ slideBar.addChild(slide);
+ slides.add(slide);
+ }
+
+ goToSlide((PNode) slides.get(0));
+ }
+
+ public static void main(String[] argv) {
+ new PiccoloPresentation();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
index a49f2c0..37896d4 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
@@ -8,71 +8,76 @@
import edu.umd.cs.piccolox.*;
public class SpecialEffects extends PFrame {
- public void initialize() {
- // Create the Target for our Activities.
+ public void initialize() {
+ // Create the Target for our Activities.
- // Create a new node that we will apply different activities to, and
- // place that node at location 200, 200.
- final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
- aNode.setOffset(200, 200);
-
- // Extend PActivity.
+ // Create a new node that we will apply different activities to, and
+ // place that node at location 200, 200.
+ final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(aNode);
+ aNode.setOffset(200, 200);
- // Store the current time in milliseconds for use below.
- long currentTime = System.currentTimeMillis();
+ // Extend PActivity.
- // Create a new custom "flash" activity. This activity will start running in
- // five seconds, and while it runs it will flash aNode's paint between
- // red and green every half second.
- PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- // Toggle the target node's brush color between red and green
- // each time the activity steps.
- if (fRed) {
- aNode.setPaint(Color.red);
- } else {
- aNode.setPaint(Color.green);
- }
-
- fRed = !fRed;
- }
- };
-
- // Schedule the activity.
- getCanvas().getRoot().addActivity(flash);
-
- // Create three activities that animate the node's position. Since our node
- // already descends from the root node the animate methods will automatically
- // schedule these activities for us.
- PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
+ // Store the current time in milliseconds for use below.
+ long currentTime = System.currentTimeMillis();
- // The animate activities will start immediately (in the next call to
- // PRoot.processInputs) by default. Here we set their start times (in PRoot
- // global time) so that they start when the previous one has finished.
- a1.setStartTime(currentTime);
- a2.startAfter(a1);
- a3.startAfter(a2);
-
- a1.setDelegate(new PActivity.PActivityDelegate() {
- public void activityStarted(PActivity activity) {
- System.out.println("a1 started");
- }
- public void activityStepped(PActivity activity) {}
- public void activityFinished(PActivity activity) {
- System.out.println("a1 finished");
- }
- });
- }
+ // Create a new custom "flash" activity. This activity will start
+ // running in five seconds, and while it runs it will flash aNode's
+ // paint between red and green every half second.
+ PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
+ boolean fRed = true;
- public static void main(String[] args) {
- new SpecialEffects();
- }
+ protected void activityStep(long elapsedTime) {
+ super.activityStep(elapsedTime);
+
+ // Toggle the target node's brush color between red and green
+ // each time the activity steps.
+ if (fRed) {
+ aNode.setPaint(Color.red);
+ }
+ else {
+ aNode.setPaint(Color.green);
+ }
+
+ fRed = !fRed;
+ }
+ };
+
+ // Schedule the activity.
+ getCanvas().getRoot().addActivity(flash);
+
+ // Create three activities that animate the node's position. Since our
+ // node already descends from the root node the animate methods will
+ // automatically schedule these activities for us.
+ PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
+ PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
+ PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
+
+ // The animate activities will start immediately (in the next call to
+ // PRoot.processInputs) by default. Here we set their start times (in
+ // PRoot global time) so that they start when the previous one has
+ // finished.
+ a1.setStartTime(currentTime);
+ a2.startAfter(a1);
+ a3.startAfter(a2);
+
+ a1.setDelegate(new PActivity.PActivityDelegate() {
+ public void activityStarted(PActivity activity) {
+ System.out.println("a1 started");
+ }
+
+ public void activityStepped(PActivity activity) {
+ }
+
+ public void activityFinished(PActivity activity) {
+ System.out.println("a1 finished");
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+ new SpecialEffects();
+ }
}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
index 8233201..76384ef 100644
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
+++ b/examples/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
@@ -14,113 +14,116 @@
public class UserInteraction extends PFrame {
- public UserInteraction() {
- super();
- }
+ public UserInteraction() {
+ super();
+ }
- public void initialize() {
- // Create a Camera Event Listener.
+ public void initialize() {
+ // Create a Camera Event Listener.
- // Remove the pan event handler that is installed by default so that it
- // does not conflict with our new squiggle handler.
- getCanvas().setPanEventHandler(null);
+ // Remove the pan event handler that is installed by default so that it
+ // does not conflict with our new squiggle handler.
+ getCanvas().setPanEventHandler(null);
- // Create a squiggle handler and register it with the Canvas.
- PBasicInputEventHandler squiggleHandler = new SquiggleHandler(getCanvas());
- getCanvas().addInputEventListener(squiggleHandler);
-
- // Create a Node Event Listener.
+ // Create a squiggle handler and register it with the Canvas.
+ PBasicInputEventHandler squiggleHandler = new SquiggleHandler(getCanvas());
+ getCanvas().addInputEventListener(squiggleHandler);
- // Create a green rectangle node.
- PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
- nodeGreen.setPaint(Color.GREEN);
- getCanvas().getLayer().addChild(nodeGreen);
+ // Create a Node Event Listener.
-// Attach event handler directly to the node.
-nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- event.getPickedNode().setPaint(Color.ORANGE);
- event.getInputManager().setKeyboardFocus(event.getPath());
- event.setHandled(true);
- }
- public void mouseDragged(PInputEvent event) {
- PNode aNode = event.getPickedNode();
- PDimension delta = event.getDeltaRelativeTo(aNode);
- aNode.translate(delta.width, delta.height);
- event.setHandled(true);
- }
- public void mouseReleased(PInputEvent event) {
- event.getPickedNode().setPaint(Color.GREEN);
- event.setHandled(true);
- }
- public void keyPressed(PInputEvent event) {
- PNode node = event.getPickedNode();
- switch (event.getKeyCode()) {
- case KeyEvent.VK_UP:
- node.translate(0, -10f);
- break;
- case KeyEvent.VK_DOWN:
- node.translate(0, 10f);
- break;
- case KeyEvent.VK_LEFT:
- node.translate(-10f, 0);
- break;
- case KeyEvent.VK_RIGHT:
- node.translate(10f, 0);
- break;
- }
- }
-});
- }
+ // Create a green rectangle node.
+ PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
+ nodeGreen.setPaint(Color.GREEN);
+ getCanvas().getLayer().addChild(nodeGreen);
- public class SquiggleHandler extends PDragSequenceEventHandler {
- protected PCanvas canvas;
-
- // The squiggle that is currently getting created.
- protected PPath squiggle;
+ // Attach event handler directly to the node.
+ nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(PInputEvent event) {
+ event.getPickedNode().setPaint(Color.ORANGE);
+ event.getInputManager().setKeyboardFocus(event.getPath());
+ event.setHandled(true);
+ }
- public SquiggleHandler(PCanvas aCanvas) {
- canvas = aCanvas;
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
+ public void mouseDragged(PInputEvent event) {
+ PNode aNode = event.getPickedNode();
+ PDimension delta = event.getDeltaRelativeTo(aNode);
+ aNode.translate(delta.width, delta.height);
+ event.setHandled(true);
+ }
- Point2D p = e.getPosition();
+ public void mouseReleased(PInputEvent event) {
+ event.getPickedNode().setPaint(Color.GREEN);
+ event.setHandled(true);
+ }
- // Create a new squiggle and add it to the canvas.
- squiggle = new PPath();
- squiggle.moveTo((float) p.getX(), (float) p.getY());
- squiggle.setStroke(new BasicStroke((float) (1 / e.getCamera().getViewScale())));
- canvas.getLayer().addChild(squiggle);
-
- // Reset the keydboard focus.
- e.getInputManager().setKeyboardFocus(null);
- }
+ public void keyPressed(PInputEvent event) {
+ PNode node = event.getPickedNode();
+ switch (event.getKeyCode()) {
+ case KeyEvent.VK_UP:
+ node.translate(0, -10f);
+ break;
+ case KeyEvent.VK_DOWN:
+ node.translate(0, 10f);
+ break;
+ case KeyEvent.VK_LEFT:
+ node.translate(-10f, 0);
+ break;
+ case KeyEvent.VK_RIGHT:
+ node.translate(10f, 0);
+ break;
+ }
+ }
+ });
+ }
- public void drag(PInputEvent e) {
- super.drag(e);
- // Update the squiggle while dragging.
- updateSquiggle(e);
- }
+ public class SquiggleHandler extends PDragSequenceEventHandler {
+ protected PCanvas canvas;
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- // Update the squiggle one last time.
- updateSquiggle(e);
- squiggle = null;
- }
+ // The squiggle that is currently getting created.
+ protected PPath squiggle;
- public void updateSquiggle(PInputEvent aEvent) {
- // Add a new segment to the squiggle from the last mouse position
- // to the current mouse position.
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float) p.getX(), (float) p.getY());
- }
- }
+ public SquiggleHandler(PCanvas aCanvas) {
+ canvas = aCanvas;
+ setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+ }
- public static void main(String[] args) {
- new UserInteraction();
- }
+ public void startDrag(PInputEvent e) {
+ super.startDrag(e);
+
+ Point2D p = e.getPosition();
+
+ // Create a new squiggle and add it to the canvas.
+ squiggle = new PPath();
+ squiggle.moveTo((float) p.getX(), (float) p.getY());
+ squiggle.setStroke(new BasicStroke((float) (1 / e.getCamera().getViewScale())));
+ canvas.getLayer().addChild(squiggle);
+
+ // Reset the keydboard focus.
+ e.getInputManager().setKeyboardFocus(null);
+ }
+
+ public void drag(PInputEvent e) {
+ super.drag(e);
+ // Update the squiggle while dragging.
+ updateSquiggle(e);
+ }
+
+ public void endDrag(PInputEvent e) {
+ super.endDrag(e);
+ // Update the squiggle one last time.
+ updateSquiggle(e);
+ squiggle = null;
+ }
+
+ public void updateSquiggle(PInputEvent aEvent) {
+ // Add a new segment to the squiggle from the last mouse position
+ // to the current mouse position.
+ Point2D p = aEvent.getPosition();
+ squiggle.lineTo((float) p.getX(), (float) p.getY());
+ }
+ }
+
+ public static void main(String[] args) {
+ new UserInteraction();
+ }
}