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
deleted file mode 100644
index 59838fd..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.activities.PActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how create and schedule activities.
- */
-public class ActivityExample extends PFrame {
- private static final long serialVersionUID = 1L;
-
- public ActivityExample() {
- this(null);
- }
-
- public ActivityExample(final PCanvas aCanvas) {
- super("ActivityExample", false, aCanvas);
- }
-
- public void initialize() {
- final 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);
- final 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.
- final PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(final 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.
- final PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- final PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- final PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
- final 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(final 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
deleted file mode 100644
index eac89f1..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Stroke;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PHandle;
-import org.piccolo2d.extras.util.PLocator;
-import org.piccolo2d.util.PDimension;
-import org.piccolo2d.util.PPaintContext;
-
-
-/**
- * This shows how to create a simple node that has two handles and can be used
- * for specifying angles. The nodes UI desing isn't very exciting, but the
- * example shows one way to create a custom node with custom handles.
- */
-public class AngleNodeExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public AngleNodeExample() {
- this(null);
- }
-
- public AngleNodeExample(final PCanvas aCanvas) {
- super("AngleNodeExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas c = getCanvas();
- final PLayer l = c.getLayer();
- l.addChild(new AngleNode());
- }
-
- public static void main(final String[] args) {
- new AngleNodeExample();
- }
-
- // the angle node class
- public static class AngleNode extends PNode {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- 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() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public double locateX() {
- return pointOne.getX();
- }
-
- public double locateY() {
- return pointOne.getY();
- }
- };
- PHandle h = new PHandle(l) {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void dragHandle(final PDimension aLocalDimension, final PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointOne.setLocation(pointOne.getX() + aLocalDimension.getWidth(), pointOne.getY()
- + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
-
- // point two
- l = new PLocator() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public double locateX() {
- return pointTwo.getX();
- }
-
- public double locateY() {
- return pointTwo.getY();
- }
- };
- h = new PHandle(l) {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void dragHandle(final PDimension aLocalDimension, final PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointTwo.setLocation(pointTwo.getX() + aLocalDimension.getWidth(), pointTwo.getY()
- + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
- }
-
- protected void paint(final PPaintContext paintContext) {
- final Graphics2D g2 = paintContext.getGraphics();
- g2.setStroke(stroke);
- g2.setPaint(getPaint());
- g2.draw(getAnglePath());
- }
-
- protected void updateBounds() {
- final GeneralPath p = getAnglePath();
- final Rectangle2D b = stroke.createStrokedShape(p).getBounds2D();
- super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
- }
-
- public GeneralPath getAnglePath() {
- final 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(final double x, final double y, final double width, final 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
deleted file mode 100644
index 3d566a5..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
+++ /dev/null
@@ -1,480 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.JDialog;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PDragEventHandler;
-import org.piccolo2d.event.PDragSequenceEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.P3DRect;
-import org.piccolo2d.nodes.PImage;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-import org.piccolo2d.util.PBounds;
-import org.piccolo2d.util.PDimension;
-import org.piccolo2d.util.PPaintContext;
-
-
-/**
- * This example, contributed by Rowan Christmas, shows how to create a birds-eye
- * view window.
- */
-public class BirdsEyeViewExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- boolean fIsPressed = false;
-
- public BirdsEyeViewExample() {
- this(null);
- }
-
- public BirdsEyeViewExample(final PCanvas aCanvas) {
- super("BirdsEyeViewExample", 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 will create the actual BirdsEyeView and put it in a JDialog
- final BirdsEyeView bev = new BirdsEyeView();
- bev.connect(getCanvas(), new PLayer[] { getCanvas().getLayer() });
- final 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() {
- final PLayer layer = getCanvas().getLayer();
- final 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.
- final 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() {
- final 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)));
- }
-
- // 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)) {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void paint(final PPaintContext aPaintContext) {
- if (fIsPressed) {
- // if mouse is pressed draw self as a square.
- final 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(final PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = true;
- n.invalidatePaint(); // this tells the framework that the node
- // needs to be redisplayed.
- }
-
- public void mouseReleased(final 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() {
- final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // create parts for the face.
- final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- final PNode eye2 = (PNode) eye1.clone();
- final 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.
- final 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() {
- final PNode n = new PNode() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void paint(final PPaintContext aPaintContext) {
- final double bx = getX();
- final double by = getY();
- final double rightBorder = bx + getWidth();
- final double bottomBorder = by + getHeight();
-
- final Line2D line = new Line2D.Double();
- final 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(final String[] args) {
- new BirdsEyeViewExample();
- }
-
- /**
- * The Birds Eye View Class
- */
- public class BirdsEyeView extends PCanvas implements PropertyChangeListener {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * This is the node that shows the viewed area.
- */
- PNode areaVisiblePNode;
-
- /**
- * This is the canvas that is being viewed
- */
- PCanvas viewedCanvas;
-
- /**
- * The change listener to know when to update the birds eye view.
- */
- PropertyChangeListener changeListener;
-
- int layerCount;
-
- /**
- * Creates a new instance of a BirdsEyeView
- */
- public BirdsEyeView() {
-
- // create the PropertyChangeListener for listening to the viewed
- // canvas
- changeListener = new PropertyChangeListener() {
- public void propertyChange(final 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);
-
- // add the drag event handler
- getCamera().addInputEventListener(new PDragSequenceEventHandler() {
- protected void startDrag(final PInputEvent e) {
- if (e.getPickedNode() == areaVisiblePNode) {
- super.startDrag(e);
- }
- }
-
- protected void drag(final PInputEvent e) {
- final PDimension dim = e.getDelta();
- viewedCanvas.getCamera().translateView(0 - dim.getWidth(), 0 - dim.getHeight());
- }
-
- });
-
- // remove Pan and Zoom
- removeInputEventListener(getPanEventHandler());
- removeInputEventListener(getZoomEventHandler());
-
- setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
-
- }
-
- public void connect(final PCanvas canvas, final PLayer[] viewed_layers) {
-
- viewedCanvas = canvas;
- layerCount = 0;
-
- viewedCanvas.getCamera().addPropertyChangeListener(changeListener);
-
- 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(final PLayer new_layer) {
- getCamera().addLayer(new_layer);
- layerCount++;
- }
-
- /**
- * Remove the layer from the viewed layers
- */
- public void removeLayer(final 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);
-
- for (int i = 0; i < getCamera().getLayerCount(); ++i) {
- getCamera().removeLayer(i);
- }
-
- }
-
- /**
- * This method will get called when the viewed canvas changes
- */
- public void propertyChange(final 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() {
-
- double viewedX;
- double viewedY;
- double viewedHeight;
- double viewedWidth;
-
- final double ul_camera_x = viewedCanvas.getCamera().getViewBounds().getX();
- final double ul_camera_y = viewedCanvas.getCamera().getViewBounds().getY();
- final double lr_camera_x = ul_camera_x + viewedCanvas.getCamera().getViewBounds().getWidth();
- final double lr_camera_y = ul_camera_y + viewedCanvas.getCamera().getViewBounds().getHeight();
-
- final Rectangle2D drag_bounds = getCamera().getUnionOfLayerFullBounds();
-
- final double ul_layer_x = drag_bounds.getX();
- final double ul_layer_y = drag_bounds.getY();
- final double lr_layer_x = drag_bounds.getX() + drag_bounds.getWidth();
- final double lr_layer_y = drag_bounds.getY() + drag_bounds.getHeight();
-
- // 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;
- }
-
- // same for y
- if (ul_camera_y < ul_layer_y) {
- viewedY = ul_layer_y;
- }
- else {
- viewedY = ul_camera_y;
- }
-
- // 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;
- }
-
- // 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);
-
- // keep the birds eye view centered
- getCamera().animateViewToCenterBounds(drag_bounds, true, 0);
-
- }
-
- } // 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
deleted file mode 100644
index e48c5ae..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCamera;
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PBoundsHandle;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how to create internal cameras
- */
-public class CameraExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public CameraExample() {
- this(null);
- }
-
- public CameraExample(final PCanvas aCanvas) {
- super("CameraExample", false, aCanvas);
- }
-
- public void initialize() {
- final PLayer l = new PLayer();
- final 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);
-
- final 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(final 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
deleted file mode 100644
index d28d7a5..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import org.piccolo2d.PCamera;
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-public class CenterExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public CenterExample() {
- this(null);
- }
-
- public CenterExample(final PCanvas aCanvas) {
- super("CenterExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas c = getCanvas();
- final PLayer l = c.getLayer();
- final PCamera cam = c.getCamera();
-
- cam.scaleView(2.0);
- final 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(final 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
deleted file mode 100644
index 10e75f4..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.awt.geom.Point2D;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.event.PDragSequenceEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * This example shows how to create a vertical and a horizontal bar which can
- * move with your graph and always stays on view.
- *
- * @author Tao
- */
-public class ChartLabelExample extends PFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- final int nodeHeight = 15;
- final int nodeWidth = 30;
-
- // Row Bar
- PLayer rowBarLayer;
-
- // Colume Bar
- PLayer colBarLayer;
-
- public ChartLabelExample() {
- this(null);
- }
-
- public ChartLabelExample(final PCanvas aCanvas) {
- super("ChartLabelExample", false, aCanvas);
- }
-
- 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 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);
-
- // create matrix nodes
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- final 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;
-
- public void mousePressed(final PInputEvent aEvent) {
- oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
- }
-
- public void mouseReleased(final 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(final 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
deleted file mode 100644
index 676cfe7..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.event.PDragEventHandler;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.PClip;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * Quick example of how to use a clip.
- */
-public class ClipExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public ClipExample() {
- this(null);
- }
-
- public ClipExample(final PCanvas aCanvas) {
- super("ClipExample", false, aCanvas);
- }
-
- public void initialize() {
- final 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(final 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
deleted file mode 100644
index 87cdbfb..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PDragEventHandler;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.PComposite;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * 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 {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public CompositeExample() {
- this(null);
- }
-
- public CompositeExample(final PCanvas aCanvas) {
- super("CompositeExample", false, aCanvas);
- }
-
- public void initialize() {
- final PComposite composite = new PComposite();
-
- final PNode circle = PPath.createEllipse(0, 0, 100, 100);
- final PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
- final 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(final 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
deleted file mode 100644
index 5193513..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.util.Iterator;
-import java.util.Random;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.PRoot;
-import org.piccolo2d.activities.PActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.util.PFixedWidthStroke;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * 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 {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public DynamicExample() {
- this(null);
- }
-
- public DynamicExample(final PCanvas aCanvas) {
- super("DynamicExample", false, aCanvas);
- }
-
- public void initialize() {
- final PLayer layer = getCanvas().getLayer();
- final PRoot root = getCanvas().getRoot();
- final 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);
- final PActivity a = new PActivity(-1, 20) {
- public void activityStep(final long currentTime) {
- super.activityStep(currentTime);
- rotateNodes();
- }
- };
- root.addActivity(a);
-
- final PPath p = new PPath();
- p.moveTo(0, 0);
- p.lineTo(0, 1000);
- final 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() {
- final Iterator i = getCanvas().getLayer().getChildrenReference().iterator();
- while (i.hasNext()) {
- final PNode each = (PNode) i.next();
- each.rotate(Math.toRadians(2));
- }
- }
-
- public static void main(final 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
deleted file mode 100644
index 7754cab..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.event.PInputEventFilter;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.util.PBounds;
-
-
-/**
- * This example shows how to create and install a custom event listener that
- * draws rectangles.
- */
-public class EventHandlerExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public EventHandlerExample() {
- this(null);
- }
-
- public EventHandlerExample(final 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.
- final 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(final PInputEvent e) {
- super.mousePressed(e);
-
- final 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(final PInputEvent e) {
- super.mouseDragged(e);
- // update the drag point location.
- dragPoint = e.getPosition();
-
- // update the rectangle shape.
- updateRectangle();
- }
-
- public void mouseReleased(final 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.
- final PBounds b = new PBounds();
- b.add(pressPoint);
- b.add(dragPoint);
-
- // Set the rectangles bounds.
- rectangle.setPathTo(b);
- }
- };
- }
-
- public static void main(final 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
deleted file mode 100644
index ab240c9..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.swing.AbstractAction;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.WindowConstants;
-import javax.swing.border.TitledBorder;
-
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.util.PDebug;
-
-
-public class ExampleRunner extends JFrame {
- private static final long serialVersionUID = 1L;
-
- public ExampleRunner() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Piccolo Example Runner");
- setSize(650, 600);
- getContentPane().setLayout(new BorderLayout());
- createExampleButtons();
-
- getContentPane().setBackground(new Color(200, 200, 200));
- validate();
- setVisible(true);
- }
-
- public void createExampleButtons() {
- final Container c = getContentPane();
-
- c.add(buildOptions(), BorderLayout.NORTH);
- JPanel panel= new JPanel(new GridLayout(0, 2));
- c.add(BorderLayout.CENTER, panel);
-
- addExampleButtons(panel, new Class[] { ActivityExample.class, AngleNodeExample.class,
- BirdsEyeViewExample.class, CameraExample.class, CenterExample.class, ChartLabelExample.class,
- ClipExample.class, CompositeExample.class, DynamicExample.class, EventHandlerExample.class,
- FullScreenNodeExample.class, GraphEditorExample.class, GridExample.class, GroupExample.class,
- HandleExample.class, HelloWorldExample.class, HierarchyZoomExample.class, HtmlViewExample.class,
- KeyEventFocusExample.class, LayoutExample.class, LensExample.class, NavigationExample.class,
- NodeCacheExample.class, NodeEventExample.class, NodeExample.class, NodeLinkExample.class,
- P3DRectExample.class, PanToExample.class, PathExample.class, PositionExample.class,
- PositionPathActivityExample.class, PulseExample.class, ScrollingExample.class, SelectionExample.class,
- ShadowExample.class, SquiggleExample.class, StickyExample.class, StickyHandleLayerExample.class,
- StrokeExample.class, TextExample.class, TooltipExample.class, TwoCanvasExample.class,
- WaitForActivitiesExample.class });
- }
-
- /**
- * @param c
- */
- private JPanel buildOptions() {
- JPanel optionsPanel = new JPanel(new GridLayout(3, 1));
- optionsPanel.setBorder(new TitledBorder("Display Options"));
-
- optionsPanel.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") {
- public void actionPerformed(final ActionEvent e) {
- PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate;
- }
- }));
-
- optionsPanel.add(new JCheckBox(new AbstractAction("Show Region Managment") {
- public void actionPerformed(final ActionEvent e) {
- PDebug.debugRegionManagement = !PDebug.debugRegionManagement;
- }
- }));
-
- optionsPanel.add(new JCheckBox(new AbstractAction("Show Full Bounds") {
- public void actionPerformed(final ActionEvent e) {
- PDebug.debugFullBounds = !PDebug.debugFullBounds;
- }
- }));
-
- return optionsPanel;
- }
-
- private void addExampleButtons(final JPanel panel, final Class[] exampleClasses) {
- for (int i = 0; i < exampleClasses.length; i++) {
- panel.add(buildExampleButton(exampleClasses[i]));
- }
- }
-
- private JButton buildExampleButton(final Class exampleClass) {
- final String fullClassName = exampleClass.getName();
- final String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
- final String exampleLabel = camelToProper(simpleClassName);
- JButton button = new JButton(new AbstractAction(exampleLabel) {
- public void actionPerformed(final ActionEvent event) {
- try {
- final PFrame example = (PFrame) exampleClass.newInstance();
- example.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- }
- catch (final Exception e) {
- JOptionPane.showMessageDialog(ExampleRunner.this,
- "A problem was encountered running the example.\n\n" + e.getMessage());
- }
- }
- });
- button.setBackground(Color.WHITE);
- button.setHorizontalAlignment(JButton.LEFT);
- return button;
- }
-
- private String camelToProper(String camel) {
- Pattern pattern = Pattern.compile("[a-z]([A-Z])");
- Matcher matcher = pattern.matcher(camel);
- StringBuffer result = new StringBuffer();
- int lastIndex = 0;
- while (matcher.find()) {
- int nextWord = matcher.start(1);
- result.append(camel.substring(lastIndex, nextWord));
- result.append(' ');
- lastIndex = nextWord;
- }
- result.append(camel.substring(lastIndex, camel.length()));
- return result.toString();
- }
-
- public static void main(final String[] args) {
- new ExampleRunner();
- }
-}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/FrameCanvasSizeBugExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/FrameCanvasSizeBugExample.java
deleted file mode 100644
index cd24c50..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/FrameCanvasSizeBugExample.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PText;
-
-
-
-/**
- * This example demonstrates a bug with setting the size
- * of a PFrame. See http://code.google.com/p/piccolo2d/issues/detail?id=141.
- */
-public class FrameCanvasSizeBugExample
- extends PFrame {
-
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Create a new frame canvas size bug example.
- */
- public FrameCanvasSizeBugExample() {
- this(null);
- }
-
- /**
- * Create a new frame canvas size bug example for the specified canvas.
- *
- * @param canvas canvas for this frame canvas size bug example
- */
- public FrameCanvasSizeBugExample(final PCanvas canvas) {
- super("FrameCanvasSizeBugExample", false, canvas);
- //setSize(410, 410);
- //getCanvas().setSize(410, 410); does not help
- }
-
-
- /** {@inheritDoc} */
- public void initialize() {
- PText label = new PText("Note white at border S and E\nIt goes away when frame is resized");
- label.setOffset(200, 340);
- getCanvas().getLayer().addChild(label);
- getCanvas().setBackground(Color.PINK);
- getCanvas().setOpaque(true);
- setSize(410, 410);
- //getCanvas().setSize(410, 410); does not help
- }
-
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- new FrameCanvasSizeBugExample();
- }
-}
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
deleted file mode 100644
index bfb2234..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-public class FullScreenNodeExample extends NodeExample {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void initialize() {
- super.initialize();
- setFullScreenMode(true);
- }
-
- public static void main(final 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
deleted file mode 100644
index 9cbabbb..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Random;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PDragSequenceEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * 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 {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public GraphEditorExample() {
- this(null);
- }
-
- public GraphEditorExample(final PCanvas aCanvas) {
- super("GraphEditorExample", false, aCanvas);
- }
-
- public void initialize() {
- final int numNodes = 50;
- final int numEdges = 50;
-
- // Initialize, and create a layer for the edges (always underneath the
- // nodes)
- final PLayer nodeLayer = getCanvas().getLayer();
- final PLayer edgeLayer = new PLayer();
- getCanvas().getCamera().addLayer(0, edgeLayer);
- final Random rnd = new Random();
- ArrayList tmp;
- for (int i = 0; i < numNodes; i++) {
- final float x = (float) (300. * rnd.nextDouble());
- final float y = (float) (400. * rnd.nextDouble());
- final 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++) {
- final int n1 = rnd.nextInt(numNodes);
- final int n2 = rnd.nextInt(numNodes);
- final PNode node1 = nodeLayer.getChild(n1);
- final PNode node2 = nodeLayer.getChild(n2);
-
- final Point2D.Double bound1 = (Point2D.Double) node1.getBounds().getCenter2D();
- final Point2D.Double bound2 = (Point2D.Double) node2.getBounds().getCenter2D();
-
- final 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 = new ArrayList();
- tmp.add(node1);
- tmp.add(node2);
- edge.addAttribute("nodes", tmp);
-
- edgeLayer.addChild(edge);
- }
-
- // Create event handler to move nodes and update edges
- nodeLayer.addInputEventListener(new NodeDragHandler());
- }
-
- public static void main(final String[] args) {
- new GraphEditorExample();
- }
-
- // TODO eclipse formatter made this ugly
- // /
"); - html.append("This is an example of what can be done with PHtml."); - html.append("
"); - html.append("It supports:
"); - appendFeatures(); - - final PHtmlView htmlNode = new PHtmlView(html.toString()); - htmlNode.setBounds(0, 0, 400, 400); - getCanvas().getLayer().addChild(htmlNode); - - getCanvas().addInputEventListener(new PBasicInputEventHandler() { - public void mouseClicked(final PInputEvent event) { - final PNode clickedNode = event.getPickedNode(); - if (!(clickedNode instanceof PHtmlView)) { - return; - } - - final Point2D clickPoint = event.getPositionRelativeTo(clickedNode); - final PHtmlView htmlNode = (PHtmlView) clickedNode; - - final String url = htmlNode.getLinkAddressAt(clickPoint.getX(), clickPoint.getY()); - JOptionPane.showMessageDialog(null, url); - } - }); - } - - private void appendFeatures() { - html.append("Col 1 | Col 2 |
---|---|
Col 1 val | Col 2 val |
offset(double, double)
and
- * translate(double, double)
.
- *
- * @see PNode#offset(double, double)
- * @see PNode#translate(double, double)
- */
-public class OffsetVsTranslateExample
- extends PFrame {
-
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Create a new offset vs. translate example.
- */
- public OffsetVsTranslateExample() {
- this(null);
- }
-
- /**
- * Create a new offset vs. translate example for the specified canvas.
- *
- * @param canvas canvas for this offset vs. translate example
- */
- public OffsetVsTranslateExample(final PCanvas canvas) {
- super("OffsetVsTranslateExample", false, canvas);
- }
-
-
- /** {@inheritDoc} */
- public void initialize() {
- final PText offset = new PText("Offset node");
- final PText offsetRotated = new PText("Offset rotated node");
- final PText translate = new PText("Translated node");
- final PText translateRotated = new PText("Translated rotated node");
-
- offset.setScale(2.0d);
- offsetRotated.setScale(2.0d);
- translate.setScale(2.0d);
- translateRotated.setScale(2.0d);
-
- offsetRotated.setRotation(Math.PI / 8.0d);
- translateRotated.setRotation(Math.PI / 8.0d);
- offset.setOffset(15.0d, 100.0d);
- offsetRotated.setOffset(15.0d, 150.0d);
- translate.setOffset(15.0d, 200.0d);
- translateRotated.setOffset(15.0d, 250.0d);
-
- getCanvas().getLayer().addChild(offset);
- getCanvas().getLayer().addChild(offsetRotated);
- getCanvas().getLayer().addChild(translate);
- getCanvas().getLayer().addChild(translateRotated);
-
- offset.addActivity(new PActivity(-1L) {
- /** {@inheritDoc} */
- protected void activityStep(final long elapsedTime) {
- offset.offset(1.0d, 0.0d);
- }
- });
- offsetRotated.addActivity(new PActivity(-1L) {
- /** {@inheritDoc} */
- protected void activityStep(final long elapsedTime) {
- offsetRotated.offset(1.0d, 0.0d);
- }
- });
- translate.addActivity(new PActivity(-1L) {
- /** {@inheritDoc} */
- protected void activityStep(final long elapsedTime) {
- translate.translate(1.0d, 0.0d);
- }
- });
- translateRotated.addActivity(new PActivity(-1L) {
- /** {@inheritDoc} */
- protected void activityStep(final long elapsedTime) {
- translateRotated.translate(1.0d, 0.0d);
- }
- });
- }
-
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- new OffsetVsTranslateExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/P3DRectExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/P3DRectExample.java
deleted file mode 100644
index 5c7de83..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/P3DRectExample.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.P3DRect;
-
-
-public class P3DRectExample extends PFrame {
-
- public P3DRectExample() {
- this(null);
- }
-
- public P3DRectExample(final PCanvas aCanvas) {
- super("P3DRect Example", false, aCanvas);
- }
-
- public void initialize() {
- final P3DRect rect1 = new P3DRect(50, 50, 100, 100);
- rect1.setPaint(new Color(239, 235, 222));
- getCanvas().getLayer().addChild(rect1);
-
- final P3DRect rect2 = new P3DRect(50, 50, 100, 100);
- rect2.setPaint(new Color(239, 235, 222));
- rect2.translate(110, 0);
- rect2.setRaised(false);
- getCanvas().getLayer().addChild(rect2);
- }
-
- public static void main(String[] args) {
- new P3DRectExample();
- }
-
-}
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
deleted file mode 100644
index 80853c6..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import javax.swing.BorderFactory;
-import javax.swing.JSlider;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-
-
-/**
- * Demonstrates the use of PSwing in a Piccolo application.
- */
-
-public class PSwingExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PSwingExample() {
- this(new PSwingCanvas());
- }
-
- public PSwingExample(final PCanvas aCanvas) {
- super("PSwingExample", false, aCanvas);
- }
-
- public void initialize() {
- final PSwingCanvas pswingCanvas = (PSwingCanvas) getCanvas();
- final PLayer l = pswingCanvas.getLayer();
-
- final JSlider js = new JSlider(0, 100);
- js.addChangeListener(new ChangeListener() {
- public void stateChanged(final ChangeEvent e) {
- System.out.println("e = " + e);
- }
- });
- js.setBorder(BorderFactory.createTitledBorder("Test JSlider"));
- final PSwing pSwing = new PSwing(js);
- pSwing.translate(100, 100);
- l.addChild(pSwing);
-
- pswingCanvas.setPanEventHandler(null);
- }
-
- public static void main(final 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
deleted file mode 100644
index aacf0bf..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.util.Random;
-
-import org.piccolo2d.PCamera;
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * 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 {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PanToExample() {
- this(null);
- }
-
- public PanToExample(final 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);
-
- eacha = PPath.createRectangle(350, 350, 100, 100);
- eacha.setPaint(Color.green);
- getCanvas().getLayer().addChild(eacha);
-
- getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(final PInputEvent event) {
- if (!(event.getPickedNode() instanceof PCamera)) {
- event.setHandled(true);
- getCanvas().getCamera().animateViewToPanToBounds(event.getPickedNode().getGlobalFullBounds(), 500);
- }
- }
- });
-
- final PLayer layer = getCanvas().getLayer();
-
- final Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- final 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(final 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
deleted file mode 100644
index 7cb86e4..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.event.PDragEventHandler;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PStickyHandleManager;
-import org.piccolo2d.extras.util.PFixedWidthStroke;
-import org.piccolo2d.nodes.PPath;
-
-
-public class PathExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PathExample() {
- this(null);
- }
-
- public PathExample(final PCanvas aCanvas) {
- super("PathExample", false, aCanvas);
- }
-
- public void initialize() {
- final PPath n1 = PPath.createRectangle(0, 0, 100, 80);
- final PPath n2 = PPath.createEllipse(100, 100, 200, 34);
- final 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(final 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
deleted file mode 100644
index d6f2728..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-public class PositionExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PositionExample() {
- this(null);
- }
-
- public PositionExample(final PCanvas aCanvas) {
- super("PositionExample", false, aCanvas);
- }
-
- public void initialize() {
- final PNode n1 = PPath.createRectangle(0, 0, 100, 80);
- final 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(final 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
deleted file mode 100644
index b09e2dc..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.geom.Arc2D;
-import java.awt.geom.GeneralPath;
-
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.activities.PPositionPathActivity;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how create a simple acitivty to animate a node along a
- * general path.
- */
-public class PositionPathActivityExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PositionPathActivityExample() {
- super();
- }
-
- public void initialize() {
- final PLayer layer = getCanvas().getLayer();
- final PNode animatedNode = PPath.createRectangle(0, 0, 100, 80);
- layer.addChild(animatedNode);
-
- // create animation path
- final 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 node to display animation path
- final PPath ppath = new PPath(path);
- layer.addChild(ppath);
-
- // create activity to run animation.
- final PPositionPathActivity positionPathActivity = new PPositionPathActivity(5000, 0,
- new PPositionPathActivity.Target() {
- public void setPosition(final double x, final 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(final String[] args) {
- new PositionPathActivityExample();
- }
-}
\ No newline at end of file
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
deleted file mode 100644
index bf9a77b..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.print.PageFormat;
-import java.awt.print.Printable;
-import java.awt.print.PrinterException;
-import java.awt.print.PrinterJob;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JToggleButton;
-import javax.swing.JToolBar;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.swing.PDefaultScrollDirector;
-import org.piccolo2d.extras.swing.PScrollDirector;
-import org.piccolo2d.extras.swing.PScrollPane;
-import org.piccolo2d.extras.swing.PViewport;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.util.PAffineTransform;
-import org.piccolo2d.util.PBounds;
-
-
-/**
- * Adding print action to scrolling example.
- *
- * @author Lance Good
- * @author Ben Bederson
- */
-public class PrintExample extends PFrame {
-
- private static final long serialVersionUID = 1L;
-
- public PrintExample() {
- this(null);
- }
-
- public PrintExample(final PCanvas aCanvas) {
- super("ScrollingExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas canvas = getCanvas();
- final PScrollPane scrollPane = new PScrollPane(canvas);
- final PViewport viewport = (PViewport) scrollPane.getViewport();
- final PScrollDirector windowSD = viewport.getScrollDirector();
- final PScrollDirector documentSD = new DocumentScrollDirector();
-
- addBackgroundShapes(canvas);
-
- // Now, create the toolbar
- final JToolBar toolBar = new JToolBar();
- final JToggleButton window = new JToggleButton("Window Scrolling");
- final JToggleButton document = new JToggleButton("Document Scrolling");
- final JButton print = new JButton("Print");
- final ButtonGroup bg = new ButtonGroup();
- bg.add(window);
- bg.add(document);
- toolBar.add(window);
- toolBar.add(document);
- toolBar.addSeparator();
- toolBar.add(print);
- toolBar.setFloatable(false);
- window.setSelected(true);
- window.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent ae) {
- viewport.setScrollDirector(windowSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- getContentPane().validate();
- }
- });
- document.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent ae) {
- viewport.setScrollDirector(documentSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- getContentPane().validate();
- }
- });
- print.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent ae) {
- try {
- print();
- }
- catch (final PrinterException e) {
- JOptionPane.showMessageDialog(PrintExample.this, "An error occured while printing");
- }
- }
- });
- final JPanel contentPane = new JPanel();
- contentPane.setLayout(new BorderLayout());
- contentPane.add("Center", scrollPane);
- contentPane.add("North", toolBar);
- setContentPane(contentPane);
- validate();
- }
-
- private void addBackgroundShapes(final PCanvas canvas) {
- for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
- int x = shapeCount % 21;
- int y = (shapeCount - x) / 21;
-
- if (shapeCount % 2 == 0) {
- final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- else if (shapeCount % 2 == 1) {
- final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
-
- }
- }
-
- /**
- * A modified scroll director that performs document based scroling rather
- * than window based scrolling (ie. the scrollbars act in the inverse
- * direction as normal)
- */
- public class DocumentScrollDirector extends PDefaultScrollDirector {
-
- /**
- * 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(final Rectangle2D viewBounds) {
- final Point pos = new Point();
- if (camera != null) {
- // First we compute the union of all the layers
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
-
- // Rather than finding the distance from the upper left corner
- // of the window to the upper left corner of the document -
- // we instead find the distance from the lower right corner
- // of the window to the upper left corner of the document
- // THEN we measure the offset from the lower right corner
- // of the document
- pos.setLocation((int) (layerBounds.getWidth()
- - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
- .getHeight()
- - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
- }
-
- return pos;
-
- }
-
- /**
- * 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(final double x, final double y) {
- if (camera == null)
- return;
-
- // If a scroll is in progress - we ignore new scrolls - if we
- // didn't, since the scrollbars depend on the camera location
- // we can end up with an infinite loop
- if (scrollInProgress)
- return;
-
- scrollInProgress = true;
-
- // Get the union of all the layers' bounds
- final PBounds layerBounds = new PBounds();
- final List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- final PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds, layerBounds);
-
- // Union the camera view bounds
- final PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates -
- // This is basically the distance from the lower right
- // corner of the window to the upper left corner of the
- // document
- // We then measure the offset from the lower right corner
- // of the document
- final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- - (y + viewBounds.getHeight()));
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
- }
-
- /**
- * Print the canvas.
- *
- * @throws PrinterException
- */
- private void print() throws PrinterException {
- final PrinterJob printJob = PrinterJob.getPrinterJob();
- printJob.setPrintable(new Printable() {
- public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex)
- throws PrinterException {
- if (pageIndex > 0) {
- return NO_SUCH_PAGE;
- }
- else {
- final Graphics2D g2 = (Graphics2D) graphics;
- g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
- getCanvas().printAll(g2);
- return PAGE_EXISTS;
- }
- }
- });
- if (printJob.printDialog()) {
- printJob.print();
- }
- }
-
- public static void main(final String[] args) {
- new PrintExample();
- }
-}
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
deleted file mode 100644
index 5943250..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.PRoot;
-import org.piccolo2d.activities.PActivityScheduler;
-import org.piccolo2d.activities.PColorActivity;
-import org.piccolo2d.activities.PInterpolatingActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how to set up interpolating activities that repeat. For
- * example it shows how to create a rectangle whos color pulses.
- *
- * @author jesse
- */
-public class PulseExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PulseExample() {
- this(null);
- }
-
- public PulseExample(final PCanvas aCanvas) {
- super("PulseExample", false, aCanvas);
- }
-
- public void initialize() {
- final PRoot root = getCanvas().getRoot();
- final PLayer layer = getCanvas().getLayer();
- final 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);
-
- layer.addChild(singlePulse);
- layer.addChild(repeatePulse);
- layer.addChild(repeateReversePulse);
-
- // animate from source to destination color in one second,
- final PColorActivity singlePulseActivity = new PColorActivity(1000, 0, 1,
- PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) singlePulse.getPaint();
- }
-
- public void setColor(final Color color) {
- singlePulse.setPaint(color);
- }
- }, Color.ORANGE);
-
- // animate from source to destination color in one second, loop 5 times
- final PColorActivity repeatPulseActivity = new PColorActivity(1000, 0, 5,
- PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) repeatePulse.getPaint();
- }
-
- public void setColor(final Color color) {
- repeatePulse.setPaint(color);
- }
- }, Color.BLUE);
-
- // animate from source to destination to source color in one second,
- // loop 10 times
- final 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(final Color color) {
- repeateReversePulse.setPaint(color);
- }
- }, Color.GREEN);
-
- scheduler.addActivity(singlePulseActivity);
- scheduler.addActivity(repeatPulseActivity);
- scheduler.addActivity(repeatReversePulseActivity);
- }
-
- public static void main(final 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
deleted file mode 100644
index 9ec8122..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.Iterator;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JPanel;
-import javax.swing.JToggleButton;
-import javax.swing.JToolBar;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.swing.PDefaultScrollDirector;
-import org.piccolo2d.extras.swing.PScrollDirector;
-import org.piccolo2d.extras.swing.PScrollPane;
-import org.piccolo2d.extras.swing.PViewport;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.util.PAffineTransform;
-import org.piccolo2d.util.PBounds;
-
-
-/**
- * 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 {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public ScrollingExample() {
- this(null);
- }
-
- public ScrollingExample(final PCanvas aCanvas) {
- super("ScrollingExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas canvas = getCanvas();
- final PScrollPane scrollPane = new PScrollPane(canvas);
- final PViewport viewport = (PViewport) scrollPane.getViewport();
- final PScrollDirector windowSD = viewport.getScrollDirector();
- final PScrollDirector documentSD = new DocumentScrollDirector();
-
- addBackgroundShapes(canvas);
-
- // Now, create the toolbar
- final JToolBar toolBar = new JToolBar();
- final JToggleButton window = new JToggleButton("Window Scrolling");
- final JToggleButton document = new JToggleButton("Document Scrolling");
- final 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(final ActionEvent ae) {
- viewport.setScrollDirector(windowSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- getContentPane().validate();
- }
- });
- document.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent ae) {
- viewport.setScrollDirector(documentSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- getContentPane().validate();
- }
- });
-
- final JPanel contentPane = new JPanel();
- contentPane.setLayout(new BorderLayout());
- contentPane.add("Center", scrollPane);
- contentPane.add("North", toolBar);
- setContentPane(contentPane);
- validate();
- }
-
- /**
- * 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 {
-
- /**
- * 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(final Rectangle2D viewBounds) {
- final Point pos = new Point();
- if (camera == null)
- return pos;
-
- // First we compute the union of all the layers
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
-
- // Rather than finding the distance from the upper left corner
- // of the window to the upper left corner of the document -
- // we instead find the distance from the lower right corner
- // of the window to the upper left corner of the document
- // THEN we measure the offset from the lower right corner
- // of the document
- pos.setLocation((int) (layerBounds.getWidth()
- - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
- .getHeight()
- - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
-
- return pos;
-
- }
-
- /**
- * 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(final double x, final double y) {
- if (camera == null)
- return;
-
- // If a scroll is in progress - we ignore new scrolls - if we
- // didn't, since the scrollbars depend on the camera
- // location we can end up with an infinite loop
- if (scrollInProgress)
- return;
-
- scrollInProgress = true;
-
- // Get the union of all the layers' bounds
- final PBounds layerBounds = new PBounds();
- final java.util.List layers = camera.getLayersReference();
- for (final Iterator i = layers.iterator(); i.hasNext();) {
- final PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- final PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds, layerBounds);
-
- // Union the camera view bounds
- final PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates -
- // This is basically the distance from the lower right
- // corner of the window to the upper left corner of the
- // document. We then measure the offset from the lower right corner
- // of the document
- final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- - (y + viewBounds.getHeight()));
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
- }
-
- private void addBackgroundShapes(final PCanvas canvas) {
- for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
- int x = shapeCount % 21;
- int y = (shapeCount - x) / 21;
-
- if (shapeCount % 2 == 0) {
- final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- else if (shapeCount % 2 == 1) {
- final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
-
- }
- }
-
- public static void main(final 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
deleted file mode 100644
index e96eb5d..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.event.PNotification;
-import org.piccolo2d.extras.event.PNotificationCenter;
-import org.piccolo2d.extras.event.PSelectionEventHandler;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how the selection event handler works. It creates a bunch
- * of objects that can be selected.
- */
-public class SelectionExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public SelectionExample() {
- this(null);
- }
-
- public SelectionExample(final PCanvas aCanvas) {
- super("SelectionExample", false, aCanvas);
- }
-
- public void initialize() {
- for (int i = 0; i < 5; i++) {
- for (int j = 0; j < 5; j++) {
- final 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
- final 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(final PNotification notfication) {
- System.out.println("selection changed");
- }
-
- public static void main(final String[] args) {
- new SelectionExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ShadowExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ShadowExample.java
deleted file mode 100755
index 662f305..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ShadowExample.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-
-import java.awt.image.BufferedImage;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.PShadow;
-import org.piccolo2d.nodes.PImage;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-
-
-
-/**
- * Shadow example.
- */
-public final class ShadowExample extends PFrame {
-
- private static final Color SHADOW_PAINT = new Color(20, 20, 20, 200);
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Create a new shadow example.
- */
- public ShadowExample() {
- this(null);
- }
-
- /**
- * Create a new shadow example with the specified canvas.
- *
- * @param canvas canvas for this shadow example
- */
- public ShadowExample(final PCanvas canvas) {
- super("ShadowExample", false, canvas);
- }
-
-
- /** {@inheritDoc} */
- public void initialize() {
- BufferedImage src = buildRedRectangleImage();
-
- addHeaderAt("Shadow nodes drawn from an image, with increasing blur radius:", 0, 0);
-
- double x = 25.0d;
- double y = 25.0d;
-
- for (int blurRadius = 4; blurRadius < 28; blurRadius += 4) {
- PImage node = new PImage(src);
- PShadow shadowNode = new PShadow(src, SHADOW_PAINT, blurRadius);
-
- node.setOffset(x, y);
- // offset the shadow to account for blur radius offset and light direction
- shadowNode.setOffset(x - (2 * blurRadius) + 5.0d, y - (2 * blurRadius) + 5.0d);
-
- // add shadow node before node, or set Z explicitly (e.g. sendToBack())
- getCanvas().getLayer().addChild(shadowNode);
- getCanvas().getLayer().addChild(node);
-
- x += 125.0d;
- if (x > 300.0d) {
- y += 125.0d;
- x = 25.0d;
- }
- }
-
- addHeaderAt("Shadow nodes drawn from node.toImage():", 0, 300);
-
- PPath rectNode = buildRedRectangleNode();
-
- PShadow rectShadow = new PShadow(rectNode.toImage(), SHADOW_PAINT, 8);
- rectShadow.setOffset(25.0d - (2 * 8) + 5.0d, 325.0d - (2 * 8) + 5.0d);
-
- getCanvas().getLayer().addChild(rectShadow);
- getCanvas().getLayer().addChild(rectNode);
-
- PText textNode = new PText("Shadow Text");
- textNode.setTextPaint(Color.RED);
- textNode.setFont(textNode.getFont().deriveFont(36.0f));
- textNode.setOffset(125.0d, 325.0d);
-
- PShadow textShadow = new PShadow(textNode.toImage(), SHADOW_PAINT, 8);
- textShadow.setOffset(125.0d - (2 * 8) + 2.5d, 325.0d - (2 * 8) + 2.5d);
-
- getCanvas().getLayer().addChild(textShadow);
- getCanvas().getLayer().addChild(textNode);
- }
-
- private PText addHeaderAt(String labelText, double x, double y) {
- PText labelNode = new PText(labelText);
- labelNode.setOffset(x, y);
- getCanvas().getLayer().addChild(labelNode);
- return labelNode;
- }
-
-
-
- private BufferedImage buildRedRectangleImage() {
- BufferedImage src = new BufferedImage(75, 75, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = src.createGraphics();
- g.setPaint(Color.RED);
- g.fillRect(0, 0, 75, 75);
- g.dispose();
- return src;
- }
-
- private PPath buildRedRectangleNode() {
- PPath rectNode = PPath.createRectangle(0.0f, 0.0f, 75.0f, 75.0f);
- rectNode.setPaint(Color.RED);
- rectNode.setStroke(null);
- rectNode.setOffset(25.0d, 325.0d);
- return rectNode;
- }
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- new ShadowExample();
- }
-}
\ No newline at end of file
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
deleted file mode 100644
index 5b4ab6b..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.BoxLayout;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSlider;
-import javax.swing.JTabbedPane;
-import javax.swing.SwingConstants;
-import javax.swing.SwingUtilities;
-import javax.swing.border.EmptyBorder;
-
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-import org.piccolo2d.extras.swing.PScrollPane;
-
-
-/**
- * Tests a set of Sliders and Checkboxes in panels.
- *
- * @author Martin Clifford
- */
-public class SliderExample extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private final PSwingCanvas canvas;
- private final PScrollPane scrollPane;
- private final JTabbedPane tabbedPane;
- private final PSwing swing;
-
- public SliderExample() {
- // Create main panel
- final JPanel mainPanel = new JPanel(false);
- // Create a tabbed pane
- tabbedPane = new JTabbedPane();
- tabbedPane.setPreferredSize(new Dimension(700, 700));
- // Add tabbed pane to main panel
- mainPanel.add(tabbedPane);
- // Set the frame contents
- getContentPane().add(mainPanel);
-
- // Create a canvas
- canvas = new PSwingCanvas();
- canvas.setPreferredSize(new Dimension(700, 700));
- // Create a scroll pane for the canvas
- scrollPane = new PScrollPane(canvas);
- // Create a new tab for the tabbed pane
- tabbedPane.add("Tab 1", scrollPane);
-
- // Create the contents for "Tab 1"
- final 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 = createNestedPanel();
- 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 = createNestedPanel();
- panel.setSize(new Dimension(250, 250));
- panel.setLocation(350, 350);
- tabPanel.add(panel);
- // Add the default zoom button
- final JButton buttonPreset = new JButton("Zoom = 100%");
- buttonPreset.addActionListener(new ActionListener() {
- public void actionPerformed(final 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);
- // Create a pswing object for the tab panel
- swing = new PSwing(tabPanel);
- swing.translate(0, 0);
- // Add the pswing object to the canvas
- canvas.getLayer().addChild(swing);
- // Turn off default pan event handling
- canvas.setPanEventHandler(null);
-
- // Set up basic frame
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Slider Example");
- setResizable(true);
- setBackground(null);
- pack();
- 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);
- final JLabel label2 = new JLabel("A Panel within a panel");
- label2.setHorizontalAlignment(SwingConstants.CENTER);
- final JSlider slider = new JSlider();
- final JCheckBox cbox1 = new JCheckBox("Checkbox 1");
- final JCheckBox cbox2 = new JCheckBox("Checkbox 2");
- final 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);
- final 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(final 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
deleted file mode 100644
index 102348b..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PDragSequenceEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.event.PInputEventFilter;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-public class SquiggleExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private PLayer layer;
-
- public SquiggleExample() {
- this(null);
- }
-
- public SquiggleExample(final PCanvas aCanvas) {
- super("SquiggleExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
- final PBasicInputEventHandler squiggleEventHandler = createSquiggleEventHandler();
- squiggleEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(squiggleEventHandler);
- layer = getCanvas().getLayer();
- }
-
- public PBasicInputEventHandler createSquiggleEventHandler() {
- return new PDragSequenceEventHandler() {
-
- protected PPath squiggle;
-
- public void startDrag(final PInputEvent e) {
- super.startDrag(e);
-
- final 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(final PInputEvent e) {
- super.drag(e);
- updateSquiggle(e);
- }
-
- public void endDrag(final PInputEvent e) {
- super.endDrag(e);
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(final PInputEvent aEvent) {
- final Point2D p = aEvent.getPosition();
- squiggle.lineTo((float) p.getX(), (float) p.getY());
- }
- };
- }
-
- public static void main(final 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
deleted file mode 100644
index 7215e2e..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PBoundsHandle;
-import org.piccolo2d.nodes.PPath;
-
-
-public class StickyExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public StickyExample() {
- this(null);
- }
-
- public StickyExample(final PCanvas aCanvas) {
- super("StickyExample", false, aCanvas);
- }
-
- public void initialize() {
- final 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(final 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
deleted file mode 100644
index ae5b4c3..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.util.Iterator;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.PRoot;
-import org.piccolo2d.activities.PActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PBoundsHandle;
-import org.piccolo2d.extras.handles.PHandle;
-import org.piccolo2d.extras.util.PBoundsLocator;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * 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
- * the view is zoomed. They will also be drawn on top of all other objects, even
- * if those objects overlap the object that they manipulate. For this setup we
- * need to add and updateHandles activity that makes sure to relocate the handle
- * after any change. Another way to do this would be to add change listeners to
- * the camera and the node that they manipulate and only update them then. But
- * this method is easier and should be plenty efficient for normal use.
- *
- * @author jesse
- */
-public class StickyHandleLayerExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public StickyHandleLayerExample() {
- this(null);
- }
-
- public StickyHandleLayerExample(final PCanvas aCanvas) {
- super("StickyHandleLayerExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas c = getCanvas();
-
- final PActivity updateHandles = new PActivity(-1, 0) {
- protected void activityStep(final long elapsedTime) {
- super.activityStep(elapsedTime);
-
- final PRoot root = getActivityScheduler().getRoot();
-
- if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
- final Iterator i = getCanvas().getCamera().getChildrenIterator();
- while (i.hasNext()) {
- final PNode each = (PNode) i.next();
- if (each instanceof PHandle) {
- final PHandle handle = (PHandle) each;
- handle.relocateHandle();
- }
- }
- }
- }
- };
-
- final 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(final String[] args) {
- new StickyHandleLayerExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/StrokeExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/StrokeExample.java
deleted file mode 100644
index 21a06a1..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/StrokeExample.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.util.PFixedWidthStroke;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * Stroke example.
- */
-public final class StrokeExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a new stroke example.
- */
- public StrokeExample() {
- this(null);
- }
-
- /**
- * Create a new stroke example with the specified canvas.
- *
- * @param canvas canvas
- */
- public StrokeExample(final PCanvas canvas) {
- super("StrokeExample", false, canvas);
- }
-
- /** {@inheritDoc} */
- public void initialize() {
- final PText label = new PText("Stroke Example");
- label.setFont(label.getFont().deriveFont(24.0f));
- label.offset(20.0d, 20.0d);
-
- final PPath rect = PPath.createRectangle(50.0f, 50.0f, 300.0f, 300.0f);
- rect.setStroke(new BasicStroke(4.0f));
- rect.setStrokePaint(new Color(80, 80, 80));
-
- final PText fixedWidthLabel = new PText("PFixedWidthStrokes");
- fixedWidthLabel.setTextPaint(new Color(80, 0, 0));
- fixedWidthLabel.offset(100.0d, 80.0d);
-
- final PPath fixedWidthRect0 = PPath.createRectangle(100.0f, 100.0f, 200.0f, 50.0f);
- fixedWidthRect0.setStroke(new PFixedWidthStroke(2.0f));
- fixedWidthRect0.setStrokePaint(new Color(60, 60, 60));
-
- final PPath fixedWidthRect1 = PPath.createRectangle(100.0f, 175.0f, 200.0f, 50.0f);
- fixedWidthRect1.setStroke(new PFixedWidthStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f));
- // fixedWidthRect1.setStroke(new PFixedWidthStroke(1.5f,
- // PFixedWidthStroke.CAP_ROUND, PFixedWidthStroke.JOIN_MITER, 10.0f));
- fixedWidthRect1.setStrokePaint(new Color(40, 40, 40));
-
- final PPath fixedWidthRect2 = PPath.createRectangle(100.0f, 250.0f, 200.0f, 50.0f);
- fixedWidthRect2.setStroke(new PFixedWidthStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
- new float[] { 2.0f, 3.0f, 4.0f }, 1.0f));
- // fixedWidthRect2.setStroke(new PFixedWidthStroke(1.0f,
- // PFixedWidthStroke.CAP_ROUND, PFixedWidthStroke.JOIN_MITER, 10.0f, new
- // float[] { 2.0f, 3.0f, 4.0f }, 1.0f));
- fixedWidthRect2.setStrokePaint(new Color(20, 20, 20));
-
- getCanvas().getLayer().addChild(label);
- getCanvas().getLayer().addChild(rect);
- getCanvas().getLayer().addChild(fixedWidthLabel);
- getCanvas().getLayer().addChild(fixedWidthRect0);
- getCanvas().getLayer().addChild(fixedWidthRect1);
- getCanvas().getLayer().addChild(fixedWidthRect2);
- }
-
- /**
- * Main.
- *
- * @param args command line arguments
- */
- public static void main(final String[] args) {
- new StrokeExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/SwingLayoutExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/SwingLayoutExample.java
deleted file mode 100644
index e14d431..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/SwingLayoutExample.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Rectangle2D;
-
-import javax.swing.BoxLayout;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSlider;
-import javax.swing.JTextField;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-import org.piccolo2d.extras.swing.SwingLayoutNode;
-import org.piccolo2d.extras.swing.SwingLayoutNode.Anchor;
-import org.piccolo2d.nodes.PHtmlView;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-public class SwingLayoutExample {
-
- public static class MyPPath extends PPath {
- public MyPPath(final Shape shape, final Color color, final Stroke stroke, final Color strokeColor) {
- super(shape, stroke);
- setPaint(color);
- setStrokePaint(strokeColor);
- }
- }
-
- public static void main(final String[] args) {
-
- final Dimension canvasSize = new Dimension(800, 600);
- final PCanvas canvas = new PSwingCanvas();
- canvas.setPreferredSize(canvasSize);
-
- final PNode rootNode = new PNode();
- canvas.getLayer().addChild(rootNode);
- rootNode.addInputEventListener(new PBasicInputEventHandler() {
- // Shift+Drag up/down will scale the node up/down
- public void mouseDragged(final PInputEvent event) {
- super.mouseDragged(event);
- if (event.isShiftDown()) {
- event.getPickedNode().scale(event.getCanvasDelta().height > 0 ? 0.98 : 1.02);
- }
- }
- });
-
- final BorderLayout borderLayout = new BorderLayout();
- borderLayout.setHgap(10);
- borderLayout.setVgap(5);
- final SwingLayoutNode borderLayoutNode = new SwingLayoutNode(borderLayout);
- borderLayoutNode.addChild(new PText("North"), BorderLayout.NORTH);
- borderLayoutNode.setAnchor(Anchor.CENTER);
- borderLayoutNode.addChild(new PText("South"), BorderLayout.SOUTH);
- borderLayoutNode.setAnchor(Anchor.WEST);
- borderLayoutNode.addChild(new PText("East"), BorderLayout.EAST);
- borderLayoutNode.addChild(new PText("West"), BorderLayout.WEST);
- borderLayoutNode.addChild(new PText("CENTER"), BorderLayout.CENTER);
- borderLayoutNode.setOffset(100, 100);
- rootNode.addChild(borderLayoutNode);
-
- final SwingLayoutNode flowLayoutNode = new SwingLayoutNode(new FlowLayout());
- flowLayoutNode.addChild(new PText("1+1"));
- flowLayoutNode.addChild(new PText("2+2"));
- flowLayoutNode.setOffset(200, 200);
- rootNode.addChild(flowLayoutNode);
-
- final SwingLayoutNode gridBagLayoutNode = new SwingLayoutNode(new GridBagLayout());
- final GridBagConstraints gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridx = GridBagConstraints.RELATIVE;
- gridBagLayoutNode.addChild(new PText("FirstNode"), gridBagConstraints);
- gridBagLayoutNode.addChild(new PText("SecondNode"), gridBagConstraints);
- gridBagConstraints.insets = new Insets(50, 50, 50, 50);
- gridBagLayoutNode.addChild(new PText("ThirdNode"), gridBagConstraints);
- gridBagLayoutNode.setOffset(400, 250);
- rootNode.addChild(gridBagLayoutNode);
-
- JPanel container = new JPanel();
- container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
- final SwingLayoutNode boxLayoutNode = new SwingLayoutNode(container);
- boxLayoutNode.addChild(new MyPPath(new Rectangle2D.Double(0, 0, 50, 50), Color.yellow, new BasicStroke(2),
- Color.red));
- boxLayoutNode.addChild(new MyPPath(new Rectangle2D.Double(0, 0, 100, 50), Color.orange, new BasicStroke(2),
- Color.blue));
- final SwingLayoutNode innerNode = new SwingLayoutNode(); // nested
- // layout
- innerNode.addChild(new PSwing(new JLabel("foo")));
- innerNode.addChild(new PSwing(new JLabel("bar")));
- boxLayoutNode.addChild(innerNode, Anchor.CENTER);
- boxLayoutNode.setOffset(300, 300);
- rootNode.addChild(boxLayoutNode);
-
- final SwingLayoutNode horizontalLayoutNode = new SwingLayoutNode(new GridBagLayout());
- horizontalLayoutNode.addChild(new PSwing(new JButton("Zero")));
- horizontalLayoutNode.addChild(new PSwing(new JButton("One")));
- horizontalLayoutNode.addChild(new PSwing(new JButton("Two")));
- horizontalLayoutNode.addChild(new PSwing(new JLabel("Three")));
- horizontalLayoutNode.addChild(new PSwing(new JSlider()));
- horizontalLayoutNode.addChild(new PSwing(new JTextField("Four")));
- final PHtmlView htmlNode = new PHtmlView("Five", new JLabel().getFont().deriveFont(15f),
- Color.blue);
- htmlNode.scale(3);
- horizontalLayoutNode.addChild(htmlNode);
- horizontalLayoutNode.setOffset(100, 450);
- rootNode.addChild(horizontalLayoutNode);
-
- // 3x2 grid of values, shapes and labels (similar to a layout in
- // acid-base-solutions)
- final SwingLayoutNode gridNode = new SwingLayoutNode(new GridBagLayout());
- final GridBagConstraints constraints = new GridBagConstraints();
- constraints.insets = new Insets(10, 10, 10, 10);
- /*---- column of values, right justified ---*/
- constraints.gridy = 0; // row
- constraints.gridx = 0; // column
- constraints.anchor = GridBagConstraints.EAST;
- final PText dynamicNode = new PText("0"); // will be controlled by
- // dynamicSlider
- gridNode.addChild(dynamicNode, constraints);
- constraints.gridy++;
- gridNode.addChild(new PText("0"), constraints);
- /*---- column of shapes, center justified ---*/
- constraints.gridy = 0; // row
- constraints.gridx++; // column
- constraints.anchor = GridBagConstraints.CENTER;
- final PPath redCircle = new PPath(new Ellipse2D.Double(0, 0, 25, 25));
- redCircle.setPaint(Color.RED);
- gridNode.addChild(redCircle, constraints);
- constraints.gridy++;
- final PPath greenCircle = new PPath(new Ellipse2D.Double(0, 0, 25, 25));
- greenCircle.setPaint(Color.GREEN);
- gridNode.addChild(greenCircle, constraints);
- /*---- column of labels, left justified ---*/
- constraints.gridy = 0; // row
- constraints.gridx++; // column
- constraints.anchor = GridBagConstraints.WEST;
- gridNode.addChild(new PHtmlView("H2O"), constraints);
- constraints.gridy++;
- gridNode.addChild(new PHtmlView("H3O+"), constraints);
- gridNode.scale(2.0);
- gridNode.setOffset(400, 50);
- rootNode.addChild(gridNode);
-
- final JPanel controlPanel = new JPanel();
- controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
- final JSlider dynamicSlider = new JSlider(0, 1000, 0); // controls
- // dynamicNode
- dynamicSlider.setMajorTickSpacing(dynamicSlider.getMaximum());
- dynamicSlider.setPaintTicks(true);
- dynamicSlider.setPaintLabels(true);
- dynamicSlider.addChangeListener(new ChangeListener() {
-
- public void stateChanged(final ChangeEvent e) {
- dynamicNode.setText(String.valueOf(dynamicSlider.getValue()));
- }
- });
- controlPanel.add(dynamicSlider);
-
- final JPanel appPanel = new JPanel(new BorderLayout());
- appPanel.add(canvas, BorderLayout.CENTER);
- appPanel.add(controlPanel, BorderLayout.EAST);
-
- final JFrame frame = new JFrame();
- frame.setContentPane(appPanel);
- frame.pack();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
-}
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
deleted file mode 100644
index 3a1afdb..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.event.PStyledTextEventHandler;
-
-
-/**
- * @author Lance Good
- */
-public class TextExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public TextExample() {
- this(null);
- }
-
- public TextExample(final PCanvas aCanvas) {
- super("TextExample", false, aCanvas);
- }
-
- public void initialize() {
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- final PStyledTextEventHandler textHandler = new PStyledTextEventHandler(getCanvas());
- getCanvas().addInputEventListener(textHandler);
- }
-
- public static void main(final String[] args) {
- new TextExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/TextOffsetBoundsExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/TextOffsetBoundsExample.java
deleted file mode 100644
index 7fb8d1a..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TextOffsetBoundsExample.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import javax.swing.text.BadLocationException;
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.Document;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.nodes.PStyledText;
-import org.piccolo2d.nodes.PHtmlView;
-import org.piccolo2d.nodes.PText;
-
-
-
-
-/**
- * Example of text rendering with offset bounds.
- */
-public class TextOffsetBoundsExample extends PFrame {
-
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
- public TextOffsetBoundsExample() {
- this(null);
- }
-
- public TextOffsetBoundsExample(final PCanvas aCanvas) {
- super("TextOffsetBoundsExample", false, aCanvas);
- }
-
- public void initialize() {
- String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere.";
- PText ptext = new PText(text);
- ptext.setPaint(Color.GRAY);
- ptext.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
- ptext.offset(0.0d, 50.0d);
-
- PHtmlView phtmlView = new PHtmlView(text);
- phtmlView.setPaint(Color.GRAY);
- phtmlView.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
- phtmlView.offset(0.0d, 150.0d);
-
- PStyledText pstyledText = new PStyledText();
- Document document = new DefaultStyledDocument();
- try {
- document.insertString(0, text, null);
- }
- catch (BadLocationException e) {
- // ignore
- }
- pstyledText.setDocument(document);
- pstyledText.setPaint(Color.GRAY);
- pstyledText.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
- pstyledText.offset(0.0d, 250.0d);
-
- getCanvas().getLayer().addChild(ptext);
- getCanvas().getLayer().addChild(phtmlView);
- getCanvas().getLayer().addChild(pstyledText);
- }
-
- public static void main(final String[] args) {
- new TextOffsetBoundsExample();
- }}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ToImageExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ToImageExample.java
deleted file mode 100644
index 62deee0..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ToImageExample.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import java.awt.image.BufferedImage;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PImage;
-import org.piccolo2d.nodes.PText;
-
-
-
-
-/**
- * This example demonstrates the difference between
- * the different fill strategies for {@link PNode#toImage(BufferedImage,Paint,int)}.
- */
-public class ToImageExample
- extends PFrame {
-
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Create a new toImage example.
- */
- public ToImageExample() {
- this(null);
- }
-
- /**
- * Create a new toImage example for the specified canvas.
- *
- * @param canvas canvas for this toImage example
- */
- public ToImageExample(final PCanvas canvas) {
- super("ToImageExample", false, canvas);
- }
-
-
- /** {@inheritDoc} */
- public void initialize() {
- PText aspectFit = new PText("Aspect Fit");
- PText aspectCover = new PText("Aspect Cover");
- PText exactFit = new PText("Exact Fit");
-
- PImage aspectFit100x100 = new PImage(aspectFit.toImage(
- new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
- PImage aspectFit100x200 = new PImage(aspectFit.toImage(
- new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
- PImage aspectFit200x100 = new PImage(aspectFit.toImage(
- new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
- aspectFit.setOffset(10.0, 20.0);
- aspectFit100x100.setOffset(10.0, 70.0);
- aspectFit100x200.setOffset(10.0, 174.0);
- aspectFit200x100.setOffset(10.0, 378.0);
-
- PImage aspectCover100x100 = new PImage(aspectCover.toImage(new BufferedImage(100, 100,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
- PImage aspectCover100x200 = new PImage(aspectCover.toImage(new BufferedImage(100, 200,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
- PImage aspectCover200x100 = new PImage(aspectCover.toImage(new BufferedImage(200, 100,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
- aspectCover.setOffset(214.0, 20.0);
- aspectCover100x100.setOffset(214.0, 70.0);
- aspectCover100x200.setOffset(214.0, 174.0);
- aspectCover200x100.setOffset(214.0, 378.0);
-
- PImage exactFit100x100 = new PImage(exactFit.toImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
- PImage exactFit100x200 = new PImage(exactFit.toImage(new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
- PImage exactFit200x100 = new PImage(exactFit.toImage(new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
- exactFit.setOffset(410.0, 20.0);
- exactFit100x100.setOffset(418.0, 70.0);
- exactFit100x200.setOffset(418.0, 174.0);
- exactFit200x100.setOffset(418.0, 378.0);
-
- PImage texture = new PImage(getClass().getResource("texture.png"));
-
- PImage textureAspectFit100x100 = new PImage(texture.toImage(
- new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
- PImage textureAspectFit100x200 = new PImage(texture.toImage(
- new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
- PImage textureAspectFit200x100 = new PImage(texture.toImage(
- new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
- PNode.FILL_STRATEGY_ASPECT_FIT));
-
- textureAspectFit100x100.setOffset(10.0, 482.0);
- textureAspectFit100x200.setOffset(10.0, 586.0);
- textureAspectFit200x100.setOffset(10.0, 790.0);
-
- PImage textureAspectCover100x100 = new PImage(texture.toImage(new BufferedImage(100, 100,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
- PImage textureAspectCover100x200 = new PImage(texture.toImage(new BufferedImage(100, 200,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
- PImage textureAspectCover200x100 = new PImage(texture.toImage(new BufferedImage(200, 100,
- BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
-
- textureAspectCover100x100.setOffset(214.0, 482.0);
- textureAspectCover100x200.setOffset(214.0, 586.0);
- textureAspectCover200x100.setOffset(214.0, 790.0);
-
- PImage textureExactFit100x100 = new PImage(texture.toImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
- PImage textureExactFit100x200 = new PImage(texture.toImage(new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
- PImage textureExactFit200x100 = new PImage(texture.toImage(new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB),
- Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
-
- textureExactFit100x100.setOffset(418.0, 482.0);
- textureExactFit100x200.setOffset(418.0, 586.0);
- textureExactFit200x100.setOffset(418.0, 790.0);
-
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aspectFit);
- layer.addChild(aspectCover);
- layer.addChild(exactFit);
- layer.addChild(aspectFit100x100);
- layer.addChild(aspectFit100x200);
- layer.addChild(aspectFit200x100);
- layer.addChild(aspectCover100x100);
- layer.addChild(aspectCover100x200);
- layer.addChild(aspectCover200x100);
- layer.addChild(exactFit100x100);
- layer.addChild(exactFit100x200);
- layer.addChild(exactFit200x100);
- layer.addChild(textureAspectFit100x100);
- layer.addChild(textureAspectFit100x200);
- layer.addChild(textureAspectFit200x100);
- layer.addChild(textureAspectCover100x100);
- layer.addChild(textureAspectCover100x200);
- layer.addChild(textureAspectCover200x100);
- layer.addChild(textureExactFit100x100);
- layer.addChild(textureExactFit100x200);
- layer.addChild(textureExactFit200x100);
-
- setSize(650, 510);
- }
-
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- new ToImageExample();
- }
-}
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
deleted file mode 100644
index 44ac21d..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.geom.Point2D;
-
-import org.piccolo2d.PCamera;
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * Simple example of one way to add tooltips
- *
- * @author jesse
- */
-public class TooltipExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public TooltipExample() {
- this(null);
- }
-
- public TooltipExample(final PCanvas aCanvas) {
- super("TooltipExample", false, aCanvas);
- }
-
- public void initialize() {
- final PNode n1 = PPath.createEllipse(0, 0, 100, 100);
- final 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(final PInputEvent event) {
- updateToolTip(event);
- }
-
- public void mouseDragged(final PInputEvent event) {
- updateToolTip(event);
- }
-
- public void updateToolTip(final PInputEvent event) {
- final PNode n = event.getPickedNode();
- final String tooltipString = (String) n.getAttribute("tooltip");
- final Point2D p = event.getCanvasPosition();
-
- event.getPath().canvasToLocal(p, camera);
-
- tooltipNode.setText(tooltipString);
- tooltipNode.setOffset(p.getX() + 8, p.getY() - 8);
- }
- });
- }
-
- public static void main(final 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
deleted file mode 100644
index 05679da..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import org.piccolo2d.PCamera;
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.PRoot;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.extras.handles.PBoundsHandle;
-import org.piccolo2d.nodes.PPath;
-
-
-public class TwoCanvasExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public TwoCanvasExample() {
- this(null);
- }
-
- public TwoCanvasExample(final PCanvas aCanvas) {
- super("TwoCanvasExample", false, aCanvas);
- }
-
- public void initialize() {
- final PRoot root = getCanvas().getRoot();
- final PLayer layer = getCanvas().getLayer();
-
- final PNode n = PPath.createRectangle(0, 0, 100, 80);
- final 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);
-
- final PCamera otherCamera = new PCamera();
- otherCamera.addLayer(layer);
- root.addChild(otherCamera);
-
- final PCanvas other = new PCanvas();
- other.setCamera(otherCamera);
- final PFrame result = new PFrame("TwoCanvasExample", false, other);
- result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- result.setLocation(500, 100);
- }
-
- public static void main(final 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
deleted file mode 100644
index a89b654..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.activities.PActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-/**
- * This example shows how to use setTriggerTime to synchronize the start and end
- * of two activities.
- */
-public class WaitForActivitiesExample extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public WaitForActivitiesExample() {
- this(null);
- }
-
- public WaitForActivitiesExample(final PCanvas aCanvas) {
- super("WaitForActivitiesExample", false, aCanvas);
- }
-
- public void initialize() {
- final PLayer layer = getCanvas().getLayer();
-
- final PNode a = PPath.createRectangle(0, 0, 100, 80);
- final PNode b = PPath.createRectangle(0, 0, 100, 80);
-
- layer.addChild(a);
- layer.addChild(b);
-
- final PActivity a1 = a.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
- final PActivity a2 = b.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
-
- a2.startAfter(a1);
- }
-
- public static void main(final String[] args) {
- new WaitForActivitiesExample();
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/CalendarNode.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/CalendarNode.java
deleted file mode 100644
index af13751..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/CalendarNode.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.fisheye;
-
-import java.awt.Font;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-
-
-class CalendarNode extends PNode {
- static int DEFAULT_NUM_DAYS = 7;
- static int DEFAULT_NUM_WEEKS = 12;
- static int TEXT_X_OFFSET = 1;
- static int TEXT_Y_OFFSET = 10;
- static int DEFAULT_ANIMATION_MILLIS = 250;
- static float FOCUS_SIZE_PERCENT = 0.65f;
- static Font DEFAULT_FONT = new Font("Arial", Font.PLAIN, 10);
-
- int numDays = DEFAULT_NUM_DAYS;
- int numWeeks = DEFAULT_NUM_WEEKS;
- int daysExpanded = 0;
- int weeksExpanded = 0;
-
- public CalendarNode() {
- for (int week = 0; week < numWeeks; week++) {
- for (int day = 0; day < numDays; day++) {
- addChild(new DayNode(week, day));
- }
- }
-
- CalendarNode.this.addInputEventListener(new PBasicInputEventHandler() {
- public void mouseReleased(PInputEvent event) {
- DayNode pickedDay = (DayNode) event.getPickedNode();
- if (pickedDay.hasWidthFocus && pickedDay.hasHeightFocus) {
- setFocusDay(null, true);
- }
- else {
- setFocusDay(pickedDay, true);
- }
- }
- });
- }
-
- public void setFocusDay(DayNode focusDay, boolean animate) {
- for (int i = 0; i < getChildrenCount(); i++) {
- DayNode each = (DayNode) getChild(i);
- each.hasWidthFocus = false;
- each.hasHeightFocus = false;
- }
-
- if (focusDay == null) {
- daysExpanded = 0;
- weeksExpanded = 0;
- }
- else {
- focusDay.hasWidthFocus = true;
- daysExpanded = 1;
- weeksExpanded = 1;
-
- for (int i = 0; i < numDays; i++) {
- getDay(focusDay.week, i).hasHeightFocus = true;
- }
-
- for (int i = 0; i < numWeeks; i++) {
- getDay(i, focusDay.day).hasWidthFocus = true;
- }
- }
-
- layoutChildren(animate);
- }
-
- public DayNode getDay(int week, int day) {
- return (DayNode) getChild((week * numDays) + day);
- }
-
- protected void layoutChildren(boolean animate) {
- double focusWidth = 0;
- double focusHeight = 0;
-
- if (daysExpanded != 0 && weeksExpanded != 0) {
- focusWidth = (getWidth() * FOCUS_SIZE_PERCENT) / daysExpanded;
- focusHeight = (getHeight() * FOCUS_SIZE_PERCENT) / weeksExpanded;
- }
-
- double collapsedWidth = (getWidth() - (focusWidth * daysExpanded))
- / (numDays - daysExpanded);
- double collapsedHeight = (getHeight() - (focusHeight * weeksExpanded))
- / (numWeeks - weeksExpanded);
-
- double xOffset = 0;
- double yOffset = 0;
- double rowHeight = 0;
- DayNode each = null;
-
- for (int week = 0; week < numWeeks; week++) {
- for (int day = 0; day < numDays; day++) {
- each = getDay(week, day);
- double width = collapsedWidth;
- double height = collapsedHeight;
-
- if (each.hasWidthFocus())
- width = focusWidth;
- if (each.hasHeightFocus())
- height = focusHeight;
-
- if (animate) {
- each.animateToBounds(xOffset, yOffset, width,
- height, DEFAULT_ANIMATION_MILLIS).setStepRate(0);
- }
- else {
- each.setBounds(xOffset, yOffset, width, height);
- }
-
- xOffset += width;
- rowHeight = height;
- }
- xOffset = 0;
- yOffset += rowHeight;
- }
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/DayNode.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/DayNode.java
deleted file mode 100644
index 2f02b1d..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/DayNode.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.fisheye;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.util.ArrayList;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.util.PPaintContext;
-
-
-class DayNode extends PNode {
- boolean hasWidthFocus;
- boolean hasHeightFocus;
- ArrayList lines;
- int week;
- int day;
- String dayOfMonthString;
-
- public DayNode(int week, int day) {
- lines = new ArrayList();
- lines.add("7:00 AM Walk the dog.");
- lines.add("9:30 AM Meet John for Breakfast.");
- lines.add("12:00 PM Lunch with Peter.");
- lines.add("3:00 PM Research Demo.");
- lines.add("6:00 PM Pickup Sarah from gymnastics.");
- lines.add("7:00 PM Pickup Tommy from karate.");
- this.week = week;
- this.day = day;
- this.dayOfMonthString = Integer.toString((week * 7) + day);
- setPaint(Color.BLACK);
- }
-
- public int getWeek() {
- return week;
- }
-
- public int getDay() {
- return day;
- }
-
- public boolean hasHeightFocus() {
- return hasHeightFocus;
- }
-
- public void setHasHeightFocus(boolean hasHeightFocus) {
- this.hasHeightFocus = hasHeightFocus;
- }
-
- public boolean hasWidthFocus() {
- return hasWidthFocus;
- }
-
- public void setHasWidthFocus(boolean hasWidthFocus) {
- this.hasWidthFocus = hasWidthFocus;
- }
-
- protected void paint(PPaintContext paintContext) {
- Graphics2D g2 = paintContext.getGraphics();
-
- g2.setPaint(getPaint());
- g2.draw(getBoundsReference());
- g2.setFont(CalendarNode.DEFAULT_FONT);
-
- float y = (float) getY() + CalendarNode.TEXT_Y_OFFSET;
- paintContext.getGraphics().drawString(dayOfMonthString,
- (float) getX() + CalendarNode.TEXT_X_OFFSET, y);
-
- if (hasWidthFocus && hasHeightFocus) {
- paintContext.pushClip(getBoundsReference());
- for (int i = 0; i < lines.size(); i++) {
- y += 10;
- g2.drawString((String) lines.get(i),
- (float) getX() + CalendarNode.TEXT_X_OFFSET, y);
- }
- paintContext.popClip(getBoundsReference());
- }
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheye.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheye.java
deleted file mode 100644
index 0d2645b..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheye.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.fisheye;
-
-import java.awt.Dimension;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-
-import org.piccolo2d.PCanvas;
-
-
-public class TabularFisheye extends PCanvas {
- private CalendarNode calendarNode;
-
- public TabularFisheye() {
- calendarNode = new CalendarNode();
- getLayer().addChild(calendarNode);
- setMinimumSize(new Dimension(300, 300));
- setPreferredSize(new Dimension(600, 600));
- setZoomEventHandler(null);
- setPanEventHandler(null);
-
- addComponentListener(new ComponentAdapter() {
- public void componentResized(ComponentEvent arg0) {
- calendarNode.setBounds(getX(), getY(),
- getWidth() - 1, getHeight() - 1);
- calendarNode.layoutChildren(false);
- }
- });
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeApplet.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeApplet.java
deleted file mode 100644
index 0e52fdd..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeApplet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.fisheye;
-
-import javax.swing.JApplet;
-
-public class TabularFisheyeApplet extends JApplet {
-
- public void init() {
- getContentPane().add(new TabularFisheye());
- }
-
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeFrame.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeFrame.java
deleted file mode 100644
index 9383fbb..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/fisheye/TabularFisheyeFrame.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.fisheye;
-
-import javax.swing.JFrame;
-
-public class TabularFisheyeFrame extends JFrame {
- public TabularFisheyeFrame() {
- setTitle("Piccolo2D Tabular Fisheye");
-
- TabularFisheye tabularFisheye = new TabularFisheye();
- getContentPane().add(tabularFisheye);
- pack();
- }
-
- public static void main(String args[]) {
- JFrame frame = new TabularFisheyeFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/MultiplePSwingCanvasesExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/MultiplePSwingCanvasesExample.java
deleted file mode 100644
index 13b8ef3..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/MultiplePSwingCanvasesExample.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.pswing;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-
-
-public class MultiplePSwingCanvasesExample extends JFrame {
-
-
- public static void main(final String[] args) {
- JFrame frame = new MultiplePSwingCanvasesExample();
-
- Container container = frame.getContentPane();
- container.setLayout(new BorderLayout());
-
- PSwingCanvas canvas1 = buildPSwingCanvas("Canvas 1", Color.RED);
- canvas1.setPreferredSize(new Dimension(350, 350));
- container.add(canvas1, BorderLayout.WEST);
-
- PSwingCanvas canvas2 = buildPSwingCanvas("Canvas 2", Color.BLUE);
- container.add(canvas2, BorderLayout.EAST);
- canvas2.setPreferredSize(new Dimension(350, 350));
-
- frame.pack();
- frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
- frame.setVisible(true);
-
- }
-
- private static PSwingCanvas buildPSwingCanvas(String canvasName, Color rectangleColor) {
- PSwingCanvas canvas = new PSwingCanvas();
- canvas.setPreferredSize(new Dimension(350, 350));
- canvas.getLayer().addChild(new PSwing(new JLabel(canvasName)));
-
- PSwing rectNode = buildRectangleNode(rectangleColor);
- rectNode.setOffset(100, 100);
- canvas.getLayer().addChild(rectNode);
-
- PSwing buttonNode = buildTestButton();
- buttonNode.setOffset(50, 50);
- canvas.getLayer().addChild(buttonNode);
-
- return canvas;
- }
-
- private static PSwing buildRectangleNode(Color rectangleColor) {
- JPanel rectPanel = new JPanel();
- rectPanel.setPreferredSize(new Dimension((int)(Math.random()*50+50), (int)(Math.random()*50+50)));
- rectPanel.setBackground(rectangleColor);
- PSwing rect = new PSwing(rectPanel);
- return rect;
- }
-
- private static PSwing buildTestButton() {
- final JButton button = new JButton("Click Me");
-
- button.addActionListener(new AbstractAction() {
-
- public void actionPerformed(ActionEvent arg0) {
- button.setText("Thanks");
- }
-
- });
-
- return new PSwing(button);
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample1.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample1.java
deleted file mode 100644
index 290a84c..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample1.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.pswing;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JColorChooser;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSlider;
-import javax.swing.JSpinner;
-import javax.swing.JTextArea;
-import javax.swing.JTree;
-import javax.swing.border.LineBorder;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PZoomEventHandler;
-import org.piccolo2d.extras.pswing.PComboBox;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
- */
-
-public class PSwingExample1 {
- public static void main(final String[] args) {
- final PSwingCanvas pCanvas = new PSwingCanvas();
- final PText pText = new PText("PText");
- pCanvas.getLayer().addChild(pText);
- final JFrame frame = new JFrame("Test Piccolo");
-
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setContentPane(pCanvas);
- frame.setSize(600, 800);
- frame.setVisible(true);
-
- final PText text2 = new PText("Text2");
- text2.setFont(new Font("Lucida Sans", Font.BOLD, 18));
- pCanvas.getLayer().addChild(text2);
- text2.translate(100, 100);
- text2.addInputEventListener(new PZoomEventHandler());
-
- pCanvas.removeInputEventListener(pCanvas.getPanEventHandler());
-
- final JButton jButton = new JButton("MyButton!");
- jButton.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- System.out.println("TestZSwing.actionPerformed!!!!!!!!!!!!!!*********************");
- }
- });
- final PSwing pSwing = new PSwing(jButton);
- pCanvas.getLayer().addChild(pSwing);
- pSwing.repaint();
-
- final JSpinner jSpinner = new JSpinner();
- jSpinner.setPreferredSize(new Dimension(100, jSpinner.getPreferredSize().height));
- final PSwing pSpinner = new PSwing(jSpinner);
- pCanvas.getLayer().addChild(pSpinner);
- pSpinner.translate(0, 150);
-
- final JCheckBox jcb = new JCheckBox("CheckBox", true);
- jcb.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- System.out.println("TestZSwing.JCheckBox.actionPerformed");
- }
- });
- jcb.addChangeListener(new ChangeListener() {
- public void stateChanged(final ChangeEvent e) {
- System.out.println("TestPSwing.JChekbox.stateChanged@" + System.currentTimeMillis());
- }
- });
- final PSwing pCheckBox = new PSwing(jcb);
- pCanvas.getLayer().addChild(pCheckBox);
- pCheckBox.translate(100, 0);
-
- // Growable JTextArea
- final JTextArea textArea = new JTextArea("This is a growable TextArea.\nTry it out!");
- textArea.setBorder(new LineBorder(Color.blue, 3));
- PSwing swing = new PSwing(textArea);
- swing.translate(150, 150);
- pCanvas.getLayer().addChild(swing);
-
- // A Slider
- final JSlider slider = new JSlider();
- final PSwing pSlider = new PSwing(slider);
- pSlider.translate(200, 200);
- pCanvas.getLayer().addChild(pSlider);
-
- // A Scrollable JTree
- final JTree tree = new JTree();
- tree.setEditable(true);
- final JScrollPane p = new JScrollPane(tree);
- p.setPreferredSize(new Dimension(150, 150));
- final PSwing pTree = new PSwing(p);
- pCanvas.getLayer().addChild(pTree);
- pTree.translate(0, 250);
-
- // A JColorChooser - also demonstrates JTabbedPane
- final JColorChooser chooser = new JColorChooser();
- final PSwing pChooser = new PSwing(chooser);
- pCanvas.getLayer().addChild(pChooser);
- pChooser.translate(100, 300);
-
- final JPanel myPanel = new JPanel();
- myPanel.setBorder(BorderFactory.createTitledBorder("Titled Border"));
- myPanel.add(new JCheckBox("CheckBox"));
- final PSwing panelSwing = new PSwing(myPanel);
- pCanvas.getLayer().addChild(panelSwing);
- panelSwing.translate(400, 50);
-
- // A Slider
- final JSlider slider2 = new JSlider();
- final PSwing pSlider2 = new PSwing(slider2);
- pSlider2.translate(200, 200);
- final PNode root = new PNode();
- root.addChild(pSlider2);
- root.scale(1.5);
- root.rotate(Math.PI / 4);
- root.translate(300, 200);
- pCanvas.getLayer().addChild(root);
-
- // A Combo Box
- final JPanel comboPanel = new JPanel();
- comboPanel.setBorder(BorderFactory.createTitledBorder("Combo Box"));
- final String[] listItems = { "Summer Teeth", "Mermaid Avenue", "Being There", "A.M." };
- final PComboBox box = new PComboBox(listItems);
- comboPanel.add(box);
- swing = new PSwing(comboPanel);
- swing.translate(200, 230);
- pCanvas.getLayer().addChild(swing);
- box.setEnvironment(swing, pCanvas);// has to be done manually at present
-
- // Revalidate and repaint
- pCanvas.revalidate();
- pCanvas.repaint();
-
- pCanvas.getCamera().animateViewToCenterBounds(pCanvas.getLayer().getFullBounds(), true, 1200);
- }
-
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample2.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample2.java
deleted file mode 100644
index 72e3d4a..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample2.java
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.pswing;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.event.ActionEvent;
-import java.io.IOException;
-import java.util.Vector;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JEditorPane;
-import javax.swing.JFrame;
-import javax.swing.JInternalFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSlider;
-import javax.swing.JSpinner;
-import javax.swing.JSplitPane;
-import javax.swing.JTabbedPane;
-import javax.swing.JTable;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.JToolBar;
-import javax.swing.JTree;
-import javax.swing.SpinnerNumberModel;
-import javax.swing.SwingConstants;
-import javax.swing.border.EmptyBorder;
-import javax.swing.border.EtchedBorder;
-import javax.swing.border.LineBorder;
-import javax.swing.border.TitledBorder;
-import javax.swing.event.HyperlinkEvent;
-import javax.swing.event.HyperlinkListener;
-import javax.swing.table.TableColumn;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-
-
-/**
- * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
- */
-
-public class PSwingExample2 extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public PSwingExample2() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- ClassLoader loader;
- PSwingCanvas canvas;
-
- // Set up basic frame
- setBounds(50, 50, 750, 750);
- setResizable(true);
- setBackground(null);
- setVisible(true);
- canvas = new PSwingCanvas();
- canvas.setPanEventHandler(null);
- getContentPane().add(canvas);
- validate();
- loader = getClass().getClassLoader();
-
- ZVisualLeaf leaf;
- PNode transform;
- PSwing swing;
- PSwing swing2;
-
- // JButton
- final JButton button = new JButton("Button");
- button.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- swing = new PSwing(button);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-500, -500);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // JButton
- final JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 10, 1));
- spinner.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
- swing = new PSwing(spinner);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-800, -500);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // 2nd Copy of JButton
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-450, -450);
- transform.rotate(Math.PI / 2);
- transform.scale(0.5);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // Growable JTextArea
- final JTextArea textArea = new JTextArea("This is a growable TextArea.\nTry it out!");
- textArea.setBorder(new LineBorder(Color.blue, 3));
- swing = new PSwing(textArea);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-250, -500);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // Growable JTextField
- JTextField textField = new JTextField("A growable text field");
- swing = new PSwing(textField);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(0, -500);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // A Slider
- final JSlider slider = new JSlider();
- swing = new PSwing(slider);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(250, -500);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // A Scrollable JTree
- final JTree tree = new JTree();
- tree.setEditable(true);
- final JScrollPane p = new JScrollPane(tree);
- p.setPreferredSize(new Dimension(150, 150));
- swing = new PSwing(p);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-500, -250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // A Scrollable JTextArea
- JScrollPane pane = new JScrollPane(new JTextArea("A Scrollable Text Area\nTry it out!"));
- pane.setPreferredSize(new Dimension(150, 150));
- swing = new PSwing(pane);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-250, -250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
- swing2 = swing;
-
- // A non-scrollable JTextField
- // A panel MUST be created with double buffering off
- JPanel panel = new JPanel(false);
- textField = new JTextField("A fixed-size text field");
- panel.setLayout(new BorderLayout());
- panel.add(textField);
- swing = new PSwing(panel);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(0, -250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // // A JComboBox
- // String[] listItems = {"Summer Teeth", "Mermaid Avenue",
- // "Being There", "A.M."};
- // ZComboBox box = new ZComboBox( listItems );
- // swing = new PSwing( canvas, box );
- // leaf = new ZVisualLeaf( swing );
- // transform = new PNode();
- // transform.translate( 0, -150 );
- // transform.addChild( leaf );
- // canvas.getLayer().addChild( transform );
-
- // A panel with TitledBorder and JList
- panel = new JPanel(false);
- panel.setBackground(Color.lightGray);
- panel.setLayout(new BorderLayout());
- panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED), "A JList", TitledBorder.LEFT,
- TitledBorder.TOP));
- panel.setPreferredSize(new Dimension(200, 200));
- final Vector data = new Vector();
- data.addElement("Choice 1");
- data.addElement("Choice 2");
- data.addElement("Choice 3");
- data.addElement("Choice 4");
- data.addElement("Choice 5");
- final JList list = new JList(data);
- list.setBackground(Color.lightGray);
- panel.add(list);
- swing = new PSwing(panel);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(250, -250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // A JLabel
- JLabel label = new JLabel("A JLabel", SwingConstants.CENTER);
- swing = new PSwing(label);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-500, 0);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- label = new JLabel("A JLabel", SwingConstants.CENTER);
- label.setIcon(new Icon() {
-
- public int getIconHeight() {
- return 20;
- }
-
- public int getIconWidth() {
- return 20;
- }
-
- public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
- g.setColor(Color.BLUE);
- g.drawRect(0, 0, 20, 20);
- }
- });
- swing = new PSwing(label);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-500, 30);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // Rotated copy of the Scrollable JTextArea
- leaf = new ZVisualLeaf(swing2);
- transform = new PNode();
- transform.translate(-100, 0);
- transform.rotate(Math.PI / 2);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // A panel with layout
- // A panel MUST be created with double buffering off
- panel = new JPanel(false);
- panel.setLayout(new BorderLayout());
- final JButton button1 = new JButton("Button 1");
- final JButton button2 = new JButton("Button 2");
- label = new JLabel("A Panel with Layout");
- label.setHorizontalAlignment(SwingConstants.CENTER);
- label.setForeground(Color.white);
- panel.setBackground(Color.red);
- panel.setPreferredSize(new Dimension(150, 150));
- panel.setBorder(new EmptyBorder(5, 5, 5, 5));
- panel.add(button1, "North");
- panel.add(button2, "South");
- panel.add(label, "Center");
- panel.revalidate();
- swing = new PSwing(panel);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(0, 0);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // JTable Example
- final Vector columns = new Vector();
- columns.addElement("Check Number");
- columns.addElement("Description");
- columns.addElement("Amount");
- final Vector rows = new Vector();
- Vector row = new Vector();
- row.addElement("101");
- row.addElement("Sandwich");
- row.addElement("$20.00");
- rows.addElement(row);
- row = new Vector();
- row.addElement("102");
- row.addElement("Monkey Wrench");
- row.addElement("$100.00");
- rows.addElement(row);
- row = new Vector();
- row.addElement("214");
- row.addElement("Ant farm");
- row.addElement("$55.00");
- rows.addElement(row);
- row = new Vector();
- row.addElement("215");
- row.addElement("Self-esteem tapes");
- row.addElement("$37.99");
- rows.addElement(row);
- row = new Vector();
- row.addElement("216");
- row.addElement("Tube Socks");
- row.addElement("$7.45");
- rows.addElement(row);
- row = new Vector();
- row.addElement("220");
- row.addElement("Ab Excerciser");
- row.addElement("$56.95");
- rows.addElement(row);
- row = new Vector();
- row.addElement("319");
- row.addElement("Y2K Supplies");
- row.addElement("$4624.33");
- rows.addElement(row);
- row = new Vector();
- row.addElement("332");
- row.addElement("Tie Rack");
- row.addElement("$15.20");
- rows.addElement(row);
- row = new Vector();
- row.addElement("344");
- row.addElement("Swing Set");
- row.addElement("$146.59");
- rows.addElement(row);
- final JTable table = new JTable(rows, columns);
- table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- table.setRowHeight(30);
- TableColumn c = table.getColumn(table.getColumnName(0));
- c.setPreferredWidth(150);
- c = table.getColumn(table.getColumnName(1));
- c.setPreferredWidth(150);
- c = table.getColumn(table.getColumnName(2));
- c.setPreferredWidth(150);
- pane = new JScrollPane(table);
- pane.setPreferredSize(new Dimension(200, 200));
- table.setDoubleBuffered(false);
- swing = new PSwing(pane);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(250, 0);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // JEditorPane - HTML example
- try {
-
- final JEditorPane editorPane = new JEditorPane(loader.getResource("csdept.html"));
- editorPane.setDoubleBuffered(false);
- editorPane.setEditable(false);
- pane = new JScrollPane(editorPane);
- pane.setDoubleBuffered(false);
- pane.setPreferredSize(new Dimension(400, 400));
- editorPane.addHyperlinkListener(new HyperlinkListener() {
- public void hyperlinkUpdate(final HyperlinkEvent e) {
- if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- try {
- editorPane.setPage(e.getURL());
- }
- catch (final IOException ioe) {
- System.out.println("Couldn't Load Web Page");
- }
- }
- }
- });
- swing = new PSwing(pane);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-500, 250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- }
- catch (final IOException ioe) {
- System.out.println("Couldn't Load Web Page");
- }
-
- // A JInternalFrame with a JSplitPane - a JOptionPane - and a
- // JToolBar
- final JInternalFrame iframe = new JInternalFrame("JInternalFrame");
- iframe.getRootPane().setDoubleBuffered(false);
- ((JComponent) iframe.getContentPane()).setDoubleBuffered(false);
- iframe.setPreferredSize(new Dimension(500, 500));
- final JTabbedPane tabby = new JTabbedPane();
- tabby.setDoubleBuffered(false);
- iframe.getContentPane().setLayout(new BorderLayout());
- final JOptionPane options = new JOptionPane("This is a JOptionPane!", JOptionPane.INFORMATION_MESSAGE,
- JOptionPane.DEFAULT_OPTION);
- options.setDoubleBuffered(false);
- options.setMinimumSize(new Dimension(50, 50));
- options.setPreferredSize(new Dimension(225, 225));
- final JPanel tools = new JPanel(false);
- tools.setMinimumSize(new Dimension(150, 150));
- tools.setPreferredSize(new Dimension(225, 225));
- final JToolBar bar = new JToolBar();
- final Action letter = new AbstractAction("Big A!") {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void actionPerformed(final ActionEvent e) {
- }
- };
-
- final Action hand = new AbstractAction("Hi!") {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void actionPerformed(final ActionEvent e) {
- }
- };
- final Action select = new AbstractAction("There!") {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void actionPerformed(final ActionEvent e) {
- }
- };
-
- label = new JLabel("A Panel with a JToolBar");
- label.setHorizontalAlignment(SwingConstants.CENTER);
- bar.add(letter);
- bar.add(hand);
- bar.add(select);
- bar.setFloatable(false);
- bar.setBorder(new LineBorder(Color.black, 2));
- tools.setLayout(new BorderLayout());
- tools.add(bar, "North");
- tools.add(label, "Center");
-
- final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, options, tools);
- split.setDoubleBuffered(false);
- iframe.getContentPane().add(split);
- swing = new PSwing(iframe);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(0, 250);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // JMenuBar menuBar = new JMenuBar();
- // ZMenu menu = new ZMenu( "File" );
- // ZMenu sub = new ZMenu( "Export" );
- // JMenuItem gif = new JMenuItem( "Funds" );
- // sub.add( gif );
- // menu.add( sub );
- // menuBar.add( menu );
- // iframe.setJMenuBar( menuBar );
-
- iframe.setVisible(true);
-
- // A JColorChooser - also demonstrates JTabbedPane
- // JColorChooser chooser = new JColorChooser();
- final JCheckBox chooser = new JCheckBox("Check Box");
- swing = new PSwing(chooser);
- leaf = new ZVisualLeaf(swing);
- transform = new PNode();
- transform.translate(-250, 850);
- transform.addChild(leaf);
- canvas.getLayer().addChild(transform);
-
- // Revalidate and repaint
- canvas.revalidate();
- canvas.repaint();
-
- final PSwing message = new PSwing(new JTextArea("Click-drag to zoom in and out."));
- message.translate(0, -50);
- canvas.getLayer().addChild(message);
-
- canvas.getCamera().animateViewToCenterBounds(canvas.getLayer().getFullBounds(), true, 1200);
- }
-
- public static void main(final String[] args) {
- new PSwingExample2().setVisible(true);
- }
-
- public static class ZVisualLeaf extends PNode {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public ZVisualLeaf(final PNode node) {
- addChild(node);
- }
- }
-
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample3.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample3.java
deleted file mode 100644
index 7f4ff22..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingExample3.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.pswing;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.SwingUtilities;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
- */
-public class PSwingExample3 extends JFrame {
- private static final long serialVersionUID = 1L;
-
- public PSwingExample3() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- // Set up basic frame
- setBounds(50, 50, 750, 750);
- setResizable(true);
- setBackground(null);
- setVisible(true);
- final PSwingCanvas canvas = new PSwingCanvas();
- getContentPane().add(canvas);
- validate();
-
- ExampleGrid exampleGrid = new ExampleGrid(3);
- exampleGrid.addChild(createButtonExamples());
- exampleGrid.addChild(createSimpleComponentExamples());
- canvas.getLayer().addChild(exampleGrid);
- SwingUtilities.invokeLater(new Runnable() {
-
- public void run() {
- canvas.getCamera().animateViewToCenterBounds(canvas.getLayer().getFullBounds(), true, 1200);
- }
-
- });
-
- }
-
- private ExampleList createSimpleComponentExamples() {
- ExampleList exampleList = new ExampleList("Simple Components");
- exampleList.addExample("JLabel", new PSwing(new JLabel("JLabel Example")));
- exampleList.addExample("JCheckBox ", new PSwing(new JCheckBox()));
-
- JRadioButton radio1 = new JRadioButton("Radio Option 1");
- JRadioButton radio2 = new JRadioButton("Radio Option 1");
- ButtonGroup buttonGroup = new ButtonGroup();
- buttonGroup.add(radio1);
- buttonGroup.add(radio2);
- exampleList.addExample("RadioButton 1", radio1);
- exampleList.addExample("RadioButton 2", radio2);
-
- JPanel examplePanel = new JPanel() {
-
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(Color.RED);
- g.fillRect(0, 0, getWidth(), getHeight());
-
- }
- };
- examplePanel.setPreferredSize(new Dimension(50, 50));
-
- exampleList.addExample("Custom JPanel ", examplePanel);
- return exampleList;
- }
-
- private ExampleList createButtonExamples() {
- ExampleList exampleList = new ExampleList("Button Examples");
- addButtonAloneNoSizing(exampleList);
- addButtonAlone200x50(exampleList);
- addButtonOnPanelNoSizing(exampleList);
- addButtonOnPanel200x50(exampleList);
- addButtonAlone10x10(exampleList);
- return exampleList;
- }
-
- private void addButtonAloneNoSizing(ExampleList exampleList) {
- JButton button = new JButton("Button");
- PSwing pButton = new PSwing(button);
- exampleList.addExample("Alone - No Sizing", pButton);
- }
-
- private void addButtonAlone200x50(ExampleList exampleList) {
- JButton button = new JButton("Button");
- button.setPreferredSize(new Dimension(200, 50));
- PSwing pButton = new PSwing(button);
- exampleList.addExample("Alone - 200x50", pButton);
- }
-
- private void addButtonAlone10x10(ExampleList exampleList) {
- JButton button = new JButton("Button");
- button.setPreferredSize(new Dimension(10, 10));
- PSwing pButton = new PSwing(button);
- exampleList.addExample("Alone - 10x10", pButton);
- }
-
- private void addButtonOnPanelNoSizing(ExampleList exampleList) {
- JButton button = new JButton("Button");
- JPanel panel = new JPanel();
- panel.add(button);
- PSwing pPanel = new PSwing(panel);
-
- exampleList.addExample("On JPanel - No Sizing", pPanel);
- }
-
- private void addButtonOnPanel200x50(ExampleList exampleList) {
- JButton button = new JButton("Button");
- button.setPreferredSize(new Dimension(200, 50));
-
- JPanel panel = new JPanel();
- panel.add(button);
- PSwing pPanel = new PSwing(panel);
-
- exampleList.addExample("On JPanel - 200x50", pPanel);
- }
-
- public static void main(final String[] args) {
- new PSwingExample3().setVisible(true);
- }
-
- class ExampleGrid extends PNode {
- private int columns;
-
- public ExampleGrid(int columns) {
- this.columns = columns;
- }
-
- public void layoutChildren() {
- double[] colWidths = calculateColumnWidths();
-
- double currentY = 0;
- for (int i = 0; i < getChildrenCount(); i++) {
- PNode child = getChild(i);
- child.setOffset(colWidths[i % columns] * 1.25, currentY * 1.25);
- if (i % columns == 0 && i > 0) {
- currentY = getFullBounds().getHeight();
- }
- }
- }
-
- private double[] calculateColumnWidths() {
- double[] colWidths = new double[columns];
- for (int i = 0; i < getChildrenCount(); i++) {
- PNode child = getChild(i);
- colWidths[i % columns] = Math.max(colWidths[i % columns], child.getFullBounds().getWidth()
- * child.getScale());
- }
- return colWidths;
- }
- }
-
- class ExampleList extends PText {
- ExampleList(String name) {
- super(name);
- setScale(2);
- }
-
- public void layoutChildren() {
- PNode node;
- double currentY = getHeight();
- for (int i = 0; i < getChildrenCount(); i++) {
- node = getChild(i);
- node.setOffset(0, currentY);
- currentY += node.getFullBounds().getHeight() + 5;
- }
- }
-
- public void addExample(String name, PNode example) {
- ExampleNode exampleNode = new ExampleNode(name, example);
- exampleNode.setScale(0.5);
- addChild(exampleNode);
- }
-
- public void addExample(String name, JComponent example) {
- addExample(name, new PSwing(example));
- }
-
- class ExampleNode extends PText {
- ExampleNode(String name, PNode example) {
- super(name);
-
- addChild(example);
- }
-
- public void layoutChildren() {
- PNode example = getChild(0);
- example.setOffset(getWidth() + 5, 0);
- // example.setScale(getHeight() / example.getHeight());
- }
- }
- }
-}
diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingMemoryLeakExample.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingMemoryLeakExample.java
deleted file mode 100644
index d1818d1..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/examples/pswing/PSwingMemoryLeakExample.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.examples.pswing;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.SwingUtilities;
-import javax.swing.Timer;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.extras.pswing.PSwing;
-import org.piccolo2d.extras.pswing.PSwingCanvas;
-import org.piccolo2d.nodes.PText;
-
-
-/**
- * Attempt to replicate the PSwingRepaintManager-related memory leak reported in
- * Issue 74.
- */
-public final class PSwingMemoryLeakExample extends JFrame {
-
- /** Default serial version UID. */
- private static final long serialVersionUID = 1L;
-
- /** Active instances. */
- private final PText active;
-
- /** Finalized instances. */
- private final PText finalized;
-
- /** Free memory. */
- private final PText freeMemory;
-
- /** Total memory. */
- private final PText totalMemory;
-
- /** Used memory. */
- private final PText usedMemory;
-
- /** Canvas. */
- private final PCanvas canvas;
-
- /** Main panel, container for PSwingCanvases. */
- private final JPanel mainPanel;
-
- /**
- * Create a new PSwing memory leak example.
- */
- public PSwingMemoryLeakExample() {
- super("PSwing memory leak example");
-
- final PText label0 = new PText("Number of active PSwingCanvases:");
- active = new PText("0");
- final PText label4 = new PText("Number of finalized PSwingCanvases:");
- finalized = new PText("0");
- final PText label1 = new PText("Total memory:");
- totalMemory = new PText("0");
- final PText label2 = new PText("Free memory:");
- freeMemory = new PText("0");
- final PText label3 = new PText("Used memory:");
- usedMemory = new PText("0");
-
- label0.offset(20.0d, 20.0d);
- active.offset(label0.getFullBounds().getWidth() + 50.0d, 20.0d);
- label4.offset(20.0d, 40.0d);
- finalized.offset(label4.getFullBounds().getWidth() + 50.0d, 40.0d);
- label1.offset(20.0d, 60.0d);
- totalMemory.offset(label1.getFullBounds().getWidth() + 40.0d, 60.0d);
- label2.offset(20.0d, 80.0d);
- freeMemory.offset(label2.getFullBounds().getWidth() + 40.0d, 80.0d);
- label3.offset(freeMemory.getFullBounds().getX() + 80.0d, 80.0d);
- usedMemory.offset(label3.getFullBounds().getX() + label3.getFullBounds().getWidth() + 20.0d, 80.0d);
-
- canvas = new PCanvas();
- canvas.getCamera().addChild(label0);
- canvas.getCamera().addChild(active);
- canvas.getCamera().addChild(label4);
- canvas.getCamera().addChild(finalized);
- canvas.getCamera().addChild(label1);
- canvas.getCamera().addChild(totalMemory);
- canvas.getCamera().addChild(label2);
- canvas.getCamera().addChild(freeMemory);
- canvas.getCamera().addChild(label3);
- canvas.getCamera().addChild(usedMemory);
- canvas.setPreferredSize(new Dimension(400, 110));
-
- mainPanel = new JPanel();
- mainPanel.setPreferredSize(new Dimension(400, 290));
- mainPanel.setLayout(new FlowLayout());
-
- getContentPane().setLayout(new BorderLayout());
- getContentPane().add("North", canvas);
- getContentPane().add("Center", mainPanel);
-
- final Timer add = new Timer(10, new ActionListener() {
- int id = 0;
-
- /** {@inheritDoc} */
- public void actionPerformed(final ActionEvent e) {
- final JLabel label = new JLabel("Label" + id);
- final PSwing pswing = new PSwing(label);
- final PSwingCanvas pswingCanvas = new PSwingCanvas() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /** {@inheritDoc} */
- public void finalize() {
- incrementFinalized();
- }
- };
- pswingCanvas.getLayer().addChild(pswing);
- pswingCanvas.setPreferredSize(new Dimension(60, 18));
- mainPanel.add(pswingCanvas);
- mainPanel.invalidate();
- mainPanel.validate();
- mainPanel.repaint();
-
- id++;
- incrementActive();
- }
- });
- add.setDelay(5);
- add.setRepeats(true);
-
- final Timer remove = new Timer(20000, new ActionListener() {
- /** {@inheritDoc} */
- public void actionPerformed(final ActionEvent e) {
- if (add.isRunning()) {
- add.stop();
- }
- final int i = mainPanel.getComponentCount() - 1;
- if (i > 0) {
- mainPanel.remove(mainPanel.getComponentCount() - 1);
- mainPanel.invalidate();
- mainPanel.validate();
- mainPanel.repaint();
- decrementActive();
- }
- }
- });
- remove.setDelay(5);
- remove.setRepeats(true);
-
- final Timer updateMemory = new Timer(500, new ActionListener() {
- /** {@inheritDoc} */
- public void actionPerformed(final ActionEvent e) {
- updateMemory();
- }
- });
- updateMemory.setDelay(2000);
- updateMemory.setRepeats(true);
-
- add.start();
- remove.start();
- updateMemory.start();
-
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setBounds(100, 100, 400, 400);
- setVisible(true);
- }
-
- /**
- * Increment active.
- */
- private void incrementActive() {
- int count = Integer.parseInt(active.getText());
- count++;
- active.setText(String.valueOf(count));
- canvas.repaint();
- }
-
- /**
- * Decrement active.
- */
- private void decrementActive() {
- int count = Integer.parseInt(active.getText());
- count--;
- active.setText(String.valueOf(count));
- canvas.repaint();
- }
-
- /**
- * Increment finalized.
- */
- private void incrementFinalized() {
- int count = Integer.parseInt(finalized.getText());
- count++;
- finalized.setText(String.valueOf(count));
- canvas.repaint();
- }
-
- /**
- * Update memory.
- */
- private void updateMemory() {
- new Thread(new Runnable() {
- /** {@inheritDoc} */
- public void run() {
- System.gc();
- System.runFinalization();
- }
- }).run();
-
- final long total = Runtime.getRuntime().totalMemory();
- totalMemory.setText(String.valueOf(total));
- final long free = Runtime.getRuntime().freeMemory();
- freeMemory.setText(String.valueOf(free));
- final long used = total - free;
- usedMemory.setText(String.valueOf(used));
- canvas.repaint();
- }
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- /** {@inheritDoc} */
- public void run() {
- new PSwingMemoryLeakExample();
- }
- });
- }
-}
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
deleted file mode 100644
index ffa396a..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PDragEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PImage;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.nodes.PText;
-import org.piccolo2d.util.PBounds;
-import org.piccolo2d.util.PPaintContext;
-
-
-public class InterfaceFrame extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- 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.
- final PNode aNode = new PNode();
-
- // A node will not be visible until its bounds and brush are set.
- aNode.setBounds(0, 0, 100, 80);
- aNode.setPaint(Color.RED);
-
- // A node needs to be a descendent of the root to be displayed.
- final PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
-
- // A node can have child nodes added to it.
- final 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);
-
- // 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.
- final PImage image = new PImage(layer.toImage(300, 300, null));
- layer.addChild(image);
-
- // Create a New Node using Composition
-
- final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // Create parts for the face.
- final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- final PNode eye2 = (PNode) eye1.clone();
- final 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.
- final 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.
- final ToggleShape ts = new ToggleShape();
- ts.setPaint(Color.ORANGE);
- layer.addChild(ts);
- }
-
- class ToggleShape extends PPath {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private boolean fIsPressed = false;
-
- public ToggleShape() {
- setPathToEllipse(0, 0, 100, 80);
-
- addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(final PInputEvent event) {
- super.mousePressed(event);
- fIsPressed = true;
- repaint();
- }
-
- public void mouseReleased(final PInputEvent event) {
- super.mouseReleased(event);
- fIsPressed = false;
- repaint();
- }
- });
- }
-
- protected void paint(final PPaintContext paintContext) {
- if (fIsPressed) {
- final Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- }
- else {
- super.paint(paintContext);
- }
- }
- }
-
- public static void main(final 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
deleted file mode 100644
index ce56815..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-import java.awt.event.KeyEvent;
-import java.awt.geom.AffineTransform;
-import java.io.File;
-import java.util.ArrayList;
-
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PImage;
-
-
-public class PiccoloPresentation extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- protected PNode slideBar;
- protected PNode currentSlide;
- protected PBasicInputEventHandler eventHandler;
- protected ArrayList slides = new ArrayList();
-
- public PiccoloPresentation() {
- super();
- }
-
- public void initialize() {
- setFullScreenMode(true);
- loadSlides();
-
- eventHandler = new PBasicInputEventHandler() {
- public void keyReleased(final PInputEvent event) {
- if (event.getKeyCode() == KeyEvent.VK_SPACE) {
- final int newIndex = slides.indexOf(currentSlide) + 1;
- if (newIndex < slides.size()) {
- goToSlide((PNode) slides.get(newIndex));
- }
- }
- }
-
- public void mouseReleased(final PInputEvent event) {
- final PNode picked = event.getPickedNode();
-
- 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());
- }
-
- public void goToSlide(final 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);
-
- final 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(final 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
deleted file mode 100644
index 006e844..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-
-import org.piccolo2d.PLayer;
-import org.piccolo2d.PNode;
-import org.piccolo2d.activities.PActivity;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-
-
-public class SpecialEffects extends PFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- 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);
- final PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
- aNode.setOffset(200, 200);
-
- // Extend PActivity.
-
- // Store the current time in milliseconds for use below.
- final long currentTime = System.currentTimeMillis();
-
- // 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.
- final PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(final 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.
- final PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- final PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- final 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(final PActivity activity) {
- System.out.println("a1 started");
- }
-
- public void activityStepped(final PActivity activity) {
- }
-
- public void activityFinished(final PActivity activity) {
- System.out.println("a1 finished");
- }
- });
- }
-
- public static void main(final 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
deleted file mode 100644
index 7b8d5e2..0000000
--- a/examples/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.geom.Point2D;
-
-import org.piccolo2d.PCanvas;
-import org.piccolo2d.PNode;
-import org.piccolo2d.event.PBasicInputEventHandler;
-import org.piccolo2d.event.PDragSequenceEventHandler;
-import org.piccolo2d.event.PInputEvent;
-import org.piccolo2d.event.PInputEventFilter;
-import org.piccolo2d.extras.PFrame;
-import org.piccolo2d.nodes.PPath;
-import org.piccolo2d.util.PDimension;
-
-
-public class UserInteraction extends PFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public UserInteraction() {
- super();
- }
-
- 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);
-
- // Create a squiggle handler and register it with the Canvas.
- final PBasicInputEventHandler squiggleHandler = new SquiggleHandler(getCanvas());
- getCanvas().addInputEventListener(squiggleHandler);
-
- // Create a Node Event Listener.
-
- // Create a green rectangle node.
- final PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
- nodeGreen.setPaint(Color.GREEN);
- getCanvas().getLayer().addChild(nodeGreen);
-
- // Attach event handler directly to the node.
- nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(final PInputEvent event) {
- event.getPickedNode().setPaint(Color.ORANGE);
- event.getInputManager().setKeyboardFocus(event.getPath());
- event.setHandled(true);
- }
-
- public void mouseDragged(final PInputEvent event) {
- final PNode aNode = event.getPickedNode();
- final PDimension delta = event.getDeltaRelativeTo(aNode);
- aNode.translate(delta.width, delta.height);
- event.setHandled(true);
- }
-
- public void mouseReleased(final PInputEvent event) {
- event.getPickedNode().setPaint(Color.GREEN);
- event.setHandled(true);
- }
-
- public void keyPressed(final PInputEvent event) {
- final 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 class SquiggleHandler extends PDragSequenceEventHandler {
- protected PCanvas canvas;
-
- // The squiggle that is currently getting created.
- protected PPath squiggle;
-
- public SquiggleHandler(final PCanvas aCanvas) {
- canvas = aCanvas;
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- public void startDrag(final PInputEvent e) {
- super.startDrag(e);
-
- final 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(final PInputEvent e) {
- super.drag(e);
- // Update the squiggle while dragging.
- updateSquiggle(e);
- }
-
- public void endDrag(final PInputEvent e) {
- super.endDrag(e);
- // Update the squiggle one last time.
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(final PInputEvent aEvent) {
- // Add a new segment to the squiggle from the last mouse position
- // to the current mouse position.
- final Point2D p = aEvent.getPosition();
- squiggle.lineTo((float) p.getX(), (float) p.getY());
- }
- }
-
- public static void main(final String[] args) {
- new UserInteraction();
- }
-}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ActivityExample.java b/examples/src/main/java/org/piccolo2d/examples/ActivityExample.java
new file mode 100644
index 0000000..f032b99
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ActivityExample.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how create and schedule activities.
+ */
+public class ActivityExample extends PFrame {
+ private static final long serialVersionUID = 1L;
+
+ public ActivityExample() {
+ this(null);
+ }
+
+ public ActivityExample(final PCanvas aCanvas) {
+ super("ActivityExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final 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);
+ final 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.
+ final PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
+ boolean fRed = true;
+
+ protected void activityStep(final 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.
+ final PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
+ final PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
+ final PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
+ final 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(final String[] args) {
+ new ActivityExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/AngleNodeExample.java b/examples/src/main/java/org/piccolo2d/examples/AngleNodeExample.java
new file mode 100644
index 0000000..666e7f0
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/AngleNodeExample.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Stroke;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PHandle;
+import org.piccolo2d.extras.util.PLocator;
+import org.piccolo2d.util.PDimension;
+import org.piccolo2d.util.PPaintContext;
+
+
+/**
+ * This shows how to create a simple node that has two handles and can be used
+ * for specifying angles. The nodes UI desing isn't very exciting, but the
+ * example shows one way to create a custom node with custom handles.
+ */
+public class AngleNodeExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public AngleNodeExample() {
+ this(null);
+ }
+
+ public AngleNodeExample(final PCanvas aCanvas) {
+ super("AngleNodeExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PCanvas c = getCanvas();
+ final PLayer l = c.getLayer();
+ l.addChild(new AngleNode());
+ }
+
+ public static void main(final String[] args) {
+ new AngleNodeExample();
+ }
+
+ // the angle node class
+ public static class AngleNode extends PNode {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ 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() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public double locateX() {
+ return pointOne.getX();
+ }
+
+ public double locateY() {
+ return pointOne.getY();
+ }
+ };
+ PHandle h = new PHandle(l) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void dragHandle(final PDimension aLocalDimension, final PInputEvent aEvent) {
+ localToParent(aLocalDimension);
+ pointOne.setLocation(pointOne.getX() + aLocalDimension.getWidth(), pointOne.getY()
+ + aLocalDimension.getHeight());
+ updateBounds();
+ relocateHandle();
+ }
+ };
+ addChild(h);
+
+ // point two
+ l = new PLocator() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public double locateX() {
+ return pointTwo.getX();
+ }
+
+ public double locateY() {
+ return pointTwo.getY();
+ }
+ };
+ h = new PHandle(l) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void dragHandle(final PDimension aLocalDimension, final PInputEvent aEvent) {
+ localToParent(aLocalDimension);
+ pointTwo.setLocation(pointTwo.getX() + aLocalDimension.getWidth(), pointTwo.getY()
+ + aLocalDimension.getHeight());
+ updateBounds();
+ relocateHandle();
+ }
+ };
+ addChild(h);
+ }
+
+ protected void paint(final PPaintContext paintContext) {
+ final Graphics2D g2 = paintContext.getGraphics();
+ g2.setStroke(stroke);
+ g2.setPaint(getPaint());
+ g2.draw(getAnglePath());
+ }
+
+ protected void updateBounds() {
+ final GeneralPath p = getAnglePath();
+ final Rectangle2D b = stroke.createStrokedShape(p).getBounds2D();
+ super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
+ }
+
+ public GeneralPath getAnglePath() {
+ final 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(final double x, final double y, final double width, final double height) {
+ return false; // bounds can be set externally
+ }
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/BirdsEyeViewExample.java b/examples/src/main/java/org/piccolo2d/examples/BirdsEyeViewExample.java
new file mode 100644
index 0000000..1603543
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/BirdsEyeViewExample.java
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JDialog;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PDragEventHandler;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.P3DRect;
+import org.piccolo2d.nodes.PImage;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PDimension;
+import org.piccolo2d.util.PPaintContext;
+
+
+/**
+ * This example, contributed by Rowan Christmas, shows how to create a birds-eye
+ * view window.
+ */
+public class BirdsEyeViewExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ boolean fIsPressed = false;
+
+ public BirdsEyeViewExample() {
+ this(null);
+ }
+
+ public BirdsEyeViewExample(final PCanvas aCanvas) {
+ super("BirdsEyeViewExample", 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 will create the actual BirdsEyeView and put it in a JDialog
+ final BirdsEyeView bev = new BirdsEyeView();
+ bev.connect(getCanvas(), new PLayer[] { getCanvas().getLayer() });
+ final 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() {
+ final PLayer layer = getCanvas().getLayer();
+ final 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.
+ final 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() {
+ final 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)));
+ }
+
+ // 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)) {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void paint(final PPaintContext aPaintContext) {
+ if (fIsPressed) {
+ // if mouse is pressed draw self as a square.
+ final 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(final PInputEvent aEvent) {
+ super.mousePressed(aEvent);
+ fIsPressed = true;
+ n.invalidatePaint(); // this tells the framework that the node
+ // needs to be redisplayed.
+ }
+
+ public void mouseReleased(final 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() {
+ final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
+
+ // create parts for the face.
+ final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
+ eye1.setPaint(Color.YELLOW);
+ final PNode eye2 = (PNode) eye1.clone();
+ final 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.
+ final 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() {
+ final PNode n = new PNode() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void paint(final PPaintContext aPaintContext) {
+ final double bx = getX();
+ final double by = getY();
+ final double rightBorder = bx + getWidth();
+ final double bottomBorder = by + getHeight();
+
+ final Line2D line = new Line2D.Double();
+ final 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(final String[] args) {
+ new BirdsEyeViewExample();
+ }
+
+ /**
+ * The Birds Eye View Class
+ */
+ public class BirdsEyeView extends PCanvas implements PropertyChangeListener {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * This is the node that shows the viewed area.
+ */
+ PNode areaVisiblePNode;
+
+ /**
+ * This is the canvas that is being viewed
+ */
+ PCanvas viewedCanvas;
+
+ /**
+ * The change listener to know when to update the birds eye view.
+ */
+ PropertyChangeListener changeListener;
+
+ int layerCount;
+
+ /**
+ * Creates a new instance of a BirdsEyeView
+ */
+ public BirdsEyeView() {
+
+ // create the PropertyChangeListener for listening to the viewed
+ // canvas
+ changeListener = new PropertyChangeListener() {
+ public void propertyChange(final 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);
+
+ // add the drag event handler
+ getCamera().addInputEventListener(new PDragSequenceEventHandler() {
+ protected void startDrag(final PInputEvent e) {
+ if (e.getPickedNode() == areaVisiblePNode) {
+ super.startDrag(e);
+ }
+ }
+
+ protected void drag(final PInputEvent e) {
+ final PDimension dim = e.getDelta();
+ viewedCanvas.getCamera().translateView(0 - dim.getWidth(), 0 - dim.getHeight());
+ }
+
+ });
+
+ // remove Pan and Zoom
+ removeInputEventListener(getPanEventHandler());
+ removeInputEventListener(getZoomEventHandler());
+
+ setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
+
+ }
+
+ public void connect(final PCanvas canvas, final PLayer[] viewed_layers) {
+
+ viewedCanvas = canvas;
+ layerCount = 0;
+
+ viewedCanvas.getCamera().addPropertyChangeListener(changeListener);
+
+ 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(final PLayer new_layer) {
+ getCamera().addLayer(new_layer);
+ layerCount++;
+ }
+
+ /**
+ * Remove the layer from the viewed layers
+ */
+ public void removeLayer(final 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);
+
+ for (int i = 0; i < getCamera().getLayerCount(); ++i) {
+ getCamera().removeLayer(i);
+ }
+
+ }
+
+ /**
+ * This method will get called when the viewed canvas changes
+ */
+ public void propertyChange(final 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() {
+
+ double viewedX;
+ double viewedY;
+ double viewedHeight;
+ double viewedWidth;
+
+ final double ul_camera_x = viewedCanvas.getCamera().getViewBounds().getX();
+ final double ul_camera_y = viewedCanvas.getCamera().getViewBounds().getY();
+ final double lr_camera_x = ul_camera_x + viewedCanvas.getCamera().getViewBounds().getWidth();
+ final double lr_camera_y = ul_camera_y + viewedCanvas.getCamera().getViewBounds().getHeight();
+
+ final Rectangle2D drag_bounds = getCamera().getUnionOfLayerFullBounds();
+
+ final double ul_layer_x = drag_bounds.getX();
+ final double ul_layer_y = drag_bounds.getY();
+ final double lr_layer_x = drag_bounds.getX() + drag_bounds.getWidth();
+ final double lr_layer_y = drag_bounds.getY() + drag_bounds.getHeight();
+
+ // 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;
+ }
+
+ // same for y
+ if (ul_camera_y < ul_layer_y) {
+ viewedY = ul_layer_y;
+ }
+ else {
+ viewedY = ul_camera_y;
+ }
+
+ // 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;
+ }
+
+ // 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);
+
+ // keep the birds eye view centered
+ getCamera().animateViewToCenterBounds(drag_bounds, true, 0);
+
+ }
+
+ } // class BirdsEyeView
+
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/CameraExample.java b/examples/src/main/java/org/piccolo2d/examples/CameraExample.java
new file mode 100644
index 0000000..3baf091
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/CameraExample.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PBoundsHandle;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how to create internal cameras
+ */
+public class CameraExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public CameraExample() {
+ this(null);
+ }
+
+ public CameraExample(final PCanvas aCanvas) {
+ super("CameraExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PLayer l = new PLayer();
+ final 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);
+
+ final 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(final String[] args) {
+ new CameraExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/CenterExample.java b/examples/src/main/java/org/piccolo2d/examples/CenterExample.java
new file mode 100644
index 0000000..e184148
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/CenterExample.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+public class CenterExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public CenterExample() {
+ this(null);
+ }
+
+ public CenterExample(final PCanvas aCanvas) {
+ super("CenterExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PCanvas c = getCanvas();
+ final PLayer l = c.getLayer();
+ final PCamera cam = c.getCamera();
+
+ cam.scaleView(2.0);
+ final 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(final String[] args) {
+ new CenterExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ChartLabelExample.java b/examples/src/main/java/org/piccolo2d/examples/ChartLabelExample.java
new file mode 100644
index 0000000..b5a3339
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ChartLabelExample.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+import java.awt.geom.Point2D;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * This example shows how to create a vertical and a horizontal bar which can
+ * move with your graph and always stays on view.
+ *
+ * @author Tao
+ */
+public class ChartLabelExample extends PFrame {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ final int nodeHeight = 15;
+ final int nodeWidth = 30;
+
+ // Row Bar
+ PLayer rowBarLayer;
+
+ // Colume Bar
+ PLayer colBarLayer;
+
+ public ChartLabelExample() {
+ this(null);
+ }
+
+ public ChartLabelExample(final PCanvas aCanvas) {
+ super("ChartLabelExample", false, aCanvas);
+ }
+
+ 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 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);
+
+ // create matrix nodes
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ final 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;
+
+ public void mousePressed(final PInputEvent aEvent) {
+ oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
+ }
+
+ public void mouseReleased(final 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(final String[] args) {
+ new ChartLabelExample();
+ }
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/ClipExample.java b/examples/src/main/java/org/piccolo2d/examples/ClipExample.java
new file mode 100644
index 0000000..7859632
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ClipExample.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.event.PDragEventHandler;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.PClip;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * Quick example of how to use a clip.
+ */
+public class ClipExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public ClipExample() {
+ this(null);
+ }
+
+ public ClipExample(final PCanvas aCanvas) {
+ super("ClipExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final 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(final String[] args) {
+ new ClipExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/CompositeExample.java b/examples/src/main/java/org/piccolo2d/examples/CompositeExample.java
new file mode 100644
index 0000000..083c986
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/CompositeExample.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PDragEventHandler;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.PComposite;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * 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 {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public CompositeExample() {
+ this(null);
+ }
+
+ public CompositeExample(final PCanvas aCanvas) {
+ super("CompositeExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PComposite composite = new PComposite();
+
+ final PNode circle = PPath.createEllipse(0, 0, 100, 100);
+ final PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
+ final 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(final String[] args) {
+ new CompositeExample();
+ }
+
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/DynamicExample.java b/examples/src/main/java/org/piccolo2d/examples/DynamicExample.java
new file mode 100644
index 0000000..e84e74b
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/DynamicExample.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.PRoot;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.util.PFixedWidthStroke;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * 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 {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public DynamicExample() {
+ this(null);
+ }
+
+ public DynamicExample(final PCanvas aCanvas) {
+ super("DynamicExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PLayer layer = getCanvas().getLayer();
+ final PRoot root = getCanvas().getRoot();
+ final 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);
+ final PActivity a = new PActivity(-1, 20) {
+ public void activityStep(final long currentTime) {
+ super.activityStep(currentTime);
+ rotateNodes();
+ }
+ };
+ root.addActivity(a);
+
+ final PPath p = new PPath();
+ p.moveTo(0, 0);
+ p.lineTo(0, 1000);
+ final 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() {
+ final Iterator i = getCanvas().getLayer().getChildrenReference().iterator();
+ while (i.hasNext()) {
+ final PNode each = (PNode) i.next();
+ each.rotate(Math.toRadians(2));
+ }
+ }
+
+ public static void main(final String[] args) {
+ new DynamicExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/EventHandlerExample.java b/examples/src/main/java/org/piccolo2d/examples/EventHandlerExample.java
new file mode 100644
index 0000000..a83c1a5
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/EventHandlerExample.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.event.InputEvent;
+import java.awt.geom.Point2D;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.event.PInputEventFilter;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PBounds;
+
+
+/**
+ * This example shows how to create and install a custom event listener that
+ * draws rectangles.
+ */
+public class EventHandlerExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public EventHandlerExample() {
+ this(null);
+ }
+
+ public EventHandlerExample(final 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.
+ final 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(final PInputEvent e) {
+ super.mousePressed(e);
+
+ final 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(final PInputEvent e) {
+ super.mouseDragged(e);
+ // update the drag point location.
+ dragPoint = e.getPosition();
+
+ // update the rectangle shape.
+ updateRectangle();
+ }
+
+ public void mouseReleased(final 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.
+ final PBounds b = new PBounds();
+ b.add(pressPoint);
+ b.add(dragPoint);
+
+ // Set the rectangles bounds.
+ rectangle.setPathTo(b);
+ }
+ };
+ }
+
+ public static void main(final String[] args) {
+ new EventHandlerExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ExampleRunner.java b/examples/src/main/java/org/piccolo2d/examples/ExampleRunner.java
new file mode 100644
index 0000000..99056b9
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ExampleRunner.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.WindowConstants;
+import javax.swing.border.TitledBorder;
+
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.util.PDebug;
+
+
+public class ExampleRunner extends JFrame {
+ private static final long serialVersionUID = 1L;
+
+ public ExampleRunner() {
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("Piccolo Example Runner");
+ setSize(650, 600);
+ getContentPane().setLayout(new BorderLayout());
+ createExampleButtons();
+
+ getContentPane().setBackground(new Color(200, 200, 200));
+ validate();
+ setVisible(true);
+ }
+
+ public void createExampleButtons() {
+ final Container c = getContentPane();
+
+ c.add(buildOptions(), BorderLayout.NORTH);
+ JPanel panel= new JPanel(new GridLayout(0, 2));
+ c.add(BorderLayout.CENTER, panel);
+
+ addExampleButtons(panel, new Class[] { ActivityExample.class, AngleNodeExample.class,
+ BirdsEyeViewExample.class, CameraExample.class, CenterExample.class, ChartLabelExample.class,
+ ClipExample.class, CompositeExample.class, DynamicExample.class, EventHandlerExample.class,
+ FullScreenNodeExample.class, GraphEditorExample.class, GridExample.class, GroupExample.class,
+ HandleExample.class, HelloWorldExample.class, HierarchyZoomExample.class, HtmlViewExample.class,
+ KeyEventFocusExample.class, LayoutExample.class, LensExample.class, NavigationExample.class,
+ NodeCacheExample.class, NodeEventExample.class, NodeExample.class, NodeLinkExample.class,
+ P3DRectExample.class, PanToExample.class, PathExample.class, PositionExample.class,
+ PositionPathActivityExample.class, PulseExample.class, ScrollingExample.class, SelectionExample.class,
+ ShadowExample.class, SquiggleExample.class, StickyExample.class, StickyHandleLayerExample.class,
+ StrokeExample.class, TextExample.class, TooltipExample.class, TwoCanvasExample.class,
+ WaitForActivitiesExample.class });
+ }
+
+ /**
+ * @param c
+ */
+ private JPanel buildOptions() {
+ JPanel optionsPanel = new JPanel(new GridLayout(3, 1));
+ optionsPanel.setBorder(new TitledBorder("Display Options"));
+
+ optionsPanel.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") {
+ public void actionPerformed(final ActionEvent e) {
+ PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate;
+ }
+ }));
+
+ optionsPanel.add(new JCheckBox(new AbstractAction("Show Region Managment") {
+ public void actionPerformed(final ActionEvent e) {
+ PDebug.debugRegionManagement = !PDebug.debugRegionManagement;
+ }
+ }));
+
+ optionsPanel.add(new JCheckBox(new AbstractAction("Show Full Bounds") {
+ public void actionPerformed(final ActionEvent e) {
+ PDebug.debugFullBounds = !PDebug.debugFullBounds;
+ }
+ }));
+
+ return optionsPanel;
+ }
+
+ private void addExampleButtons(final JPanel panel, final Class[] exampleClasses) {
+ for (int i = 0; i < exampleClasses.length; i++) {
+ panel.add(buildExampleButton(exampleClasses[i]));
+ }
+ }
+
+ private JButton buildExampleButton(final Class exampleClass) {
+ final String fullClassName = exampleClass.getName();
+ final String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
+ final String exampleLabel = camelToProper(simpleClassName);
+ JButton button = new JButton(new AbstractAction(exampleLabel) {
+ public void actionPerformed(final ActionEvent event) {
+ try {
+ final PFrame example = (PFrame) exampleClass.newInstance();
+ example.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ }
+ catch (final Exception e) {
+ JOptionPane.showMessageDialog(ExampleRunner.this,
+ "A problem was encountered running the example.\n\n" + e.getMessage());
+ }
+ }
+ });
+ button.setBackground(Color.WHITE);
+ button.setHorizontalAlignment(JButton.LEFT);
+ return button;
+ }
+
+ private String camelToProper(String camel) {
+ Pattern pattern = Pattern.compile("[a-z]([A-Z])");
+ Matcher matcher = pattern.matcher(camel);
+ StringBuffer result = new StringBuffer();
+ int lastIndex = 0;
+ while (matcher.find()) {
+ int nextWord = matcher.start(1);
+ result.append(camel.substring(lastIndex, nextWord));
+ result.append(' ');
+ lastIndex = nextWord;
+ }
+ result.append(camel.substring(lastIndex, camel.length()));
+ return result.toString();
+ }
+
+ public static void main(final String[] args) {
+ new ExampleRunner();
+ }
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/FrameCanvasSizeBugExample.java b/examples/src/main/java/org/piccolo2d/examples/FrameCanvasSizeBugExample.java
new file mode 100644
index 0000000..146a7cb
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/FrameCanvasSizeBugExample.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PText;
+
+
+
+/**
+ * This example demonstrates a bug with setting the size
+ * of a PFrame. See http://code.google.com/p/piccolo2d/issues/detail?id=141.
+ */
+public class FrameCanvasSizeBugExample
+ extends PFrame {
+
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * Create a new frame canvas size bug example.
+ */
+ public FrameCanvasSizeBugExample() {
+ this(null);
+ }
+
+ /**
+ * Create a new frame canvas size bug example for the specified canvas.
+ *
+ * @param canvas canvas for this frame canvas size bug example
+ */
+ public FrameCanvasSizeBugExample(final PCanvas canvas) {
+ super("FrameCanvasSizeBugExample", false, canvas);
+ //setSize(410, 410);
+ //getCanvas().setSize(410, 410); does not help
+ }
+
+
+ /** {@inheritDoc} */
+ public void initialize() {
+ PText label = new PText("Note white at border S and E\nIt goes away when frame is resized");
+ label.setOffset(200, 340);
+ getCanvas().getLayer().addChild(label);
+ getCanvas().setBackground(Color.PINK);
+ getCanvas().setOpaque(true);
+ setSize(410, 410);
+ //getCanvas().setSize(410, 410); does not help
+ }
+
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ new FrameCanvasSizeBugExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/FullScreenNodeExample.java b/examples/src/main/java/org/piccolo2d/examples/FullScreenNodeExample.java
new file mode 100644
index 0000000..77658ce
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/FullScreenNodeExample.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+public class FullScreenNodeExample extends NodeExample {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void initialize() {
+ super.initialize();
+ setFullScreenMode(true);
+ }
+
+ public static void main(final String[] args) {
+ new FullScreenNodeExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/GraphEditorExample.java b/examples/src/main/java/org/piccolo2d/examples/GraphEditorExample.java
new file mode 100644
index 0000000..c97ab27
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/GraphEditorExample.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.Random;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * 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 {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public GraphEditorExample() {
+ this(null);
+ }
+
+ public GraphEditorExample(final PCanvas aCanvas) {
+ super("GraphEditorExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final int numNodes = 50;
+ final int numEdges = 50;
+
+ // Initialize, and create a layer for the edges (always underneath the
+ // nodes)
+ final PLayer nodeLayer = getCanvas().getLayer();
+ final PLayer edgeLayer = new PLayer();
+ getCanvas().getCamera().addLayer(0, edgeLayer);
+ final Random rnd = new Random();
+ ArrayList tmp;
+ for (int i = 0; i < numNodes; i++) {
+ final float x = (float) (300. * rnd.nextDouble());
+ final float y = (float) (400. * rnd.nextDouble());
+ final 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++) {
+ final int n1 = rnd.nextInt(numNodes);
+ final int n2 = rnd.nextInt(numNodes);
+ final PNode node1 = nodeLayer.getChild(n1);
+ final PNode node2 = nodeLayer.getChild(n2);
+
+ final Point2D.Double bound1 = (Point2D.Double) node1.getBounds().getCenter2D();
+ final Point2D.Double bound2 = (Point2D.Double) node2.getBounds().getCenter2D();
+
+ final 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 = new ArrayList();
+ tmp.add(node1);
+ tmp.add(node2);
+ edge.addAttribute("nodes", tmp);
+
+ edgeLayer.addChild(edge);
+ }
+
+ // Create event handler to move nodes and update edges
+ nodeLayer.addInputEventListener(new NodeDragHandler());
+ }
+
+ public static void main(final String[] args) {
+ new GraphEditorExample();
+ }
+
+ // TODO eclipse formatter made this ugly
+ // / "); + html.append("This is an example of what can be done with PHtml."); + html.append("
"); + html.append("It supports:
"); + appendFeatures(); + + final PHtmlView htmlNode = new PHtmlView(html.toString()); + htmlNode.setBounds(0, 0, 400, 400); + getCanvas().getLayer().addChild(htmlNode); + + getCanvas().addInputEventListener(new PBasicInputEventHandler() { + public void mouseClicked(final PInputEvent event) { + final PNode clickedNode = event.getPickedNode(); + if (!(clickedNode instanceof PHtmlView)) { + return; + } + + final Point2D clickPoint = event.getPositionRelativeTo(clickedNode); + final PHtmlView htmlNode = (PHtmlView) clickedNode; + + final String url = htmlNode.getLinkAddressAt(clickPoint.getX(), clickPoint.getY()); + JOptionPane.showMessageDialog(null, url); + } + }); + } + + private void appendFeatures() { + html.append("Col 1 | Col 2 |
---|---|
Col 1 val | Col 2 val |
offset(double, double)
and
+ * translate(double, double)
.
+ *
+ * @see PNode#offset(double, double)
+ * @see PNode#translate(double, double)
+ */
+public class OffsetVsTranslateExample
+ extends PFrame {
+
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * Create a new offset vs. translate example.
+ */
+ public OffsetVsTranslateExample() {
+ this(null);
+ }
+
+ /**
+ * Create a new offset vs. translate example for the specified canvas.
+ *
+ * @param canvas canvas for this offset vs. translate example
+ */
+ public OffsetVsTranslateExample(final PCanvas canvas) {
+ super("OffsetVsTranslateExample", false, canvas);
+ }
+
+
+ /** {@inheritDoc} */
+ public void initialize() {
+ final PText offset = new PText("Offset node");
+ final PText offsetRotated = new PText("Offset rotated node");
+ final PText translate = new PText("Translated node");
+ final PText translateRotated = new PText("Translated rotated node");
+
+ offset.setScale(2.0d);
+ offsetRotated.setScale(2.0d);
+ translate.setScale(2.0d);
+ translateRotated.setScale(2.0d);
+
+ offsetRotated.setRotation(Math.PI / 8.0d);
+ translateRotated.setRotation(Math.PI / 8.0d);
+ offset.setOffset(15.0d, 100.0d);
+ offsetRotated.setOffset(15.0d, 150.0d);
+ translate.setOffset(15.0d, 200.0d);
+ translateRotated.setOffset(15.0d, 250.0d);
+
+ getCanvas().getLayer().addChild(offset);
+ getCanvas().getLayer().addChild(offsetRotated);
+ getCanvas().getLayer().addChild(translate);
+ getCanvas().getLayer().addChild(translateRotated);
+
+ offset.addActivity(new PActivity(-1L) {
+ /** {@inheritDoc} */
+ protected void activityStep(final long elapsedTime) {
+ offset.offset(1.0d, 0.0d);
+ }
+ });
+ offsetRotated.addActivity(new PActivity(-1L) {
+ /** {@inheritDoc} */
+ protected void activityStep(final long elapsedTime) {
+ offsetRotated.offset(1.0d, 0.0d);
+ }
+ });
+ translate.addActivity(new PActivity(-1L) {
+ /** {@inheritDoc} */
+ protected void activityStep(final long elapsedTime) {
+ translate.translate(1.0d, 0.0d);
+ }
+ });
+ translateRotated.addActivity(new PActivity(-1L) {
+ /** {@inheritDoc} */
+ protected void activityStep(final long elapsedTime) {
+ translateRotated.translate(1.0d, 0.0d);
+ }
+ });
+ }
+
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ new OffsetVsTranslateExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/P3DRectExample.java b/examples/src/main/java/org/piccolo2d/examples/P3DRectExample.java
new file mode 100644
index 0000000..bb06fbb
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/P3DRectExample.java
@@ -0,0 +1,36 @@
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.P3DRect;
+
+
+public class P3DRectExample extends PFrame {
+
+ public P3DRectExample() {
+ this(null);
+ }
+
+ public P3DRectExample(final PCanvas aCanvas) {
+ super("P3DRect Example", false, aCanvas);
+ }
+
+ public void initialize() {
+ final P3DRect rect1 = new P3DRect(50, 50, 100, 100);
+ rect1.setPaint(new Color(239, 235, 222));
+ getCanvas().getLayer().addChild(rect1);
+
+ final P3DRect rect2 = new P3DRect(50, 50, 100, 100);
+ rect2.setPaint(new Color(239, 235, 222));
+ rect2.translate(110, 0);
+ rect2.setRaised(false);
+ getCanvas().getLayer().addChild(rect2);
+ }
+
+ public static void main(String[] args) {
+ new P3DRectExample();
+ }
+
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PSwingExample.java b/examples/src/main/java/org/piccolo2d/examples/PSwingExample.java
new file mode 100644
index 0000000..984cf18
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PSwingExample.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import javax.swing.BorderFactory;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+
+
+/**
+ * Demonstrates the use of PSwing in a Piccolo application.
+ */
+
+public class PSwingExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PSwingExample() {
+ this(new PSwingCanvas());
+ }
+
+ public PSwingExample(final PCanvas aCanvas) {
+ super("PSwingExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PSwingCanvas pswingCanvas = (PSwingCanvas) getCanvas();
+ final PLayer l = pswingCanvas.getLayer();
+
+ final JSlider js = new JSlider(0, 100);
+ js.addChangeListener(new ChangeListener() {
+ public void stateChanged(final ChangeEvent e) {
+ System.out.println("e = " + e);
+ }
+ });
+ js.setBorder(BorderFactory.createTitledBorder("Test JSlider"));
+ final PSwing pSwing = new PSwing(js);
+ pSwing.translate(100, 100);
+ l.addChild(pSwing);
+
+ pswingCanvas.setPanEventHandler(null);
+ }
+
+ public static void main(final String[] args) {
+ new PSwingExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PanToExample.java b/examples/src/main/java/org/piccolo2d/examples/PanToExample.java
new file mode 100644
index 0000000..01a76fe
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PanToExample.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.util.Random;
+
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * 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 {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PanToExample() {
+ this(null);
+ }
+
+ public PanToExample(final 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);
+
+ eacha = PPath.createRectangle(350, 350, 100, 100);
+ eacha.setPaint(Color.green);
+ getCanvas().getLayer().addChild(eacha);
+
+ getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(final PInputEvent event) {
+ if (!(event.getPickedNode() instanceof PCamera)) {
+ event.setHandled(true);
+ getCanvas().getCamera().animateViewToPanToBounds(event.getPickedNode().getGlobalFullBounds(), 500);
+ }
+ }
+ });
+
+ final PLayer layer = getCanvas().getLayer();
+
+ final Random random = new Random();
+ for (int i = 0; i < 1000; i++) {
+ final 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(final String[] args) {
+ new PanToExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PathExample.java b/examples/src/main/java/org/piccolo2d/examples/PathExample.java
new file mode 100644
index 0000000..ef58657
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PathExample.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.event.PDragEventHandler;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PStickyHandleManager;
+import org.piccolo2d.extras.util.PFixedWidthStroke;
+import org.piccolo2d.nodes.PPath;
+
+
+public class PathExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PathExample() {
+ this(null);
+ }
+
+ public PathExample(final PCanvas aCanvas) {
+ super("PathExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PPath n1 = PPath.createRectangle(0, 0, 100, 80);
+ final PPath n2 = PPath.createEllipse(100, 100, 200, 34);
+ final 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(final String[] args) {
+ new PathExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PositionExample.java b/examples/src/main/java/org/piccolo2d/examples/PositionExample.java
new file mode 100644
index 0000000..d7c90f3
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PositionExample.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+public class PositionExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PositionExample() {
+ this(null);
+ }
+
+ public PositionExample(final PCanvas aCanvas) {
+ super("PositionExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PNode n1 = PPath.createRectangle(0, 0, 100, 80);
+ final 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(final String[] args) {
+ new PositionExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PositionPathActivityExample.java b/examples/src/main/java/org/piccolo2d/examples/PositionPathActivityExample.java
new file mode 100644
index 0000000..789a00e
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PositionPathActivityExample.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.geom.Arc2D;
+import java.awt.geom.GeneralPath;
+
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.activities.PPositionPathActivity;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how create a simple acitivty to animate a node along a
+ * general path.
+ */
+public class PositionPathActivityExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PositionPathActivityExample() {
+ super();
+ }
+
+ public void initialize() {
+ final PLayer layer = getCanvas().getLayer();
+ final PNode animatedNode = PPath.createRectangle(0, 0, 100, 80);
+ layer.addChild(animatedNode);
+
+ // create animation path
+ final 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 node to display animation path
+ final PPath ppath = new PPath(path);
+ layer.addChild(ppath);
+
+ // create activity to run animation.
+ final PPositionPathActivity positionPathActivity = new PPositionPathActivity(5000, 0,
+ new PPositionPathActivity.Target() {
+ public void setPosition(final double x, final 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(final String[] args) {
+ new PositionPathActivityExample();
+ }
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/PrintExample.java b/examples/src/main/java/org/piccolo2d/examples/PrintExample.java
new file mode 100644
index 0000000..9f7802b
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PrintExample.java
@@ -0,0 +1,304 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JToggleButton;
+import javax.swing.JToolBar;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.swing.PDefaultScrollDirector;
+import org.piccolo2d.extras.swing.PScrollDirector;
+import org.piccolo2d.extras.swing.PScrollPane;
+import org.piccolo2d.extras.swing.PViewport;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PAffineTransform;
+import org.piccolo2d.util.PBounds;
+
+
+/**
+ * Adding print action to scrolling example.
+ *
+ * @author Lance Good
+ * @author Ben Bederson
+ */
+public class PrintExample extends PFrame {
+
+ private static final long serialVersionUID = 1L;
+
+ public PrintExample() {
+ this(null);
+ }
+
+ public PrintExample(final PCanvas aCanvas) {
+ super("ScrollingExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PCanvas canvas = getCanvas();
+ final PScrollPane scrollPane = new PScrollPane(canvas);
+ final PViewport viewport = (PViewport) scrollPane.getViewport();
+ final PScrollDirector windowSD = viewport.getScrollDirector();
+ final PScrollDirector documentSD = new DocumentScrollDirector();
+
+ addBackgroundShapes(canvas);
+
+ // Now, create the toolbar
+ final JToolBar toolBar = new JToolBar();
+ final JToggleButton window = new JToggleButton("Window Scrolling");
+ final JToggleButton document = new JToggleButton("Document Scrolling");
+ final JButton print = new JButton("Print");
+ final ButtonGroup bg = new ButtonGroup();
+ bg.add(window);
+ bg.add(document);
+ toolBar.add(window);
+ toolBar.add(document);
+ toolBar.addSeparator();
+ toolBar.add(print);
+ toolBar.setFloatable(false);
+ window.setSelected(true);
+ window.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent ae) {
+ viewport.setScrollDirector(windowSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ getContentPane().validate();
+ }
+ });
+ document.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent ae) {
+ viewport.setScrollDirector(documentSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ getContentPane().validate();
+ }
+ });
+ print.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent ae) {
+ try {
+ print();
+ }
+ catch (final PrinterException e) {
+ JOptionPane.showMessageDialog(PrintExample.this, "An error occured while printing");
+ }
+ }
+ });
+ final JPanel contentPane = new JPanel();
+ contentPane.setLayout(new BorderLayout());
+ contentPane.add("Center", scrollPane);
+ contentPane.add("North", toolBar);
+ setContentPane(contentPane);
+ validate();
+ }
+
+ private void addBackgroundShapes(final PCanvas canvas) {
+ for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
+ int x = shapeCount % 21;
+ int y = (shapeCount - x) / 21;
+
+ if (shapeCount % 2 == 0) {
+ final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+ else if (shapeCount % 2 == 1) {
+ final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+
+ }
+ }
+
+ /**
+ * A modified scroll director that performs document based scroling rather
+ * than window based scrolling (ie. the scrollbars act in the inverse
+ * direction as normal)
+ */
+ public class DocumentScrollDirector extends PDefaultScrollDirector {
+
+ /**
+ * 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(final Rectangle2D viewBounds) {
+ final Point pos = new Point();
+ if (camera != null) {
+ // First we compute the union of all the layers
+ final PBounds layerBounds = new PBounds();
+ final java.util.List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
+ }
+
+ // Then we put the bounds into camera coordinates and
+ // union the camera bounds
+ camera.viewToLocal(layerBounds);
+ layerBounds.add(viewBounds);
+
+ // Rather than finding the distance from the upper left corner
+ // of the window to the upper left corner of the document -
+ // we instead find the distance from the lower right corner
+ // of the window to the upper left corner of the document
+ // THEN we measure the offset from the lower right corner
+ // of the document
+ pos.setLocation((int) (layerBounds.getWidth()
+ - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
+ .getHeight()
+ - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
+ }
+
+ return pos;
+
+ }
+
+ /**
+ * 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(final double x, final double y) {
+ if (camera == null)
+ return;
+
+ // If a scroll is in progress - we ignore new scrolls - if we
+ // didn't, since the scrollbars depend on the camera location
+ // we can end up with an infinite loop
+ if (scrollInProgress)
+ return;
+
+ scrollInProgress = true;
+
+ // Get the union of all the layers' bounds
+ final PBounds layerBounds = new PBounds();
+ final List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
+ }
+
+ final PAffineTransform at = camera.getViewTransform();
+ at.transform(layerBounds, layerBounds);
+
+ // Union the camera view bounds
+ final PBounds viewBounds = camera.getBoundsReference();
+ layerBounds.add(viewBounds);
+
+ // Now find the new view position in view coordinates -
+ // This is basically the distance from the lower right
+ // corner of the window to the upper left corner of the
+ // document
+ // We then measure the offset from the lower right corner
+ // of the document
+ final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
+ - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
+ - (y + viewBounds.getHeight()));
+
+ // Now transform the new view position into global coords
+ camera.localToView(newPoint);
+
+ // Compute the new matrix values to put the camera at the
+ // correct location
+ final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
+ final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
+
+ at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
+
+ // Now actually set the camera's transform
+ camera.setViewTransform(at);
+ scrollInProgress = false;
+ }
+ }
+
+ /**
+ * Print the canvas.
+ *
+ * @throws PrinterException
+ */
+ private void print() throws PrinterException {
+ final PrinterJob printJob = PrinterJob.getPrinterJob();
+ printJob.setPrintable(new Printable() {
+ public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex)
+ throws PrinterException {
+ if (pageIndex > 0) {
+ return NO_SUCH_PAGE;
+ }
+ else {
+ final Graphics2D g2 = (Graphics2D) graphics;
+ g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+ getCanvas().printAll(g2);
+ return PAGE_EXISTS;
+ }
+ }
+ });
+ if (printJob.printDialog()) {
+ printJob.print();
+ }
+ }
+
+ public static void main(final String[] args) {
+ new PrintExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/PulseExample.java b/examples/src/main/java/org/piccolo2d/examples/PulseExample.java
new file mode 100644
index 0000000..54e1fc1
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/PulseExample.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.PRoot;
+import org.piccolo2d.activities.PActivityScheduler;
+import org.piccolo2d.activities.PColorActivity;
+import org.piccolo2d.activities.PInterpolatingActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how to set up interpolating activities that repeat. For
+ * example it shows how to create a rectangle whos color pulses.
+ *
+ * @author jesse
+ */
+public class PulseExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PulseExample() {
+ this(null);
+ }
+
+ public PulseExample(final PCanvas aCanvas) {
+ super("PulseExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PRoot root = getCanvas().getRoot();
+ final PLayer layer = getCanvas().getLayer();
+ final 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);
+
+ layer.addChild(singlePulse);
+ layer.addChild(repeatePulse);
+ layer.addChild(repeateReversePulse);
+
+ // animate from source to destination color in one second,
+ final PColorActivity singlePulseActivity = new PColorActivity(1000, 0, 1,
+ PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
+ public Color getColor() {
+ return (Color) singlePulse.getPaint();
+ }
+
+ public void setColor(final Color color) {
+ singlePulse.setPaint(color);
+ }
+ }, Color.ORANGE);
+
+ // animate from source to destination color in one second, loop 5 times
+ final PColorActivity repeatPulseActivity = new PColorActivity(1000, 0, 5,
+ PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
+ public Color getColor() {
+ return (Color) repeatePulse.getPaint();
+ }
+
+ public void setColor(final Color color) {
+ repeatePulse.setPaint(color);
+ }
+ }, Color.BLUE);
+
+ // animate from source to destination to source color in one second,
+ // loop 10 times
+ final 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(final Color color) {
+ repeateReversePulse.setPaint(color);
+ }
+ }, Color.GREEN);
+
+ scheduler.addActivity(singlePulseActivity);
+ scheduler.addActivity(repeatPulseActivity);
+ scheduler.addActivity(repeatReversePulseActivity);
+ }
+
+ public static void main(final String[] args) {
+ new PulseExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ScrollingExample.java b/examples/src/main/java/org/piccolo2d/examples/ScrollingExample.java
new file mode 100644
index 0000000..1d41287
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ScrollingExample.java
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JPanel;
+import javax.swing.JToggleButton;
+import javax.swing.JToolBar;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.swing.PDefaultScrollDirector;
+import org.piccolo2d.extras.swing.PScrollDirector;
+import org.piccolo2d.extras.swing.PScrollPane;
+import org.piccolo2d.extras.swing.PViewport;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PAffineTransform;
+import org.piccolo2d.util.PBounds;
+
+
+/**
+ * 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 {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public ScrollingExample() {
+ this(null);
+ }
+
+ public ScrollingExample(final PCanvas aCanvas) {
+ super("ScrollingExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PCanvas canvas = getCanvas();
+ final PScrollPane scrollPane = new PScrollPane(canvas);
+ final PViewport viewport = (PViewport) scrollPane.getViewport();
+ final PScrollDirector windowSD = viewport.getScrollDirector();
+ final PScrollDirector documentSD = new DocumentScrollDirector();
+
+ addBackgroundShapes(canvas);
+
+ // Now, create the toolbar
+ final JToolBar toolBar = new JToolBar();
+ final JToggleButton window = new JToggleButton("Window Scrolling");
+ final JToggleButton document = new JToggleButton("Document Scrolling");
+ final 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(final ActionEvent ae) {
+ viewport.setScrollDirector(windowSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ getContentPane().validate();
+ }
+ });
+ document.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent ae) {
+ viewport.setScrollDirector(documentSD);
+ viewport.fireStateChanged();
+ scrollPane.revalidate();
+ getContentPane().validate();
+ }
+ });
+
+ final JPanel contentPane = new JPanel();
+ contentPane.setLayout(new BorderLayout());
+ contentPane.add("Center", scrollPane);
+ contentPane.add("North", toolBar);
+ setContentPane(contentPane);
+ validate();
+ }
+
+ /**
+ * 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 {
+
+ /**
+ * 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(final Rectangle2D viewBounds) {
+ final Point pos = new Point();
+ if (camera == null)
+ return pos;
+
+ // First we compute the union of all the layers
+ final PBounds layerBounds = new PBounds();
+ final java.util.List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
+ }
+
+ // Then we put the bounds into camera coordinates and
+ // union the camera bounds
+ camera.viewToLocal(layerBounds);
+ layerBounds.add(viewBounds);
+
+ // Rather than finding the distance from the upper left corner
+ // of the window to the upper left corner of the document -
+ // we instead find the distance from the lower right corner
+ // of the window to the upper left corner of the document
+ // THEN we measure the offset from the lower right corner
+ // of the document
+ pos.setLocation((int) (layerBounds.getWidth()
+ - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
+ .getHeight()
+ - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
+
+ return pos;
+
+ }
+
+ /**
+ * 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(final double x, final double y) {
+ if (camera == null)
+ return;
+
+ // If a scroll is in progress - we ignore new scrolls - if we
+ // didn't, since the scrollbars depend on the camera
+ // location we can end up with an infinite loop
+ if (scrollInProgress)
+ return;
+
+ scrollInProgress = true;
+
+ // Get the union of all the layers' bounds
+ final PBounds layerBounds = new PBounds();
+ final java.util.List layers = camera.getLayersReference();
+ for (final Iterator i = layers.iterator(); i.hasNext();) {
+ final PLayer layer = (PLayer) i.next();
+ layerBounds.add(layer.getFullBoundsReference());
+ }
+
+ final PAffineTransform at = camera.getViewTransform();
+ at.transform(layerBounds, layerBounds);
+
+ // Union the camera view bounds
+ final PBounds viewBounds = camera.getBoundsReference();
+ layerBounds.add(viewBounds);
+
+ // Now find the new view position in view coordinates -
+ // This is basically the distance from the lower right
+ // corner of the window to the upper left corner of the
+ // document. We then measure the offset from the lower right corner
+ // of the document
+ final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
+ - (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
+ - (y + viewBounds.getHeight()));
+
+ // Now transform the new view position into global coords
+ camera.localToView(newPoint);
+
+ // Compute the new matrix values to put the camera at the
+ // correct location
+ final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
+ final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
+
+ at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
+
+ // Now actually set the camera's transform
+ camera.setViewTransform(at);
+ scrollInProgress = false;
+ }
+ }
+
+ private void addBackgroundShapes(final PCanvas canvas) {
+ for (int shapeCount = 0; shapeCount < 440; shapeCount++) {
+ int x = shapeCount % 21;
+ int y = (shapeCount - x) / 21;
+
+ if (shapeCount % 2 == 0) {
+ final PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+ else if (shapeCount % 2 == 1) {
+ final PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
+ path.setPaint(Color.blue);
+ path.setStrokePaint(Color.black);
+ canvas.getLayer().addChild(path);
+ }
+
+ }
+ }
+
+ public static void main(final String[] args) {
+ new ScrollingExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/SelectionExample.java b/examples/src/main/java/org/piccolo2d/examples/SelectionExample.java
new file mode 100644
index 0000000..7d1bea2
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/SelectionExample.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.event.PNotification;
+import org.piccolo2d.extras.event.PNotificationCenter;
+import org.piccolo2d.extras.event.PSelectionEventHandler;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how the selection event handler works. It creates a bunch
+ * of objects that can be selected.
+ */
+public class SelectionExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public SelectionExample() {
+ this(null);
+ }
+
+ public SelectionExample(final PCanvas aCanvas) {
+ super("SelectionExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ for (int i = 0; i < 5; i++) {
+ for (int j = 0; j < 5; j++) {
+ final 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
+ final 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(final PNotification notfication) {
+ System.out.println("selection changed");
+ }
+
+ public static void main(final String[] args) {
+ new SelectionExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ShadowExample.java b/examples/src/main/java/org/piccolo2d/examples/ShadowExample.java
new file mode 100755
index 0000000..90fcba3
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ShadowExample.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+
+import java.awt.image.BufferedImage;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.PShadow;
+import org.piccolo2d.nodes.PImage;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+
+
+
+/**
+ * Shadow example.
+ */
+public final class ShadowExample extends PFrame {
+
+ private static final Color SHADOW_PAINT = new Color(20, 20, 20, 200);
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * Create a new shadow example.
+ */
+ public ShadowExample() {
+ this(null);
+ }
+
+ /**
+ * Create a new shadow example with the specified canvas.
+ *
+ * @param canvas canvas for this shadow example
+ */
+ public ShadowExample(final PCanvas canvas) {
+ super("ShadowExample", false, canvas);
+ }
+
+
+ /** {@inheritDoc} */
+ public void initialize() {
+ BufferedImage src = buildRedRectangleImage();
+
+ addHeaderAt("Shadow nodes drawn from an image, with increasing blur radius:", 0, 0);
+
+ double x = 25.0d;
+ double y = 25.0d;
+
+ for (int blurRadius = 4; blurRadius < 28; blurRadius += 4) {
+ PImage node = new PImage(src);
+ PShadow shadowNode = new PShadow(src, SHADOW_PAINT, blurRadius);
+
+ node.setOffset(x, y);
+ // offset the shadow to account for blur radius offset and light direction
+ shadowNode.setOffset(x - (2 * blurRadius) + 5.0d, y - (2 * blurRadius) + 5.0d);
+
+ // add shadow node before node, or set Z explicitly (e.g. sendToBack())
+ getCanvas().getLayer().addChild(shadowNode);
+ getCanvas().getLayer().addChild(node);
+
+ x += 125.0d;
+ if (x > 300.0d) {
+ y += 125.0d;
+ x = 25.0d;
+ }
+ }
+
+ addHeaderAt("Shadow nodes drawn from node.toImage():", 0, 300);
+
+ PPath rectNode = buildRedRectangleNode();
+
+ PShadow rectShadow = new PShadow(rectNode.toImage(), SHADOW_PAINT, 8);
+ rectShadow.setOffset(25.0d - (2 * 8) + 5.0d, 325.0d - (2 * 8) + 5.0d);
+
+ getCanvas().getLayer().addChild(rectShadow);
+ getCanvas().getLayer().addChild(rectNode);
+
+ PText textNode = new PText("Shadow Text");
+ textNode.setTextPaint(Color.RED);
+ textNode.setFont(textNode.getFont().deriveFont(36.0f));
+ textNode.setOffset(125.0d, 325.0d);
+
+ PShadow textShadow = new PShadow(textNode.toImage(), SHADOW_PAINT, 8);
+ textShadow.setOffset(125.0d - (2 * 8) + 2.5d, 325.0d - (2 * 8) + 2.5d);
+
+ getCanvas().getLayer().addChild(textShadow);
+ getCanvas().getLayer().addChild(textNode);
+ }
+
+ private PText addHeaderAt(String labelText, double x, double y) {
+ PText labelNode = new PText(labelText);
+ labelNode.setOffset(x, y);
+ getCanvas().getLayer().addChild(labelNode);
+ return labelNode;
+ }
+
+
+
+ private BufferedImage buildRedRectangleImage() {
+ BufferedImage src = new BufferedImage(75, 75, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = src.createGraphics();
+ g.setPaint(Color.RED);
+ g.fillRect(0, 0, 75, 75);
+ g.dispose();
+ return src;
+ }
+
+ private PPath buildRedRectangleNode() {
+ PPath rectNode = PPath.createRectangle(0.0f, 0.0f, 75.0f, 75.0f);
+ rectNode.setPaint(Color.RED);
+ rectNode.setStroke(null);
+ rectNode.setOffset(25.0d, 325.0d);
+ return rectNode;
+ }
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ new ShadowExample();
+ }
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/SliderExample.java b/examples/src/main/java/org/piccolo2d/examples/SliderExample.java
new file mode 100644
index 0000000..b464af9
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/SliderExample.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.border.EmptyBorder;
+
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+import org.piccolo2d.extras.swing.PScrollPane;
+
+
+/**
+ * Tests a set of Sliders and Checkboxes in panels.
+ *
+ * @author Martin Clifford
+ */
+public class SliderExample extends JFrame {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private final PSwingCanvas canvas;
+ private final PScrollPane scrollPane;
+ private final JTabbedPane tabbedPane;
+ private final PSwing swing;
+
+ public SliderExample() {
+ // Create main panel
+ final JPanel mainPanel = new JPanel(false);
+ // Create a tabbed pane
+ tabbedPane = new JTabbedPane();
+ tabbedPane.setPreferredSize(new Dimension(700, 700));
+ // Add tabbed pane to main panel
+ mainPanel.add(tabbedPane);
+ // Set the frame contents
+ getContentPane().add(mainPanel);
+
+ // Create a canvas
+ canvas = new PSwingCanvas();
+ canvas.setPreferredSize(new Dimension(700, 700));
+ // Create a scroll pane for the canvas
+ scrollPane = new PScrollPane(canvas);
+ // Create a new tab for the tabbed pane
+ tabbedPane.add("Tab 1", scrollPane);
+
+ // Create the contents for "Tab 1"
+ final 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 = createNestedPanel();
+ 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 = createNestedPanel();
+ panel.setSize(new Dimension(250, 250));
+ panel.setLocation(350, 350);
+ tabPanel.add(panel);
+ // Add the default zoom button
+ final JButton buttonPreset = new JButton("Zoom = 100%");
+ buttonPreset.addActionListener(new ActionListener() {
+ public void actionPerformed(final 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);
+ // Create a pswing object for the tab panel
+ swing = new PSwing(tabPanel);
+ swing.translate(0, 0);
+ // Add the pswing object to the canvas
+ canvas.getLayer().addChild(swing);
+ // Turn off default pan event handling
+ canvas.setPanEventHandler(null);
+
+ // Set up basic frame
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Slider Example");
+ setResizable(true);
+ setBackground(null);
+ pack();
+ 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);
+ final JLabel label2 = new JLabel("A Panel within a panel");
+ label2.setHorizontalAlignment(SwingConstants.CENTER);
+ final JSlider slider = new JSlider();
+ final JCheckBox cbox1 = new JCheckBox("Checkbox 1");
+ final JCheckBox cbox2 = new JCheckBox("Checkbox 2");
+ final 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);
+ final 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(final String[] args) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ new SliderExample();
+ }
+ });
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/SquiggleExample.java b/examples/src/main/java/org/piccolo2d/examples/SquiggleExample.java
new file mode 100644
index 0000000..8415710
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/SquiggleExample.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.event.InputEvent;
+import java.awt.geom.Point2D;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.event.PInputEventFilter;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+public class SquiggleExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private PLayer layer;
+
+ public SquiggleExample() {
+ this(null);
+ }
+
+ public SquiggleExample(final PCanvas aCanvas) {
+ super("SquiggleExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ super.initialize();
+ final PBasicInputEventHandler squiggleEventHandler = createSquiggleEventHandler();
+ squiggleEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ getCanvas().addInputEventListener(squiggleEventHandler);
+ layer = getCanvas().getLayer();
+ }
+
+ public PBasicInputEventHandler createSquiggleEventHandler() {
+ return new PDragSequenceEventHandler() {
+
+ protected PPath squiggle;
+
+ public void startDrag(final PInputEvent e) {
+ super.startDrag(e);
+
+ final 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(final PInputEvent e) {
+ super.drag(e);
+ updateSquiggle(e);
+ }
+
+ public void endDrag(final PInputEvent e) {
+ super.endDrag(e);
+ updateSquiggle(e);
+ squiggle = null;
+ }
+
+ public void updateSquiggle(final PInputEvent aEvent) {
+ final Point2D p = aEvent.getPosition();
+ squiggle.lineTo((float) p.getX(), (float) p.getY());
+ }
+ };
+ }
+
+ public static void main(final String[] args) {
+ new SquiggleExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/StickyExample.java b/examples/src/main/java/org/piccolo2d/examples/StickyExample.java
new file mode 100644
index 0000000..d8be6d2
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/StickyExample.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PBoundsHandle;
+import org.piccolo2d.nodes.PPath;
+
+
+public class StickyExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public StickyExample() {
+ this(null);
+ }
+
+ public StickyExample(final PCanvas aCanvas) {
+ super("StickyExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final 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(final String[] args) {
+ new StickyExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/StickyHandleLayerExample.java b/examples/src/main/java/org/piccolo2d/examples/StickyHandleLayerExample.java
new file mode 100644
index 0000000..0b47f09
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/StickyHandleLayerExample.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+import java.util.Iterator;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.PRoot;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PBoundsHandle;
+import org.piccolo2d.extras.handles.PHandle;
+import org.piccolo2d.extras.util.PBoundsLocator;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * 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
+ * the view is zoomed. They will also be drawn on top of all other objects, even
+ * if those objects overlap the object that they manipulate. For this setup we
+ * need to add and updateHandles activity that makes sure to relocate the handle
+ * after any change. Another way to do this would be to add change listeners to
+ * the camera and the node that they manipulate and only update them then. But
+ * this method is easier and should be plenty efficient for normal use.
+ *
+ * @author jesse
+ */
+public class StickyHandleLayerExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public StickyHandleLayerExample() {
+ this(null);
+ }
+
+ public StickyHandleLayerExample(final PCanvas aCanvas) {
+ super("StickyHandleLayerExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PCanvas c = getCanvas();
+
+ final PActivity updateHandles = new PActivity(-1, 0) {
+ protected void activityStep(final long elapsedTime) {
+ super.activityStep(elapsedTime);
+
+ final PRoot root = getActivityScheduler().getRoot();
+
+ if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
+ final Iterator i = getCanvas().getCamera().getChildrenIterator();
+ while (i.hasNext()) {
+ final PNode each = (PNode) i.next();
+ if (each instanceof PHandle) {
+ final PHandle handle = (PHandle) each;
+ handle.relocateHandle();
+ }
+ }
+ }
+ }
+ };
+
+ final 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(final String[] args) {
+ new StickyHandleLayerExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/StrokeExample.java b/examples/src/main/java/org/piccolo2d/examples/StrokeExample.java
new file mode 100644
index 0000000..1ec9fb1
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/StrokeExample.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.util.PFixedWidthStroke;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * Stroke example.
+ */
+public final class StrokeExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create a new stroke example.
+ */
+ public StrokeExample() {
+ this(null);
+ }
+
+ /**
+ * Create a new stroke example with the specified canvas.
+ *
+ * @param canvas canvas
+ */
+ public StrokeExample(final PCanvas canvas) {
+ super("StrokeExample", false, canvas);
+ }
+
+ /** {@inheritDoc} */
+ public void initialize() {
+ final PText label = new PText("Stroke Example");
+ label.setFont(label.getFont().deriveFont(24.0f));
+ label.offset(20.0d, 20.0d);
+
+ final PPath rect = PPath.createRectangle(50.0f, 50.0f, 300.0f, 300.0f);
+ rect.setStroke(new BasicStroke(4.0f));
+ rect.setStrokePaint(new Color(80, 80, 80));
+
+ final PText fixedWidthLabel = new PText("PFixedWidthStrokes");
+ fixedWidthLabel.setTextPaint(new Color(80, 0, 0));
+ fixedWidthLabel.offset(100.0d, 80.0d);
+
+ final PPath fixedWidthRect0 = PPath.createRectangle(100.0f, 100.0f, 200.0f, 50.0f);
+ fixedWidthRect0.setStroke(new PFixedWidthStroke(2.0f));
+ fixedWidthRect0.setStrokePaint(new Color(60, 60, 60));
+
+ final PPath fixedWidthRect1 = PPath.createRectangle(100.0f, 175.0f, 200.0f, 50.0f);
+ fixedWidthRect1.setStroke(new PFixedWidthStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f));
+ // fixedWidthRect1.setStroke(new PFixedWidthStroke(1.5f,
+ // PFixedWidthStroke.CAP_ROUND, PFixedWidthStroke.JOIN_MITER, 10.0f));
+ fixedWidthRect1.setStrokePaint(new Color(40, 40, 40));
+
+ final PPath fixedWidthRect2 = PPath.createRectangle(100.0f, 250.0f, 200.0f, 50.0f);
+ fixedWidthRect2.setStroke(new PFixedWidthStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
+ new float[] { 2.0f, 3.0f, 4.0f }, 1.0f));
+ // fixedWidthRect2.setStroke(new PFixedWidthStroke(1.0f,
+ // PFixedWidthStroke.CAP_ROUND, PFixedWidthStroke.JOIN_MITER, 10.0f, new
+ // float[] { 2.0f, 3.0f, 4.0f }, 1.0f));
+ fixedWidthRect2.setStrokePaint(new Color(20, 20, 20));
+
+ getCanvas().getLayer().addChild(label);
+ getCanvas().getLayer().addChild(rect);
+ getCanvas().getLayer().addChild(fixedWidthLabel);
+ getCanvas().getLayer().addChild(fixedWidthRect0);
+ getCanvas().getLayer().addChild(fixedWidthRect1);
+ getCanvas().getLayer().addChild(fixedWidthRect2);
+ }
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments
+ */
+ public static void main(final String[] args) {
+ new StrokeExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/SwingLayoutExample.java b/examples/src/main/java/org/piccolo2d/examples/SwingLayoutExample.java
new file mode 100644
index 0000000..5d51c0a
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/SwingLayoutExample.java
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.BasicStroke;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JTextField;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+import org.piccolo2d.extras.swing.SwingLayoutNode;
+import org.piccolo2d.extras.swing.SwingLayoutNode.Anchor;
+import org.piccolo2d.nodes.PHtmlView;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+public class SwingLayoutExample {
+
+ public static class MyPPath extends PPath {
+ public MyPPath(final Shape shape, final Color color, final Stroke stroke, final Color strokeColor) {
+ super(shape, stroke);
+ setPaint(color);
+ setStrokePaint(strokeColor);
+ }
+ }
+
+ public static void main(final String[] args) {
+
+ final Dimension canvasSize = new Dimension(800, 600);
+ final PCanvas canvas = new PSwingCanvas();
+ canvas.setPreferredSize(canvasSize);
+
+ final PNode rootNode = new PNode();
+ canvas.getLayer().addChild(rootNode);
+ rootNode.addInputEventListener(new PBasicInputEventHandler() {
+ // Shift+Drag up/down will scale the node up/down
+ public void mouseDragged(final PInputEvent event) {
+ super.mouseDragged(event);
+ if (event.isShiftDown()) {
+ event.getPickedNode().scale(event.getCanvasDelta().height > 0 ? 0.98 : 1.02);
+ }
+ }
+ });
+
+ final BorderLayout borderLayout = new BorderLayout();
+ borderLayout.setHgap(10);
+ borderLayout.setVgap(5);
+ final SwingLayoutNode borderLayoutNode = new SwingLayoutNode(borderLayout);
+ borderLayoutNode.addChild(new PText("North"), BorderLayout.NORTH);
+ borderLayoutNode.setAnchor(Anchor.CENTER);
+ borderLayoutNode.addChild(new PText("South"), BorderLayout.SOUTH);
+ borderLayoutNode.setAnchor(Anchor.WEST);
+ borderLayoutNode.addChild(new PText("East"), BorderLayout.EAST);
+ borderLayoutNode.addChild(new PText("West"), BorderLayout.WEST);
+ borderLayoutNode.addChild(new PText("CENTER"), BorderLayout.CENTER);
+ borderLayoutNode.setOffset(100, 100);
+ rootNode.addChild(borderLayoutNode);
+
+ final SwingLayoutNode flowLayoutNode = new SwingLayoutNode(new FlowLayout());
+ flowLayoutNode.addChild(new PText("1+1"));
+ flowLayoutNode.addChild(new PText("2+2"));
+ flowLayoutNode.setOffset(200, 200);
+ rootNode.addChild(flowLayoutNode);
+
+ final SwingLayoutNode gridBagLayoutNode = new SwingLayoutNode(new GridBagLayout());
+ final GridBagConstraints gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = GridBagConstraints.RELATIVE;
+ gridBagLayoutNode.addChild(new PText("FirstNode"), gridBagConstraints);
+ gridBagLayoutNode.addChild(new PText("SecondNode"), gridBagConstraints);
+ gridBagConstraints.insets = new Insets(50, 50, 50, 50);
+ gridBagLayoutNode.addChild(new PText("ThirdNode"), gridBagConstraints);
+ gridBagLayoutNode.setOffset(400, 250);
+ rootNode.addChild(gridBagLayoutNode);
+
+ JPanel container = new JPanel();
+ container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
+ final SwingLayoutNode boxLayoutNode = new SwingLayoutNode(container);
+ boxLayoutNode.addChild(new MyPPath(new Rectangle2D.Double(0, 0, 50, 50), Color.yellow, new BasicStroke(2),
+ Color.red));
+ boxLayoutNode.addChild(new MyPPath(new Rectangle2D.Double(0, 0, 100, 50), Color.orange, new BasicStroke(2),
+ Color.blue));
+ final SwingLayoutNode innerNode = new SwingLayoutNode(); // nested
+ // layout
+ innerNode.addChild(new PSwing(new JLabel("foo")));
+ innerNode.addChild(new PSwing(new JLabel("bar")));
+ boxLayoutNode.addChild(innerNode, Anchor.CENTER);
+ boxLayoutNode.setOffset(300, 300);
+ rootNode.addChild(boxLayoutNode);
+
+ final SwingLayoutNode horizontalLayoutNode = new SwingLayoutNode(new GridBagLayout());
+ horizontalLayoutNode.addChild(new PSwing(new JButton("Zero")));
+ horizontalLayoutNode.addChild(new PSwing(new JButton("One")));
+ horizontalLayoutNode.addChild(new PSwing(new JButton("Two")));
+ horizontalLayoutNode.addChild(new PSwing(new JLabel("Three")));
+ horizontalLayoutNode.addChild(new PSwing(new JSlider()));
+ horizontalLayoutNode.addChild(new PSwing(new JTextField("Four")));
+ final PHtmlView htmlNode = new PHtmlView("Five", new JLabel().getFont().deriveFont(15f),
+ Color.blue);
+ htmlNode.scale(3);
+ horizontalLayoutNode.addChild(htmlNode);
+ horizontalLayoutNode.setOffset(100, 450);
+ rootNode.addChild(horizontalLayoutNode);
+
+ // 3x2 grid of values, shapes and labels (similar to a layout in
+ // acid-base-solutions)
+ final SwingLayoutNode gridNode = new SwingLayoutNode(new GridBagLayout());
+ final GridBagConstraints constraints = new GridBagConstraints();
+ constraints.insets = new Insets(10, 10, 10, 10);
+ /*---- column of values, right justified ---*/
+ constraints.gridy = 0; // row
+ constraints.gridx = 0; // column
+ constraints.anchor = GridBagConstraints.EAST;
+ final PText dynamicNode = new PText("0"); // will be controlled by
+ // dynamicSlider
+ gridNode.addChild(dynamicNode, constraints);
+ constraints.gridy++;
+ gridNode.addChild(new PText("0"), constraints);
+ /*---- column of shapes, center justified ---*/
+ constraints.gridy = 0; // row
+ constraints.gridx++; // column
+ constraints.anchor = GridBagConstraints.CENTER;
+ final PPath redCircle = new PPath(new Ellipse2D.Double(0, 0, 25, 25));
+ redCircle.setPaint(Color.RED);
+ gridNode.addChild(redCircle, constraints);
+ constraints.gridy++;
+ final PPath greenCircle = new PPath(new Ellipse2D.Double(0, 0, 25, 25));
+ greenCircle.setPaint(Color.GREEN);
+ gridNode.addChild(greenCircle, constraints);
+ /*---- column of labels, left justified ---*/
+ constraints.gridy = 0; // row
+ constraints.gridx++; // column
+ constraints.anchor = GridBagConstraints.WEST;
+ gridNode.addChild(new PHtmlView("H2O"), constraints);
+ constraints.gridy++;
+ gridNode.addChild(new PHtmlView("H3O+"), constraints);
+ gridNode.scale(2.0);
+ gridNode.setOffset(400, 50);
+ rootNode.addChild(gridNode);
+
+ final JPanel controlPanel = new JPanel();
+ controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
+ final JSlider dynamicSlider = new JSlider(0, 1000, 0); // controls
+ // dynamicNode
+ dynamicSlider.setMajorTickSpacing(dynamicSlider.getMaximum());
+ dynamicSlider.setPaintTicks(true);
+ dynamicSlider.setPaintLabels(true);
+ dynamicSlider.addChangeListener(new ChangeListener() {
+
+ public void stateChanged(final ChangeEvent e) {
+ dynamicNode.setText(String.valueOf(dynamicSlider.getValue()));
+ }
+ });
+ controlPanel.add(dynamicSlider);
+
+ final JPanel appPanel = new JPanel(new BorderLayout());
+ appPanel.add(canvas, BorderLayout.CENTER);
+ appPanel.add(controlPanel, BorderLayout.EAST);
+
+ final JFrame frame = new JFrame();
+ frame.setContentPane(appPanel);
+ frame.pack();
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setVisible(true);
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/TextExample.java b/examples/src/main/java/org/piccolo2d/examples/TextExample.java
new file mode 100644
index 0000000..fba115b
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/TextExample.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.event.PStyledTextEventHandler;
+
+
+/**
+ * @author Lance Good
+ */
+public class TextExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public TextExample() {
+ this(null);
+ }
+
+ public TextExample(final PCanvas aCanvas) {
+ super("TextExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
+ final PStyledTextEventHandler textHandler = new PStyledTextEventHandler(getCanvas());
+ getCanvas().addInputEventListener(textHandler);
+ }
+
+ public static void main(final String[] args) {
+ new TextExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/TextOffsetBoundsExample.java b/examples/src/main/java/org/piccolo2d/examples/TextOffsetBoundsExample.java
new file mode 100644
index 0000000..feb3f3f
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/TextOffsetBoundsExample.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Document;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.nodes.PStyledText;
+import org.piccolo2d.nodes.PHtmlView;
+import org.piccolo2d.nodes.PText;
+
+
+
+
+/**
+ * Example of text rendering with offset bounds.
+ */
+public class TextOffsetBoundsExample extends PFrame {
+
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+ public TextOffsetBoundsExample() {
+ this(null);
+ }
+
+ public TextOffsetBoundsExample(final PCanvas aCanvas) {
+ super("TextOffsetBoundsExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere.";
+ PText ptext = new PText(text);
+ ptext.setPaint(Color.GRAY);
+ ptext.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
+ ptext.offset(0.0d, 50.0d);
+
+ PHtmlView phtmlView = new PHtmlView(text);
+ phtmlView.setPaint(Color.GRAY);
+ phtmlView.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
+ phtmlView.offset(0.0d, 150.0d);
+
+ PStyledText pstyledText = new PStyledText();
+ Document document = new DefaultStyledDocument();
+ try {
+ document.insertString(0, text, null);
+ }
+ catch (BadLocationException e) {
+ // ignore
+ }
+ pstyledText.setDocument(document);
+ pstyledText.setPaint(Color.GRAY);
+ pstyledText.setBounds(0.0d, 10.0d, 600.0d, 40.0d);
+ pstyledText.offset(0.0d, 250.0d);
+
+ getCanvas().getLayer().addChild(ptext);
+ getCanvas().getLayer().addChild(phtmlView);
+ getCanvas().getLayer().addChild(pstyledText);
+ }
+
+ public static void main(final String[] args) {
+ new TextOffsetBoundsExample();
+ }}
diff --git a/examples/src/main/java/org/piccolo2d/examples/ToImageExample.java b/examples/src/main/java/org/piccolo2d/examples/ToImageExample.java
new file mode 100644
index 0000000..33ad6f1
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/ToImageExample.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import java.awt.image.BufferedImage;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PImage;
+import org.piccolo2d.nodes.PText;
+
+
+
+
+/**
+ * This example demonstrates the difference between
+ * the different fill strategies for {@link PNode#toImage(BufferedImage,Paint,int)}.
+ */
+public class ToImageExample
+ extends PFrame {
+
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * Create a new toImage example.
+ */
+ public ToImageExample() {
+ this(null);
+ }
+
+ /**
+ * Create a new toImage example for the specified canvas.
+ *
+ * @param canvas canvas for this toImage example
+ */
+ public ToImageExample(final PCanvas canvas) {
+ super("ToImageExample", false, canvas);
+ }
+
+
+ /** {@inheritDoc} */
+ public void initialize() {
+ PText aspectFit = new PText("Aspect Fit");
+ PText aspectCover = new PText("Aspect Cover");
+ PText exactFit = new PText("Exact Fit");
+
+ PImage aspectFit100x100 = new PImage(aspectFit.toImage(
+ new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+ PImage aspectFit100x200 = new PImage(aspectFit.toImage(
+ new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+ PImage aspectFit200x100 = new PImage(aspectFit.toImage(
+ new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+ aspectFit.setOffset(10.0, 20.0);
+ aspectFit100x100.setOffset(10.0, 70.0);
+ aspectFit100x200.setOffset(10.0, 174.0);
+ aspectFit200x100.setOffset(10.0, 378.0);
+
+ PImage aspectCover100x100 = new PImage(aspectCover.toImage(new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+ PImage aspectCover100x200 = new PImage(aspectCover.toImage(new BufferedImage(100, 200,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+ PImage aspectCover200x100 = new PImage(aspectCover.toImage(new BufferedImage(200, 100,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+ aspectCover.setOffset(214.0, 20.0);
+ aspectCover100x100.setOffset(214.0, 70.0);
+ aspectCover100x200.setOffset(214.0, 174.0);
+ aspectCover200x100.setOffset(214.0, 378.0);
+
+ PImage exactFit100x100 = new PImage(exactFit.toImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+ PImage exactFit100x200 = new PImage(exactFit.toImage(new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+ PImage exactFit200x100 = new PImage(exactFit.toImage(new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+ exactFit.setOffset(410.0, 20.0);
+ exactFit100x100.setOffset(418.0, 70.0);
+ exactFit100x200.setOffset(418.0, 174.0);
+ exactFit200x100.setOffset(418.0, 378.0);
+
+ PImage texture = new PImage(getClass().getResource("texture.png"));
+
+ PImage textureAspectFit100x100 = new PImage(texture.toImage(
+ new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+ PImage textureAspectFit100x200 = new PImage(texture.toImage(
+ new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+ PImage textureAspectFit200x100 = new PImage(texture.toImage(
+ new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB), Color.LIGHT_GRAY,
+ PNode.FILL_STRATEGY_ASPECT_FIT));
+
+ textureAspectFit100x100.setOffset(10.0, 482.0);
+ textureAspectFit100x200.setOffset(10.0, 586.0);
+ textureAspectFit200x100.setOffset(10.0, 790.0);
+
+ PImage textureAspectCover100x100 = new PImage(texture.toImage(new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+ PImage textureAspectCover100x200 = new PImage(texture.toImage(new BufferedImage(100, 200,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+ PImage textureAspectCover200x100 = new PImage(texture.toImage(new BufferedImage(200, 100,
+ BufferedImage.TYPE_INT_ARGB), Color.YELLOW, PNode.FILL_STRATEGY_ASPECT_COVER));
+
+ textureAspectCover100x100.setOffset(214.0, 482.0);
+ textureAspectCover100x200.setOffset(214.0, 586.0);
+ textureAspectCover200x100.setOffset(214.0, 790.0);
+
+ PImage textureExactFit100x100 = new PImage(texture.toImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+ PImage textureExactFit100x200 = new PImage(texture.toImage(new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+ PImage textureExactFit200x100 = new PImage(texture.toImage(new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB),
+ Color.PINK, PNode.FILL_STRATEGY_EXACT_FIT));
+
+ textureExactFit100x100.setOffset(418.0, 482.0);
+ textureExactFit100x200.setOffset(418.0, 586.0);
+ textureExactFit200x100.setOffset(418.0, 790.0);
+
+ PLayer layer = getCanvas().getLayer();
+ layer.addChild(aspectFit);
+ layer.addChild(aspectCover);
+ layer.addChild(exactFit);
+ layer.addChild(aspectFit100x100);
+ layer.addChild(aspectFit100x200);
+ layer.addChild(aspectFit200x100);
+ layer.addChild(aspectCover100x100);
+ layer.addChild(aspectCover100x200);
+ layer.addChild(aspectCover200x100);
+ layer.addChild(exactFit100x100);
+ layer.addChild(exactFit100x200);
+ layer.addChild(exactFit200x100);
+ layer.addChild(textureAspectFit100x100);
+ layer.addChild(textureAspectFit100x200);
+ layer.addChild(textureAspectFit200x100);
+ layer.addChild(textureAspectCover100x100);
+ layer.addChild(textureAspectCover100x200);
+ layer.addChild(textureAspectCover200x100);
+ layer.addChild(textureExactFit100x100);
+ layer.addChild(textureExactFit100x200);
+ layer.addChild(textureExactFit200x100);
+
+ setSize(650, 510);
+ }
+
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ new ToImageExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/TooltipExample.java b/examples/src/main/java/org/piccolo2d/examples/TooltipExample.java
new file mode 100644
index 0000000..d2de9c4
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/TooltipExample.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.geom.Point2D;
+
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * Simple example of one way to add tooltips
+ *
+ * @author jesse
+ */
+public class TooltipExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public TooltipExample() {
+ this(null);
+ }
+
+ public TooltipExample(final PCanvas aCanvas) {
+ super("TooltipExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PNode n1 = PPath.createEllipse(0, 0, 100, 100);
+ final 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(final PInputEvent event) {
+ updateToolTip(event);
+ }
+
+ public void mouseDragged(final PInputEvent event) {
+ updateToolTip(event);
+ }
+
+ public void updateToolTip(final PInputEvent event) {
+ final PNode n = event.getPickedNode();
+ final String tooltipString = (String) n.getAttribute("tooltip");
+ final Point2D p = event.getCanvasPosition();
+
+ event.getPath().canvasToLocal(p, camera);
+
+ tooltipNode.setText(tooltipString);
+ tooltipNode.setOffset(p.getX() + 8, p.getY() - 8);
+ }
+ });
+ }
+
+ public static void main(final String[] argv) {
+ new TooltipExample();
+ }
+}
\ No newline at end of file
diff --git a/examples/src/main/java/org/piccolo2d/examples/TwoCanvasExample.java b/examples/src/main/java/org/piccolo2d/examples/TwoCanvasExample.java
new file mode 100644
index 0000000..95f1903
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/TwoCanvasExample.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import java.awt.Color;
+
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.PRoot;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.extras.handles.PBoundsHandle;
+import org.piccolo2d.nodes.PPath;
+
+
+public class TwoCanvasExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public TwoCanvasExample() {
+ this(null);
+ }
+
+ public TwoCanvasExample(final PCanvas aCanvas) {
+ super("TwoCanvasExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PRoot root = getCanvas().getRoot();
+ final PLayer layer = getCanvas().getLayer();
+
+ final PNode n = PPath.createRectangle(0, 0, 100, 80);
+ final 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);
+
+ final PCamera otherCamera = new PCamera();
+ otherCamera.addLayer(layer);
+ root.addChild(otherCamera);
+
+ final PCanvas other = new PCanvas();
+ other.setCamera(otherCamera);
+ final PFrame result = new PFrame("TwoCanvasExample", false, other);
+ result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ result.setLocation(500, 100);
+ }
+
+ public static void main(final String[] args) {
+ new TwoCanvasExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/WaitForActivitiesExample.java b/examples/src/main/java/org/piccolo2d/examples/WaitForActivitiesExample.java
new file mode 100644
index 0000000..001cd2d
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/WaitForActivitiesExample.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+/**
+ * This example shows how to use setTriggerTime to synchronize the start and end
+ * of two activities.
+ */
+public class WaitForActivitiesExample extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public WaitForActivitiesExample() {
+ this(null);
+ }
+
+ public WaitForActivitiesExample(final PCanvas aCanvas) {
+ super("WaitForActivitiesExample", false, aCanvas);
+ }
+
+ public void initialize() {
+ final PLayer layer = getCanvas().getLayer();
+
+ final PNode a = PPath.createRectangle(0, 0, 100, 80);
+ final PNode b = PPath.createRectangle(0, 0, 100, 80);
+
+ layer.addChild(a);
+ layer.addChild(b);
+
+ final PActivity a1 = a.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
+ final PActivity a2 = b.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
+
+ a2.startAfter(a1);
+ }
+
+ public static void main(final String[] args) {
+ new WaitForActivitiesExample();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/fisheye/CalendarNode.java b/examples/src/main/java/org/piccolo2d/examples/fisheye/CalendarNode.java
new file mode 100644
index 0000000..573a889
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/fisheye/CalendarNode.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.fisheye;
+
+import java.awt.Font;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+
+
+class CalendarNode extends PNode {
+ static int DEFAULT_NUM_DAYS = 7;
+ static int DEFAULT_NUM_WEEKS = 12;
+ static int TEXT_X_OFFSET = 1;
+ static int TEXT_Y_OFFSET = 10;
+ static int DEFAULT_ANIMATION_MILLIS = 250;
+ static float FOCUS_SIZE_PERCENT = 0.65f;
+ static Font DEFAULT_FONT = new Font("Arial", Font.PLAIN, 10);
+
+ int numDays = DEFAULT_NUM_DAYS;
+ int numWeeks = DEFAULT_NUM_WEEKS;
+ int daysExpanded = 0;
+ int weeksExpanded = 0;
+
+ public CalendarNode() {
+ for (int week = 0; week < numWeeks; week++) {
+ for (int day = 0; day < numDays; day++) {
+ addChild(new DayNode(week, day));
+ }
+ }
+
+ CalendarNode.this.addInputEventListener(new PBasicInputEventHandler() {
+ public void mouseReleased(PInputEvent event) {
+ DayNode pickedDay = (DayNode) event.getPickedNode();
+ if (pickedDay.hasWidthFocus && pickedDay.hasHeightFocus) {
+ setFocusDay(null, true);
+ }
+ else {
+ setFocusDay(pickedDay, true);
+ }
+ }
+ });
+ }
+
+ public void setFocusDay(DayNode focusDay, boolean animate) {
+ for (int i = 0; i < getChildrenCount(); i++) {
+ DayNode each = (DayNode) getChild(i);
+ each.hasWidthFocus = false;
+ each.hasHeightFocus = false;
+ }
+
+ if (focusDay == null) {
+ daysExpanded = 0;
+ weeksExpanded = 0;
+ }
+ else {
+ focusDay.hasWidthFocus = true;
+ daysExpanded = 1;
+ weeksExpanded = 1;
+
+ for (int i = 0; i < numDays; i++) {
+ getDay(focusDay.week, i).hasHeightFocus = true;
+ }
+
+ for (int i = 0; i < numWeeks; i++) {
+ getDay(i, focusDay.day).hasWidthFocus = true;
+ }
+ }
+
+ layoutChildren(animate);
+ }
+
+ public DayNode getDay(int week, int day) {
+ return (DayNode) getChild((week * numDays) + day);
+ }
+
+ protected void layoutChildren(boolean animate) {
+ double focusWidth = 0;
+ double focusHeight = 0;
+
+ if (daysExpanded != 0 && weeksExpanded != 0) {
+ focusWidth = (getWidth() * FOCUS_SIZE_PERCENT) / daysExpanded;
+ focusHeight = (getHeight() * FOCUS_SIZE_PERCENT) / weeksExpanded;
+ }
+
+ double collapsedWidth = (getWidth() - (focusWidth * daysExpanded))
+ / (numDays - daysExpanded);
+ double collapsedHeight = (getHeight() - (focusHeight * weeksExpanded))
+ / (numWeeks - weeksExpanded);
+
+ double xOffset = 0;
+ double yOffset = 0;
+ double rowHeight = 0;
+ DayNode each = null;
+
+ for (int week = 0; week < numWeeks; week++) {
+ for (int day = 0; day < numDays; day++) {
+ each = getDay(week, day);
+ double width = collapsedWidth;
+ double height = collapsedHeight;
+
+ if (each.hasWidthFocus())
+ width = focusWidth;
+ if (each.hasHeightFocus())
+ height = focusHeight;
+
+ if (animate) {
+ each.animateToBounds(xOffset, yOffset, width,
+ height, DEFAULT_ANIMATION_MILLIS).setStepRate(0);
+ }
+ else {
+ each.setBounds(xOffset, yOffset, width, height);
+ }
+
+ xOffset += width;
+ rowHeight = height;
+ }
+ xOffset = 0;
+ yOffset += rowHeight;
+ }
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/fisheye/DayNode.java b/examples/src/main/java/org/piccolo2d/examples/fisheye/DayNode.java
new file mode 100644
index 0000000..3f25e64
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/fisheye/DayNode.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.fisheye;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.util.ArrayList;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.util.PPaintContext;
+
+
+class DayNode extends PNode {
+ boolean hasWidthFocus;
+ boolean hasHeightFocus;
+ ArrayList lines;
+ int week;
+ int day;
+ String dayOfMonthString;
+
+ public DayNode(int week, int day) {
+ lines = new ArrayList();
+ lines.add("7:00 AM Walk the dog.");
+ lines.add("9:30 AM Meet John for Breakfast.");
+ lines.add("12:00 PM Lunch with Peter.");
+ lines.add("3:00 PM Research Demo.");
+ lines.add("6:00 PM Pickup Sarah from gymnastics.");
+ lines.add("7:00 PM Pickup Tommy from karate.");
+ this.week = week;
+ this.day = day;
+ this.dayOfMonthString = Integer.toString((week * 7) + day);
+ setPaint(Color.BLACK);
+ }
+
+ public int getWeek() {
+ return week;
+ }
+
+ public int getDay() {
+ return day;
+ }
+
+ public boolean hasHeightFocus() {
+ return hasHeightFocus;
+ }
+
+ public void setHasHeightFocus(boolean hasHeightFocus) {
+ this.hasHeightFocus = hasHeightFocus;
+ }
+
+ public boolean hasWidthFocus() {
+ return hasWidthFocus;
+ }
+
+ public void setHasWidthFocus(boolean hasWidthFocus) {
+ this.hasWidthFocus = hasWidthFocus;
+ }
+
+ protected void paint(PPaintContext paintContext) {
+ Graphics2D g2 = paintContext.getGraphics();
+
+ g2.setPaint(getPaint());
+ g2.draw(getBoundsReference());
+ g2.setFont(CalendarNode.DEFAULT_FONT);
+
+ float y = (float) getY() + CalendarNode.TEXT_Y_OFFSET;
+ paintContext.getGraphics().drawString(dayOfMonthString,
+ (float) getX() + CalendarNode.TEXT_X_OFFSET, y);
+
+ if (hasWidthFocus && hasHeightFocus) {
+ paintContext.pushClip(getBoundsReference());
+ for (int i = 0; i < lines.size(); i++) {
+ y += 10;
+ g2.drawString((String) lines.get(i),
+ (float) getX() + CalendarNode.TEXT_X_OFFSET, y);
+ }
+ paintContext.popClip(getBoundsReference());
+ }
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheye.java b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheye.java
new file mode 100644
index 0000000..09a97bb
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheye.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.fisheye;
+
+import java.awt.Dimension;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+
+import org.piccolo2d.PCanvas;
+
+
+public class TabularFisheye extends PCanvas {
+ private CalendarNode calendarNode;
+
+ public TabularFisheye() {
+ calendarNode = new CalendarNode();
+ getLayer().addChild(calendarNode);
+ setMinimumSize(new Dimension(300, 300));
+ setPreferredSize(new Dimension(600, 600));
+ setZoomEventHandler(null);
+ setPanEventHandler(null);
+
+ addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent arg0) {
+ calendarNode.setBounds(getX(), getY(),
+ getWidth() - 1, getHeight() - 1);
+ calendarNode.layoutChildren(false);
+ }
+ });
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeApplet.java b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeApplet.java
new file mode 100644
index 0000000..95eab45
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeApplet.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.fisheye;
+
+import javax.swing.JApplet;
+
+public class TabularFisheyeApplet extends JApplet {
+
+ public void init() {
+ getContentPane().add(new TabularFisheye());
+ }
+
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeFrame.java b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeFrame.java
new file mode 100644
index 0000000..4c7243a
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/fisheye/TabularFisheyeFrame.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.fisheye;
+
+import javax.swing.JFrame;
+
+public class TabularFisheyeFrame extends JFrame {
+ public TabularFisheyeFrame() {
+ setTitle("Piccolo2D Tabular Fisheye");
+
+ TabularFisheye tabularFisheye = new TabularFisheye();
+ getContentPane().add(tabularFisheye);
+ pack();
+ }
+
+ public static void main(String args[]) {
+ JFrame frame = new TabularFisheyeFrame();
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setVisible(true);
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/pswing/MultiplePSwingCanvasesExample.java b/examples/src/main/java/org/piccolo2d/examples/pswing/MultiplePSwingCanvasesExample.java
new file mode 100644
index 0000000..a37e14a
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/pswing/MultiplePSwingCanvasesExample.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.pswing;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+
+
+public class MultiplePSwingCanvasesExample extends JFrame {
+
+
+ public static void main(final String[] args) {
+ JFrame frame = new MultiplePSwingCanvasesExample();
+
+ Container container = frame.getContentPane();
+ container.setLayout(new BorderLayout());
+
+ PSwingCanvas canvas1 = buildPSwingCanvas("Canvas 1", Color.RED);
+ canvas1.setPreferredSize(new Dimension(350, 350));
+ container.add(canvas1, BorderLayout.WEST);
+
+ PSwingCanvas canvas2 = buildPSwingCanvas("Canvas 2", Color.BLUE);
+ container.add(canvas2, BorderLayout.EAST);
+ canvas2.setPreferredSize(new Dimension(350, 350));
+
+ frame.pack();
+ frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
+ frame.setVisible(true);
+
+ }
+
+ private static PSwingCanvas buildPSwingCanvas(String canvasName, Color rectangleColor) {
+ PSwingCanvas canvas = new PSwingCanvas();
+ canvas.setPreferredSize(new Dimension(350, 350));
+ canvas.getLayer().addChild(new PSwing(new JLabel(canvasName)));
+
+ PSwing rectNode = buildRectangleNode(rectangleColor);
+ rectNode.setOffset(100, 100);
+ canvas.getLayer().addChild(rectNode);
+
+ PSwing buttonNode = buildTestButton();
+ buttonNode.setOffset(50, 50);
+ canvas.getLayer().addChild(buttonNode);
+
+ return canvas;
+ }
+
+ private static PSwing buildRectangleNode(Color rectangleColor) {
+ JPanel rectPanel = new JPanel();
+ rectPanel.setPreferredSize(new Dimension((int)(Math.random()*50+50), (int)(Math.random()*50+50)));
+ rectPanel.setBackground(rectangleColor);
+ PSwing rect = new PSwing(rectPanel);
+ return rect;
+ }
+
+ private static PSwing buildTestButton() {
+ final JButton button = new JButton("Click Me");
+
+ button.addActionListener(new AbstractAction() {
+
+ public void actionPerformed(ActionEvent arg0) {
+ button.setText("Thanks");
+ }
+
+ });
+
+ return new PSwing(button);
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample1.java b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample1.java
new file mode 100644
index 0000000..ad0876e
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample1.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.pswing;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JColorChooser;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.JTextArea;
+import javax.swing.JTree;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PZoomEventHandler;
+import org.piccolo2d.extras.pswing.PComboBox;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
+ */
+
+public class PSwingExample1 {
+ public static void main(final String[] args) {
+ final PSwingCanvas pCanvas = new PSwingCanvas();
+ final PText pText = new PText("PText");
+ pCanvas.getLayer().addChild(pText);
+ final JFrame frame = new JFrame("Test Piccolo");
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setContentPane(pCanvas);
+ frame.setSize(600, 800);
+ frame.setVisible(true);
+
+ final PText text2 = new PText("Text2");
+ text2.setFont(new Font("Lucida Sans", Font.BOLD, 18));
+ pCanvas.getLayer().addChild(text2);
+ text2.translate(100, 100);
+ text2.addInputEventListener(new PZoomEventHandler());
+
+ pCanvas.removeInputEventListener(pCanvas.getPanEventHandler());
+
+ final JButton jButton = new JButton("MyButton!");
+ jButton.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent e) {
+ System.out.println("TestZSwing.actionPerformed!!!!!!!!!!!!!!*********************");
+ }
+ });
+ final PSwing pSwing = new PSwing(jButton);
+ pCanvas.getLayer().addChild(pSwing);
+ pSwing.repaint();
+
+ final JSpinner jSpinner = new JSpinner();
+ jSpinner.setPreferredSize(new Dimension(100, jSpinner.getPreferredSize().height));
+ final PSwing pSpinner = new PSwing(jSpinner);
+ pCanvas.getLayer().addChild(pSpinner);
+ pSpinner.translate(0, 150);
+
+ final JCheckBox jcb = new JCheckBox("CheckBox", true);
+ jcb.addActionListener(new ActionListener() {
+ public void actionPerformed(final ActionEvent e) {
+ System.out.println("TestZSwing.JCheckBox.actionPerformed");
+ }
+ });
+ jcb.addChangeListener(new ChangeListener() {
+ public void stateChanged(final ChangeEvent e) {
+ System.out.println("TestPSwing.JChekbox.stateChanged@" + System.currentTimeMillis());
+ }
+ });
+ final PSwing pCheckBox = new PSwing(jcb);
+ pCanvas.getLayer().addChild(pCheckBox);
+ pCheckBox.translate(100, 0);
+
+ // Growable JTextArea
+ final JTextArea textArea = new JTextArea("This is a growable TextArea.\nTry it out!");
+ textArea.setBorder(new LineBorder(Color.blue, 3));
+ PSwing swing = new PSwing(textArea);
+ swing.translate(150, 150);
+ pCanvas.getLayer().addChild(swing);
+
+ // A Slider
+ final JSlider slider = new JSlider();
+ final PSwing pSlider = new PSwing(slider);
+ pSlider.translate(200, 200);
+ pCanvas.getLayer().addChild(pSlider);
+
+ // A Scrollable JTree
+ final JTree tree = new JTree();
+ tree.setEditable(true);
+ final JScrollPane p = new JScrollPane(tree);
+ p.setPreferredSize(new Dimension(150, 150));
+ final PSwing pTree = new PSwing(p);
+ pCanvas.getLayer().addChild(pTree);
+ pTree.translate(0, 250);
+
+ // A JColorChooser - also demonstrates JTabbedPane
+ final JColorChooser chooser = new JColorChooser();
+ final PSwing pChooser = new PSwing(chooser);
+ pCanvas.getLayer().addChild(pChooser);
+ pChooser.translate(100, 300);
+
+ final JPanel myPanel = new JPanel();
+ myPanel.setBorder(BorderFactory.createTitledBorder("Titled Border"));
+ myPanel.add(new JCheckBox("CheckBox"));
+ final PSwing panelSwing = new PSwing(myPanel);
+ pCanvas.getLayer().addChild(panelSwing);
+ panelSwing.translate(400, 50);
+
+ // A Slider
+ final JSlider slider2 = new JSlider();
+ final PSwing pSlider2 = new PSwing(slider2);
+ pSlider2.translate(200, 200);
+ final PNode root = new PNode();
+ root.addChild(pSlider2);
+ root.scale(1.5);
+ root.rotate(Math.PI / 4);
+ root.translate(300, 200);
+ pCanvas.getLayer().addChild(root);
+
+ // A Combo Box
+ final JPanel comboPanel = new JPanel();
+ comboPanel.setBorder(BorderFactory.createTitledBorder("Combo Box"));
+ final String[] listItems = { "Summer Teeth", "Mermaid Avenue", "Being There", "A.M." };
+ final PComboBox box = new PComboBox(listItems);
+ comboPanel.add(box);
+ swing = new PSwing(comboPanel);
+ swing.translate(200, 230);
+ pCanvas.getLayer().addChild(swing);
+ box.setEnvironment(swing, pCanvas);// has to be done manually at present
+
+ // Revalidate and repaint
+ pCanvas.revalidate();
+ pCanvas.repaint();
+
+ pCanvas.getCamera().animateViewToCenterBounds(pCanvas.getLayer().getFullBounds(), true, 1200);
+ }
+
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample2.java b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample2.java
new file mode 100644
index 0000000..a373e70
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample2.java
@@ -0,0 +1,519 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.pswing;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.util.Vector;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JToolBar;
+import javax.swing.JTree;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+import javax.swing.border.LineBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.table.TableColumn;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+
+
+/**
+ * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
+ */
+
+public class PSwingExample2 extends JFrame {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public PSwingExample2() {
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ ClassLoader loader;
+ PSwingCanvas canvas;
+
+ // Set up basic frame
+ setBounds(50, 50, 750, 750);
+ setResizable(true);
+ setBackground(null);
+ setVisible(true);
+ canvas = new PSwingCanvas();
+ canvas.setPanEventHandler(null);
+ getContentPane().add(canvas);
+ validate();
+ loader = getClass().getClassLoader();
+
+ ZVisualLeaf leaf;
+ PNode transform;
+ PSwing swing;
+ PSwing swing2;
+
+ // JButton
+ final JButton button = new JButton("Button");
+ button.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
+ swing = new PSwing(button);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-500, -500);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // JButton
+ final JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 10, 1));
+ spinner.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
+ swing = new PSwing(spinner);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-800, -500);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // 2nd Copy of JButton
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-450, -450);
+ transform.rotate(Math.PI / 2);
+ transform.scale(0.5);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // Growable JTextArea
+ final JTextArea textArea = new JTextArea("This is a growable TextArea.\nTry it out!");
+ textArea.setBorder(new LineBorder(Color.blue, 3));
+ swing = new PSwing(textArea);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-250, -500);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // Growable JTextField
+ JTextField textField = new JTextField("A growable text field");
+ swing = new PSwing(textField);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(0, -500);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // A Slider
+ final JSlider slider = new JSlider();
+ swing = new PSwing(slider);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(250, -500);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // A Scrollable JTree
+ final JTree tree = new JTree();
+ tree.setEditable(true);
+ final JScrollPane p = new JScrollPane(tree);
+ p.setPreferredSize(new Dimension(150, 150));
+ swing = new PSwing(p);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-500, -250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // A Scrollable JTextArea
+ JScrollPane pane = new JScrollPane(new JTextArea("A Scrollable Text Area\nTry it out!"));
+ pane.setPreferredSize(new Dimension(150, 150));
+ swing = new PSwing(pane);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-250, -250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+ swing2 = swing;
+
+ // A non-scrollable JTextField
+ // A panel MUST be created with double buffering off
+ JPanel panel = new JPanel(false);
+ textField = new JTextField("A fixed-size text field");
+ panel.setLayout(new BorderLayout());
+ panel.add(textField);
+ swing = new PSwing(panel);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(0, -250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // // A JComboBox
+ // String[] listItems = {"Summer Teeth", "Mermaid Avenue",
+ // "Being There", "A.M."};
+ // ZComboBox box = new ZComboBox( listItems );
+ // swing = new PSwing( canvas, box );
+ // leaf = new ZVisualLeaf( swing );
+ // transform = new PNode();
+ // transform.translate( 0, -150 );
+ // transform.addChild( leaf );
+ // canvas.getLayer().addChild( transform );
+
+ // A panel with TitledBorder and JList
+ panel = new JPanel(false);
+ panel.setBackground(Color.lightGray);
+ panel.setLayout(new BorderLayout());
+ panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED), "A JList", TitledBorder.LEFT,
+ TitledBorder.TOP));
+ panel.setPreferredSize(new Dimension(200, 200));
+ final Vector data = new Vector();
+ data.addElement("Choice 1");
+ data.addElement("Choice 2");
+ data.addElement("Choice 3");
+ data.addElement("Choice 4");
+ data.addElement("Choice 5");
+ final JList list = new JList(data);
+ list.setBackground(Color.lightGray);
+ panel.add(list);
+ swing = new PSwing(panel);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(250, -250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // A JLabel
+ JLabel label = new JLabel("A JLabel", SwingConstants.CENTER);
+ swing = new PSwing(label);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-500, 0);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ label = new JLabel("A JLabel", SwingConstants.CENTER);
+ label.setIcon(new Icon() {
+
+ public int getIconHeight() {
+ return 20;
+ }
+
+ public int getIconWidth() {
+ return 20;
+ }
+
+ public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
+ g.setColor(Color.BLUE);
+ g.drawRect(0, 0, 20, 20);
+ }
+ });
+ swing = new PSwing(label);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-500, 30);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // Rotated copy of the Scrollable JTextArea
+ leaf = new ZVisualLeaf(swing2);
+ transform = new PNode();
+ transform.translate(-100, 0);
+ transform.rotate(Math.PI / 2);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // A panel with layout
+ // A panel MUST be created with double buffering off
+ panel = new JPanel(false);
+ panel.setLayout(new BorderLayout());
+ final JButton button1 = new JButton("Button 1");
+ final JButton button2 = new JButton("Button 2");
+ label = new JLabel("A Panel with Layout");
+ label.setHorizontalAlignment(SwingConstants.CENTER);
+ label.setForeground(Color.white);
+ panel.setBackground(Color.red);
+ panel.setPreferredSize(new Dimension(150, 150));
+ panel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ panel.add(button1, "North");
+ panel.add(button2, "South");
+ panel.add(label, "Center");
+ panel.revalidate();
+ swing = new PSwing(panel);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(0, 0);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // JTable Example
+ final Vector columns = new Vector();
+ columns.addElement("Check Number");
+ columns.addElement("Description");
+ columns.addElement("Amount");
+ final Vector rows = new Vector();
+ Vector row = new Vector();
+ row.addElement("101");
+ row.addElement("Sandwich");
+ row.addElement("$20.00");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("102");
+ row.addElement("Monkey Wrench");
+ row.addElement("$100.00");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("214");
+ row.addElement("Ant farm");
+ row.addElement("$55.00");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("215");
+ row.addElement("Self-esteem tapes");
+ row.addElement("$37.99");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("216");
+ row.addElement("Tube Socks");
+ row.addElement("$7.45");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("220");
+ row.addElement("Ab Excerciser");
+ row.addElement("$56.95");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("319");
+ row.addElement("Y2K Supplies");
+ row.addElement("$4624.33");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("332");
+ row.addElement("Tie Rack");
+ row.addElement("$15.20");
+ rows.addElement(row);
+ row = new Vector();
+ row.addElement("344");
+ row.addElement("Swing Set");
+ row.addElement("$146.59");
+ rows.addElement(row);
+ final JTable table = new JTable(rows, columns);
+ table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ table.setRowHeight(30);
+ TableColumn c = table.getColumn(table.getColumnName(0));
+ c.setPreferredWidth(150);
+ c = table.getColumn(table.getColumnName(1));
+ c.setPreferredWidth(150);
+ c = table.getColumn(table.getColumnName(2));
+ c.setPreferredWidth(150);
+ pane = new JScrollPane(table);
+ pane.setPreferredSize(new Dimension(200, 200));
+ table.setDoubleBuffered(false);
+ swing = new PSwing(pane);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(250, 0);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // JEditorPane - HTML example
+ try {
+
+ final JEditorPane editorPane = new JEditorPane(loader.getResource("csdept.html"));
+ editorPane.setDoubleBuffered(false);
+ editorPane.setEditable(false);
+ pane = new JScrollPane(editorPane);
+ pane.setDoubleBuffered(false);
+ pane.setPreferredSize(new Dimension(400, 400));
+ editorPane.addHyperlinkListener(new HyperlinkListener() {
+ public void hyperlinkUpdate(final HyperlinkEvent e) {
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ try {
+ editorPane.setPage(e.getURL());
+ }
+ catch (final IOException ioe) {
+ System.out.println("Couldn't Load Web Page");
+ }
+ }
+ }
+ });
+ swing = new PSwing(pane);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-500, 250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ }
+ catch (final IOException ioe) {
+ System.out.println("Couldn't Load Web Page");
+ }
+
+ // A JInternalFrame with a JSplitPane - a JOptionPane - and a
+ // JToolBar
+ final JInternalFrame iframe = new JInternalFrame("JInternalFrame");
+ iframe.getRootPane().setDoubleBuffered(false);
+ ((JComponent) iframe.getContentPane()).setDoubleBuffered(false);
+ iframe.setPreferredSize(new Dimension(500, 500));
+ final JTabbedPane tabby = new JTabbedPane();
+ tabby.setDoubleBuffered(false);
+ iframe.getContentPane().setLayout(new BorderLayout());
+ final JOptionPane options = new JOptionPane("This is a JOptionPane!", JOptionPane.INFORMATION_MESSAGE,
+ JOptionPane.DEFAULT_OPTION);
+ options.setDoubleBuffered(false);
+ options.setMinimumSize(new Dimension(50, 50));
+ options.setPreferredSize(new Dimension(225, 225));
+ final JPanel tools = new JPanel(false);
+ tools.setMinimumSize(new Dimension(150, 150));
+ tools.setPreferredSize(new Dimension(225, 225));
+ final JToolBar bar = new JToolBar();
+ final Action letter = new AbstractAction("Big A!") {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(final ActionEvent e) {
+ }
+ };
+
+ final Action hand = new AbstractAction("Hi!") {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(final ActionEvent e) {
+ }
+ };
+ final Action select = new AbstractAction("There!") {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void actionPerformed(final ActionEvent e) {
+ }
+ };
+
+ label = new JLabel("A Panel with a JToolBar");
+ label.setHorizontalAlignment(SwingConstants.CENTER);
+ bar.add(letter);
+ bar.add(hand);
+ bar.add(select);
+ bar.setFloatable(false);
+ bar.setBorder(new LineBorder(Color.black, 2));
+ tools.setLayout(new BorderLayout());
+ tools.add(bar, "North");
+ tools.add(label, "Center");
+
+ final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, options, tools);
+ split.setDoubleBuffered(false);
+ iframe.getContentPane().add(split);
+ swing = new PSwing(iframe);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(0, 250);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // JMenuBar menuBar = new JMenuBar();
+ // ZMenu menu = new ZMenu( "File" );
+ // ZMenu sub = new ZMenu( "Export" );
+ // JMenuItem gif = new JMenuItem( "Funds" );
+ // sub.add( gif );
+ // menu.add( sub );
+ // menuBar.add( menu );
+ // iframe.setJMenuBar( menuBar );
+
+ iframe.setVisible(true);
+
+ // A JColorChooser - also demonstrates JTabbedPane
+ // JColorChooser chooser = new JColorChooser();
+ final JCheckBox chooser = new JCheckBox("Check Box");
+ swing = new PSwing(chooser);
+ leaf = new ZVisualLeaf(swing);
+ transform = new PNode();
+ transform.translate(-250, 850);
+ transform.addChild(leaf);
+ canvas.getLayer().addChild(transform);
+
+ // Revalidate and repaint
+ canvas.revalidate();
+ canvas.repaint();
+
+ final PSwing message = new PSwing(new JTextArea("Click-drag to zoom in and out."));
+ message.translate(0, -50);
+ canvas.getLayer().addChild(message);
+
+ canvas.getCamera().animateViewToCenterBounds(canvas.getLayer().getFullBounds(), true, 1200);
+ }
+
+ public static void main(final String[] args) {
+ new PSwingExample2().setVisible(true);
+ }
+
+ public static class ZVisualLeaf extends PNode {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public ZVisualLeaf(final PNode node) {
+ addChild(node);
+ }
+ }
+
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample3.java b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample3.java
new file mode 100644
index 0000000..bda0fc4
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingExample3.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.pswing;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.SwingUtilities;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * User: Sam Reid Date: Jul 11, 2005 Time: 12:15:55 PM
+ */
+public class PSwingExample3 extends JFrame {
+ private static final long serialVersionUID = 1L;
+
+ public PSwingExample3() {
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ // Set up basic frame
+ setBounds(50, 50, 750, 750);
+ setResizable(true);
+ setBackground(null);
+ setVisible(true);
+ final PSwingCanvas canvas = new PSwingCanvas();
+ getContentPane().add(canvas);
+ validate();
+
+ ExampleGrid exampleGrid = new ExampleGrid(3);
+ exampleGrid.addChild(createButtonExamples());
+ exampleGrid.addChild(createSimpleComponentExamples());
+ canvas.getLayer().addChild(exampleGrid);
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ canvas.getCamera().animateViewToCenterBounds(canvas.getLayer().getFullBounds(), true, 1200);
+ }
+
+ });
+
+ }
+
+ private ExampleList createSimpleComponentExamples() {
+ ExampleList exampleList = new ExampleList("Simple Components");
+ exampleList.addExample("JLabel", new PSwing(new JLabel("JLabel Example")));
+ exampleList.addExample("JCheckBox ", new PSwing(new JCheckBox()));
+
+ JRadioButton radio1 = new JRadioButton("Radio Option 1");
+ JRadioButton radio2 = new JRadioButton("Radio Option 1");
+ ButtonGroup buttonGroup = new ButtonGroup();
+ buttonGroup.add(radio1);
+ buttonGroup.add(radio2);
+ exampleList.addExample("RadioButton 1", radio1);
+ exampleList.addExample("RadioButton 2", radio2);
+
+ JPanel examplePanel = new JPanel() {
+
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ g.setColor(Color.RED);
+ g.fillRect(0, 0, getWidth(), getHeight());
+
+ }
+ };
+ examplePanel.setPreferredSize(new Dimension(50, 50));
+
+ exampleList.addExample("Custom JPanel ", examplePanel);
+ return exampleList;
+ }
+
+ private ExampleList createButtonExamples() {
+ ExampleList exampleList = new ExampleList("Button Examples");
+ addButtonAloneNoSizing(exampleList);
+ addButtonAlone200x50(exampleList);
+ addButtonOnPanelNoSizing(exampleList);
+ addButtonOnPanel200x50(exampleList);
+ addButtonAlone10x10(exampleList);
+ return exampleList;
+ }
+
+ private void addButtonAloneNoSizing(ExampleList exampleList) {
+ JButton button = new JButton("Button");
+ PSwing pButton = new PSwing(button);
+ exampleList.addExample("Alone - No Sizing", pButton);
+ }
+
+ private void addButtonAlone200x50(ExampleList exampleList) {
+ JButton button = new JButton("Button");
+ button.setPreferredSize(new Dimension(200, 50));
+ PSwing pButton = new PSwing(button);
+ exampleList.addExample("Alone - 200x50", pButton);
+ }
+
+ private void addButtonAlone10x10(ExampleList exampleList) {
+ JButton button = new JButton("Button");
+ button.setPreferredSize(new Dimension(10, 10));
+ PSwing pButton = new PSwing(button);
+ exampleList.addExample("Alone - 10x10", pButton);
+ }
+
+ private void addButtonOnPanelNoSizing(ExampleList exampleList) {
+ JButton button = new JButton("Button");
+ JPanel panel = new JPanel();
+ panel.add(button);
+ PSwing pPanel = new PSwing(panel);
+
+ exampleList.addExample("On JPanel - No Sizing", pPanel);
+ }
+
+ private void addButtonOnPanel200x50(ExampleList exampleList) {
+ JButton button = new JButton("Button");
+ button.setPreferredSize(new Dimension(200, 50));
+
+ JPanel panel = new JPanel();
+ panel.add(button);
+ PSwing pPanel = new PSwing(panel);
+
+ exampleList.addExample("On JPanel - 200x50", pPanel);
+ }
+
+ public static void main(final String[] args) {
+ new PSwingExample3().setVisible(true);
+ }
+
+ class ExampleGrid extends PNode {
+ private int columns;
+
+ public ExampleGrid(int columns) {
+ this.columns = columns;
+ }
+
+ public void layoutChildren() {
+ double[] colWidths = calculateColumnWidths();
+
+ double currentY = 0;
+ for (int i = 0; i < getChildrenCount(); i++) {
+ PNode child = getChild(i);
+ child.setOffset(colWidths[i % columns] * 1.25, currentY * 1.25);
+ if (i % columns == 0 && i > 0) {
+ currentY = getFullBounds().getHeight();
+ }
+ }
+ }
+
+ private double[] calculateColumnWidths() {
+ double[] colWidths = new double[columns];
+ for (int i = 0; i < getChildrenCount(); i++) {
+ PNode child = getChild(i);
+ colWidths[i % columns] = Math.max(colWidths[i % columns], child.getFullBounds().getWidth()
+ * child.getScale());
+ }
+ return colWidths;
+ }
+ }
+
+ class ExampleList extends PText {
+ ExampleList(String name) {
+ super(name);
+ setScale(2);
+ }
+
+ public void layoutChildren() {
+ PNode node;
+ double currentY = getHeight();
+ for (int i = 0; i < getChildrenCount(); i++) {
+ node = getChild(i);
+ node.setOffset(0, currentY);
+ currentY += node.getFullBounds().getHeight() + 5;
+ }
+ }
+
+ public void addExample(String name, PNode example) {
+ ExampleNode exampleNode = new ExampleNode(name, example);
+ exampleNode.setScale(0.5);
+ addChild(exampleNode);
+ }
+
+ public void addExample(String name, JComponent example) {
+ addExample(name, new PSwing(example));
+ }
+
+ class ExampleNode extends PText {
+ ExampleNode(String name, PNode example) {
+ super(name);
+
+ addChild(example);
+ }
+
+ public void layoutChildren() {
+ PNode example = getChild(0);
+ example.setOffset(getWidth() + 5, 0);
+ // example.setScale(getHeight() / example.getHeight());
+ }
+ }
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingMemoryLeakExample.java b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingMemoryLeakExample.java
new file mode 100644
index 0000000..9d84dc2
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/examples/pswing/PSwingMemoryLeakExample.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.examples.pswing;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.Timer;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.extras.pswing.PSwing;
+import org.piccolo2d.extras.pswing.PSwingCanvas;
+import org.piccolo2d.nodes.PText;
+
+
+/**
+ * Attempt to replicate the PSwingRepaintManager-related memory leak reported in
+ * Issue 74.
+ */
+public final class PSwingMemoryLeakExample extends JFrame {
+
+ /** Default serial version UID. */
+ private static final long serialVersionUID = 1L;
+
+ /** Active instances. */
+ private final PText active;
+
+ /** Finalized instances. */
+ private final PText finalized;
+
+ /** Free memory. */
+ private final PText freeMemory;
+
+ /** Total memory. */
+ private final PText totalMemory;
+
+ /** Used memory. */
+ private final PText usedMemory;
+
+ /** Canvas. */
+ private final PCanvas canvas;
+
+ /** Main panel, container for PSwingCanvases. */
+ private final JPanel mainPanel;
+
+ /**
+ * Create a new PSwing memory leak example.
+ */
+ public PSwingMemoryLeakExample() {
+ super("PSwing memory leak example");
+
+ final PText label0 = new PText("Number of active PSwingCanvases:");
+ active = new PText("0");
+ final PText label4 = new PText("Number of finalized PSwingCanvases:");
+ finalized = new PText("0");
+ final PText label1 = new PText("Total memory:");
+ totalMemory = new PText("0");
+ final PText label2 = new PText("Free memory:");
+ freeMemory = new PText("0");
+ final PText label3 = new PText("Used memory:");
+ usedMemory = new PText("0");
+
+ label0.offset(20.0d, 20.0d);
+ active.offset(label0.getFullBounds().getWidth() + 50.0d, 20.0d);
+ label4.offset(20.0d, 40.0d);
+ finalized.offset(label4.getFullBounds().getWidth() + 50.0d, 40.0d);
+ label1.offset(20.0d, 60.0d);
+ totalMemory.offset(label1.getFullBounds().getWidth() + 40.0d, 60.0d);
+ label2.offset(20.0d, 80.0d);
+ freeMemory.offset(label2.getFullBounds().getWidth() + 40.0d, 80.0d);
+ label3.offset(freeMemory.getFullBounds().getX() + 80.0d, 80.0d);
+ usedMemory.offset(label3.getFullBounds().getX() + label3.getFullBounds().getWidth() + 20.0d, 80.0d);
+
+ canvas = new PCanvas();
+ canvas.getCamera().addChild(label0);
+ canvas.getCamera().addChild(active);
+ canvas.getCamera().addChild(label4);
+ canvas.getCamera().addChild(finalized);
+ canvas.getCamera().addChild(label1);
+ canvas.getCamera().addChild(totalMemory);
+ canvas.getCamera().addChild(label2);
+ canvas.getCamera().addChild(freeMemory);
+ canvas.getCamera().addChild(label3);
+ canvas.getCamera().addChild(usedMemory);
+ canvas.setPreferredSize(new Dimension(400, 110));
+
+ mainPanel = new JPanel();
+ mainPanel.setPreferredSize(new Dimension(400, 290));
+ mainPanel.setLayout(new FlowLayout());
+
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add("North", canvas);
+ getContentPane().add("Center", mainPanel);
+
+ final Timer add = new Timer(10, new ActionListener() {
+ int id = 0;
+
+ /** {@inheritDoc} */
+ public void actionPerformed(final ActionEvent e) {
+ final JLabel label = new JLabel("Label" + id);
+ final PSwing pswing = new PSwing(label);
+ final PSwingCanvas pswingCanvas = new PSwingCanvas() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** {@inheritDoc} */
+ public void finalize() {
+ incrementFinalized();
+ }
+ };
+ pswingCanvas.getLayer().addChild(pswing);
+ pswingCanvas.setPreferredSize(new Dimension(60, 18));
+ mainPanel.add(pswingCanvas);
+ mainPanel.invalidate();
+ mainPanel.validate();
+ mainPanel.repaint();
+
+ id++;
+ incrementActive();
+ }
+ });
+ add.setDelay(5);
+ add.setRepeats(true);
+
+ final Timer remove = new Timer(20000, new ActionListener() {
+ /** {@inheritDoc} */
+ public void actionPerformed(final ActionEvent e) {
+ if (add.isRunning()) {
+ add.stop();
+ }
+ final int i = mainPanel.getComponentCount() - 1;
+ if (i > 0) {
+ mainPanel.remove(mainPanel.getComponentCount() - 1);
+ mainPanel.invalidate();
+ mainPanel.validate();
+ mainPanel.repaint();
+ decrementActive();
+ }
+ }
+ });
+ remove.setDelay(5);
+ remove.setRepeats(true);
+
+ final Timer updateMemory = new Timer(500, new ActionListener() {
+ /** {@inheritDoc} */
+ public void actionPerformed(final ActionEvent e) {
+ updateMemory();
+ }
+ });
+ updateMemory.setDelay(2000);
+ updateMemory.setRepeats(true);
+
+ add.start();
+ remove.start();
+ updateMemory.start();
+
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setBounds(100, 100, 400, 400);
+ setVisible(true);
+ }
+
+ /**
+ * Increment active.
+ */
+ private void incrementActive() {
+ int count = Integer.parseInt(active.getText());
+ count++;
+ active.setText(String.valueOf(count));
+ canvas.repaint();
+ }
+
+ /**
+ * Decrement active.
+ */
+ private void decrementActive() {
+ int count = Integer.parseInt(active.getText());
+ count--;
+ active.setText(String.valueOf(count));
+ canvas.repaint();
+ }
+
+ /**
+ * Increment finalized.
+ */
+ private void incrementFinalized() {
+ int count = Integer.parseInt(finalized.getText());
+ count++;
+ finalized.setText(String.valueOf(count));
+ canvas.repaint();
+ }
+
+ /**
+ * Update memory.
+ */
+ private void updateMemory() {
+ new Thread(new Runnable() {
+ /** {@inheritDoc} */
+ public void run() {
+ System.gc();
+ System.runFinalization();
+ }
+ }).run();
+
+ final long total = Runtime.getRuntime().totalMemory();
+ totalMemory.setText(String.valueOf(total));
+ final long free = Runtime.getRuntime().freeMemory();
+ freeMemory.setText(String.valueOf(free));
+ final long used = total - free;
+ usedMemory.setText(String.valueOf(used));
+ canvas.repaint();
+ }
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ SwingUtilities.invokeLater(new Runnable() {
+ /** {@inheritDoc} */
+ public void run() {
+ new PSwingMemoryLeakExample();
+ }
+ });
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/tutorial/InterfaceFrame.java b/examples/src/main/java/org/piccolo2d/tutorial/InterfaceFrame.java
new file mode 100644
index 0000000..490e8b1
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/tutorial/InterfaceFrame.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.tutorial;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PDragEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PImage;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PPaintContext;
+
+
+public class InterfaceFrame extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ 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.
+ final PNode aNode = new PNode();
+
+ // A node will not be visible until its bounds and brush are set.
+ aNode.setBounds(0, 0, 100, 80);
+ aNode.setPaint(Color.RED);
+
+ // A node needs to be a descendent of the root to be displayed.
+ final PLayer layer = getCanvas().getLayer();
+ layer.addChild(aNode);
+
+ // A node can have child nodes added to it.
+ final 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);
+
+ // 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.
+ final PImage image = new PImage(layer.toImage(300, 300, null));
+ layer.addChild(image);
+
+ // Create a New Node using Composition
+
+ final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
+
+ // Create parts for the face.
+ final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
+ eye1.setPaint(Color.YELLOW);
+ final PNode eye2 = (PNode) eye1.clone();
+ final 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.
+ final 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.
+ final ToggleShape ts = new ToggleShape();
+ ts.setPaint(Color.ORANGE);
+ layer.addChild(ts);
+ }
+
+ class ToggleShape extends PPath {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private boolean fIsPressed = false;
+
+ public ToggleShape() {
+ setPathToEllipse(0, 0, 100, 80);
+
+ addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(final PInputEvent event) {
+ super.mousePressed(event);
+ fIsPressed = true;
+ repaint();
+ }
+
+ public void mouseReleased(final PInputEvent event) {
+ super.mouseReleased(event);
+ fIsPressed = false;
+ repaint();
+ }
+ });
+ }
+
+ protected void paint(final PPaintContext paintContext) {
+ if (fIsPressed) {
+ final Graphics2D g2 = paintContext.getGraphics();
+ g2.setPaint(getPaint());
+ g2.fill(getBoundsReference());
+ }
+ else {
+ super.paint(paintContext);
+ }
+ }
+ }
+
+ public static void main(final String[] args) {
+ new InterfaceFrame();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java b/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java
new file mode 100644
index 0000000..c46703f
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.tutorial;
+
+import java.awt.Color;
+import java.awt.event.KeyEvent;
+import java.awt.geom.AffineTransform;
+import java.io.File;
+import java.util.ArrayList;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PImage;
+
+
+public class PiccoloPresentation extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ protected PNode slideBar;
+ protected PNode currentSlide;
+ protected PBasicInputEventHandler eventHandler;
+ protected ArrayList slides = new ArrayList();
+
+ public PiccoloPresentation() {
+ super();
+ }
+
+ public void initialize() {
+ setFullScreenMode(true);
+ loadSlides();
+
+ eventHandler = new PBasicInputEventHandler() {
+ public void keyReleased(final PInputEvent event) {
+ if (event.getKeyCode() == KeyEvent.VK_SPACE) {
+ final int newIndex = slides.indexOf(currentSlide) + 1;
+ if (newIndex < slides.size()) {
+ goToSlide((PNode) slides.get(newIndex));
+ }
+ }
+ }
+
+ public void mouseReleased(final PInputEvent event) {
+ final PNode picked = event.getPickedNode();
+
+ 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());
+ }
+
+ public void goToSlide(final 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);
+
+ final 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(final String[] argv) {
+ new PiccoloPresentation();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/tutorial/SpecialEffects.java b/examples/src/main/java/org/piccolo2d/tutorial/SpecialEffects.java
new file mode 100644
index 0000000..120a3e6
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/tutorial/SpecialEffects.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.tutorial;
+
+import java.awt.Color;
+
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PNode;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+
+
+public class SpecialEffects extends PFrame {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ 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);
+ final PLayer layer = getCanvas().getLayer();
+ layer.addChild(aNode);
+ aNode.setOffset(200, 200);
+
+ // Extend PActivity.
+
+ // Store the current time in milliseconds for use below.
+ final long currentTime = System.currentTimeMillis();
+
+ // 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.
+ final PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
+ boolean fRed = true;
+
+ protected void activityStep(final 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.
+ final PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
+ final PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
+ final 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(final PActivity activity) {
+ System.out.println("a1 started");
+ }
+
+ public void activityStepped(final PActivity activity) {
+ }
+
+ public void activityFinished(final PActivity activity) {
+ System.out.println("a1 finished");
+ }
+ });
+ }
+
+ public static void main(final String[] args) {
+ new SpecialEffects();
+ }
+}
diff --git a/examples/src/main/java/org/piccolo2d/tutorial/UserInteraction.java b/examples/src/main/java/org/piccolo2d/tutorial/UserInteraction.java
new file mode 100644
index 0000000..1857d3b
--- /dev/null
+++ b/examples/src/main/java/org/piccolo2d/tutorial/UserInteraction.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.tutorial;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.geom.Point2D;
+
+import org.piccolo2d.PCanvas;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.event.PInputEventFilter;
+import org.piccolo2d.extras.PFrame;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PDimension;
+
+
+public class UserInteraction extends PFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public UserInteraction() {
+ super();
+ }
+
+ 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);
+
+ // Create a squiggle handler and register it with the Canvas.
+ final PBasicInputEventHandler squiggleHandler = new SquiggleHandler(getCanvas());
+ getCanvas().addInputEventListener(squiggleHandler);
+
+ // Create a Node Event Listener.
+
+ // Create a green rectangle node.
+ final PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
+ nodeGreen.setPaint(Color.GREEN);
+ getCanvas().getLayer().addChild(nodeGreen);
+
+ // Attach event handler directly to the node.
+ nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
+ public void mousePressed(final PInputEvent event) {
+ event.getPickedNode().setPaint(Color.ORANGE);
+ event.getInputManager().setKeyboardFocus(event.getPath());
+ event.setHandled(true);
+ }
+
+ public void mouseDragged(final PInputEvent event) {
+ final PNode aNode = event.getPickedNode();
+ final PDimension delta = event.getDeltaRelativeTo(aNode);
+ aNode.translate(delta.width, delta.height);
+ event.setHandled(true);
+ }
+
+ public void mouseReleased(final PInputEvent event) {
+ event.getPickedNode().setPaint(Color.GREEN);
+ event.setHandled(true);
+ }
+
+ public void keyPressed(final PInputEvent event) {
+ final 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 class SquiggleHandler extends PDragSequenceEventHandler {
+ protected PCanvas canvas;
+
+ // The squiggle that is currently getting created.
+ protected PPath squiggle;
+
+ public SquiggleHandler(final PCanvas aCanvas) {
+ canvas = aCanvas;
+ setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
+ }
+
+ public void startDrag(final PInputEvent e) {
+ super.startDrag(e);
+
+ final 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(final PInputEvent e) {
+ super.drag(e);
+ // Update the squiggle while dragging.
+ updateSquiggle(e);
+ }
+
+ public void endDrag(final PInputEvent e) {
+ super.endDrag(e);
+ // Update the squiggle one last time.
+ updateSquiggle(e);
+ squiggle = null;
+ }
+
+ public void updateSquiggle(final PInputEvent aEvent) {
+ // Add a new segment to the squiggle from the last mouse position
+ // to the current mouse position.
+ final Point2D p = aEvent.getPosition();
+ squiggle.lineTo((float) p.getX(), (float) p.getY());
+ }
+ }
+
+ public static void main(final String[] args) {
+ new UserInteraction();
+ }
+}
diff --git a/examples/src/main/resources/edu/umd/cs/piccolo/examples/texture.png b/examples/src/main/resources/edu/umd/cs/piccolo/examples/texture.png
deleted file mode 100755
index 611033f..0000000
--- a/examples/src/main/resources/edu/umd/cs/piccolo/examples/texture.png
+++ /dev/null
Binary files differ
diff --git a/examples/src/main/resources/org/piccolo2d/examples/texture.png b/examples/src/main/resources/org/piccolo2d/examples/texture.png
new file mode 100755
index 0000000..611033f
--- /dev/null
+++ b/examples/src/main/resources/org/piccolo2d/examples/texture.png
Binary files differ
diff --git a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java
deleted file mode 100644
index edfe675..0000000
--- a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolox.swt.examples;
-
-import java.awt.Color;
-
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.piccolo2d.extras.swt.PSWTCanvas;
-import org.piccolo2d.extras.swt.PSWTPath;
-import org.piccolo2d.extras.swt.PSWTText;
-
-
-public final class SWTBasicExample {
-
- /**
- * Create and open a new shell on the specified display.
- *
- * @param display display
- * @return a new shell on the specified display
- */
- public static Shell open(final Display display) {
- final Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
-
- // create a new SWT canvas
- final PSWTCanvas canvas = new PSWTCanvas(shell, 0);
-
- // create some SWT nodes
- // and add them as child nodes to the canvas' camera's first layer
- 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\nMultiline");
- text.translate(350, 150);
- text.setPenColor(Color.GRAY);
- text.setBackgroundColor(Color.BLACK);
- 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 void main(final String[] args) {
- final Display display = new Display();
- final Shell shell = open(display);
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
-}
diff --git a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBenchTest.java b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBenchTest.java
deleted file mode 100644
index 5e407d2..0000000
--- a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBenchTest.java
+++ /dev/null
@@ -1,480 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolox.swt.examples;
-
-import java.awt.AlphaComposite;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.util.Random;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.piccolo2d.extras.swt.SWTGraphics2D;
-
-
-/**
- * Piccolo2D SWT benchmarking test suite.
- */
-public class SWTBenchTest extends Canvas {
-
- // Paths
- private GeneralPath testShape = new GeneralPath();
-
- // Images
- private Image testImageOpaque;
- private Image testImageBitmask;
- private Image testImageTranslucent;
- private Image testImageARGB;
-
- // Transforms
- private AffineTransform transform = new AffineTransform();
- private static final AffineTransform IDENTITY = new AffineTransform();
-
- // Geometry
- private double pts[] = new double[20];
-
- // Colors
- private static final Color colors[] = { Color.RED, Color.GREEN, Color.BLUE, Color.WHITE, Color.YELLOW, };
-
- // Flags
- private boolean offscreen;
- private boolean antialiased;
-
- // Statistics
- private int results[][] = new int[NUM_CONTEXTS][NUM_TESTS];
-
- // Constants
-
- private static final int CTX_NORMAL = 0;
- // private static final int CTX_CLIPPED = 1;
- private static final int CTX_TRANSFORMED = 1;
- // private static final int CTX_BLENDED = 3;
- private static final int NUM_CONTEXTS = 2;
-
- // private static String contextNames[] = {
- // "normal",
- // "clip",
- // "transform",
- // "alpha",
- // };
-
- private static String contextNames[] = { "normal", "transform" };
-
- //
- // TEST METHODS
- //
-
- private static final int DRAW_LINE = 0;
- private static final int DRAW_RECT = 1;
- private static final int FILL_RECT = 2;
- private static final int DRAW_OVAL = 3;
- private static final int FILL_OVAL = 4;
- private static final int DRAW_POLY = 5;
- private static final int FILL_POLY = 6;
- private static final int DRAW_TEXT = 7;
- private static final int DRAW_IMG1 = 8;
- private static final int DRAW_IMG2 = 9;
- private static final int DRAW_IMG3 = 10;
- private static final int DRAW_IMG4 = 11;
- private static final int DRAW_IMG5 = 12;
- private static final int NUM_TESTS = 13;
-
- private static String testNames[] = { "line", "rect", "fill rect", "oval", "fill oval", "poly", "fill poly", "text",
- "image", "scaled image", "mask image", "alpha image", "argb image", };
-
- private void testDrawLine(final SWTGraphics2D g, final Random r) {
- g.drawLine(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void testDrawRect(final SWTGraphics2D g, final Random r) {
- g.drawRect(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void testFillRect(final SWTGraphics2D g, final Random r) {
- g.fillRect(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void testDrawOval(final SWTGraphics2D g, final Random r) {
- g.drawOval(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void testFillOval(final SWTGraphics2D g, final Random r) {
- g.fillOval(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void genPoly(final Random r) {
- for (int i = 0; i < pts.length / 2; i++) {
- pts[2 * i] = rand(r);
- pts[2 * i + 1] = rand(r);
- }
- }
-
- private void testDrawPoly(final SWTGraphics2D g, final Random r) {
- genPoly(r);
- g.drawPolyline(pts);
- }
-
- private void testFillPoly(final SWTGraphics2D g, final Random r) {
- genPoly(r);
- g.fillPolygon(pts);
- }
-
- private void testDrawText(final SWTGraphics2D g, final Random r) {
- g.drawString("Abcdefghijklmnop", rand(r), rand(r));
- }
-
- // Basic image
- private void testDrawImg1(final SWTGraphics2D g, final Random r) {
- g.drawImage(testImageOpaque, rand(r), rand(r));
- }
-
- // Scaled image
- private void testDrawImg2(final SWTGraphics2D g, final Random r) {
- final Rectangle rect = testImageOpaque.getBounds();
- g.drawImage(testImageOpaque, 0, 0, rect.width, rect.height, rand(r), rand(r), rand(r), rand(r));
- }
-
- // Bitmask image (unscaled)
- private void testDrawImg3(final SWTGraphics2D g, final Random r) {
- g.drawImage(testImageBitmask, rand(r), rand(r));
- }
-
- // Translucent image (unscaled)
- private void testDrawImg4(final SWTGraphics2D g, final Random r) {
- g.drawImage(testImageTranslucent, rand(r), rand(r));
- }
-
- // Buffered image (unscaled)
- private void testDrawImg5(final SWTGraphics2D g, final Random r) {
- g.drawImage(testImageARGB, rand(r), rand(r));
- }
-
- private static Image loadImage(final Display display, final String name) {
- InputStream stream = null;
- try {
- stream = SWTBenchTest.class.getResourceAsStream(name);
- if (stream != null) {
- final ImageData imageData = new ImageData(stream);
- return new Image(display, imageData);
- // if (imageData != null) {
- // ImageData mask = imageData.getTransparencyMask();
- // return new Image(display, imageData, mask);
- // }
-
- }
- }
- catch (final Exception e) {
- throw new RuntimeException(e);
- }
- return null;
- }
-
- /**
- * Create a new Piccolo2D SWT benchmarking test suite with the specified parent and style.
- *
- * @param parent parent
- * @param style style
- */
- private SWTBenchTest(final Composite parent, final 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);
-
- final GC tmpGC = new GC(testImageARGB);
- tmpGC.drawImage(testImageTranslucent, 0, 0);
- tmpGC.dispose();
-
- addPaintListener(new PaintListener() {
- public void paintControl(final PaintEvent pe) {
- runAll(new SWTGraphics2D(pe.gc, getDisplay()));
- }
- });
- }
-
- private void setupTransform(final Graphics2D g, final Random r) {
- transform.setToIdentity();
-
- switch (abs(r.nextInt()) % 5) {
- default:
- // case 0: // UNIFORM SCALE
- final 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);
- }
-
- private void setupClip(final Graphics2D g, final Random r) {
- // g.setClip(rand(r), rand(r), rand(r), rand(r));
- }
-
- private void setupBlend(final Graphics2D g, final Random r) {
- g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, r.nextFloat()));
- }
-
- private void setup(final int ctx, final Graphics2D g, final Random r) {
- switch (ctx) {
- case CTX_NORMAL:
- break;
-
- case CTX_TRANSFORMED:
- setupTransform(g, r);
- break;
-
- // case CTX_CLIPPED:
- // setupClip(g, r);
- // break;
- //
- // case CTX_BLENDED:
- // setupBlend(g, r);
- // break;
- }
- }
-
- private void test(final int testNum, final SWTGraphics2D g, final Random r) {
-
- g.setColor(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;
- }
- }
-
- private void runTest(final SWTGraphics2D g, final int ctx, final int testNum) {
- final Random r1 = new Random(1);
- final Random r2 = new Random(1);
-
- System.out.println("Test: " + testNames[testNum]);
- final long t1 = System.currentTimeMillis();
- int i = 0;
- while (true) {
- if (i % 10 == 0) {
- setup(ctx, g, r1);
- }
- test(testNum, g, r2);
- i++;
- final long t2 = System.currentTimeMillis();
- if (t2 - t1 >= 5000) {
- break;
- }
- }
- results[ctx][testNum] += i / 5;
- System.out.println("Shapes per second: " + results[ctx][testNum]);
- }
-
- private void runAll(final SWTGraphics2D g) {
- System.out.println("BENCHMARKING: " + g);
-
- 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);
- }
-
- for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
- System.out.println("Context: " + contextNames[ctx]);
- for (int i = 0; i < NUM_TESTS; i++) {
- g.setClip(null);
- g.setTransform(IDENTITY);
- runTest(g, ctx, i);
- }
- }
-
- if (offscreen) {
- g.dispose();
- }
-
- String fileName = g.getClass().getName().replace('.', '_');
- if (offscreen) {
- fileName += "-offscreen";
- }
- if (antialiased) {
- fileName += "-antialiased";
- }
- dumpResults(fileName + ".txt");
- System.exit(0);
- }
-
- private void dumpResults(final String fileName) {
- try {
- final FileOutputStream fout = new FileOutputStream(fileName);
- final PrintWriter out = new PrintWriter(fout);
- out.print('\t');
- for (int i = 0; i < NUM_TESTS; i++) {
- out.print(testNames[i]);
- out.print('\t');
- }
- out.println("");
- for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
- out.print(contextNames[ctx]);
- for (int i = 0; i < NUM_TESTS; i++) {
- out.print('\t');
- out.print(results[ctx][i]);
- }
- out.println("");
- }
- out.close();
- results = new int[NUM_CONTEXTS][NUM_TESTS];
- }
- catch (final IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- public Point computeSize(final int wHint, final int hHint) {
- return new Point(512, 512);
- }
-
- public Point computeSize(final int wHint, final int hHint, final boolean changed) {
- return computeSize(wHint, hHint);
- }
-
- private static int abs(final int x) {
- return x < 0 ? -x : x;
- }
-
- private static double rand(final Random r) {
- return abs(r.nextInt()) % 500;
- }
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String args[]) {
- // Create frame
- final Display display = new Display();
- final Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
-
- // Add bench test
- final 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;
- }
- else if (args[i].intern() == "-anti") {
- m.antialiased = true;
- }
- else {
- System.out.println("Usage: java BenchTest [-anti] [-offscreen]");
- System.exit(1);
- }
- }
-
- shell.pack();
- shell.open();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
-}
\ No newline at end of file
diff --git a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTHelloWorld.java b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTHelloWorld.java
deleted file mode 100644
index cf737f6..0000000
--- a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTHelloWorld.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package edu.umd.cs.piccolox.swt.examples;
-
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.piccolo2d.extras.swt.PSWTCanvas;
-import org.piccolo2d.extras.swt.PSWTText;
-
-
-/**
- * Piccolo2D SWT Hello World example.
- */
-public class SWTHelloWorld {
-
- /**
- * Create a new Piccolo2D SWT Hello World example.
- */
- public SWTHelloWorld() {
- super();
- }
-
-
- /**
- * Create and open a new shell on the specified display.
- *
- * @param display display
- * @return a new shell on the specified display
- */
- public static Shell open(final Display display) {
- final Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
-
- // create a new SWT canvas
- final PSWTCanvas canvas = new PSWTCanvas(shell, 0);
- // create a new SWT text node
- final PSWTText text = new PSWTText("Hello World");
- // add it as a child of the canvas' camera's first layer
- canvas.getLayer().addChild(text);
-
- shell.open();
- return shell;
- }
-
- /**
- * Main.
- *
- * @param args command line arguments, ignored
- */
- public static void main(final String[] args) {
- final Display display = new Display();
- final Shell shell = open(display);
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
-}
diff --git a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/package-info.java b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/package-info.java
deleted file mode 100644
index 65bde73..0000000
--- a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/package-info.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * Piccolo2D SWT examples.
- */
-package edu.umd.cs.piccolox.swt.examples;
\ No newline at end of file
diff --git a/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBasicExample.java b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBasicExample.java
new file mode 100644
index 0000000..df47482
--- /dev/null
+++ b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBasicExample.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.extras.swt.examples;
+
+import java.awt.Color;
+
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.piccolo2d.extras.swt.PSWTCanvas;
+import org.piccolo2d.extras.swt.PSWTPath;
+import org.piccolo2d.extras.swt.PSWTText;
+
+
+public final class SWTBasicExample {
+
+ /**
+ * Create and open a new shell on the specified display.
+ *
+ * @param display display
+ * @return a new shell on the specified display
+ */
+ public static Shell open(final Display display) {
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+
+ // create a new SWT canvas
+ final PSWTCanvas canvas = new PSWTCanvas(shell, 0);
+
+ // create some SWT nodes
+ // and add them as child nodes to the canvas' camera's first layer
+ 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\nMultiline");
+ text.translate(350, 150);
+ text.setPenColor(Color.GRAY);
+ text.setBackgroundColor(Color.BLACK);
+ 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 void main(final String[] args) {
+ final Display display = new Display();
+ final Shell shell = open(display);
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+}
diff --git a/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBenchTest.java b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBenchTest.java
new file mode 100644
index 0000000..7e923fc
--- /dev/null
+++ b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTBenchTest.java
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.extras.swt.examples;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Random;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.piccolo2d.extras.swt.SWTGraphics2D;
+
+
+/**
+ * Piccolo2D SWT benchmarking test suite.
+ */
+public class SWTBenchTest extends Canvas {
+
+ // Paths
+ private GeneralPath testShape = new GeneralPath();
+
+ // Images
+ private Image testImageOpaque;
+ private Image testImageBitmask;
+ private Image testImageTranslucent;
+ private Image testImageARGB;
+
+ // Transforms
+ private AffineTransform transform = new AffineTransform();
+ private static final AffineTransform IDENTITY = new AffineTransform();
+
+ // Geometry
+ private double pts[] = new double[20];
+
+ // Colors
+ private static final Color colors[] = { Color.RED, Color.GREEN, Color.BLUE, Color.WHITE, Color.YELLOW, };
+
+ // Flags
+ private boolean offscreen;
+ private boolean antialiased;
+
+ // Statistics
+ private int results[][] = new int[NUM_CONTEXTS][NUM_TESTS];
+
+ // Constants
+
+ private static final int CTX_NORMAL = 0;
+ // private static final int CTX_CLIPPED = 1;
+ private static final int CTX_TRANSFORMED = 1;
+ // private static final int CTX_BLENDED = 3;
+ private static final int NUM_CONTEXTS = 2;
+
+ // private static String contextNames[] = {
+ // "normal",
+ // "clip",
+ // "transform",
+ // "alpha",
+ // };
+
+ private static String contextNames[] = { "normal", "transform" };
+
+ //
+ // TEST METHODS
+ //
+
+ private static final int DRAW_LINE = 0;
+ private static final int DRAW_RECT = 1;
+ private static final int FILL_RECT = 2;
+ private static final int DRAW_OVAL = 3;
+ private static final int FILL_OVAL = 4;
+ private static final int DRAW_POLY = 5;
+ private static final int FILL_POLY = 6;
+ private static final int DRAW_TEXT = 7;
+ private static final int DRAW_IMG1 = 8;
+ private static final int DRAW_IMG2 = 9;
+ private static final int DRAW_IMG3 = 10;
+ private static final int DRAW_IMG4 = 11;
+ private static final int DRAW_IMG5 = 12;
+ private static final int NUM_TESTS = 13;
+
+ private static String testNames[] = { "line", "rect", "fill rect", "oval", "fill oval", "poly", "fill poly", "text",
+ "image", "scaled image", "mask image", "alpha image", "argb image", };
+
+ private void testDrawLine(final SWTGraphics2D g, final Random r) {
+ g.drawLine(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void testDrawRect(final SWTGraphics2D g, final Random r) {
+ g.drawRect(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void testFillRect(final SWTGraphics2D g, final Random r) {
+ g.fillRect(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void testDrawOval(final SWTGraphics2D g, final Random r) {
+ g.drawOval(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void testFillOval(final SWTGraphics2D g, final Random r) {
+ g.fillOval(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void genPoly(final Random r) {
+ for (int i = 0; i < pts.length / 2; i++) {
+ pts[2 * i] = rand(r);
+ pts[2 * i + 1] = rand(r);
+ }
+ }
+
+ private void testDrawPoly(final SWTGraphics2D g, final Random r) {
+ genPoly(r);
+ g.drawPolyline(pts);
+ }
+
+ private void testFillPoly(final SWTGraphics2D g, final Random r) {
+ genPoly(r);
+ g.fillPolygon(pts);
+ }
+
+ private void testDrawText(final SWTGraphics2D g, final Random r) {
+ g.drawString("Abcdefghijklmnop", rand(r), rand(r));
+ }
+
+ // Basic image
+ private void testDrawImg1(final SWTGraphics2D g, final Random r) {
+ g.drawImage(testImageOpaque, rand(r), rand(r));
+ }
+
+ // Scaled image
+ private void testDrawImg2(final SWTGraphics2D g, final Random r) {
+ final Rectangle rect = testImageOpaque.getBounds();
+ g.drawImage(testImageOpaque, 0, 0, rect.width, rect.height, rand(r), rand(r), rand(r), rand(r));
+ }
+
+ // Bitmask image (unscaled)
+ private void testDrawImg3(final SWTGraphics2D g, final Random r) {
+ g.drawImage(testImageBitmask, rand(r), rand(r));
+ }
+
+ // Translucent image (unscaled)
+ private void testDrawImg4(final SWTGraphics2D g, final Random r) {
+ g.drawImage(testImageTranslucent, rand(r), rand(r));
+ }
+
+ // Buffered image (unscaled)
+ private void testDrawImg5(final SWTGraphics2D g, final Random r) {
+ g.drawImage(testImageARGB, rand(r), rand(r));
+ }
+
+ private static Image loadImage(final Display display, final String name) {
+ InputStream stream = null;
+ try {
+ stream = SWTBenchTest.class.getResourceAsStream(name);
+ if (stream != null) {
+ final ImageData imageData = new ImageData(stream);
+ return new Image(display, imageData);
+ // if (imageData != null) {
+ // ImageData mask = imageData.getTransparencyMask();
+ // return new Image(display, imageData, mask);
+ // }
+
+ }
+ }
+ catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+
+ /**
+ * Create a new Piccolo2D SWT benchmarking test suite with the specified parent and style.
+ *
+ * @param parent parent
+ * @param style style
+ */
+ private SWTBenchTest(final Composite parent, final 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);
+
+ final GC tmpGC = new GC(testImageARGB);
+ tmpGC.drawImage(testImageTranslucent, 0, 0);
+ tmpGC.dispose();
+
+ addPaintListener(new PaintListener() {
+ public void paintControl(final PaintEvent pe) {
+ runAll(new SWTGraphics2D(pe.gc, getDisplay()));
+ }
+ });
+ }
+
+ private void setupTransform(final Graphics2D g, final Random r) {
+ transform.setToIdentity();
+
+ switch (abs(r.nextInt()) % 5) {
+ default:
+ // case 0: // UNIFORM SCALE
+ final 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);
+ }
+
+ private void setupClip(final Graphics2D g, final Random r) {
+ // g.setClip(rand(r), rand(r), rand(r), rand(r));
+ }
+
+ private void setupBlend(final Graphics2D g, final Random r) {
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, r.nextFloat()));
+ }
+
+ private void setup(final int ctx, final Graphics2D g, final Random r) {
+ switch (ctx) {
+ case CTX_NORMAL:
+ break;
+
+ case CTX_TRANSFORMED:
+ setupTransform(g, r);
+ break;
+
+ // case CTX_CLIPPED:
+ // setupClip(g, r);
+ // break;
+ //
+ // case CTX_BLENDED:
+ // setupBlend(g, r);
+ // break;
+ }
+ }
+
+ private void test(final int testNum, final SWTGraphics2D g, final Random r) {
+
+ g.setColor(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;
+ }
+ }
+
+ private void runTest(final SWTGraphics2D g, final int ctx, final int testNum) {
+ final Random r1 = new Random(1);
+ final Random r2 = new Random(1);
+
+ System.out.println("Test: " + testNames[testNum]);
+ final long t1 = System.currentTimeMillis();
+ int i = 0;
+ while (true) {
+ if (i % 10 == 0) {
+ setup(ctx, g, r1);
+ }
+ test(testNum, g, r2);
+ i++;
+ final long t2 = System.currentTimeMillis();
+ if (t2 - t1 >= 5000) {
+ break;
+ }
+ }
+ results[ctx][testNum] += i / 5;
+ System.out.println("Shapes per second: " + results[ctx][testNum]);
+ }
+
+ private void runAll(final SWTGraphics2D g) {
+ System.out.println("BENCHMARKING: " + g);
+
+ 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);
+ }
+
+ for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
+ System.out.println("Context: " + contextNames[ctx]);
+ for (int i = 0; i < NUM_TESTS; i++) {
+ g.setClip(null);
+ g.setTransform(IDENTITY);
+ runTest(g, ctx, i);
+ }
+ }
+
+ if (offscreen) {
+ g.dispose();
+ }
+
+ String fileName = g.getClass().getName().replace('.', '_');
+ if (offscreen) {
+ fileName += "-offscreen";
+ }
+ if (antialiased) {
+ fileName += "-antialiased";
+ }
+ dumpResults(fileName + ".txt");
+ System.exit(0);
+ }
+
+ private void dumpResults(final String fileName) {
+ try {
+ final FileOutputStream fout = new FileOutputStream(fileName);
+ final PrintWriter out = new PrintWriter(fout);
+ out.print('\t');
+ for (int i = 0; i < NUM_TESTS; i++) {
+ out.print(testNames[i]);
+ out.print('\t');
+ }
+ out.println("");
+ for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
+ out.print(contextNames[ctx]);
+ for (int i = 0; i < NUM_TESTS; i++) {
+ out.print('\t');
+ out.print(results[ctx][i]);
+ }
+ out.println("");
+ }
+ out.close();
+ results = new int[NUM_CONTEXTS][NUM_TESTS];
+ }
+ catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Point computeSize(final int wHint, final int hHint) {
+ return new Point(512, 512);
+ }
+
+ public Point computeSize(final int wHint, final int hHint, final boolean changed) {
+ return computeSize(wHint, hHint);
+ }
+
+ private static int abs(final int x) {
+ return x < 0 ? -x : x;
+ }
+
+ private static double rand(final Random r) {
+ return abs(r.nextInt()) % 500;
+ }
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String args[]) {
+ // Create frame
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+
+ // Add bench test
+ final 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;
+ }
+ else if (args[i].intern() == "-anti") {
+ m.antialiased = true;
+ }
+ else {
+ System.out.println("Usage: java BenchTest [-anti] [-offscreen]");
+ System.exit(1);
+ }
+ }
+
+ shell.pack();
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+}
\ No newline at end of file
diff --git a/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTHelloWorld.java b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTHelloWorld.java
new file mode 100644
index 0000000..0513914
--- /dev/null
+++ b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/SWTHelloWorld.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.extras.swt.examples;
+
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.piccolo2d.extras.swt.PSWTCanvas;
+import org.piccolo2d.extras.swt.PSWTText;
+
+
+/**
+ * Piccolo2D SWT Hello World example.
+ */
+public class SWTHelloWorld {
+
+ /**
+ * Create a new Piccolo2D SWT Hello World example.
+ */
+ public SWTHelloWorld() {
+ super();
+ }
+
+
+ /**
+ * Create and open a new shell on the specified display.
+ *
+ * @param display display
+ * @return a new shell on the specified display
+ */
+ public static Shell open(final Display display) {
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+
+ // create a new SWT canvas
+ final PSWTCanvas canvas = new PSWTCanvas(shell, 0);
+ // create a new SWT text node
+ final PSWTText text = new PSWTText("Hello World");
+ // add it as a child of the canvas' camera's first layer
+ canvas.getLayer().addChild(text);
+
+ shell.open();
+ return shell;
+ }
+
+ /**
+ * Main.
+ *
+ * @param args command line arguments, ignored
+ */
+ public static void main(final String[] args) {
+ final Display display = new Display();
+ final Shell shell = open(display);
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+}
diff --git a/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/package-info.java b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/package-info.java
new file mode 100644
index 0000000..96fb5f3
--- /dev/null
+++ b/swt-examples/src/main/java/org/piccolo2d/extras/swt/examples/package-info.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Piccolo2D SWT examples.
+ */
+package org.piccolo2d.extras.swt.examples;
\ No newline at end of file
diff --git a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/bitmask.gif b/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/bitmask.gif
deleted file mode 100644
index 053a5da..0000000
--- a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/bitmask.gif
+++ /dev/null
Binary files differ
diff --git a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/opaque.jpg b/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/opaque.jpg
deleted file mode 100644
index 2ff5ba6..0000000
--- a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/opaque.jpg
+++ /dev/null
Binary files differ
diff --git a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/translucent.png b/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/translucent.png
deleted file mode 100644
index 07601a7..0000000
--- a/swt-examples/src/main/resources/edu/umd/cs/piccolox/swt/examples/translucent.png
+++ /dev/null
Binary files differ
diff --git a/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/bitmask.gif b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/bitmask.gif
new file mode 100644
index 0000000..053a5da
--- /dev/null
+++ b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/bitmask.gif
Binary files differ
diff --git a/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/opaque.jpg b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/opaque.jpg
new file mode 100644
index 0000000..2ff5ba6
--- /dev/null
+++ b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/opaque.jpg
Binary files differ
diff --git a/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/translucent.png b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/translucent.png
new file mode 100644
index 0000000..07601a7
--- /dev/null
+++ b/swt-examples/src/main/resources/org/piccolo2d/extras/swt/examples/translucent.png
Binary files differ