diff --git a/core/src/test/java/AffineTransformTest.java b/core/src/test/java/AffineTransformTest.java deleted file mode 100644 index 7635d8e..0000000 --- a/core/src/test/java/AffineTransformTest.java +++ /dev/null @@ -1,67 +0,0 @@ -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.util.PAffineTransform; -import edu.umd.cs.piccolo.util.PBounds; - -public class AffineTransformTest extends TestCase { - - public AffineTransformTest(String aName) { - super(aName); - } - - public void testRotation() { - PAffineTransform at = new PAffineTransform(); - at.rotate(Math.toRadians(45)); - assertEquals(at.getRotation(), Math.toRadians(45), 0.000000001); - at.setRotation(Math.toRadians(90)); - assertEquals(at.getRotation(), Math.toRadians(90), 0.000000001); - } - - public void testScale() { - PAffineTransform at = new PAffineTransform(); - at.scaleAboutPoint(0.45, 0, 1); - assertEquals(at.getScale(), 0.45, 0.000000001); - at.setScale(0.11); - assertEquals(at.getScale(), 0.11, 0.000000001); - } - - public void testTransformRect() { - PBounds b1 = new PBounds(0, 0, 100, 80); - PBounds b2 = new PBounds(100, 100, 100, 80); - - PAffineTransform at = new PAffineTransform(); - at.scale(0.5, 0.5); - at.translate(100, 50); - - at.transform(b1, b1); - at.transform(b2, b2); - - PBounds b3 = new PBounds(); - PBounds b4 = new PBounds(0, 0, 100, 100); - - assertTrue(at.transform(b3, b4).isEmpty()); - - assertEquals(b1.getX(), 50, 0.000000001); - assertEquals(b1.getY(), 25, 0.000000001); - assertEquals(b1.getWidth(), 50, 0.000000001); - assertEquals(b1.getHeight(), 40, 0.000000001); - - assertEquals(b2.getX(), 100, 0.000000001); - assertEquals(b2.getY(), 75, 0.000000001); - assertEquals(b2.getWidth(), 50, 0.000000001); - assertEquals(b2.getHeight(), 40, 0.000000001); - - at.inverseTransform(b1, b1); - at.inverseTransform(b2, b2); - - assertEquals(b1.getX(), 0, 0.000000001); - assertEquals(b1.getY(), 0, 0.000000001); - assertEquals(b1.getWidth(), 100, 0.000000001); - assertEquals(b1.getHeight(), 80, 0.000000001); - - assertEquals(b2.getX(), 100, 0.000000001); - assertEquals(b2.getY(), 100, 0.000000001); - assertEquals(b2.getWidth(), 100, 0.000000001); - assertEquals(b2.getHeight(), 80, 0.000000001); - } -} diff --git a/core/src/test/java/CameraNodeTest.java b/core/src/test/java/CameraNodeTest.java deleted file mode 100644 index c32e8c8..0000000 --- a/core/src/test/java/CameraNodeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.PCamera; -import edu.umd.cs.piccolo.PLayer; -import edu.umd.cs.piccolo.PNode; - -public class CameraNodeTest extends TestCase { - - public CameraNodeTest(String name) { - super(name); - } - - public void testCopy() { - PNode n = new PNode(); - - PLayer layer1 = new PLayer(); - PLayer layer2 = new PLayer(); - - PCamera camera1 = new PCamera(); - PCamera camera2 = new PCamera(); - - n.addChild(layer1); - n.addChild(layer2); - n.addChild(camera1); - n.addChild(camera2); - - camera1.addLayer(layer1); - camera1.addLayer(layer2); - camera2.addLayer(layer1); - camera2.addLayer(layer2); - - // no layers should be written out since they are written conditionally. - PCamera cameraCopy = (PCamera) camera1.clone(); - assertEquals(cameraCopy.getLayerCount(), 0); - - n.clone(); - assertEquals(((PCamera)n.getChildrenReference().get(2)).getLayerCount(), 2); - assertEquals(((PLayer)n.getChildrenReference().get(1)).getCameraCount(), 2); - } -} diff --git a/core/src/test/java/ImageNodeTest.java b/core/src/test/java/ImageNodeTest.java deleted file mode 100644 index fdbb5ec..0000000 --- a/core/src/test/java/ImageNodeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -import java.awt.image.BufferedImage; - -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.nodes.PImage; -import edu.umd.cs.piccolo.util.PBounds; - -public class ImageNodeTest extends TestCase { - - public ImageNodeTest(String name) { - super(name); - } - - public void testCopy() { - PImage aNode = new PImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB)); - aNode = (PImage) aNode.clone(); - assertNotNull(aNode.getImage()); - assertEquals(aNode.getBounds(), new PBounds(0, 0, 100, 100)); - } - - public void testToString() { - PImage aNode = new PImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB)); - aNode.getFullBoundsReference(); - assertNotNull(aNode.toString()); - } -} diff --git a/core/src/test/java/NodeTest.java b/core/src/test/java/NodeTest.java deleted file mode 100644 index 413c627..0000000 --- a/core/src/test/java/NodeTest.java +++ /dev/null @@ -1,231 +0,0 @@ -import java.awt.Color; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; - -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolo.event.PBasicInputEventHandler; -import edu.umd.cs.piccolo.util.PAffineTransform; -import edu.umd.cs.piccolo.util.PBounds; -import edu.umd.cs.piccolo.util.PDimension; - -public class NodeTest extends TestCase { - - public NodeTest(String name) { - super(name); - } - - public void setUp() { - } - - public void testCenterBaseBoundsOnPoint() { - PNode aNode = new PNode(); - - aNode.setBounds(100, 300, 100, 80); - aNode.centerBoundsOnPoint(0, 0); - assertEquals(-50, aNode.getBoundsReference().getX(), 0); - assertEquals(-40, aNode.getBoundsReference().getY(), 0); - } - - public void testClientProperties() { - PNode n = new PNode(); - - assertNull(n.getAttribute(null)); - n.addAttribute("a", "b"); - assertEquals(n.getAttribute("a"), "b"); - assertNull(n.getAttribute(null)); - n.addAttribute("a", null); - assertNull(n.getAttribute("a")); - } - - public void testFullScale() { - PNode aParent = new PNode(); - PNode aNode = new PNode(); - - aParent.addChild(aNode); - - aParent.scale(2.0); - aNode.scale(0.5); - - - assertEquals(1.0, aNode.getGlobalScale(), 0); - - aParent.setScale(1.0); - assertEquals(0.5, aNode.getGlobalScale(), 0); - - aNode.setScale(.75); - assertEquals(0.75, aNode.getGlobalScale(), 0); - } - - public void testReparent() { - PNode aParent = new PNode(); - PNode aNode = new PNode(); - - aParent.setOffset(400, 500); - aParent.scale(0.5); - aNode.reparent(aParent); - - assertEquals(0, aNode.getGlobalTranslation().getX(), 0); - assertEquals(0, aNode.getGlobalTranslation().getY(), 0); - assertEquals(2.0, aNode.getScale(), 0); - - aNode.setGlobalScale(0.25); - aNode.setGlobalTranslation(new Point2D.Double(10, 10)); - - assertEquals(10, aNode.getGlobalTranslation().getX(), 0); - assertEquals(10, aNode.getGlobalTranslation().getY(), 0); - assertEquals(0.25, aNode.getGlobalScale(), 0); - } - - public void testFindIntersectingNodes() { - PNode n = new PNode(); - PNode c = new PNode(); - - n.addChild(c); - n.setBounds(0, 0, 100, 100); - c.setBounds(0, 0, 100, 100); - c.scale(200); - - ArrayList found = new ArrayList(); - Rectangle2D rect2d = new Rectangle2D.Double(50, 50, 10, 10); - n.findIntersectingNodes(rect2d, found); - - assertEquals(found.size(), 2); - assertEquals(rect2d.getHeight(), 10, 0); - found = new ArrayList(); - - PBounds bounds = new PBounds(50, 50, 10, 10); - n.findIntersectingNodes(bounds, found); - - assertEquals(found.size(), 2); - assertEquals(bounds.getHeight(), 10, 0); - } - - public void testRemoveNonexistantListener() { - PNode n = new PNode(); - n.removeInputEventListener(new PBasicInputEventHandler()); - } - - public void testAddChild() { - PNode p = new PNode(); - PNode c = new PNode(); - - p.addChild(c); - p.addChild(new PNode()); - p.addChild(new PNode()); - - p.addChild(c); - assertEquals(c, p.getChild(2)); - - p.addChild(0, c); - assertEquals(c, p.getChild(0)); - - p.addChild(1, c); - assertEquals(c, p.getChild(1)); - - p.addChild(2, c); - assertEquals(c, p.getChild(2)); - } - - public void testCopy() { - PNode aNode = new PNode(); - aNode.setPaint(Color.yellow); - - PNode aChild = new PNode(); - aNode.addChild(aChild); - - aNode = (PNode) aNode.clone(); - - assertEquals(aNode.getPaint(), Color.yellow); - assertEquals(aNode.getChildrenCount(), 1); - } - - public void testLocalToGlobal() { - PNode aParent = new PNode(); - PNode aChild = new PNode(); - - aParent.addChild(aChild); - aChild.scale(0.5); - - // bounds - PBounds bnds = new PBounds(0, 0, 50, 50); - - aChild.localToGlobal(bnds); - assertEquals(0, bnds.x, 0); - assertEquals(0, bnds.y, 0); - assertEquals(25, bnds.width, 0); - assertEquals(25, bnds.height, 0); - - aChild.globalToLocal(bnds); - assertEquals(0, bnds.x, 0); - assertEquals(0, bnds.y, 0); - assertEquals(50, bnds.width, 0); - assertEquals(50, bnds.height, 0); - - aChild.getGlobalToLocalTransform(new PAffineTransform()); - aChild.getLocalToGlobalTransform(new PAffineTransform()).createTransformedShape(aChild.getBounds()); - - // dimensions - PDimension dim = new PDimension(50, 50); - - aChild.localToGlobal(dim); - assertEquals(25, dim.getHeight(), 0); - assertEquals(25, dim.getWidth(), 0); - - - aChild.globalToLocal(dim); - assertEquals(50, dim.getHeight(), 0); - assertEquals(50, dim.getWidth(), 0); - } - - public void testToString() { - PNode a = new PNode(); - PNode b = new PNode(); - PNode c = new PNode(); - PNode d = new PNode(); - PNode e = new PNode(); - PNode f = new PNode(); - - a.translate(100, 100); - a.getFullBoundsReference(); - - a.addChild(b); - b.addChild(c); - c.addChild(d); - d.addChild(e); - e.addChild(f); - - assertNotNull(a.toString()); - } - - public void testRecursiveLayout() { - PNode layoutNode1 = new PNode() { - protected void layoutChildren() { - if (getChildrenCount() > 0) { - getChild(0).setOffset(1, 0); - } - } - }; - - PNode layoutNode2 = new PNode() { - protected void layoutChildren() { - if (getChildrenCount() > 0) { - getChild(0).setOffset(1, 0); - } - } - }; - - layoutNode1.addChild(layoutNode2); - - PNode n = new PNode(); - n.setBounds(0, 0, 100, 100); - - layoutNode2.addChild(n); - - n.setBounds(10, 10, 100, 100); - - layoutNode1.getFullBoundsReference(); - } -} diff --git a/core/src/test/java/PathNodeTest.java b/core/src/test/java/PathNodeTest.java deleted file mode 100644 index 8a5650c..0000000 --- a/core/src/test/java/PathNodeTest.java +++ /dev/null @@ -1,50 +0,0 @@ -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import junit.framework.TestCase; -import edu.umd.cs.piccolo.nodes.PPath; -import edu.umd.cs.piccolo.util.PBounds; -import edu.umd.cs.piccolo.util.PObjectOutputStream; - -public class PathNodeTest extends TestCase { - - public PathNodeTest(String name) { - super(name); - } - - public void testCopy() { - PPath p = PPath.createEllipse(0, 0, 100, 100); - PBounds b = p.getBounds(); - p = (PPath) p.clone(); - assertEquals(p.getBounds(), b); - } - - public void testSaveToFile() { - PPath p = PPath.createEllipse(0, 0, 100, 100); - PBounds b = p.getBounds(); - try { - File file = new File("myfile"); - FileOutputStream fout = new FileOutputStream(file); - PObjectOutputStream out = new PObjectOutputStream(fout); - out.writeObjectTree(p); - out.flush(); - out.close(); - - FileInputStream fin = new FileInputStream(file); - ObjectInputStream in = new ObjectInputStream(fin); - p = (PPath) in.readObject(); - assertEquals(p.getBounds(), b); - file.delete(); - } catch (FileNotFoundException e) { - assertTrue(false); - } catch (ClassNotFoundException e) { - assertTrue(false); - } catch (IOException e) { - assertTrue(false); - } - } -} diff --git a/core/src/test/java/PerformanceLog.java b/core/src/test/java/PerformanceLog.java deleted file mode 100644 index 4c4a61c..0000000 --- a/core/src/test/java/PerformanceLog.java +++ /dev/null @@ -1,60 +0,0 @@ -import java.util.ArrayList; -import java.util.Iterator; - -public class PerformanceLog { - - private ArrayList log = new ArrayList(); - private long testTime; - - public static class ZLogEntry { - public String name; - public long time; - - public ZLogEntry(String aName, long aTime) { - name = aName; - time = aTime; - } - } - - public void startTest() { - Runtime.getRuntime().gc(); - testTime = System.currentTimeMillis(); - } - - public void endTest(String name) { - testTime = System.currentTimeMillis() - testTime; - addEntry(name, testTime); - System.gc(); - } - - public void addEntry(String aName, long aTime) { - log.add(new ZLogEntry(aName, aTime)); - } - - public void clear() { - log.clear(); - } - - public void writeLog() { - - System.out.println(); - System.out.println("Test data for input into spreadsheet:"); - System.out.println(); - - Iterator i = log.iterator(); - while (i.hasNext()) { - ZLogEntry each = (ZLogEntry) i.next(); - System.out.println(each.time); - } - - System.out.println(); - System.out.println("Labled test results, see above for simple column \n of times for input into spreadsheet:"); - System.out.println(); - - i = log.iterator(); - while (i.hasNext()) { - ZLogEntry each = (ZLogEntry) i.next(); - System.out.println(each.name + ", " + each.time); - } - } -} diff --git a/core/src/test/java/PerformanceTests.java b/core/src/test/java/PerformanceTests.java deleted file mode 100644 index 78039e5..0000000 --- a/core/src/test/java/PerformanceTests.java +++ /dev/null @@ -1,359 +0,0 @@ -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsEnvironment; -import java.awt.Transparency; -import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.Random; - -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolo.nodes.PPath; -import edu.umd.cs.piccolo.util.PAffineTransform; -import edu.umd.cs.piccolo.util.PBounds; - -public class PerformanceTests extends TestCase { - - private static PerformanceLog log = new PerformanceLog(); - private static int NUMBER_NODES = 20000; - - public PerformanceTests(String name) { - super(name); - } - - public void testRunPerformanceTests() { - // three times to warm up JVM - for (int i = 0; i < 3; i++) { - addNodes(); - copyNodes(); - createNodes(); - createPaths(); - fullIntersectsNodes(); - memorySizeOfNodes(); - //removeNodes(); - translateNodes(); - costOfNoBoundsCache(); -// renderSpeed(); - if (i != 2) { - log.clear(); - } - } - log.writeLog(); - } - - public void createNodes() { - PNode[] nodes = new PNode[NUMBER_NODES]; - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - } - log.endTest("Create " + NUMBER_NODES + " new nodes"); - } - - public void createPaths() { - PNode[] nodes = new PNode[NUMBER_NODES]; - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = PPath.createRectangle(0, 0, 100, 80); - } - log.endTest("Create " + NUMBER_NODES + " new rect paths"); - - Random r = new Random(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i].translate(r.nextFloat() * 300, r.nextFloat() * 300); - } - } - - public void addNodes() { - PNode parent = new PNode(); - PNode[] nodes = new PNode[NUMBER_NODES]; - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - } - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - parent.addChild(nodes[i]); - } - log.endTest("Add " + NUMBER_NODES + " nodes to a new parent"); - } - - public void removeNodes() { - PNode parent = new PNode(); - PNode[] nodes = new PNode[NUMBER_NODES]; - ArrayList list = new ArrayList(); - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - } - - for (int i = 0; i < NUMBER_NODES; i++) { - parent.addChild(nodes[i]); - list.add(nodes[i]); - } - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - parent.removeChild(nodes[i]); - } - log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() front to back"); - - parent.addChildren(list); - - log.startTest(); - for (int i = NUMBER_NODES - 1; i >= 0; i--) { - parent.removeChild(i); - } - log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() back to front by index"); - - log.startTest(); -// for (int i = NUMBER_NODES - 1; i >= 0; i--) { -// parent.removeChild(nodes[i]); -// } - log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() back to front by object, TO_SLOW"); - - parent.addChildren(list); - - log.startTest(); - parent.removeChildren(list); - log.endTest("Remove " + NUMBER_NODES + " nodes using removeChildren()"); - - parent.addChildren(list); - - log.startTest(); - parent.removeAllChildren(); - log.endTest("Remove " + NUMBER_NODES + " nodes using removeAllChildren()"); - } - - public void translateNodes() { - PNode parent = new PNode(); - PNode[] nodes = new PNode[NUMBER_NODES]; - PBounds b = new PBounds(); - Random r = new Random(); - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - nodes[i].setBounds(1000 * r.nextFloat(), 1000 * r.nextFloat(), 100, 80); - parent.addChild(nodes[i]); - nodes[i].getFullBoundsReference(); - } - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i].translate(1000 * r.nextFloat(), 1000 * r.nextFloat()); - nodes[i].scale(1000 * r.nextFloat()); -// nodes[i].translateBy(100.01, 100.2); -// nodes[i].scaleBy(0.9); - } - log.endTest("Translate " + NUMBER_NODES + " nodes, not counting repaint or validate layout"); - - log.startTest(); - //parent.validateFullBounds(); now protected. - parent.getFullBoundsReference(); // calls validateFullBounds as a side effect. - log.endTest("Validate Layout after translate " + NUMBER_NODES + " nodes"); - - log.startTest(); - parent.validateFullPaint(); - log.endTest("Validate Paint after translate " + NUMBER_NODES + " nodes"); - - log.startTest(); - parent.computeFullBounds(b); - log.endTest("Parent compute bounds of " + NUMBER_NODES + " children nodes"); - } - - public void fullIntersectsNodes() { - PNode parent = new PNode(); - PNode[] nodes = new PNode[NUMBER_NODES]; - PBounds b = new PBounds(0, 50, 100, 20); - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - parent.addChild(nodes[i]); - } - - //parent.validateFullBounds(); // now protected - parent.getFullBoundsReference(); // calls validateFullBounds as a side effect. - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i].fullIntersects(b); - } - log.endTest("Do fullIntersects test for " + NUMBER_NODES + " nodes"); - } - - public void memorySizeOfNodes() { - PNode[] nodes = new PNode[NUMBER_NODES]; - Runtime.getRuntime().gc(); - long startTotalMemory = Runtime.getRuntime().totalMemory(); - long startFree = Runtime.getRuntime().freeMemory(); - long endFree; - long endTotal; - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - } - - Runtime.getRuntime().gc(); - endFree = Runtime.getRuntime().freeMemory(); - endTotal = Runtime.getRuntime().totalMemory(); - - log.addEntry("Approximate k used by " + NUMBER_NODES + " nodes", ((endTotal - startTotalMemory) + (startFree - endFree)) / 1024); - nodes[0].getPaint(); - } - - public void copyNodes() { - PNode parent = new PNode(); - PNode[] nodes = new PNode[NUMBER_NODES]; - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - parent.addChild(nodes[i]); - } - - log.startTest(); - parent.clone(); - log.endTest("Copy/Serialize " + NUMBER_NODES + " nodes"); - } - - public void costOfNoBoundsCache() { - PNode[] nodes = new PNode[NUMBER_NODES]; - PBounds[] bounds = new PBounds[NUMBER_NODES]; - PBounds pickRect = new PBounds(0, 0, 1, 1); - Random r = new Random(); - - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i] = new PNode(); - nodes[i].translate(1000 * r.nextFloat(), 1000 * r.nextFloat()); - nodes[i].scale(1000 * r.nextFloat()); - bounds[i] = new PBounds(1000 * r.nextFloat(), 1000 * r.nextFloat(), 100, 80); - } - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - bounds[i].intersects(pickRect); - } - log.endTest("Do intersects test for " + NUMBER_NODES + " bounds"); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - nodes[i].localToParent(bounds[i]); - } - log.endTest("Transform " + NUMBER_NODES + " bounds from local to parent"); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - pickRect.add(bounds[i]); - } - log.endTest("Sum " + NUMBER_NODES + " bounds"); - - PBounds b = new PBounds(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); - log.startTest(); - for (int i = 0; i < NUMBER_NODES * 10; i++) { - b.clone(); - } - log.endTest("Clone " + NUMBER_NODES * 10 + " PBounds"); - - } - - public void renderSpeed() { - Random r = new Random(); - PAffineTransform at = new PAffineTransform(); - at.setScale(r.nextFloat()); - at.translate(r.nextFloat(), r.nextFloat()); - - try { - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - at.createInverse(); - } - log.endTest("Create inverse transform " + NUMBER_NODES + " times"); - } catch (NoninvertibleTransformException e) { - } - - int height = 400; - int width = 400; - - double scale1 = 0.5; - double scale2 = 2; - boolean scaleFlip = true; - - PAffineTransform transorm1 = new PAffineTransform(); - //transorm1.scale(0.5, 0.5); - transorm1.translate(0.5, 10.1); - PAffineTransform transorm2 = null; - - try { - transorm2 = new PAffineTransform(transorm1.createInverse()); - } catch (NoninvertibleTransformException e) {} - - - GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); - BufferedImage result = (BufferedImage)graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT); - Graphics2D g2 = result.createGraphics(); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - if (scaleFlip) { - g2.scale(scale2, scale2); - scaleFlip = !scaleFlip; - } else { - g2.scale(scale1, scale1); - scaleFlip = !scaleFlip; - } - } - log.endTest("Scale graphics context " + NUMBER_NODES + " times"); - - g2.setTransform(new AffineTransform()); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - g2.translate(0.5, 0.5); - } - log.endTest("Translate graphics context " + NUMBER_NODES + " times"); - - g2.setTransform(new AffineTransform()); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - if (scaleFlip) { - g2.transform(transorm1); - scaleFlip = !scaleFlip; - } else { - g2.transform(transorm2); - scaleFlip = !scaleFlip; - } - } - log.endTest("Transform graphics context " + NUMBER_NODES + " times"); - - - Rectangle2D rect = new Rectangle2D.Double(0, 0, 100, 80); - GeneralPath path = new GeneralPath(rect); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - g2.fill(rect); - } - log.endTest("Fill " + NUMBER_NODES + " rects"); - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - g2.getTransform().getScaleX(); - } - log.endTest("Call g2.getTransform() " + NUMBER_NODES + " times"); - - - log.startTest(); - for (int i = 0; i < NUMBER_NODES; i++) { - g2.fill(path); - } - log.endTest("Fill " + NUMBER_NODES + " paths"); - } -} diff --git a/core/src/test/java/PickTest.java b/core/src/test/java/PickTest.java deleted file mode 100644 index d33d6dc..0000000 --- a/core/src/test/java/PickTest.java +++ /dev/null @@ -1,39 +0,0 @@ -import edu.umd.cs.piccolo.PCamera; -import edu.umd.cs.piccolo.PCanvas; -import edu.umd.cs.piccolo.PLayer; -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolo.nodes.PPath; -import edu.umd.cs.piccolo.util.PPickPath; -import junit.framework.TestCase; - -public class PickTest extends TestCase { - - public PickTest(String name) { - super(name); - } - - public void testPick() { - PCanvas canvas = new PCanvas(); - PCamera camera = canvas.getCamera(); - PLayer layer = canvas.getLayer(); - - camera.setBounds(0, 0, 100, 100); - - PNode a = PPath.createRectangle(0, 0, 100, 100); - PNode b = PPath.createRectangle(0, 0, 100, 100); - PNode c = PPath.createRectangle(0, 0, 100, 100); - - layer.addChild(a); - layer.addChild(b); - layer.addChild(c); - - PPickPath pickPath = camera.pick(50, 50, 2); - - assertTrue(pickPath.getPickedNode() == c); - assertTrue(pickPath.nextPickedNode() == b); - assertTrue(pickPath.nextPickedNode() == a); - assertTrue(pickPath.nextPickedNode() == camera); - assertTrue(pickPath.nextPickedNode() == null); - assertTrue(pickPath.nextPickedNode() == null); - } -} diff --git a/core/src/test/java/SerializationTest.java b/core/src/test/java/SerializationTest.java deleted file mode 100644 index a950f7d..0000000 --- a/core/src/test/java/SerializationTest.java +++ /dev/null @@ -1,35 +0,0 @@ -import java.util.Iterator; - -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.PLayer; -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolo.nodes.PPath; -import edu.umd.cs.piccolo.nodes.PText; - -public class SerializationTest extends TestCase { - - public SerializationTest(String name) { - super(name); - } - - public void test() { - PNode l = new PLayer(); - - - for (int i = 0; i < 100; i++) { - l.addChild(new PNode()); - l.addChild(new PText("Hello World")); - l.addChild(new PPath()); - } - - l = (PNode) l.clone(); // copy uses serialization internally - assertTrue(l.getChildrenCount() == 300); - - Iterator i = l.getChildrenIterator(); - while (i.hasNext()) { - PNode each = (PNode) i.next(); - assertEquals(l, each.getParent()); - } - } -} diff --git a/core/src/test/java/TextNodeTest.java b/core/src/test/java/TextNodeTest.java deleted file mode 100644 index 2afa59f..0000000 --- a/core/src/test/java/TextNodeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -import junit.framework.TestCase; - -import edu.umd.cs.piccolo.nodes.PText; - -public class TextNodeTest extends TestCase { - - public TextNodeTest(String name) { - super(name); - } - - public void testCopy() { - PText aNode = new PText("Boo"); - aNode = (PText) aNode.clone(); - assertNotNull(aNode.getText()); - assertNotNull(aNode.getFont()); - } - - public void testEmptyString() { - PText t = new PText(); - t.setText("hello world"); - t.setText(""); - t.setText(null); - } - - public void testBoundsOfEmptyString() { - PText t = new PText(); - t.setText("hello world"); - assertTrue(t.getBoundsReference().getWidth() > 0); - t.setText(""); - assertTrue(t.getBoundsReference().getWidth() == 0); - t.setText(null); - assertTrue(t.getBoundsReference().getWidth() == 0); - } - - public void testToString() { - PText t = new PText(); - t.setText("hello world"); - assertNotNull(t.toString()); - } -} diff --git a/core/src/test/java/TransformActivityTest.java b/core/src/test/java/TransformActivityTest.java deleted file mode 100644 index 30c2c24..0000000 --- a/core/src/test/java/TransformActivityTest.java +++ /dev/null @@ -1,15 +0,0 @@ -import edu.umd.cs.piccolo.activities.PTransformActivity; - -import junit.framework.TestCase; - -public class TransformActivityTest extends TestCase { - - public TransformActivityTest(String name) { - super(name); - } - - public void testToString() { - PTransformActivity transformActivity = new PTransformActivity(1000, 0, null); - assertNotNull(transformActivity.toString()); - } -} diff --git a/core/src/test/java/ZoomEventHandlerTest.java b/core/src/test/java/ZoomEventHandlerTest.java deleted file mode 100644 index b344f66..0000000 --- a/core/src/test/java/ZoomEventHandlerTest.java +++ /dev/null @@ -1,15 +0,0 @@ -import edu.umd.cs.piccolo.event.PZoomEventHandler; - -import junit.framework.TestCase; - -public class ZoomEventHandlerTest extends TestCase { - - public ZoomEventHandlerTest(String name) { - super(name); - } - - public void testToString() { - PZoomEventHandler zoomEventHandler = new PZoomEventHandler(); - assertNotNull(zoomEventHandler.toString()); - } -} diff --git a/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java b/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java new file mode 100644 index 0000000..bbb97a0 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java @@ -0,0 +1,37 @@ +package edu.umd.cs.piccolo; +import junit.framework.TestCase; + +public class PCameraTest extends TestCase { + + public PCameraTest(String name) { + super(name); + } + + public void testCopy() { + PNode n = new PNode(); + + PLayer layer1 = new PLayer(); + PLayer layer2 = new PLayer(); + + PCamera camera1 = new PCamera(); + PCamera camera2 = new PCamera(); + + n.addChild(layer1); + n.addChild(layer2); + n.addChild(camera1); + n.addChild(camera2); + + camera1.addLayer(layer1); + camera1.addLayer(layer2); + camera2.addLayer(layer1); + camera2.addLayer(layer2); + + // no layers should be written out since they are written conditionally. + PCamera cameraCopy = (PCamera) camera1.clone(); + assertEquals(cameraCopy.getLayerCount(), 0); + + n.clone(); + assertEquals(((PCamera)n.getChildrenReference().get(2)).getLayerCount(), 2); + assertEquals(((PLayer)n.getChildrenReference().get(1)).getCameraCount(), 2); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java new file mode 100644 index 0000000..3481dc4 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java @@ -0,0 +1,230 @@ +package edu.umd.cs.piccolo; +import java.awt.Color; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.event.PBasicInputEventHandler; +import edu.umd.cs.piccolo.util.PAffineTransform; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PDimension; + +public class PNodeTest extends TestCase { + + public PNodeTest(String name) { + super(name); + } + + public void setUp() { + } + + public void testCenterBaseBoundsOnPoint() { + PNode aNode = new PNode(); + + aNode.setBounds(100, 300, 100, 80); + aNode.centerBoundsOnPoint(0, 0); + assertEquals(-50, aNode.getBoundsReference().getX(), 0); + assertEquals(-40, aNode.getBoundsReference().getY(), 0); + } + + public void testClientProperties() { + PNode n = new PNode(); + + assertNull(n.getAttribute(null)); + n.addAttribute("a", "b"); + assertEquals(n.getAttribute("a"), "b"); + assertNull(n.getAttribute(null)); + n.addAttribute("a", null); + assertNull(n.getAttribute("a")); + } + + public void testFullScale() { + PNode aParent = new PNode(); + PNode aNode = new PNode(); + + aParent.addChild(aNode); + + aParent.scale(2.0); + aNode.scale(0.5); + + + assertEquals(1.0, aNode.getGlobalScale(), 0); + + aParent.setScale(1.0); + assertEquals(0.5, aNode.getGlobalScale(), 0); + + aNode.setScale(.75); + assertEquals(0.75, aNode.getGlobalScale(), 0); + } + + public void testReparent() { + PNode aParent = new PNode(); + PNode aNode = new PNode(); + + aParent.setOffset(400, 500); + aParent.scale(0.5); + aNode.reparent(aParent); + + assertEquals(0, aNode.getGlobalTranslation().getX(), 0); + assertEquals(0, aNode.getGlobalTranslation().getY(), 0); + assertEquals(2.0, aNode.getScale(), 0); + + aNode.setGlobalScale(0.25); + aNode.setGlobalTranslation(new Point2D.Double(10, 10)); + + assertEquals(10, aNode.getGlobalTranslation().getX(), 0); + assertEquals(10, aNode.getGlobalTranslation().getY(), 0); + assertEquals(0.25, aNode.getGlobalScale(), 0); + } + + public void testFindIntersectingNodes() { + PNode n = new PNode(); + PNode c = new PNode(); + + n.addChild(c); + n.setBounds(0, 0, 100, 100); + c.setBounds(0, 0, 100, 100); + c.scale(200); + + ArrayList found = new ArrayList(); + Rectangle2D rect2d = new Rectangle2D.Double(50, 50, 10, 10); + n.findIntersectingNodes(rect2d, found); + + assertEquals(found.size(), 2); + assertEquals(rect2d.getHeight(), 10, 0); + found = new ArrayList(); + + PBounds bounds = new PBounds(50, 50, 10, 10); + n.findIntersectingNodes(bounds, found); + + assertEquals(found.size(), 2); + assertEquals(bounds.getHeight(), 10, 0); + } + + public void testRemoveNonexistantListener() { + PNode n = new PNode(); + n.removeInputEventListener(new PBasicInputEventHandler()); + } + + public void testAddChild() { + PNode p = new PNode(); + PNode c = new PNode(); + + p.addChild(c); + p.addChild(new PNode()); + p.addChild(new PNode()); + + p.addChild(c); + assertEquals(c, p.getChild(2)); + + p.addChild(0, c); + assertEquals(c, p.getChild(0)); + + p.addChild(1, c); + assertEquals(c, p.getChild(1)); + + p.addChild(2, c); + assertEquals(c, p.getChild(2)); + } + + public void testCopy() { + PNode aNode = new PNode(); + aNode.setPaint(Color.yellow); + + PNode aChild = new PNode(); + aNode.addChild(aChild); + + aNode = (PNode) aNode.clone(); + + assertEquals(aNode.getPaint(), Color.yellow); + assertEquals(aNode.getChildrenCount(), 1); + } + + public void testLocalToGlobal() { + PNode aParent = new PNode(); + PNode aChild = new PNode(); + + aParent.addChild(aChild); + aChild.scale(0.5); + + // bounds + PBounds bnds = new PBounds(0, 0, 50, 50); + + aChild.localToGlobal(bnds); + assertEquals(0, bnds.x, 0); + assertEquals(0, bnds.y, 0); + assertEquals(25, bnds.width, 0); + assertEquals(25, bnds.height, 0); + + aChild.globalToLocal(bnds); + assertEquals(0, bnds.x, 0); + assertEquals(0, bnds.y, 0); + assertEquals(50, bnds.width, 0); + assertEquals(50, bnds.height, 0); + + aChild.getGlobalToLocalTransform(new PAffineTransform()); + aChild.getLocalToGlobalTransform(new PAffineTransform()).createTransformedShape(aChild.getBounds()); + + // dimensions + PDimension dim = new PDimension(50, 50); + + aChild.localToGlobal(dim); + assertEquals(25, dim.getHeight(), 0); + assertEquals(25, dim.getWidth(), 0); + + + aChild.globalToLocal(dim); + assertEquals(50, dim.getHeight(), 0); + assertEquals(50, dim.getWidth(), 0); + } + + public void testToString() { + PNode a = new PNode(); + PNode b = new PNode(); + PNode c = new PNode(); + PNode d = new PNode(); + PNode e = new PNode(); + PNode f = new PNode(); + + a.translate(100, 100); + a.getFullBoundsReference(); + + a.addChild(b); + b.addChild(c); + c.addChild(d); + d.addChild(e); + e.addChild(f); + + assertNotNull(a.toString()); + } + + public void testRecursiveLayout() { + PNode layoutNode1 = new PNode() { + protected void layoutChildren() { + if (getChildrenCount() > 0) { + getChild(0).setOffset(1, 0); + } + } + }; + + PNode layoutNode2 = new PNode() { + protected void layoutChildren() { + if (getChildrenCount() > 0) { + getChild(0).setOffset(1, 0); + } + } + }; + + layoutNode1.addChild(layoutNode2); + + PNode n = new PNode(); + n.setBounds(0, 0, 100, 100); + + layoutNode2.addChild(n); + + n.setBounds(10, 10, 100, 100); + + layoutNode1.getFullBoundsReference(); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/PerformanceLog.java b/core/src/test/java/edu/umd/cs/piccolo/PerformanceLog.java new file mode 100644 index 0000000..8e44f65 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/PerformanceLog.java @@ -0,0 +1,61 @@ +package edu.umd.cs.piccolo; +import java.util.ArrayList; +import java.util.Iterator; + +public class PerformanceLog { + + private ArrayList log = new ArrayList(); + private long testTime; + + public static class ZLogEntry { + public String name; + public long time; + + public ZLogEntry(String aName, long aTime) { + name = aName; + time = aTime; + } + } + + public void startTest() { + Runtime.getRuntime().gc(); + testTime = System.currentTimeMillis(); + } + + public void endTest(String name) { + testTime = System.currentTimeMillis() - testTime; + addEntry(name, testTime); + System.gc(); + } + + public void addEntry(String aName, long aTime) { + log.add(new ZLogEntry(aName, aTime)); + } + + public void clear() { + log.clear(); + } + + public void writeLog() { + + System.out.println(); + System.out.println("Test data for input into spreadsheet:"); + System.out.println(); + + Iterator i = log.iterator(); + while (i.hasNext()) { + ZLogEntry each = (ZLogEntry) i.next(); + System.out.println(each.time); + } + + System.out.println(); + System.out.println("Labled test results, see above for simple column \n of times for input into spreadsheet:"); + System.out.println(); + + i = log.iterator(); + while (i.hasNext()) { + ZLogEntry each = (ZLogEntry) i.next(); + System.out.println(each.name + ", " + each.time); + } + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/PerformanceTests.java b/core/src/test/java/edu/umd/cs/piccolo/PerformanceTests.java new file mode 100644 index 0000000..bb026a2 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/PerformanceTests.java @@ -0,0 +1,358 @@ +package edu.umd.cs.piccolo; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.Transparency; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; +import java.awt.geom.NoninvertibleTransformException; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Random; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PAffineTransform; +import edu.umd.cs.piccolo.util.PBounds; + +public class PerformanceTests extends TestCase { + + private static PerformanceLog log = new PerformanceLog(); + private static int NUMBER_NODES = 20000; + + public PerformanceTests(String name) { + super(name); + } + + public void testRunPerformanceTests() { + // three times to warm up JVM + for (int i = 0; i < 3; i++) { + addNodes(); + copyNodes(); + createNodes(); + createPaths(); + fullIntersectsNodes(); + memorySizeOfNodes(); + //removeNodes(); + translateNodes(); + costOfNoBoundsCache(); +// renderSpeed(); + if (i != 2) { + log.clear(); + } + } + log.writeLog(); + } + + public void createNodes() { + PNode[] nodes = new PNode[NUMBER_NODES]; + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + } + log.endTest("Create " + NUMBER_NODES + " new nodes"); + } + + public void createPaths() { + PNode[] nodes = new PNode[NUMBER_NODES]; + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = PPath.createRectangle(0, 0, 100, 80); + } + log.endTest("Create " + NUMBER_NODES + " new rect paths"); + + Random r = new Random(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i].translate(r.nextFloat() * 300, r.nextFloat() * 300); + } + } + + public void addNodes() { + PNode parent = new PNode(); + PNode[] nodes = new PNode[NUMBER_NODES]; + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + } + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + parent.addChild(nodes[i]); + } + log.endTest("Add " + NUMBER_NODES + " nodes to a new parent"); + } + + public void removeNodes() { + PNode parent = new PNode(); + PNode[] nodes = new PNode[NUMBER_NODES]; + ArrayList list = new ArrayList(); + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + } + + for (int i = 0; i < NUMBER_NODES; i++) { + parent.addChild(nodes[i]); + list.add(nodes[i]); + } + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + parent.removeChild(nodes[i]); + } + log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() front to back"); + + parent.addChildren(list); + + log.startTest(); + for (int i = NUMBER_NODES - 1; i >= 0; i--) { + parent.removeChild(i); + } + log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() back to front by index"); + + log.startTest(); +// for (int i = NUMBER_NODES - 1; i >= 0; i--) { +// parent.removeChild(nodes[i]); +// } + log.endTest("Remove " + NUMBER_NODES + " nodes using removeChild() back to front by object, TO_SLOW"); + + parent.addChildren(list); + + log.startTest(); + parent.removeChildren(list); + log.endTest("Remove " + NUMBER_NODES + " nodes using removeChildren()"); + + parent.addChildren(list); + + log.startTest(); + parent.removeAllChildren(); + log.endTest("Remove " + NUMBER_NODES + " nodes using removeAllChildren()"); + } + + public void translateNodes() { + PNode parent = new PNode(); + PNode[] nodes = new PNode[NUMBER_NODES]; + PBounds b = new PBounds(); + Random r = new Random(); + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + nodes[i].setBounds(1000 * r.nextFloat(), 1000 * r.nextFloat(), 100, 80); + parent.addChild(nodes[i]); + nodes[i].getFullBoundsReference(); + } + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i].translate(1000 * r.nextFloat(), 1000 * r.nextFloat()); + nodes[i].scale(1000 * r.nextFloat()); +// nodes[i].translateBy(100.01, 100.2); +// nodes[i].scaleBy(0.9); + } + log.endTest("Translate " + NUMBER_NODES + " nodes, not counting repaint or validate layout"); + + log.startTest(); + //parent.validateFullBounds(); now protected. + parent.getFullBoundsReference(); // calls validateFullBounds as a side effect. + log.endTest("Validate Layout after translate " + NUMBER_NODES + " nodes"); + + log.startTest(); + parent.validateFullPaint(); + log.endTest("Validate Paint after translate " + NUMBER_NODES + " nodes"); + + log.startTest(); + parent.computeFullBounds(b); + log.endTest("Parent compute bounds of " + NUMBER_NODES + " children nodes"); + } + + public void fullIntersectsNodes() { + PNode parent = new PNode(); + PNode[] nodes = new PNode[NUMBER_NODES]; + PBounds b = new PBounds(0, 50, 100, 20); + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + parent.addChild(nodes[i]); + } + + //parent.validateFullBounds(); // now protected + parent.getFullBoundsReference(); // calls validateFullBounds as a side effect. + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i].fullIntersects(b); + } + log.endTest("Do fullIntersects test for " + NUMBER_NODES + " nodes"); + } + + public void memorySizeOfNodes() { + PNode[] nodes = new PNode[NUMBER_NODES]; + Runtime.getRuntime().gc(); + long startTotalMemory = Runtime.getRuntime().totalMemory(); + long startFree = Runtime.getRuntime().freeMemory(); + long endFree; + long endTotal; + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + } + + Runtime.getRuntime().gc(); + endFree = Runtime.getRuntime().freeMemory(); + endTotal = Runtime.getRuntime().totalMemory(); + + log.addEntry("Approximate k used by " + NUMBER_NODES + " nodes", ((endTotal - startTotalMemory) + (startFree - endFree)) / 1024); + nodes[0].getPaint(); + } + + public void copyNodes() { + PNode parent = new PNode(); + PNode[] nodes = new PNode[NUMBER_NODES]; + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + parent.addChild(nodes[i]); + } + + log.startTest(); + parent.clone(); + log.endTest("Copy/Serialize " + NUMBER_NODES + " nodes"); + } + + public void costOfNoBoundsCache() { + PNode[] nodes = new PNode[NUMBER_NODES]; + PBounds[] bounds = new PBounds[NUMBER_NODES]; + PBounds pickRect = new PBounds(0, 0, 1, 1); + Random r = new Random(); + + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i] = new PNode(); + nodes[i].translate(1000 * r.nextFloat(), 1000 * r.nextFloat()); + nodes[i].scale(1000 * r.nextFloat()); + bounds[i] = new PBounds(1000 * r.nextFloat(), 1000 * r.nextFloat(), 100, 80); + } + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + bounds[i].intersects(pickRect); + } + log.endTest("Do intersects test for " + NUMBER_NODES + " bounds"); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + nodes[i].localToParent(bounds[i]); + } + log.endTest("Transform " + NUMBER_NODES + " bounds from local to parent"); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + pickRect.add(bounds[i]); + } + log.endTest("Sum " + NUMBER_NODES + " bounds"); + + PBounds b = new PBounds(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()); + log.startTest(); + for (int i = 0; i < NUMBER_NODES * 10; i++) { + b.clone(); + } + log.endTest("Clone " + NUMBER_NODES * 10 + " PBounds"); + + } + + public void renderSpeed() { + Random r = new Random(); + PAffineTransform at = new PAffineTransform(); + at.setScale(r.nextFloat()); + at.translate(r.nextFloat(), r.nextFloat()); + + try { + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + at.createInverse(); + } + log.endTest("Create inverse transform " + NUMBER_NODES + " times"); + } catch (NoninvertibleTransformException e) { + } + + int height = 400; + int width = 400; + + double scale1 = 0.5; + double scale2 = 2; + boolean scaleFlip = true; + + PAffineTransform transorm1 = new PAffineTransform(); + //transorm1.scale(0.5, 0.5); + transorm1.translate(0.5, 10.1); + PAffineTransform transorm2 = null; + + try { + transorm2 = new PAffineTransform(transorm1.createInverse()); + } catch (NoninvertibleTransformException e) {} + + + GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); + BufferedImage result = (BufferedImage)graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT); + Graphics2D g2 = result.createGraphics(); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + if (scaleFlip) { + g2.scale(scale2, scale2); + scaleFlip = !scaleFlip; + } else { + g2.scale(scale1, scale1); + scaleFlip = !scaleFlip; + } + } + log.endTest("Scale graphics context " + NUMBER_NODES + " times"); + + g2.setTransform(new AffineTransform()); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + g2.translate(0.5, 0.5); + } + log.endTest("Translate graphics context " + NUMBER_NODES + " times"); + + g2.setTransform(new AffineTransform()); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + if (scaleFlip) { + g2.transform(transorm1); + scaleFlip = !scaleFlip; + } else { + g2.transform(transorm2); + scaleFlip = !scaleFlip; + } + } + log.endTest("Transform graphics context " + NUMBER_NODES + " times"); + + + Rectangle2D rect = new Rectangle2D.Double(0, 0, 100, 80); + GeneralPath path = new GeneralPath(rect); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + g2.fill(rect); + } + log.endTest("Fill " + NUMBER_NODES + " rects"); + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + g2.getTransform().getScaleX(); + } + log.endTest("Call g2.getTransform() " + NUMBER_NODES + " times"); + + + log.startTest(); + for (int i = 0; i < NUMBER_NODES; i++) { + g2.fill(path); + } + log.endTest("Fill " + NUMBER_NODES + " paths"); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/SerializationTest.java b/core/src/test/java/edu/umd/cs/piccolo/SerializationTest.java new file mode 100644 index 0000000..868e500 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/SerializationTest.java @@ -0,0 +1,33 @@ +package edu.umd.cs.piccolo; +import java.util.Iterator; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.nodes.PText; + +public class SerializationTest extends TestCase { + + public SerializationTest(String name) { + super(name); + } + + public void test() { + PNode l = new PLayer(); + + + for (int i = 0; i < 100; i++) { + l.addChild(new PNode()); + l.addChild(new PText("Hello World")); + l.addChild(new PPath()); + } + + l = (PNode) l.clone(); // copy uses serialization internally + assertTrue(l.getChildrenCount() == 300); + + Iterator i = l.getChildrenIterator(); + while (i.hasNext()) { + PNode each = (PNode) i.next(); + assertEquals(l, each.getParent()); + } + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/activities/PTransformActivityTest.java b/core/src/test/java/edu/umd/cs/piccolo/activities/PTransformActivityTest.java new file mode 100644 index 0000000..c38b829 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/activities/PTransformActivityTest.java @@ -0,0 +1,16 @@ +package edu.umd.cs.piccolo.activities; +import edu.umd.cs.piccolo.activities.PTransformActivity; + +import junit.framework.TestCase; + +public class PTransformActivityTest extends TestCase { + + public PTransformActivityTest(String name) { + super(name); + } + + public void testToString() { + PTransformActivity transformActivity = new PTransformActivity(1000, 0, null); + assertNotNull(transformActivity.toString()); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/event/PZoomEventHandlerTest.java b/core/src/test/java/edu/umd/cs/piccolo/event/PZoomEventHandlerTest.java new file mode 100644 index 0000000..f2d4078 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/event/PZoomEventHandlerTest.java @@ -0,0 +1,16 @@ +package edu.umd.cs.piccolo.event; +import edu.umd.cs.piccolo.event.PZoomEventHandler; + +import junit.framework.TestCase; + +public class PZoomEventHandlerTest extends TestCase { + + public PZoomEventHandlerTest(String name) { + super(name); + } + + public void testToString() { + PZoomEventHandler zoomEventHandler = new PZoomEventHandler(); + assertNotNull(zoomEventHandler.toString()); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java new file mode 100644 index 0000000..2d14cd8 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java @@ -0,0 +1,27 @@ +package edu.umd.cs.piccolo.nodes; +import java.awt.image.BufferedImage; + +import junit.framework.TestCase; + +import edu.umd.cs.piccolo.nodes.PImage; +import edu.umd.cs.piccolo.util.PBounds; + +public class PImageTest extends TestCase { + + public PImageTest(String name) { + super(name); + } + + public void testCopy() { + PImage aNode = new PImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB)); + aNode = (PImage) aNode.clone(); + assertNotNull(aNode.getImage()); + assertEquals(aNode.getBounds(), new PBounds(0, 0, 100, 100)); + } + + public void testToString() { + PImage aNode = new PImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB)); + aNode.getFullBoundsReference(); + assertNotNull(aNode.toString()); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java new file mode 100644 index 0000000..d25666d --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java @@ -0,0 +1,51 @@ +package edu.umd.cs.piccolo.nodes; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PBounds; +import edu.umd.cs.piccolo.util.PObjectOutputStream; + +public class PPathTest extends TestCase { + + public PPathTest(String name) { + super(name); + } + + public void testCopy() { + PPath p = PPath.createEllipse(0, 0, 100, 100); + PBounds b = p.getBounds(); + p = (PPath) p.clone(); + assertEquals(p.getBounds(), b); + } + + public void testSaveToFile() { + PPath p = PPath.createEllipse(0, 0, 100, 100); + PBounds b = p.getBounds(); + try { + File file = new File("myfile"); + FileOutputStream fout = new FileOutputStream(file); + PObjectOutputStream out = new PObjectOutputStream(fout); + out.writeObjectTree(p); + out.flush(); + out.close(); + + FileInputStream fin = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(fin); + p = (PPath) in.readObject(); + assertEquals(p.getBounds(), b); + file.delete(); + } catch (FileNotFoundException e) { + assertTrue(false); + } catch (ClassNotFoundException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java new file mode 100644 index 0000000..5e908e2 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java @@ -0,0 +1,41 @@ +package edu.umd.cs.piccolo.nodes; +import junit.framework.TestCase; + +import edu.umd.cs.piccolo.nodes.PText; + +public class PTextTest extends TestCase { + + public PTextTest(String name) { + super(name); + } + + public void testCopy() { + PText aNode = new PText("Boo"); + aNode = (PText) aNode.clone(); + assertNotNull(aNode.getText()); + assertNotNull(aNode.getFont()); + } + + public void testEmptyString() { + PText t = new PText(); + t.setText("hello world"); + t.setText(""); + t.setText(null); + } + + public void testBoundsOfEmptyString() { + PText t = new PText(); + t.setText("hello world"); + assertTrue(t.getBoundsReference().getWidth() > 0); + t.setText(""); + assertTrue(t.getBoundsReference().getWidth() == 0); + t.setText(null); + assertTrue(t.getBoundsReference().getWidth() == 0); + } + + public void testToString() { + PText t = new PText(); + t.setText("hello world"); + assertNotNull(t.toString()); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java b/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java new file mode 100644 index 0000000..95cd3c0 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java @@ -0,0 +1,68 @@ +package edu.umd.cs.piccolo.util; +import junit.framework.TestCase; + +import edu.umd.cs.piccolo.util.PAffineTransform; +import edu.umd.cs.piccolo.util.PBounds; + +public class PAffineTransformTest extends TestCase { + + public PAffineTransformTest(String aName) { + super(aName); + } + + public void testRotation() { + PAffineTransform at = new PAffineTransform(); + at.rotate(Math.toRadians(45)); + assertEquals(at.getRotation(), Math.toRadians(45), 0.000000001); + at.setRotation(Math.toRadians(90)); + assertEquals(at.getRotation(), Math.toRadians(90), 0.000000001); + } + + public void testScale() { + PAffineTransform at = new PAffineTransform(); + at.scaleAboutPoint(0.45, 0, 1); + assertEquals(at.getScale(), 0.45, 0.000000001); + at.setScale(0.11); + assertEquals(at.getScale(), 0.11, 0.000000001); + } + + public void testTransformRect() { + PBounds b1 = new PBounds(0, 0, 100, 80); + PBounds b2 = new PBounds(100, 100, 100, 80); + + PAffineTransform at = new PAffineTransform(); + at.scale(0.5, 0.5); + at.translate(100, 50); + + at.transform(b1, b1); + at.transform(b2, b2); + + PBounds b3 = new PBounds(); + PBounds b4 = new PBounds(0, 0, 100, 100); + + assertTrue(at.transform(b3, b4).isEmpty()); + + assertEquals(b1.getX(), 50, 0.000000001); + assertEquals(b1.getY(), 25, 0.000000001); + assertEquals(b1.getWidth(), 50, 0.000000001); + assertEquals(b1.getHeight(), 40, 0.000000001); + + assertEquals(b2.getX(), 100, 0.000000001); + assertEquals(b2.getY(), 75, 0.000000001); + assertEquals(b2.getWidth(), 50, 0.000000001); + assertEquals(b2.getHeight(), 40, 0.000000001); + + at.inverseTransform(b1, b1); + at.inverseTransform(b2, b2); + + assertEquals(b1.getX(), 0, 0.000000001); + assertEquals(b1.getY(), 0, 0.000000001); + assertEquals(b1.getWidth(), 100, 0.000000001); + assertEquals(b1.getHeight(), 80, 0.000000001); + + assertEquals(b2.getX(), 100, 0.000000001); + assertEquals(b2.getY(), 100, 0.000000001); + assertEquals(b2.getWidth(), 100, 0.000000001); + assertEquals(b2.getHeight(), 80, 0.000000001); + } +} diff --git a/core/src/test/java/edu/umd/cs/piccolo/util/PPickPathTest.java b/core/src/test/java/edu/umd/cs/piccolo/util/PPickPathTest.java new file mode 100644 index 0000000..e59c9a6 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/util/PPickPathTest.java @@ -0,0 +1,40 @@ +package edu.umd.cs.piccolo.util; +import edu.umd.cs.piccolo.PCamera; +import edu.umd.cs.piccolo.PCanvas; +import edu.umd.cs.piccolo.PLayer; +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.nodes.PPath; +import edu.umd.cs.piccolo.util.PPickPath; +import junit.framework.TestCase; + +public class PPickPathTest extends TestCase { + + public PPickPathTest(String name) { + super(name); + } + + public void testPick() { + PCanvas canvas = new PCanvas(); + PCamera camera = canvas.getCamera(); + PLayer layer = canvas.getLayer(); + + camera.setBounds(0, 0, 100, 100); + + PNode a = PPath.createRectangle(0, 0, 100, 100); + PNode b = PPath.createRectangle(0, 0, 100, 100); + PNode c = PPath.createRectangle(0, 0, 100, 100); + + layer.addChild(a); + layer.addChild(b); + layer.addChild(c); + + PPickPath pickPath = camera.pick(50, 50, 2); + + assertTrue(pickPath.getPickedNode() == c); + assertTrue(pickPath.nextPickedNode() == b); + assertTrue(pickPath.nextPickedNode() == a); + assertTrue(pickPath.nextPickedNode() == camera); + assertTrue(pickPath.nextPickedNode() == null); + assertTrue(pickPath.nextPickedNode() == null); + } +} diff --git a/core/src/test/java/tests.manifest b/core/src/test/java/tests.manifest deleted file mode 100644 index c8ad31a..0000000 --- a/core/src/test/java/tests.manifest +++ /dev/null @@ -1,3 +0,0 @@ -Main-Class: RunAllUnitTests -Class-Path: piccolo.jar lib/junit.jar -Created-By: Jesse Grosjean \ No newline at end of file diff --git a/extras/src/test/java/NotificationCenterTest.java b/extras/src/test/java/NotificationCenterTest.java deleted file mode 100644 index 2428bb4..0000000 --- a/extras/src/test/java/NotificationCenterTest.java +++ /dev/null @@ -1,57 +0,0 @@ -import edu.umd.cs.piccolox.event.PNotification; -import edu.umd.cs.piccolox.event.PNotificationCenter; - -import junit.framework.TestCase; - -public class NotificationCenterTest extends TestCase { - - boolean changed1; - boolean changed2; - boolean changed3; - boolean changed4; - - public NotificationCenterTest(String name) { - super(name); - } - - public void testToString() { - PNotificationCenter center = PNotificationCenter.defaultCenter(); - - center.addListener(this, "changed1", "propertyChanged", this); - center.addListener(this, "changed2", null, this); - center.addListener(this, "changed3", "propertyChanged", null); - center.addListener(this, "changed4", null, null); - - center.postNotification("propertyChanged", this); - assertTrue(changed1 && changed2 && changed3 && changed4); - changed1 = changed2 = changed3 = changed4 = false; - - center.postNotification("propertyChanged", new Object()); - assertTrue(!changed1 && !changed2 && changed3 && changed4); - changed1 = changed2 = changed3 = changed4 = false; - - center.postNotification("otherPropertyChanged", this); - assertTrue(!changed1 && changed2 && !changed3 && changed4); - changed1 = changed2 = changed3 = changed4 = false; - - center.postNotification("otherPropertyChanged", new Object()); - assertTrue(!changed1 && !changed2 && !changed3 && changed4); - changed1 = changed2 = changed3 = changed4 = false; - } - - public void changed1(PNotification notification) { - changed1 = true; - } - - public void changed2(PNotification notification) { - changed2 = true; - } - - public void changed3(PNotification notification) { - changed3 = true; - } - - public void changed4(PNotification notification) { - changed4 = true; - } -} diff --git a/extras/src/test/java/PFrameTest.java b/extras/src/test/java/PFrameTest.java deleted file mode 100644 index 22f4a0c..0000000 --- a/extras/src/test/java/PFrameTest.java +++ /dev/null @@ -1,27 +0,0 @@ -import edu.umd.cs.piccolox.PFrame; -import junit.framework.TestCase; - -import java.awt.*; -import java.lang.reflect.InvocationTargetException; - -public class PFrameTest extends TestCase { - private static final int TEST_WIDTH = 500; - private static final int TEST_HEIGHT = 300; - - public PFrameTest(String name) { - super(name); - } - - public void testComponentResized() throws InvocationTargetException, InterruptedException { - final PFrame frame = new PFrame(); - frame.setBounds(0, 0, TEST_WIDTH, TEST_HEIGHT); - EventQueue.invokeAndWait(new Runnable() { - public void run() { - // clear the event queue - } - }); - Rectangle bounds = frame.getCanvas().getBounds(); - assertEquals("Canvas width should match width of content pane", frame.getContentPane().getWidth(), bounds.width); - assertEquals("Canvas height should match height of content pane", frame.getContentPane().getHeight(), bounds.height); - } -} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/PFrameTest.java b/extras/src/test/java/edu/umd/cs/piccolox/PFrameTest.java new file mode 100644 index 0000000..ee90198 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/PFrameTest.java @@ -0,0 +1,28 @@ +package edu.umd.cs.piccolox; +import java.awt.EventQueue; +import java.awt.Rectangle; +import java.lang.reflect.InvocationTargetException; + +import junit.framework.TestCase; + +public class PFrameTest extends TestCase { + private static final int TEST_WIDTH = 500; + private static final int TEST_HEIGHT = 300; + + public PFrameTest(String name) { + super(name); + } + + public void testComponentResized() throws InvocationTargetException, InterruptedException { + final PFrame frame = new PFrame(); + frame.setBounds(0, 0, TEST_WIDTH, TEST_HEIGHT); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + // clear the event queue + } + }); + Rectangle bounds = frame.getCanvas().getBounds(); + assertEquals("Canvas width should match width of content pane", frame.getContentPane().getWidth(), bounds.width); + assertEquals("Canvas height should match height of content pane", frame.getContentPane().getHeight(), bounds.height); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java b/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java new file mode 100644 index 0000000..bc0252f --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java @@ -0,0 +1,55 @@ +package edu.umd.cs.piccolox.event; +import junit.framework.TestCase; + +public class PNotificationCenterTest extends TestCase { + + boolean changed1; + boolean changed2; + boolean changed3; + boolean changed4; + + public PNotificationCenterTest(String name) { + super(name); + } + + public void testToString() { + PNotificationCenter center = PNotificationCenter.defaultCenter(); + + center.addListener(this, "changed1", "propertyChanged", this); + center.addListener(this, "changed2", null, this); + center.addListener(this, "changed3", "propertyChanged", null); + center.addListener(this, "changed4", null, null); + + center.postNotification("propertyChanged", this); + assertTrue(changed1 && changed2 && changed3 && changed4); + changed1 = changed2 = changed3 = changed4 = false; + + center.postNotification("propertyChanged", new Object()); + assertTrue(!changed1 && !changed2 && changed3 && changed4); + changed1 = changed2 = changed3 = changed4 = false; + + center.postNotification("otherPropertyChanged", this); + assertTrue(!changed1 && changed2 && !changed3 && changed4); + changed1 = changed2 = changed3 = changed4 = false; + + center.postNotification("otherPropertyChanged", new Object()); + assertTrue(!changed1 && !changed2 && !changed3 && changed4); + changed1 = changed2 = changed3 = changed4 = false; + } + + public void changed1(PNotification notification) { + changed1 = true; + } + + public void changed2(PNotification notification) { + changed2 = true; + } + + public void changed3(PNotification notification) { + changed3 = true; + } + + public void changed4(PNotification notification) { + changed4 = true; + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwing.java b/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwing.java new file mode 100644 index 0000000..7a4362e --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwing.java @@ -0,0 +1,143 @@ +package edu.umd.cs.piccolox.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 edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.event.PZoomEventHandler; +import edu.umd.cs.piccolo.nodes.PText; + +/** + * User: Sam Reid + * Date: Jul 11, 2005 + * Time: 12:15:55 PM + */ + +public class TestPSwing { + public static void main( String[] args ) { + PSwingCanvas pCanvas = new PSwingCanvas(); + final PText pText = new PText( "PText" ); + pCanvas.getLayer().addChild( pText ); + JFrame frame = new JFrame( "Test Piccolo" ); + + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.setContentPane( pCanvas ); + frame.setSize( 600, 800 ); + frame.setVisible( true ); + + 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() ); + + JButton jButton = new JButton( "MyButton!" ); + jButton.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + System.out.println( "TestZSwing.actionPerformed!!!!!!!!!!!!!!*********************" ); + } + } ); + final PSwing pSwing = new PSwing(jButton ); + pCanvas.getLayer().addChild( pSwing ); + pSwing.repaint(); + + JSpinner jSpinner = new JSpinner(); + jSpinner.setPreferredSize( new Dimension( 100, jSpinner.getPreferredSize().height ) ); + PSwing pSpinner = new PSwing(jSpinner ); + pCanvas.getLayer().addChild( pSpinner ); + pSpinner.translate( 0, 150 ); + + JCheckBox jcb = new JCheckBox( "CheckBox", true ); + jcb.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) { + System.out.println( "TestZSwing.JCheckBox.actionPerformed" ); + } + } ); + jcb.addChangeListener( new ChangeListener() { + public void stateChanged( ChangeEvent e ) { + System.out.println( "TestPSwing.JChekbox.stateChanged@" + System.currentTimeMillis() ); + } + } ); + PSwing pCheckBox = new PSwing(jcb ); + pCanvas.getLayer().addChild( pCheckBox ); + pCheckBox.translate( 100, 0 ); + + // Growable JTextArea + 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 + JSlider slider = new JSlider(); + PSwing pSlider = new PSwing(slider ); + pSlider.translate( 200, 200 ); + pCanvas.getLayer().addChild( pSlider ); + + // A Scrollable JTree + JTree tree = new JTree(); + tree.setEditable( true ); + JScrollPane p = new JScrollPane( tree ); + p.setPreferredSize( new Dimension( 150, 150 ) ); + PSwing pTree = new PSwing(p ); + pCanvas.getLayer().addChild( pTree ); + pTree.translate( 0, 250 ); + + // A JColorChooser - also demonstrates JTabbedPane + JColorChooser chooser = new JColorChooser(); + PSwing pChooser = new PSwing(chooser ); + pCanvas.getLayer().addChild( pChooser ); + pChooser.translate( 100, 300 ); + + JPanel myPanel = new JPanel(); + myPanel.setBorder( BorderFactory.createTitledBorder( "Titled Border" ) ); + myPanel.add( new JCheckBox( "CheckBox" ) ); + PSwing panelSwing = new PSwing(myPanel ); + pCanvas.getLayer().addChild( panelSwing ); + panelSwing.translate( 400, 50 ); + + // A Slider + JSlider slider2 = new JSlider(); + PSwing pSlider2 = new PSwing(slider2 ); + pSlider2.translate( 200, 200 ); + PNode root = new PNode(); + root.addChild( pSlider2 ); + root.scale( 1.5 ); + root.rotate( Math.PI / 4 ); + root.translate( 300, 200 ); + pCanvas.getLayer().addChild( root ); + + String[] listItems = {"Summer Teeth", "Mermaid Avenue", "Being There", "A.M."}; + PComboBox box = new PComboBox( listItems ); + swing = new PSwing(box ); + swing.translate( 200, 250 ); + pCanvas.getLayer().addChild( swing ); + box.setEnvironment( swing, pCanvas );//has to be done manually at present + + // Revalidate and repaint + pCanvas.revalidate(); + pCanvas.repaint(); + } + +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwingFull.java b/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwingFull.java new file mode 100644 index 0000000..ccfd848 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/pswing/TestPSwingFull.java @@ -0,0 +1,440 @@ +package edu.umd.cs.piccolox.pswing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.util.Vector; + +import javax.swing.AbstractAction; +import javax.swing.Action; +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 edu.umd.cs.piccolo.PNode; + +/** + * User: Sam Reid + * Date: Jul 11, 2005 + * Time: 12:15:55 PM + */ + +public class TestPSwingFull extends JFrame { + public TestPSwingFull() { + 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 + 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 + 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 + 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 + 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 + JTree tree = new JTree(); + tree.setEditable( true ); + 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 ) ); + Vector data = new Vector(); + data.addElement( "Choice 1" ); + data.addElement( "Choice 2" ); + data.addElement( "Choice 3" ); + data.addElement( "Choice 4" ); + data.addElement( "Choice 5" ); + 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 ); + + // 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() ); + JButton button1 = new JButton( "Button 1" ); + 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 + Vector columns = new Vector(); + columns.addElement( "Check Number" ); + columns.addElement( "Description" ); + columns.addElement( "Amount" ); + 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 ); + 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( HyperlinkEvent e ) { + if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) { + try { + editorPane.setPage( e.getURL() ); + } + catch( 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( IOException ioe ) { + System.out.println( "Couldn't Load Web Page" ); + } + + // A JInternalFrame with a JSplitPane - a JOptionPane - and a + // JToolBar + JInternalFrame iframe = new JInternalFrame( "JInternalFrame" ); + iframe.getRootPane().setDoubleBuffered( false ); + ( (JComponent)iframe.getContentPane() ).setDoubleBuffered( false ); + iframe.setPreferredSize( new Dimension( 500, 500 ) ); + JTabbedPane tabby = new JTabbedPane(); + tabby.setDoubleBuffered( false ); + iframe.getContentPane().setLayout( new BorderLayout() ); + 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 ) ); + JPanel tools = new JPanel( false ); + tools.setMinimumSize( new Dimension( 150, 150 ) ); + tools.setPreferredSize( new Dimension( 225, 225 ) ); + JToolBar bar = new JToolBar(); + Action letter = new AbstractAction( "Big A!" ) { + + public void actionPerformed( ActionEvent e ) { + } + }; + + Action hand = new AbstractAction( "Hi!" ) { + public void actionPerformed( ActionEvent e ) { + } + }; + Action select = new AbstractAction( "There!" ) { + public void actionPerformed( 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" ); + + 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(); + 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(); + + PSwing message = new PSwing(new JTextArea( "Click-drag to zoom in and out." ) ); + message.translate( 0, -50 ); + canvas.getLayer().addChild( message ); + + canvas.getCamera().animateViewToCenterBounds( message.getFullBounds(), false, 1200 ); + } + + public static void main( String[] args ) { + new TestPSwingFull().setVisible( true ); + } + + public static class ZVisualLeaf extends PNode { + public ZVisualLeaf( PNode node ) { + addChild( node ); + } + } + +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/package.html b/extras/src/test/java/edu/umd/cs/piccolox/pswing/package.html new file mode 100644 index 0000000..c90ab78 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/pswing/package.html @@ -0,0 +1,34 @@ + + + +

This package provides unit tests for PSwing nodes and related classes.

+ + diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwing.java b/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwing.java deleted file mode 100644 index ae0fa4a..0000000 --- a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwing.java +++ /dev/null @@ -1,133 +0,0 @@ -package edu.umd.cs.piccolox.pswing.tests; - -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolo.event.PZoomEventHandler; -import edu.umd.cs.piccolo.nodes.PText; -import edu.umd.cs.piccolox.pswing.PComboBox; -import edu.umd.cs.piccolox.pswing.PSwing; -import edu.umd.cs.piccolox.pswing.PSwingCanvas; - -import javax.swing.*; -import javax.swing.border.LineBorder; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * User: Sam Reid - * Date: Jul 11, 2005 - * Time: 12:15:55 PM - */ - -public class TestPSwing { - public static void main( String[] args ) { - PSwingCanvas pCanvas = new PSwingCanvas(); - final PText pText = new PText( "PText" ); - pCanvas.getLayer().addChild( pText ); - JFrame frame = new JFrame( "Test Piccolo" ); - - frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); - frame.setContentPane( pCanvas ); - frame.setSize( 600, 800 ); - frame.setVisible( true ); - - 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() ); - - JButton jButton = new JButton( "MyButton!" ); - jButton.addActionListener( new ActionListener() { - public void actionPerformed( ActionEvent e ) { - System.out.println( "TestZSwing.actionPerformed!!!!!!!!!!!!!!*********************" ); - } - } ); - final PSwing pSwing = new PSwing(jButton ); - pCanvas.getLayer().addChild( pSwing ); - pSwing.repaint(); - - JSpinner jSpinner = new JSpinner(); - jSpinner.setPreferredSize( new Dimension( 100, jSpinner.getPreferredSize().height ) ); - PSwing pSpinner = new PSwing(jSpinner ); - pCanvas.getLayer().addChild( pSpinner ); - pSpinner.translate( 0, 150 ); - - JCheckBox jcb = new JCheckBox( "CheckBox", true ); - jcb.addActionListener( new ActionListener() { - public void actionPerformed( ActionEvent e ) { - System.out.println( "TestZSwing.JCheckBox.actionPerformed" ); - } - } ); - jcb.addChangeListener( new ChangeListener() { - public void stateChanged( ChangeEvent e ) { - System.out.println( "TestPSwing.JChekbox.stateChanged@" + System.currentTimeMillis() ); - } - } ); - PSwing pCheckBox = new PSwing(jcb ); - pCanvas.getLayer().addChild( pCheckBox ); - pCheckBox.translate( 100, 0 ); - - // Growable JTextArea - 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 - JSlider slider = new JSlider(); - PSwing pSlider = new PSwing(slider ); - pSlider.translate( 200, 200 ); - pCanvas.getLayer().addChild( pSlider ); - - // A Scrollable JTree - JTree tree = new JTree(); - tree.setEditable( true ); - JScrollPane p = new JScrollPane( tree ); - p.setPreferredSize( new Dimension( 150, 150 ) ); - PSwing pTree = new PSwing(p ); - pCanvas.getLayer().addChild( pTree ); - pTree.translate( 0, 250 ); - - // A JColorChooser - also demonstrates JTabbedPane - JColorChooser chooser = new JColorChooser(); - PSwing pChooser = new PSwing(chooser ); - pCanvas.getLayer().addChild( pChooser ); - pChooser.translate( 100, 300 ); - - JPanel myPanel = new JPanel(); - myPanel.setBorder( BorderFactory.createTitledBorder( "Titled Border" ) ); - myPanel.add( new JCheckBox( "CheckBox" ) ); - PSwing panelSwing = new PSwing(myPanel ); - pCanvas.getLayer().addChild( panelSwing ); - panelSwing.translate( 400, 50 ); - - // A Slider - JSlider slider2 = new JSlider(); - PSwing pSlider2 = new PSwing(slider2 ); - pSlider2.translate( 200, 200 ); - PNode root = new PNode(); - root.addChild( pSlider2 ); - root.scale( 1.5 ); - root.rotate( Math.PI / 4 ); - root.translate( 300, 200 ); - pCanvas.getLayer().addChild( root ); - - String[] listItems = {"Summer Teeth", "Mermaid Avenue", "Being There", "A.M."}; - PComboBox box = new PComboBox( listItems ); - swing = new PSwing(box ); - swing.translate( 200, 250 ); - pCanvas.getLayer().addChild( swing ); - box.setEnvironment( swing, pCanvas );//has to be done manually at present - - // Revalidate and repaint - pCanvas.revalidate(); - pCanvas.repaint(); - } - -} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java b/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java deleted file mode 100644 index a360afe..0000000 --- a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java +++ /dev/null @@ -1,415 +0,0 @@ -package edu.umd.cs.piccolox.pswing.tests; - -import edu.umd.cs.piccolo.PNode; -import edu.umd.cs.piccolox.pswing.PSwing; -import edu.umd.cs.piccolox.pswing.PSwingCanvas; - -import javax.swing.*; -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 java.awt.*; -import java.awt.event.ActionEvent; -import java.io.IOException; -import java.util.Vector; - -/** - * User: Sam Reid - * Date: Jul 11, 2005 - * Time: 12:15:55 PM - */ - -public class TestPSwingFull extends JFrame { - public TestPSwingFull() { - 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 - 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 - 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 - 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 - 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 - JTree tree = new JTree(); - tree.setEditable( true ); - 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 ) ); - Vector data = new Vector(); - data.addElement( "Choice 1" ); - data.addElement( "Choice 2" ); - data.addElement( "Choice 3" ); - data.addElement( "Choice 4" ); - data.addElement( "Choice 5" ); - 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 ); - - // 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() ); - JButton button1 = new JButton( "Button 1" ); - 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 - Vector columns = new Vector(); - columns.addElement( "Check Number" ); - columns.addElement( "Description" ); - columns.addElement( "Amount" ); - 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 ); - 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( HyperlinkEvent e ) { - if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) { - try { - editorPane.setPage( e.getURL() ); - } - catch( 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( IOException ioe ) { - System.out.println( "Couldn't Load Web Page" ); - } - - // A JInternalFrame with a JSplitPane - a JOptionPane - and a - // JToolBar - JInternalFrame iframe = new JInternalFrame( "JInternalFrame" ); - iframe.getRootPane().setDoubleBuffered( false ); - ( (JComponent)iframe.getContentPane() ).setDoubleBuffered( false ); - iframe.setPreferredSize( new Dimension( 500, 500 ) ); - JTabbedPane tabby = new JTabbedPane(); - tabby.setDoubleBuffered( false ); - iframe.getContentPane().setLayout( new BorderLayout() ); - 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 ) ); - JPanel tools = new JPanel( false ); - tools.setMinimumSize( new Dimension( 150, 150 ) ); - tools.setPreferredSize( new Dimension( 225, 225 ) ); - JToolBar bar = new JToolBar(); - Action letter = new AbstractAction( "Big A!" ) { - - public void actionPerformed( ActionEvent e ) { - } - }; - - Action hand = new AbstractAction( "Hi!" ) { - public void actionPerformed( ActionEvent e ) { - } - }; - Action select = new AbstractAction( "There!" ) { - public void actionPerformed( 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" ); - - 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(); - 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(); - - PSwing message = new PSwing(new JTextArea( "Click-drag to zoom in and out." ) ); - message.translate( 0, -50 ); - canvas.getLayer().addChild( message ); - - canvas.getCamera().animateViewToCenterBounds( message.getFullBounds(), false, 1200 ); - } - - public static void main( String[] args ) { - new TestPSwingFull().setVisible( true ); - } - - public static class ZVisualLeaf extends PNode { - public ZVisualLeaf( PNode node ) { - addChild( node ); - } - } - -} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/package.html b/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/package.html deleted file mode 100644 index c90ab78..0000000 --- a/extras/src/test/java/edu/umd/cs/piccolox/pswing/tests/package.html +++ /dev/null @@ -1,34 +0,0 @@ - - - -

This package provides unit tests for PSwing nodes and related classes.

- -