diff --git a/src/main/java/edu/umd/cs/piccolo/PCamera.java b/src/main/java/edu/umd/cs/piccolo/PCamera.java
deleted file mode 100755
index ee39c46..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PCamera.java
+++ /dev/null
@@ -1,736 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Dimension2D;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.umd.cs.piccolo.activities.PTransformActivity;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PObjectOutputStream;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PPickPath;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PCamera represents a viewport onto a list of layer nodes.
- * Each camera maintains a view transform through which it views these
- * layers. Translating and scaling this view transform is how zooming
- * and panning are implemented.
- *
- * Cameras are also the point through which all PInputEvents enter Piccolo. The
- * canvas coordinate system, and the local coordinate system of the topmost camera
- * should always be the same.
- *
- * @see PLayer
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PCamera extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -8870345914993419772L;
- /**
- * The property name that identifies a change in the set of this camera's
- * layers (see {@link #getLayer getLayer}, {@link #getLayerCount
- * getLayerCount}, {@link #getLayersReference getLayersReference}). A
- * property change event's new value will be a reference to the list of this
- * nodes layers, but old value will always be null.
- */
- public static final String PROPERTY_LAYERS = "layers";
- public static final int PROPERTY_CODE_LAYERS = 1 << 11;
-
- /**
- * The property name that identifies a change in this camera's view
- * transform (see {@link #getViewTransform getViewTransform}, {@link
- * #getViewTransformReference getViewTransformReference}). A property change
- * event's new value will be a reference to the view transform, but old
- * value will always be null.
- */
- public static final String PROPERTY_VIEW_TRANSFORM = "viewTransform";
- public static final int PROPERTY_CODE_VIEW_TRANSFORM = 1 << 12;
-
- public static final int VIEW_CONSTRAINT_NONE = 0;
- public static final int VIEW_CONSTRAINT_ALL = 1;
- public static final int VIEW_CONSTRAINT_CENTER = 2;
-
- private transient PComponent component;
- private transient List layers;
- private PAffineTransform viewTransform;
- private int viewConstraint;
-
- /**
- * Construct a new camera with no layers and a default white color.
- */
- public PCamera() {
- super();
- viewTransform = new PAffineTransform();
- layers = new ArrayList();
- viewConstraint = VIEW_CONSTRAINT_NONE;
- }
-
- /**
- * Get the canvas associated with this camera. This will return null if
- * not canvas has been associated, as may be the case for internal cameras.
- */
- public PComponent getComponent() {
- return component;
- }
-
- /**
- * Set the canvas associated with this camera. When the camera is repainted
- * it will request repaints on this canvas.
- */
- public void setComponent(PComponent aComponent) {
- component = aComponent;
- invalidatePaint();
- }
-
- /**
- * Repaint this camera, and forward the repaint request to the camera's
- * canvas if it is not null.
- */
- public void repaintFrom(PBounds localBounds, PNode descendentOrThis) {
- if (getParent() != null) {
- if (descendentOrThis != this) {
- localToParent(localBounds);
- }
-
- if (component != null) {
- component.repaint(localBounds);
- }
-
- getParent().repaintFrom(localBounds, this);
- }
- }
-
- private static PBounds TEMP_REPAINT_RECT = new PBounds();
-
- /**
- * Repaint from one of the cameras layers. The repaint region needs to be
- * transformed from view to local in this case. Unlike most repaint
- * methods in piccolo this one must not modify the viewBounds parameter.
- */
- public void repaintFromLayer(PBounds viewBounds, PNode repaintedLayer) {
- TEMP_REPAINT_RECT.setRect(viewBounds);
-
- viewToLocal(TEMP_REPAINT_RECT);
- if (getBoundsReference().intersects(TEMP_REPAINT_RECT)) {
- PBounds.intersect(TEMP_REPAINT_RECT, getBoundsReference(), TEMP_REPAINT_RECT);
- repaintFrom(TEMP_REPAINT_RECT, repaintedLayer);
- }
- }
-
- //****************************************************************
- // Layers
- //****************************************************************
-
- /**
- * Return a reference to the list of layers managed by this camera.
- */
- public List getLayersReference() {
- return layers;
- }
-
- public int getLayerCount() {
- return layers.size();
- }
-
- public PLayer getLayer(int index) {
- return (PLayer) layers.get(index);
- }
-
- public int indexOfLayer(PLayer layer) {
- return layers.indexOf(layer);
- }
-
- /**
- * Add the layer to the end of this camera's list of layers.
- * Layers may be viewed by multiple cameras at once.
- */
- public void addLayer(PLayer layer) {
- addLayer(layers.size(), layer);
- }
-
- /**
- * Add the layer at the given index in this camera's list of layers.
- * Layers may be viewed by multiple cameras at once.
- */
- public void addLayer(int index, PLayer layer) {
- layers.add(index, layer);
- layer.addCamera(this);
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_LAYERS ,PROPERTY_LAYERS, null, layers);
- }
-
- /**
- * Remove the given layer from the list of layers managed by this
- * camera.
- */
- public PLayer removeLayer(PLayer layer) {
- return removeLayer(layers.indexOf(layer));
- }
-
- /**
- * Remove the layer at the given index from the list of
- * layers managed by this camera.
- */
- public PLayer removeLayer(int index) {
- PLayer layer = (PLayer) layers.remove(index);
- layer.removeCamera(this);
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_LAYERS, PROPERTY_LAYERS, null, layers);
- return layer;
- }
-
- /**
- * Return the total bounds of all the layers that this camera looks at.
- */
- public PBounds getUnionOfLayerFullBounds() {
- PBounds result = new PBounds();
-
- int count = getLayerCount();
- for (int i = 0; i < count; i++) {
- PLayer each = (PLayer) layers.get(i);
- result.add(each.getFullBoundsReference());
- }
-
- return result;
- }
-
- //****************************************************************
- // Painting Layers
- //****************************************************************
-
- /**
- * Paint this camera (default background color is white) and then paint
- * the cameras view through the view transform.
- */
- protected void paint(PPaintContext paintContext) {
- super.paint(paintContext);
-
- paintContext.pushClip(getBoundsReference());
- paintContext.pushTransform(viewTransform);
-
- paintCameraView(paintContext);
- paintDebugInfo(paintContext);
-
- paintContext.popTransform(viewTransform);
- paintContext.popClip(getBoundsReference());
- }
-
- /**
- * Paint all the layers that the camera is looking at, this method is
- * only called when the cameras view transform and clip are applied
- * to the paintContext.
- */
- protected void paintCameraView(PPaintContext paintContext) {
- int count = getLayerCount();
- for (int i = 0; i < count; i++) {
- PLayer each = (PLayer) layers.get(i);
- each.fullPaint(paintContext);
- }
- }
-
- protected void paintDebugInfo(PPaintContext paintContext) {
- if (PDebug.debugBounds || PDebug.debugFullBounds) {
- Graphics2D g2 = paintContext.getGraphics();
- paintContext.setRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- g2.setStroke(new BasicStroke(0));
- ArrayList nodes = new ArrayList();
- PBounds nodeBounds = new PBounds();
-
- Color boundsColor = Color.red;
- Color fullBoundsColor = new Color(1.0f, 0f, 0f, 0.2f);
-
- for (int i = 0; i < getLayerCount(); i++) {
- getLayer(i).getAllNodes(null, nodes);
- }
-
- Iterator i = getAllNodes(null, nodes).iterator();
-
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
-
- if (PDebug.debugBounds) {
- g2.setPaint(boundsColor);
- nodeBounds.setRect(each.getBoundsReference());
-
- if (!nodeBounds.isEmpty()) {
- each.localToGlobal(nodeBounds);
- globalToLocal(nodeBounds);
- if (each == this || each.isDescendentOf(this)) {
- localToView(nodeBounds);
- }
- g2.draw(nodeBounds);
- }
- }
-
- if (PDebug.debugFullBounds) {
- g2.setPaint(fullBoundsColor);
- nodeBounds.setRect(each.getFullBoundsReference());
-
- if (!nodeBounds.isEmpty()) {
- if (each.getParent() != null) {
- each.getParent().localToGlobal(nodeBounds);
- }
- globalToLocal(nodeBounds);
- if (each == this || each.isDescendentOf(this)) {
- localToView(nodeBounds);
- }
- g2.fill(nodeBounds);
- }
- }
- }
- }
- }
-
- /**
- * Override fullPaint to push the camera onto the paintContext so that it
- * can be later be accessed by PPaintContext.getCamera();
- */
- public void fullPaint(PPaintContext paintContext) {
- paintContext.pushCamera(this);
- super.fullPaint(paintContext);
- paintContext.popCamera(this);
- }
-
- //****************************************************************
- // Picking
- //****************************************************************
-
- /**
- * Generate and return a PPickPath for the point x,y specified in the local
- * coord system of this camera. Picking is done with a rectangle, halo
- * specifies how large that rectangle will be.
- */
- public PPickPath pick(double x, double y, double halo) {
- PBounds b = new PBounds(new Point2D.Double(x, y), -halo, -halo);
- PPickPath result = new PPickPath(this, b);
-
- fullPick(result);
-
- // make sure this camera is pushed.
- if (result.getNodeStackReference().size() == 0) {
- result.pushNode(this);
- result.pushTransform(getTransformReference(false));
- }
-
- return result;
- }
-
- /**
- * After the direct children of the camera have been given a chance to be
- * picked objects viewed by the camera are given a chance to be picked.
- */
- protected boolean pickAfterChildren(PPickPath pickPath) {
- if (intersects(pickPath.getPickBounds())) {
- pickPath.pushTransform(viewTransform);
-
- if (pickCameraView(pickPath)) {
- return true;
- }
-
- pickPath.popTransform(viewTransform);
- return true;
- }
- return false;
- }
-
- /**
- * Pick all the layers that the camera is looking at, this method is
- * only called when the cameras view transform and clip are applied
- * to the pickPath.
- */
- protected boolean pickCameraView(PPickPath pickPath) {
- int count = getLayerCount();
- for (int i = count - 1; i >= 0; i--) {
- PLayer each = (PLayer) layers.get(i);
- if (each.fullPick(pickPath)) {
- return true;
- }
- }
- return false;
- }
-
-
- //****************************************************************
- // View Transform - Methods for accessing the view transform. The
- // view transform is applied before painting and picking the cameras
- // layers. But not before painting or picking its direct children.
- //
- // Changing the view transform is how zooming and panning are
- // accomplished.
- //****************************************************************
-
- /**
- * Return the bounds of this camera in the view coordinate system.
- */
- public PBounds getViewBounds() {
- return (PBounds) localToView(getBounds());
- }
-
- /**
- * Translates and scales the camera's view transform so that the given bounds (in camera
- * layer's coordinate system)are centered withing the cameras view bounds. Use this method
- * to point the camera at a given location.
- */
- public void setViewBounds(Rectangle2D centerBounds) {
- animateViewToCenterBounds(centerBounds, true, 0);
- }
-
- /**
- * Return the scale applied by the view transform to the layers
- * viewed by this camera.
- */
- public double getViewScale() {
- return viewTransform.getScale();
- }
-
- /**
- * Scale the view transform that is applied to the layers
- * viewed by this camera by the given amount.
- */
- public void scaleView(double scale) {
- scaleViewAboutPoint(scale, 0, 0);
- }
-
- /**
- * Scale the view transform that is applied to the layers
- * viewed by this camera by the given amount about the given point.
- */
- public void scaleViewAboutPoint(double scale, double x, double y) {
- viewTransform.scaleAboutPoint(scale, x, y);
- applyViewConstraints();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_VIEW_TRANSFORM, PROPERTY_VIEW_TRANSFORM, null, viewTransform);
- }
-
- /**
- * Set the scale of the view transform that is applied to
- * the layers viewed by this camera.
- */
- public void setViewScale(double scale) {
- scaleView(scale / getViewScale());
- }
-
- /**
- * Translate the view transform that is applied to the camera's
- * layers.
- */
- public void translateView(double dx, double dy) {
- viewTransform.translate(dx, dy);
- applyViewConstraints();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_VIEW_TRANSFORM, PROPERTY_VIEW_TRANSFORM, null, viewTransform);
- }
-
- /**
- * Sets the offset of the view transform that is applied
- * to the camera's layers.
- */
- public void setViewOffset(double x, double y) {
- viewTransform.setOffset(x, y);
- applyViewConstraints();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_VIEW_TRANSFORM, PROPERTY_VIEW_TRANSFORM, null, viewTransform);
- }
-
- /**
- * Get a copy of the view transform that is applied to the camera's
- * layers.
- */
- public PAffineTransform getViewTransform() {
- return (PAffineTransform) viewTransform.clone();
- }
-
- /**
- * Get a reference to the view transform that is applied to the camera's
- * layers.
- */
- public PAffineTransform getViewTransformReference() {
- return viewTransform;
- }
-
- /**
- * Set the view transform that is applied to the views layers.
- */
- public void setViewTransform(AffineTransform aTransform) {
- viewTransform.setTransform(aTransform);
- applyViewConstraints();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_VIEW_TRANSFORM, PROPERTY_VIEW_TRANSFORM, null, viewTransform);
- }
-
- /**
- * Animate the camera's view from its current transform when the activity
- * starts to a new transform that centers the given bounds in the camera
- * layers coordinate system into the cameras view bounds. If the duration is
- * 0 then the view will be transformed immediately, and null will be
- * returned. Else a new PTransformActivity will get returned that is set to
- * animate the camera's view transform to the new bounds. If shouldScale
- * is true, then the camera will also scale its view so that the given
- * bounds fit fully within the cameras view bounds, else the camera will
- * maintain its original scale.
- */
- public PTransformActivity animateViewToCenterBounds(Rectangle2D centerBounds, boolean shouldScaleToFit, long duration) {
- PBounds viewBounds = getViewBounds();
- PDimension delta = viewBounds.deltaRequiredToCenter(centerBounds);
- PAffineTransform newTransform = getViewTransform();
- newTransform.translate(delta.width, delta.height);
-
- if (shouldScaleToFit) {
- double s = Math.min(viewBounds.getWidth() / centerBounds.getWidth(), viewBounds.getHeight() / centerBounds.getHeight());
- if (s != Double.POSITIVE_INFINITY && s != 0) {
- newTransform.scaleAboutPoint(s, centerBounds.getCenterX(), centerBounds.getCenterY());
- }
- }
-
- return animateViewToTransform(newTransform, duration);
- }
-
- /**
- * Pan the camera's view from its current transform when the activity starts
- * to a new transform so that the view bounds will contain (if possible, intersect
- * if not possible) the new bounds in the camera layers coordinate system.
- * If the duration is 0 then the view will be transformed immediately, and null
- * will be returned. Else a new PTransformActivity will get returned that is set
- * to animate the camera's view transform to the new bounds.
- */
- public PTransformActivity animateViewToPanToBounds(Rectangle2D panToBounds, long duration) {
- PBounds viewBounds = getViewBounds();
- PDimension delta = viewBounds.deltaRequiredToContain(panToBounds);
-
- if (delta.width != 0 || delta.height != 0) {
- if (duration == 0) {
- translateView(-delta.width, -delta.height);
- } else {
- AffineTransform at = getViewTransform();
- at.translate(-delta.width, -delta.height);
- return animateViewToTransform(at, duration);
- }
- }
-
- return null;
- }
-
- /**
- * @deprecated Renamed to animateViewToPanToBounds
- */
- public PTransformActivity animateViewToIncludeBounds(Rectangle2D includeBounds, long duration) {
- return animateViewToPanToBounds(includeBounds, duration);
- }
-
- /**
- * Animate the cameras view transform from its current value when the
- * activity starts to the new destination transform value.
- */
- public PTransformActivity animateViewToTransform(AffineTransform destination, long duration) {
- if (duration == 0) {
- setViewTransform(destination);
- return null;
- }
-
- PTransformActivity.Target t = new PTransformActivity.Target() {
- public void setTransform(AffineTransform aTransform) {
- PCamera.this.setViewTransform(aTransform);
- }
- public void getSourceMatrix(double[] aSource) {
- PCamera.this.viewTransform.getMatrix(aSource);
- }
- };
-
- PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destination);
-
- PRoot r = getRoot();
- if (r != null) {
- r.getActivityScheduler().addActivity(ta);
- }
-
- return ta;
- }
-
- //****************************************************************
- // View Transform Constraints - Methods for setting and applying
- // constraints to the view transform.
- //****************************************************************
-
- public int getViewConstraint() {
- return viewConstraint;
- }
- public void setViewConstraint(int constraint) {
- viewConstraint = constraint;
- applyViewConstraints();
- }
-
- protected void applyViewConstraints() {
- if (viewConstraint == VIEW_CONSTRAINT_NONE)
- return;
-
- PBounds viewBounds = getViewBounds();
- PBounds layerBounds = (PBounds) globalToLocal(getUnionOfLayerFullBounds());
- PDimension constraintDelta = null;
-
- switch (viewConstraint) {
- case VIEW_CONSTRAINT_ALL:
- constraintDelta = viewBounds.deltaRequiredToContain(layerBounds);
- break;
-
- case VIEW_CONSTRAINT_CENTER:
- layerBounds.setRect(layerBounds.getCenterX(), layerBounds.getCenterY(), 0, 0);
- constraintDelta = viewBounds.deltaRequiredToContain(layerBounds);
- break;
- }
-
- viewTransform.translate(-constraintDelta.width, -constraintDelta.height);
- }
-
- //****************************************************************
- // Camera View Coord System Conversions - Methods to translate from
- // the camera's local coord system (above the camera's view transform) to the
- // camera view coord system (below the camera's view transform). When
- // converting geometry from one of the canvas's layers you must go
- // through the view transform.
- //****************************************************************
-
- /**
- * Convert the point from the camera's view coordinate system to the
- * camera's local coordinate system. The given point is modified by this.
- */
- public Point2D viewToLocal(Point2D viewPoint) {
- return viewTransform.transform(viewPoint, viewPoint);
- }
-
- /**
- * Convert the dimension from the camera's view coordinate system to the
- * camera's local coordinate system. The given dimension is modified by this.
- */
- public Dimension2D viewToLocal(Dimension2D viewDimension) {
- return viewTransform.transform(viewDimension, viewDimension);
- }
-
- /**
- * Convert the rectangle from the camera's view coordinate system to the
- * camera's local coordinate system. The given rectangle is modified by this method.
- */
- public Rectangle2D viewToLocal(Rectangle2D viewRectangle) {
- return viewTransform.transform(viewRectangle, viewRectangle);
- }
-
- /**
- * Convert the point from the camera's local coordinate system to the
- * camera's view coordinate system. The given point is modified by this method.
- */
- public Point2D localToView(Point2D localPoint) {
- try {
- return viewTransform.inverseTransform(localPoint, localPoint);
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Convert the dimension from the camera's local coordinate system to the
- * camera's view coordinate system. The given dimension is modified by this method.
- */
- public Dimension2D localToView(Dimension2D localDimension) {
- return viewTransform.inverseTransform(localDimension, localDimension);
- }
-
- /**
- * Convert the rectangle from the camera's local coordinate system to the
- * camera's view coordinate system. The given rectangle is modified by this method.
- */
- public Rectangle2D localToView(Rectangle2D localRectangle) {
- return viewTransform.inverseTransform(localRectangle, localRectangle);
- }
-
- //****************************************************************
- // Serialization - Cameras conditionally serialize their layers.
- // This means that only the layer references that were unconditionally
- // (using writeObject) serialized by someone else will be restored
- // when the camera is unserialized.
- //****************************************************************/
-
- /**
- * Write this camera and all its children out to the given stream. Note
- * that the cameras layers are written conditionally, so they will only
- * get written out if someone else writes them unconditionally.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
-
- int count = getLayerCount();
- for (int i = 0; i < count; i++) {
- ((PObjectOutputStream)out).writeConditionalObject(layers.get(i));
- }
-
- out.writeObject(Boolean.FALSE);
- ((PObjectOutputStream)out).writeConditionalObject(component);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
-
- layers = new ArrayList();
-
- while (true) {
- Object each = in.readObject();
- if (each != null) {
- if (each.equals(Boolean.FALSE)) {
- break;
- } else {
- layers.add((PLayer)each);
- }
- }
- }
-
- component = (PComponent) in.readObject();
- }
-}
-
diff --git a/src/main/java/edu/umd/cs/piccolo/PCanvas.java b/src/main/java/edu/umd/cs/piccolo/PCanvas.java
deleted file mode 100755
index 894f177..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PCanvas.java
+++ /dev/null
@@ -1,609 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.event.ActionListener;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-
-import javax.swing.JComponent;
-import javax.swing.RepaintManager;
-import javax.swing.Timer;
-
-import edu.umd.cs.piccolo.event.PInputEventListener;
-import edu.umd.cs.piccolo.event.PPanEventHandler;
-import edu.umd.cs.piccolo.event.PZoomEventHandler;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PStack;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PCanvas is a simple Swing component that can be used to embed
- * Piccolo into a Java Swing application. Canvases view the Piccolo scene graph
- * through a camera. The canvas manages screen updates coming from this camera,
- * and forwards swing mouse and keyboard events to the camera.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PCanvas extends JComponent implements PComponent {
-
- /**
- *
- */
- private static final long serialVersionUID = -3189990907056781407L;
-
- public static final String INTERATING_CHANGED_NOTIFICATION = "INTERATING_CHANGED_NOTIFICATION";
-
- public static PCanvas CURRENT_ZCANVAS = null;
-
- private PCamera camera;
- private PStack cursorStack;
- private int interacting;
- private int defaultRenderQuality;
- private int animatingRenderQuality;
- private int interactingRenderQuality;
- private PPanEventHandler panEventHandler;
- private PZoomEventHandler zoomEventHandler;
- private boolean paintingImmediately;
- private boolean animatingOnLastPaint;
- private MouseListener mouseListener;
- private KeyListener keyListener;
- private MouseWheelListener mouseWheelListener;
- private MouseMotionListener mouseMotionListener;
-
- /**
- * Construct a canvas with the basic scene graph consisting of a
- * root, camera, and layer. Event handlers for zooming and panning
- * are automatically installed.
- */
- public PCanvas() {
- CURRENT_ZCANVAS = this;
- cursorStack = new PStack();
- setCamera(createDefaultCamera());
- installInputSources();
- setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
- setAnimatingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- setInteractingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- setPanEventHandler(new PPanEventHandler());
- setZoomEventHandler(new PZoomEventHandler());
- setBackground(Color.WHITE);
- }
-
- protected PCamera createDefaultCamera() {
- return PUtil.createBasicScenegraph();
- }
-
- //****************************************************************
- // Basic - Methods for accessing common piccolo nodes.
- //****************************************************************
-
- /**
- * Get the pan event handler associated with this canvas. This event handler
- * is set up to get events from the camera associated with this canvas by
- * default.
- */
- public PPanEventHandler getPanEventHandler() {
- return panEventHandler;
- }
-
- /**
- * Set the pan event handler associated with this canvas.
- * @param handler the new zoom event handler
- */
- public void setPanEventHandler(PPanEventHandler handler) {
- if(panEventHandler != null) {
- removeInputEventListener(panEventHandler);
- }
-
- panEventHandler = handler;
-
- if(panEventHandler != null) {
- addInputEventListener(panEventHandler);
- }
- }
-
- /**
- * Get the zoom event handler associated with this canvas. This event handler
- * is set up to get events from the camera associated with this canvas by
- * default.
- */
- public PZoomEventHandler getZoomEventHandler() {
- return zoomEventHandler;
- }
-
- /**
- * Set the zoom event handler associated with this canvas.
- * @param handler the new zoom event handler
- */
- public void setZoomEventHandler(PZoomEventHandler handler) {
- if(zoomEventHandler != null) {
- removeInputEventListener(zoomEventHandler);
- }
-
- zoomEventHandler = handler;
-
- if(zoomEventHandler != null) {
- addInputEventListener(zoomEventHandler);
- }
- }
-
- /**
- * Return the camera associated with this canvas. All input events from this canvas
- * go through this camera. And this is the camera that paints this canvas.
- */
- public PCamera getCamera() {
- return camera;
- }
-
- /**
- * Set the camera associated with this canvas. All input events from this canvas
- * go through this camera. And this is the camera that paints this canvas.
- */
- public void setCamera(PCamera newCamera) {
- if (camera != null) {
- camera.setComponent(null);
- }
-
- camera = newCamera;
-
- if (camera != null) {
- camera.setComponent(this);
- camera.setBounds(getBounds());
- }
- }
-
- /**
- * Return root for this canvas.
- */
- public PRoot getRoot() {
- return camera.getRoot();
- }
-
- /**
- * Return layer for this canvas.
- */
- public PLayer getLayer() {
- return camera.getLayer(0);
- }
-
- /**
- * Add an input listener to the camera associated with this canvas.
- */
- public void addInputEventListener(PInputEventListener listener) {
- getCamera().addInputEventListener(listener);
- }
-
- /**
- * Remove an input listener to the camera associated with this canvas.
- */
- public void removeInputEventListener(PInputEventListener listener) {
- getCamera().removeInputEventListener(listener);
- }
-
- //****************************************************************
- // Painting
- //****************************************************************
-
- /**
- * Return true if this canvas has been marked as interacting. If so
- * the canvas will normally render at a lower quality that is faster.
- */
- public boolean getInteracting() {
- return interacting > 0;
- }
-
- /**
- * Return true if any activities that respond with true to the method
- * isAnimating were run in the last PRoot.processInputs() loop. This
- * values is used by this canvas to determine the render quality
- * to use for the next paint.
- */
- public boolean getAnimating() {
- return getRoot().getActivityScheduler().getAnimating();
- }
-
- /**
- * Set if this canvas is interacting. If so the canvas will normally
- * render at a lower quality that is faster. Also repaints the canvas if the
- * render quality should change.
- */
- public void setInteracting(boolean isInteracting) {
- boolean wasInteracting = getInteracting();
-
- if (isInteracting) {
- interacting++;
- } else {
- interacting--;
- }
-
- if (!getInteracting()) { // determine next render quality and repaint if it's greater then the old
- // interacting render quality.
- int nextRenderQuality = defaultRenderQuality;
- if (getAnimating()) nextRenderQuality = animatingRenderQuality;
- if (nextRenderQuality > interactingRenderQuality) {
- repaint();
- }
- }
-
- isInteracting = getInteracting();
-
- if (wasInteracting != isInteracting) {
- firePropertyChange(INTERATING_CHANGED_NOTIFICATION, wasInteracting, isInteracting);
- }
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas
- * when it is not interacting or animating. The default value is
- * PPaintContext. HIGH_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setDefaultRenderQuality(int requestedQuality) {
- defaultRenderQuality = requestedQuality;
- repaint();
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas
- * when it is animating. The default value is PPaintContext.LOW_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setAnimatingRenderQuality(int requestedQuality) {
- animatingRenderQuality = requestedQuality;
- if (getAnimating()) repaint();
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas
- * when it is interacting. The default value is PPaintContext.LOW_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setInteractingRenderQuality(int requestedQuality) {
- interactingRenderQuality = requestedQuality;
- if (getInteracting()) repaint();
- }
-
- /**
- * Set the canvas cursor, and remember the previous cursor on the
- * cursor stack.
- */
- public void pushCursor(Cursor cursor) {
- cursorStack.push(getCursor());
- setCursor(cursor);
- }
-
- /**
- * Pop the cursor on top of the cursorStack and set it as the
- * canvas cursor.
- */
- public void popCursor() {
- setCursor((Cursor)cursorStack.pop());
- }
-
- //****************************************************************
- // Code to manage connection to Swing. There appears to be a bug in
- // swing where it will occasionally send to many mouse pressed or mouse
- // released events. Below we attempt to filter out those cases before
- // they get delivered to the Piccolo framework.
- //****************************************************************
-
- private boolean isButton1Pressed;
- private boolean isButton2Pressed;
- private boolean isButton3Pressed;
-
- /**
- * Overrride setEnabled to install/remove canvas input sources as needed.
- */
- public void setEnabled(boolean enabled) {
- super.setEnabled(enabled);
-
- if (isEnabled()) {
- installInputSources();
- } else {
- removeInputSources();
- }
- }
-
- /**
- * This method installs mouse and key listeners on the canvas that forward
- * those events to piccolo.
- */
- protected void installInputSources() {
- if (mouseListener == null) {
- mouseListener = new MouseListener() {
- public void mouseClicked(MouseEvent e) {
- sendInputEventToInputManager(e, MouseEvent.MOUSE_CLICKED);
- }
-
- public void mouseEntered(MouseEvent e) {
- MouseEvent simulated = null;
-
- if ((e.getModifiersEx() & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
- simulated = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_DRAGGED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- } else {
- simulated = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_MOVED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- }
-
- sendInputEventToInputManager(e, MouseEvent.MOUSE_ENTERED);
- sendInputEventToInputManager(simulated, simulated.getID());
- }
-
- public void mouseExited(MouseEvent e) {
- MouseEvent simulated = null;
-
- if ((e.getModifiersEx() & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
- simulated = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_DRAGGED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- } else {
- simulated = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_MOVED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- }
-
- sendInputEventToInputManager(simulated, simulated.getID());
- sendInputEventToInputManager(e, MouseEvent.MOUSE_EXITED);
- }
-
- public void mousePressed(MouseEvent e) {
- requestFocus();
-
- boolean shouldBalanceEvent = false;
-
- if (e.getButton() == MouseEvent.NOBUTTON) {
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_PRESSED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON1);
- }
- else if ((e.getModifiers() & MouseEvent.BUTTON2_MASK) == MouseEvent.BUTTON2_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_PRESSED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON2);
- }
- else if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_PRESSED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON3);
- }
- }
-
- switch (e.getButton()) {
- case MouseEvent.BUTTON1:
- if (isButton1Pressed) {
- shouldBalanceEvent = true;
- }
- isButton1Pressed = true;
- break;
-
- case MouseEvent.BUTTON2:
- if (isButton2Pressed) {
- shouldBalanceEvent = true;
- }
- isButton2Pressed = true;
- break;
-
- case MouseEvent.BUTTON3:
- if (isButton3Pressed) {
- shouldBalanceEvent = true;
- }
- isButton3Pressed = true;
- break;
- }
-
- if (shouldBalanceEvent) {
- MouseEvent balanceEvent = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_RELEASED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- sendInputEventToInputManager(balanceEvent, MouseEvent.MOUSE_RELEASED);
- }
-
- sendInputEventToInputManager(e, MouseEvent.MOUSE_PRESSED);
- }
-
- public void mouseReleased(MouseEvent e) {
- boolean shouldBalanceEvent = false;
-
- if (e.getButton() == MouseEvent.NOBUTTON) {
- if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_RELEASED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON1);
- }
- else if ((e.getModifiers() & MouseEvent.BUTTON2_MASK) == MouseEvent.BUTTON2_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_RELEASED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON2);
- }
- else if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK) {
- e = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_RELEASED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),MouseEvent.BUTTON3);
- }
- }
-
- switch (e.getButton()) {
- case MouseEvent.BUTTON1:
- if (!isButton1Pressed) {
- shouldBalanceEvent = true;
- }
- isButton1Pressed = false;
- break;
-
- case MouseEvent.BUTTON2:
- if (!isButton2Pressed) {
- shouldBalanceEvent = true;
- }
- isButton2Pressed = false;
- break;
-
- case MouseEvent.BUTTON3:
- if (!isButton3Pressed) {
- shouldBalanceEvent = true;
- }
- isButton3Pressed = false;
- break;
- }
-
- if (shouldBalanceEvent) {
- MouseEvent balanceEvent = new MouseEvent((Component)e.getSource(),MouseEvent.MOUSE_PRESSED,e.getWhen(),e.getModifiers(),e.getX(),e.getY(),e.getClickCount(),e.isPopupTrigger(),e.getButton());
- sendInputEventToInputManager(balanceEvent, MouseEvent.MOUSE_PRESSED);
- }
-
- sendInputEventToInputManager(e, MouseEvent.MOUSE_RELEASED);
- }
- };
- addMouseListener(mouseListener);
- }
-
- if (mouseMotionListener == null) {
- mouseMotionListener = new MouseMotionListener() {
- public void mouseDragged(MouseEvent e) {
- sendInputEventToInputManager(e, MouseEvent.MOUSE_DRAGGED);
- }
- public void mouseMoved(MouseEvent e) {
- sendInputEventToInputManager(e, MouseEvent.MOUSE_MOVED);
- }
- };
- addMouseMotionListener(mouseMotionListener);
- }
-
- if (mouseWheelListener == null) {
- mouseWheelListener = new MouseWheelListener() {
- public void mouseWheelMoved(MouseWheelEvent e) {
- sendInputEventToInputManager(e, e.getScrollType());
- if (!e.isConsumed() && getParent() != null) {
- getParent().dispatchEvent(e);
- }
- }
- };
- addMouseWheelListener(mouseWheelListener);
- }
-
- if (keyListener == null) {
- keyListener = new KeyListener() {
- public void keyPressed(KeyEvent e) {
- sendInputEventToInputManager(e, KeyEvent.KEY_PRESSED);
- }
- public void keyReleased(KeyEvent e) {
- sendInputEventToInputManager(e, KeyEvent.KEY_RELEASED);
- }
- public void keyTyped(KeyEvent e) {
- sendInputEventToInputManager(e, KeyEvent.KEY_TYPED);
- }
- };
- addKeyListener(keyListener);
- }
- }
-
- /**
- * This method removes mouse and key listeners on the canvas that forward
- * those events to piccolo.
- */
- protected void removeInputSources() {
- if (mouseListener != null) removeMouseListener(mouseListener);
- if (mouseMotionListener != null) removeMouseMotionListener(mouseMotionListener);
- if (mouseWheelListener != null) removeMouseWheelListener(mouseWheelListener);
- if (keyListener != null) removeKeyListener(keyListener);
-
- mouseListener = null;
- mouseMotionListener = null;
- mouseWheelListener = null;
- keyListener = null;
- }
-
- protected void sendInputEventToInputManager(InputEvent e, int type) {
- getRoot().getDefaultInputManager().processEventFromCamera(e, type, getCamera());
- }
-
- public void setBounds(int x, int y, final int w, final int h) {
- camera.setBounds(camera.getX(), camera.getY(), w, h);
- super.setBounds(x, y, w, h);
- }
-
- public void repaint(PBounds bounds) {
- PDebug.processRepaint();
-
- bounds.expandNearestIntegerDimensions();
- bounds.inset(-1, -1);
-
- repaint((int)bounds.x,
- (int)bounds.y,
- (int)bounds.width,
- (int)bounds.height);
- }
-
- public void paintComponent(Graphics g) {
- PDebug.startProcessingOutput();
-
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setColor(getBackground());
- g2.fillRect(0, 0, getWidth(), getHeight());
-
- // create new paint context and set render quality to lowest common
- // denominator render quality.
- PPaintContext paintContext = new PPaintContext(g2);
- if (getInteracting() || getAnimating()) {
- if (interactingRenderQuality < animatingRenderQuality) {
- paintContext.setRenderQuality(interactingRenderQuality);
- } else {
- paintContext.setRenderQuality(animatingRenderQuality);
- }
- } else {
- paintContext.setRenderQuality(defaultRenderQuality);
- }
-
- // paint piccolo
- camera.fullPaint(paintContext);
-
- // if switched state from animating to not animating invalidate the entire
- // screen so that it will be drawn with the default instead of animating
- // render quality.
- if (!getAnimating() && animatingOnLastPaint) {
- repaint();
- }
- animatingOnLastPaint = getAnimating();
-
- PDebug.endProcessingOutput(g2);
- }
-
- public void paintImmediately() {
- if (paintingImmediately) {
- return;
- }
-
- paintingImmediately = true;
- RepaintManager.currentManager(this).paintDirtyRegions();
- paintingImmediately = false;
- }
-
- public Timer createTimer(int delay, ActionListener listener) {
- return new Timer(delay,listener);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/PComponent.java b/src/main/java/edu/umd/cs/piccolo/PComponent.java
deleted file mode 100755
index 45a1780..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PComponent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.awt.Cursor;
-
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * Interface that a component needs to implement if it wants to act as a Piccolo
- * canvas.
- *
- * @version 1.0
- * @author Lance Good
- */
-public interface PComponent {
-
- public void repaint(PBounds bounds);
-
- public void paintImmediately();
-
- public void pushCursor(Cursor cursor);
-
- public void popCursor();
-
- public void setInteracting(boolean interacting);
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/PInputManager.java b/src/main/java/edu/umd/cs/piccolo/PInputManager.java
deleted file mode 100755
index b810cb6..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PInputManager.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.awt.event.FocusEvent;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PInputManager is responsible for dispatching PInputEvents
- * to node's event listeners. Events are dispatched from PRoot's processInputs
- * method.
- *
- * @see edu.umd.cs.piccolo.event.PInputEvent
- * @see PRoot
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PInputManager extends PBasicInputEventHandler implements PRoot.InputSource {
-
- private Point2D lastCanvasPosition;
- private Point2D currentCanvasPosition;
-
- private InputEvent nextInput;
- private int nextType;
- private PCamera nextInputSource;
-
- private PPickPath mouseFocus;
- private PPickPath previousMouseFocus;
- private PPickPath mouseOver;
- private PPickPath previousMouseOver;
- private PInputEventListener keyboardFocus;
-
- private int pressedCount;
-
- public PInputManager() {
- super();
- lastCanvasPosition = new Point2D.Double();
- currentCanvasPosition = new Point2D.Double();
- }
-
- //****************************************************************
- // Basic
- //****************************************************************
-
- /**
- * Return the node that currently has the keyboard focus. This node
- * receives the key events.
- */
- public PInputEventListener getKeyboardFocus() {
- return keyboardFocus;
- }
-
- /**
- * Set the node that should recive key events.
- */
- public void setKeyboardFocus(PInputEventListener eventHandler) {
- PInputEvent focusEvent = new PInputEvent(this, null);
-
- if (keyboardFocus != null) {
- dispatchEventToListener(focusEvent, FocusEvent.FOCUS_LOST, keyboardFocus);
- }
-
- keyboardFocus = eventHandler;
-
- if (keyboardFocus != null) {
- dispatchEventToListener(focusEvent, FocusEvent.FOCUS_GAINED, keyboardFocus);
- }
- }
-
- /**
- * Return the node that currently has the mouse focus. This will return
- * the node that received the current mouse pressed event, or null if the
- * mouse is not pressed. The mouse focus gets mouse dragged events even
- * what the mouse is not over the mouse focus.
- */
- public PPickPath getMouseFocus() {
- return mouseFocus;
- }
-
- public void setMouseFocus(PPickPath path) {
- previousMouseFocus = mouseFocus;
- mouseFocus = path;
- }
-
- /**
- * Return the node the the mouse is currently over.
- */
- public PPickPath getMouseOver() {
- return mouseOver;
- }
-
- public void setMouseOver(PPickPath path) {
- mouseOver = path;
- }
-
- public Point2D getLastCanvasPosition() {
- return lastCanvasPosition;
- }
-
- public Point2D getCurrentCanvasPosition() {
- return currentCanvasPosition;
- }
-
- //****************************************************************
- // Event Handling - Methods for handling events
- //
- // The dispatch manager updates the focus nodes based on the
- // incoming events, and dispatches those events to the appropriate
- // focus nodes.
- //****************************************************************
-
- public void keyPressed(PInputEvent event) {
- dispatchEventToListener(event, KeyEvent.KEY_PRESSED, keyboardFocus);
- }
-
- public void keyReleased(PInputEvent event) {
- dispatchEventToListener(event, KeyEvent.KEY_RELEASED, keyboardFocus);
- }
-
- public void keyTyped(PInputEvent event) {
- dispatchEventToListener(event, KeyEvent.KEY_TYPED, keyboardFocus);
- }
-
- public void mouseClicked(PInputEvent event) {
- dispatchEventToListener(event, MouseEvent.MOUSE_CLICKED, previousMouseFocus);
- }
-
- public void mouseWheelRotated(PInputEvent event) {
- setMouseFocus(getMouseOver());
- dispatchEventToListener(event, MouseWheelEvent.WHEEL_UNIT_SCROLL, mouseOver);
- }
-
- public void mouseWheelRotatedByBlock(PInputEvent event) {
- setMouseFocus(getMouseOver());
- dispatchEventToListener(event, MouseWheelEvent.WHEEL_BLOCK_SCROLL, mouseOver);
- }
-
- public void mouseDragged(PInputEvent event) {
- checkForMouseEnteredAndExited(event);
- dispatchEventToListener(event, MouseEvent.MOUSE_DRAGGED, mouseFocus);
- }
-
- public void mouseEntered(PInputEvent event) {
- dispatchEventToListener(event, MouseEvent.MOUSE_ENTERED, mouseOver);
- }
-
- public void mouseExited(PInputEvent event) {
- dispatchEventToListener(event, MouseEvent.MOUSE_EXITED, previousMouseOver);
- }
-
- public void mouseMoved(PInputEvent event) {
- checkForMouseEnteredAndExited(event);
- dispatchEventToListener(event, MouseEvent.MOUSE_MOVED, mouseOver);
- }
-
- public void mousePressed(PInputEvent event) {
- if (pressedCount == 0) {
- setMouseFocus(getMouseOver());
- }
- pressedCount++;
- dispatchEventToListener(event, MouseEvent.MOUSE_PRESSED, mouseFocus);
- if (pressedCount < 1 || pressedCount > 3) System.err.println("invalid pressedCount on mouse pressed: " + pressedCount);
- }
-
- public void mouseReleased(PInputEvent event) {
- pressedCount--;
- checkForMouseEnteredAndExited(event);
- dispatchEventToListener(event, MouseEvent.MOUSE_RELEASED, mouseFocus);
- if (pressedCount == 0) {
- setMouseFocus(null);
- }
- if (pressedCount < 0 || pressedCount > 2) System.err.println("invalid pressedCount on mouse released: " + pressedCount);
- }
-
- protected void checkForMouseEnteredAndExited(PInputEvent event) {
- PNode c = (mouseOver != null) ? mouseOver.getPickedNode() : null;
- PNode p = (previousMouseOver != null) ? previousMouseOver.getPickedNode() : null;
-
- if (c != p) {
- dispatchEventToListener(event, MouseEvent.MOUSE_EXITED, previousMouseOver);
- dispatchEventToListener(event, MouseEvent.MOUSE_ENTERED, mouseOver);
- previousMouseOver = mouseOver;
- }
- }
-
- //****************************************************************
- // Event Dispatch.
- //****************************************************************
-
- public void processInput() {
- if (nextInput == null) return;
-
- PInputEvent e = new PInputEvent(this, nextInput);
-
- Point2D newCurrentCanvasPosition = null;
- Point2D newLastCanvasPosition = null;
-
- if (e.isMouseEvent()) {
- if (e.isMouseEnteredOrMouseExited()) {
- PPickPath aPickPath = nextInputSource.pick(((MouseEvent)nextInput).getX(), ((MouseEvent)nextInput).getY(), 1);
- setMouseOver(aPickPath);
- previousMouseOver = aPickPath;
- newCurrentCanvasPosition = (Point2D) currentCanvasPosition.clone();
- newLastCanvasPosition = (Point2D) lastCanvasPosition.clone();
- } else {
- lastCanvasPosition.setLocation(currentCanvasPosition);
- currentCanvasPosition.setLocation(((MouseEvent)nextInput).getX(), ((MouseEvent)nextInput).getY());
- PPickPath aPickPath = nextInputSource.pick(currentCanvasPosition.getX(), currentCanvasPosition.getY(), 1);
- setMouseOver(aPickPath);
- }
- }
-
- nextInput = null;
- nextInputSource = null;
-
- this.processEvent(e, nextType);
-
- if (newCurrentCanvasPosition != null && newLastCanvasPosition != null) {
- currentCanvasPosition.setLocation(newCurrentCanvasPosition);
- lastCanvasPosition.setLocation(newLastCanvasPosition);
- }
- }
-
- public void processEventFromCamera(InputEvent event, int type, PCamera camera) {
- // queue input
- nextInput = event;
- nextType = type;
- nextInputSource = camera;
-
- // tell root to process queued inputs
- camera.getRoot().processInputs();
- }
-
- private void dispatchEventToListener(PInputEvent event, int type, PInputEventListener listener) {
- if (listener != null) {
- // clear the handled bit since the same event object is used to send multiple events such as
- // mouseEntered/mouseExited and mouseMove.
- event.setHandled(false);
- listener.processEvent(event, type);
- }
- }
-}
-
diff --git a/src/main/java/edu/umd/cs/piccolo/PLayer.java b/src/main/java/edu/umd/cs/piccolo/PLayer.java
deleted file mode 100755
index 33dfbe4..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PLayer.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PObjectOutputStream;
-
-/**
- * PLayer is a node that can be viewed directly by multiple camera nodes.
- * Generally child nodes are added to a layer to give the viewing cameras
- * something to look at.
- *
- * A single layer node may be viewed through multiple cameras with each
- * camera using its own view transform. This means that any node (since layers can have
- * children) may be visible through multiple cameras at the same time.
- *
- * @see PCamera
- * @see edu.umd.cs.piccolo.event.PInputEvent
- * @see edu.umd.cs.piccolo.util.PPickPath
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PLayer extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 3135722599250436769L;
- /**
- * The property name that identifies a change in the set of this layer's
- * cameras (see {@link #getCamera getCamera}, {@link #getCameraCount
- * getCameraCount}, {@link #getCamerasReference getCamerasReference}). In
- * any property change event the new value will be a reference to the list
- * of cameras, but old value will always be null.
- */
- public static final String PROPERTY_CAMERAS = "cameras";
- public static final int PROPERTY_CODE_CAMERAS = 1 << 13;
-
- private transient List cameras;
-
- public PLayer() {
- super();
- cameras = new ArrayList();
- }
-
- //****************************************************************
- // Cameras - Maintain the list of cameras that are viewing this
- // layer.
- //****************************************************************
-
- /**
- * Get the list of cameras viewing this layer.
- */
- public List getCamerasReference() {
- return cameras;
- }
-
- /**
- * Get the number of cameras viewing this layer.
- */
- public int getCameraCount() {
- if (cameras == null) {
- return 0;
- }
- return cameras.size();
- }
-
- /**
- * Get the camera in this layer's camera list at the specified index.
- */
- public PCamera getCamera(int index) {
- return (PCamera) cameras.get(index);
- }
-
- /**
- * Add a camera to this layer's camera list. This method it called automatically
- * when a layer is added to a camera.
- */
- public void addCamera(PCamera camera) {
- addCamera(cameras.size(), camera);
- }
-
- /**
- * Add a camera to this layer's camera list at the specified index. This
- * method it called automatically when a layer is added to a camera.
- */
- public void addCamera(int index, PCamera camera) {
- cameras.add(index, camera);
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_CAMERAS, PROPERTY_CAMERAS, null, cameras);
- }
-
- /**
- * Remove the camera from this layer's camera list.
- */
- public PCamera removeCamera(PCamera camera) {
- return removeCamera(cameras.indexOf(camera));
- }
-
- /**
- * Remove the camera at the given index from this layer's camera list.
- */
- public PCamera removeCamera(int index) {
- PCamera result = (PCamera) cameras.remove(index);
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_CAMERAS, PROPERTY_CAMERAS, null, cameras);
- return result;
- }
-
- //****************************************************************
- // Camera Repaint Notifications - Layer nodes must forward their
- // repaints to each camera that is viewing them so that the camera
- // views will also get repainted.
- //****************************************************************
-
- /**
- * Override repaints and forward them to the cameras that are
- * viewing this layer.
- */
- public void repaintFrom(PBounds localBounds, PNode childOrThis) {
- if (childOrThis != this) {
- localToParent(localBounds);
- }
-
- notifyCameras(localBounds);
-
- if (getParent() != null) {
- getParent().repaintFrom(localBounds, childOrThis);
- }
- }
-
- protected void notifyCameras(PBounds parentBounds) {
- int count = getCameraCount();
- for (int i = 0; i < count; i++) {
- PCamera each = (PCamera) cameras.get(i);
- each.repaintFromLayer(parentBounds, this);
- }
- }
-
- //****************************************************************
- // Serialization - Layers conditionally serialize their cameras.
- // This means that only the camera references that were unconditionally
- // (using writeObject) serialized by someone else will be restored
- // when the layer is unserialized.
- //****************************************************************
-
- /**
- * Write this layer and all its children out to the given stream. Note
- * that the layer writes out any cameras that are viewing it conditionally, so they will only
- * get written out if someone else writes them unconditionally.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
-
- int count = getCameraCount();
- for (int i = 0; i < count; i++) {
- ((PObjectOutputStream)out).writeConditionalObject(cameras.get(i));
- }
-
- out.writeObject(Boolean.FALSE);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
-
- cameras = new ArrayList();
-
- while (true) {
- Object each = in.readObject();
- if (each != null) {
- if (each.equals(Boolean.FALSE)) {
- break;
- } else {
- cameras.add((PCamera)each);
- }
- }
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/PNode.java b/src/main/java/edu/umd/cs/piccolo/PNode.java
deleted file mode 100755
index 78e9e70..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PNode.java
+++ /dev/null
@@ -1,3084 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-
-package edu.umd.cs.piccolo;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Transparency;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Dimension2D;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.print.Book;
-import java.awt.print.PageFormat;
-import java.awt.print.Paper;
-import java.awt.print.Printable;
-import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-import javax.swing.event.EventListenerList;
-import javax.swing.event.SwingPropertyChangeSupport;
-import javax.swing.text.MutableAttributeSet;
-import javax.swing.text.SimpleAttributeSet;
-
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.activities.PColorActivity;
-import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
-import edu.umd.cs.piccolo.activities.PTransformActivity;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PNodeFilter;
-import edu.umd.cs.piccolo.util.PObjectOutputStream;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PPickPath;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PNode is the central abstraction in Piccolo. All objects that are
- * visible on the screen are instances of the node class. All nodes may have
- * other "child" nodes added to them.
- *
- * See edu.umd.piccolo.examples.NodeExample.java for demonstrations of how nodes
- * can be used and how new types of nodes can be created.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PNode implements Cloneable, Serializable, Printable {
- private static final long serialVersionUID = -5710973444775892582L;
-//ORIG private static final long serialVersionUID = -5737613834659240286L;
- /**
- * The property name that identifies a change in this node's client
- * propertie (see {@link #getClientProperty getClientProperty}). In
- * an property change event the new value will be a reference to the map of
- * client properties but old value will always be null.
- */
- public static final String PROPERTY_CLIENT_PROPERTIES = "clientProperties";
- public static final int PROPERTY_CODE_CLIENT_PROPERTIES = 1 << 0;
-
- /**
- * The property name that identifies a change of this node's bounds (see
- * {@link #getBounds getBounds}, {@link #getBoundsReference
- * getBoundsReference}). In any property change event the new value will be
- * a reference to this node's bounds, but old value will always be null.
- */
- public static final String PROPERTY_BOUNDS = "bounds";
- public static final int PROPERTY_CODE_BOUNDS = 1 << 1;
-
- /**
- * The property name that identifies a change of this node's full bounds
- * (see {@link #getFullBounds getFullBounds}, {@link #getFullBoundsReference
- * getFullBoundsReference}). In any property change event the new value will
- * be a reference to this node's full bounds cache, but old value will
- * always be null.
- */
- public static final String PROPERTY_FULL_BOUNDS = "fullBounds";
- public static final int PROPERTY_CODE_FULL_BOUNDS = 1 << 2;
-
- /**
- * The property name that identifies a change of this node's transform (see
- * {@link #getTransform getTransform}, {@link #getTransformReference
- * getTransformReference}). In any property change event the new value will
- * be a reference to this node's transform, but old value will always be
- * null.
- */
- public static final String PROPERTY_TRANSFORM = "transform";
- public static final int PROPERTY_CODE_TRANSFORM = 1 << 3;
-
- /**
- * The property name that identifies a change of this node's visibility (see
- * {@link #getVisible getVisible}). Both old value and new value will be
- * null in any property change event.
- */
- public static final String PROPERTY_VISIBLE = "visible";
- public static final int PROPERTY_CODE_VISIBLE = 1 << 4;
-
- /**
- * The property name that identifies a change of this node's paint (see
- * {@link #getPaint getPaint}). Both old value and new value will be set
- * correctly in any property change event.
- */
- public static final String PROPERTY_PAINT = "paint";
- public static final int PROPERTY_CODE_PAINT = 1 << 5;
-
- /**
- * The property name that identifies a change of this node's transparency
- * (see {@link #getTransparency getTransparency}). Both old value and new
- * value will be null in any property change event.
- */
- public static final String PROPERTY_TRANSPARENCY = "transparency";
- public static final int PROPERTY_CODE_TRANSPARENCY = 1 << 6;
-
- /**
- * The property name that identifies a change of this node's pickable status
- * (see {@link #getPickable getPickable}). Both old value and new value will
- * be null in any property change event.
- */
- public static final String PROPERTY_PICKABLE = "pickable";
- public static final int PROPERTY_CODE_PICKABLE = 1 << 7;
-
- /**
- * The property name that identifies a change of this node's children
- * pickable status (see {@link #getChildrenPickable getChildrenPickable}).
- * Both old value and new value will be null in any property change event.
- */
- public static final String PROPERTY_CHILDREN_PICKABLE = "childrenPickable";
- public static final int PROPERTY_CODE_CHILDREN_PICKABLE = 1 << 8;
-
- /**
- * The property name that identifies a change in the set of this node's direct children
- * (see {@link #getChildrenReference getChildrenReference}, {@link #getChildrenIterator getChildrenIterator}).
- * In any property change event the new value will be a reference to this node's children,
- * but old value will always be null. */
- public static final String PROPERTY_CHILDREN = "children";
- public static final int PROPERTY_CODE_CHILDREN = 1 << 9;
-
- /**
- * The property name that identifies a change of this node's parent
- * (see {@link #getParent getParent}).
- * Both old value and new value will be set correctly in any property change event.
- */
- public static final String PROPERTY_PARENT = "parent";
- public static final int PROPERTY_CODE_PARENT = 1 << 10;
-
- private static final PBounds TEMP_REPAINT_BOUNDS = new PBounds();
-
- /**
- * The single scene graph delegate that recives low level node events.
- */
- public static PSceneGraphDelegate SCENE_GRAPH_DELEGATE = null;
-
- /**
- * PSceneGraphDelegate is an interface to recive low level node events. It together
- * with PNode.SCENE_GRAPH_DELEGATE gives Piccolo users an efficient way to learn about
- * low level changes in Piccolo's scene graph. Most users will not need to use this.
- */
- public interface PSceneGraphDelegate {
- public void nodePaintInvalidated(PNode node);
- public void nodeFullBoundsInvalidated(PNode node);
- }
-
- private transient PNode parent;
- private List children;
- private PBounds bounds;
- private PAffineTransform transform;
- private Paint paint;
- private float transparency;
- private MutableAttributeSet clientProperties;
- private PBounds fullBoundsCache;
-
- private int propertyChangeParentMask = 0;
- private transient SwingPropertyChangeSupport changeSupport;
- private transient EventListenerList listenerList;
-
- private boolean pickable;
- private boolean childrenPickable;
- private boolean visible;
- private boolean childBoundsVolatile;
- private boolean paintInvalid;
- private boolean childPaintInvalid;
- private boolean boundsChanged;
- private boolean fullBoundsInvalid;
- private boolean childBoundsInvalid;
- private boolean occluded;
-
- /**
- * Constructs a new PNode.
- *
- * By default a node's paint is null, and bounds are empty. These values
- * must be set for the node to show up on the screen once it's added to
- * a scene graph.
- */
- public PNode() {
- bounds = new PBounds();
- fullBoundsCache = new PBounds();
- transparency = 1.0f;
- pickable = true;
- childrenPickable = true;
- visible = true;
- }
-
- //****************************************************************
- // Animation - Methods to animate this node.
- //
- // Note that animation is implemented by activities (PActivity),
- // so if you need more control over your animation look at the
- // activities package. Each animate method creates an animation that
- // will animate the node from its current state to the new state
- // specified over the given duration. These methods will try to
- // automatically schedule the new activity, but if the node does not
- // descend from the root node when the method is called then the
- // activity will not be scheduled and you must schedule it manually.
- //****************************************************************
-
- /**
- * Animate this node's bounds from their current location when the activity
- * starts to the specified bounds. If this node descends from the root then
- * the activity will be scheduled, else the returned activity should be
- * scheduled manually. If two different transform activities are scheduled
- * for the same node at the same time, they will both be applied to the
- * node, but the last one scheduled will be applied last on each frame, so
- * it will appear to have replaced the original. Generally you will not want
- * to do that. Note this method animates the node's bounds, but does not change
- * the node's transform. Use animateTransformToBounds() to animate the node's
- * transform instead.
- *
- * @param duration amount of time that the animation should take
- * @return the newly scheduled activity
- */
- public PInterpolatingActivity animateToBounds(double x, double y, double width, double height, long duration) {
- if (duration == 0) {
- setBounds(x, y, width, height);
- return null;
- } else {
- final PBounds dst = new PBounds(x, y, width, height);
-
- PInterpolatingActivity ta = new PInterpolatingActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE) {
- private PBounds src;
-
- protected void activityStarted() {
- src = getBounds();
- startResizeBounds();
- super.activityStarted();
- }
-
- public void setRelativeTargetValue(float zeroToOne) {
- PNode.this.setBounds(src.x + (zeroToOne * (dst.x - src.x)),
- src.y + (zeroToOne * (dst.y - src.y)),
- src.width + (zeroToOne * (dst.width - src.width)),
- src.height + (zeroToOne * (dst.height - src.height)));
- }
-
- protected void activityFinished() {
- super.activityFinished();
- endResizeBounds();
- }
- };
-
- addActivity(ta);
- return ta;
- }
- }
-
- /**
- * Animate this node from it's current transform when the activity starts
- * a new transform that will fit the node into the given bounds. If this
- * node descends from the root then the activity will be scheduled, else
- * the returned activity should be scheduled manually. If two different
- * transform activities are scheduled for the same node at the same time,
- * they will both be applied to the node, but the last one scheduled will be
- * applied last on each frame, so it will appear to have replaced the original.
- * Generally you will not want to do that. Note this method animates the node's
- * transform, but does not directly change the node's bounds rectangle. Use
- * animateToBounds() to animate the node's bounds rectangle instead.
- *
- * @param duration amount of time that the animation should take
- * @return the newly scheduled activity
- */
- public PTransformActivity animateTransformToBounds(double x, double y, double width, double height, long duration) {
- PAffineTransform t = new PAffineTransform();
- t.setToScale(width / getWidth(), height / getHeight());
- double scale = t.getScale();
- t.setOffset(x - (getX() * scale), y - (getY() * scale));
- return animateToTransform(t, duration);
- }
-
- /**
- * Animate this node's transform from its current location when the
- * activity starts to the specified location, scale, and rotation. If this
- * node descends from the root then the activity will be scheduled, else the
- * returned activity should be scheduled manually. If two different
- * transform activities are scheduled for the same node at the same time,
- * they will both be applied to the node, but the last one scheduled will be
- * applied last on each frame, so it will appear to have replaced the
- * original. Generally you will not want to do that.
- *
- * @param duration amount of time that the animation should take
- * @param theta final theta value (in radians) for the animation
- * @return the newly scheduled activity
- */
- public PTransformActivity animateToPositionScaleRotation(double x, double y, double scale, double theta, long duration) {
- PAffineTransform t = getTransform();
- t.setOffset(x, y);
- t.setScale(scale);
- t.setRotation(theta);
- return animateToTransform(t, duration);
- }
-
- /**
- * Animate this node's transform from its current values when the activity
- * starts to the new values specified in the given transform. If this node
- * descends from the root then the activity will be scheduled, else the
- * returned activity should be scheduled manually. If two different
- * transform activities are scheduled for the same node at the same time,
- * they will both be applied to the node, but the last one scheduled will be
- * applied last on each frame, so it will appear to have replaced the
- * original. Generally you will not want to do that.
- *
- * @param destTransform the final transform value
- * @param duration amount of time that the animation should take
- * @return the newly scheduled activity
- */
- public PTransformActivity animateToTransform(AffineTransform destTransform, long duration) {
- if (duration == 0) {
- setTransform(destTransform);
- return null;
- } else {
- PTransformActivity.Target t = new PTransformActivity.Target() {
- public void setTransform(AffineTransform aTransform) {
- PNode.this.setTransform(aTransform);
- }
- public void getSourceMatrix(double[] aSource) {
- PNode.this.getTransformReference(true).getMatrix(aSource);
- }
- };
-
- PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destTransform);
- addActivity(ta);
- return ta;
- }
- }
-
- /**
- * Animate this node's color from its current value to the new value
- * specified. This meathod assumes that this nodes paint property is of
- * type color. If this node descends from the root then the activity will be
- * scheduled, else the returned activity should be scheduled manually. If
- * two different color activities are scheduled for the same node at the
- * same time, they will both be applied to the node, but the last one
- * scheduled will be applied last on each frame, so it will appear to have
- * replaced the original. Generally you will not want to do that.
- *
- * @param destColor final color value.
- * @param duration amount of time that the animation should take
- * @return the newly scheduled activity
- */
- public PInterpolatingActivity animateToColor(Color destColor, long duration) {
- if (duration == 0) {
- setPaint(destColor);
- return null;
- } else {
- PColorActivity.Target t = new PColorActivity.Target() {
- public Color getColor() {
- return (Color) getPaint();
- }
- public void setColor(Color color) {
- setPaint(color);
- }
- };
-
- PColorActivity ca = new PColorActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destColor);
- addActivity(ca);
- return ca;
- }
- }
-
- /**
- * Animate this node's transparency from its current value to the
- * new value specified. Transparency values must range from zero to one.
- * If this node descends from the root then the activity will be
- * scheduled, else the returned activity should be scheduled manually.
- * If two different transparency activities are scheduled for the same
- * node at the same time, they will both be applied to the node, but the
- * last one scheduled will be applied last on each frame, so it will appear
- * to have replaced the original. Generally you will not want to do that.
- *
- * @param zeroToOne final transparency value.
- * @param duration amount of time that the animation should take
- * @return the newly scheduled activity
- */
- public PInterpolatingActivity animateToTransparency(float zeroToOne, long duration) {
- if (duration == 0) {
- setTransparency(zeroToOne);
- return null;
- } else {
- final float dest = zeroToOne;
-
- PInterpolatingActivity ta = new PInterpolatingActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE) {
- private float source;
-
- protected void activityStarted() {
- source = getTransparency();
- super.activityStarted();
- }
-
- public void setRelativeTargetValue(float zeroToOne) {
- PNode.this.setTransparency(source + (zeroToOne * (dest - source)));
- }
- };
-
- addActivity(ta);
- return ta;
- }
- }
-
- /**
- * Schedule the given activity with the root, note that only scheduled
- * activities will be stepped. If the activity is successfully added true is
- * returned, else false.
- *
- * @param activity new activity to schedule
- * @return true if the activity is successfully scheduled.
- */
- public boolean addActivity(PActivity activity) {
- PRoot r = getRoot();
- if (r != null) {
- return r.addActivity(activity);
- }
- return false;
- }
-
- // ****************************************************************
- // Client Properties - Methods for managing client properties for
- // this node.
- //
- // Client properties provide a way for programmers to attach
- // extra information to a node without having to subclass it and
- // add new instance variables.
- //****************************************************************
-
- /**
- * Return mutable attributed set of client properites associated with
- * this node.
- */
- public MutableAttributeSet getClientProperties() {
- if (clientProperties == null) {
- clientProperties = new SimpleAttributeSet();
- }
- return clientProperties;
- }
-
- /**
- * Returns the value of the client attribute with the specified key. Only
- * attributes added with addAttribute
will return
- * a non-null value.
- *
- * @return the value of this attribute or null
- */
- public Object getAttribute(Object key) {
- if (clientProperties == null || key == null) {
- return null;
- } else {
- return clientProperties.getAttribute(key);
- }
- }
-
- /**
- * Add an arbitrary key/value to this node.
- *
- * The get/add attribute methods provide access to
- * a small per-instance attribute set. Callers can use get/add attribute
- * to annotate nodes that were created by another module.
- *
- * If value is null this method will remove the attribute.
- */
- public void addAttribute(Object key, Object value) {
- if (value == null && clientProperties == null) return;
-
- Object oldValue = getAttribute(key);
-
- if (value != oldValue) {
- if (clientProperties == null) {
- clientProperties = new SimpleAttributeSet();
- }
-
- if (value == null) {
- clientProperties.removeAttribute(key);
- } else {
- clientProperties.addAttribute(key, value);
- }
-
- if (clientProperties.getAttributeCount() == 0 && clientProperties.getResolveParent() == null) {
- clientProperties = null;
- }
-
- firePropertyChange(PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CLIENT_PROPERTIES, null, clientProperties);
- firePropertyChange(PROPERTY_CODE_CLIENT_PROPERTIES, key.toString(), oldValue, value);
- }
- }
-
- /**
- * Returns an enumeration of all keys maped to attribute values values.
- *
- * @return an Enumeration over attribute keys
- */
- public Enumeration> getClientPropertyKeysEnumeration() {
- if (clientProperties == null) {
- return PUtil.NULL_ENUMERATION;
- } else {
- return clientProperties.getAttributeNames();
- }
- }
-
- // convenience methods for attributes
-
- public Object getAttribute(Object key, Object def) {
- Object o = getAttribute(key);
- return (o == null ? def : o);
- }
-
- public boolean getBooleanAttribute(Object key, boolean def) {
- Boolean b = (Boolean)getAttribute(key);
- return (b == null ? def : b.booleanValue());
- }
-
- public int getIntegerAttribute(Object key, int def) {
- Number n = (Number)getAttribute(key);
- return (n == null ? def : n.intValue());
- }
-
- public double getDoubleAttribute(Object key, double def) {
- Number n = (Number)getAttribute(key);
- return (n == null ? def : n.doubleValue());
- }
-
- /**
- * @deprecated use getAttribute(Object key)instead.
- */
- public Object getClientProperty(Object key) {
- return getAttribute(key);
- }
-
- /**
- * @deprecated use addAttribute(Object key, Object value)instead.
- */
- public void addClientProperty(Object key, Object value) {
- addAttribute(key, value);
- }
-
- /**
- * @deprecated use getClientPropertyKeysEnumerator() instead.
- */
- public Iterator> getClientPropertyKeysIterator() {
- final Enumeration> enumeration = getClientPropertyKeysEnumeration();
- return new Iterator() {
- public boolean hasNext() {
- return enumeration.hasMoreElements();
- }
- public Object next() {
- return enumeration.nextElement();
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
-
- //****************************************************************
- // Copying - Methods for copying this node and its descendants.
- // Copying is implemened in terms of serialization.
- //****************************************************************
-
- /**
- * The copy method copies this node and all of its descendents. Note
- * that copying is implemented in terms of java serialization. See
- * the serialization notes for more information.
- *
- * @return new copy of this node or null if the node was not serializable
- */
- public Object clone() {
- try {
- byte[] ser = PObjectOutputStream.toByteArray(this);
- return (PNode) new ObjectInputStream(new ByteArrayInputStream(ser)).readObject();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- //****************************************************************
- // Coordinate System Conversions - Methods for converting
- // geometry between this nodes local coordinates and the other
- // major coordinate systems.
- //
- // Each nodes has an affine transform that it uses to define its
- // own coordinate system. For example if you create a new node and
- // add it to the canvas it will appear in the upper right corner. Its
- // coordinate system matches the coordinate system of its parent
- // (the root node) at this point. But if you move this node by calling
- // node.translate() the nodes affine transform will be modified and the
- // node will appear at a different location on the screen. The node
- // coordinate system no longer matches the coordinate system of its
- // parent.
- //
- // This is useful because it means that the node's methods for
- // rendering and picking don't need to worry about the fact that
- // the node has been moved to another position on the screen, they
- // keep working just like they did when it was in the upper right
- // hand corner of the screen.
- //
- // The problem is now that each node defines its own coordinate
- // system it is difficult to compare the positions of two node with
- // each other. These methods are all meant to help solve that problem.
- //
- // The terms used in the methods are as follows:
- //
- // local - The local or base coordinate system of a node.
- // parent - The coordinate system of a node's parent
- // global - The topmost coordinate system, above the root node.
- //
- // Normally when comparing the positions of two nodes you will
- // convert the local position of each node to the global coordinate
- // system, and then compare the positions in that common coordinate
- // system.
- //***************************************************************
-
- /**
- * Transform the given point from this node's local coordinate system to
- * its parent's local coordinate system. Note that this will modify the point
- * parameter.
- *
- * @param localPoint point in local coordinate system to be transformed.
- * @return point in parent's local coordinate system
- */
- public Point2D localToParent(Point2D localPoint) {
- if (transform == null) return localPoint;
- return transform.transform(localPoint, localPoint);
- }
-
- /**
- * Transform the given dimension from this node's local coordinate system to
- * its parent's local coordinate system. Note that this will modify the dimension
- * parameter.
- *
- * @param localDimension dimension in local coordinate system to be transformed.
- * @return dimension in parent's local coordinate system
- */
- public Dimension2D localToParent(Dimension2D localDimension) {
- if (transform == null) return localDimension;
- return transform.transform(localDimension, localDimension);
- }
-
- /**
- * Transform the given rectangle from this node's local coordinate system to
- * its parent's local coordinate system. Note that this will modify the rectangle
- * parameter.
- *
- * @param localRectangle rectangle in local coordinate system to be transformed.
- * @return rectangle in parent's local coordinate system
- */
- public Rectangle2D localToParent(Rectangle2D localRectangle) {
- if (transform == null) return localRectangle;
- return transform.transform(localRectangle, localRectangle);
- }
-
- /**
- * Transform the given point from this node's parent's local coordinate system to
- * the local coordinate system of this node. Note that this will modify the point
- * parameter.
- *
- * @param parentPoint point in parent's coordinate system to be transformed.
- * @return point in this node's local coordinate system
- */
- public Point2D parentToLocal(Point2D parentPoint) {
- if (transform == null) return parentPoint;
- try {
- return transform.inverseTransform(parentPoint, parentPoint);
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Transform the given dimension from this node's parent's local coordinate system to
- * the local coordinate system of this node. Note that this will modify the dimension
- * parameter.
- *
- * @param parentDimension dimension in parent's coordinate system to be transformed.
- * @return dimension in this node's local coordinate system
- */
- public Dimension2D parentToLocal(Dimension2D parentDimension) {
- if (transform == null) return parentDimension;
- return transform.inverseTransform(parentDimension, parentDimension);
- }
-
- /**
- * Transform the given rectangle from this node's parent's local coordinate system to
- * the local coordinate system of this node. Note that this will modify the rectangle
- * parameter.
- *
- * @param parentRectangle rectangle in parent's coordinate system to be transformed.
- * @return rectangle in this node's local coordinate system
- */
- public Rectangle2D parentToLocal(Rectangle2D parentRectangle) {
- if (transform == null) return parentRectangle;
- return transform.inverseTransform(parentRectangle, parentRectangle);
- }
-
- /**
- * Transform the given point from this node's local coordinate system to
- * the global coordinate system. Note that this will modify the point
- * parameter.
- *
- * @param localPoint point in local coordinate system to be transformed.
- * @return point in global coordinates
- */
- public Point2D localToGlobal(Point2D localPoint) {
- PNode n = this;
- while (n != null) {
- localPoint = n.localToParent(localPoint);
- n = n.parent;
- }
- return localPoint;
- }
-
- /**
- * Transform the given dimension from this node's local coordinate system to
- * the global coordinate system. Note that this will modify the dimension
- * parameter.
- *
- * @param localDimension dimension in local coordinate system to be transformed.
- * @return dimension in global coordinates
- */
- public Dimension2D localToGlobal(Dimension2D localDimension) {
- PNode n = this;
- while (n != null) {
- localDimension = n.localToParent(localDimension);
- n = n.parent;
- }
- return localDimension;
- }
-
- /**
- * Transform the given rectangle from this node's local coordinate system to
- * the global coordinate system. Note that this will modify the rectangle
- * parameter.
- *
- * @param localRectangle rectangle in local coordinate system to be transformed.
- * @return rectangle in global coordinates
- */
- public Rectangle2D localToGlobal(Rectangle2D localRectangle) {
- PNode n = this;
- while (n != null) {
- localRectangle = n.localToParent(localRectangle);
- n = n.parent;
- }
- return localRectangle;
- }
-
- /**
- * Transform the given point from global coordinates to this node's
- * local coordinate system. Note that this will modify the point
- * parameter.
- *
- * @param globalPoint point in global coordinates to be transformed.
- * @return point in this node's local coordinate system.
- */
- public Point2D globalToLocal(Point2D globalPoint) {
- if (parent != null) {
- globalPoint = parent.globalToLocal(globalPoint);
- }
- return parentToLocal(globalPoint);
- }
-
- /**
- * Transform the given dimension from global coordinates to this node's
- * local coordinate system. Note that this will modify the dimension
- * parameter.
- *
- * @param globalDimension dimension in global coordinates to be transformed.
- * @return dimension in this node's local coordinate system.
- */
- public Dimension2D globalToLocal(Dimension2D globalDimension) {
- if (parent != null) {
- globalDimension = parent.globalToLocal(globalDimension);
- }
- return parentToLocal(globalDimension);
- }
-
- /**
- * Transform the given rectangle from global coordinates to this node's
- * local coordinate system. Note that this will modify the rectangle
- * parameter.
- *
- * @param globalRectangle rectangle in global coordinates to be transformed.
- * @return rectangle in this node's local coordinate system.
- */
- public Rectangle2D globalToLocal(Rectangle2D globalRectangle) {
- if (parent != null) {
- globalRectangle = parent.globalToLocal(globalRectangle);
- }
- return parentToLocal(globalRectangle);
- }
-
- /**
- * Return the transform that converts local coordinates at this node
- * to the global coordinate system.
- *
- * @return The concatenation of transforms from the top node down to this node.
- */
- public PAffineTransform getLocalToGlobalTransform(PAffineTransform dest) {
- if (parent != null) {
- dest = parent.getLocalToGlobalTransform(dest);
- if (transform != null) dest.concatenate(transform);
- } else {
- if (dest == null) {
- dest = getTransform();
- } else {
- if (transform != null) {
- dest.setTransform(transform);
- } else {
- dest.setToIdentity();
- }
- }
- }
- return dest;
- }
-
- /**
- * Return the transform that converts global coordinates
- * to local coordinates of this node.
- *
- * @return The inverse of the concatenation of transforms from the root down to this node.
- */
- public PAffineTransform getGlobalToLocalTransform(PAffineTransform dest) {
- try {
- dest = getLocalToGlobalTransform(dest);
- dest.setTransform(dest.createInverse());
- return dest;
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- //****************************************************************
- // Event Listeners - Methods for adding and removing event listeners
- // from a node.
- //
- // Here methods are provided to add property change listeners and
- // input event listeners. The property change listeners are notified
- // when certain properties of this node change, and the input event
- // listeners are notified when the nodes receives new key and mouse
- // events.
- //****************************************************************
-
- /**
- * Return the list of event listeners associated with this node.
- *
- * @return event listener list or null
- */
- public EventListenerList getListenerList() {
- return listenerList;
- }
-
- /**
- * Adds the specified input event listener to receive input events
- * from this node.
- *
- * @param listener the new input listener
- */
- public void addInputEventListener(PInputEventListener listener) {
- if (listenerList == null) listenerList = new EventListenerList();
- getListenerList().add(PInputEventListener.class, listener);
- }
-
- /**
- * Removes the specified input event listener so that it no longer
- * receives input events from this node.
- *
- * @param listener the input listener to remove
- */
- public void removeInputEventListener(PInputEventListener listener) {
- if (listenerList == null) return;
- getListenerList().remove(PInputEventListener.class, listener);
- if (listenerList.getListenerCount() == 0) {
- listenerList = null;
- }
- }
-
- /**
- * Add a PropertyChangeListener to the listener list.
- * The listener is registered for all properties.
- * See the fields in PNode and subclasses that start
- * with PROPERTY_ to find out which properties exist.
- * @param listener The PropertyChangeListener to be added
- */
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- if (changeSupport == null) {
- changeSupport = new SwingPropertyChangeSupport(this);
- }
- changeSupport.addPropertyChangeListener(listener);
- }
-
- /**
- * Add a PropertyChangeListener for a specific property. The listener
- * will be invoked only when a call on firePropertyChange names that
- * specific property. See the fields in PNode and subclasses that start
- * with PROPERTY_ to find out which properties are supported.
- * @param propertyName The name of the property to listen on.
- * @param listener The PropertyChangeListener to be added
- */
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- if (listener == null) {
- return;
- }
- if (changeSupport == null) {
- changeSupport = new SwingPropertyChangeSupport(this);
- }
- changeSupport.addPropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Remove a PropertyChangeListener from the listener list.
- * This removes a PropertyChangeListener that was registered
- * for all properties.
- *
- * @param listener The PropertyChangeListener to be removed
- */
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- if (changeSupport != null) {
- changeSupport.removePropertyChangeListener(listener);
- }
- }
-
- /**
- * Remove a PropertyChangeListener for a specific property.
- *
- * @param propertyName The name of the property that was listened on.
- * @param listener The PropertyChangeListener to be removed
- */
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- if (listener == null) {
- return;
- }
- if (changeSupport == null) {
- return;
- }
- changeSupport.removePropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Return the propertyChangeParentMask that determines which property
- * change events are forwared to this nodes parent so that its property
- * change listeners will also be notified.
- */
- public int getPropertyChangeParentMask() {
- return propertyChangeParentMask;
- }
-
- /**
- * Set the propertyChangeParentMask that determines which property
- * change events are forwared to this nodes parent so that its property
- * change listeners will also be notified.
- */
- public void setPropertyChangeParentMask(int propertyChangeParentMask) {
- this.propertyChangeParentMask = propertyChangeParentMask;
- }
-
- /**
- * Report a bound property update to any registered listeners.
- * No event is fired if old and new are equal and non-null. If the propertyCode
- * exists in this node's propertyChangeParentMask then a property change event
- * will also be fired on this nodes parent.
- *
- * @param propertyCode The code of the property changed.
- * @param propertyName The programmatic name of the property that was changed.
- * @param oldValue The old value of the property.
- * @param newValue The new value of the property.
- */
- protected void firePropertyChange(int propertyCode, String propertyName, Object oldValue, Object newValue) {
- PropertyChangeEvent event = null;
-
- if (changeSupport != null) {
- event = new PropertyChangeEvent(this, propertyName, oldValue, newValue);
- changeSupport.firePropertyChange(event);
- }
- if (parent != null && (propertyCode & propertyChangeParentMask) != 0) {
- if (event == null) event = new PropertyChangeEvent(this, propertyName, oldValue, newValue);
- parent.fireChildPropertyChange(event, propertyCode);
- }
- }
-
- /**
- * Called by child node to forward property change events up the node tree
- * so that property change listeners registered with this node will be notified
- * of property changes of its children nodes. For performance reason only propertyCodes
- * listed in the propertyChangeParentMask are forwarded.
- *
- * @param event The property change event containing source node and changed values.
- * @param propertyCode The code of the property changed.
- */
- protected void fireChildPropertyChange(PropertyChangeEvent event, int propertyCode) {
- if (changeSupport != null) {
- changeSupport.firePropertyChange(event);
- }
- if (parent != null && (propertyCode & propertyChangeParentMask) != 0) {
- parent.fireChildPropertyChange(event, propertyCode);
- }
- }
-
- //****************************************************************
- // Bounds Geometry - Methods for setting and querying the bounds
- // of this node.
- //
- // The bounds of a node store the node's position and size in
- // the nodes local coordinate system. Many node subclasses will need
- // to override the setBounds method so that they can update their
- // internal state appropriately. See PPath for an example.
- //
- // Since the bounds are stored in the local coordinate system
- // they WILL NOT change if the node is scaled, translated, or rotated.
- //
- // The bounds may be accessed with either getBounds, or
- // getBoundsReference. The former returns a copy of the bounds
- // the latter returns a reference to the nodes bounds that should
- // normally not be modified. If a node is marked as volatile then
- // it may modify its bounds before returning them from getBoundsReference,
- // otherwise it may not.
- //****************************************************************
-
- /**
- * Return a copy of this node's bounds. These bounds are stored in
- * the local coordinate system of this node and do not include the
- * bounds of any of this node's children.
- */
- public PBounds getBounds() {
- return (PBounds) getBoundsReference().clone();
- }
-
- /**
- * Return a direct reference to this node's bounds. These bounds
- * are stored in the local coordinate system of this node and do
- * not include the bounds of any of this node's children. The value
- * returned should not be modified.
- */
- public PBounds getBoundsReference() {
- return bounds;
- }
-
- /**
- * Notify this node that you will beging to repeadily call setBounds
.
- * When you are done call endResizeBounds
to let the node know that
- * you are done.
- */
- public void startResizeBounds() {
- }
-
- /**
- * Notify this node that you have finished a resize bounds sequence.
- */
- public void endResizeBounds() {
- }
-
- public boolean setX(double x) {
- return setBounds(x, getY(), getWidth(), getHeight());
- }
-
- public boolean setY(double y) {
- return setBounds(getX(), y, getWidth(), getHeight());
- }
-
- public boolean setWidth(double width) {
- return setBounds(getX(), getY(), width, getHeight());
- }
-
- public boolean setHeight(double height) {
- return setBounds(getX(), getY(), getWidth(), height);
- }
-
- /**
- * Set the bounds of this node to the given value. These bounds
- * are stored in the local coordinate system of this node.
- *
- * @return true if the bounds changed.
- */
- public boolean setBounds(Rectangle2D newBounds) {
- return setBounds(newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight());
- }
-
- /**
- * Set the bounds of this node to the given value. These bounds
- * are stored in the local coordinate system of this node.
- *
- * If the width or height is less then or equal to zero then the bound's
- * emtpy bit will be set to true.
- *
- * Subclasses must call the super.setBounds() method.
- *
- * @return true if the bounds changed.
- */
- public boolean setBounds(double x, double y, double width, double height) {
- if (bounds.x != x || bounds.y != y || bounds.width != width || bounds.height != height) {
- bounds.setRect(x, y, width, height);
-
- if (width <= 0 || height <= 0) {
- bounds.reset();
- }
-
- internalUpdateBounds(x, y, width, height);
- invalidatePaint();
- signalBoundsChanged();
- return true;
- }
- // Don't put any invalidating code here or else nodes with volatile bounds will
- // create a soft infinite loop (calling Swing.invokeLater()) when they validate
- // their bounds.
- return false;
- }
-
- /**
- * Gives nodes a chance to update their internal structure
- * before bounds changed notifications are sent. When this message
- * is recived the nodes bounds field will contain the new value.
- *
- * See PPath for an example that uses this method.
- */
- protected void internalUpdateBounds(double x, double y, double width, double height) {
- }
-
- /**
- * Set the empty bit of this bounds to true.
- */
- public void resetBounds() {
- setBounds(0, 0, 0, 0);
- }
-
- /**
- * Return the x position (in local coords) of this node's bounds.
- */
- public double getX() {
- return getBoundsReference().getX();
- }
-
- /**
- * Return the y position (in local coords) of this node's bounds.
- */
- public double getY() {
- return getBoundsReference().getY();
- }
-
- /**
- * Return the width (in local coords) of this node's bounds.
- */
- public double getWidth() {
- return getBoundsReference().getWidth();
- }
-
- /**
- * Return the height (in local coords) of this node's bounds.
- */
- public double getHeight() {
- return getBoundsReference().getHeight();
- }
-
- /**
- * Return a copy of the bounds of this node in the global
- * coordinate system.
- *
- * @return the bounds in global coordinate system.
- */
- public PBounds getGlobalBounds() {
- return (PBounds) localToGlobal(getBounds());
- }
-
- /**
- * Center the bounds of this node so that they are centered on the given
- * point specified on the local coords of this node. Note that this meathod
- * will modify the nodes bounds, while centerFullBoundsOnPoint will modify
- * the nodes transform.
- *
- * @return true if the bounds changed.
- */
- public boolean centerBoundsOnPoint(double localX, double localY) {
- double dx = localX - bounds.getCenterX();
- double dy = localY - bounds.getCenterY();
- return setBounds(bounds.x + dx, bounds.y + dy, bounds.width, bounds.height);
- }
-
- /**
- * Center the ffull bounds of this node so that they are centered on the
- * given point specified on the local coords of this nodes parent. Note that
- * this meathod will modify the nodes transform, while centerBoundsOnPoint
- * will modify the nodes bounds.
- */
- public void centerFullBoundsOnPoint(double parentX, double parentY) {
- double dx = parentX - getFullBoundsReference().getCenterX();
- double dy = parentY - getFullBoundsReference().getCenterY();
- offset(dx, dy);
- }
-
- /**
- * Return true if this node intersects the given rectangle specified in
- * local bounds. If the geometry of this node is complex this method can become
- * expensive, it is therefore recommended that fullIntersects
is used
- * for quick rejects before calling this method.
- *
- * @param localBounds the bounds to test for intersection against
- * @return true if the given rectangle intersects this nodes geometry.
- */
- public boolean intersects(Rectangle2D localBounds) {
- if (localBounds == null) return true;
- return getBoundsReference().intersects(localBounds);
- }
-
- //****************************************************************
- // Full Bounds - Methods for computing and querying the
- // full bounds of this node.
- //
- // The full bounds of a node store the nodes bounds
- // together with the union of the bounds of all the
- // node's descendents. The full bounds are stored in the parent
- // coordinate system of this node, the full bounds DOES change
- // when you translate, scale, or rotate this node.
- //
- // The full bounds may be accessed with either getFullBounds, or
- // getFullBoundsReference. The former returns a copy of the full bounds
- // the latter returns a reference to the node's full bounds that should
- // not be modified.
- //****************************************************************
-
- /**
- * Return a copy of this node's full bounds. These bounds are stored in
- * the parent coordinate system of this node and they include the
- * union of this node's bounds and all the bounds of it's descendents.
- *
- * @return a copy of this node's full bounds.
- */
- public PBounds getFullBounds() {
- return (PBounds) getFullBoundsReference().clone();
- }
-
- /**
- * Return a reference to this node's full bounds cache. These bounds are
- * stored in the parent coordinate system of this node and they include the
- * union of this node's bounds and all the bounds of it's descendents. The bounds
- * returned by this method should not be modified.
- *
- * @return a reference to this node's full bounds cache.
- */
- public PBounds getFullBoundsReference() {
- validateFullBounds();
- return fullBoundsCache;
- }
-
- /**
- * Compute and return the full bounds of this node. If the dstBounds
- * parameter is not null then it will be used to return the results instead
- * of creating a new PBounds.
- *
- * @param dstBounds if not null the new bounds will be stored here
- * @return the full bounds in the parent coordinate system of this node
- */
- public PBounds computeFullBounds(PBounds dstBounds) {
- PBounds result = getUnionOfChildrenBounds(dstBounds);
- result.add(getBoundsReference());
- localToParent(result);
- return result;
- }
-
- /**
- * Compute and return the union of the full bounds of all the
- * children of this node. If the dstBounds parameter is not null
- * then it will be used to return the results instead of creating
- * a new PBounds.
- *
- * @param dstBounds if not null the new bounds will be stored here
- */
- public PBounds getUnionOfChildrenBounds(PBounds dstBounds) {
- if (dstBounds == null) {
- dstBounds = new PBounds();
- } else {
- dstBounds.resetToZero();
- }
-
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- if (i < children.size()){
- PNode each = children.get(i);
- dstBounds.add(each.getFullBoundsReference());
- }
- }
-
- return dstBounds;
- }
-
- /**
- * Return a copy of the full bounds of this node in the global
- * coordinate system.
- *
- * @return the full bounds in global coordinate system.
- */
- public PBounds getGlobalFullBounds() {
- PBounds b = getFullBounds();
- if (parent != null) {
- parent.localToGlobal(b);
- }
- return b;
- }
-
- /**
- * Return true if the full bounds of this node intersects with the
- * specified bounds.
- *
- * @param parentBounds the bounds to test for intersection against (specified in parent's coordinate system)
- * @return true if this nodes full bounds intersect the given bounds.
- */
- public boolean fullIntersects(Rectangle2D parentBounds) {
- if (parentBounds == null) return true;
- return getFullBoundsReference().intersects(parentBounds);
- }
-
- //****************************************************************
- // Bounds Damage Management - Methods used to invalidate and validate
- // the bounds of nodes.
- //****************************************************************
-
- /**
- * Return true if this nodes bounds may change at any time. The default
- * behavior is to return false, subclasses that override this method to
- * return true should also override getBoundsReference() and compute their
- * volatile bounds there before returning the reference.
- *
- * @return true if this node has volatile bounds
- */
- protected boolean getBoundsVolatile() {
- return false;
- }
-
- /**
- * Return true if this node has a child with volatile bounds.
- *
- * @return true if this node has a child with volatile bounds
- */
- protected boolean getChildBoundsVolatile() {
- return childBoundsVolatile;
- }
-
- /**
- * Set if this node has a child with volatile bounds. This should normally
- * be managed automatically by the bounds validation process.
- *
- * @param childBoundsVolatile true if this node has a descendent with volatile bounds
- */
- protected void setChildBoundsVolatile(boolean childBoundsVolatile) {
- this.childBoundsVolatile = childBoundsVolatile;
- }
-
- /**
- * Return true if this node's bounds have recently changed. This flag
- * will be reset on the next call of validateFullBounds.
- *
- * @return true if this node's bounds have changed.
- */
- protected boolean getBoundsChanged() {
- return boundsChanged;
- }
-
- /**
- * Set the bounds chnaged flag. This flag
- * will be reset on the next call of validateFullBounds.
- *
- * @param boundsChanged true if this nodes bounds have changed.
- */
- protected void setBoundsChanged(boolean boundsChanged) {
- this.boundsChanged = boundsChanged;
- }
-
- /**
- * Return true if the full bounds of this node are invalid. This means that
- * the full bounds of this node have changed and need to be recomputed.
- *
- * @return true if the full bounds of this node are invalid
- */
- protected boolean getFullBoundsInvalid() {
- return fullBoundsInvalid;
- }
-
- /**
- * Set the full bounds invalid flag. This flag is set when the full bounds of
- * this node need to be recomputed as is the case when this node is transformed
- * or when one of this node's children changes geometry.
- */
- protected void setFullBoundsInvalid(boolean fullBoundsInvalid) {
- this.fullBoundsInvalid = fullBoundsInvalid;
- }
-
- /**
- * Return true if one of this node's descendents has invalid bounds.
- */
- protected boolean getChildBoundsInvalid() {
- return childBoundsInvalid;
- }
-
- /**
- * Set the flag indicating that one of this node's descendents has
- * invalid bounds.
- */
- protected void setChildBoundsInvalid(boolean childBoundsInvalid) {
- this.childBoundsInvalid = childBoundsInvalid;
- }
-
- /**
- * This method should be called when the bounds of this node are changed.
- * It invalidates the full bounds of this node, and also notifies each of
- * this nodes children that their parent's bounds have changed. As a result
- * of this method getting called this nodes layoutChildren will be called.
- */
- public void signalBoundsChanged() {
- invalidateFullBounds();
- setBoundsChanged(true);
- firePropertyChange(PROPERTY_CODE_BOUNDS, PROPERTY_BOUNDS, null, bounds);
-
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- PNode each = children.get(i);
- each.parentBoundsChanged();
- }
- }
-
- /**
- * Invalidate this node's layout, so that later
- * layoutChildren will get called.
- */
- public void invalidateLayout() {
- invalidateFullBounds();
- }
-
- /**
- * A notification that the bounds of this node's parent have changed.
- */
- protected void parentBoundsChanged() {
- }
-
- /**
- * Invalidates the full bounds of this node, and sets the child bounds invalid flag
- * on each of this node's ancestors.
- */
- public void invalidateFullBounds() {
- setFullBoundsInvalid(true);
-
- PNode n = parent;
- while (n != null && !n.getChildBoundsInvalid()) {
- n.setChildBoundsInvalid(true);
- n = n.parent;
- }
-
- if (SCENE_GRAPH_DELEGATE != null) SCENE_GRAPH_DELEGATE.nodeFullBoundsInvalidated(this);
- }
-
- /**
- * This method is called to validate the bounds of this node and all of its
- * descendents. It returns true if this nodes bounds or the bounds of any of its
- * descendents are marked as volatile.
- *
- * @return true if this node or any of its descendents have volatile bounds
- */
- public boolean validateFullBounds() {
- boolean boundsVolatile = getBoundsVolatile();
-
- // 1. Only compute new bounds if invalid flags are set.
- if (fullBoundsInvalid || childBoundsInvalid || boundsVolatile || childBoundsVolatile) {
-
- // 2. If my bounds are volatile and they have not been changed then signal a change.
- // For most cases this will
- // do nothing, but if a nodes bounds depend on its model, then validate bounds has the
- // responsibility of making the bounds match the models value. For example PPaths
- // validateBounds method makes sure that the bounds are equal to the bounds of the GeneralPath
- // model.
- if (boundsVolatile && !boundsChanged) {
- signalBoundsChanged();
- }
-
- // 3. If the bounds of on of my decendents are invalidate then validate the bounds of all
- // of my children.
- if (childBoundsInvalid || childBoundsVolatile) {
- childBoundsVolatile = false;
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- if (i < children.size()) {
- PNode each = children.get(i);
- childBoundsVolatile |= each.validateFullBounds();
- }
- }
- }
-
- // 4. Now that my children's bounds are valid and my own bounds are valid run any
- // layout algorithm here. Note that if you try to layout volatile children piccolo
- // will most likely start a "soft" infinite loop. It won't freeze your program, but
- // it will make an infinite number of calls to SwingUtilities invoke later. You don't
- // want to do that.
- layoutChildren();
-
- // 5. If the full bounds cache is invalid then recompute the full bounds cache
- // here after our own bounds and the children's bounds have been computed above.
- if (fullBoundsInvalid) {
- double oldX = fullBoundsCache.x;
- double oldY = fullBoundsCache.y;
- double oldWidth = fullBoundsCache.width;
- double oldHeight = fullBoundsCache.height;
- boolean oldEmpty = fullBoundsCache.isEmpty();
-
- // 6. This will call getFullBoundsReference on all of the children. So if the above
- // layoutChildren method changed the bounds of any of the children they will be
- // validated again here.
- fullBoundsCache = computeFullBounds(fullBoundsCache);
-
- boolean fullBoundsChanged = fullBoundsCache.x != oldX ||
- fullBoundsCache.y != oldY ||
- fullBoundsCache.width != oldWidth ||
- fullBoundsCache.height != oldHeight ||
- fullBoundsCache.isEmpty() != oldEmpty;
-
- // 7. If the new full bounds cache differs from the previous cache then
- // tell our parent to invalidate their full bounds. This is how bounds changes
- // deep in the tree percolate up.
- if (fullBoundsChanged) {
- if (parent != null) parent.invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_FULL_BOUNDS, PROPERTY_FULL_BOUNDS, null, fullBoundsCache);
-
- // 8. If our paint was invalid make sure to repaint our old full bounds. The
- // new bounds will be computed later in the validatePaint pass.
- if (paintInvalid && !oldEmpty) {
- TEMP_REPAINT_BOUNDS.setRect(oldX, oldY, oldWidth, oldHeight);
- repaintFrom(TEMP_REPAINT_BOUNDS, this);
- }
- }
- }
-
- // 9. Clear the invalid bounds flags.
- boundsChanged = false;
- fullBoundsInvalid = false;
- childBoundsInvalid = false;
- }
-
- return boundsVolatile || childBoundsVolatile;
- }
-
- /**
- * Nodes that apply layout constraints to their children should override
- * this method and do the layout there.
- */
- protected void layoutChildren() {
- }
-
- //****************************************************************
- // Node Transform - Methods to manipulate the node's transform.
- //
- // Each node has a transform that is used to define the nodes
- // local coordinate system. IE it is applied before picking and
- // rendering the node.
- //
- // The usual way to move nodes about on the canvas is to manipulate
- // this transform, as opposed to changing the bounds of the
- // node.
- //
- // Since this transform defines the local coordinate system of this
- // node the following methods with affect the global position both
- // this node and all of its descendents.
- //****************************************************************
-
- /**
- * Returns the rotation applied by this node's transform in radians.
- * This rotation affects this node and all its descendents. The value
- * returned will be between 0 and 2pi radians.
- *
- * @return rotation in radians.
- */
- public double getRotation() {
- if (transform == null) return 0;
- return transform.getRotation();
- }
-
- /**
- * Sets the rotation of this nodes transform in radians. This will
- * affect this node and all its descendents.
- *
- * @param theta rotation in radians
- */
- public void setRotation(double theta) {
- rotate(theta - getRotation());
- }
-
- /**
- * Rotates this node by theta (in radians) about the 0,0 point.
- * This will affect this node and all its descendents.
- *
- * @param theta the amount to rotate by in radians
- */
- public void rotate(double theta) {
- rotateAboutPoint(theta, 0, 0);
- }
-
- /**
- * Rotates this node by theta (in radians), and then translates the node so
- * that the x, y position of its fullBounds stays constant.
- *
- * @param theta the amount to rotate by in radians
- */
- public void rotateInPlace(double theta) {
- PBounds b = getFullBoundsReference();
- double px = b.x;
- double py = b.y;
- rotateAboutPoint(theta, 0, 0);
- b = getFullBoundsReference();
- offset(px - b.x, py - b.y);
- }
-
- /**
- * Rotates this node by theta (in radians) about the given
- * point. This will affect this node and all its descendents.
- *
- * @param theta the amount to rotate by in radians
- */
- public void rotateAboutPoint(double theta, Point2D point) {
- rotateAboutPoint(theta, point.getX(), point.getY());
- }
-
- /**
- * Rotates this node by theta (in radians) about the given
- * point. This will affect this node and all its descendents.
- *
- * @param theta the amount to rotate by in radians
- */
- public void rotateAboutPoint(double theta, double x, double y) {
- getTransformReference(true).rotate(theta, x, y);
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- /**
- * Return the total amount of rotation applied to this node by its own
- * transform together with the transforms of all its ancestors. The value
- * returned will be between 0 and 2pi radians.
- *
- * @return the total amount of rotation applied to this node in radians
- */
- public double getGlobalRotation() {
- return getLocalToGlobalTransform(null).getRotation();
- }
-
- /**
- * Set the global rotation (in radians) of this node. This is implemented by
- * rotating this nodes transform the required amount so that the nodes
- * global rotation is as requested.
- *
- * @param theta the amount to rotate by in radians relative to the global coord system.
- */
- public void setGlobalRotation(double theta) {
- if (parent != null) {
- setRotation(theta - parent.getGlobalRotation());
- } else {
- setRotation(theta);
- }
- }
-
- /**
- * Return the scale applied by this node's transform. The scale is
- * effecting this node and all its descendents.
- *
- * @return scale applied by this nodes transform.
- */
- public double getScale() {
- if (transform == null) return 1;
- return transform.getScale();
- }
-
- /**
- * Set the scale of this node's transform. The scale will
- * affect this node and all its descendents.
- *
- * @param scale the scale to set the transform to
- */
- public void setScale(double scale) {
- if (scale == 0) throw new RuntimeException("Can't set scale to 0");
- scale(scale / getScale());
- }
-
- /**
- * Scale this nodes transform by the given amount. This will affect this
- * node and all of its descendents.
- *
- * @param scale the amount to scale by
- */
- public void scale(double scale) {
- scaleAboutPoint(scale, 0, 0);
- }
-
- /**
- * Scale this nodes transform by the given amount about the specified
- * point. This will affect this node and all of its descendents.
- *
- * @param scale the amount to scale by
- * @param point the point to scale about
- */
- public void scaleAboutPoint(double scale, Point2D point) {
- scaleAboutPoint(scale, point.getX(), point.getY());
- }
-
- /**
- * Scale this nodes transform by the given amount about the specified
- * point. This will affect this node and all of its descendents.
- *
- * @param scale the amount to scale by
- */
- public void scaleAboutPoint(double scale, double x, double y) {
- getTransformReference(true).scaleAboutPoint(scale, x, y);
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- /**
- * Return the global scale that is being applied to this node by its transform
- * together with the transforms of all its ancestors.
- */
- public double getGlobalScale() {
- return getLocalToGlobalTransform(null).getScale();
- }
-
- /**
- * Set the global scale of this node. This is implemented by scaling
- * this nodes transform the required amount so that the nodes global scale
- * is as requested.
- *
- * @param scale the desired global scale
- */
- public void setGlobalScale(double scale) {
- if (parent != null) {
- setScale(scale / parent.getGlobalScale());
- } else {
- setScale(scale);
- }
- }
-
- public double getXOffset() {
- if (transform == null) return 0;
- return transform.getTranslateX();
- }
-
- public double getYOffset() {
- if (transform == null) return 0;
- return transform.getTranslateY();
- }
-
- /**
- * Return the offset that is being applied to this node by its
- * transform. This offset effects this node and all of its descendents
- * and is specified in the parent coordinate system. This returns the
- * values that are in the m02 and m12 positions in the affine transform.
- *
- * @return a point representing the x and y offset
- */
- public Point2D getOffset() {
- if (transform == null) return new Point2D.Double();
- return new Point2D.Double(transform.getTranslateX(), transform.getTranslateY());
- }
-
- /**
- * Set the offset that is being applied to this node by its
- * transform. This offset effects this node and all of its descendents and
- * is specified in the nodes parent coordinate system. This directly sets the values
- * of the m02 and m12 positions in the affine transform. Unlike "PNode.translate()" it
- * is not effected by the transforms scale.
- *
- * @param point a point representing the x and y offset
- */
- public void setOffset(Point2D point) {
- setOffset(point.getX(), point.getY());
- }
-
- /**
- * Set the offset that is being applied to this node by its
- * transform. This offset effects this node and all of its descendents and
- * is specified in the nodes parent coordinate system. This directly sets the values
- * of the m02 and m12 positions in the affine transform. Unlike "PNode.translate()" it
- * is not effected by the transforms scale.
- *
- * @param x amount of x offset
- * @param y amount of y offset
- */
- public void setOffset(double x, double y) {
- getTransformReference(true).setOffset(x, y);
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- /**
- * Offset this node relative to the parents coordinate system, and is NOT
- * effected by this nodes current scale or rotation. This is implemented
- * by directly adding dx to the m02 position and dy to the m12 position in the
- * affine transform.
- */
- public void offset(double dx, double dy) {
- getTransformReference(true);
- setOffset(transform.getTranslateX() + dx,
- transform.getTranslateY() + dy);
- }
-
- /**
- * Translate this node's transform by the given amount, using the standard affine
- * transform translate method. This translation effects this node and all of its
- * descendents.
- */
- public void translate(double dx, double dy) {
- getTransformReference(true).translate(dx, dy);
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- /**
- * Return the global translation that is being applied to this node by its transform
- * together with the transforms of all its ancestors.
- */
- public Point2D getGlobalTranslation() {
- Point2D p = getOffset();
- if (parent != null) {
- parent.localToGlobal(p);
- }
- return p;
- }
-
- /**
- * Set the global translation of this node. This is implemented by translating
- * this nodes transform the required amount so that the nodes global scale
- * is as requested.
- *
- * @param globalPoint the desired global translation
- */
- public void setGlobalTranslation(Point2D globalPoint) {
- if (parent != null) {
- parent.getGlobalToLocalTransform(null).transform(globalPoint, globalPoint);
- }
- setOffset(globalPoint);
- }
-
- /**
- * Transform this nodes transform by the given transform.
- *
- * @param aTransform the transform to apply.
- */
- public void transformBy(AffineTransform aTransform) {
- getTransformReference(true).concatenate(aTransform);
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- /**
- * Linearly interpolates between a and b, based on t.
- * Specifically, it computes lerp(a, b, t) = a + t*(b - a).
- * This produces a result that changes from a (when t = 0) to b (when t = 1).
- *
- * @param a from point
- * @param b to Point
- * @param t variable 'time' parameter
- */
- static public double lerp(double t, double a, double b) {
- return (a + t * (b - a));
- }
-
- /**
- * This will calculate the necessary transform in order to make this
- * node appear at a particular position relative to the
- * specified bounding box. The source point specifies a point in the
- * unit square (0, 0) - (1, 1) that represents an anchor point on the
- * corresponding node to this transform. The destination point specifies
- * an anchor point on the reference node. The position method then
- * computes the transform that results in transforming this node so that
- * the source anchor point coincides with the reference anchor
- * point. This can be useful for layout algorithms as it is
- * straightforward to position one object relative to another.
- *
- * For example, If you have two nodes, A and B, and you call
- *
- * Point2D srcPt = new Point2D.Double(1.0, 0.0);
- * Point2D destPt = new Point2D.Double(0.0, 0.0);
- * A.position(srcPt, destPt, B.getGlobalBounds(), 750, null);
- *
- * The result is that A will move so that its upper-right corner is at
- * the same place as the upper-left corner of B, and the transition will
- * be smoothly animated over a period of 750 milliseconds.
- * @param srcPt The anchor point on this transform's node (normalized to a unit square)
- * @param destPt The anchor point on destination bounds (normalized to a unit square)
- * @param destBounds The bounds (in global coordinates) used to calculate this transform's node
- * @param millis Number of milliseconds over which to perform the animation
- */
- public void position(Point2D srcPt, Point2D destPt, Rectangle2D destBounds, int millis) {
- double srcx, srcy;
- double destx, desty;
- double dx, dy;
- Point2D pt1, pt2;
-
- if (parent != null) {
- // First compute translation amount in global coordinates
- Rectangle2D srcBounds = getGlobalFullBounds();
- srcx = lerp(srcPt.getX(), srcBounds.getX(), srcBounds.getX() + srcBounds.getWidth());
- srcy = lerp(srcPt.getY(), srcBounds.getY(), srcBounds.getY() + srcBounds.getHeight());
- destx = lerp(destPt.getX(), destBounds.getX(), destBounds.getX() + destBounds.getWidth());
- desty = lerp(destPt.getY(), destBounds.getY(), destBounds.getY() + destBounds.getHeight());
-
- // Convert vector to local coordinates
- pt1 = new Point2D.Double(srcx, srcy);
- globalToLocal(pt1);
- pt2 = new Point2D.Double(destx, desty);
- globalToLocal(pt2);
- dx = (pt2.getX() - pt1.getX());
- dy = (pt2.getY() - pt1.getY());
-
- // Finally, animate change
- PAffineTransform at = new PAffineTransform(getTransformReference(true));
- at.translate(dx, dy);
- animateToTransform(at, millis);
- }
- }
-
-
- /**
- * Return a copy of the transform associated with this node.
- *
- * @return copy of this node's transform
- */
- public PAffineTransform getTransform() {
- if (transform == null) {
- return new PAffineTransform();
- } else {
- return (PAffineTransform) transform.clone();
- }
- }
-
- /**
- * Return a reference to the transform associated with this node.
- * This returned transform should not be modified. PNode transforms are
- * created lazily when needed. If you access the transform reference
- * before the transform has been created it may return null. The
- * createNewTransformIfNull parameter is used to specify that the PNode
- * should create a new transform (and assign that transform to the nodes
- * local transform variable) instead of returning null.
- *
- * @return reference to this node's transform
- */
- public PAffineTransform getTransformReference(boolean createNewTransformIfNull) {
- if (transform == null && createNewTransformIfNull) {
- transform = new PAffineTransform();
- }
- return transform;
- }
-
- /**
- * Return an inverted copy of the transform associated with this node.
- *
- * @return inverted copy of this node's transform
- */
- public PAffineTransform getInverseTransform() {
- if (transform == null) {
- return new PAffineTransform();
- } else {
- try {
- return new PAffineTransform(transform.createInverse());
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
-
- /**
- * Set the transform applied to this node.
- *
- * @param newTransform the new transform value
- */
- public void setTransform(AffineTransform newTransform) {
- if (newTransform == null) {
- transform = null;
- } else {
- getTransformReference(true).setTransform(newTransform);
- }
-
- invalidatePaint();
- invalidateFullBounds();
- firePropertyChange(PROPERTY_CODE_TRANSFORM, PROPERTY_TRANSFORM, null, transform);
- }
-
- //****************************************************************
- // Paint Damage Management - Methods used to invalidate the areas of
- // the screen that this node appears in so that they will later get
- // painted.
- //
- // Generally you will not need to call these invalidate methods
- // when starting out with Piccolo because methods such as setPaint
- // already automatically call them for you. You will need to call
- // them when you start creating your own nodes.
- //
- // When you do create you own nodes the only method that you will
- // normally need to call is invalidatePaint. This method marks the
- // nodes as having invalid paint, the root node's UI cycle will then
- // later discover this damage and report it to the Java repaint manager.
- //
- // Repainting is normally done with PNode.invalidatePaint() instead of
- // directly calling PNode.repaint() because PNode.repaint() requires
- // the nodes bounds to be computed right away. But with invalidatePaint
- // the bounds computation can be delayed until the end of the root's UI
- // cycle, and this can add up to a bit savings when modifying a
- // large number of nodes all at once.
- //
- // The other methods here will rarely be called except internally
- // from the framework.
- //****************************************************************
-
- /**
- * Return true if this nodes paint is invalid, in which case the node
- * needs to be repainted.
- *
- * @return true if this node needs to be repainted
- */
- public boolean getPaintInvalid() {
- return paintInvalid;
- }
-
- /**
- * Mark this node as having invalid paint. If this is set the node
- * will later be repainted. Node this method is most often
- * used internally.
- *
- * @param paintInvalid true if this node should be repainted
- */
- public void setPaintInvalid(boolean paintInvalid) {
- this.paintInvalid = paintInvalid;
- }
-
- /**
- * Return true if this node has a child with invalid paint.
- *
- * @return true if this node has a child with invalid paint
- */
- public boolean getChildPaintInvalid() {
- return childPaintInvalid;
- }
-
- /**
- * Mark this node as having a child with invalid paint.
- *
- * @param childPaintInvalid true if this node has a child with invalid paint
- */
- public void setChildPaintInvalid(boolean childPaintInvalid) {
- this.childPaintInvalid = childPaintInvalid;
- }
-
- /**
- * Invalidate this node's paint, and mark all of its ancestors as having a node
- * with invalid paint.
- */
- public void invalidatePaint() {
- setPaintInvalid(true);
-
- PNode n = parent;
- while (n != null && !n.getChildPaintInvalid()) {
- n.setChildPaintInvalid(true);
- n = n.parent;
- }
-
- if (SCENE_GRAPH_DELEGATE != null) SCENE_GRAPH_DELEGATE.nodePaintInvalidated(this);
- }
-
- /**
- * Repaint this node and any of its descendents if they have invalid paint.
- */
- public void validateFullPaint() {
- if (getPaintInvalid()) {
- repaint();
- setPaintInvalid(false);
- }
-
- if (getChildPaintInvalid()) {
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- PNode each = children.get(i);
- each.validateFullPaint();
- }
- setChildPaintInvalid(false);
- }
- }
-
- /**
- * Mark the area on the screen represented by this nodes full bounds
- * as needing a repaint.
- */
- public void repaint() {
- TEMP_REPAINT_BOUNDS.setRect(getFullBoundsReference());
- repaintFrom(TEMP_REPAINT_BOUNDS, this);
- }
-
- /**
- * Pass the given repaint request up the tree, so that any cameras
- * can invalidate that region on their associated canvas.
- *
- * @param localBounds the bounds to repaint
- * @param childOrThis if childOrThis does not equal this then this nodes transform will be applied to the localBounds param
- */
- public void repaintFrom(PBounds localBounds, PNode childOrThis) {
- if (parent != null) {
- if (childOrThis != this) {
- localToParent(localBounds);
- } else if (!getVisible()) {
- return;
- }
- parent.repaintFrom(localBounds, this);
- }
- }
-
- //****************************************************************
- // Occluding - Methods to suppor occluding optimization. Not yet
- // complete.
- //****************************************************************
-
- public boolean isOpaque(Rectangle2D boundary) {
- return false;
- }
-
- public boolean getOccluded() {
- return occluded;
- }
-
- public void setOccluded(boolean isOccluded) {
- occluded = isOccluded;
- }
-
- //****************************************************************
- // Painting - Methods for painting this node and its children
- //
- // Painting is how a node defines its visual representation on the
- // screen, and is done in the local coordinate system of the node.
- //
- // The default painting behavior is to first paint the node, and
- // then paint the node's children on top of the node. If a node
- // needs wants specialized painting behavior it can override:
- //
- // paint() - Painting here will happen before the children
- // are painted, so the children will be painted on top of painting done
- // here.
- // paintAfterChildren() - Painting here will happen after the children
- // are painted, so it will paint on top of them.
- //
- // Note that you should not normally need to override fullPaint().
- //
- // The visible flag can be used to make a node invisible so that
- // it will never get painted.
- //****************************************************************
-
- /**
- * Return true if this node is visible, that is if it will paint itself
- * and descendents.
- *
- * @return true if this node and its descendents are visible.
- */
- public boolean getVisible() {
- return visible;
- }
-
- /**
- * Set the visibility of this node and its descendents.
- *
- * @param isVisible true if this node and its descendents are visible
- */
- public void setVisible(boolean isVisible) {
- if (getVisible() != isVisible) {
- if (!isVisible) repaint();
- visible = isVisible;
- firePropertyChange(PROPERTY_CODE_VISIBLE ,PROPERTY_VISIBLE, null, null);
- invalidatePaint();
- }
- }
-
- /**
- * Return the paint used to paint this node. This value may be null.
- */
- public Paint getPaint() {
- return paint;
- }
-
- /**
- * Set the paint used to paint this node. This value may be set to null.
- */
- public void setPaint(Paint newPaint) {
- if (paint == newPaint) return;
-
- Paint old = paint;
- paint = newPaint;
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_PAINT ,PROPERTY_PAINT, old, paint);
- }
-
- /**
- * Return the transparency used when painting this node. Note that this
- * transparency is also applied to all of the node's descendents.
- */
- public float getTransparency() {
- return transparency;
- }
-
- /**
- * Set the transparency used to paint this node. Note that this transparency
- * applies to this node and all of its descendents.
- */
- public void setTransparency(float zeroToOne) {
- if (transparency == zeroToOne) return;
-
- transparency = zeroToOne;
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_TRANSPARENCY, PROPERTY_TRANSPARENCY, null, null);
- }
-
- /**
- * Paint this node behind any of its children nodes. Subclasses that define
- * a different appearance should override this method and paint themselves
- * there.
- *
- * @param paintContext the paint context to use for painting the node
- */
- protected void paint(PPaintContext paintContext) {
- if (paint != null) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(paint);
- g2.fill(getBoundsReference());
- }
- }
-
- /**
- * Paint this node and all of its descendents. Most subclasses do not need to
- * override this method, they should override paint
or
- * paintAfterChildren
instead.
- *
- * @param paintContext the paint context to use for painting this node and its children
- */
- public void fullPaint(PPaintContext paintContext) {
- if (getVisible() && fullIntersects(paintContext.getLocalClip())) {
- paintContext.pushTransform(transform);
- paintContext.pushTransparency(transparency);
-
- if (!getOccluded())
- paint(paintContext);
-
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- if (i < children.size()) { // TODO: このチェックはあとで追加した
- PNode each = children.get(i);
- each.fullPaint(paintContext);
- }
- }
-
- paintAfterChildren(paintContext);
-
- paintContext.popTransparency(transparency);
- paintContext.popTransform(transform);
- }
- }
-
- /**
- * Subclasses that wish to do additional painting after their children
- * are painted should override this method and do that painting here.
- *
- * @param paintContext the paint context to sue for painting after the children are painted
- */
- protected void paintAfterChildren(PPaintContext paintContext) {
- }
-
- /**
- * Return a new Image representing this node and all of its children. The image size will
- * be equal to the size of this nodes full bounds.
- *
- * @return a new image representing this node and its descendents
- */
- public Image toImage() {
- PBounds b = getFullBoundsReference();
- return toImage((int) Math.ceil(b.getWidth()), (int) Math.ceil(b.getHeight()), null);
- }
-
- /**
- * Return a new Image of the requested size representing this
- * node and all of its children. If backGroundPaint is null the resulting
- * image will have transparent regions, else those regions will be filled
- * with the backgroundPaint.
- *
- * @param width pixel width of the resulting image
- * @param height pixel height of the resulting image
- * @return a new image representing this node and its descendents
- */
- public Image toImage(int width, int height, Paint backGroundPaint) {
- PBounds imageBounds = getFullBounds();
-
- imageBounds.expandNearestIntegerDimensions();
-
- if(width / imageBounds.width < height / imageBounds.height) {
- double scale = width / imageBounds.width;
- height = (int) (imageBounds.height * scale);
- } else {
- double scale = height / imageBounds.height;
- width = (int) (imageBounds.width * scale);
- }
-
- GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- BufferedImage result = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
-
- return toImage(result, backGroundPaint);
- }
-
- /**
- * Paint a representation of this node into the specified buffered image. If background,
- * paint is null, then the image will not be filled with a color prior to rendering
- *
- * @return a rendering of this image and its descendents into the specified image
- */
- public Image toImage(BufferedImage image, Paint backGroundPaint) {
- int width = image.getWidth();
- int height = image.getHeight();
- Graphics2D g2 = image.createGraphics();
-
- if (backGroundPaint != null) {
- g2.setPaint(backGroundPaint);
- g2.fillRect(0, 0, width, height);
- }
-
- // reuse print method
- Paper paper = new Paper();
- paper.setSize(width, height);
- paper.setImageableArea(0, 0, width, height);
- PageFormat pageFormat = new PageFormat();
- pageFormat.setPaper(paper);
- print(g2, pageFormat, 0);
-
- return image;
- }
-
- /**
- * Constructs a new PrinterJob, allows the user to select which printer
- * to print to, And then prints the node.
- */
- public void print() {
- PrinterJob printJob = PrinterJob.getPrinterJob();
- PageFormat pageFormat = printJob.defaultPage();
- Book book = new Book();
- book.append(this, pageFormat);
- printJob.setPageable(book);
-
- if (printJob.printDialog()) {
- try {
- printJob.print();
- } catch (Exception e) {
- System.out.println("Error Printing");
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Prints the node into the given Graphics context using the specified
- * format. The zero based index of the requested page is specified by
- * pageIndex. If the requested page does not exist then this method returns
- * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. If the printable object
- * aborts the print job then it throws a PrinterException.
- *
- * @param graphics the context into which the node is drawn
- * @param pageFormat the size and orientation of the page
- * @param pageIndex the zero based index of the page to be drawn
- */
- public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
- if (pageIndex != 0) {
- return NO_SUCH_PAGE;
- }
-
- Graphics2D g2 = (Graphics2D)graphics;
- PBounds imageBounds = getFullBounds();
-
- imageBounds.expandNearestIntegerDimensions();
-
- g2.setClip(0, 0, (int)pageFormat.getWidth(), (int)pageFormat.getHeight());
- g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
-
- // scale the graphics so node's full bounds fit in the imageable bounds.
- double scale = pageFormat.getImageableWidth() / imageBounds.getWidth();
- if (pageFormat.getImageableHeight() / imageBounds.getHeight() < scale) {
- scale = pageFormat.getImageableHeight() / imageBounds.getHeight();
- }
-
- g2.scale(scale, scale);
- g2.translate(-imageBounds.x, -imageBounds.y);
-
- PPaintContext pc = new PPaintContext(g2);
- pc.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
- fullPaint(pc);
-
- return PAGE_EXISTS;
- }
-
- //****************************************************************
- // Picking - Methods for picking this node and its children.
- //
- // Picking is used to determine the node that intersects a point or
- // rectangle on the screen. It is most frequently used by the
- // PInputManager to determine the node that the cursor is over.
- //
- // The intersects() method is used to determine if a node has
- // been picked or not. The default implementation just test to see
- // if the pick bounds intersects the bounds of the node. Subclasses
- // whose geometry (a circle for example) does not match up exactly with
- // the bounds should override the intersects() method.
- //
- // The default picking behavior is to first try to pick the nodes
- // children, and then try to pick the nodes own bounds. If a node
- // wants specialized picking behavior it can override:
- //
- // pick() - Pick nodes here that should be picked before the nodes
- // children are picked.
- // pickAfterChildren() - Pick nodes here that should be picked after the
- // node's children are picked.
- //
- // Note that fullPick should not normally be overridden.
- //
- // The pickable and childrenPickable flags can be used to make a
- // node or it children not pickable even if their geometry does
- // intersect the pick bounds.
- //****************************************************************
-
- /**
- * Return true if this node is pickable. Only pickable nodes can
- * receive input events. Nodes are pickable by default.
- *
- * @return true if this node is pickable
- */
- public boolean getPickable() {
- return pickable;
- }
-
- /**
- * Set the pickable flag for this node. Only pickable nodes can
- * receive input events. Nodes are pickable by default.
- *
- * @param isPickable true if this node is pickable
- */
- public void setPickable(boolean isPickable) {
- if (getPickable() != isPickable) {
- pickable = isPickable;
- firePropertyChange(PROPERTY_CODE_PICKABLE, PROPERTY_PICKABLE, null, null);
- }
- }
-
- /**
- * Return true if the children of this node should be picked. If this flag
- * is false then this node will not try to pick its children. Children
- * are pickable by default.
- *
- * @return true if this node tries to pick its children
- */
- public boolean getChildrenPickable() {
- return childrenPickable;
- }
-
- /**
- * Set the children pickable flag. If this flag is false then this
- * node will not try to pick its children. Children are pickable by
- * default.
- *
- * @param areChildrenPickable true if this node tries to pick its children
- */
- public void setChildrenPickable(boolean areChildrenPickable) {
- if (getChildrenPickable() != areChildrenPickable) {
- childrenPickable = areChildrenPickable;
- firePropertyChange(PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CHILDREN_PICKABLE, null, null);
- }
- }
-
- /**
- * Try to pick this node before its children have had a chance to be
- * picked. Nodes that paint on top of their children may want to override
- * this method to if the pick path intersects that paint.
- *
- * @param pickPath the pick path used for the pick operation
- * @return true if this node was picked
- */
- protected boolean pick(PPickPath pickPath) {
- return false;
- }
-
- /**
- * Try to pick this node and all of its descendents. Most subclasses should not
- * need to override this method. Instead they should override pick
or
- * pickAfterChildren
.
- *
- * @param pickPath the pick path to add the node to if its picked
- * @return true if this node or one of its descendents was picked.
- */
- public boolean fullPick(PPickPath pickPath) {
- if ((getPickable() || getChildrenPickable()) && fullIntersects(pickPath.getPickBounds())) {
- pickPath.pushNode(this);
- pickPath.pushTransform(transform);
-
- boolean thisPickable = getPickable() && pickPath.acceptsNode(this);
-
- if (thisPickable) {
- if (pick(pickPath)) {
- return true;
- }
- }
-
- if (getChildrenPickable()) {
- int count = getChildrenCount();
- for (int i = count - 1; i >= 0; i--) {
- PNode each = children.get(i);
- if (each.fullPick(pickPath))
- return true;
- }
- }
-
- if (thisPickable) {
- if (pickAfterChildren(pickPath)) {
- return true;
- }
- }
-
- pickPath.popTransform(transform);
- pickPath.popNode(this);
- }
-
- return false;
- }
-
- public void findIntersectingNodes(Rectangle2D fullBounds, ArrayList results) {
- if (fullIntersects(fullBounds)) {
- Rectangle2D localBounds = parentToLocal((Rectangle2D)fullBounds.clone());
-
- if (intersects(localBounds)) {
- results.add(this);
- }
-
- int count = getChildrenCount();
- for (int i = count - 1; i >= 0; i--) {
- PNode each = children.get(i);
- each.findIntersectingNodes(localBounds, results);
- }
- }
- }
-
- /**
- * Try to pick this node after its children have had a chance to be
- * picked. Most subclasses the define a different geometry will need to
- * override this method.
- *
- * @param pickPath the pick path used for the pick operation
- * @return true if this node was picked
- */
- protected boolean pickAfterChildren(PPickPath pickPath) {
- if (intersects(pickPath.getPickBounds())) {
- return true;
- }
- return false;
- }
-
- //****************************************************************
- // Structure - Methods for manipulating and traversing the
- // parent child relationship
- //
- // Most of these methods won't need to be overridden by subclasses
- // but you will use them frequently to build up your node structures.
- //****************************************************************
-
- /**
- * Add a node to be a new child of this node. The new node
- * is added to the end of the list of this node's children.
- * If child was previously a child of another node, it is
- * removed from that first.
- *
- * @param child the new child to add to this node
- */
- public void addChild(PNode child) {
- int insertIndex = getChildrenCount();
- if (child.parent == this)
- insertIndex--;
- addChild(insertIndex, child);
- }
-
- /**
- * Add a node to be a new child of this node at the specified index.
- * If child was previously a child of another node, it is removed
- * from that node first.
- *
- * @param child the new child to add to this node
- */
- public void addChild(int index, PNode child) {
- PNode oldParent = child.getParent();
-
- if (oldParent != null) {
- oldParent.removeChild(child);
- }
-
- child.setParent(this);
- getChildrenReference().add(index, child);
- child.invalidatePaint();
- invalidateFullBounds();
-
- firePropertyChange(PROPERTY_CODE_CHILDREN, PROPERTY_CHILDREN, null, children);
- }
-
- /**
- * Add a collection of nodes to be children of this node. If these nodes
- * already have parents they will first be removed from those parents.
- *
- * @param nodes a collection of nodes to be added to this node
- */
- public void addChildren(Collection nodes) {
- Iterator i = nodes.iterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- addChild(each);
- }
- }
-
- /**
- * Return true if this node is an ancestor of the parameter node.
- *
- * @param node a possible descendent node
- * @return true if this node is an ancestor of the given node
- */
- public boolean isAncestorOf(PNode node) {
- PNode p = node.parent;
- while (p != null) {
- if (p == this) return true;
- p = p.parent;
- }
- return false;
- }
-
-
- /**
- * Return true if this node is a descendent of the parameter node.
- *
- * @param node a possible ancestor node
- * @return true if this nodes descends from the given node
- */
- public boolean isDescendentOf(PNode node) {
- PNode p = parent;
- while (p != null) {
- if (p == node) return true;
- p = p.parent;
- }
- return false;
- }
-
- /**
- * Return true if this node descends from the root.
- */
- public boolean isDescendentOfRoot() {
- return getRoot() != null;
- }
-
- /**
- * Change the order of this node in its parent's children list so that
- * it will draw in back of all of its other sibling nodes.
- */
- public void moveToBack() {
- PNode p = parent;
- if (p != null) {
- p.removeChild(this);
- p.addChild(0, this);
- }
- }
-
- /**
- * Change the order of this node in its parent's children list so that
- * it will draw in front of all of its other sibling nodes.
- */
- public void moveInBackOf(PNode sibling) {
- PNode p = parent;
- if (p != null && p == sibling.getParent()) {
- p.removeChild(this);
- int index = p.indexOfChild(sibling);
- p.addChild(index, this);
- }
- }
-
- /**
- * Change the order of this node in its parent's children list so that
- * it will draw after the given sibling node.
- */
- public void moveToFront() {
- PNode p = parent;
- if (p != null) {
- p.removeChild(this);
- p.addChild(this);
- }
- }
-
- /**
- * Change the order of this node in its parent's children list so that
- * it will draw before the given sibling node.
- */
- public void moveInFrontOf(PNode sibling) {
- PNode p = parent;
- if (p != null && p == sibling.getParent()) {
- p.removeChild(this);
- int index = p.indexOfChild(sibling);
- p.addChild(index + 1, this);
- }
- }
-
- /**
- * Return the parent of this node. This will be null if this node has not been
- * added to a parent yet.
- *
- * @return this nodes parent or null
- */
- public PNode getParent() {
- return parent;
- }
-
- /**
- * Set the parent of this node. Note this is set automatically when adding and
- * removing children.
- */
- public void setParent(PNode newParent) {
- PNode old = parent;
- parent = newParent;
- firePropertyChange(PROPERTY_CODE_PARENT, PROPERTY_PARENT, old, parent);
- }
-
- /**
- * Return the index where the given child is stored.
- */
- public int indexOfChild(PNode child) {
- if (children == null) return -1;
- return children.indexOf(child);
- }
-
- /**
- * Remove the given child from this node's children list. Any
- * subsequent children are shifted to the left (one is subtracted
- * from their indices). The removed child's parent is set to null.
- *
- * @param child the child to remove
- * @return the removed child
- */
- public PNode removeChild(PNode child) {
- return removeChild(indexOfChild(child));
- }
-
- /**
- * Remove the child at the specified position of this group node's children.
- * Any subsequent children are shifted to the left (one is subtracted from
- * their indices). The removed child's parent is set to null.
- *
- * @param index the index of the child to remove
- * @return the removed child
- */
- public PNode removeChild(int index) {
- PNode child = children.remove(index);
-
- if (children.size() == 0) {
- children = null;
- }
-
- child.repaint();
- child.setParent(null);
- invalidateFullBounds();
-
- firePropertyChange(PROPERTY_CODE_CHILDREN, PROPERTY_CHILDREN, null, children);
-
- return child;
- }
-
- /**
- * Remove all the children in the given collection from this node's
- * list of children. All removed nodes will have their parent set to
- * null.
- *
- * @param childrenNodes the collection of children to remove
- */
- public void removeChildren(Collection childrenNodes) {
- Iterator i = childrenNodes.iterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- removeChild(each);
- }
- }
-
- /**
- * Remove all the children from this node. Node this method is more efficient then
- * removing each child individually.
- */
- public void removeAllChildren() {
- if (children != null) {
- int count = children.size();
- for (int i = 0; i < count; i++) {
- PNode each = children.get(i);
- each.setParent(null);
- }
- children = null;
- invalidatePaint();
- invalidateFullBounds();
-
- firePropertyChange(PROPERTY_CODE_CHILDREN, PROPERTY_CHILDREN, null, children);
- }
- }
-
- /**
- * Delete this node by removing it from its parent's list of children.
- */
- public void removeFromParent() {
- if (parent != null) {
- parent.removeChild(this);
- }
- }
-
- /**
- * Set the parent of this node, and transform the node in such a way that it
- * doesn't move in global coordinates.
- *
- * @param newParent The new parent of this node.
- */
- public void reparent(PNode newParent) {
- AffineTransform originalTransform = getLocalToGlobalTransform(null);
- AffineTransform newTransform = newParent.getGlobalToLocalTransform(null);
- newTransform.concatenate(originalTransform);
-
- removeFromParent();
- setTransform(newTransform);
- newParent.addChild(this);
- computeFullBounds(fullBoundsCache);
- }
-
- /**
- * Swaps this node out of the scene graph tree, and replaces it with the specified
- * replacement node. This node is left dangling, and it is up to the caller to
- * manage it. The replacement node will be added to this node's parent in the same
- * position as this was. That is, if this was the 3rd child of its parent, then
- * after calling replaceWith(), the replacement node will also be the 3rd child of its parent.
- * If this node has no parent when replace is called, then nothing will be done at all.
- *
- * @param replacementNode the new node that replaces the current node in the scene graph tree.
- */
- public void replaceWith(PNode replacementNode) {
- if (parent != null) {
- PNode p = this.parent;
- int index = p.getChildrenReference().indexOf(this);
- p.removeChild(this);
- p.addChild(index, replacementNode);
- }
- }
-
- /**
- * Return the number of children that this node has.
- *
- * @return the number of children
- */
- public int getChildrenCount() {
- if (children == null) {
- return 0;
- }
- return children.size();
- }
-
- /**
- * Return the child node at the specified index.
- *
- * @param index a child index
- * @return the child node at the specified index
- */
- public PNode getChild(int index) {
- return children.get(index);
- }
-
- /**
- * Return a reference to the list used to manage this node's
- * children. This list should not be modified.
- *
- * @return reference to the children list
- */
- public List getChildrenReference() {
- if (children == null) {
- children = new ArrayList();
- }
- return children;
- }
-
- /**
- * Return an iterator over this node's direct descendent children.
- *
- * @return iterator over this nodes children
- */
- @SuppressWarnings("unchecked")
- public ListIterator getChildrenIterator() {
- if (children == null) {
- return (ListIterator) Collections.EMPTY_LIST.listIterator();
- }
- return Collections.unmodifiableList(children).listIterator();
- }
-
- /**
- * Return the root node (instance of PRoot). If this node does not
- * descend from a PRoot then null will be returned.
- */
- public PRoot getRoot() {
- if (parent != null) {
- return parent.getRoot();
- }
- return null;
- }
-
- /**
- * Return a collection containing this node and all of its descendent nodes.
- *
- * @return a new collection containing this node and all descendents
- */
- public Collection getAllNodes() {
- return getAllNodes(null, null);
- }
-
- /**
- * Return a collection containing the subset of this node and all of
- * its descendent nodes that are accepted by the given node filter. If the
- * filter is null then all nodes will be accepted. If the results parameter
- * is not null then it will be used to collect this subset instead of
- * creating a new collection.
- *
- * @param filter the filter used to determine the subset
- * @return a collection containing this node and all descendents
- */
- public Collection getAllNodes(PNodeFilter filter, Collection results) {
- if (results == null) results = new ArrayList();
- if (filter == null || filter.accept(this)) results.add(this);
-
- if (filter == null || filter.acceptChildrenOf(this)) {
- int count = getChildrenCount();
- for (int i = 0; i < count; i++) {
- PNode each = children.get(i);
- each.getAllNodes(filter, results);
- }
- }
-
- return results;
- }
-
- //****************************************************************
- // Serialization - Nodes conditionally serialize their parent.
- // This means that only the parents that were unconditionally
- // (using writeObject) serialized by someone else will be restored
- // when the node is unserialized.
- //****************************************************************
-
- /**
- * Write this node and all of its descendent nodes to the given outputsteam.
- * This stream must be an instance of PObjectOutputStream or serialization
- * will fail. This nodes parent is written out conditionally, that is it will
- * only be written out if someone else writes it out unconditionally.
- *
- * @param out the output stream to write to, must be an instance of PObjectOutputStream
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- ((PObjectOutputStream)out).writeConditionalObject(parent);
- }
-
- /**
- * Read this node and all of its descendents in from the given input stream.
- *
- * @param in the stream to read from
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- parent = (PNode) in.readObject();
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representation of this object for debugging purposes.
- */
- public String toString() {
- String result = super.toString().replaceAll(".*\\.", "");
- return result + "[" + paramString() + "]";
- }
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("bounds=" + (bounds == null ? "null" : bounds.toString()));
- result.append(",fullBounds=" + (fullBoundsCache == null ? "null" : fullBoundsCache.toString()));
- result.append(",transform=" + (transform == null ? "null" : transform.toString()));
- result.append(",paint=" + (paint == null ? "null" : paint.toString()));
- result.append(",transparency=" + transparency);
- result.append(",childrenCount=" + getChildrenCount());
-
- if (fullBoundsInvalid) {
- result.append(",fullBoundsInvalid");
- }
-
- if (pickable) {
- result.append(",pickable");
- }
-
- if (childrenPickable) {
- result.append(",childrenPickable");
- }
-
- if (visible) {
- result.append(",visible");
- }
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/PRoot.java b/src/main/java/edu/umd/cs/piccolo/PRoot.java
deleted file mode 100755
index ba71e2f..0000000
--- a/src/main/java/edu/umd/cs/piccolo/PRoot.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo;
-
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.swing.SwingUtilities;
-import javax.swing.Timer;
-
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.activities.PActivityScheduler;
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolo.util.PNodeFilter;
-
-/**
- * PRoot serves as the top node in Piccolo's runtime structure.
- * The PRoot responsible for running the main UI loop that processes
- * input from activities and external events.
- *
- * @version 1.1
- * @author Jesse Grosjean
- */
-public class PRoot extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -9195180118852888172L;
- /**
- * The property name that identifies a change in the set of this root's
- * input sources (see {@link InputSource InputSource}). In any property
- * change event the new value will be a reference to the list of this root's
- * input sources, but old value will always be null.
- */
- public static final String PROPERTY_INPUT_SOURCES = "inputSources";
- public static final int PROPERTY_CODE_INPUT_SOURCES = 1 << 14;
-
- protected transient boolean processingInputs;
- protected transient boolean processInputsScheduled;
-
- private PInputManager defaultInputManager;
- private transient List inputSources;
- private transient long globalTime;
- private PActivityScheduler activityScheduler;
-
- /**
- * This interfaces is for advanced use only. If you want to implement a
- * different kind of input framework then Piccolo provides you can hook
- * it in here.
- */
- public static interface InputSource {
- public void processInput();
- }
-
- /**
- * Construct a new PRoot(). Note the PCanvas already creates a basic scene
- * graph for you so often you will not need to construct your own roots.
- */
- public PRoot() {
- super();
- inputSources = new ArrayList();
- globalTime = System.currentTimeMillis();
- activityScheduler = new PActivityScheduler(this);
- }
-
- //****************************************************************
- // Activities
- //****************************************************************
-
- /**
- * Add an activity to the activity scheduler associated with this root.
- * Activities are given a chance to run during each call to the roots
- * processInputs
method. When the activity has finished
- * running it will automatically get removed.
- */
- public boolean addActivity(PActivity activity) {
- getActivityScheduler().addActivity(activity);
- return true;
- }
-
- /**
- * Get the activity scheduler associated with this root.
- */
- public PActivityScheduler getActivityScheduler() {
- return activityScheduler;
- }
-
- /**
- * Wait for all scheduled activities to finish before returning from
- * this method. This will freeze out user input, and so it is generally
- * recommended that you use PActivities.setTriggerTime() to offset activities
- * instead of using this method.
- */
- public void waitForActivities() {
- PNodeFilter cameraWithCanvas = new PNodeFilter() {
- public boolean accept(PNode aNode) {
- return (aNode instanceof PCamera) && (((PCamera)aNode).getComponent() != null);
- }
- public boolean acceptChildrenOf(PNode aNode) {
- return true;
- }
- };
-
- while (activityScheduler.getActivitiesReference().size() > 0) {
- processInputs();
- Iterator i = getAllNodes(cameraWithCanvas, null).iterator();
- while (i.hasNext()) {
- PCamera each = (PCamera) i.next();
- each.getComponent().paintImmediately();
- }
- }
- }
-
- //****************************************************************
- // Basics
- //****************************************************************
-
- /**
- * Return this.
- */
- public PRoot getRoot() {
- return this;
- }
-
- /**
- * Get the default input manager to be used when processing input
- * events. PCanvas's use this method when they forward new swing input
- * events to the PInputManager.
- */
- public PInputManager getDefaultInputManager() {
- if (defaultInputManager == null) {
- defaultInputManager = new PInputManager();
- addInputSource(defaultInputManager);
- }
- return defaultInputManager;
- }
-
- /**
- * Advanced. If you want to add additional input sources to the roots
- * UI process you can do that here. You will seldom do this unless you
- * are making additions to the piccolo framework.
- */
- public void addInputSource(InputSource inputSource) {
- inputSources.add(inputSource);
- firePropertyChange(PROPERTY_CODE_INPUT_SOURCES ,PROPERTY_INPUT_SOURCES, null, inputSources);
- }
-
- /**
- * Advanced. If you want to remove the default input source from the roots
- * UI process you can do that here. You will seldom do this unless you
- * are making additions to the piccolo framework.
- */
- public void removeInputSource(InputSource inputSource) {
- inputSources.remove(inputSource);
- firePropertyChange(PROPERTY_CODE_INPUT_SOURCES ,PROPERTY_INPUT_SOURCES, null, inputSources);
- }
-
- /**
- * Returns a new timer. This method allows subclasses, such as PSWTRoot to
- * create custom timers that will be used transparently by the Piccolo
- * framework.
- */
- public Timer createTimer(int delay, ActionListener listener) {
- return new Timer(delay,listener);
- }
-
- //****************************************************************
- // UI Loop - Methods for running the main UI loop of Piccolo.
- //****************************************************************
-
- /**
- * Get the global Piccolo time. This is set to System.currentTimeMillis() at
- * the beginning of the roots processInputs
method. Activities
- * should usually use this global time instead of System.
- * currentTimeMillis() so that multiple activities will be synchronized.
- */
- public long getGlobalTime() {
- return globalTime;
- }
-
- /**
- * This is the heartbeat of the Piccolo framework. Pending input events
- * are processed. Activities are given a chance to run, and the bounds caches
- * and any paint damage is validated.
- */
- public void processInputs() {
- PDebug.startProcessingInput();
- processingInputs = true;
-
- globalTime = System.currentTimeMillis();
- int count = inputSources == null ? 0: inputSources.size();
- for (int i = 0; i < count; i++) {
- InputSource each = (InputSource) inputSources.get(i);
- each.processInput();
- }
-
- activityScheduler.processActivities(globalTime);
- validateFullBounds();
- validateFullPaint();
-
- processingInputs = false;
- PDebug.endProcessingInput();
- }
-
- public void setFullBoundsInvalid(boolean fullLayoutInvalid) {
- super.setFullBoundsInvalid(fullLayoutInvalid);
- scheduleProcessInputsIfNeeded();
- }
-
- public void setChildBoundsInvalid(boolean childLayoutInvalid) {
- super.setChildBoundsInvalid(childLayoutInvalid);
- scheduleProcessInputsIfNeeded();
- }
-
- public void setPaintInvalid(boolean paintInvalid) {
- super.setPaintInvalid(paintInvalid);
- scheduleProcessInputsIfNeeded();
- }
-
- public void setChildPaintInvalid(boolean childPaintInvalid) {
- super.setChildPaintInvalid(childPaintInvalid);
- scheduleProcessInputsIfNeeded();
- }
-
- public void scheduleProcessInputsIfNeeded() {
- // The reason for the special case here (when not in the event dispatch thread) is that
- // the SwingUtilitiles.invokeLater code below only invokes later with respect to the
- // event dispatch thread, it will invoke concurrently with other threads.
- if (!SwingUtilities.isEventDispatchThread()) {
- // Piccolo is not thread safe and should amost always be called from the
- // Swing event dispatch thread. It should only reach this point when a new canvas
- // is being created.
- return;
- }
-
- PDebug.scheduleProcessInputs();
-
- if (!processInputsScheduled && !processingInputs &&
- (getFullBoundsInvalid() || getChildBoundsInvalid() || getPaintInvalid() || getChildPaintInvalid())) {
-
- processInputsScheduled = true;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- processInputs();
- PRoot.this.processInputsScheduled = false;
- }
- });
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java b/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java
deleted file mode 100755
index 081fef2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/activities/PActivity.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.activities;
-
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PActivity controls some time dependent aspect of Piccolo, such
- * as animation. Once created activities must be scheduled with the
- * PActivityScheduler managed by the PRoot to run. They are automatically
- * removed from the scheduler when the animation has finished.
- *
- * See the PNode.animate*() methods for an example of how to set up and run
- * different activities.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PActivity {
-
- public static final int TERMINATE_WITHOUT_FINISHING = 0;
- public static final int TERMINATE_AND_FINISH = 1;
- public static final int TERMINATE_AND_FINISH_IF_STEPPING = 2;
-
- private PActivityScheduler scheduler;
-
- private long startTime;
- private long duration;
- private long stepRate;
- private PActivityDelegate delegate;
-
- private boolean stepping;
- private long nextStepTime;
-
- /**
- * PActivityDelegate is used by classes to learn about and act on the
- * different states that a PActivity goes through, such as when the activity
- * starts and stops stepping.
- */
- public interface PActivityDelegate {
- public void activityStarted(PActivity activity);
- public void activityStepped(PActivity activity);
- public void activityFinished(PActivity activity);
- }
-
- /**
- * Constructs a new PActivity.
- *
- * @param aDuration the amount of time that this activity should take to complete, -1 for infinite.
- */
- public PActivity(long aDuration) {
- this(aDuration, PUtil.DEFAULT_ACTIVITY_STEP_RATE);
- }
-
- /**
- * Constructs a new PActivity.
- *
- * @param aDuration the amount of time that this activity should take to complete, -1 for infinite.
- * @param aStepRate the maximum rate that this activity should receive step events.
- */
- public PActivity(long aDuration, long aStepRate) {
- this(aDuration, aStepRate, System.currentTimeMillis());
- }
-
- /**
- * Constructs a new PActivity.
- *
- * @param aDuration the amount of time that this activity should take to complete, -1 for infinite.
- * @param aStepRate the maximum rate that this activity should receive step events.
- * @param aStartTime the time (relative to System.currentTimeMillis()) that
- * this activity should start.
- */
- public PActivity(long aDuration, long aStepRate, long aStartTime) {
- duration = aDuration;
- stepRate = aStepRate;
- startTime = aStartTime;
- nextStepTime = aStartTime;
- stepping = false;
- }
-
- //****************************************************************
- // Basics
- //****************************************************************
-
- /**
- * Return the time that this activity should start running in PRoot
- * global time. When this time is reached (or soon after) this activity
- * will have its startStepping() method called.
- */
- public long getStartTime() {
- return startTime;
- }
-
- /**
- * Set the time that this activity should start running in PRoot
- * global time. When this time is reached (or soon after) this activity
- * will have its startStepping() method called.
- */
- public void setStartTime(long aTriggerTime) {
- startTime = aTriggerTime;
- }
-
- /**
- * Return the amount of time that this activity should delay
- * between steps.
- */
- public long getStepRate() {
- return stepRate;
- }
-
- /**
- * Set the amount of time that this activity should delay
- * between steps.
- */
- public void setStepRate(long aStepRate) {
- stepRate = aStepRate;
- }
-
- public long getNextStepTime() {
- return nextStepTime;
- }
-
- /**
- * Return the amount of time that this activity should take to complete,
- * after the startStepping method is called.
- */
- public long getDuration() {
- return duration;
- }
-
- /**
- * Set the amount of time that this activity should take to complete,
- * after the startStepping method is called.
- */
- public void setDuration(long aDuration) {
- duration = aDuration;
- }
-
- public PActivityScheduler getActivityScheduler() {
- return scheduler;
- }
-
- public void setActivityScheduler(PActivityScheduler aScheduler) {
- scheduler = aScheduler;
- }
-
- //****************************************************************
- // Stepping
- //****************************************************************
-
- /**
- * Return true if this activity is stepping.
- */
- public boolean isStepping() {
- return stepping;
- }
-
- /**
- * Return true if this activity is performing an animation. This is used
- * by the PCanvas to determine if it should set the render quality to
- * PCanvas.animatingRenderQuality or not for each frame it renders.
- */
- protected boolean isAnimation() {
- return false;
- }
-
- /**
- * This method is called right before an activity is scheduled to start
- * running. After this method is called step() will be called until the
- * activity finishes.
- */
- protected void activityStarted() {
- if (delegate != null)
- delegate.activityStarted(this);
- }
-
- /**
- * This is the method that most activities override to perform their
- * behavior. It will be called repeatedly when the activity is running.
- *
- * @param elapsedTime the amount of time that has passed relative to the activities startTime.
- */
- protected void activityStep(long elapsedTime) {
- if (delegate != null)
- delegate.activityStepped(this);
- }
-
- /**
- * This method is called after an activity is has finished running and the
- * activity has been removed from the PActivityScheduler queue.
- */
- protected void activityFinished() {
- if (delegate != null)
- delegate.activityFinished(this);
- }
-
- /**
- * Get the delegate for this activity. The delegate is notified when
- * the activity starts and stops stepping.
- */
- public PActivityDelegate getDelegate() {
- return delegate;
- }
-
- /**
- * Set the delegate for this activity. The delegate is notified when
- * the activity starts and stops stepping.
- */
- public void setDelegate(PActivityDelegate delegate) {
- this.delegate = delegate;
- }
-
- //****************************************************************
- // Controlling
- //****************************************************************
-
- /**
- * Schedules this activity to start after the first activity has finished.
- * Note that no link is created between these activities, if the startTime
- * or duration of the first activity is later changed this activities start
- * time will not be updated to reflect that change.
- */
- public void startAfter(PActivity first) {
- setStartTime(first.getStartTime() + first.getDuration());
- }
-
- /**
- * Stop this activity immediately, and remove it from the activity
- * scheduler. The default termination behavior is call activityFinished
- * if the activity is currently stepping. Use terminate(terminationBehavior)
- * use a different termination behavior.
- */
- public void terminate() {
- terminate(TERMINATE_AND_FINISH_IF_STEPPING);
- }
-
- /**
- * Stop this activity immediately, and remove it from the activity
- * scheduler. The termination behavior determines when and if activityStarted
- * and activityFinished get called. The possible termination behaviors are as
- * follow:
- *
- * TERMINATE_WITHOUT_FINISHING - The method activityFinished will never get called and
- * so the activity will be terminated midway.
- * TERMINATE_AND_FINISH - The method activityFinished will always get called. And so the
- * activity will always end in it's completed state. If the activity has not yet started
- * the method activityStarted will also be called.
- * TERMINATE_AND_FINISH_IF_STEPPING - The method activityFinished will only be called
- * if the activity has previously started.
- */
- public void terminate(int terminationBehavior) {
- if (scheduler != null) {
- scheduler.removeActivity(this);
- }
-
- switch (terminationBehavior) {
- case TERMINATE_WITHOUT_FINISHING:
- stepping = false;
- break;
-
- case TERMINATE_AND_FINISH:
- if (stepping) {
- stepping = false;
- activityFinished();
- } else {
- activityStarted();
- activityFinished();
- }
-
- break;
-
- case TERMINATE_AND_FINISH_IF_STEPPING:
- if (stepping) {
- stepping = false;
- activityFinished();
- }
- break;
- }
- }
-
- /**
- * The activity scheduler calls this method and it is here
- * that the activity decides if it should do a step or not for the
- * given time.
- */
- public long processStep(long currentTime) {
- // if before start time
- if (currentTime < startTime) {
- return startTime - currentTime;
- }
-
- // if past stop time
- if (currentTime > getStopTime()) {
- if (stepping) {
- stepping = false;
- scheduler.removeActivity(this);
- activityFinished();
- } else {
- activityStarted();
- scheduler.removeActivity(this);
- activityFinished();
- }
- return -1;
- }
-
- // else should be stepping
- if (!stepping) {
- activityStarted();
- stepping = true;
- }
-
- if (currentTime >= nextStepTime) {
- activityStep(currentTime - startTime);
- nextStepTime = currentTime + stepRate;
- }
-
- return stepRate;
- }
-
- /**
- * Return the time when this activity should finish running. At this time
- * (or soon after) the stoppedStepping method will be called
- */
- public long getStopTime() {
- if (duration == -1) {
- return Long.MAX_VALUE;
- }
- return startTime + duration;
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representation of this object for debugging purposes.
- */
- public String toString() {
- String result = super.toString().replaceAll(".*\\.", "");
- return result + "[" + paramString() + "]";
- }
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("startTime=" + startTime);
- result.append(",duration=" + duration);
- result.append(",stepRate=" + stepRate);
- if (stepping) result.append(",stepping");
- result.append(",nextStepTime=" + nextStepTime);
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java b/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java
deleted file mode 100755
index 8245e09..0000000
--- a/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.activities;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.Timer;
-
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PActivityScheduler is responsible for maintaining a list of
- * activities. It is given a chance to process these activities from
- * the PRoot's processInputs() method. Most users will not need to use
- * the PActivityScheduler directly, instead you should look at:
- *
- * PNode.addActivity - to schedule a new activity
- * PActivity.terminate - to terminate a running activity
- * PRoot.processInputs - already calls processActivities for you.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PActivityScheduler {
-
- private PRoot root;
- private List activities;
- private Timer activityTimer;
- private boolean activitiesChanged;
- private boolean animating;
- private ArrayList processingActivities;
-
- public PActivityScheduler(PRoot rootNode) {
- root = rootNode;
- activities = new ArrayList();
- processingActivities = new ArrayList();
- }
-
- public PRoot getRoot() {
- return root;
- }
-
- public void addActivity(PActivity activity) {
- addActivity(activity, false);
- }
-
- /**
- * Add this activity to the scheduler. Sometimes it's useful to make sure
- * that an activity is run after all other activities have been run. To do
- * this set processLast to true when adding the activity.
- */
- public void addActivity(PActivity activity, boolean processLast) {
- if (activities.contains(activity)) return;
-
- activitiesChanged = true;
-
- if (processLast) {
- activities.add(0, activity);
- } else {
- activities.add(activity);
- }
-
- activity.setActivityScheduler(this);
-
- if (!getActivityTimer().isRunning()) {
- startActivityTimer();
- }
- }
-
- public void removeActivity(PActivity activity) {
- if (!activities.contains(activity)) return;
-
- activitiesChanged = true;
- activities.remove(activity);
-
- if (activities.size() == 0) {
- stopActivityTimer();
- }
- }
-
- public void removeAllActivities() {
- activitiesChanged = true;
- activities.clear();
- stopActivityTimer();
- }
-
- public List getActivitiesReference() {
- return activities;
- }
-
- /**
- * Process all scheduled activities for the given time. Each activity
- * is given one "step", equivalent to one frame of animation.
- */
- public void processActivities(long currentTime) {
- int size = activities.size();
- if (size > 0) {
- processingActivities.clear();
- processingActivities.addAll(activities);
- for (int i = size - 1; i >= 0; i--) {
- PActivity each = (PActivity) processingActivities.get(i);
- each.processStep(currentTime);
- }
- }
- }
-
- /**
- * Return true if any of the scheduled activities return true to
- * the message isAnimation();
- */
- public boolean getAnimating() {
- if (activitiesChanged) {
- animating = false;
- for(int i=0; iPColorActivity interpolates between two colors for its target over the
- * duration of the animation. The source color is retrieved from the target just
- * before the activity is scheduled to start.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PColorActivity extends PInterpolatingActivity {
-
- private Color source;
- private Color destination;
- private Target target;
-
- /**
- * Target Objects that want their color to be set by the color
- * activity must implement this interface.
- */
- public interface Target {
-
- /**
- * This will be called by the color activity for each new
- * interpolated color that it computes while it is stepping.
- */
- public void setColor(Color color);
-
- /**
- * This method is called right before the color activity starts. That
- * way an object's color is always animated from its current color the
- * the destination color that is specified in the color activity.
- */
- public Color getColor();
- }
-
- public PColorActivity(long duration, long stepRate, Target aTarget) {
- this(duration, stepRate, aTarget, null);
- }
-
- public PColorActivity(long duration, long stepRate, Target aTarget, Color aDestination) {
- this(duration, stepRate, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION, aTarget, aDestination);
- }
-
- /**
- * Create a new PColorActivity.
- *
- * @param duration the length of one loop of the activity
- * @param stepRate the amount of time between steps of the activity
- * @param loopCount number of times the activity should reschedule itself
- * @param mode defines how the activity interpolates between states
- * @param aTarget the object that the activity will be applied to and where
- * the source state will be taken from.
- * @param aDestination the destination color state
- */
- public PColorActivity(long duration, long stepRate, int loopCount, int mode, Target aTarget, Color aDestination) {
- super(duration, stepRate, loopCount, mode);
- target = aTarget;
- destination = aDestination;
- }
-
- protected boolean isAnimation() {
- return true;
- }
-
- /**
- * Return the final color that will be set on the color activities target
- * when the activity stops stepping.
- */
- public Color getDestinationColor() {
- return destination;
- }
-
- /**
- * Set the final color that will be set on the color activities target when
- * the activity stops stepping.
- */
- public void setDestinationColor(Color newDestination) {
- destination = newDestination;
- }
-
- protected void activityStarted() {
- if (getFirstLoop()) source = target.getColor();
- super.activityStarted();
- }
-
- public void setRelativeTargetValue(float zeroToOne) {
- super.setRelativeTargetValue(zeroToOne);
- float red = (float) (source.getRed() + (zeroToOne * (destination.getRed() - source.getRed())));
- float green = (float) (source.getGreen() + (zeroToOne * (destination.getGreen() - source.getGreen())));
- float blue = (float) (source.getBlue() + (zeroToOne * (destination.getBlue() - source.getBlue())));
- float alpha = (float) (source.getAlpha() + (zeroToOne * (destination.getAlpha() - source.getAlpha())));
- target.setColor(new Color(red/255, green/255, blue/255, alpha/255));
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this object. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this object's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("source=" + (source == null ? "null" : source.toString()));
- result.append(",destination=" + (destination == null ? "null" : destination.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/activities/PInterpolatingActivity.java b/src/main/java/edu/umd/cs/piccolo/activities/PInterpolatingActivity.java
deleted file mode 100755
index 3273296..0000000
--- a/src/main/java/edu/umd/cs/piccolo/activities/PInterpolatingActivity.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.activities;
-
-/**
- * PInterpolatingActivity interpolates between two states (source and
- * destination) over the duration of the activity. The interpolation can be
- * either linear or slow- in, slow-out.
- *
- * The mode determines how the activity interpolates between the two states. The
- * default mode interpolates from source to destination, but you can also go
- * from destination to source, and from source to destination to source.
- *
- * A loopCount of greater then one will make the activity reschedule itself when
- * it has finished. This makes the activity loop between the two states.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PInterpolatingActivity extends PActivity {
-
- public static final int SOURCE_TO_DESTINATION = 1;
- public static final int DESTINATION_TO_SOURCE = 2;
- public static final int SOURCE_TO_DESTINATION_TO_SOURCE = 3;
-
- private int mode;
- private boolean slowInSlowOut;
- private int loopCount;
- private boolean firstLoop;
-
- public PInterpolatingActivity(long duration, long stepRate) {
- this(duration, stepRate, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION);
- }
-
- public PInterpolatingActivity(long duration, long stepRate, int loopCount, int mode) {
- this(duration, stepRate, System.currentTimeMillis(), loopCount, mode);
- }
-
- /**
- * Create a new PInterpolatingActivity.
- *
- * @param duration the length of one loop of the activity
- * @param stepRate the amount of time between steps of the activity
- * @param startTime the time (relative to System.currentTimeMillis()) that
- * this activity should start.
- * @param loopCount number of times the activity should reschedule itself
- * @param mode defines how the activity interpolates between states
- */
- public PInterpolatingActivity(long duration, long stepRate, long startTime, int loopCount, int mode) {
- super(duration, stepRate, startTime);
- this.loopCount = loopCount;
- this.mode = mode;
- slowInSlowOut = true;
- firstLoop = true;
- }
-
- /**
- * Set the amount of time that this activity should take to complete,
- * after the startStepping method is called. The duration must be greater
- * then zero so that the interpolation value can be computed.
- */
- public void setDuration(long aDuration) {
- if (aDuration <= 0)
- throw new IllegalArgumentException("Duration for PInterpolatingActivity must be greater then 0");
-
- super.setDuration(aDuration);
- }
-
- //****************************************************************
- // Basics.
- //****************************************************************
-
- /**
- * Return the mode that defines how the activity interpolates between
- * states.
- */
- public int getMode() {
- return mode;
- }
-
- /**
- * Set the mode that defines how the activity interpolates between states.
- */
- public void setMode(int mode) {
- this.mode = mode;
- }
-
- /**
- * Return the number of times the activity should automatically reschedule
- * itself after it has finished.
- */
- public int getLoopCount() {
- return loopCount;
- }
-
- /**
- * Set the number of times the activity should automatically reschedule
- * itself after it has finished.
- */
- public void setLoopCount(int loopCount) {
- this.loopCount = loopCount;
- }
-
- /**
- * Return true if the activity is executing its first loop. Subclasses
- * normally initialize their source state on the first loop.
- */
- public boolean getFirstLoop() {
- return firstLoop;
- }
-
- /**
- * Set if the activity is executing its first loop. Subclasses normally
- * initialize their source state on the first loop. This method will rarely
- * need to be called, unless your are reusing activities.
- */
- public void setFirstLoop(boolean firstLoop) {
- this.firstLoop = firstLoop;
- }
-
- public boolean getSlowInSlowOut() {
- return slowInSlowOut;
- }
-
- public void setSlowInSlowOut(boolean isSlowInSlowOut) {
- slowInSlowOut = isSlowInSlowOut;
- }
-
- //****************************************************************
- // Stepping - Instead of overriding the step methods subclasses
- // of this activity will normally override setRelativeTargetValue().
- // This method will be called for every step of the activity with
- // a value ranging from 0,0 (for the first step) to 1.0 (for the
- // final step). See PTransformActivity for an example.
- //****************************************************************
-
- protected void activityStarted() {
- super.activityStarted();
- setRelativeTargetValueAdjustingForMode(0);
- }
-
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- float t = elapsedTime / (float) getDuration();
-
- t = Math.min(1, t);
- t = Math.max(0, t);
-
- if (getSlowInSlowOut()) {
- t = computeSlowInSlowOut(t);
- }
-
- setRelativeTargetValueAdjustingForMode(t);
- }
-
- protected void activityFinished() {
- setRelativeTargetValueAdjustingForMode(1);
- super.activityFinished();
-
- PActivityScheduler scheduler = getActivityScheduler();
- if (loopCount > 1) {
- if (loopCount != Integer.MAX_VALUE) loopCount--;
- firstLoop = false;
- setStartTime(scheduler.getRoot().getGlobalTime());
- scheduler.addActivity(this);
- }
- }
-
- /**
- * Stop this activity immediately, and remove it from the activity
- * scheduler. If this activity is currently running then stoppedStepping
- * will be called after it has been removed from the activity scheduler.
- */
- public void terminate() {
- loopCount = 0; // set to zero so that we don't reschedule self.
- super.terminate();
- }
-
- /**
- * Subclasses should override this method and set the value on their
- * target (the object that they are modifying) accordingly.
- */
- public void setRelativeTargetValue(float zeroToOne) {
- }
-
- public float computeSlowInSlowOut(float zeroToOne) {
- if (zeroToOne < 0.5) {
- return 2.0f * zeroToOne * zeroToOne;
- } else {
- float complement = 1.0f - zeroToOne;
- return 1.0f - (2.0f * complement * complement);
- }
- }
-
- protected void setRelativeTargetValueAdjustingForMode(float zeroToOne) {
- switch (mode) {
- case SOURCE_TO_DESTINATION:
- break;
-
- case DESTINATION_TO_SOURCE:
- zeroToOne = 1 - zeroToOne;
- break;
-
- case SOURCE_TO_DESTINATION_TO_SOURCE:
- if (zeroToOne <= 0.5) {
- zeroToOne *= 2;
- } else {
- zeroToOne = 1 - ((zeroToOne - 0.5f) * 2);
- }
- break;
- }
-
- setRelativeTargetValue(zeroToOne);
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- if (slowInSlowOut) {
- result.append("slowinSlowOut,");
- }
-
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/activities/PTransformActivity.java b/src/main/java/edu/umd/cs/piccolo/activities/PTransformActivity.java
deleted file mode 100755
index c1c6483..0000000
--- a/src/main/java/edu/umd/cs/piccolo/activities/PTransformActivity.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.activities;
-
-import java.awt.geom.AffineTransform;
-
-import edu.umd.cs.piccolo.util.PAffineTransform;
-
-/**
- * PTransformActivity interpolates between two transforms setting its
- * target's transform as it goes. See PNode. animate*() for an example of this
- * activity in used. The source transform is retrieved from the target just
- * before the animation is scheduled to start.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PTransformActivity extends PInterpolatingActivity {
-
- private static PAffineTransform STATIC_TRANSFORM = new PAffineTransform();
-
- private double[] source;
- private double[] destination;
- private Target target;
-
- /**
- * Target Objects that want to get transformed by the transform
- * activity must implement this interface. See PNode.animateToTransform()
- * for one way to do this.
- */
- public interface Target {
-
- /**
- * This will be called by the transform activity for each new transform
- * that it computes while it is stepping.
- */
- public void setTransform(AffineTransform aTransform);
-
- /**
- * This method is called right before the transform activity starts. That
- * way an object is always animated from its current position.
- */
- public void getSourceMatrix(double[] aSource);
- }
-
- public PTransformActivity(long duration, long stepRate, Target aTarget) {
- this(duration, stepRate, aTarget, null);
- }
-
- public PTransformActivity(long duration, long stepRate, Target aTarget, AffineTransform aDestination) {
- this(duration, stepRate, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION, aTarget, aDestination);
- }
-
- /**
- * Create a new PTransformActivity.
- *
- * @param duration the length of one loop of the activity
- * @param stepRate the amount of time between steps of the activity
- * @param loopCount number of times the activity should reschedule itself
- * @param mode defines how the activity interpolates between states
- * @param aTarget the object that the activity will be applied to and where
- * the source state will be taken from.
- * @param aDestination the destination color state
- */
- public PTransformActivity(long duration, long stepRate, int loopCount, int mode, Target aTarget, AffineTransform aDestination) {
- super(duration, stepRate, loopCount, mode);
- source = new double[6];
- destination = new double[6];
- target = aTarget;
- if (aDestination != null) aDestination.getMatrix(destination);
- }
-
- protected boolean isAnimation() {
- return true;
- }
-
- /**
- * Return the final transform that will be set on the transform activities
- * target when the transform activity stops stepping.
- */
- public double[] getDestinationTransform() {
- return destination;
- }
-
- /**
- * Set the final transform that will be set on the transform activities
- * target when the transform activity stops stepping.
- */
- public void setDestinationTransform(double[] newDestination) {
- destination = newDestination;
- }
-
- protected void activityStarted() {
- if (getFirstLoop()) target.getSourceMatrix(source);
- super.activityStarted();
- }
-
- public void setRelativeTargetValue(float zeroToOne) {
- super.setRelativeTargetValue(zeroToOne);
-
- STATIC_TRANSFORM.setTransform(source[0] + (zeroToOne * (destination[0] - source[0])),
- source[1] + (zeroToOne * (destination[1] - source[1])),
- source[2] + (zeroToOne * (destination[2] - source[2])),
- source[3] + (zeroToOne * (destination[3] - source[3])),
- source[4] + (zeroToOne * (destination[4] - source[4])),
- source[5] + (zeroToOne * (destination[5] - source[5])));
-
- target.setTransform(STATIC_TRANSFORM);
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this activity. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this activity's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("source=" + (source == null ? "null" : source.toString()));
- result.append(",destination=" + (destination == null ? "null" : destination.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/activities/package.html b/src/main/java/edu/umd/cs/piccolo/activities/package.html
deleted file mode 100755
index b857b42..0000000
--- a/src/main/java/edu/umd/cs/piccolo/activities/package.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
-This package supports Piccolo activities. Activities are used to control some time
-dependent aspect of Piccolo such as animation.
-
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PBasicInputEventHandler.java b/src/main/java/edu/umd/cs/piccolo/event/PBasicInputEventHandler.java
deleted file mode 100755
index 2b78473..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PBasicInputEventHandler.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.event.FocusEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-
-/**
- * PBasicInputEventHandler is the standard class in Piccolo that
- * is used to register for mouse and keyboard events on a PNode. Note the
- * events that you get depends on the node that you have registered with. For
- * example you will only get mouse moved events when the mouse is over the node
- * that you have registered with, not when the mouse is over some other node.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PBasicInputEventHandler implements PInputEventListener {
-
- private PInputEventFilter eventFilter;
-
- public PBasicInputEventHandler() {
- super();
- eventFilter = new PInputEventFilter();
- }
-
- public void processEvent(PInputEvent event, int type) {
- if (!acceptsEvent(event, type)) return;
-
- switch (type) {
- case KeyEvent.KEY_PRESSED:
- keyPressed(event);
- break;
-
- case KeyEvent.KEY_RELEASED:
- keyReleased(event);
- break;
-
- case KeyEvent.KEY_TYPED:
- keyTyped(event);
- break;
-
- case MouseEvent.MOUSE_CLICKED:
- mouseClicked(event);
- break;
-
- case MouseEvent.MOUSE_DRAGGED:
- mouseDragged(event);
- break;
-
- case MouseEvent.MOUSE_ENTERED:
- mouseEntered(event);
- break;
-
- case MouseEvent.MOUSE_EXITED:
- mouseExited(event);
- break;
-
- case MouseEvent.MOUSE_MOVED:
- mouseMoved(event);
- break;
-
- case MouseEvent.MOUSE_PRESSED:
- mousePressed(event);
- break;
-
- case MouseEvent.MOUSE_RELEASED:
- mouseReleased(event);
- break;
-
- case MouseWheelEvent.WHEEL_UNIT_SCROLL:
- mouseWheelRotated(event);
- break;
-
- case MouseWheelEvent.WHEEL_BLOCK_SCROLL:
- mouseWheelRotatedByBlock(event);
- break;
-
- case FocusEvent.FOCUS_GAINED:
- keyboardFocusGained(event);
- break;
-
- case FocusEvent.FOCUS_LOST:
- keyboardFocusLost(event);
- break;
-
- default:
- throw new RuntimeException("Bad Event Type");
- }
- }
-
- //****************************************************************
- // Event Filter - All this event listener can be associated with a event
- // filter. The filter accepts and rejects events based on their modifier
- // flags and type. If the filter is null (the
- // default case) then it accepts all events.
- //****************************************************************
-
- public boolean acceptsEvent(PInputEvent event, int type) {
- return eventFilter.acceptsEvent(event, type);
- }
-
- public PInputEventFilter getEventFilter() {
- return eventFilter;
- }
-
- public void setEventFilter(PInputEventFilter newEventFilter) {
- eventFilter = newEventFilter;
- }
-
- //****************************************************************
- // Events - Methods for handling events sent to the event listener.
- //****************************************************************
-
- public void keyPressed(PInputEvent event) {
- }
-
- public void keyReleased(PInputEvent event) {
- }
-
- public void keyTyped(PInputEvent event) {
- }
-
- public void mouseClicked(PInputEvent event) {
- }
-
- public void mousePressed(PInputEvent event) {
- }
-
- public void mouseDragged(PInputEvent event) {
- }
-
- public void mouseEntered(PInputEvent event) {
- }
-
- public void mouseExited(PInputEvent event) {
- }
-
- public void mouseMoved(PInputEvent event) {
- }
-
- public void mouseReleased(PInputEvent event) {
- }
-
- public void mouseWheelRotated(PInputEvent event) {
- }
-
- public void mouseWheelRotatedByBlock(PInputEvent event) {
- }
-
- public void keyboardFocusGained(PInputEvent event) {
- }
-
- public void keyboardFocusLost(PInputEvent event) {
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representation of this object for debugging purposes.
- */
- public String toString() {
- String result = super.toString().replaceAll(".*\\.", "");
- return result + "[" + paramString() + "]";
- }
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
- result.append("eventFilter=" + eventFilter == null ? "null" : eventFilter.toString());
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PDragEventHandler.java b/src/main/java/edu/umd/cs/piccolo/event/PDragEventHandler.java
deleted file mode 100755
index 5ac264d..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PDragEventHandler.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.event.InputEvent;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PDimension;
-
-/**
- * PDragEventHandler is a simple event handler for dragging a
- * node on the canvas.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PDragEventHandler extends PDragSequenceEventHandler {
-
- private PNode draggedNode;
- private boolean moveToFrontOnPress = false;
-
- public PDragEventHandler() {
- super();
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- protected PNode getDraggedNode() {
- return draggedNode;
- }
-
- protected void setDraggedNode(PNode draggedNode) {
- this.draggedNode = draggedNode;
- }
-
- protected boolean shouldStartDragInteraction(PInputEvent event) {
- if (super.shouldStartDragInteraction(event)) {
- return event.getPickedNode() != event.getTopCamera();
- }
- return false;
- }
-
- protected void startDrag(PInputEvent event) {
- super.startDrag(event);
- draggedNode = event.getPickedNode();
- if (moveToFrontOnPress) {
- draggedNode.moveToFront();
- }
- }
-
- protected void drag(PInputEvent event) {
- super.drag(event);
- PDimension d = event.getDeltaRelativeTo(draggedNode);
- draggedNode.localToParent(d);
- draggedNode.offset(d.getWidth(), d.getHeight());
- }
-
- protected void endDrag(PInputEvent event) {
- super.endDrag(event);
- draggedNode = null;
- }
-
- public boolean getMoveToFrontOnPress() {
- return moveToFrontOnPress;
- }
-
- public void setMoveToFrontOnPress(boolean moveToFrontOnPress) {
- this.moveToFrontOnPress = moveToFrontOnPress;
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("draggedNode=" + draggedNode == null ? "null" : draggedNode.toString());
- if (moveToFrontOnPress) result.append(",moveToFrontOnPress");
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PDragSequenceEventHandler.java b/src/main/java/edu/umd/cs/piccolo/event/PDragSequenceEventHandler.java
deleted file mode 100755
index 9287d79..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PDragSequenceEventHandler.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PDragSequenceEventHandler is designed to support mouse pressed, dragged, and
- * released interaction sequences. Support is also provided for running a continuous
- * activity during the drag sequence.
- *
- * PDragSequenceEventHandler should be subclassed by a concrete event handler
- * that implements a particular interaction. See PPanEventHandler, PZoomEventHandler,
- * and PDragEventHandler for examples.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public abstract class PDragSequenceEventHandler extends PBasicInputEventHandler {
-
- private double minDragStartDistance = 0;
- private transient boolean isDragging = false;
- private transient Point2D mousePressedCanvasPoint;
- private transient PActivity dragActivity;
- private transient PInputEvent dragEvent;
- private transient int sequenceInitiatedButton = MouseEvent.NOBUTTON;
-
- public PDragSequenceEventHandler() {
- }
-
- //****************************************************************
- // Basics
- //****************************************************************
-
- public boolean isDragging() {
- return isDragging;
- }
-
- public void setIsDragging(boolean isDragging) {
- this.isDragging = isDragging;
- }
-
- public double getMinDragStartDistance() {
- return minDragStartDistance;
- }
-
- /**
- * Set the minimum distance that the mouse should be dragged (in screen coords)
- * before a new drag sequence is initiate.
- */
- public void setMinDragStartDistance(double minDistance) {
- minDragStartDistance = minDistance;
- }
-
- /**
- * Return the point in canvas coordinates where the mouse was last
- * pressed.
- */
- public Point2D getMousePressedCanvasPoint() {
- if (mousePressedCanvasPoint == null) {
- mousePressedCanvasPoint = new Point2D.Double();
- }
- return mousePressedCanvasPoint;
- }
-
- //****************************************************************
- // Dragging - Methods to indicate the stages of the drag sequence.
- //****************************************************************
-
- /**
- * Subclasses should override this method to get notified of the start of
- * a new drag sequence. Note that that overriding methods must still
- * call super.startDrag() for correct behavior.
- */
- protected void startDrag(PInputEvent e) {
- dragEvent = e;
- startDragActivity(e);
- setIsDragging(true);
- e.getComponent().setInteracting(true);
- }
-
- /**
- * Subclasses should override this method to get notified of the drag
- * events in a drag sequence. Note that that overriding methods must still
- * call super.startDrag() for correct behavior.
- */
- protected void drag(PInputEvent e) {
- dragEvent = e;
- }
-
- /**
- * Subclasses should override this method to get notified of the end event
- * in a drag sequence. Note that that overriding methods must still
- * call super.startDrag() for correct behavior.
- */
- protected void endDrag(PInputEvent e) {
- stopDragActivity(e);
- dragEvent = null;
- e.getComponent().setInteracting(false);
- setIsDragging(false);
- }
-
- protected boolean shouldStartDragInteraction(PInputEvent e) {
- return getMousePressedCanvasPoint().distance(e.getCanvasPosition()) >= getMinDragStartDistance();
- }
-
- //****************************************************************
- // Drag Activity - Used for scheduling an activity during a drag
- // sequence. For example zooming and auto panning are implemented
- // using this.
- //****************************************************************
-
- protected PActivity getDragActivity() {
- return dragActivity;
- }
-
- protected void startDragActivity(PInputEvent aEvent) {
- dragActivity = new PActivity(-1, PUtil.DEFAULT_ACTIVITY_STEP_RATE);
- dragActivity.setDelegate(new PActivity.PActivityDelegate() {
- public void activityStarted(PActivity activity) {
- dragActivityFirstStep(dragEvent);
- }
- public void activityStepped(PActivity activity) {
- dragActivityStep(dragEvent);
- }
- public void activityFinished(PActivity activity) {
- dragActivityFinalStep(dragEvent);
- }
- });
-
- aEvent.getCamera().getRoot().addActivity(dragActivity);
- }
-
- protected void stopDragActivity(PInputEvent aEvent) {
- dragActivity.terminate();
- dragActivity = null;
- }
-
- /**
- * Override this method to get notified when the drag activity
- * starts stepping.
- */
- protected void dragActivityFirstStep(PInputEvent aEvent) {
- }
-
- /**
- * During a drag sequence an activity is scheduled that runs continuously
- * while the drag sequence is active. This can be used to support some
- * additional behavior that is not driven directly by mouse events. For
- * example PZoomEventHandler uses it for zooming and PPanEventHandler uses
- * it for auto panning.
- */
- protected void dragActivityStep(PInputEvent aEvent) {
- }
-
- /**
- * Override this method to get notified when the drag activity
- * stops stepping.
- */
- protected void dragActivityFinalStep(PInputEvent aEvent) {
- }
-
- //****************************************************************
- // Events - subclasses should not override these methods, instead
- // override the appropriate drag method.
- //****************************************************************
-
- public void mousePressed(PInputEvent e) {
- super.mousePressed(e);
-
- if (sequenceInitiatedButton == MouseEvent.NOBUTTON) {
- sequenceInitiatedButton = e.getButton();
- } else {
- return;
- }
-
- getMousePressedCanvasPoint().setLocation(e.getCanvasPosition());
- if (!isDragging()) {
- if (shouldStartDragInteraction(e)) {
- startDrag(e);
- }
- }
- }
-
- public void mouseDragged(PInputEvent e) {
- super.mouseDragged(e);
-
- if (sequenceInitiatedButton != MouseEvent.NOBUTTON) {
- if (!isDragging()) {
- if (shouldStartDragInteraction(e)) {
- startDrag(e);
- }
- return;
- }
- drag(e);
- }
- }
-
- public void mouseReleased(PInputEvent e) {
- super.mouseReleased(e);
- if (sequenceInitiatedButton == e.getButton()) {
- if (isDragging()) endDrag(e);
- sequenceInitiatedButton = MouseEvent.NOBUTTON;
- }
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("minDragStartDistance=" + minDragStartDistance);
- result.append(",mousePressedCanvasPoint=" + (mousePressedCanvasPoint == null ? "null" : mousePressedCanvasPoint.toString()));
- result.append(",sequenceInitiatedButton=" + sequenceInitiatedButton);
- if (isDragging) result.append(",dragging");
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java b/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
deleted file mode 100755
index ed69c0e..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.Cursor;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-import java.awt.geom.Point2D;
-
-import javax.swing.SwingUtilities;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PComponent;
-import edu.umd.cs.piccolo.PInputManager;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PInputEvent is used to notify PInputEventListeners of keyboard and mouse
- * input. It has methods for normal event properties such as event modifier keys
- * and event canvas location.
- *
- * In addition is has methods to get the mouse position and delta in a variety
- * of coordinate systems.
- *
- * Last of all it provides access to the dispatch manager that can be queried
- * to find the current mouse over, mouse focus, and keyboard focus.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PInputEvent {
-
- private InputEvent inputEvent;
- private PPickPath pickPath;
- private PInputManager inputManager;
- private boolean handled;
- /**
- * Modified by miura
- * @param s
- */
- private String actionCommand;
-
- public PInputEvent(PInputManager inputManager, InputEvent event) {
- super();
- inputEvent = event;
- this.inputManager = inputManager;
- }
- /**
- * Modified by miura
- * @param s
- */
- public void setActionCommand(String s){
- actionCommand = s;
- }
- /**
- * Modified by miura
- * @param s
- */
- public String getActionCommand(){
- return actionCommand;
- }
-
- public void pushCursor(Cursor cursor) {
- PComponent component = getTopCamera().getComponent();
- component.pushCursor(cursor);
- }
-
- public void popCursor() {
- PComponent component = getTopCamera().getComponent();
- component.popCursor();
- }
-
- //****************************************************************
- // Accessing Picked Objects - Methods to access the objects associated
- // with this event.
- //
- // Cameras can view layers that have
- // other cameras on them, so events may be arriving through a stack
- // of many cameras. The getCamera() method returns the bottommost
- // camera on that stack. The getTopCamera method returns the topmost
- // camera on that stack, this is also the camera through which the
- // event originated.
- //****************************************************************
-
- /**
- * Return the bottom most camera that is currently painting. If you are
- * using internal cameras this may be different then what is returned by
- * getTopCamera.
- */
- public PCamera getCamera() {
- return getPath().getBottomCamera();
- }
-
- /**
- * Return the topmost camera this is painting. This is the camera assocaited
- * with the PCanvas that requested the current repaint.
- */
- public PCamera getTopCamera() {
- return getPath().getTopCamera();
- }
-
- /**
- * Get the canvas associated with the top camera. This is the canvas where the
- * originating swing event came from.
- */
- public PComponent getComponent() {
- return getTopCamera().getComponent();
- }
-
- /**
- * Return the input manager that dispatched this event. You can use this input
- * manager to find the current mouse focus, mouse over, and key focus nodes.
- * You can also set a new key focus node.
- */
- public PInputManager getInputManager() {
- return inputManager;
- }
-
- /**
- * Return the PPickPath associated with this input event.
- */
- public PPickPath getPath() {
- return pickPath;
- }
-
- public void setPath(PPickPath path) {
- pickPath = path;
- }
-
- /**
- * Return the bottom node on the current pickpath, that is the picked node
- * furthest from the root node.
- */
- public PNode getPickedNode() {
- return pickPath.getPickedNode();
- }
-
- //****************************************************************
- // Basics
- //****************************************************************
-
- public int getKeyCode() {
- if (isKeyEvent()) {
- KeyEvent e = (KeyEvent) inputEvent;
- return e.getKeyCode();
- }
- throw new IllegalStateException("Can't get keycode from mouse event");
- }
-
- public char getKeyChar() {
- if (isKeyEvent()) {
- KeyEvent e = (KeyEvent) inputEvent;
- return e.getKeyChar();
- }
- throw new IllegalStateException("Can't get keychar from mouse event");
- }
-
- public int getKeyLocation() {
- if (isKeyEvent()) {
- KeyEvent e = (KeyEvent) inputEvent;
- return e.getKeyLocation();
- }
- throw new IllegalStateException("Can't get keylocation from mouse event");
- }
-
- public boolean isActionKey() {
- if (isKeyEvent()) {
- KeyEvent e = (KeyEvent) inputEvent;
- return e.isActionKey();
- }
- throw new IllegalStateException("Can't get isActionKey from mouse event");
- }
-
- public int getModifiers() {
- if (!isFocusEvent()) {
- return inputEvent.getModifiers();
- }
- throw new IllegalStateException("Can't get modifiers from focus event");
- }
-
- public int getModifiersEx() {
- if (!isFocusEvent()) {
- return inputEvent.getModifiersEx();
- }
- throw new IllegalStateException("Can't get modifiers ex from focus event");
- }
-
- public int getClickCount() {
- if (isMouseEvent()) {
- return ((MouseEvent)inputEvent).getClickCount();
- }
- throw new IllegalStateException("Can't get clickcount from key event");
- }
-
- public long getWhen() {
- if (!isFocusEvent()) {
- return inputEvent.getWhen();
- }
- throw new IllegalStateException("Can't get when from focus event");
- }
-
- public boolean isAltDown() {
- if (!isFocusEvent()) {
- return inputEvent.isAltDown();
- }
- throw new IllegalStateException("Can't get altdown from focus event");
- }
-
- public boolean isControlDown() {
- if (!isFocusEvent()) {
- return inputEvent.isControlDown();
- }
- throw new IllegalStateException("Can't get controldown from focus event");
- }
-
- public boolean isMetaDown() {
- if (!isFocusEvent()) {
- return inputEvent.isMetaDown();
- }
- throw new IllegalStateException("Can't get modifiers from focus event");
- }
-
- public boolean isShiftDown() {
- if (!isFocusEvent()) {
- return inputEvent.isShiftDown();
- }
- throw new IllegalStateException("Can't get shiftdown from focus event");
- }
-
- public boolean isLeftMouseButton() {
- if (isMouseEvent()) {
- return SwingUtilities.isLeftMouseButton((MouseEvent)getSourceSwingEvent());
- }
- throw new IllegalStateException("Can't get isLeftMouseButton from focus event");
- }
-
- public boolean isMiddleMouseButton() {
- if (isMouseEvent()) {
- return SwingUtilities.isMiddleMouseButton((MouseEvent)getSourceSwingEvent());
- }
- throw new IllegalStateException("Can't get isMiddleMouseButton from focus event");
- }
-
- public boolean isRightMouseButton() {
- if (isMouseEvent()) {
- return SwingUtilities.isRightMouseButton((MouseEvent)getSourceSwingEvent());
- }
- throw new IllegalStateException("Can't get isRightMouseButton from focus event");
- }
-
- /**
- * Return true if another event handler has already handled this event. Event handlers should use
- * this as a hint before handling the event themselves and possibly reject events that have
- * already been handled.
- */
- public boolean isHandled() {
- return handled;
- }
-
- /**
- * Set that this event has been handled by an event handler. This is a relaxed for of consuming events.
- * The event will continue to get dispatched to event handlers even after it is marked as handled, but
- * other event handlers that might conflict are expected to ignore events that have already been handled.
- */
- public void setHandled(boolean handled) {
- this.handled = handled;
- }
-
- public int getButton() {
- if (isMouseEvent()) {
- return ((MouseEvent)inputEvent).getButton();
- }
- throw new IllegalStateException("Can't get button from key event");
- }
-
- public int getWheelRotation() {
- if (isMouseWheelEvent()) {
- return ((MouseWheelEvent) inputEvent).getWheelRotation();
- }
- throw new IllegalStateException("Can't get wheel rotation from non-wheel event");
- }
-
- public InputEvent getSourceSwingEvent() {
- return inputEvent;
- }
-
- //****************************************************************
- // Classification - Methods to distinguish between mouse and key
- // events.
- //****************************************************************
-
- public boolean isKeyEvent() {
- return inputEvent instanceof KeyEvent;
- }
-
- public boolean isMouseEvent() {
- return inputEvent instanceof MouseEvent;
- }
-
- public boolean isMouseWheelEvent() {
- return inputEvent instanceof MouseWheelEvent;
- }
-
- public boolean isFocusEvent() {
- return inputEvent == null;
- }
-
- public boolean isMouseEnteredOrMouseExited() {
- if (isMouseEvent()) {
- return inputEvent.getID() == MouseEvent.MOUSE_ENTERED ||
- inputEvent.getID() == MouseEvent.MOUSE_EXITED;
- }
- return false;
- }
-
- /**
- * Returns whether or not this event is a popup menu trigger event for the
- * platform. Must not be called if this event isn't a mouse event.
- *
Note : Popup menus are triggered differently on different
- * systems. Therefore, isPopupTrigger
should be checked in both
- * mousePressed
and mouseReleased
for proper
- * cross-platform functionality.
- *
- * @return boolean, true if this event triggers a popup menu for this
- * platform
- * @throws IllegalStateException if this event is not a mouse event
- */
- public boolean isPopupTrigger() {
- if (isMouseEvent()) {
- return ((MouseEvent) inputEvent).isPopupTrigger();
- }
- throw new IllegalStateException("Can't get clickcount from key event");
- }
-
- //****************************************************************
- // Coordinate Systems - Methods for getting mouse location data
- // These methods are only designed for use with PInputEvents that
- // return true to the isMouseEvent method.
- //****************************************************************
-
- /**
- * Return the mouse position in PCanvas coordinates.
- */
- public Point2D getCanvasPosition() {
- return (Point2D) inputManager.getCurrentCanvasPosition().clone();
- }
-
- /**
- * Return the delta between the last and current mouse
- * position in PCanvas coordinates.
- */
- public PDimension getCanvasDelta() {
- Point2D last = inputManager.getLastCanvasPosition();
- Point2D current = inputManager.getCurrentCanvasPosition();
- return new PDimension(current.getX() - last.getX(), current.getY() - last.getY());
- }
-
- /**
- * Return the mouse position relative to a given node on the pick path.
- */
- public Point2D getPositionRelativeTo(PNode nodeOnPath) {
- Point2D r = getCanvasPosition();
- return pickPath.canvasToLocal(r, nodeOnPath);
- }
-
- /**
- * Return the delta between the last and current mouse positions
- * relative to a given node on the pick path.
- */
- public PDimension getDeltaRelativeTo(PNode nodeOnPath) {
- PDimension r = getCanvasDelta();
- return (PDimension) pickPath.canvasToLocal(r, nodeOnPath);
- }
-
- /**
- * Return the mouse position transformed through the view transform of
- * the bottom camera.
- */
- public Point2D getPosition() {
- Point2D r = getCanvasPosition();
- pickPath.canvasToLocal(r, getCamera());
- return getCamera().localToView(r);
- }
-
- /**
- * Return the delta between the last and current mouse positions
- * transformed through the view transform of the bottom camera.
- */
- public PDimension getDelta() {
- PDimension r = getCanvasDelta();
- pickPath.canvasToLocal(r, getCamera());
- return (PDimension) getCamera().localToView(r);
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representation of this object for debugging purposes.
- */
- public String toString() {
- StringBuffer result = new StringBuffer();
-
- result.append(super.toString().replaceAll(".*\\.", ""));
- result.append('[');
- if (handled) {
- result.append("handled");
- }
- result.append(']');
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java b/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java
deleted file mode 100755
index ee627c0..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.event.FocusEvent;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-
-/**
- * PInputEventFilter is a class that filters input events based on the
- * events modifiers and type. Any PBasicInputEventHandler that is associated
- * with an event filter will only receive events that pass through the filter.
- *
- * To be accepted events must contain all the modifiers listed in the andMask,
- * at least one of the modifiers listed in the orMask, and none of the
- * modifiers listed in the notMask. The event filter also lets you specify specific
- * event types (mousePressed, released, ...) to accept or reject.
- *
- * If the event filter is set to consume, then it will call consume on any event
- * that it successfully accepts.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PInputEventFilter {
-
- public static int ALL_MODIFIERS_MASK = InputEvent.BUTTON1_MASK |
- InputEvent.BUTTON2_MASK |
- InputEvent.BUTTON3_MASK |
- InputEvent.SHIFT_MASK |
- InputEvent.CTRL_MASK |
- InputEvent.ALT_MASK |
- InputEvent.ALT_GRAPH_MASK |
- InputEvent.META_MASK;
-
- private int andMask;
- private int orMask;
- private int notMask;
- private short clickCount = -1;
-
- private boolean marksAcceptedEventsAsHandled = false;
-
- private boolean acceptsAlreadyHandledEvents = false;
- private boolean acceptsKeyPressed = true;
- private boolean acceptsKeyReleased = true;
- private boolean acceptsKeyTyped = true;
-
- private boolean acceptsMouseClicked = true;
- private boolean acceptsMouseDragged = true;
- private boolean acceptsMouseEntered = true;
- private boolean acceptsMouseExited = true;
- private boolean acceptsMouseMoved = true;
- private boolean acceptsMousePressed = true;
- private boolean acceptsMouseReleased = true;
- private boolean acceptsMouseWheelRotated = true;
- private boolean acceptsFocusEvents = true;
-
- public PInputEventFilter() {
- acceptEverything();
- }
-
- public PInputEventFilter(int aAndMask) {
- this();
- andMask = aAndMask;
- }
-
- public PInputEventFilter(int aAndMask, int aNotMask) {
- this(aAndMask);
- notMask = aNotMask;
- }
-
- public boolean acceptsEvent(PInputEvent aEvent, int type) {
- boolean aResult = false;
- int modifiers = 0;
-
- if (!aEvent.isFocusEvent()) {
- modifiers = aEvent.getModifiers();
- }
-
- if ((!aEvent.isHandled() || acceptsAlreadyHandledEvents) &&
- (modifiers == 0 || // if no modifiers then ignore modifier constraints, ELSE
- (modifiers & andMask) == andMask && // must have all modifiers from the AND mask and
- (modifiers & orMask) != 0 && // must have at least one modifier from the OR mask and
- (modifiers & notMask) == 0)) { // can't have any modifiers from the NOT mask
-
- if (aEvent.isMouseEvent() && clickCount != -1 && clickCount != aEvent.getClickCount()) {
- aResult = false;
- } else {
- switch (type) {
- case KeyEvent.KEY_PRESSED:
- aResult = getAcceptsKeyPressed();
- break;
-
- case KeyEvent.KEY_RELEASED:
- aResult = getAcceptsKeyReleased();
- break;
-
- case KeyEvent.KEY_TYPED:
- aResult = getAcceptsKeyTyped();
- break;
-
- case MouseEvent.MOUSE_CLICKED:
- aResult = getAcceptsMouseClicked();
- break;
-
- case MouseEvent.MOUSE_DRAGGED:
- aResult = getAcceptsMouseDragged();
- break;
-
- case MouseEvent.MOUSE_ENTERED:
- aResult = getAcceptsMouseEntered();
- break;
-
- case MouseEvent.MOUSE_EXITED:
- aResult = getAcceptsMouseExited();
- break;
-
- case MouseEvent.MOUSE_MOVED:
- aResult = getAcceptsMouseMoved();
- break;
-
- case MouseEvent.MOUSE_PRESSED:
- aResult = getAcceptsMousePressed();
- break;
-
- case MouseEvent.MOUSE_RELEASED:
- aResult = getAcceptsMouseReleased();
- break;
-
- case MouseWheelEvent.WHEEL_UNIT_SCROLL:
- case MouseWheelEvent.WHEEL_BLOCK_SCROLL:
- aResult = getAcceptsMouseWheelRotated();
- break;
-
- case FocusEvent.FOCUS_GAINED:
- case FocusEvent.FOCUS_LOST:
- aResult = getAcceptsFocusEvents();
- break;
-
- default:
- throw new RuntimeException("PInputEvent with bad ID");
- }
- }
- }
-
- if (aResult && getMarksAcceptedEventsAsHandled()) {
- aEvent.setHandled(true);
- }
-
- return aResult;
- }
-
- public void acceptAllClickCounts() {
- clickCount = -1;
- }
-
- public void acceptAllEventTypes() {
- acceptsKeyPressed = true;
- acceptsKeyReleased = true;
- acceptsKeyTyped = true;
- acceptsMouseClicked = true;
- acceptsMouseDragged = true;
- acceptsMouseEntered = true;
- acceptsMouseExited = true;
- acceptsMouseMoved = true;
- acceptsMousePressed = true;
- acceptsMouseReleased = true;
- acceptsMouseWheelRotated = true;
- acceptsFocusEvents = true;
- }
-
- public void acceptEverything() {
- acceptAllEventTypes();
- setAndMask(0);
- setOrMask(ALL_MODIFIERS_MASK);
- setNotMask(0);
- acceptAllClickCounts();
- }
-
- public boolean getAcceptsKeyPressed() {
- return acceptsKeyPressed;
- }
-
- public boolean getAcceptsKeyReleased() {
- return acceptsKeyReleased;
- }
-
- public boolean getAcceptsKeyTyped() {
- return acceptsKeyTyped;
- }
-
- public boolean getAcceptsMouseClicked() {
- return acceptsMouseClicked;
- }
-
- public boolean getAcceptsMouseDragged() {
- return acceptsMouseDragged;
- }
-
- public boolean getAcceptsMouseEntered() {
- return acceptsMouseEntered;
- }
-
- public boolean getAcceptsMouseExited() {
- return acceptsMouseExited;
- }
-
- public boolean getAcceptsMouseMoved() {
- return acceptsMouseMoved;
- }
-
- public boolean getAcceptsMousePressed() {
- return acceptsMousePressed;
- }
-
- public boolean getAcceptsMouseReleased() {
- return acceptsMouseReleased;
- }
-
- public boolean getAcceptsMouseWheelRotated() {
- return acceptsMouseWheelRotated;
- }
-
- public boolean getAcceptsFocusEvents() {
- return acceptsFocusEvents;
- }
-
- public boolean getAcceptsAlreadyHandledEvents() {
- return acceptsAlreadyHandledEvents;
- }
-
- public boolean getMarksAcceptedEventsAsHandled() {
- return marksAcceptedEventsAsHandled;
- }
-
- public void rejectAllClickCounts() {
- clickCount = Short.MAX_VALUE;
- }
-
- public void rejectAllEventTypes() {
- acceptsKeyPressed = false;
- acceptsKeyReleased = false;
- acceptsKeyTyped = false;
- acceptsMouseClicked = false;
- acceptsMouseDragged = false;
- acceptsMouseEntered = false;
- acceptsMouseExited = false;
- acceptsMouseMoved = false;
- acceptsMousePressed = false;
- acceptsMouseReleased = false;
- acceptsMouseWheelRotated = false;
- acceptsFocusEvents = false;
- }
-
- public void setAcceptClickCount(short aClickCount) {
- clickCount = aClickCount;
- }
-
- public void setAcceptsKeyPressed(boolean aBoolean) {
- acceptsKeyPressed = aBoolean;
- }
-
- public void setAcceptsKeyReleased(boolean aBoolean) {
- acceptsKeyReleased = aBoolean;
- }
-
- public void setAcceptsKeyTyped(boolean aBoolean) {
- acceptsKeyTyped = aBoolean;
- }
-
- public void setAcceptsMouseClicked(boolean aBoolean) {
- acceptsMouseClicked = aBoolean;
- }
-
- public void setAcceptsMouseDragged(boolean aBoolean) {
- acceptsMouseDragged = aBoolean;
- }
-
- public void setAcceptsMouseEntered(boolean aBoolean) {
- acceptsMouseEntered = aBoolean;
- }
-
- public void setAcceptsMouseExited(boolean aBoolean) {
- acceptsMouseExited = aBoolean;
- }
-
- public void setAcceptsMouseMoved(boolean aBoolean) {
- acceptsMouseMoved = aBoolean;
- }
-
- public void setAcceptsMousePressed(boolean aBoolean) {
- acceptsMousePressed = aBoolean;
- }
-
- public void setAcceptsMouseReleased(boolean aBoolean) {
- acceptsMouseReleased = aBoolean;
- }
-
- public void setAcceptsMouseWheelRotated(boolean aBoolean) {
- acceptsMouseWheelRotated = aBoolean;
- }
-
- public void setAcceptsFocusEvents(boolean aBoolean) {
- acceptsFocusEvents = aBoolean;
- }
-
- public void setAndMask(int aAndMask) {
- andMask = aAndMask;
- }
-
- public void setAcceptsAlreadyHandledEvents(boolean aBoolean) {
- acceptsAlreadyHandledEvents = aBoolean;
- }
-
- public void setMarksAcceptedEventsAsHandled(boolean aBoolean) {
- marksAcceptedEventsAsHandled = aBoolean;
- }
-
- public void setNotMask(int aNotMask) {
- notMask = aNotMask;
- }
-
- public void setOrMask(int aOrMask) {
- orMask = aOrMask;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PInputEventListener.java b/src/main/java/edu/umd/cs/piccolo/event/PInputEventListener.java
deleted file mode 100755
index 26383cf..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PInputEventListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.util.EventListener;
-
-/**
- * PInputEventListener defines the most basic interface for objects that
- * want to listen to PNodes for input events. This interface is very simple so that
- * others may extend Piccolo's input management system. If you are just using Piccolo's
- * default input management system then you will most often use PBasicInputEventHandler
- * to register with a node for input events.
- *
- * @see PBasicInputEventHandler
- * @version 1.0
- * @author Jesse Grosjean
- */
-public interface PInputEventListener extends EventListener {
-
- public void processEvent(PInputEvent aEvent, int type);
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java b/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
deleted file mode 100755
index aa4d7c1..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.Rectangle;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-
-/**
- * PPanEventHandler provides event handlers for basic panning
- * of the canvas view with the left mouse. The interaction is that
- * clicking and dragging the mouse translates the view so that
- * the point on the surface stays under the mouse.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PPanEventHandler extends PDragSequenceEventHandler {
-
- private boolean autopan;
- private double minAutopanSpeed = 250;
- private double maxAutopanSpeed = 750;
-
- public PPanEventHandler() {
- super();
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- setAutopan(true);
- }
-
- protected void drag(PInputEvent e) {
- super.drag(e);
- pan(e);
- }
-
- protected void pan(PInputEvent e) {
- PCamera c = e.getCamera();
- Point2D l = e.getPosition();
-
- if (c.getViewBounds().contains(l)) {
- PDimension d = e.getDelta();
- c.translateView(d.getWidth(), d.getHeight());
- }
- }
-
- //****************************************************************
- // Auto Pan
- //****************************************************************
-
- public void setAutopan(boolean autopan) {
- this.autopan = autopan;
- }
-
- public boolean getAutopan() {
- return autopan;
- }
-
- /**
- * Set the minAutoPan speed in pixels per second.
- * @param minAutopanSpeed
- */
- public void setMinAutopanSpeed(double minAutopanSpeed) {
- this.minAutopanSpeed = minAutopanSpeed;
- }
-
- /**
- * Set the maxAutoPan speed in pixes per second.
- * @param maxAutopanSpeed
- */
- public void setMaxAutopanSpeed(double maxAutopanSpeed) {
- this.maxAutopanSpeed = maxAutopanSpeed;
- }
-
- /**
- * Do auto panning even when the mouse is not moving.
- */
- protected void dragActivityStep(PInputEvent aEvent) {
- if (!autopan) return;
-
- PCamera c = aEvent.getCamera();
- PBounds b = c.getBoundsReference();
- Point2D l = aEvent.getPositionRelativeTo(c);
- int outcode = b.outcode(l);
- PDimension delta = new PDimension();
-
- if ((outcode & Rectangle.OUT_TOP) != 0) {
- delta.height = validatePanningSpeed(-1.0 - (0.5 * Math.abs(l.getY() - b.getY())));
- } else if ((outcode & Rectangle.OUT_BOTTOM) != 0) {
- delta.height = validatePanningSpeed(1.0 + (0.5 * Math.abs(l.getY() - (b.getY() + b.getHeight()))));
- }
-
- if ((outcode & Rectangle.OUT_RIGHT) != 0) {
- delta.width = validatePanningSpeed(1.0 + (0.5 * Math.abs(l.getX() - (b.getX() + b.getWidth()))));
- } else if ((outcode & Rectangle.OUT_LEFT) != 0) {
- delta.width = validatePanningSpeed(-1.0 - (0.5 * Math.abs(l.getX() - b.getX())));
- }
-
- c.localToView(delta);
-
- if (delta.width != 0 || delta.height != 0) {
- c.translateView(delta.width, delta.height);
- }
- }
-
- protected double validatePanningSpeed(double delta) {
- double minDelta = minAutopanSpeed / (1000 / getDragActivity().getStepRate());
- double maxDelta = maxAutopanSpeed / (1000 / getDragActivity().getStepRate());
-
- boolean deltaNegative = delta < 0;
- delta = Math.abs(delta);
- if (delta < minDelta) delta = minDelta;
- if (delta > maxDelta) delta = maxDelta;
- if (deltaNegative) delta = -delta;
- return delta;
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("minAutopanSpeed=" + minAutopanSpeed);
- result.append(",maxAutopanSpeed=" + maxAutopanSpeed);
- if (autopan) result.append(",autopan");
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/PZoomEventHandler.java b/src/main/java/edu/umd/cs/piccolo/event/PZoomEventHandler.java
deleted file mode 100755
index 14aab24..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/PZoomEventHandler.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.event;
-
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCamera;
-
-/**
- * ZoomEventhandler provides event handlers for basic zooming
- * of the canvas view with the right (third) button. The interaction is that
- * the initial mouse press defines the zoom anchor point, and then
- * moving the mouse to the right zooms with a speed proportional
- * to the amount the mouse is moved to the right of the anchor point.
- * Similarly, if the mouse is moved to the left, the the view is
- * zoomed out.
- *
- * On a Mac with its single mouse button one may wish to change the
- * standard right mouse button zooming behavior. This can be easily done
- * with the PInputEventFilter. For example to zoom with button one and shift you
- * would do this:
- *
- *
- *
- * zoomEventHandler.getEventFilter().setAndMask(InputEvent.BUTTON1_MASK |
- * InputEvent.SHIFT_MASK);
- *
- *
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PZoomEventHandler extends PDragSequenceEventHandler {
-
- private double minScale = 0;
- private double maxScale = Double.MAX_VALUE;
- private Point2D viewZoomPoint;
-
- /**
- * Creates a new zoom handler.
- */
- public PZoomEventHandler() {
- super();
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON3_MASK));
- }
-
- //****************************************************************
- // Zooming
- //****************************************************************
-
- /**
- * Returns the minimum view magnification factor that this event handler is bound by.
- * The default is 0.
- * @return the minimum camera view scale
- */
- public double getMinScale() {
- return minScale;
- }
-
- /**
- * Sets the minimum view magnification factor that this event handler is bound by.
- * The camera is left at its current scale even if minScale
is larger than
- * the current scale.
- * @param minScale the minimum scale, must not be negative.
- */
- public void setMinScale(double minScale) {
- this.minScale = minScale;
- }
-
- /**
- * Returns the maximum view magnification factor that this event handler is bound by.
- * The default is Double.MAX_VALUE.
- * @return the maximum camera view scale
- */
- public double getMaxScale() {
- return maxScale;
- }
-
- /**
- * Sets the maximum view magnification factor that this event handler is bound by.
- * The camera is left at its current scale even if maxScale
is smaller than
- * the current scale. Use Double.MAX_VALUE to specify the largest possible scale.
- * @param maxScale the maximum scale, must not be negative.
- */
- public void setMaxScale(double maxScale) {
- this.maxScale = maxScale;
- }
-
- protected void dragActivityFirstStep(PInputEvent aEvent) {
- viewZoomPoint = aEvent.getPosition();
- super.dragActivityFirstStep(aEvent);
- }
-
- protected void dragActivityStep(PInputEvent aEvent) {
- PCamera camera = aEvent.getCamera();
- double dx = aEvent.getCanvasPosition().getX() - getMousePressedCanvasPoint().getX();
- double scaleDelta = (1.0 + (0.001 * dx));
-
- double currentScale = camera.getViewScale();
- double newScale = currentScale * scaleDelta;
-
- if (newScale < minScale) {
- scaleDelta = minScale / currentScale;
- }
- if ((maxScale > 0) && (newScale > maxScale)) {
- scaleDelta = maxScale / currentScale;
- }
-
- camera.scaleViewAboutPoint(scaleDelta, viewZoomPoint.getX(), viewZoomPoint.getY());
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("minScale=" + minScale);
- result.append(",maxScale=" + maxScale);
- result.append(",viewZoomPoint=" + (viewZoomPoint == null ? "null" : viewZoomPoint.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/event/package.html b/src/main/java/edu/umd/cs/piccolo/event/package.html
deleted file mode 100755
index 9fa7ad1..0000000
--- a/src/main/java/edu/umd/cs/piccolo/event/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This package supports Piccolo event handlers. It contains event
-listeners and adapters for user-driven input events. It also contains basic event handlers
-for common typical interaction such as zooming and panning.
-
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java b/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
deleted file mode 100755
index 6fcbbc2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/ActivityExample.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how create and schedule activities.
- */
-public class ActivityExample extends PFrame {
-
- public ActivityExample() {
- this(null);
- }
-
- public ActivityExample(PCanvas aCanvas) {
- super("ActivityExample", false, aCanvas);
- }
-
- public void initialize() {
- long currentTime = System.currentTimeMillis();
-
- // Create a new node that we will apply different activities to, and
- // place that node at location 200, 200.
- final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
- aNode.setOffset(200, 200);
-
- // Create a new custom "flash" activity. This activity will start running in
- // five seconds, and while it runs it will flash aNode's paint between
- // red and green every half second.
- PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- if (fRed) {
- aNode.setPaint(Color.red);
- } else {
- aNode.setPaint(Color.green);
- }
-
- fRed = !fRed;
- }
- };
-
- // An activity will not run unless it is scheduled with the root. Once
- // it has been scheduled it will be given a chance to run during the next
- // PRoot.processInputs() call.
- getCanvas().getRoot().addActivity(flash);
-
- // Use the PNode animate methods to create three activities that animate
- // the node's position. Since our node already descends from the root node the
- // animate methods will automatically schedule these activities for us.
- PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
- PActivity a4 = aNode.animateToTransparency(0.25f, 3000);
-
- // the animate activities will start immediately (in the next call to PRoot.processInputs)
- // by default. Here we set their start times (in PRoot global time) so that they start
- // when the previous one has finished.
- a1.setStartTime(currentTime);
-
- a2.startAfter(a1);
- a3.startAfter(a2);
- a4.startAfter(a3);
-
- // or the previous three lines could be replaced with these lines for the same effect.
- //a2.setStartTime(currentTime + 5000);
- //a3.setStartTime(currentTime + 10000);
- //a4.setStartTime(currentTime + 15000);
- }
-
- public static void main(String[] args) {
- new ActivityExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java b/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
deleted file mode 100755
index 7524a94..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/AngleNodeExample.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Stroke;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PHandle;
-import edu.umd.cs.piccolox.util.PLocator;
-
-/**
- * This shows how to create a simple node that has two handles and can be used
- * for specifying angles. The nodes UI desing isn't very exciting, but the
- * example shows one way to create a custom node with custom handles.
- */
-public class AngleNodeExample extends PFrame {
-
- public AngleNodeExample() {
- this(null);
- }
-
- public AngleNodeExample(PCanvas aCanvas) {
- super("AngleNodeExample", false, aCanvas);
- }
-
- public void initialize() {
- PCanvas c = getCanvas();
- PLayer l = c.getLayer();
- l.addChild(new AngleNode());
- }
-
- public static void main(String[] args) {
- new AngleNodeExample();
- }
-
- // the angle node class
- public static class AngleNode extends PNode {
- protected Point2D.Double pointOne;
- protected Point2D.Double pointTwo;
- protected Stroke stroke;
-
- public AngleNode() {
- pointOne = new Point2D.Double(100, 0);
- pointTwo = new Point2D.Double(0, 100);
- stroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
- setPaint(Color.BLACK);
- updateBounds();
- addHandles();
- }
-
- public void addHandles() {
- // point one
- PLocator l = new PLocator() {
- public double locateX() { return pointOne.getX(); }
- public double locateY() { return pointOne.getY(); }
- };
- PHandle h = new PHandle(l) {
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointOne.setLocation(pointOne.getX() + aLocalDimension.getWidth(),
- pointOne.getY() + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
-
- // point two
- l = new PLocator() {
- public double locateX() { return pointTwo.getX(); }
- public double locateY() { return pointTwo.getY(); }
- };
- h = new PHandle(l) {
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- pointTwo.setLocation(pointTwo.getX() + aLocalDimension.getWidth(),
- pointTwo.getY() + aLocalDimension.getHeight());
- updateBounds();
- relocateHandle();
- }
- };
- addChild(h);
- }
-
- protected void paint(PPaintContext paintContext) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setStroke(stroke);
- g2.setPaint(getPaint());
- g2.draw(getAnglePath());
- }
-
- protected void updateBounds() {
- GeneralPath p = getAnglePath();
- Rectangle2D b = stroke.createStrokedShape(p).getBounds2D();
- super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
- }
-
- public GeneralPath getAnglePath() {
- GeneralPath p = new GeneralPath();
- p.moveTo((float)pointOne.getX(), (float)pointOne.getY());
- p.lineTo(0, 0);
- p.lineTo((float)pointTwo.getX(), (float)pointTwo.getY());
- return p;
- }
-
- public boolean setBounds(double x, double y, double width, double height) {
- return false; // bounds can be set externally
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java b/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
deleted file mode 100755
index bc54c08..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/BirdsEyeViewExample.java
+++ /dev/null
@@ -1,432 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.JDialog;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PImage;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.nodes.P3DRect;
-
-/**
- * This example, contributed by Rowan Christmas, shows how to
- * create a birds-eye view window.
- */
-public class BirdsEyeViewExample extends PFrame {
-
- boolean fIsPressed = false;
-
- public BirdsEyeViewExample() {
- this(null);
- }
-
- public BirdsEyeViewExample(PCanvas aCanvas) {
- super("BirdsEyeViewExample", false, aCanvas);
- }
-
- public void initialize() {
-
- nodeDemo();
- createNodeUsingExistingClasses();
- subclassExistingClasses();
- composeOtherNodes();
- createCustomNode();
-
- // Last of all lets remove the default pan event handler, and add a
- // drag event handler instead. This way you will be able to drag the
- // nodes around with the mouse.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
-
- // this will create the actual BirdsEyeView and put it in a JDialog
- BirdsEyeView bev = new BirdsEyeView();
- bev.connect(getCanvas(), new PLayer[]{getCanvas().getLayer()});
- JDialog bird = new JDialog();
- bird.getContentPane().add(bev);
- bird.pack();
- bird.setSize(150, 150);
- bird.setVisible(true);
-
- }
-
- // This method demonstrates the kinds of things that can be done with any
- // node.
- public void nodeDemo() {
- PLayer layer = getCanvas().getLayer();
- PNode aNode = PPath.createRectangle(0, 0, 100, 80);
-
- // A node needs to be a descendent of the root to be displayed on the
- // screen.
- layer.addChild(aNode);
-
- // The default color for a node is blue, but you can change that with
- // the setPaint method.
- aNode.setPaint(Color.red);
-
- // A node can have children nodes added to it.
- aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
-
- // The base bounds of a node is easy to change. Note that changing the
- // base
- // bounds of a node will not change it's children.
- aNode.setBounds(-10, -10, 200, 110);
-
- // Each node has a transform that can be used to transform the node, and
- // all its children on the screen.
- aNode.translate(100, 100);
- aNode.scale(1.5);
- aNode.rotate(45);
-
- // The transparency of any node can be set, this transparency will be
- // applied to any of the nodes children as well.
- aNode.setTransparency(0.75f);
-
- // Its easy to copy nodes.
- PNode aCopy = (PNode) aNode.clone();
-
- // Make is so that the copies children are not pickable. For this
- // example
- // that means you will not be able to grab the child and remove it from
- // its parent.
- aNode.setChildrenPickable(false);
-
- // Change the look of the copy
- aNode.setPaint(Color.GREEN);
- aNode.setTransparency(1.0f);
-
- // Let's add the copy to the root, and translate it so that it does not
- // cover the original node.
- layer.addChild(aCopy);
- aCopy.setOffset(0, 0);
- aCopy.rotate(-45);
- }
-
- // So far we have just been using PNode, but of course PNode has many
- // subclasses that you can try out to.
- public void createNodeUsingExistingClasses() {
- PLayer layer = getCanvas().getLayer();
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
-
- // Here we create an image node that displays a thumbnail
- // image of the root node. Note that you can easily get a thumbnail
- // of any node by using PNode.toImage().
- layer.addChild(new PImage(layer.toImage(300, 300, Color.YELLOW)));
- }
-
- // Another way to create nodes is to customize other nodes that already
- // exist. Here we create an ellipse, except when you press the mouse on
- // this ellipse it turns into a square, when you release the mouse it
- // goes back to being an ellipse.
- public void subclassExistingClasses() {
- final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
-
- public void paint(PPaintContext aPaintContext) {
- if (fIsPressed) {
- // if mouse is pressed draw self as a square.
- Graphics2D g2 = aPaintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- // if mouse is not pressed draw self normally.
- super.paint(aPaintContext);
- }
- }
- };
-
- n.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = true;
- n.invalidatePaint(); // this tells the framework that the node
- // needs to be redisplayed.
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = false;
- n.invalidatePaint(); // this tells the framework that the node
- // needs to be redisplayed.
- }
- });
-
- n.setPaint(Color.ORANGE);
- getCanvas().getLayer().addChild(n);
- }
-
- // Here a new "face" node is created. But instead of drawing the face
- // directly
- // using Graphics2D we compose the face from other nodes.
- public void composeOtherNodes() {
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
-
- // add the face parts
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
-
- // don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
-
- // position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
-
- // set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- myCompositeFace.setBounds(b.inset(-5, -5));
-
- // opps it to small, so scale it up.
- myCompositeFace.scale(1.5);
-
- getCanvas().getLayer().addChild(myCompositeFace);
- }
-
- // Here a completely new kind of node, a grid node" is created. We do
- // all the drawing ourselves here instead of passing the work off to
- // other parts of the framework.
- public void createCustomNode() {
- PNode n = new PNode() {
- public void paint(PPaintContext aPaintContext) {
- double bx = getX();
- double by = getY();
- double rightBorder = bx + getWidth();
- double bottomBorder = by + getHeight();
-
- Line2D line = new Line2D.Double();
- Graphics2D g2 = aPaintContext.getGraphics();
-
- g2.setStroke(new BasicStroke(0));
- g2.setPaint(getPaint());
-
- // draw vertical lines
- for (double x = bx; x < rightBorder; x += 5) {
- line.setLine(x, by, x, bottomBorder);
- g2.draw(line);
- }
-
- for (double y = by; y < bottomBorder; y += 5) {
- line.setLine(bx, y, rightBorder, y);
- g2.draw(line);
- }
- }
- };
- n.setBounds(0, 0, 100, 80);
- n.setPaint(Color.black);
- getCanvas().getLayer().addChild(n);
- }
-
- public static void main(String[] args) {
- new BirdsEyeViewExample();
- }
-
- /**
- * The Birds Eye View Class
- */
- public class BirdsEyeView extends PCanvas implements PropertyChangeListener {
-
- /**
- * This is the node that shows the viewed area.
- */
- PNode areaVisiblePNode;
-
- /**
- * This is the canvas that is being viewed
- */
- PCanvas viewedCanvas;
-
- /**
- * The change listener to know when to update the birds eye view.
- */
- PropertyChangeListener changeListener;
-
- int layerCount;
-
- /**
- * Creates a new instance of a BirdsEyeView
- */
- public BirdsEyeView() {
-
- // create the PropertyChangeListener for listening to the viewed
- // canvas
- changeListener = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- updateFromViewed();
- }
- };
-
- // create the coverage node
- areaVisiblePNode = new P3DRect();
- areaVisiblePNode.setPaint(new Color(128, 128, 255));
- areaVisiblePNode.setTransparency(.8f);
- areaVisiblePNode.setBounds(0, 0, 100, 100);
- getCamera().addChild(areaVisiblePNode);
-
- // add the drag event handler
- getCamera().addInputEventListener(new PDragSequenceEventHandler() {
- protected void startDrag(PInputEvent e) {
- if (e.getPickedNode() == areaVisiblePNode)
- super.startDrag(e);
- }
-
- protected void drag(PInputEvent e) {
- PDimension dim = e.getDelta();
- viewedCanvas.getCamera().translateView(0 - dim.getWidth(),
- 0 - dim.getHeight());
- }
-
- });
-
- // remove Pan and Zoom
- removeInputEventListener(getPanEventHandler());
- removeInputEventListener(getZoomEventHandler());
-
- setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
-
- }
-
- public void connect(PCanvas canvas, PLayer[] viewed_layers) {
-
- this.viewedCanvas = canvas;
- layerCount = 0;
-
- viewedCanvas.getCamera().addPropertyChangeListener(changeListener);
-
- for (layerCount = 0; layerCount < viewed_layers.length; ++layerCount) {
- getCamera().addLayer(layerCount, viewed_layers[layerCount]);
- }
-
- }
-
- /**
- * Add a layer to list of viewed layers
- */
- public void addLayer(PLayer new_layer) {
- getCamera().addLayer(new_layer);
- layerCount++;
- }
-
- /**
- * Remove the layer from the viewed layers
- */
- public void removeLayer(PLayer old_layer) {
- getCamera().removeLayer(old_layer);
- layerCount--;
- }
-
- /**
- * Stop the birds eye view from receiving events from the viewed canvas
- * and remove all layers
- */
- public void disconnect() {
- viewedCanvas.getCamera().removePropertyChangeListener(
- changeListener);
-
- for (int i = 0; i < getCamera().getLayerCount(); ++i) {
- getCamera().removeLayer(i);
- }
-
- }
-
- /**
- * This method will get called when the viewed canvas changes
- */
- public void propertyChange(PropertyChangeEvent event) {
- updateFromViewed();
- }
-
- /**
- * This method gets the state of the viewed canvas and updates the
- * BirdsEyeViewer This can be called from outside code
- */
- public void updateFromViewed() {
-
- double viewedX;
- double viewedY;
- double viewedHeight;
- double viewedWidth;
-
- double ul_camera_x = viewedCanvas.getCamera().getViewBounds()
- .getX();
- double ul_camera_y = viewedCanvas.getCamera().getViewBounds()
- .getY();
- double lr_camera_x = ul_camera_x
- + viewedCanvas.getCamera().getViewBounds().getWidth();
- double lr_camera_y = ul_camera_y
- + viewedCanvas.getCamera().getViewBounds().getHeight();
-
- Rectangle2D drag_bounds = getCamera().getUnionOfLayerFullBounds();
-
- double ul_layer_x = drag_bounds.getX();
- double ul_layer_y = drag_bounds.getY();
- double lr_layer_x = drag_bounds.getX() + drag_bounds.getWidth();
- double lr_layer_y = drag_bounds.getY() + drag_bounds.getHeight();
-
- // find the upper left corner
-
- // set to the lesser value
- if (ul_camera_x < ul_layer_x)
- viewedX = ul_layer_x;
- else
- viewedX = ul_camera_x;
-
- // same for y
- if (ul_camera_y < ul_layer_y)
- viewedY = ul_layer_y;
- else
- viewedY = ul_camera_y;
-
- // find the lower right corner
-
- // set to the greater value
- if (lr_camera_x < lr_layer_x)
- viewedWidth = lr_camera_x - viewedX;
- else
- viewedWidth = lr_layer_x - viewedX;
-
- // same for height
- if (lr_camera_y < lr_layer_y)
- viewedHeight = lr_camera_y - viewedY;
- else
- viewedHeight = lr_layer_y - viewedY;
-
- Rectangle2D bounds = new Rectangle2D.Double(viewedX, viewedY,
- viewedWidth, viewedHeight);
- bounds = getCamera().viewToLocal(bounds);
- areaVisiblePNode.setBounds(bounds);
-
- // keep the birds eye view centered
- getCamera().animateViewToCenterBounds(drag_bounds, true, 0);
-
- }
-
- } // class BirdsEyeView
-
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java b/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
deleted file mode 100755
index 8a7fb78..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/CameraExample.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-
-/**
- * This example shows how to create internal cameras
- */
-public class CameraExample extends PFrame {
-
- public CameraExample() {
- this(null);
- }
-
- public CameraExample(PCanvas aCanvas) {
- super("CameraExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer l = new PLayer();
- PPath n = PPath.createEllipse(0, 0, 100, 80);
- n.setPaint(Color.red);
- n.setStroke(null);
- PBoundsHandle.addBoundsHandlesTo(n);
- l.addChild(n);
- n.translate(200, 200);
-
- PCamera c = new PCamera();
- c.setBounds(0, 0, 100, 80);
- c.scaleView(0.1);
- c.addLayer(l);
- PBoundsHandle.addBoundsHandlesTo(c);
- c.setPaint(Color.yellow);
-
- getCanvas().getLayer().addChild(l);
- getCanvas().getLayer().addChild(c);
- }
-
- public static void main(String[] args) {
- new CameraExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java b/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
deleted file mode 100755
index 20aadd5..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/CenterExample.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-public class CenterExample extends PFrame {
-
- public CenterExample() {
- this(null);
- }
-
- public CenterExample(PCanvas aCanvas) {
- super("CenterExample", false, aCanvas);
- }
-
- public void initialize() {
- PCanvas c = getCanvas();
- PLayer l = c.getLayer();
- PCamera cam = c.getCamera();
-
- cam.scaleView(2.0);
- PPath path = PPath.createRectangle(0, 0, 100, 100);
-
- l.addChild(path);
- path.translate(100, 10);
- path.scale(0.2);
- cam.animateViewToCenterBounds(path.getGlobalFullBounds(), true, 1000);
- }
-
- public static void main(String[] args) {
- new CenterExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java b/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
deleted file mode 100755
index 52a1e7c..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/ChartLabelExample.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to create a vertical and a horizontal bar which can
- * move with your graph and always stays on view.
- *
- * @author Tao
- */
-public class ChartLabelExample extends PFrame {
- final int nodeHeight = 15;
- final int nodeWidth = 30;
-
- //Row Bar
- PLayer rowBarLayer;
-
- //Colume Bar
- PLayer colBarLayer;
-
- public ChartLabelExample() {
- this(null);
- }
-
- public ChartLabelExample(PCanvas aCanvas) {
- super("ChartLabelExample", false, aCanvas);
- }
-
- public void initialize() {
- //create bar layers
- rowBarLayer = new PLayer();
- colBarLayer = new PLayer();
-
- //create bar nodes
- for (int i = 0; i < 10; i++) {
- //create row bar with node row1, row2,...row10
- PText p = new PText("Row " + i);
- p.setX(0);
- p.setY(nodeHeight * i + nodeHeight);
- p.setPaint(Color.white);
- colBarLayer.addChild(p);
-
- //create col bar with node col1, col2,...col10
- p = new PText("Col " + i);
- p.setX(nodeWidth * i + nodeWidth);
- p.setY(0);
- p.setPaint(Color.white);
- rowBarLayer.addChild(p);
- }
-
- //add bar layers to camera
- getCanvas().getCamera().addChild(rowBarLayer);
- getCanvas().getCamera().addChild(colBarLayer);
-
- //create matrix nodes
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- PPath path = PPath.createRectangle(nodeWidth * j + nodeWidth,
- nodeHeight * i + nodeHeight, nodeWidth - 1,
- nodeHeight - 1);
- getCanvas().getLayer().addChild(path);
- }
- }
-
- //catch drag event and move bars corresponding
- getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
- Point2D oldP, newP;
-
- public void mousePressed(PInputEvent aEvent) {
- oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- newP = getCanvas().getCamera().getViewBounds().getCenter2D();
- colBarLayer.translate(0, (oldP.getY() - newP.getY())
- / getCanvas().getLayer().getScale());
- rowBarLayer.translate((oldP.getX() - newP.getX())
- / getCanvas().getLayer().getScale(), 0);
- }
- });
- }
-
- public static void main(String[] args) {
- new ChartLabelExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java b/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
deleted file mode 100755
index 950a3ab..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/ClipExample.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.nodes.PClip;
-
-/**
- * Quick example of how to use a clip.
- */
-public class ClipExample extends PFrame {
-
- public ClipExample() {
- this(null);
- }
-
- public ClipExample(PCanvas aCanvas) {
- super("ClipExample", false, aCanvas);
- }
-
- public void initialize() {
- PClip clip = new PClip();
- clip.setPathToEllipse(0, 0, 100, 100);
- clip.setPaint(Color.red);
-
- clip.addChild(PPath.createRectangle(20, 20, 100, 50));
- getCanvas().getLayer().addChild(clip);
-
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new ClipExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java b/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
deleted file mode 100755
index 368d9fa..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/CompositeExample.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.nodes.PComposite;
-
-/**
- * This example shows how to create a composite node. A composite node is
- * a group of nodes that behave as a single node when interacted with.
- */
-public class CompositeExample extends PFrame {
-
- public CompositeExample() {
- this(null);
- }
-
- public CompositeExample(PCanvas aCanvas) {
- super("CompositeExample", false, aCanvas);
- }
-
- public void initialize() {
- PComposite composite = new PComposite();
-
- PNode circle = PPath.createEllipse(0, 0, 100, 100);
- PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
- PNode text = new PText("Hello world!");
-
- composite.addChild(circle);
- composite.addChild(rectangle);
- composite.addChild(text);
-
- rectangle.rotate(Math.toRadians(45));
- rectangle.setPaint(Color.RED);
-
- text.scale(2.0);
- text.setPaint(Color.GREEN);
-
- getCanvas().getLayer().addChild(composite);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new CompositeExample();
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java b/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
deleted file mode 100755
index b7ea44e..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/DynamicExample.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.util.Iterator;
-import java.util.Random;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.util.PFixedWidthStroke;
-
-/**
- * 1000 nodes rotated continuously. Note that if you zoom to a portion of the screen where
- * you can't see any nodes the CPU usage goes down to 1%, even though all the objects are
- * still getting rotated continuously (every 20 milliseconds). This shows that the cost
- * of repainting and bounds caches is very cheap compared to the cost of drawing.
- */
-public class DynamicExample extends PFrame {
-
- public DynamicExample() {
- this(null);
- }
-
- public DynamicExample(PCanvas aCanvas) {
- super("DynamicExample", false, aCanvas);
- }
-
- public void initialize() {
- final PLayer layer = getCanvas().getLayer();
- PRoot root = getCanvas().getRoot();
- Random r = new Random();
- for (int i = 0; i < 1000; i++) {
- final PNode n = PPath.createRectangle(0, 0, 100, 80);
- n.translate(10000 * r.nextFloat(), 10000 * r.nextFloat());
- n.setPaint(new Color(r.nextFloat(), r.nextFloat(),r.nextFloat()));
- layer.addChild(n);
- }
- getCanvas().getCamera().animateViewToCenterBounds(layer.getGlobalFullBounds(), true, 0);
- PActivity a = new PActivity(-1, 20) {
- public void activityStep(long currentTime) {
- super.activityStep(currentTime);
- rotateNodes();
- }
- };
- root.addActivity(a);
-
- PPath p = new PPath();
- p.moveTo(0, 0);
- p.lineTo(0, 1000);
- PFixedWidthStroke stroke = new PFixedWidthStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, new float[] {5, 2}, 0);
- p.setStroke(stroke);
- layer.addChild(p);
- }
-
- public void rotateNodes() {
- Iterator i = getCanvas().getLayer().getChildrenReference().iterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- each.rotate(Math.toRadians(2));
- }
- }
-
- public static void main(String[] args) {
- new DynamicExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java b/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
deleted file mode 100755
index b0c3cd2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/EventHandlerExample.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * This example shows how to create and install a custom event listener that draws
- * rectangles.
- */
-public class EventHandlerExample extends PFrame {
-
- public EventHandlerExample() {
- this(null);
- }
-
- public EventHandlerExample(PCanvas aCanvas) {
- super("EventHandlerExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
-
- // Create a new event handler the creates new rectangles on
- // mouse pressed, dragged, release.
- PBasicInputEventHandler rectEventHandler = createRectangleEventHandler();
-
- // Make the event handler only work with BUTTON1 events, so that it does
- // not conflict with the zoom event handler that is installed by default.
- rectEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
-
- // Remove the pan event handler that is installed by default so that it
- // does not conflict with our new rectangle creation event handler.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
-
- // Register our new event handler.
- getCanvas().addInputEventListener(rectEventHandler);
- }
-
- public PBasicInputEventHandler createRectangleEventHandler() {
-
- // Create a new subclass of PBasicEventHandler that creates new PPath nodes
- // on mouse pressed, dragged, and released sequences. Not that subclassing
- // PDragSequenceEventHandler would make this class easier to implement, but
- // here you can see how to do it from scratch.
- return new PBasicInputEventHandler() {
-
- // The rectangle that is currently getting created.
- protected PPath rectangle;
-
- // The mouse press location for the current pressed, drag, release sequence.
- protected Point2D pressPoint;
-
- // The current drag location.
- protected Point2D dragPoint;
-
- public void mousePressed(PInputEvent e) {
- super.mousePressed(e);
-
- PLayer layer = getCanvas().getLayer();
-
- // Initialize the locations.
- pressPoint = e.getPosition();
- dragPoint = pressPoint;
-
- // create a new rectangle and add it to the canvas layer so that
- // we can see it.
- rectangle = new PPath();
- rectangle.setStroke(new BasicStroke((float)(1/ e.getCamera().getViewScale())));
- layer.addChild(rectangle);
-
- // update the rectangle shape.
- updateRectangle();
- }
-
- public void mouseDragged(PInputEvent e) {
- super.mouseDragged(e);
- // update the drag point location.
- dragPoint = e.getPosition();
-
- // update the rectangle shape.
- updateRectangle();
- }
-
- public void mouseReleased(PInputEvent e) {
- super.mouseReleased(e);
- // update the rectangle shape.
- updateRectangle();
- rectangle = null;
- }
-
- public void updateRectangle() {
- // create a new bounds that contains both the press and current
- // drag point.
- PBounds b = new PBounds();
- b.add(pressPoint);
- b.add(dragPoint);
-
- // Set the rectangles bounds.
- rectangle.setPathTo(b);
- }
- };
- }
-
- public static void main(String[] args) {
- new EventHandlerExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java b/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
deleted file mode 100755
index ab75a88..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java
+++ /dev/null
@@ -1,362 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolox.PFrame;
-
-public class ExampleRunner extends JFrame {
-
- public ExampleRunner() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Piccolo Example Runner");
- setSize(426, 335);
- getContentPane().setLayout(new BorderLayout());
- createExampleButtons();
- validate();
- pack();
- setVisible(true);
- }
-
- public void createExampleButtons() {
- Container c = getContentPane();
- Container p = new JPanel();
-
- p = new JPanel(new GridLayout(0, 1));
- c.add(BorderLayout.NORTH, p);
-
- p.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate;
- }
- }));
-
- p.add(new JCheckBox(new AbstractAction("Show Region Managment") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugRegionManagement = !PDebug.debugRegionManagement;
- }
- }));
-
- p.add(new JCheckBox(new AbstractAction("Show Full Bounds") {
- public void actionPerformed(ActionEvent e) {
- PDebug.debugFullBounds = !PDebug.debugFullBounds;
- }
- }));
-
- p = new JPanel(new GridLayout(0, 2));
- c.add(BorderLayout.CENTER, p);
-
- p.add(new JButton(new AbstractAction("ActivityExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ActivityExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("AngleNodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new AngleNodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("BirdsEyeViewExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new BirdsEyeViewExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("CameraExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CameraExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("CenterExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CenterExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("ChartLabelExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ChartLabelExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("ClipExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ClipExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("CompositeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new CompositeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("DynamicExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new DynamicExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("EventHandlerExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new EventHandlerExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("FullScreenNodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new FullScreenNodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("GraphEditorExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GraphEditorExample();
- example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
- p.add(new JButton(new AbstractAction("GridExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GridExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("GroupExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new GroupExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("HandleExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new HandleExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("HierarchyZoomExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new HierarchyZoomExample();
- example.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("KeyEventFocusExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new KeyEventFocusExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("LayoutExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new LayoutExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("LensExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new LensExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("NavigationExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NavigationExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("NodeCacheExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeCacheExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("NodeEventExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeEventExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("NodeExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("NodeLinkExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new NodeLinkExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("PanToExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PanToExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("PathExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PathExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("PositionExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PositionExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("PositionPathActivityExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PositionPathActivityExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("PulseExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new PulseExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("ScrollingExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new ScrollingExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("SelectionExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new SelectionExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("SquiggleExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new SquiggleExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("StickyExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new StickyExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("StickyHandleLayerExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new StickyHandleLayerExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("TextExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TextExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("Tooltip Example") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TooltipExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("TwoCanvasExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new TwoCanvasExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
-
- p.add(new JButton(new AbstractAction("WaitForActivitiesExample") {
- public void actionPerformed(ActionEvent e) {
- PFrame example = new WaitForActivitiesExample();
- example
- .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- }
- }));
- }
-
- public static void main(String[] args) {
- new ExampleRunner();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java b/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
deleted file mode 100755
index fcabba1..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/FullScreenNodeExample.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-
-public class FullScreenNodeExample extends NodeExample {
-
- public void initialize() {
- super.initialize();
- setFullScreenMode(true);
- }
-
- public static void main(String[] args) {
- new FullScreenNodeExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java b/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
deleted file mode 100755
index 115c94f..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/GraphEditorExample.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Random;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * Create a simple graph with some random nodes and connected edges.
- * An event handler allows users to drag nodes around, keeping the edges connected.
- *
- * ported from .NET GraphEditorExample by Sun Hongmei.
- */
-public class GraphEditorExample extends PFrame {
-
- public GraphEditorExample() {
- this(null);
- }
-
- public GraphEditorExample(PCanvas aCanvas) {
- super("GraphEditorExample", false, aCanvas);
- }
-
- public void initialize() {
- int numNodes = 50;
- int numEdges = 50;
-
- // Initialize, and create a layer for the edges (always underneath the nodes)
- PLayer nodeLayer = getCanvas().getLayer();
- PLayer edgeLayer = new PLayer();
- getCanvas().getCamera().addLayer(0, edgeLayer);
- Random rnd = new Random();
- ArrayList tmp;
- for (int i = 0; i < numNodes; i++) {
- float x = (float) (300. * rnd.nextDouble());
- float y = (float) (400. * rnd.nextDouble());
- PPath path = PPath.createEllipse(x, y, 20, 20);
- tmp = new ArrayList();
- path.addAttribute("edges", tmp);
- nodeLayer.addChild(path);
- }
-
- // Create some random edges
- // Each edge's Tag has an ArrayList used to store associated nodes
- for (int i = 0; i < numEdges; i++) {
- int n1 = rnd.nextInt(numNodes);
- int n2 = rnd.nextInt(numNodes);
- PNode node1 = nodeLayer.getChild(n1);
- PNode node2 = nodeLayer.getChild(n2);
-
- Point2D.Double bound1 = (Point2D.Double) node1.getBounds().getCenter2D();
- Point2D.Double bound2 = (Point2D.Double) node2.getBounds().getCenter2D();
-
- PPath edge = new PPath();
- edge.moveTo((float) bound1.getX(), (float) bound1.getY());
- edge.lineTo((float) bound2.getX(), (float) bound2.getY());
-
- tmp = (ArrayList) node1.getAttribute("edges");
- tmp.add(edge);
- tmp = (ArrayList) node2.getAttribute("edges");
- tmp.add(edge);
-
- tmp = new ArrayList();
- tmp.add(node1);
- tmp.add(node2);
- edge.addAttribute("nodes", tmp);
-
- edgeLayer.addChild(edge);
- }
-
- // Create event handler to move nodes and update edges
- nodeLayer.addInputEventListener(new NodeDragHandler());
- }
-
- public static void main(String[] args) {
- new GraphEditorExample();
- }
-
- ///
- /// Simple event handler which applies the following actions to every node it is called on:
- /// * Turn node red when the mouse goes over the node
- /// * Turn node white when the mouse exits the node
- /// * Drag the node, and associated edges on mousedrag
- /// It assumes that the node's Tag references an ArrayList with a list of associated
- /// edges where each edge is a PPath which each have a Tag that references an ArrayList
- /// with a list of associated nodes.
- ///
- class NodeDragHandler extends PDragSequenceEventHandler {
- public NodeDragHandler() {
- getEventFilter().setMarksAcceptedEventsAsHandled(true);
- }
- public void mouseEntered(PInputEvent e) {
- if (e.getButton() == 0) {
- e.getPickedNode().setPaint(Color.red);
- }
- }
-
- public void mouseExited(PInputEvent e) {
- if (e.getButton() == 0) {
- e.getPickedNode().setPaint(Color.white);
- }
- }
-
- public void drag(PInputEvent e) {
- PNode node = e.getPickedNode();
- node.translate(e.getDelta().width, e.getDelta().height);
-
- ArrayList edges = (ArrayList) e.getPickedNode().getAttribute("edges");
-
- int i;
- for (i = 0; i < edges.size(); i++) {
- PPath edge = (PPath) edges.get(i);
- ArrayList nodes = (ArrayList) edge.getAttribute("nodes");
- PNode node1 = (PNode) nodes.get(0);
- PNode node2 = (PNode) nodes.get(1);
-
- edge.reset();
- // Note that the node's "FullBounds" must be used (instead of just the "Bound")
- // because the nodes have non-identity transforms which must be included when
- // determining their position.
- Point2D.Double bound1 = (Point2D.Double) node1.getFullBounds().getCenter2D();
- Point2D.Double bound2 = (Point2D.Double) node2.getFullBounds().getCenter2D();
-
- edge.moveTo((float) bound1.getX(), (float) bound1.getY());
- edge.lineTo((float) bound2.getX(), (float) bound2.getY());
- }
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java b/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java
deleted file mode 100755
index e19d9dc..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/GridExample.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Stroke;
-import java.awt.geom.Line2D;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-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.PRoot;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * Example of drawing an infinite grid, and providing support for snap to grid.
- */
-public class GridExample extends PFrame {
-
- static protected Line2D gridLine = new Line2D.Double();
- static protected Stroke gridStroke = new BasicStroke(1);
- static protected Color gridPaint = Color.BLACK;
- static protected double gridSpacing = 20;
-
- public GridExample() {
- this(null);
- }
-
- public GridExample(PCanvas aCanvas) {
- super("GridExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- final PCamera camera = getCanvas().getCamera();
- final PLayer gridLayer = new PLayer() {
- protected void paint(PPaintContext paintContext) {
- // make sure grid gets drawn on snap to grid boundaries. And
- // expand a little to make sure that entire view is filled.
- double bx = (getX() - (getX() % gridSpacing)) - gridSpacing;
- double by = (getY() - (getY() % gridSpacing)) - gridSpacing;
- double rightBorder = getX() + getWidth() + gridSpacing;
- double bottomBorder = getY() + getHeight() + gridSpacing;
-
- Graphics2D g2 = paintContext.getGraphics();
- Rectangle2D clip = paintContext.getLocalClip();
-
- g2.setStroke(gridStroke);
- g2.setPaint(gridPaint);
-
- for (double x = bx; x < rightBorder; x += gridSpacing) {
- gridLine.setLine(x, by, x, bottomBorder);
- if (clip.intersectsLine(gridLine)) {
- g2.draw(gridLine);
- }
- }
-
- for (double y = by; y < bottomBorder; y += gridSpacing) {
- gridLine.setLine(bx, y, rightBorder, y);
- if (clip.intersectsLine(gridLine)) {
- g2.draw(gridLine);
- }
- }
- }
- };
-
- // replace standar layer with grid layer.
- root.removeChild(camera.getLayer(0));
- camera.removeLayer(0);
- root.addChild(gridLayer);
- camera.addLayer(gridLayer);
-
- // add constrains so that grid layers bounds always match cameras view bounds. This makes
- // it look like an infinite grid.
- camera.addPropertyChangeListener(PNode.PROPERTY_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- gridLayer.setBounds(camera.getViewBounds());
- }
- });
-
- camera.addPropertyChangeListener(PCamera.PROPERTY_VIEW_TRANSFORM, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- gridLayer.setBounds(camera.getViewBounds());
- }
- });
-
- gridLayer.setBounds(camera.getViewBounds());
-
- PNode n = new PNode();
- n.setPaint(Color.BLUE);
- n.setBounds(0, 0, 100, 80);
-
- getCanvas().getLayer().addChild(n);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
-
- // add a drag event handler that supports snap to grid.
- getCanvas().addInputEventListener(new PDragSequenceEventHandler() {
-
- protected PNode draggedNode;
- protected Point2D nodeStartPosition;
-
- protected boolean shouldStartDragInteraction(PInputEvent event) {
- if (super.shouldStartDragInteraction(event)) {
- return event.getPickedNode() != event.getTopCamera() && !(event.getPickedNode() instanceof PLayer);
- }
- return false;
- }
-
- protected void startDrag(PInputEvent event) {
- super.startDrag(event);
- draggedNode = event.getPickedNode();
- draggedNode.moveToFront();
- nodeStartPosition = draggedNode.getOffset();
- }
-
- protected void drag(PInputEvent event) {
- super.drag(event);
-
- Point2D start = getCanvas().getCamera().localToView((Point2D)getMousePressedCanvasPoint().clone());
- Point2D current = event.getPositionRelativeTo(getCanvas().getLayer());
- Point2D dest = new Point2D.Double();
-
- dest.setLocation(nodeStartPosition.getX() + (current.getX() - start.getX()),
- nodeStartPosition.getY() + (current.getY() - start.getY()));
-
- dest.setLocation(dest.getX() - (dest.getX() % gridSpacing),
- dest.getY() - (dest.getY() % gridSpacing));
-
- draggedNode.setOffset(dest.getX(), dest.getY());
- }
- });
- }
-
- public static void main(String[] args) {
- new GridExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java b/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java
deleted file mode 100755
index 9ccc469..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/GroupExample.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.util.ArrayList;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.event.PSelectionEventHandler;
-
-/**
- * An example of how to implement decorator groups. Decorator groups are nodes that base their bounds and rendering on their children.
- * This seems to be a common type of visual node that requires some potentially non-obvious subclassing to get right.
- *
- * Both a volatile and a non-volatile implementation are shown. The volatile implementation might be used in cases where you want to
- * keep a scale-independent pen width border around a group of objects. The non-volatile implementation can be used in more standard
- * cases where the decorator's bounds are stable during zooming.
- *
- * @author Lance Good
- */
-public class GroupExample extends PFrame {
-
- public GroupExample() {
- this(null);
- }
-
- public GroupExample(PCanvas aCanvas) {
- super("GroupExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
-
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
-
- // Create a decorator group that is NOT volatile
- DecoratorGroup dg = new DecoratorGroup();
- dg.setPaint(Color.magenta);
-
- // Put some nodes under the group for it to decorate
- PPath p1 = PPath.createEllipse(25,25,75,75);
- p1.setPaint(Color.red);
- PPath p2 = PPath.createRectangle(125,75,50,50);
- p2.setPaint(Color.blue);
-
- // Add everything to the Piccolo hierarchy
- dg.addChild(p1);
- dg.addChild(p2);
- getCanvas().getLayer().addChild(dg);
-
- // Create a decorator group that IS volatile
- VolatileDecoratorGroup vdg = new VolatileDecoratorGroup(getCanvas().getCamera());
- vdg.setPaint(Color.cyan);
-
- // Put some nodes under the group for it to decorate
- PPath p3 = PPath.createEllipse(275,175,50,50);
- p3.setPaint(Color.blue);
- PPath p4 = PPath.createRectangle(175,175,75,75);
- p4.setPaint(Color.green);
-
- // Add everything to the Piccolo hierarchy
- vdg.addChild(p3);
- vdg.addChild(p4);
- getCanvas().getLayer().addChild(vdg);
-
- // Create a selection handler so we can see that the decorator actually works
- ArrayList selectableParents = new ArrayList();
- selectableParents.add(dg);
- selectableParents.add(vdg);
-
- PSelectionEventHandler ps = new PSelectionEventHandler(getCanvas().getLayer(),selectableParents);
- getCanvas().addInputEventListener(ps);
- }
-
- public static void main(String[] args) {
- new GroupExample();
- }
-}
-
-/**
- * This is the non-volatile implementation of a decorator group that paints a background rectangle based
- * on the bounds of its children.
- */
-class DecoratorGroup extends PNode {
- int INDENT = 10;
-
- PBounds cachedChildBounds = new PBounds();
- PBounds comparisonBounds = new PBounds();
-
- public DecoratorGroup() {
- super();
- }
-
- /**
- * Change the default paint to fill an expanded bounding box based on its children's bounds
- */
- public void paint(PPaintContext ppc) {
- Paint paint = getPaint();
- if (paint != null) {
- Graphics2D g2 = ppc.getGraphics();
- g2.setPaint(paint);
-
- PBounds bounds = getUnionOfChildrenBounds(null);
- bounds.setRect(bounds.getX()-INDENT,bounds.getY()-INDENT,bounds.getWidth()+2*INDENT,bounds.getHeight()+2*INDENT);
- g2.fill(bounds);
- }
- }
-
- /**
- * Change the full bounds computation to take into account that we are expanding the children's bounds
- * Do this instead of overriding getBoundsReference() since the node is not volatile
- */
- public PBounds computeFullBounds(PBounds dstBounds) {
- PBounds result = getUnionOfChildrenBounds(dstBounds);
-
- cachedChildBounds.setRect(result);
- result.setRect(result.getX()-INDENT,result.getY()-INDENT,result.getWidth()+2*INDENT,result.getHeight()+2*INDENT);
- localToParent(result);
- return result;
- }
-
- /**
- * This is a crucial step. We have to override this method to invalidate the paint each time the bounds are changed so
- * we repaint the correct region
- */
- public boolean validateFullBounds() {
- comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
-
- if (!cachedChildBounds.equals(comparisonBounds)) {
- setPaintInvalid(true);
- }
- return super.validateFullBounds();
- }
-}
-
-/**
- * This is the volatile implementation of a decorator group that paints a background rectangle based
- * on the bounds of its children.
- */
-class VolatileDecoratorGroup extends PNode {
- int INDENT = 10;
-
- PBounds cachedChildBounds = new PBounds();
- PBounds comparisonBounds = new PBounds();
- PCamera renderCamera;
-
- public VolatileDecoratorGroup(PCamera camera) {
- super();
- renderCamera = camera;
- }
-
- /**
- * Indicate that the bounds are volatile for this group
- */
- public boolean getBoundsVolatile() {
- return true;
- }
-
- /**
- * Since our bounds are volatile, we can override this method to indicate that we are expanding our bounds beyond our children
- */
- public PBounds getBoundsReference() {
- PBounds bds = super.getBoundsReference();
- getUnionOfChildrenBounds(bds);
-
- cachedChildBounds.setRect(bds);
- double scaledIndent = INDENT/renderCamera.getViewScale();
- bds.setRect(bds.getX()-scaledIndent,bds.getY()-scaledIndent,bds.getWidth()+2*scaledIndent,bds.getHeight()+2*scaledIndent);
-
- return bds;
- }
-
- /**
- * This is a crucial step. We have to override this method to invalidate the paint each time the bounds are changed so
- * we repaint the correct region
- */
- public boolean validateFullBounds() {
- comparisonBounds = getUnionOfChildrenBounds(comparisonBounds);
-
- if (!cachedChildBounds.equals(comparisonBounds)) {
- setPaintInvalid(true);
- }
- return super.validateFullBounds();
- }
-}
-
-
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java b/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java
deleted file mode 100755
index 7430fec..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/HandleExample.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-import edu.umd.cs.piccolox.handles.PHandle;
-import edu.umd.cs.piccolox.util.PNodeLocator;
-
-/**
- * This example show how to add the default handles to a node, and also how
- * to create your own custom handles.
- */
-public class HandleExample extends PFrame {
-
- public HandleExample() {
- this(null);
- }
-
- public HandleExample(PCanvas aCanvas) {
- super("HandleExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath n = PPath.createRectangle(0, 0, 100, 80);
-
- // add another node the the root as a reference point so that we can
- // tell that our node is getting dragged, as opposed the the canvas
- // view being panned.
- getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
-
- getCanvas().getLayer().addChild(n);
-
- // tell the node to show its default handles.
- PBoundsHandle.addBoundsHandlesTo(n);
-
- // The default PBoundsHandle implementation doesn't work well with PPaths that have strokes. The reason
- // for this is that the default PBoundsHandle modifies the bounds of an PNode, but when adding handles to
- // a PPath we really want it to be modifying the underlying geometry of the PPath, the shape without the
- // stroke. The solution is that we need to create handles specific to PPaths that locate themselves on the
- // paths internal geometry, not the external bounds geometry...
-
- n.setStroke(new BasicStroke(10));
- n.setPaint(Color.green);
-
- // Here we create our own custom handle. This handle is located in the center of its parent
- // node and you can use it to drag the parent around. This handle also updates its color when
- // the is pressed/released in it.
- final PHandle h = new PHandle(new PNodeLocator(n)) { // the default locator locates the center of a node.
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- localToParent(aLocalDimension);
- getParent().translate(aLocalDimension.getWidth(), aLocalDimension.getHeight());
- }
- };
-
- h.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- h.setPaint(Color.YELLOW);
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- h.setPaint(Color.RED);
- }
- });
-
- // make this handle appear a bit different then the default handle appearance.
- h.setPaint(Color.RED);
- h.setBounds(-10, -10, 20, 20);
-
- // also add our new custom handle to the node.
- n.addChild(h);
- }
-
- public static void main(String[] args) {
- new HandleExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java b/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java
deleted file mode 100755
index 75967aa..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/HelloWorldExample.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolox.PFrame;
-
-public class HelloWorldExample extends PFrame {
-
- public HelloWorldExample() {
- this(null);
- }
-
- public HelloWorldExample(PCanvas aCanvas) {
- super("HelloWorldExample", false, aCanvas);
- }
-
- public void initialize() {
- PText text = new PText("Hello World");
- getCanvas().getLayer().addChild(text);
- }
-
- public static void main(String[] args) {
- new HelloWorldExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java b/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java
deleted file mode 100755
index d7ec773..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/HierarchyZoomExample.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to create and zoom over a node hierarchy.
- */
-public class HierarchyZoomExample extends PFrame {
-
- public HierarchyZoomExample() {
- this(null);
- }
-
- public HierarchyZoomExample(PCanvas aCanvas) {
- super("HierarchyZoomExample", false, aCanvas);
- }
-
- public void initialize() {
- PNode root = createHierarchy(10);
- getCanvas().getLayer().addChild(root);
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- getCanvas().getCamera().animateViewToCenterBounds(event.getPickedNode().getGlobalBounds(), true, 500);
- }
- });
- }
-
- public PNode createHierarchy(int level) {
- PPath result = PPath.createRectangle(0, 0, 100, 100);
-
- if (level > 0) {
- PNode child = createHierarchy(level - 1);
- child.scale(0.5);
- result.addChild(child);
- child.offset(25, 25);
- }
-
- return result;
- }
-
- public static void main(String[] args) {
- new HierarchyZoomExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java b/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java
deleted file mode 100755
index f2c6d0d..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/KeyEventFocusExample.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how a node can get the keyboard focus.
- */
-public class KeyEventFocusExample extends PFrame {
-
- public KeyEventFocusExample() {
- this(null);
- }
-
- public KeyEventFocusExample(PCanvas aCanvas) {
- super("KeyEventFocusExample", false, aCanvas);
- }
-
- public void initialize() {
- // Create a green and red node and add them to canvas layer.
- PCanvas canvas = getCanvas();
- PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
- PNode nodeRed = PPath.createRectangle(0, 0, 100, 100);
- nodeRed.translate(200, 0);
- nodeGreen.setPaint(Color.green);
- nodeRed.setPaint(Color.red);
- canvas.getLayer().addChild(nodeGreen);
- canvas.getLayer().addChild(nodeRed);
-
- // Add an event handler to the green node the prints "green mousepressed"
- // when the mouse is pressed on the green node, and "green keypressed" when
- // the key is pressed and the event listener has keyboard focus.
- nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
- public void keyPressed(PInputEvent event) {
- System.out.println("green keypressed");
- }
-
- // Key board focus is managed by the PInputManager, accessible from
- // the root object, or from an incoming PInputEvent. In this case when
- // the mouse is pressed in the green node, then the event handler associated
- // with it will set the keyfocus to itself. Now it will receive key events
- // until someone else gets the focus.
- public void mousePressed(PInputEvent event) {
- event.getInputManager().setKeyboardFocus(event.getPath());
- System.out.println("green mousepressed");
- }
-
- public void keyboardFocusGained(PInputEvent event) {
- System.out.println("green focus gained");
- }
-
- public void keyboardFocusLost(PInputEvent event) {
- System.out.println("green focus lost");
- }
- });
-
- // do the same thing with the red node.
- nodeRed.addInputEventListener(new PBasicInputEventHandler() {
- public void keyPressed(PInputEvent event) {
- System.out.println("red keypressed");
- }
-
- public void mousePressed(PInputEvent event) {
- event.getInputManager().setKeyboardFocus(event.getPath());
- System.out.println("red mousepressed");
- }
-
- public void keyboardFocusGained(PInputEvent event) {
- System.out.println("red focus gained");
- }
-
- public void keyboardFocusLost(PInputEvent event) {
- System.out.println("red focus lost");
- }
- });
- }
-
- public static void main(String[] args) {
- new KeyEventFocusExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java b/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java
deleted file mode 100755
index d5652ae..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/LayoutExample.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-import java.util.Iterator;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-
-/**
- * This example shows how to create a node that will automatically
- * layout its children.
- */
-public class LayoutExample extends PFrame {
-
- public LayoutExample() {
- this(null);
- }
-
- public LayoutExample(PCanvas aCanvas) {
- super("LayoutExample", false, aCanvas);
- }
-
- public void initialize() {
- // Create a new node and override its validateLayoutAfterChildren method so
- // that it lays out its children in a row from left to
- // right.
-
- final PNode layoutNode = new PNode() {
- public void layoutChildren() {
- double xOffset = 0;
- double yOffset = 0;
-
- Iterator i = getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- each.setOffset(xOffset - each.getX(), yOffset);
- xOffset += each.getWidth();
- }
- }
- };
-
- layoutNode.setPaint(Color.red);
-
- // add some children to the layout node.
- for (int i = 0; i < 1000; i++) {
- // create child to add to the layout node.
- PNode each = PPath.createRectangle(0, 0, 100, 80);
-
- // add the child to the layout node.
- layoutNode.addChild(each);
- }
-
- PBoundsHandle.addBoundsHandlesTo(layoutNode.getChild(0));
-
- // add layoutNode to the root so it will be displayed.
- getCanvas().getLayer().addChild(layoutNode);
- }
-
- public static void main(String[] args) {
- new LayoutExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java b/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java
deleted file mode 100755
index 17374c2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/LensExample.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.geom.Point2D;
-
-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.PRoot;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-import edu.umd.cs.piccolox.nodes.PLens;
-
-/**
- * This example shows one way to create and use lens's in Piccolo.
- */
-public class LensExample extends PFrame {
-
- public LensExample() {
- this(null);
- }
-
- public LensExample(PCanvas aCanvas) {
- super("LensExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PCamera camera = getCanvas().getCamera();
- PLayer mainLayer = getCanvas().getLayer(); // viewed by the PCanvas camera, the lens is added to this layer.
- PLayer sharedLayer = new PLayer(); // viewed by both the lens camera and the PCanvas camera
- final PLayer lensOnlyLayer = new PLayer(); // viewed by only the lens camera
-
- root.addChild(lensOnlyLayer);
- root.addChild(sharedLayer);
- camera.addLayer(0, sharedLayer);
-
- final PLens lens = new PLens();
- lens.setBounds(10, 10, 100, 130);
- lens.addLayer(0, lensOnlyLayer);
- lens.addLayer(1, sharedLayer);
- mainLayer.addChild(lens);
- PBoundsHandle.addBoundsHandlesTo(lens);
-
- // Create an event handler that draws squiggles on the first layer of the bottom
- // most camera.
- PDragSequenceEventHandler squiggleEventHandler = new PDragSequenceEventHandler() {
- protected PPath squiggle;
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
- Point2D p = e.getPosition();
- squiggle = new PPath();
- squiggle.moveTo((float)p.getX(), (float)p.getY());
-
- // add squiggles to the first layer of the bottom camera. In the case of the
- // lens these squiggles will be added to the layer that is only visible by the lens,
- // In the case of the canvas camera the squiggles will be added to the shared layer
- // viewed by both the canvas camera and the lens.
- e.getCamera().getLayer(0).addChild(squiggle);
- }
-
- public void drag(PInputEvent e) {
- super.drag(e);
- updateSquiggle(e);
- }
-
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(PInputEvent aEvent) {
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float)p.getX(), (float)p.getY());
- }
- };
-
- // add the squiggle event handler to both the lens and the
- // canvas camera.
- lens.getCamera().addInputEventListener(squiggleEventHandler);
- camera.addInputEventListener(squiggleEventHandler);
-
- // make sure that the event handler consumes events so that it doesn't
- // conflic with other event handlers or with itself (since its added to two
- // event sources).
- squiggleEventHandler.getEventFilter().setMarksAcceptedEventsAsHandled(true);
-
- // remove default event handlers, not really nessessary since the squiggleEventHandler
- // consumes everything anyway, but still good to do.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
-
- // create a node that is viewed both by the main camera and by the
- // lens. Note that in its paint method it checks to see which camera
- // is painting it, and if its the lens uses a different color.
- PNode sharedNode = new PNode() {
- protected void paint(PPaintContext paintContext) {
- if (paintContext.getCamera() == lens.getCamera()) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(Color.RED);
- g2.fill(getBoundsReference());
- } else {
- super.paint(paintContext);
- }
- }
- };
- sharedNode.setPaint(Color.GREEN);
- sharedNode.setBounds(0, 0, 100, 200);
- sharedNode.translate(200, 200);
- sharedLayer.addChild(sharedNode);
-
- PText label = new PText("Move the lens \n (by dragging title bar) over the green rectangle, and it will appear red. press and drag the mouse on the canvas and it will draw squiggles. press and drag the mouse over the lens and drag squiggles that are only visible through the lens.");
- label.setConstrainWidthToTextWidth(false);
- label.setConstrainHeightToTextHeight(false);
- label.setBounds(200, 100, 200, 200);
-
- sharedLayer.addChild(label);
- }
-
- public static void main(String[] args) {
- new LensExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java b/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java
deleted file mode 100755
index cb7ef22..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/NavigationExample.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.util.Random;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.event.PNavigationEventHandler;
-
-public class NavigationExample extends PFrame {
-
- public NavigationExample() {
- this(null);
- }
-
- public NavigationExample(PCanvas aCanvas) {
- super("NavigationExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- PPath each = PPath.createRectangle(0, 0, 100, 80);
- each.scale(random.nextFloat() * 2);
- each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
- each.setPaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
- each.setStrokePaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- layer.addChild(each);
- }
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PNavigationEventHandler());
- }
-
- public static void main(String[] args) {
- new NavigationExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java b/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java
deleted file mode 100755
index 744fe06..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/NodeCacheExample.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.nodes.PNodeCache;
-
-public class NodeCacheExample extends PFrame {
-
- public NodeCacheExample() {
- this(null);
- }
-
- public NodeCacheExample(PCanvas aCanvas) {
- super("NodeCacheExample", false, aCanvas);
- }
-
- public void initialize() {
- PCanvas canvas = getCanvas();
-
- PPath circle = PPath.createEllipse(0, 0, 100, 100);
- circle.setStroke(new BasicStroke(10));
- circle.setPaint(Color.YELLOW);
-
- PPath rectangle = PPath.createRectangle(-100, -50, 100, 100);
- rectangle.setStroke(new BasicStroke(15));
- rectangle.setPaint(Color.ORANGE);
-
- PNodeCache cache = new PNodeCache();
- cache.addChild(circle);
- cache.addChild(rectangle);
-
- cache.invalidateCache();
-
- canvas.getLayer().addChild(cache);
- canvas.removeInputEventListener(canvas.getPanEventHandler());
- canvas.addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new NodeCacheExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java b/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java
deleted file mode 100755
index 10369d1..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/NodeEventExample.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-import java.awt.geom.Dimension2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to make a node handle events.
- */
-public class NodeEventExample extends PFrame {
-
- public NodeEventExample() {
- this(null);
- }
-
- public NodeEventExample(PCanvas aCanvas) {
- super("NodeEventExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- // create a new node and override some of the event handling
- // methods so that the node changes to orange when the mouse (Button 1) is
- // pressed on the node, and changes back to green when the mouse
- // is released. Also when the mouse is dragged the node updates its
- // position so that the node is "dragged". Note that this only serves
- // as a simple example, most of the time dragging nodes is best done
- // with the PDragEventHandler, but this shows another way to do it.
- //
- // Note that each of these methods marks the event as handled. This is so that
- // when the node is being dragged the zoom and pan event handles
- // (that are installed by default) do not also operate, but they will
- // still respond to events that are not handled by the node. (try to uncomment
- // the aEvent.setHandled() calls and see what happens.
- final PNode aNode = new PNode();
- aNode.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- aNode.setPaint(Color.orange);
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- public void mouseDragged(PInputEvent aEvent) {
- Dimension2D delta = aEvent.getDeltaRelativeTo(aNode);
- aNode.translate(delta.getWidth(), delta.getHeight());
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- aNode.setPaint(Color.green);
- printEventCoords(aEvent);
- aEvent.setHandled(true);
- }
-
- // Note this slows things down a lot, comment it out to see how the normal
- // speed of things is.
- //
- // For fun the coords of each event that the node handles are printed out.
- // This can help to understand how coordinate systems work. Notice that when
- // the example first starts all the values for (canvas, global, and local) are
- // equal. But once you drag the node then the local coordinates become different
- // then the screen and global coordinates. When you pan or zoom then the screen
- // coordinates become different from the global coordinates.
- public void printEventCoords(PInputEvent aEvent) {
- System.out.println("Canvas Location: " + aEvent.getCanvasPosition());
- //System.out.println("Global Location: " + aEvent.getGlobalLocation());
- System.out.println("Local Location: " + aEvent.getPositionRelativeTo(aNode));
- System.out.println("Canvas Delta: " + aEvent.getCanvasDelta());
- //System.out.println("Global Delta: " + aEvent.getGlobalDelta());
- System.out.println("Local Delta: " + aEvent.getDeltaRelativeTo(aNode));
- }
- });
- aNode.setBounds(0, 0, 200, 200);
- aNode.setPaint(Color.green);
-
- // By default the filter accepts all events, but here we constrain the kinds of
- // events that aNode receives to button 1 events. Comment this line out and then
- // you will be able to drag the node with any mouse button.
- //aNode.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
-
- // add another node to the canvas that does not handle events as a reference
- // point, so that we can make sure that our green node is getting dragged.
- layer.addChild(PPath.createRectangle(0, 0, 100, 80));
- layer.addChild(aNode);
- }
-
- public static void main(String[] args) {
- new NodeEventExample();
- }
-}
-
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java b/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java
deleted file mode 100755
index 033467e..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/NodeExample.java
+++ /dev/null
@@ -1,222 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Line2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PImage;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to create and manipulate nodes.
- */
-public class NodeExample extends PFrame {
-
- boolean fIsPressed = false;
-
- public NodeExample() {
- this(null);
- }
-
- public NodeExample(PCanvas aCanvas) {
- super("NodeExample", false, aCanvas);
- }
-
- public void initialize() {
- nodeDemo();
- createNodeUsingExistingClasses();
- subclassExistingClasses();
- composeOtherNodes();
- createCustomNode();
-
- // Last of all lets remove the default pan event handler, and add a
- // drag event handler instead. This way you will be able to drag the
- // nodes around with the mouse.
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- // This method demonstrates the kinds of things that can be done with any node.
- public void nodeDemo() {
- PLayer layer = getCanvas().getLayer();
- PNode aNode = PPath.createRectangle(0, 0, 100, 80);
-
- // A node needs to be a descendent of the root to be displayed on the screen.
- layer.addChild(aNode);
-
- // The default color for a node is blue, but you can change that with
- // the setPaint method.
- aNode.setPaint(Color.red);
-
- // A node can have children nodes added to it.
- aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
-
- // The base bounds of a node is easy to change. Note that changing the base
- // bounds of a node will not change it's children.
- aNode.setBounds(-10, -10, 200, 110);
-
- // Each node has a transform that can be used to transform the node, and
- // all its children on the screen.
- aNode.translate(100, 100);
- aNode.scale(1.5);
- aNode.rotate(45);
-
- // The transparency of any node can be set, this transparency will be
- // applied to any of the nodes children as well.
- aNode.setTransparency(0.75f);
-
- // Its easy to copy nodes.
- PNode aCopy = (PNode) aNode.clone();
-
- // Make is so that the copies children are not pickable. For this example
- // that means you will not be able to grab the child and remove it from
- // its parent.
- aNode.setChildrenPickable(false);
-
- // Change the look of the copy
- aNode.setPaint(Color.GREEN);
- aNode.setTransparency(1.0f);
-
- // Let's add the copy to the root, and translate it so that it does not
- // cover the original node.
- layer.addChild(aCopy);
- aCopy.setOffset(0, 0);
- aCopy.rotate(-45);
- }
-
- // So far we have just been using PNode, but of course PNode has many
- // subclasses that you can try out to.
- public void createNodeUsingExistingClasses() {
- PLayer layer = getCanvas().getLayer();
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
-
- // Here we create an image node that displays a thumbnail
- // image of the root node. Note that you can easily get a thumbnail
- // of any node by using PNode.toImage().
- PImage image = new PImage(layer.toImage(300, 300, null));
- layer.addChild(image);
- }
-
- // Another way to create nodes is to customize other nodes that already
- // exist. Here we create an ellipse, except when you press the mouse on
- // this ellipse it turns into a square, when you release the mouse it
- // goes back to being an ellipse.
- public void subclassExistingClasses() {
- final PNode n = new PPath(new Ellipse2D.Float(0, 0, 100, 80)) {
-
- public void paint(PPaintContext aPaintContext) {
- if (fIsPressed) {
- // if mouse is pressed draw self as a square.
- Graphics2D g2 = aPaintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- // if mouse is not pressed draw self normally.
- super.paint(aPaintContext);
- }
- }
- };
-
- n.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = true;
- n.invalidatePaint(); // this tells the framework that the node needs to be redisplayed.
- }
-
- public void mouseReleased(PInputEvent aEvent) {
- super.mousePressed(aEvent);
- fIsPressed = false;
- n.invalidatePaint(); // this tells the framework that the node needs to be redisplayed.
- }
- });
-
- n.setPaint(Color.ORANGE);
- getCanvas().getLayer().addChild(n);
- }
-
- // Here a new "face" node is created. But instead of drawing the face directly
- // using Graphics2D we compose the face from other nodes.
- public void composeOtherNodes() {
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
-
- // add the face parts
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
-
- // don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
-
- // position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
-
- // set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- myCompositeFace.setBounds(b.inset(-5, -5));
-
- // opps it to small, so scale it up.
- myCompositeFace.scale(1.5);
-
- getCanvas().getLayer().addChild(myCompositeFace);
- }
-
- // Here a completely new kind of node, a grid node" is created. We do
- // all the drawing ourselves here instead of passing the work off to
- // other parts of the framework.
- public void createCustomNode() {
- PNode n = new PNode() {
- public void paint(PPaintContext aPaintContext) {
- double bx = getX();
- double by = getY();
- double rightBorder = bx + getWidth();
- double bottomBorder = by + getHeight();
-
- Line2D line = new Line2D.Double();
- Graphics2D g2 = aPaintContext.getGraphics();
-
- g2.setStroke(new BasicStroke(0));
- g2.setPaint(getPaint());
-
- // draw vertical lines
- for (double x = bx; x < rightBorder; x += 5) {
- line.setLine(x, by, x, bottomBorder);
- g2.draw(line);
- }
-
- for (double y = by; y < bottomBorder; y += 5) {
- line.setLine(bx, y, rightBorder, y);
- g2.draw(line);
- }
- }
- };
- n.setBounds(0, 0, 100, 80);
- n.setPaint(Color.black);
- getCanvas().getLayer().addChild(n);
- }
-
- public static void main(String[] args) {
- new NodeExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java b/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java
deleted file mode 100755
index d22df55..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/NodeLinkExample.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.geom.Line2D;
-import java.awt.geom.Point2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * Simple example showing one way to create a link between two nodes.
- *
- * @author Jesse Grosjean
- */
-public class NodeLinkExample extends PFrame {
-
- PNode node1;
- PNode node2;
- PPath link;
-
- public NodeLinkExample() {
- this(null);
- }
-
- public NodeLinkExample(PCanvas aCanvas) {
- super("NodeLinkExample", false, aCanvas);
- }
-
- public void initialize() {
- PCanvas canvas = getCanvas();
-
- canvas.removeInputEventListener(canvas.getPanEventHandler());
- canvas.addInputEventListener(new PDragEventHandler());
-
- PNode layer = canvas.getLayer();
-
- node1 = PPath.createEllipse(0, 0, 100, 100);
- node2 = PPath.createEllipse(0, 0, 100, 100);
- link = PPath.createLine(50, 50, 50, 50);
- link.setPickable(false);
- layer.addChild(node1);
- layer.addChild(node2);
- layer.addChild(link);
-
- node2.translate(200, 200);
-
- node1.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- updateLink();
- }
- });
-
- node2.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- updateLink();
- }
- });
- }
-
- public void updateLink() {
- Point2D p1 = node1.getFullBoundsReference().getCenter2D();
- Point2D p2 = node2.getFullBoundsReference().getCenter2D();
- Line2D line = new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY());
- link.setPathTo(line);
- }
-
- public static void main(String[] args) {
- new NodeLinkExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
deleted file mode 100755
index 8dd7ba7..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PSwingExample.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.pswing.PSwing;
-import edu.umd.cs.piccolox.pswing.PSwingCanvas;
-
-import javax.swing.*;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-/**
- * Demonstrates the use of PSwing in a Piccolo application.
- */
-
-public class PSwingExample extends PFrame {
-
- public PSwingExample() {
- this( new PSwingCanvas() );
- }
-
- public PSwingExample( PCanvas aCanvas ) {
- super( "PSwingExample", false, aCanvas );
- }
-
- public void initialize() {
- PSwingCanvas pswingCanvas = (PSwingCanvas)getCanvas();
- PLayer l = pswingCanvas.getLayer();
-
- JSlider js = new JSlider( 0, 100 );
- js.addChangeListener( new ChangeListener() {
- public void stateChanged( ChangeEvent e ) {
- System.out.println( "e = " + e );
- }
- } );
- js.setBorder( BorderFactory.createTitledBorder( "Test JSlider" ) );
- PSwing pSwing = new PSwing( js );
- pSwing.translate( 100, 100 );
- l.addChild( pSwing );
-
- pswingCanvas.setPanEventHandler( null );
- }
-
- public static void main( String[] args ) {
- new PSwingExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
deleted file mode 100755
index 24a738f..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PanToExample.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.util.Random;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * Click on a node and the camera will pan the minimum distance to bring that node fully into
- * the cameras view.
- */
-public class PanToExample extends PFrame {
-
- public PanToExample() {
- this(null);
- }
-
- public PanToExample(PCanvas aCanvas) {
- super("PanToExample", false, aCanvas);
- }
-
- public void initialize() {
-
- PPath eacha = PPath.createRectangle(50, 50, 300, 300);
- eacha.setPaint(Color.red);
- getCanvas().getLayer().addChild(eacha);
-
- eacha = PPath.createRectangle(-50, -50, 100, 100);
- eacha.setPaint(Color.green);
- getCanvas().getLayer().addChild(eacha);
-
- eacha = PPath.createRectangle(350, 350, 100, 100);
- eacha.setPaint(Color.green);
- getCanvas().getLayer().addChild(eacha);
-
-
- getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- if (!(event.getPickedNode() instanceof PCamera)) {
- event.setHandled(true);
- getCanvas().getCamera().animateViewToPanToBounds(event.getPickedNode().getGlobalFullBounds(), 500);
- }
- }
- });
-
- PLayer layer = getCanvas().getLayer();
-
- Random random = new Random();
- for (int i = 0; i < 1000; i++) {
- PPath each = PPath.createRectangle(0, 0, 100, 80);
- each.scale(random.nextFloat() * 2);
- each.offset(random.nextFloat() * 10000, random.nextFloat() * 10000);
- each.setPaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- each.setStroke(new BasicStroke(1 + (10 * random.nextFloat())));
- each.setStrokePaint(new Color(random.nextFloat(),random.nextFloat(),random.nextFloat()));
- layer.addChild(each);
- }
-
-
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
- }
-
- public static void main(String[] args) {
- new PanToExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
deleted file mode 100755
index 14e5b95..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PathExample.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PStickyHandleManager;
-import edu.umd.cs.piccolox.util.PFixedWidthStroke;
-
-public class PathExample extends PFrame {
-
- public PathExample() {
- this(null);
- }
-
- public PathExample(PCanvas aCanvas) {
- super("PathExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath n1 = PPath.createRectangle(0, 0, 100, 80);
- PPath n2 = PPath.createEllipse(100, 100, 200, 34);
- PPath n3 = new PPath();
- n3.moveTo(0, 0);
- n3.lineTo(20, 40);
- n3.lineTo(10, 200);
- n3.lineTo(155.444f, 33.232f);
- n3.closePath();
- n3.setPaint(Color.yellow);
-
- n1.setStroke(new BasicStroke(5));
- n1.setStrokePaint(Color.red);
- n2.setStroke(new PFixedWidthStroke());
- n3.setStroke(new PFixedWidthStroke());
-// n3.setStroke(null);
-
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
- getCanvas().getLayer().addChild(n3);
-
- // create a set of bounds handles for reshaping n3, and make them
- // sticky relative to the getCanvas().getCamera().
- new PStickyHandleManager(getCanvas().getCamera(), n3);
-
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(new PDragEventHandler());
- }
-
- public static void main(String[] args) {
- new PathExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
deleted file mode 100755
index 94d698a..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PositionExample.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-public class PositionExample extends PFrame {
-
- public PositionExample() {
- this(null);
- }
-
- public PositionExample(PCanvas aCanvas) {
- super("PositionExample", false, aCanvas);
- }
-
- public void initialize() {
- PNode n1 = PPath.createRectangle(0, 0, 100, 80);
- PNode n2 = PPath.createRectangle(0, 0, 100, 80);
-
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
-
- n2.scale(2.0);
- n2.rotate(Math.toRadians(90));
- //n2.setScale(2.0);
- //n2.setScale(1.0);
- n2.scale(0.5);
- n2.setPaint(Color.red);
-
- n1.offset(100, 0);
- n2.offset(100, 0);
- }
-
- public static void main(String[] args) {
- new PositionExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
deleted file mode 100755
index 9f6dfdc..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PositionPathActivityExample.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.geom.Arc2D;
-import java.awt.geom.GeneralPath;
-
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.activities.PPositionPathActivity;
-
-/**
- * This example shows how create a simple acitivty to animate a node along a
- * general path.
- */
-public class PositionPathActivityExample extends PFrame {
-
- public PositionPathActivityExample() {
- super();
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
- final PNode animatedNode = PPath.createRectangle(0, 0, 100, 80);
- layer.addChild(animatedNode);
-
- // create animation path
- GeneralPath path = new GeneralPath();
- path.moveTo(0, 0);
- path.lineTo(300, 300);
- path.lineTo(300, 0);
- path.append(new Arc2D.Float(0, 0, 300, 300, 90, -90, Arc2D.OPEN), true);
- path.closePath();
-
- // create node to display animation path
- PPath ppath = new PPath(path);
- layer.addChild(ppath);
-
- // create activity to run animation.
- PPositionPathActivity positionPathActivity = new PPositionPathActivity(5000, 0, new PPositionPathActivity.Target() {
- public void setPosition(double x, double y) {
- animatedNode.setOffset(x, y);
- }
- });
-// positionPathActivity.setSlowInSlowOut(false);
- positionPathActivity.setPositions(path);
- positionPathActivity.setLoopCount(Integer.MAX_VALUE);
-
- // add the activity.
- animatedNode.addActivity(positionPathActivity);
- }
-
- public static void main(String[] args) {
- new PositionPathActivityExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java b/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
deleted file mode 100755
index 1b1fee4..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/PulseExample.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.activities.PActivityScheduler;
-import edu.umd.cs.piccolo.activities.PColorActivity;
-import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to set up interpolating activities that repeat. For
- * example it shows how to create a rectangle whos color pulses.
- *
- * @author jesse
- */
-public class PulseExample extends PFrame {
-
- public PulseExample() {
- this(null);
- }
-
- public PulseExample(PCanvas aCanvas) {
- super("PulseExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PLayer layer = getCanvas().getLayer();
- PActivityScheduler scheduler = root.getActivityScheduler();
-
- final PNode singlePulse = PPath.createRectangle(0, 0, 100, 80);
- final PPath repeatePulse = PPath.createRectangle(100, 80, 100, 80);
- final PNode repeateReversePulse = PPath.createRectangle(200, 160, 100, 80);
-
- layer.addChild(singlePulse);
- layer.addChild(repeatePulse);
- layer.addChild(repeateReversePulse);
-
- // animate from source to destination color in one second,
- PColorActivity singlePulseActivity = new PColorActivity(1000, 0, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) singlePulse.getPaint();
- }
- public void setColor(Color color) {
- singlePulse.setPaint(color);
- }
- }, Color.ORANGE);
-
- // animate from source to destination color in one second, loop 5 times
- PColorActivity repeatPulseActivity = new PColorActivity(1000, 0, 5, PInterpolatingActivity.SOURCE_TO_DESTINATION, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) repeatePulse.getPaint();
- }
- public void setColor(Color color) {
- repeatePulse.setPaint(color);
- }
- }, Color.BLUE);
-
- // animate from source to destination to source color in one second, loop 10 times
- PColorActivity repeatReversePulseActivity = new PColorActivity(500, 0, 10, PInterpolatingActivity.SOURCE_TO_DESTINATION_TO_SOURCE, new PColorActivity.Target() {
- public Color getColor() {
- return (Color) repeateReversePulse.getPaint();
- }
- public void setColor(Color color) {
- repeateReversePulse.setPaint(color);
- }
- }, Color.GREEN);
-
- scheduler.addActivity(singlePulseActivity);
- scheduler.addActivity(repeatPulseActivity);
- scheduler.addActivity(repeatReversePulseActivity);
- }
-
- public static void main(String[] args) {
- new PulseExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java b/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
deleted file mode 100755
index 1d3a0a5..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/ScrollingExample.java
+++ /dev/null
@@ -1,223 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.Iterator;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JToggleButton;
-import javax.swing.JToolBar;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.swing.PDefaultScrollDirector;
-import edu.umd.cs.piccolox.swing.PScrollDirector;
-import edu.umd.cs.piccolox.swing.PScrollPane;
-import edu.umd.cs.piccolox.swing.PViewport;
-
-/**
- * This creates a simple scene and allows switching between
- * traditional scrolling where the scrollbars control the view
- * and alternate scrolling where the scrollbars control the
- * document. In laymans terms - in traditional window scrolling the stuff
- * in the window moves in the opposite direction of the scroll bars and in
- * document scrolling the stuff moves in the same direction as the scrollbars.
- *
- * Toggle buttons are provided to toggle between these two types
- * of scrolling.
- *
- * @author Lance Good
- * @author Ben Bederson
- */
-public class ScrollingExample extends PFrame {
-
- public ScrollingExample() {
- this(null);
- }
-
- public ScrollingExample(PCanvas aCanvas) {
- super("ScrollingExample", false, aCanvas);
- }
-
- public void initialize() {
- final PCanvas canvas = getCanvas();
-
- final PScrollPane scrollPane = new PScrollPane(canvas);
- getContentPane().add(scrollPane);
-
- final PViewport viewport = (PViewport) scrollPane.getViewport();
- final PScrollDirector windowSD = viewport.getScrollDirector();
- final PScrollDirector documentSD = new DocumentScrollDirector();
-
- // Make some rectangles on the surface so we can see where we are
- for (int x = 0; x < 20; x++) {
- for (int y = 0; y < 20; y++) {
- if (((x + y) % 2) == 0) {
- PPath path = PPath.createRectangle(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- else if (((x + y) % 2) == 1) {
- PPath path = PPath.createEllipse(50 * x, 50 * y, 40, 40);
- path.setPaint(Color.blue);
- path.setStrokePaint(Color.black);
- canvas.getLayer().addChild(path);
- }
- }
- }
-
- // Now, create the toolbar
- JToolBar toolBar = new JToolBar();
- JToggleButton window = new JToggleButton("Window Scrolling");
- JToggleButton document = new JToggleButton("Document Scrolling");
- ButtonGroup bg = new ButtonGroup();
- bg.add(window);
- bg.add(document);
- toolBar.add(window);
- toolBar.add(document);
- toolBar.setFloatable(false);
- window.setSelected(true);
- window.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- viewport.setScrollDirector(windowSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- }
- });
- document.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- viewport.setScrollDirector(documentSD);
- viewport.fireStateChanged();
- scrollPane.revalidate();
- }
- });
- getContentPane().add(toolBar, BorderLayout.NORTH);
-
- getContentPane().validate();
- }
-
- /**
- * A modified scroll director that performs document based scroling
- * rather than window based scrolling (ie. the scrollbars act in
- * the inverse direction as normal)
- */
- public class DocumentScrollDirector extends PDefaultScrollDirector {
-
- /**
- * Get the View position given the specified camera bounds - modified
- * such that:
- *
- * Rather than finding the distance from the upper left corner
- * of the window to the upper left corner of the document -
- * we instead find the distance from the lower right corner
- * of the window to the upper left corner of the document
- * THEN we subtract that value from total document width so
- * that the position is inverted
- *
- * @param viewBounds The bounds for which the view position will be computed
- * @return The view position
- */
- public Point getViewPosition(Rectangle2D viewBounds) {
- Point pos = new Point();
- if (camera != null) {
- // First we compute the union of all the layers
- PBounds layerBounds = new PBounds();
- java.util.List layers = camera.getLayersReference();
- for (Iterator i = layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
-
- // Rather than finding the distance from the upper left corner
- // of the window to the upper left corner of the document -
- // we instead find the distance from the lower right corner
- // of the window to the upper left corner of the document
- // THEN we measure the offset from the lower right corner
- // of the document
- pos.setLocation(
- (int) (layerBounds.getWidth() - (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5),
- (int) (layerBounds.getHeight() - (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
- }
-
- return pos;
-
- }
-
- /**
- * We do the same thing we did in getViewPosition above to flip the
- * document-window position relationship
- *
- * @param x The new x position
- * @param y The new y position
- */
- public void setViewPosition(double x, double y) {
- if (camera != null) {
- // If a scroll is in progress - we ignore new scrolls -
- // if we didn't, since the scrollbars depend on the camera location
- // we can end up with an infinite loop
- if (!scrollInProgress) {
- scrollInProgress = true;
-
- // Get the union of all the layers' bounds
- PBounds layerBounds = new PBounds();
- java.util.List layers = camera.getLayersReference();
- for (Iterator i = layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer) i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds,layerBounds);
-
- // Union the camera view bounds
- PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates -
- // This is basically the distance from the lower right
- // corner of the window to the upper left corner of the
- // document
- // We then measure the offset from the lower right corner
- // of the document
- Point2D newPoint =
- new Point2D.Double(
- layerBounds.getX() + layerBounds.getWidth() - (x + viewBounds.getWidth()),
- layerBounds.getY() + layerBounds.getHeight() - (y + viewBounds.getHeight()));
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- double newX = - (at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- double newY = - (at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
- }
- }
- }
-
- public static void main(String[] args) {
- new ScrollingExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java b/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
deleted file mode 100755
index 5e120eb..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/SelectionExample.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.event.PNotification;
-import edu.umd.cs.piccolox.event.PNotificationCenter;
-import edu.umd.cs.piccolox.event.PSelectionEventHandler;
-
-/**
- * This example shows how the selection event handler works.
- * It creates a bunch of objects that can be selected.
- */
-public class SelectionExample extends PFrame {
-
- public SelectionExample() {
- this(null);
- }
-
- public SelectionExample(PCanvas aCanvas) {
- super("SelectionExample", false, aCanvas);
- }
-
- public void initialize() {
- for (int i=0; i<5; i++) {
- for (int j=0; j<5; j++) {
- PNode rect = PPath.createRectangle(i*60, j*60, 50, 50);
- rect.setPaint(Color.blue);
- getCanvas().getLayer().addChild(rect);
- }
- }
-
- // Turn off default navigation event handlers
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
-
- // Create a selection event handler
- PSelectionEventHandler selectionEventHandler = new PSelectionEventHandler(getCanvas().getLayer(), getCanvas().getLayer());
- getCanvas().addInputEventListener(selectionEventHandler);
- getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(selectionEventHandler);
-
- PNotificationCenter.defaultCenter().addListener(this,
- "selectionChanged",
- PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION,
- selectionEventHandler);
- }
-
- public void selectionChanged(PNotification notfication) {
- System.out.println("selection changed");
- }
-
- public static void main(String[] args) {
- new SelectionExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java b/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
deleted file mode 100755
index fbfa5ed..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/SliderExample.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolox.pswing.PSwing;
-import edu.umd.cs.piccolox.pswing.PSwingCanvas;
-import edu.umd.cs.piccolox.swing.PScrollPane;
-
-import javax.swing.*;
-import javax.swing.border.EmptyBorder;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-
-/**
- * Tests a set of Sliders and Checkboxes in panels.
- *
- * @author Martin Clifford
- */
-public class SliderExample extends JFrame {
- private PSwingCanvas canvas;
- private PScrollPane scrollPane;
- private JTabbedPane tabbedPane;
- private PSwing swing;
-
- public SliderExample() {
- // Create main panel
- JPanel mainPanel = new JPanel( false );
- // Create a tabbed pane
- tabbedPane = new JTabbedPane();
- tabbedPane.setPreferredSize( new Dimension( 700, 700 ) );
- // Add tabbed pane to main panel
- mainPanel.add( tabbedPane );
- // Set the frame contents
- getContentPane().add( mainPanel );
-
- // Create a canvas
- canvas = new PSwingCanvas();
- canvas.setPreferredSize( new Dimension( 700, 700 ) );
- // Create a scroll pane for the canvas
- scrollPane = new PScrollPane( canvas );
- // Create a new tab for the tabbed pane
- tabbedPane.add( "Tab 1", scrollPane );
-
- // Create the contents for "Tab 1"
- JPanel tabPanel = new JPanel( false );
- tabPanel.setLayout( null );
- tabPanel.setPreferredSize( new Dimension( 700, 700 ) );
- // Populate the tab panel with four instances of nested panel.
- JPanel panel;
- panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 0, 0 );
- tabPanel.add( panel );
- panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 0, 350 );
- tabPanel.add( panel );
- panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 350, 0 );
- tabPanel.add( panel );
- panel = createNestedPanel();
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setLocation( 350, 350 );
- tabPanel.add( panel );
- // Add the default zoom button
- JButton buttonPreset = new JButton( "Zoom = 100%" );
- buttonPreset.addActionListener( new ActionListener() {
- public void actionPerformed( ActionEvent e ) {
- canvas.getCamera().setViewScale( 1.0 );
- canvas.getCamera().setViewOffset( 0, 0 );
- }
- } );
- buttonPreset.setSize( new Dimension( 120, 25 ) );
- buttonPreset.setLocation( 240, 285 );
- tabPanel.add( buttonPreset );
- // Create a pswing object for the tab panel
- swing = new PSwing( tabPanel );
- swing.translate( 0, 0 );
- // Add the pswing object to the canvas
- canvas.getLayer().addChild( swing );
- // Turn off default pan event handling
- canvas.setPanEventHandler( null );
-
- // Set up basic frame
- setDefaultCloseOperation( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
- setTitle( "Slider Example" );
- setResizable( true );
- setBackground( null );
- pack();
- setVisible( true );
- }
-
- private JPanel createNestedPanel() {
- // A panel MUST be created with double buffering off
- JPanel panel;
- JLabel label;
- panel = new JPanel( false );
- panel.setLayout( new BorderLayout() );
- label = new JLabel( "A Panel within a panel" );
- label.setHorizontalAlignment( SwingConstants.CENTER );
- label.setForeground( Color.white );
- JLabel label2 = new JLabel( "A Panel within a panel" );
- label2.setHorizontalAlignment( SwingConstants.CENTER );
- JSlider slider = new JSlider();
- JCheckBox cbox1 = new JCheckBox( "Checkbox 1" );
- JCheckBox cbox2 = new JCheckBox( "Checkbox 2" );
- JPanel panel3 = new JPanel( false );
- panel3.setLayout( new BoxLayout( panel3, BoxLayout.PAGE_AXIS ) );
- panel3.setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
- panel3.add( label2 );
- panel3.add( slider );
- panel3.add( cbox1 );
- panel3.add( cbox2 );
- JPanel panel2 = new JPanel( false );
- panel2.setBackground( Color.blue );
- panel.setBorder( new EmptyBorder( 1, 1, 1, 1 ) );
- panel2.add( label );
- panel2.add( panel3 );
- panel.setBackground( Color.red );
- panel.setSize( new Dimension( 250, 250 ) );
- panel.setBorder( new EmptyBorder( 5, 5, 5, 5 ) );
- panel.add( panel2, "Center" );
- panel.revalidate();
- return panel;
- }
-
- public static void main( String[] args ) {
- SwingUtilities.invokeLater( new Runnable() {
- public void run() {
- new SliderExample();
- }
- } );
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java b/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
deleted file mode 100755
index bfc8b77..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/SquiggleExample.java
+++ /dev/null
@@ -1,75 +0,0 @@
-
-package edu.umd.cs.piccolo.examples;
-import java.awt.BasicStroke;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-public class SquiggleExample extends PFrame {
-
- private PLayer layer;
-
- public SquiggleExample() {
- this(null);
- }
-
- public SquiggleExample(PCanvas aCanvas) {
- super("SquiggleExample", false, aCanvas);
- }
-
- public void initialize() {
- super.initialize();
- PBasicInputEventHandler squiggleEventHandler = createSquiggleEventHandler();
- squiggleEventHandler.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- getCanvas().addInputEventListener(squiggleEventHandler);
- layer = getCanvas().getLayer();
- }
-
- public PBasicInputEventHandler createSquiggleEventHandler() {
- return new PDragSequenceEventHandler() {
-
- protected PPath squiggle;
-
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
-
- Point2D p = e.getPosition();
-
- squiggle = new PPath();
- squiggle.moveTo((float)p.getX(), (float)p.getY());
- squiggle.setStroke(new BasicStroke((float)(1/ e.getCamera().getViewScale())));
- layer.addChild(squiggle);
- }
-
- public void drag(PInputEvent e) {
- super.drag(e);
- updateSquiggle(e);
- }
-
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(PInputEvent aEvent) {
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float)p.getX(), (float)p.getY());
- }
- };
- }
-
- public static void main(String[] args) {
- new SquiggleExample();
- }
-}
-
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java b/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
deleted file mode 100755
index 4de65ff..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/StickyExample.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-
-public class StickyExample extends PFrame {
-
- public StickyExample() {
- this(null);
- }
-
- public StickyExample(PCanvas aCanvas) {
- super("StickyExample", false, aCanvas);
- }
-
- public void initialize() {
- PPath sticky = PPath.createRectangle(0, 0, 50, 50);
- sticky.setPaint(Color.YELLOW);
- sticky.setStroke(null);
- PBoundsHandle.addBoundsHandlesTo(sticky);
- getCanvas().getLayer().addChild(PPath.createRectangle(0, 0, 100, 80));
- getCanvas().getCamera().addChild(sticky);
- }
-
- public static void main(String[] args) {
- new StickyExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java b/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
deleted file mode 100755
index e22e606..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/StickyHandleLayerExample.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.Color;
-import java.util.Iterator;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-import edu.umd.cs.piccolox.handles.PHandle;
-import edu.umd.cs.piccolox.util.PBoundsLocator;
-
-/**
-* This example shows another way to create sticky handles. These handles are
- * not added as children to the object that they manipulate. Instead they are
- * added to the camera the views that objects. This means that they will not be
- * affected by the cameras view transform, and so will stay the same size when
- * the view is zoomed. They will also be drawn on top of all other objects, even
- * if those objects overlap the object that they manipulate. For this setup we
- * need to add and updateHandles activity that makes sure to relocate the handle
- * after any change. Another way to do this would be to add change listeners to
- * the camera and the node that they manipulate and only update them then. But
- * this method is easier and should be plenty efficient for normal use.
- *
- * @author jesse
- */
-public class StickyHandleLayerExample extends PFrame {
-
- public StickyHandleLayerExample() {
- this(null);
- }
-
- public StickyHandleLayerExample(PCanvas aCanvas) {
- super("StickyHandleLayerExample", false, aCanvas);
- }
-
- public void initialize() {
- PCanvas c = getCanvas();
-
- PActivity updateHandles = new PActivity(-1, 0) {
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- PRoot root = getActivityScheduler().getRoot();
-
- if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
- Iterator i = getCanvas().getCamera().getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (each instanceof PHandle) {
- PHandle handle = (PHandle) each;
- handle.relocateHandle();
- }
- }
- }
- }
- };
-
- PPath rect = PPath.createRectangle(0, 0, 100, 100);
- rect.setPaint(Color.RED);
- c.getLayer().addChild(rect);
-
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(rect)));
- c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(rect)));
-
- c.getRoot().getActivityScheduler().addActivity(updateHandles, true);
- }
-
- public static void main(String[] args) {
- new StickyHandleLayerExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java b/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
deleted file mode 100755
index f78c650..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/TextExample.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.event.PStyledTextEventHandler;
-
-/**
- * @author Lance Good
- */
-public class TextExample extends PFrame {
-
- public TextExample() {
- this(null);
- }
-
- public TextExample(PCanvas aCanvas) {
- super("TextExample", false, aCanvas);
- }
-
- public void initialize() {
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- PStyledTextEventHandler textHandler = new PStyledTextEventHandler(getCanvas());
- getCanvas().addInputEventListener(textHandler);
- }
-
- public static void main(String[] args) {
- new TextExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java b/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
deleted file mode 100755
index fad544b..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/TooltipExample.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * Simple example of one way to add tooltips
- *
- * @author jesse
- */
-public class TooltipExample extends PFrame {
-
- public TooltipExample() {
- this(null);
- }
-
- public TooltipExample(PCanvas aCanvas) {
- super("TooltipExample", false, aCanvas);
- }
-
- public void initialize() {
- PNode n1 = PPath.createEllipse(0, 0, 100, 100);
- PNode n2 = PPath.createRectangle(300, 200, 100, 100);
-
- n1.addAttribute("tooltip", "node 1");
- n2.addAttribute("tooltip", "node 2");
- getCanvas().getLayer().addChild(n1);
- getCanvas().getLayer().addChild(n2);
-
- final PCamera camera = getCanvas().getCamera();
- final PText tooltipNode = new PText();
-
- tooltipNode.setPickable(false);
- camera.addChild(tooltipNode);
-
- camera.addInputEventListener(new PBasicInputEventHandler() {
- public void mouseMoved(PInputEvent event) {
- updateToolTip(event);
- }
-
- public void mouseDragged(PInputEvent event) {
- updateToolTip(event);
- }
-
- public void updateToolTip(PInputEvent event) {
- PNode n = event.getInputManager().getMouseOver().getPickedNode();
- String tooltipString = (String) n.getAttribute("tooltip");
- Point2D p = event.getCanvasPosition();
-
- event.getPath().canvasToLocal(p, camera);
-
- tooltipNode.setText(tooltipString);
- tooltipNode.setOffset(p.getX() + 8,
- p.getY() - 8);
- }
- });
- }
-
- public static void main(String[] argv) {
- new TooltipExample();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java b/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
deleted file mode 100755
index 65afc6d..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/TwoCanvasExample.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import java.awt.Color;
-
-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.PRoot;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-
-public class TwoCanvasExample extends PFrame {
-
- public TwoCanvasExample() {
- this(null);
- }
-
- public TwoCanvasExample(PCanvas aCanvas) {
- super("TwoCanvasExample", false, aCanvas);
- }
-
- public void initialize() {
- PRoot root = getCanvas().getRoot();
- PLayer layer = getCanvas().getLayer();
-
- PNode n = PPath.createRectangle(0, 0, 100, 80);
- PNode sticky = PPath.createRectangle(0, 0, 50, 50);
- PBoundsHandle.addBoundsHandlesTo(n);
- sticky.setPaint(Color.YELLOW);
- PBoundsHandle.addBoundsHandlesTo(sticky);
-
- layer.addChild(n);
- getCanvas().getCamera().addChild(sticky);
-
- PCamera otherCamera = new PCamera();
- otherCamera.addLayer(layer);
- root.addChild(otherCamera);
-
- PCanvas other = new PCanvas();
- other.setCamera(otherCamera);
- PFrame result = new PFrame("TwoCanvasExample", false, other);
- result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- result.setLocation(500, 100);
- }
-
- public static void main(String[] args) {
- new TwoCanvasExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java b/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
deleted file mode 100755
index 5009e14..0000000
--- a/src/main/java/edu/umd/cs/piccolo/examples/WaitForActivitiesExample.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package edu.umd.cs.piccolo.examples;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolox.PFrame;
-
-/**
- * This example shows how to use setTriggerTime to synchronize the start and end of
- * two activities.
- */
-public class WaitForActivitiesExample extends PFrame {
-
- public WaitForActivitiesExample() {
- this(null);
- }
-
- public WaitForActivitiesExample(PCanvas aCanvas) {
- super("WaitForActivitiesExample", false, aCanvas);
- }
-
- public void initialize() {
- PLayer layer = getCanvas().getLayer();
-
- PNode a = PPath.createRectangle(0, 0, 100, 80);
- PNode b = PPath.createRectangle(0, 0, 100, 80);
-
- layer.addChild(a);
- layer.addChild(b);
-
- PActivity a1 = a.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
- PActivity a2 = b.animateToPositionScaleRotation(200, 200, 1, 0, 5000);
-
- a2.startAfter(a1);
- }
-
- public static void main(String[] args) {
- new WaitForActivitiesExample();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java b/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java
deleted file mode 100755
index c163d2b..0000000
--- a/src/main/java/edu/umd/cs/piccolo/nodes/PImage.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.nodes;
-
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.MediaTracker;
-import java.awt.Toolkit;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import javax.imageio.ImageIO;
-import javax.swing.ImageIcon;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * PImage is a wrapper around a java.awt.Image. If this node is copied or
- * serialized that image will be converted into a BufferedImage if it is not
- * already one.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PImage extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 5035231574212425854L;
- /**
- * The property name that identifies a change of this node's image (see
- * {@link #getImage getImage}). Both old and new value will be set correctly
- * to Image objects in any property change event.
- */
- public static final String PROPERTY_IMAGE = "image";
- public static final int PROPERTY_CODE_IMAGE = 1 << 15;
-
- private transient Image image;
-
- public PImage() {
- super();
- }
-
- /**
- * Construct a new PImage wrapping the given java.awt.Image.
- */
- public PImage(Image newImage) {
- this();
- setImage(newImage);
- }
-
- /**
- * Construct a new PImage by loading the given fileName and wrapping the
- * resulting java.awt.Image.
- */
- public PImage(String fileName) {
- this(Toolkit.getDefaultToolkit().getImage(fileName));
- }
-
- /**
- * Construct a new PImage by loading the given url and wrapping the
- * resulting java.awt.Image. If the url is null
, create an
- * empty PImage; this behaviour is useful when fetching resources that may
- * be missing.
- */
- public PImage(java.net.URL url) {
- this();
- if (url != null) setImage(Toolkit.getDefaultToolkit().getImage(url));
- }
-
- /**
- * Returns the image that is shown by this node.
- * @return the image that is shown by this node
- */
- public Image getImage() {
- return image;
- }
-
- /**
- * Set the image that is wrapped by this PImage node. This method will also
- * load the image using a MediaTracker before returning.
- */
- public void setImage(String fileName) {
- setImage(Toolkit.getDefaultToolkit().getImage(fileName));
- }
-
- /**
- * Set the image that is wrapped by this PImage node. This method will also
- * load the image using a MediaTracker before returning.
- */
- public void setImage(Image newImage) {
- Image old = image;
-
- if (newImage == null || newImage instanceof BufferedImage) {
- image = newImage;
- } else { // else make sure the image is loaded
- ImageIcon imageLoader = new ImageIcon(newImage);
- switch (imageLoader.getImageLoadStatus()) {
- case MediaTracker.LOADING:
- System.err.println("media tracker still loading image after requested to wait until finished");
-
- case MediaTracker.COMPLETE:
- image = imageLoader.getImage();
- break;
-
- case MediaTracker.ABORTED:
- System.err.println("media tracker aborted image load");
- image = null;
- break;
-
- case MediaTracker.ERRORED:
- System.err.println("media tracker errored image load");
- image = null;
- break;
- }
- }
-
- if (image != null) {
- setBounds(0, 0, getImage().getWidth(null), getImage().getHeight(null));
- invalidatePaint();
- } else {
- image = null;
- }
-
- firePropertyChange(PROPERTY_CODE_IMAGE, PROPERTY_IMAGE, old, image);
- }
-
- protected void paint(PPaintContext paintContext) {
- if (getImage() != null) {
- double iw = image.getWidth(null);
- double ih = image.getHeight(null);
- PBounds b = getBoundsReference();
- Graphics2D g2 = paintContext.getGraphics();
-
- if (b.x != 0 || b.y != 0 || b.width != iw || b.height != ih) {
- g2.translate(b.x, b.y);
- g2.scale(b.width / iw, b.height / ih);
- g2.drawImage(image, 0, 0, null);
- g2.scale(iw / b.width, ih / b.height);
- g2.translate(-b.x, -b.y);
- } else {
- g2.drawImage(image, 0, 0, null);
- }
- }
- }
-
- //****************************************************************
- // Serialization
- //****************************************************************
-
- /**
- * The java.awt.Image wrapped by this PImage is converted into a BufferedImage
- * when serialized.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- BufferedImage bufferedImage = toBufferedImage(image, false);
- if (bufferedImage != null) ImageIO.write(bufferedImage, "png", out);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- image = ImageIO.read(in);
- }
-
- //****************************************************************
- // Util
- //****************************************************************
-
- /**
- * If alwaysCreateCopy is false then if the image is already a buffered
- * image it will not be copied and instead the original image will just be
- * returned.
- */
- public static BufferedImage toBufferedImage(Image image, boolean alwaysCreateCopy) {
- if (image == null) return null;
-
- if (!alwaysCreateCopy && image instanceof BufferedImage) {
- return (BufferedImage) image;
- } else {
- GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- BufferedImage result = graphicsConfiguration.createCompatibleImage(image.getWidth(null), image.getHeight(null));
- Graphics2D g2 = result.createGraphics();
- g2.drawImage(image, 0, 0, null);
- g2.dispose();
- return result;
- }
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("image=" + (image == null ? "null" : image.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java b/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java
deleted file mode 100755
index 45650fe..0000000
--- a/src/main/java/edu/umd/cs/piccolo/nodes/PPath.java
+++ /dev/null
@@ -1,476 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.nodes;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RoundRectangle2D;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.activities.PColorActivity;
-import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * PPath is a wrapper around a java.awt.geom.GeneralPath. The
- * setBounds method works by scaling the path to fit into the specified
- * bounds. This normally works well, but if the specified base bounds
- * get too small then it is impossible to expand the path shape again since
- * all its numbers have tended to zero, so application code may need to take
- * this into consideration.
- *
- * One option that applications have is to call startResizeBounds
before
- * starting an interaction that may make the bounds very small, and calling
- * endResizeBounds
when this interaction is finished. When this is done
- * PPath will use a copy of the original path to do the resizing so the numbers
- * in the path wont loose resolution.
- *
- * This class also provides methods for constructing common shapes using a
- * general path.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PPath extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -7131557761746031134L;
- //ORIG private static final long serialVersionUID = 4992462752831480740L;
- /**
- * The property name that identifies a change of this node's stroke paint
- * (see {@link #getStrokePaint getStrokePaint}). Both old and new value will
- * be set correctly to Paint objects in any property change event.
- */
- public static final String PROPERTY_STROKE_PAINT = "strokePaint";
- public static final int PROPERTY_CODE_STROKE_PAINT = 1 << 16;
-
- /**
- * The property name that identifies a change of this node's stroke (see
- * {@link #getStroke getStroke}). Both old and new value will be set
- * correctly to Stroke objects in any property change event.
- */
- public static final String PROPERTY_STROKE = "stroke";
- public static final int PROPERTY_CODE_STROKE = 1 << 17;
-
- /**
- * The property name that identifies a change of this node's path (see
- * {@link #getPathReference getPathReference}). In any property change
- * event the new value will be a reference to this node's path, but old
- * value will always be null.
- */
- public static final String PROPERTY_PATH = "path";
- public static final int PROPERTY_CODE_PATH = 1 << 18;
-
- private static final Rectangle2D.Float TEMP_RECTANGLE = new Rectangle2D.Float();
- private static final RoundRectangle2D.Float TEMP_ROUNDRECTANGLE = new RoundRectangle2D.Float();
- private static final Ellipse2D.Float TEMP_ELLIPSE = new Ellipse2D.Float();
- private static final PAffineTransform TEMP_TRANSFORM = new PAffineTransform();
- private static final BasicStroke DEFAULT_STROKE = new BasicStroke(1.0f);
- private static final Color DEFAULT_STROKE_PAINT = Color.black;
-
- private transient GeneralPath path;
- private transient GeneralPath resizePath;
- private transient Stroke stroke;
- private transient boolean updatingBoundsFromPath;
- private Paint strokePaint;
-
- public static PPath createRectangle(float x, float y, float width, float height) {
- TEMP_RECTANGLE.setFrame(x, y, width, height);
- PPath result = new PPath(TEMP_RECTANGLE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PPath createRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight) {
- TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight);
- PPath result = new PPath(TEMP_ROUNDRECTANGLE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PPath createEllipse(float x, float y, float width, float height) {
- TEMP_ELLIPSE.setFrame(x, y, width, height);
- PPath result = new PPath(TEMP_ELLIPSE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PPath createLine(float x1, float y1, float x2, float y2) {
- PPath result = new PPath();
- result.moveTo(x1, y1);
- result.lineTo(x2, y2);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PPath createPolyline(Point2D[] points) {
- PPath result = new PPath();
- result.setPathToPolyline(points);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PPath createPolyline(float[] xp, float[] yp) {
- PPath result = new PPath();
- result.setPathToPolyline(xp, yp);
- result.setPaint(Color.white);
- return result;
- }
-
- public PPath() {
- strokePaint = DEFAULT_STROKE_PAINT;
- stroke = DEFAULT_STROKE;
- path = new GeneralPath();
- }
-
- public PPath(Shape aShape) {
- this(aShape, DEFAULT_STROKE);
- }
-
- /**
- * Construct this path with the given shape and stroke.
- * This method may be used to optimize the creation of a large number of
- * PPaths. Normally PPaths have a default stroke of width one, but when a
- * path has a non null stroke it takes significantly longer to compute its
- * bounds. This method allows you to override that default stroke before the
- * bounds are ever calculated, so if you pass in a null stroke here you
- * won't ever have to pay that bounds calculation price if you don't need
- * to.
- */
- public PPath(Shape aShape, Stroke aStroke) {
- this();
- stroke = aStroke;
- if (aShape != null) append(aShape, false);
- }
-
- //****************************************************************
- // Stroke
- //****************************************************************
-
- public Paint getStrokePaint() {
- return strokePaint;
- }
-
- public void setStrokePaint(Paint aPaint) {
- Paint old = strokePaint;
- strokePaint = aPaint;
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_STROKE_PAINT ,PROPERTY_STROKE_PAINT, old, strokePaint);
- }
-
- public Stroke getStroke() {
- return stroke;
- }
-
- public void setStroke(Stroke aStroke) {
- Stroke old = stroke;
- stroke = aStroke;
- updateBoundsFromPath();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_STROKE ,PROPERTY_STROKE, old, stroke);
- }
-
- //****************************************************************
- // Bounds
- //****************************************************************
-
- public void startResizeBounds() {
- resizePath = new GeneralPath(path);
- }
-
- public void endResizeBounds() {
- resizePath = null;
- }
-
- /**
- * Set the bounds of this path. This method works by scaling the path
- * to fit into the specified bounds. This normally works well, but if
- * the specified base bounds get too small then it is impossible to
- * expand the path shape again since all its numbers have tended to zero,
- * so application code may need to take this into consideration.
- */
- protected void internalUpdateBounds(double x, double y, double width, double height) {
- if (updatingBoundsFromPath) return;
- if (path == null) return;
-
- if (resizePath != null) {
- path.reset();
- path.append(resizePath, false);
- }
-
- Rectangle2D pathBounds = path.getBounds2D();
- Rectangle2D pathStrokeBounds = getPathBoundsWithStroke();
- double strokeOutset = Math.max(pathStrokeBounds.getWidth() - pathBounds.getWidth(),
- pathStrokeBounds.getHeight() - pathBounds.getHeight());
-
- x += strokeOutset / 2;
- y += strokeOutset / 2;
- width -= strokeOutset;
- height -= strokeOutset;
-
- double scaleX = (width == 0 || pathBounds.getWidth() == 0) ? 1 : width / pathBounds.getWidth();
- double scaleY = (height == 0 || pathBounds.getHeight() == 0) ? 1 : height / pathBounds.getHeight();
-
- TEMP_TRANSFORM.setToIdentity();
- TEMP_TRANSFORM.translate(x, y);
- TEMP_TRANSFORM.scale(scaleX, scaleY);
- TEMP_TRANSFORM.translate(-pathBounds.getX(), -pathBounds.getY());
-
- path.transform(TEMP_TRANSFORM);
- }
-
- public boolean intersects(Rectangle2D aBounds) {
- if (super.intersects(aBounds)) {
- if (getPaint() != null && path.intersects(aBounds)) {
- return true;
- } else if (stroke != null && strokePaint != null) {
- return stroke.createStrokedShape(path).intersects(aBounds);
- }
- }
- return false;
- }
-
- public Rectangle2D getPathBoundsWithStroke() {
- if (stroke != null) {
- return stroke.createStrokedShape(path).getBounds2D();
- } else {
- return path.getBounds2D();
- }
- }
-
- public void updateBoundsFromPath() {
- updatingBoundsFromPath = true;
- if (path == null) {
- resetBounds();
- } else {
- Rectangle2D b = getPathBoundsWithStroke();
- setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
- }
- updatingBoundsFromPath = false;
- }
-
- //****************************************************************
- // Painting
- //****************************************************************
-
- protected void paint(PPaintContext paintContext) {
- Paint p = getPaint();
- Graphics2D g2 = paintContext.getGraphics();
-
- if (p != null) {
- g2.setPaint(p);
- g2.fill(path);
- }
-
- if (stroke != null && strokePaint != null) {
- g2.setPaint(strokePaint);
- g2.setStroke(stroke);
- g2.draw(path);
- }
- }
-
- //****************************************************************
- // Path Support set java.awt.GeneralPath documentation for more
- // information on using these methods.
- //****************************************************************
-
- public GeneralPath getPathReference() {
- return path;
- }
-
- public void moveTo(float x, float y) {
- path.moveTo(x, y);
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void lineTo(float x, float y) {
- path.lineTo(x, y);
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void quadTo(float x1, float y1, float x2, float y2) {
- path.quadTo(x1, y1, x2, y2);
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
- path.curveTo(x1, y1, x2, y2, x3, y3);
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void append(Shape aShape, boolean connect) {
- path.append(aShape, connect);
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void setPathTo(Shape aShape) {
- path.reset();
- append(aShape, false);
- }
-
- public void setPathToRectangle(float x, float y, float width, float height) {
- TEMP_RECTANGLE.setFrame(x, y, width, height);
- setPathTo(TEMP_RECTANGLE);
- }
-
- public void setPathToEllipse(float x, float y, float width, float height) {
- TEMP_ELLIPSE.setFrame(x, y, width, height);
- setPathTo(TEMP_ELLIPSE);
- }
-
- public void setPathToPolyline(Point2D[] points) {
- path.reset();
- path.moveTo((float)points[0].getX(), (float)points[0].getY());
- for (int i = 1; i < points.length; i++) {
- path.lineTo((float)points[i].getX(), (float)points[i].getY());
- }
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void setPathToPolyline(float[] xp, float[] yp) {
- path.reset();
- path.moveTo(xp[0], yp[0]);
- for (int i = 1; i < xp.length; i++) {
- path.lineTo(xp[i], yp[i]);
- }
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void closePath() {
- path.closePath();
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void reset() {
- path.reset();
- firePropertyChange(PROPERTY_CODE_PATH, PROPERTY_PATH, null, path);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- //****************************************************************
- // Serialization
- //****************************************************************
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- PUtil.writeStroke(stroke, out);
- PUtil.writePath(path, out);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- stroke = PUtil.readStroke(in);
- path = PUtil.readPath(in);
- }
-
- /**
- * added by miura 2012/11/29
- * @param destColor
- * @param duration
- * @return
- */
- public PInterpolatingActivity animateToStrokeColor(final Color destColor, final long duration) {
- if (duration == 0) {
- setPaint(destColor);
- return null;
- }
- else {
- final PColorActivity.Target t = new PColorActivity.Target() {
- public Color getColor() {
- return (Color) getStrokePaint();
- }
-
- public void setColor(final Color color) {
- setStrokePaint(color);
- }
- };
-
- final PColorActivity ca = new PColorActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destColor);
- addActivity(ca);
- return ca;
- }
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("path=" + (path == null ? "null" : path.toString()));
- result.append(",stroke=" + (stroke == null ? "null" : stroke.toString()));
- result.append(",strokePaint=" + (strokePaint == null ? "null" : strokePaint.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/nodes/PText.java b/src/main/java/edu/umd/cs/piccolo/nodes/PText.java
deleted file mode 100755
index a098870..0000000
--- a/src/main/java/edu/umd/cs/piccolo/nodes/PText.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- on* Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.nodes;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.font.LineBreakMeasurer;
-import java.awt.font.TextAttribute;
-import java.awt.font.TextLayout;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.util.ArrayList;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * PText is a multi-line text node. The text will flow to base
- * on the width of the node's bounds.
- *
- * @version 1.1
- * @author Jesse Grosjean
- */
-public class PText extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -2140625156256285574L;
- /**
- * The property name that identifies a change of this node's text (see
- * {@link #getText getText}). Both old and new value will be set in any
- * property change event.
- */
- public static final String PROPERTY_TEXT = "text";
- public static final int PROPERTY_CODE_TEXT = 1 << 19;
-
- /**
- * The property name that identifies a change of this node's font (see
- * {@link #getFont getFont}). Both old and new value will be set in any
- * property change event.
- */
- public static final String PROPERTY_FONT = "font";
- public static final int PROPERTY_CODE_FONT = 1 << 20;
-
- public static Font DEFAULT_FONT = new Font("Helvetica", Font.PLAIN, 12);
- public static double DEFAULT_GREEK_THRESHOLD = 5.5;
-
- public static int NO_WRAP = 1; // Bounds gets set to text
- public static int WRAP = 2; // Set width, height gets calculated, text wraps
- public static int WRAP_CLIP = 3; // Set width and height, text wraps and gets clipped off bottom
-
- private String text;
- private Paint textPaint;
- private Font font;
- protected double greekThreshold = DEFAULT_GREEK_THRESHOLD;
- private float justification = javax.swing.JLabel.LEFT_ALIGNMENT;
- private boolean constrainHeightToTextHeight = true;
- private boolean constrainWidthToTextWidth = true;
- private transient TextLayout[] lines;
-
- public PText() {
- super();
- setTextPaint(Color.BLACK);
- }
-
- public PText(String aText) {
- this();
- setText(aText);
- }
-
- /**
- * Return the justificaiton of the text in the bounds.
- * @return float
- */
- public float getJustification() {
- return justification;
- }
-
- /**
- * Sets the justificaiton of the text in the bounds.
- * @param just
- */
- public void setJustification(float just) {
- justification = just;
- recomputeLayout();
- }
-
- /**
- * Get the paint used to paint this nodes text.
- * @return Paint
- */
- public Paint getTextPaint() {
- return textPaint;
- }
-
- /**
- * Set the paint used to paint this node's text background.
- * @param textPaint
- */
- public void setTextPaint(Paint textPaint) {
- this.textPaint = textPaint;
- invalidatePaint();
- }
-
- /**
- * Determines how bounds get set and how text wraps within bounds
- * NO_WRAP Bounds gets set to text
- * WRAP Set width, height gets calculated, text wraps
- * WRAP_CLIP Set width and height, text wraps and gets clipped off bottom
- * @param wrapMode
- */
- public void setWrapMode(int wrapMode) {
- if (wrapMode == NO_WRAP) {
- constrainWidthToTextWidth = false;
- constrainHeightToTextHeight = false;
- } else if (wrapMode == WRAP) {
- constrainWidthToTextWidth = true;
- constrainHeightToTextHeight = true;
- } else if (wrapMode == WRAP_CLIP){
- constrainWidthToTextWidth = false;
- constrainHeightToTextHeight = true;
- }
- recomputeLayout();
- }
-
- /**
- * @deprecated See setWrapMode()
- * @return
- */
- public boolean isConstrainWidthToTextWidth() {
- return constrainWidthToTextWidth;
- }
-
- /**
- * Controls whether this node changes its width to fit the width
- * of its text. If flag is true it does; if flag is false it doesn't
- * @deprecated See setWrapMode()
- */
- public void setConstrainWidthToTextWidth(boolean constrainWidthToTextWidth) {
- this.constrainWidthToTextWidth = constrainWidthToTextWidth;
- recomputeLayout();
- }
-
- /**
- * @deprecated See setWrapMode()
- * @return
- */
- public boolean isConstrainHeightToTextHeight() {
- return constrainHeightToTextHeight;
- }
-
- /**
- * Controls whether this node changes its height to fit the height
- * of its text. If flag is true it does; if flag is false it doesn't
- * @deprecated See setWrapMode()
- */
- public void setConstrainHeightToTextHeight(boolean constrainHeightToTextHeight) {
- this.constrainHeightToTextHeight = constrainHeightToTextHeight;
- recomputeLayout();
- }
-
- /**
- * Returns the current greek threshold. When the screen font size will be below
- * this threshold the text is rendered as 'greek' instead of drawing the text
- * glyphs.
- */
- public double getGreekThreshold() {
- return greekThreshold;
- }
-
- /**
- * Sets the current greek threshold. When the screen font size will be below
- * this threshold the text is rendered as 'greek' instead of drawing the text
- * glyphs.
- *
- * @param threshold minimum screen font size.
- */
- public void setGreekThreshold(double threshold) {
- greekThreshold = threshold;
- invalidatePaint();
- }
-
- public String getText() {
- return text;
- }
-
- /**
- * Set the text for this node. The text will be broken up into multiple
- * lines based on the size of the text and the bounds width of this node.
- */
- public void setText(String aText) {
- String old = text;
- text = aText;
- lines = null;
- recomputeLayout();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_TEXT, PROPERTY_TEXT, old, text);
- }
-
- /**
- * Returns the font of this PText.
- * @return the font of this PText.
- */
- public Font getFont() {
- if (font == null) {
- font = DEFAULT_FONT;
- }
- return font;
- }
-
- /**
- * Set the font of this PText. Note that in Piccolo if you want to change
- * the size of a text object it's often a better idea to scale the PText
- * node instead of changing the font size to get that same effect. Using
- * very large font sizes can slow performance.
- */
- public void setFont(Font aFont) {
- Font old = font;
- font = aFont;
- lines = null;
- recomputeLayout();
- invalidatePaint();
- firePropertyChange(PROPERTY_CODE_FONT, PROPERTY_FONT, old, font);
- }
-
- private static final TextLayout[] EMPTY_TEXT_LAYOUT_ARRAY = new TextLayout[0];
-
- /**
- * Compute the bounds of the text wrapped by this node. The text layout
- * is wrapped based on the bounds of this node.
- */
- public void recomputeLayout() {
- ArrayList linesList = new ArrayList();
- double textWidth = 0;
- double textHeight = 0;
-
- if (text != null && text.length() > 0) {
- AttributedString atString = new AttributedString(text);
- atString.addAttribute(TextAttribute.FONT, getFont());
- AttributedCharacterIterator itr = atString.getIterator();
- LineBreakMeasurer measurer = new LineBreakMeasurer(itr, PPaintContext.RENDER_QUALITY_HIGH_FRC);
- float availableWidth = constrainWidthToTextWidth ? Float.MAX_VALUE : (float) getWidth();
-
- int nextLineBreakOffset = text.indexOf('\n');
- if (nextLineBreakOffset == -1) {
- nextLineBreakOffset = Integer.MAX_VALUE;
- } else {
- nextLineBreakOffset++;
- }
-
- while (measurer.getPosition() < itr.getEndIndex()) {
- TextLayout aTextLayout = computeNextLayout(measurer, availableWidth, nextLineBreakOffset);
-
- if (nextLineBreakOffset == measurer.getPosition()) {
- nextLineBreakOffset = text.indexOf('\n', measurer.getPosition());
- if (nextLineBreakOffset == -1) {
- nextLineBreakOffset = Integer.MAX_VALUE;
- } else {
- nextLineBreakOffset++;
- }
- }
-
- linesList.add(aTextLayout);
- textHeight += aTextLayout.getAscent();
- textHeight += aTextLayout.getDescent() + aTextLayout.getLeading();
- textWidth = Math.max(textWidth, aTextLayout.getAdvance());
- }
- }
-
- lines = (TextLayout[]) linesList.toArray(EMPTY_TEXT_LAYOUT_ARRAY);
-
- if (constrainWidthToTextWidth || constrainHeightToTextHeight) {
- double newWidth = getWidth();
- double newHeight = getHeight();
-
- if (constrainWidthToTextWidth) {
- newWidth = textWidth;
- }
-
- if (constrainHeightToTextHeight) {
- newHeight = textHeight;
- }
-
- super.setBounds(getX(), getY(), newWidth, newHeight);
- }
- }
-
- // provided in case someone needs to override the way that lines are wrapped.
- protected TextLayout computeNextLayout(LineBreakMeasurer measurer, float availibleWidth, int nextLineBreakOffset) {
- return measurer.nextLayout(availibleWidth, nextLineBreakOffset, false);
- }
-
- protected void paint(PPaintContext paintContext) {
- super.paint(paintContext);
-
- float screenFontSize = getFont().getSize() * (float) paintContext.getScale();
- if (textPaint != null && screenFontSize > greekThreshold) {
- float x = (float) getX();
- float y = (float) getY();
- float bottomY = (float) getHeight() + y;
-
- Graphics2D g2 = paintContext.getGraphics();
-
- if (lines == null) {
- recomputeLayout();
- repaint();
- return;
- }
-
- g2.setPaint(textPaint);
-
- for (int i = 0; i < lines.length; i++) {
- TextLayout tl = lines[i];
- y += tl.getAscent();
-
- if (bottomY < y) {
- return;
- }
-
- float offset = (float) (getWidth() - tl.getAdvance()) * justification;
- tl.draw(g2, x + offset, y);
-
- y += tl.getDescent() + tl.getLeading();
- }
- }
- }
-
- protected void internalUpdateBounds(double x, double y, double width, double height) {
- recomputeLayout();
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("text=" + (text == null ? "null" : text));
- result.append(",font=" + (font == null ? "null" : font.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/nodes/package.html b/src/main/java/edu/umd/cs/piccolo/nodes/package.html
deleted file mode 100755
index 1039fc0..0000000
--- a/src/main/java/edu/umd/cs/piccolo/nodes/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This package contains nodes that may be useful for Piccolo applications. These
-nodes are intended to be useful, but not definitive. Many applications will also
-end up defining their nodes which can be used along with these.
-
diff --git a/src/main/java/edu/umd/cs/piccolo/overview.html b/src/main/java/edu/umd/cs/piccolo/overview.html
deleted file mode 100755
index cf5f2ab..0000000
--- a/src/main/java/edu/umd/cs/piccolo/overview.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
-Piccolo is a revolutionary way (in the Jazz ZUI tradition)
-to create robust, full-featured graphical applications in Java, with
-striking features such as zooming and multiple representation. Piccolo is an
-extensive toolkit based on the Java2D API (also supporting a OpenGL pluggin).
-And best of all, Piccolo is not only free, it's open source!
-
-Piccolo is a general-purpose Java-based engine that supports 2D visualizations.
-A primary characteristic of Piccolo is that it is designed to support zoomable
-information spaces, although any particular applications may or may not
-take advantage of this feature. Piccolo is implemented entirely in Java 2 (1.4),
-and as such runs identically on any platform that supports Java 2.
-
-Piccolo is not an application in itself, but rather it is an engine that is designed
-to support applications that require the ability to create, manipulate, and render
-object-oriented graphics. If you are familiar with the terminology of 3D graphics,
-Piccolo supports a scenegraph. This is a data structure that represents a hierarchy
-of graphical objects. Piccolo uses a tuned run-time system to render the scenegraph
-as quickly as possible to support interactive applications.
-
-
diff --git a/src/main/java/edu/umd/cs/piccolo/package.html b/src/main/java/edu/umd/cs/piccolo/package.html
deleted file mode 100755
index be1fa0e..0000000
--- a/src/main/java/edu/umd/cs/piccolo/package.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-Piccolo is a general-purpose Java-based engine that supports 2D visualizations.
-A primary characteristic of Piccolo is that it is designed to support zoomable
-information spaces, although any particular applications may or may not
-take advantage of this feature. Piccolo is implemented entirely in Java 2 (1.4),
-and as such runs identically on any platform that supports Java 2.
-
-Piccolo is not an application in itself, but rather it is an engine that is designed
-to support applications that require the ability to create, manipulate, and render
-object-oriented graphics. If you are familiar with the terminology of 3D graphics,
-Piccolo supports a scenegraph. This is a data structure that represents a hierarchy
-of graphical objects. Piccolo uses a tuned run-time system to render the scenegraph
-as quickly as possible to support interactive applications.
-
-This is the root package for all Jazz classes. It contains the core scenegraph
-classes itself, and in addition, contains the activities
, event
,
-nodes
and util
packages that are used to build Jazz applications.
-
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java b/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java
deleted file mode 100755
index b2a9b40..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBasicExample.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package edu.umd.cs.piccolo.swtexamples;
-
-import java.awt.Color;
-
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import edu.umd.cs.piccolox.swt.PSWTCanvas;
-import edu.umd.cs.piccolox.swt.PSWTPath;
-import edu.umd.cs.piccolox.swt.PSWTText;
-
-/**
- * @author good
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class SWTBasicExample {
-
- /**
- * Constructor for SWTBasicExample.
- */
- public SWTBasicExample() {
- super();
- }
-
- public static void main(String[] args) {
- Display display = new Display ();
- Shell shell = open (display);
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
- public static Shell open(Display display) {
- final Shell shell = new Shell (display);
- shell.setLayout(new FillLayout());
- PSWTCanvas canvas = new PSWTCanvas(shell,0);
-
- PSWTPath rect = PSWTPath.createRectangle(25,25,50,50);
- rect.setPaint(Color.red);
- canvas.getLayer().addChild(rect);
-
- rect = PSWTPath.createRectangle(300,25,100,50);
- rect.setPaint(Color.blue);
- canvas.getLayer().addChild(rect);
-
- PSWTPath circle = PSWTPath.createEllipse(100,200,50,50);
- circle.setPaint(Color.green);
- canvas.getLayer().addChild(circle);
-
- circle = PSWTPath.createEllipse(400,400,75,150);
- circle.setPaint(Color.yellow);
- canvas.getLayer().addChild(circle);
-
- PSWTText text = new PSWTText("Hello World");
- text.translate(350,150);
- text.setPenColor(Color.gray);
- canvas.getLayer().addChild(text);
-
- text = new PSWTText("Goodbye World");
- text.translate(50,400);
- text.setPenColor(Color.magenta);
- canvas.getLayer().addChild(text);
-
- shell.open ();
- return shell;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java b/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java
deleted file mode 100755
index c9839ef..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTBenchTest.java
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * Copyright (C) 1998-2002 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolo.swtexamples;
-
-import java.util.Random;
-import java.io.*;
-import java.awt.*;
-import java.awt.geom.*;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import edu.umd.cs.piccolox.swt.SWTGraphics2D;
-
-/**
- * Benchmarking test suite for SWT package
- */
-public class SWTBenchTest extends Canvas {
-
- // Paths
- GeneralPath testShape = new GeneralPath();
-
- // Images
- Image testImageOpaque, testImageBitmask, testImageTranslucent, testImageARGB;
-
- // Transforms
- AffineTransform transform = new AffineTransform();
- static final AffineTransform IDENTITY = new AffineTransform();
-
- // Geometry
- double pts[] = new double[20];
-
- // Colors
- static final Color colors[] = {
- Color.red, Color.green, Color.blue, Color.white, Color.yellow,
- };
-
- // Flags
- boolean offscreen;
- boolean antialiased;
-
- // Statistics
- int results[][] = new int[NUM_CONTEXTS][NUM_TESTS];
-
-
- // Constants
-
- static final int CTX_NORMAL = 0;
-// static final int CTX_CLIPPED = 1;
- static final int CTX_TRANSFORMED = 1;
-// static final int CTX_BLENDED = 3;
- static final int NUM_CONTEXTS = 2;
-
-// static String contextNames[] = {
-// "normal",
-// "clip",
-// "transform",
-// "alpha",
-// };
-
- static String contextNames[] = {
- "normal",
- "transform"
- };
-
-
- //
- // TEST METHODS
- //
-
- static final int DRAW_LINE = 0;
- static final int DRAW_RECT = 1;
- static final int FILL_RECT = 2;
- static final int DRAW_OVAL = 3;
- static final int FILL_OVAL = 4;
- static final int DRAW_POLY = 5;
- static final int FILL_POLY = 6;
- static final int DRAW_TEXT = 7;
- static final int DRAW_IMG1 = 8;
- static final int DRAW_IMG2 = 9;
- static final int DRAW_IMG3 = 10;
- static final int DRAW_IMG4 = 11;
- static final int DRAW_IMG5 = 12;
- static final int NUM_TESTS = 13;
-
- static String testNames[] = {
- "line",
- "rect",
- "fill rect",
- "oval",
- "fill oval",
- "poly",
- "fill poly",
- "text",
- "image",
- "scaled image",
- "mask image",
- "alpha image",
- "argb image",
- };
-
- void testDrawLine(SWTGraphics2D g, Random r) {
- g.drawLine(rand(r), rand(r), rand(r), rand(r));
- }
-
- void testDrawRect(SWTGraphics2D g, Random r) {
- g.drawRect(rand(r), rand(r), rand(r), rand(r));
- }
-
- void testFillRect(SWTGraphics2D g, Random r) {
- g.fillRect(rand(r), rand(r), rand(r), rand(r));
- }
-
- void testDrawOval(SWTGraphics2D g, Random r) {
- g.drawOval(rand(r), rand(r), rand(r), rand(r));
- }
-
- void testFillOval(SWTGraphics2D g, Random r) {
- g.fillOval(rand(r), rand(r), rand(r), rand(r));
- }
-
- void genPoly(Random r) {
- for (int i = 0; i < pts.length/2; i++) {
- pts[2*i] = rand(r);
- pts[2*i+1] = rand(r);
- }
- }
-
- void testDrawPoly(SWTGraphics2D g, Random r) {
- genPoly(r);
- g.drawPolyline(pts);
- }
-
- void testFillPoly(SWTGraphics2D g, Random r) {
- genPoly(r);
- g.fillPolygon(pts);
- }
-
- void testDrawText(SWTGraphics2D g, Random r) {
- g.drawString("Abcdefghijklmnop", rand(r), rand(r));
- }
-
- // Basic image
- void testDrawImg1(SWTGraphics2D g, Random r) {
- g.drawImage(testImageOpaque, rand(r), rand(r));
- }
-
- // Scaled image
- void testDrawImg2(SWTGraphics2D g, Random r) {
- Rectangle rect = testImageOpaque.getBounds();
- g.drawImage(testImageOpaque, 0, 0, rect.width, rect.height, rand(r), rand(r), rand(r), rand(r));
- }
-
- // Bitmask image (unscaled)
- void testDrawImg3(SWTGraphics2D g, Random r) {
- g.drawImage(testImageBitmask, rand(r), rand(r));
- }
-
- // Translucent image (unscaled)
- void testDrawImg4(SWTGraphics2D g, Random r) {
- g.drawImage(testImageTranslucent, rand(r), rand(r));
- }
-
- // Buffered image (unscaled)
- void testDrawImg5(SWTGraphics2D g, Random r) {
- g.drawImage(testImageARGB, rand(r), rand(r));
- }
-
- Image loadImage(Display display, String name) {
- try {
- InputStream stream = SWTBenchTest.class.getResourceAsStream(name);
- if (stream != null) {
- ImageData imageData = new ImageData(stream);
- return new Image(display,imageData);
-// if (imageData != null) {
-// ImageData mask = imageData.getTransparencyMask();
-// return new Image(display, imageData, mask);
-// }
-
- }
- } catch (Exception e) {
- }
- return null;
- }
-
- SWTBenchTest(Composite parent, int style) {
- super(parent,style);
-
- testImageOpaque = loadImage(getDisplay(),"opaque.jpg");
- testImageBitmask = loadImage(getDisplay(),"bitmask.gif");
- testImageTranslucent = loadImage(getDisplay(),"translucent.png");
- testImageARGB = new Image(getDisplay(),128, 128);
-
- GC tmpGC = new GC(testImageARGB);
- tmpGC.drawImage(testImageTranslucent,0,0);
- tmpGC.dispose();
-
- addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent pe) {
- runAll(new SWTGraphics2D(pe.gc,getDisplay()));
- }
- });
- }
-
- void setupTransform(Graphics2D g, Random r) {
- transform.setToIdentity();
-
- switch (abs(r.nextInt()) % 5) {
- default:
-// case 0: // UNIFORM SCALE
- double s = r.nextDouble();
- transform.scale(5*s + 0.1, 5*s + 0.1);
- break;
-// case 1: // NON-UNIFORM SCALE
-// transform.scale(5 * r.nextDouble() + 0.1, 5 * r.nextDouble() + 0.1);
-// break;
-// case 2: // ROTATION
-// transform.rotate(r.nextDouble() * Math.PI * 2);
-// break;
-// case 3: // TRANSLATION
-// transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
-// break;
-// case 4: // TRANSLATE + ROTATE + SCALE
-// s = r.nextDouble();
-// transform.translate(r.nextDouble() * 500, r.nextDouble() * 500);
-// transform.rotate(r.nextDouble() * Math.PI * 2);
-// transform.scale(5*s + 0.1, 5*s + 0.1);
-// break;
- }
-
- g.setTransform(transform);
- }
-
- void setupClip(Graphics2D g, Random r) {
-// g.setClip(rand(r), rand(r), rand(r), rand(r));
- }
-
- void setupBlend(Graphics2D g, Random r) {
- g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, r.nextFloat()));
- }
-
- void setup(int ctx, Graphics2D g, Random r) {
- switch (ctx) {
- case CTX_NORMAL:
- break;
-
- case CTX_TRANSFORMED:
- setupTransform(g, r);
- break;
-
-// case CTX_CLIPPED:
-// setupClip(g, r);
-// break;
-//
-// case CTX_BLENDED:
-// setupBlend(g, r);
-// break;
- }
- }
-
- void test(int testNum, SWTGraphics2D g, Random r) {
-
- g.setColor(colors[abs(r.nextInt()) % colors.length]);
- g.setBackground(colors[abs(r.nextInt()) % colors.length]);
-
- switch (testNum) {
- case DRAW_LINE: testDrawLine(g, r); break;
- case DRAW_RECT: testDrawRect(g, r); break;
- case FILL_RECT: testFillRect(g, r); break;
- case DRAW_OVAL: testDrawOval(g, r); break;
- case FILL_OVAL: testFillOval(g, r); break;
- case DRAW_POLY: testDrawPoly(g, r); break;
- case FILL_POLY: testFillPoly(g, r); break;
- case DRAW_TEXT: testDrawText(g, r); break;
- case DRAW_IMG1: testDrawImg1(g, r); break;
- case DRAW_IMG2: testDrawImg2(g, r); break;
- case DRAW_IMG3: testDrawImg3(g, r); break;
- case DRAW_IMG4: testDrawImg4(g, r); break;
- case DRAW_IMG5: testDrawImg5(g, r); break;
- }
- }
-
- void runTest(SWTGraphics2D g, int ctx, int testNum) {
- Random r1 = new Random(1);
- Random r2 = new Random(1);
-
- System.out.println("Test: " + testNames[testNum]);
- long t1 = System.currentTimeMillis();
- int i = 0;
- while (true) {
- if (i % 10 == 0) setup(ctx, g, r1);
- test(testNum, g, r2);
- i++;
- long t2 = System.currentTimeMillis();
- if (t2 - t1 >= 5000) {
- break;
- }
- }
- results[ctx][testNum] += i / 5;
- System.out.println("Shapes per second: " + (results[ctx][testNum]));
- }
-
- void runAll(SWTGraphics2D g) {
- System.out.println("BENCHMARKING: " + g);
-
- if (antialiased) {
- System.out.println("ANTIALIASED");
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- }
-
- for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
- System.out.println("Context: " + contextNames[ctx]);
- for (int i = 0; i < NUM_TESTS; i++) {
- g.setClip(null);
- g.setTransform(IDENTITY);
- runTest(g, ctx, i);
- }
- }
-
- if (offscreen) {
- g.dispose();
- }
-
- String fileName = g.getClass().getName().replace('.', '_');
- if (offscreen) fileName += "-offscreen";
- if (antialiased) fileName += "-antialiased";
- dumpResults(fileName + ".txt");
- System.exit(0);
- }
-
- void dumpResults(String fileName) {
- try {
- FileOutputStream fout = new FileOutputStream(fileName);
- PrintWriter out = new PrintWriter(fout);
- out.print('\t');
- for (int i = 0; i < NUM_TESTS; i++) {
- out.print(testNames[i]);
- out.print('\t');
- }
- out.println("");
- for (int ctx = 0; ctx < NUM_CONTEXTS; ctx++) {
- out.print(contextNames[ctx]);
- for (int i = 0; i < NUM_TESTS; i++) {
- out.print('\t');
- out.print(results[ctx][i]);
- }
- out.println("");
- }
- out.close();
- results = new int[NUM_CONTEXTS][NUM_TESTS];
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- public Point computeSize(int wHint, int hHint) {
- return new Point(512,512);
- }
-
- public Point computeSize(int wHint, int hHint, boolean changed) {
- return computeSize(wHint,hHint);
- }
-
- final static int abs(int x) {
- return (x < 0 ? -x : x);
- }
-
- final static double rand(Random r) {
- return abs(r.nextInt()) % 500;
- }
-
- public static void main(String args[]) {
- // Create frame
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
-
- // Add bench test
- SWTBenchTest m = new SWTBenchTest(shell,SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
- m.setSize(512,512);
- for (int i = 0; i < args.length; i++) {
- if (args[i].intern() == "-offscreen")
- m.offscreen = true;
- else if (args[i].intern() == "-anti")
- m.antialiased = true;
- else {
- System.out.println("Usage: java BenchTest [-anti] [-offscreen]");
- System.exit(1);
- }
- }
-
- shell.pack();
- shell.open();
-
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java b/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java
deleted file mode 100755
index ca94965..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/SWTHelloWorld.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package edu.umd.cs.piccolo.swtexamples;
-
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import edu.umd.cs.piccolox.swt.PSWTCanvas;
-import edu.umd.cs.piccolox.swt.PSWTText;
-
-/**
- * @author good
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class SWTHelloWorld {
-
- /**
- * Constructor for SWTBasicExample.
- */
- public SWTHelloWorld() {
- super();
- }
-
- public static void main(String[] args) {
- Display display = new Display ();
- Shell shell = open (display);
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
- public static Shell open(Display display) {
- final Shell shell = new Shell (display);
- shell.setLayout(new FillLayout());
- PSWTCanvas canvas = new PSWTCanvas(shell,0);
-
- PSWTText text = new PSWTText("Hello World");
- canvas.getLayer().addChild(text);
-
- shell.open ();
- return shell;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/bitmask.gif b/src/main/java/edu/umd/cs/piccolo/swtexamples/bitmask.gif
deleted file mode 100755
index 053a5da..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/bitmask.gif
+++ /dev/null
Binary files differ
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/opaque.jpg b/src/main/java/edu/umd/cs/piccolo/swtexamples/opaque.jpg
deleted file mode 100755
index 2ff5ba6..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/opaque.jpg
+++ /dev/null
Binary files differ
diff --git a/src/main/java/edu/umd/cs/piccolo/swtexamples/translucent.png b/src/main/java/edu/umd/cs/piccolo/swtexamples/translucent.png
deleted file mode 100755
index 07601a7..0000000
--- a/src/main/java/edu/umd/cs/piccolo/swtexamples/translucent.png
+++ /dev/null
Binary files differ
diff --git a/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java b/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
deleted file mode 100755
index a142264..0000000
--- a/src/main/java/edu/umd/cs/piccolo/tutorial/InterfaceFrame.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-
-import edu.umd.cs.piccolo.*;
-import edu.umd.cs.piccolo.event.*;
-import edu.umd.cs.piccolo.nodes.*;
-import edu.umd.cs.piccolo.util.*;
-import edu.umd.cs.piccolox.*;
-
-public class InterfaceFrame extends PFrame {
-
- public void initialize() {
- // Remove the Default pan event handler and add a drag event handler
- // so that we can drag the nodes around individually.
- getCanvas().setPanEventHandler(null);
- getCanvas().addInputEventListener(new PDragEventHandler());
-
- // Add Some Default Nodes
-
- // Create a node.
- PNode aNode = new PNode();
-
- // A node will not be visible until its bounds and brush are set.
- aNode.setBounds(0, 0, 100, 80);
- aNode.setPaint(Color.RED);
-
- // A node needs to be a descendent of the root to be displayed.
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
-
- // A node can have child nodes added to it.
- PNode anotherNode = new PNode();
- anotherNode.setBounds(0, 0, 100, 80);
- anotherNode.setPaint(Color.YELLOW);
- aNode.addChild(anotherNode);
-
- // The base bounds of a node are easy to change. Changing the bounds
- // of a node will not affect it's children.
- aNode.setBounds(-10, -10, 200, 110);
-
- // Each node has a transform that can be used to modify the position,
- // scale or rotation of a node. Changing a node's transform, will
- // transform all of its children as well.
- aNode.translate(100, 100);
- aNode.scale(1.5f);
- aNode.rotate(45);
-
- // Add a couple of PPath nodes and a PText node.
- layer.addChild(PPath.createEllipse(0, 0, 100, 100));
- layer.addChild(PPath.createRectangle(0, 100, 100, 100));
- layer.addChild(new PText("Hello World"));
-
- // Here we create a PImage node that displays a thumbnail image
- // of the root node. Then we add the new PImage to the main layer.
- PImage image = new PImage(layer.toImage(300, 300, null));
- layer.addChild(image);
-
- // Create a New Node using Composition
-
- PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
-
- // Create parts for the face.
- PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
- eye1.setPaint(Color.YELLOW);
- PNode eye2 = (PNode) eye1.clone();
- PNode mouth = PPath.createRectangle(0, 0, 40, 20);
- mouth.setPaint(Color.BLACK);
-
- // Add the face parts.
- myCompositeFace.addChild(eye1);
- myCompositeFace.addChild(eye2);
- myCompositeFace.addChild(mouth);
-
- // Don't want anyone grabbing out our eye's.
- myCompositeFace.setChildrenPickable(false);
-
- // Position the face parts.
- eye2.translate(25, 0);
- mouth.translate(0, 30);
-
- // Set the face bounds so that it neatly contains the face parts.
- PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
- b.inset(-5, -5);
- myCompositeFace.setBounds(b);
-
- // Opps its to small, so scale it up.
- myCompositeFace.scale(1.5);
-
- layer.addChild(myCompositeFace);
-
- // Create a New Node using Inheritance.
- ToggleShape ts = new ToggleShape();
- ts.setPaint(Color.ORANGE);
- layer.addChild(ts);
- }
-
- class ToggleShape extends PPath {
-
- private boolean fIsPressed = false;
-
- public ToggleShape() {
- setPathToEllipse(0, 0, 100, 80);
-
- addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- super.mousePressed(event);
- fIsPressed = true;
- repaint();
- }
- public void mouseReleased(PInputEvent event) {
- super.mouseReleased(event);
- fIsPressed = false;
- repaint();
- }
- });
- }
-
- protected void paint(PPaintContext paintContext) {
- if (fIsPressed) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- } else {
- super.paint(paintContext);
- }
- }
- }
-
- public static void main(String[] args) {
- new InterfaceFrame();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java b/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
deleted file mode 100755
index 3fe86d6..0000000
--- a/src/main/java/edu/umd/cs/piccolo/tutorial/PiccoloPresentation.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-import java.awt.event.KeyEvent;
-import java.awt.geom.AffineTransform;
-import java.io.File;
-import java.util.ArrayList;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PImage;
-import edu.umd.cs.piccolox.PFrame;
-
-public class PiccoloPresentation extends PFrame {
-
- protected PNode slideBar;
- protected PNode currentSlide;
- protected PBasicInputEventHandler eventHandler;
- protected ArrayList slides = new ArrayList();
-
- public PiccoloPresentation() {
- super();
- }
-
- public void initialize() {
- setFullScreenMode(true);
- loadSlides();
-
- eventHandler = new PBasicInputEventHandler() {
- public void keyReleased(PInputEvent event) {
- if (event.getKeyCode() == KeyEvent.VK_SPACE) {
- int newIndex = slides.indexOf(currentSlide) + 1;
- if (newIndex < slides.size()) {
- goToSlide((PNode)slides.get(newIndex));
- }
- }
- }
-
- public void mouseReleased(PInputEvent event) {
- PNode picked = event.getPickedNode();
-
- if (picked.getParent() == slideBar) {
- picked.moveToFront();
- if (picked.getScale() == 1) {
- goToSlide(null);
- } else {
- goToSlide(picked);
- }
- }
- }
- };
-
- getCanvas().requestFocus();
- getCanvas().addInputEventListener(eventHandler);
- getCanvas().getRoot().getDefaultInputManager().setKeyboardFocus(eventHandler);
- getCanvas().removeInputEventListener(getCanvas().getZoomEventHandler());
- getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
- }
-
- public void goToSlide(PNode slide) {
- if (currentSlide != null) {
- currentSlide.animateToTransform((AffineTransform)currentSlide.getAttribute("small"), 1000);
- }
-
- currentSlide = slide;
-
- if (currentSlide != null) {
- currentSlide.moveToFront();
- currentSlide.animateToTransform((AffineTransform)currentSlide.getAttribute("large"), 1000);
- }
- }
-
- public void loadSlides() {
- slideBar = new PNode();
- slideBar.setPaint(Color.DARK_GRAY);
- slideBar.setBounds(0, 0, getCanvas().getWidth(), 100);
- slideBar.setOffset(0, getCanvas().getHeight() - 100);
- getCanvas().getLayer().addChild(slideBar);
-
- File[] slideFiles = new File("slides").listFiles();
- for (int i = 0; i < slideFiles.length; i++) {
- PNode slide = new PImage(slideFiles[i].getPath());
-
- if (slide.getHeight() != (getHeight() - 100)) {
- slide = new PImage(slide.toImage(getWidth(), getHeight() - 100, null));
- }
- slide.offset((getWidth() - slide.getWidth()) / 2, - (getHeight() - 100));
- slide.addAttribute("large", slide.getTransform());
-
- slide.setTransform(new AffineTransform());
- slide.scale((100 - 20) / slide.getHeight());
- slide.offset(i * (slide.getFullBoundsReference().getWidth() + 10) + 10, 10);
- slide.addAttribute("small", slide.getTransform());
-
- slideBar.addChild(slide);
- slides.add(slide);
- }
-
- goToSlide((PNode)slides.get(0));
- }
-
- public static void main(String[] argv) {
- new PiccoloPresentation();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java b/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
deleted file mode 100755
index a49f2c0..0000000
--- a/src/main/java/edu/umd/cs/piccolo/tutorial/SpecialEffects.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.Color;
-
-import edu.umd.cs.piccolo.*;
-import edu.umd.cs.piccolo.activities.*;
-import edu.umd.cs.piccolo.nodes.*;
-import edu.umd.cs.piccolox.*;
-
-public class SpecialEffects extends PFrame {
- public void initialize() {
- // Create the Target for our Activities.
-
- // Create a new node that we will apply different activities to, and
- // place that node at location 200, 200.
- final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
- PLayer layer = getCanvas().getLayer();
- layer.addChild(aNode);
- aNode.setOffset(200, 200);
-
- // Extend PActivity.
-
- // Store the current time in milliseconds for use below.
- long currentTime = System.currentTimeMillis();
-
- // Create a new custom "flash" activity. This activity will start running in
- // five seconds, and while it runs it will flash aNode's paint between
- // red and green every half second.
- PActivity flash = new PActivity(-1, 500, currentTime + 5000) {
- boolean fRed = true;
-
- protected void activityStep(long elapsedTime) {
- super.activityStep(elapsedTime);
-
- // Toggle the target node's brush color between red and green
- // each time the activity steps.
- if (fRed) {
- aNode.setPaint(Color.red);
- } else {
- aNode.setPaint(Color.green);
- }
-
- fRed = !fRed;
- }
- };
-
- // Schedule the activity.
- getCanvas().getRoot().addActivity(flash);
-
- // Create three activities that animate the node's position. Since our node
- // already descends from the root node the animate methods will automatically
- // schedule these activities for us.
- PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
- PActivity a2 = aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
- PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);
-
- // The animate activities will start immediately (in the next call to
- // PRoot.processInputs) by default. Here we set their start times (in PRoot
- // global time) so that they start when the previous one has finished.
- a1.setStartTime(currentTime);
- a2.startAfter(a1);
- a3.startAfter(a2);
-
- a1.setDelegate(new PActivity.PActivityDelegate() {
- public void activityStarted(PActivity activity) {
- System.out.println("a1 started");
- }
- public void activityStepped(PActivity activity) {}
- public void activityFinished(PActivity activity) {
- System.out.println("a1 finished");
- }
- });
- }
-
- public static void main(String[] args) {
- new SpecialEffects();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java b/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
deleted file mode 100755
index 8233201..0000000
--- a/src/main/java/edu/umd/cs/piccolo/tutorial/UserInteraction.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package edu.umd.cs.piccolo.tutorial;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.geom.Point2D;
-
-import edu.umd.cs.piccolo.*;
-import edu.umd.cs.piccolo.event.*;
-import edu.umd.cs.piccolo.nodes.*;
-import edu.umd.cs.piccolo.util.*;
-import edu.umd.cs.piccolox.*;
-
-public class UserInteraction extends PFrame {
-
- public UserInteraction() {
- super();
- }
-
- public void initialize() {
- // Create a Camera Event Listener.
-
- // Remove the pan event handler that is installed by default so that it
- // does not conflict with our new squiggle handler.
- getCanvas().setPanEventHandler(null);
-
- // Create a squiggle handler and register it with the Canvas.
- PBasicInputEventHandler squiggleHandler = new SquiggleHandler(getCanvas());
- getCanvas().addInputEventListener(squiggleHandler);
-
- // Create a Node Event Listener.
-
- // Create a green rectangle node.
- PNode nodeGreen = PPath.createRectangle(0, 0, 100, 100);
- nodeGreen.setPaint(Color.GREEN);
- getCanvas().getLayer().addChild(nodeGreen);
-
-// Attach event handler directly to the node.
-nodeGreen.addInputEventListener(new PBasicInputEventHandler() {
- public void mousePressed(PInputEvent event) {
- event.getPickedNode().setPaint(Color.ORANGE);
- event.getInputManager().setKeyboardFocus(event.getPath());
- event.setHandled(true);
- }
- public void mouseDragged(PInputEvent event) {
- PNode aNode = event.getPickedNode();
- PDimension delta = event.getDeltaRelativeTo(aNode);
- aNode.translate(delta.width, delta.height);
- event.setHandled(true);
- }
- public void mouseReleased(PInputEvent event) {
- event.getPickedNode().setPaint(Color.GREEN);
- event.setHandled(true);
- }
- public void keyPressed(PInputEvent event) {
- PNode node = event.getPickedNode();
- switch (event.getKeyCode()) {
- case KeyEvent.VK_UP:
- node.translate(0, -10f);
- break;
- case KeyEvent.VK_DOWN:
- node.translate(0, 10f);
- break;
- case KeyEvent.VK_LEFT:
- node.translate(-10f, 0);
- break;
- case KeyEvent.VK_RIGHT:
- node.translate(10f, 0);
- break;
- }
- }
-});
- }
-
- public class SquiggleHandler extends PDragSequenceEventHandler {
- protected PCanvas canvas;
-
- // The squiggle that is currently getting created.
- protected PPath squiggle;
-
- public SquiggleHandler(PCanvas aCanvas) {
- canvas = aCanvas;
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- public void startDrag(PInputEvent e) {
- super.startDrag(e);
-
- Point2D p = e.getPosition();
-
- // Create a new squiggle and add it to the canvas.
- squiggle = new PPath();
- squiggle.moveTo((float) p.getX(), (float) p.getY());
- squiggle.setStroke(new BasicStroke((float) (1 / e.getCamera().getViewScale())));
- canvas.getLayer().addChild(squiggle);
-
- // Reset the keydboard focus.
- e.getInputManager().setKeyboardFocus(null);
- }
-
- public void drag(PInputEvent e) {
- super.drag(e);
- // Update the squiggle while dragging.
- updateSquiggle(e);
- }
-
- public void endDrag(PInputEvent e) {
- super.endDrag(e);
- // Update the squiggle one last time.
- updateSquiggle(e);
- squiggle = null;
- }
-
- public void updateSquiggle(PInputEvent aEvent) {
- // Add a new segment to the squiggle from the last mouse position
- // to the current mouse position.
- Point2D p = aEvent.getPosition();
- squiggle.lineTo((float) p.getX(), (float) p.getY());
- }
- }
-
- public static void main(String[] args) {
- new UserInteraction();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java b/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java
deleted file mode 100755
index d585e9e..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PAffineTransform.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Dimension2D;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-/**
- * PAffineTransform is a subclass of AffineTransform that has been extended
- * with convenience methods.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PAffineTransform extends AffineTransform {
-
- /**
- *
- */
- private static final long serialVersionUID = -6191845401665188757L;
- private static double[] PTS1 = new double[8];
- private static double[] PTS2 = new double[8];
-
- public PAffineTransform() {
- super();
- }
-
- public PAffineTransform(double[] flatmatrix) {
- super(flatmatrix);
- }
-
- public PAffineTransform(float[] flatmatrix) {
- super(flatmatrix);
- }
-
- public PAffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) {
- super(m00, m10, m01, m11, m02, m12);
- }
-
- public PAffineTransform(float m00, float m10, float m01, float m11, float m02, float m12) {
- super(m00, m10, m01, m11, m02, m12);
- }
-
- public PAffineTransform(AffineTransform tx) {
- super(tx);
- }
-
- public void scaleAboutPoint(double scale, double x, double y) {
- translate(x, y);
- scale(scale, scale);
- translate(-x, -y);
- }
-
- public double getScale() {
- PTS1[0] = 0;//x1
- PTS1[1] = 0;//y1
- PTS1[2] = 1;//x2
- PTS1[3] = 0;//y2
- transform(PTS1, 0, PTS2, 0, 2);
- return Point2D.distance(PTS2[0], PTS2[1], PTS2[2], PTS2[3]);
- }
-
- public void setScale(double scale) {
- if (scale == 0) throw new RuntimeException("Can't set scale to 0");
- scaleAboutPoint(scale / getScale(), 0, 0);
- }
-
- public void setOffset(double tx, double ty) {
- setTransform(getScaleX(), getShearY(), getShearX(), getScaleY(), tx, ty);
- }
-
- /**
- * Returns the rotation applied to this affine transform in radians. The
- * value returned will be between 0 and 2pi.
- *
- * @return rotation in radians
- */
- public double getRotation() {
- PTS1[0] = 0;//x1
- PTS1[1] = 0;//y1
- PTS1[2] = 1;//x2
- PTS1[3] = 0;//y2
-
- transform(PTS1, 0, PTS2, 0, 2);
-
- double dy = Math.abs(PTS2[3] - PTS2[1]);
- double l = Point2D.distance(PTS2[0], PTS2[1], PTS2[2], PTS2[3]);
- double rotation = Math.asin(dy / l);
-
- // correct for quadrant
- if (PTS2[3] - PTS2[1] > 0) {
- if (PTS2[2] - PTS2[0] < 0) {
- rotation = Math.PI - rotation;
- }
- } else {
- if (PTS2[2] - PTS2[0] > 0) {
- rotation = 2 * Math.PI - rotation;
- } else {
- rotation = rotation + Math.PI;
- }
- }
-
- return rotation;
- }
-
- /**
- * Set rotation in radians.
- */
- public void setRotation(double theta) {
- rotate(theta - getRotation());
- }
-
- public Dimension2D transform(Dimension2D dimSrc, Dimension2D dimDst) {
- if (dimDst == null) {
- dimDst = (Dimension2D) dimSrc.clone();
- }
-
- PTS1[0] = dimSrc.getWidth();
- PTS1[1] = dimSrc.getHeight();
- deltaTransform(PTS1, 0, PTS2, 0, 1);
- dimDst.setSize(PTS2[0], PTS2[1]);
- return dimDst;
- }
-
- public Dimension2D inverseTransform(Dimension2D dimSrc, Dimension2D dimDst) {
- if (dimDst == null) {
- dimDst = (Dimension2D) dimSrc.clone();
- }
-
- double width = dimSrc.getWidth();
- double height = dimSrc.getHeight();
- double m00 = getScaleX();
- double m11 = getScaleY();
- double m01 = getShearX();
- double m10 = getShearY();
- double det = m00 * m11 - m01 * m10;
-
- try {
- if (Math.abs(det) <= Double.MIN_VALUE) {
- throw new NoninvertibleTransformException("Determinant is "+ det);
- }
- dimDst.setSize((width * m11 - height * m01) / det, (height * m00 - width * m10) / det);
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
-
- return dimDst;
- }
-
- public Rectangle2D transform(Rectangle2D rectSrc, Rectangle2D rectDst) {
- if (rectDst == null) {
- rectDst = (Rectangle2D) rectSrc.clone();
- }
-
- if (rectSrc.isEmpty()) {
- rectDst.setRect(rectSrc);
- if (rectDst instanceof PBounds) {
- ((PBounds)rectDst).reset();
- }
- return rectDst;
- }
-
- double scale;
-
- switch (getType()) {
- case AffineTransform.TYPE_IDENTITY:
- if (rectSrc != rectDst)
- rectDst.setRect(rectSrc);
- break;
-
- case AffineTransform.TYPE_TRANSLATION:
- rectDst.setRect(rectSrc.getX() + getTranslateX(),
- rectSrc.getY() + getTranslateY(),
- rectSrc.getWidth(),
- rectSrc.getHeight());
- break;
-
- case AffineTransform.TYPE_UNIFORM_SCALE:
- scale = getScaleX();
- rectDst.setRect(rectSrc.getX() * scale,
- rectSrc.getY() * scale,
- rectSrc.getWidth() * scale,
- rectSrc.getHeight() * scale);
- break;
-
- case AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_UNIFORM_SCALE:
- scale = getScaleX();
- rectDst.setRect((rectSrc.getX() * scale) + getTranslateX(),
- (rectSrc.getY() * scale) + getTranslateY(),
- rectSrc.getWidth() * scale,
- rectSrc.getHeight() * scale);
- break;
-
- default :
- double[] pts = rectToArray(rectSrc);
- transform(pts, 0, pts, 0, 4);
- rectFromArray(rectDst, pts);
- break;
- }
-
-
- return rectDst;
- }
-
- public Rectangle2D inverseTransform(Rectangle2D rectSrc, Rectangle2D rectDst) {
- if (rectDst == null) {
- rectDst = (Rectangle2D) rectSrc.clone();
- }
-
- if (rectSrc.isEmpty()) {
- rectDst.setRect(rectSrc);
- if (rectDst instanceof PBounds) {
- ((PBounds)rectDst).reset();
- }
- return rectDst;
- }
-
- double scale;
-
- switch (getType()) {
- case AffineTransform.TYPE_IDENTITY:
- if (rectSrc != rectDst)
- rectDst.setRect(rectSrc);
- break;
-
- case AffineTransform.TYPE_TRANSLATION:
- rectDst.setRect(rectSrc.getX() - getTranslateX(),
- rectSrc.getY() - getTranslateY(),
- rectSrc.getWidth(),
- rectSrc.getHeight());
- break;
-
- case AffineTransform.TYPE_UNIFORM_SCALE:
- scale = 1 / getScaleX();
- rectDst.setRect(rectSrc.getX() * scale,
- rectSrc.getY() * scale,
- rectSrc.getWidth() * scale,
- rectSrc.getHeight() * scale);
- break;
-
- case AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_UNIFORM_SCALE:
- scale = 1 / getScaleX();
- rectDst.setRect((rectSrc.getX() - getTranslateX()) * scale,
- (rectSrc.getY() - getTranslateY()) * scale,
- rectSrc.getWidth() * scale,
- rectSrc.getHeight() * scale);
- break;
-
- default :
- double[] pts = rectToArray(rectSrc);
- try {
- inverseTransform(pts, 0, pts, 0, 4);
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- rectFromArray(rectDst, pts);
- break;
- }
-
- return rectDst;
- }
-
- private static double[] rectToArray(Rectangle2D aRectangle) {
- PTS1[0] = aRectangle.getX();
- PTS1[1] = aRectangle.getY();
- PTS1[2] = PTS1[0] + aRectangle.getWidth();
- PTS1[3] = PTS1[1];
- PTS1[4] = PTS1[0] + aRectangle.getWidth();
- PTS1[5] = PTS1[1] + aRectangle.getHeight();
- PTS1[6] = PTS1[0];
- PTS1[7] = PTS1[1] + aRectangle.getHeight();
- return PTS1;
- }
-
- private static void rectFromArray(Rectangle2D aRectangle, double[] pts) {
- double minX = pts[0];
- double minY = pts[1];
- double maxX = pts[0];
- double maxY = pts[1];
-
- double x;
- double y;
-
- for (int i = 1; i < 4; i++) {
- x = pts[2 * i];
- y = pts[(2 * i) + 1];
-
- if (x < minX) {
- minX = x;
- }
- if (y < minY) {
- minY = y;
- }
- if (x > maxX) {
- maxX = x;
- }
- if (y > maxY) {
- maxY = y;
- }
- }
- aRectangle.setRect(minX, minY, maxX - minX, maxY - minY);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PBounds.java b/src/main/java/edu/umd/cs/piccolo/util/PBounds.java
deleted file mode 100755
index b7416fc..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PBounds.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.geom.Dimension2D;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-/**
- * PBounds is simply a Rectangle2D.Double with extra methods that more
- * properly deal with the case when the rectangle is "empty". A PBounds
- * has an extra bit to store emptiness. In this state, adding new geometry
- * replaces the current geometry. A PBounds is emptied with the reset() method.
- * A useful side effect of the reset method is that it only modifies the fIsEmpty
- * variable, the other x, y, with, height variables are left alone. This is used
- * by Piccolo's layout management system to see if a the full bounds of a node
- * has really changed when it is recomputed. See PNode.validateLayout.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PBounds extends Rectangle2D.Double implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 5415028518953265301L;
- private boolean isEmpty = true;
-
- public PBounds() {
- super();
- }
-
- public PBounds(PBounds aBounds) {
- this(aBounds.x, aBounds.y, aBounds.width, aBounds.height);
- isEmpty = aBounds.isEmpty();
- }
-
- public PBounds(Rectangle2D aBounds) {
- this(aBounds.getX(), aBounds.getY(), aBounds.getWidth(), aBounds.getHeight());
- isEmpty = aBounds.isEmpty();
- }
-
- public PBounds(Point2D aCenterPoint, double insetX, double insetY) {
- this(aCenterPoint.getX(), aCenterPoint.getY(), 0, 0);
- inset(insetX, insetY);
- }
-
- public PBounds(double x, double y, double width, double height) {
- super(x, y, width, height);
- isEmpty = false;
- }
-
- public Object clone() {
- return new PBounds(this);
- }
-
- public boolean isEmpty() {
- return isEmpty;
- }
-
- public PBounds reset() {
- isEmpty = true;
- return this;
- }
-
- public PBounds resetToZero() {
- x = 0;
- y = 0;
- width = 0;
- height = 0;
- isEmpty = true;
- return this;
- }
-
- public void setRect(Rectangle2D r) {
- super.setRect(r);
- isEmpty = false;
- }
-
- public void setRect(PBounds b) {
- isEmpty = b.isEmpty;
- x = b.x;
- y = b.y;
- width = b.width;
- height = b.height;
- }
-
- public void setRect(double x, double y, double w, double h) {
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
- isEmpty = false;
- }
-
- public void add(double newx, double newy) {
- if (isEmpty) {
- setRect(newx, newy, 0, 0);
- isEmpty = false;
- } else {
- super.add(newx, newy);
- }
- }
-
- public void add(Rectangle2D r) {
- if (isEmpty) {
- setRect(r);
- } else {
- super.add(r);
- }
- }
-
- // optimized add when adding two PBounds together.
- public void add(PBounds r) {
- if (r.isEmpty) {
- return;
- } else if (isEmpty) {
- x = r.x;
- y = r.y;
- width = r.width;
- height = r.height;
- isEmpty = false;
- } else {
- double x1 = (x <= r.x) ? x : r.x;
- double y1 = (y <= r.y) ? y : r.y;
- double x2 = ((x + width) >= (r.x + r.width)) ? (x + width) : (r.x + r.width);
- double y2 = ((y + height) >= (r.y + r.height)) ? (y + height) : (r.y + r.height);
-
- x = x1;
- y = y1;
- width = x2 - x1;
- height = y2 - y1;
- isEmpty = false;
- }
- }
-
- public Point2D getOrigin() {
- return new Point2D.Double(x, y);
- }
-
- public PBounds setOrigin(double x, double y) {
- this.x = x;
- this.y = y;
- isEmpty = false;
- return this;
- }
-
- public Dimension2D getSize() {
- return new PDimension(width, height);
- }
-
- public void setSize(double width, double height) {
- setRect(x, y, width, height);
- }
-
- public Point2D getCenter2D() {
- return new Point2D.Double(getCenterX(), getCenterY());
- }
-
- public PBounds moveBy(double dx, double dy) {
- setOrigin(x + dx, y + dy);
- return this;
- }
-
- public void expandNearestIntegerDimensions() {
- x = Math.floor(x);
- y = Math.floor(y);
- width = Math.ceil(width);
- height = Math.ceil(height);
- }
-
- public PBounds inset(double dx, double dy) {
- setRect(x + dx,
- y + dy,
- width - (dx*2),
- height - (dy*2));
- return this;
- }
-
- public PDimension deltaRequiredToCenter(Rectangle2D b) {
- PDimension result = new PDimension();
- double xDelta = getCenterX() - b.getCenterX();
- double yDelta = getCenterY() - b.getCenterY();
- result.setSize(xDelta, yDelta);
- return result;
- }
-
- public PDimension deltaRequiredToContain(Rectangle2D b) {
- PDimension result = new PDimension();
-
- if (!contains(b)) {
- double bMaxX = b.getMaxX();
- double bMinX = b.getMinX();
- double bMaxY = b.getMaxY();
- double bMinY = b.getMinY();
- double maxX = getMaxX();
- double minX = getMinX();
- double maxY = getMaxY();
- double minY = getMinY();
-
- if (!(bMaxX > maxX && bMinX < minX)) {
- if (bMaxX > maxX || bMinX < minX) {
- double difMaxX = bMaxX - maxX;
- double difMinX = bMinX - minX;
- if (Math.abs(difMaxX) < Math.abs(difMinX)) {
- result.width = difMaxX;
- } else {
- result.width = difMinX;
- }
- }
- }
-
- if (!(bMaxY > maxY && bMinY < minY)) {
- if (bMaxY > maxY || bMinY < minY) {
- double difMaxY = bMaxY - maxY;
- double difMinY = bMinY - minY;
- if (Math.abs(difMaxY) < Math.abs(difMinY)) {
- result.height = difMaxY;
- } else {
- result.height = difMinY;
- }
- }
- }
- }
-
- return result;
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- out.writeDouble(x);
- out.writeDouble(y);
- out.writeDouble(width);
- out.writeDouble(height);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- x = in.readDouble();
- y = in.readDouble();
- width = in.readDouble();
- height = in.readDouble();
- }
-
- public String toString() {
- StringBuffer result = new StringBuffer();
-
- result.append(getClass().getName().replaceAll(".*\\.", ""));
- result.append('[');
-
- if (isEmpty) {
- result.append("EMPTY");
- } else {
- result.append("x=");
- result.append(x);
- result.append(",y=");
- result.append(y);
- result.append(",width=");
- result.append(width);
- result.append(",height=");
- result.append(height);
- }
-
- result.append(']');
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PDebug.java b/src/main/java/edu/umd/cs/piccolo/util/PDebug.java
deleted file mode 100755
index c049fc3..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PDebug.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-
-import javax.swing.SwingUtilities;
-
-/**
- * PDebug is used to set framework wide debugging flags.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PDebug {
-
- public static boolean debugRegionManagement = false;
- public static boolean debugPaintCalls = false;
- public static boolean debugPrintFrameRate = false;
- public static boolean debugPrintUsedMemory = false;
- public static boolean debugBounds = false;
- public static boolean debugFullBounds = false;
- public static boolean debugThreads = false;
- public static int printResultsFrameRate = 10;
-
- private static int debugPaintColor;
-
- private static long framesProcessed;
- private static long startProcessingOutputTime;
- private static long startProcessingInputTime;
- private static long processOutputTime;
- private static long processInputTime;
- private static boolean processingOutput;
-
- private PDebug() {
- super();
- }
-
- public static Color getDebugPaintColor() {
- int color = 100 + (debugPaintColor++ % 10) * 10;
- return new Color(color, color, color, 150);
- }
-
- // called when scene graph needs update.
- public static void scheduleProcessInputs() {
- if (debugThreads && !SwingUtilities.isEventDispatchThread()) {
- System.out.println("scene graph manipulated on wrong thread");
- }
- }
-
- public static void processRepaint() {
- if (processingOutput && debugPaintCalls) {
- System.err.println("Got repaint while painting scene. This can result in a recursive process that degrades performance.");
- }
-
- if (debugThreads && !SwingUtilities.isEventDispatchThread()) {
- System.out.println("repaint called on wrong thread");
- }
- }
-
- public static boolean getProcessingOutput() {
- return processingOutput;
- }
-
- public static void startProcessingOutput() {
- processingOutput = true;
- startProcessingOutputTime = System.currentTimeMillis();
- }
-
- public static void endProcessingOutput(Graphics g) {
- processOutputTime += (System.currentTimeMillis() - startProcessingOutputTime);
- framesProcessed++;
-
- if (PDebug.debugPrintFrameRate) {
- if (framesProcessed % printResultsFrameRate == 0) {
- System.out.println("Process output frame rate: " + getOutputFPS() + " fps");
- System.out.println("Process input frame rate: " + getInputFPS() + " fps");
- System.out.println("Total frame rate: " + getTotalFPS() + " fps");
- System.out.println();
- resetFPSTiming();
- }
- }
-
- if (PDebug.debugPrintUsedMemory) {
- if (framesProcessed % printResultsFrameRate == 0) {
- System.out.println("Approximate used memory: " + getApproximateUsedMemory() / 1024 + " k");
- }
- }
-
- if (PDebug.debugRegionManagement) {
- Graphics2D g2 = (Graphics2D)g;
- g.setColor(PDebug.getDebugPaintColor());
- g2.fill(g.getClipBounds().getBounds2D());
- }
-
- processingOutput = false;
- }
-
- public static void startProcessingInput() {
- startProcessingInputTime = System.currentTimeMillis();
- }
-
- public static void endProcessingInput() {
- processInputTime += (System.currentTimeMillis() - startProcessingInputTime);
- }
-
- /**
- * Return how many frames are processed and painted per second.
- * Note that since piccolo doesn't paint continuously this rate
- * will be slow unless you are interacting with the system or have
- * activities scheduled.
- */
- public static double getTotalFPS() {
- if ((framesProcessed > 0)) {
- return 1000.0 / ((processInputTime + processOutputTime) / (double) framesProcessed);
- } else {
- return 0;
- }
- }
-
- /**
- * Return the frames per second used to process
- * input events and activities.
- */
- public static double getInputFPS() {
- if ((processInputTime > 0) && (framesProcessed > 0)) {
- return 1000.0 / (processInputTime / (double) framesProcessed);
- } else {
- return 0;
- }
- }
-
- /**
- * Return the frames per seconds used to paint
- * graphics to the screen.
- */
- public static double getOutputFPS() {
- if ((processOutputTime > 0) && (framesProcessed > 0)) {
- return 1000.0 / (processOutputTime / (double) framesProcessed);
- } else {
- return 0;
- }
- }
-
- /**
- * Return the number of frames that have been processed since the last
- * time resetFPSTiming was called.
- */
- public long getFramesProcessed() {
- return framesProcessed;
- }
-
- /**
- * Reset the variables used to track FPS. If you reset seldom they you will
- * get good average FPS values, if you reset more often only the frames recorded
- * after the last reset will be taken into consideration.
- */
- public static void resetFPSTiming() {
- framesProcessed = 0;
- processInputTime = 0;
- processOutputTime = 0;
- }
-
- public static long getApproximateUsedMemory() {
- System.gc();
- System.runFinalization();
- long totalMemory = Runtime.getRuntime().totalMemory();
- long free = Runtime.getRuntime().freeMemory();
- return totalMemory - free;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PDimension.java b/src/main/java/edu/umd/cs/piccolo/util/PDimension.java
deleted file mode 100755
index 2965b22..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PDimension.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.geom.Dimension2D;
-import java.awt.geom.Point2D;
-import java.io.Serializable;
-
-/**
- * PDimension this class should be removed once a concrete Dimension2D
- * that supports doubles is added to java.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PDimension extends Dimension2D implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 7875655660949128061L;
- public double width;
- public double height;
-
- public PDimension() {
- super();
- }
-
- public PDimension(Dimension2D aDimension) {
- this(aDimension.getWidth(), aDimension.getHeight());
- }
-
- public PDimension(double aWidth, double aHeight) {
- super();
- width = aWidth;
- height = aHeight;
- }
-
- public PDimension(Point2D p1, Point2D p2) {
- width = p2.getX() - p1.getX();
- height = p2.getY() - p1.getY();
- }
-
- public double getHeight() {
- return height;
- }
-
- public double getWidth() {
- return width;
- }
-
- public void setSize(double aWidth, double aHeight) {
- width = aWidth;
- height = aHeight;
- }
-
- public String toString() {
- StringBuffer result = new StringBuffer();
-
- result.append(super.toString().replaceAll(".*\\.", ""));
- result.append('[');
- result.append("width=");
- result.append(width);
- result.append(",height=");
- result.append(height);
- result.append(']');
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PNodeFilter.java b/src/main/java/edu/umd/cs/piccolo/util/PNodeFilter.java
deleted file mode 100755
index 7871d0d..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PNodeFilter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import edu.umd.cs.piccolo.PNode;
-
-/**
- * PNodeFilter is a interface that filters (accepts or rejects) nodes. Its
- * main use is to retrieve all the children of a node the meet some criteria
- * by using the method PNode.getAllNodes(collection, filter);
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public interface PNodeFilter {
-
- /**
- * Return true if the filter should accept the given node.
- */
- public boolean accept(PNode aNode);
-
- /**
- * Return true if the filter should test the children of
- * the given node for acceptance.
- */
- public boolean acceptChildrenOf(PNode aNode);
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PObjectOutputStream.java b/src/main/java/edu/umd/cs/piccolo/util/PObjectOutputStream.java
deleted file mode 100755
index a9b8462..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PObjectOutputStream.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-
-/**
- * PObjectOutputStream is an extension of ObjectOutputStream to handle optional
- * elements. This is similar to the concept of Java's "weak references", but applied to
- * object serialization rather than garbage collection. Here, PObjectOutputStream
- * provides a method, writeConditionalObject
, which only
- * serializes the specified object to the stream if there is a strong reference (if it
- * has been written somewhere else using writeObject()) to that object elsewhere in the
- * stream.
- *
- * To discover strong references to objects, PObjectOutputStream uses a two-phase writing
- * process. First, a "discovery" phase is used to find out what objects are about to
- * be serialized. This works by effectively serializing the object graph to /dev/null, recording
- * which objects are unconditionally written using the standard writeObject method. Then,
- * in the second "write" phase, ObjectOutputStream actually serializes the data
- * to the output stream. During this phase, calls to writeConditionalObject() will
- * only write the specified object if the object was found to be serialized during the
- * discovery stage. If the object was not recorded during the discovery stage, a an optional null
- * (the default) is unconditionally written in place of the object. To skip writting out the
- * null use writeConditionalObject(object, false)
- *
- * By careful implementation of readObject and writeObject methods, streams serialized using
- * PObjectOutputStream can be deserialized using the standard ObjectInputStream.
- *
- * @version 1.0
- * @author Jon Meyer
- * @author Jesse Grosjean
- */
-public class PObjectOutputStream extends ObjectOutputStream {
-
- private boolean writingRoot;
- private HashMap unconditionallyWritten;
-
- public static byte[] toByteArray(Object aRoot) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PObjectOutputStream zout = new PObjectOutputStream(out);
- zout.writeObjectTree(aRoot);
- return out.toByteArray();
- }
-
- public PObjectOutputStream(OutputStream out) throws IOException {
- super(out);
- unconditionallyWritten = new HashMap();
- }
-
- public void writeObjectTree(Object aRoot) throws IOException {
- writingRoot = true;
- recordUnconditionallyWritten(aRoot); // record pass
- writeObject(aRoot); // write pass
- writingRoot = false;
- }
-
- public void writeConditionalObject(Object object) throws IOException {
- if (!writingRoot) {
- throw new RuntimeException("writeConditionalObject() may only be called when a root object has been written.");
- }
-
- if (unconditionallyWritten.containsKey(object)) {
- writeObject(object);
- } else {
- writeObject(null);
- }
- }
-
- public void reset() throws IOException {
- super.reset();
- unconditionallyWritten.clear();
- }
-
- protected void recordUnconditionallyWritten(Object aRoot) throws IOException {
- class ZMarkObjectOutputStream extends PObjectOutputStream {
- public ZMarkObjectOutputStream() throws IOException {
- super(PUtil.NULL_OUTPUT_STREAM);
- enableReplaceObject(true);
- }
- public Object replaceObject(Object object) {
- PObjectOutputStream.this.unconditionallyWritten.put(object, Boolean.TRUE);
- return object;
- }
- public void writeConditionalObject(Object object) throws IOException {
- }
- }
- new ZMarkObjectOutputStream().writeObject(aRoot);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PPaintContext.java b/src/main/java/edu/umd/cs/piccolo/util/PPaintContext.java
deleted file mode 100755
index a548aa2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PPaintContext.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.AlphaComposite;
-import java.awt.Composite;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.font.FontRenderContext;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-import edu.umd.cs.piccolo.PCamera;
-
-/**
-* PPaintContext is used by piccolo nodes to paint themselves on the screen.
- * PPaintContext wraps a Graphics2D to implement painting.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PPaintContext {
-
- public static final int LOW_QUALITY_RENDERING = 0;
- public static final int HIGH_QUALITY_RENDERING = 1;
-
- public static FontRenderContext RENDER_QUALITY_LOW_FRC = new FontRenderContext(null, false, true);
- public static FontRenderContext RENDER_QUALITY_HIGH_FRC = new FontRenderContext(null, true, true);
- public static PPaintContext CURRENT_PAINT_CONTEXT;
-
- private static double[] PTS = new double[4];
-
- private Graphics2D graphics;
- protected PStack compositeStack;
- protected PStack clipStack;
- protected PStack localClipStack;
- protected PStack cameraStack;
- protected PStack transformStack;
- protected int renderQuality;
-
- public PPaintContext(Graphics2D aGraphics) {
- super();
- graphics = aGraphics;
- compositeStack = new PStack();
- clipStack = new PStack();
- localClipStack = new PStack();
- cameraStack = new PStack();
- transformStack = new PStack();
- renderQuality = HIGH_QUALITY_RENDERING;
-
- Shape clip = aGraphics.getClip();
- if (clip == null) {
- clip = new PBounds(
- -Integer.MAX_VALUE / 2,
- -Integer.MAX_VALUE / 2,
- Integer.MAX_VALUE,
- Integer.MAX_VALUE);
- aGraphics.setClip(clip);
- }
-
- localClipStack.push(clip.getBounds2D());
-
- CURRENT_PAINT_CONTEXT = this;
- }
-
- public Graphics2D getGraphics() {
- return graphics;
- }
-
- //****************************************************************
- // Context Attributes.
- //****************************************************************
-
- public Rectangle2D getLocalClip() {
- return (Rectangle2D) localClipStack.peek();
- }
-
- public double getScale() {
- PTS[0] = 0;//x1
- PTS[1] = 0;//y1
- PTS[2] = 1;//x2
- PTS[3] = 0;//y2
- graphics.getTransform().transform(PTS, 0, PTS, 0, 2);
- return Point2D.distance(PTS[0], PTS[1], PTS[2], PTS[3]);
- }
-
- //****************************************************************
- // Context Attribute Stacks. attributes that can be pushed and
- // popped.
- //****************************************************************
-
- public void pushCamera(PCamera aCamera) {
- cameraStack.push(aCamera);
- }
-
- public void popCamera(PCamera aCamera) {
- cameraStack.pop();
- }
-
- public PCamera getCamera() {
- return (PCamera) cameraStack.peek();
- }
-
- public void pushClip(Shape aClip) {
- Shape currentClip = graphics.getClip();
- clipStack.push(currentClip);
- graphics.clip(aClip);
- Rectangle2D newLocalClip = aClip.getBounds2D();
- Rectangle2D.intersect(getLocalClip(), newLocalClip, newLocalClip);
- localClipStack.push(newLocalClip);
- }
-
- public void popClip(Shape aClip) {
- Shape newClip = (Shape) clipStack.pop();
- graphics.setClip(newClip);
- localClipStack.pop();
- }
-
- public void pushTransparency(float transparency) {
- if (transparency == 1) {
- return;
- }
- Composite current = graphics.getComposite();
- float currentAlaph = 1.0f;
- compositeStack.push(current);
-
- if (current instanceof AlphaComposite) {
- currentAlaph = ((AlphaComposite)current).getAlpha();
- }
- AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, currentAlaph * transparency);
- graphics.setComposite(newComposite);
- }
-
- public void popTransparency(float transparency) {
- if (transparency == 1) {
- return;
- }
- Composite c = (Composite) compositeStack.pop();
- graphics.setComposite(c);
- }
-
- public void pushTransform(PAffineTransform aTransform) {
- if (aTransform == null) return;
- Rectangle2D newLocalClip = (Rectangle2D) getLocalClip().clone();
- aTransform.inverseTransform(newLocalClip, newLocalClip);
- transformStack.push(graphics.getTransform());
- localClipStack.push(newLocalClip);
- graphics.transform(aTransform);
- }
-
- public void popTransform(PAffineTransform aTransform) {
- if (aTransform == null) return;
- graphics.setTransform((AffineTransform)transformStack.pop());
- localClipStack.pop();
- }
-
- //****************************************************************
- // Render Quality.
- //****************************************************************/
-
- /**
- * Return the render quality used by this paint context.
- */
- public int getRenderQuality() {
- return renderQuality;
- }
-
- /**
- * Set the rendering hints for this paint context. The render quality is most
- * often set by the rendering PCanvas. Use PCanvas.setRenderQuality() and
- * PCanvas.setInteractingRenderQuality() to set these values.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setRenderQuality(int requestedQuality) {
- renderQuality = requestedQuality;
-
- switch (renderQuality) {
- case HIGH_QUALITY_RENDERING:
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- break;
-
- case LOW_QUALITY_RENDERING:
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
- graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- break;
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PPickPath.java b/src/main/java/edu/umd/cs/piccolo/util/PPickPath.java
deleted file mode 100755
index bc952f2..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PPickPath.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.geom.Dimension2D;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.HashMap;
-
-import javax.swing.event.EventListenerList;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-
-/**
- * PPickPath represents a ordered list of nodes that have been picked.
- * The topmost ancestor node is the first node in the list (and should be a camera),
- * the bottommost child node is at the end of the list. It is this bottom node that
- * is given first chance to handle events, and that any active event handlers usually
- * manipulate.
- *
- * Note that because of layers (which can be picked by multiple camera's) the ordered
- * list of nodes in a pick path do not all share a parent child relationship with the
- * nodes in the list next to them. This means that the normal localToGlobal methods don't
- * work when trying to transform geometry up and down the pick path, instead you should
- * use the pick paths canvasToLocal methods to get the mouse event points into your local
- * coord system.
- *
- * Note that PInputEvent wraps most of the useful PPickPath methods, so often you
- * can use a PInputEvent directly instead of having to access its pick path.
- *
- * @see edu.umd.cs.piccolo.event.PInputEvent
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PPickPath implements PInputEventListener {
-
- public static PPickPath CURRENT_PICK_PATH;
-
- private static double[] PTS = new double[4];
-
- private PStack nodeStack;
- private PStack transformStack;
- private PStack pickBoundsStack;
- private PCamera topCamera;
- private PCamera bottomCamera;
- private HashMap excludedNodes;
-
- public PPickPath(PCamera aCamera, PBounds aScreenPickBounds) {
- super();
- pickBoundsStack = new PStack();
- topCamera = aCamera;
- nodeStack = new PStack();
- transformStack = new PStack();
- pickBoundsStack.push(aScreenPickBounds);
-
- CURRENT_PICK_PATH = this;
- }
-
- public PBounds getPickBounds() {
- return (PBounds) pickBoundsStack.peek();
- }
-
- public boolean acceptsNode(PNode node) {
- if (excludedNodes != null) {
- return !excludedNodes.containsKey(node);
- }
- return true;
- }
-
- //****************************************************************
- // Picked Nodes
- //****************************************************************
-
- public void pushNode(PNode aNode) {
- nodeStack.push(aNode);
- }
-
- public void popNode(PNode aNode) {
- nodeStack.pop();
- }
-
- /**
- * Get the bottom node on the pick path node stack. That is the last node to
- * be picked.
- */
- public PNode getPickedNode() {
- return (PNode) nodeStack.peek();
- }
-
- //****************************************************************
- // Iterating over picked nodes.
- //****************************************************************
-
- /**
- * Return the next node that will be picked after the current picked node.
- * For instance of you have two overlaping children nodes then the topmost
- * child will always be picked first, use this method to find the covered child.
- * Return the camera when no more visual will be picked.
- */
- public PNode nextPickedNode() {
- PNode picked = getPickedNode();
-
- if (picked == topCamera) return null;
- if (excludedNodes == null) excludedNodes = new HashMap();
-
- // exclude current picked node
- excludedNodes.put(picked, picked);
-
- Object screenPickBounds = pickBoundsStack.get(0);
-
- // reset path state
- pickBoundsStack = new PStack();
- nodeStack = new PStack();
- transformStack = new PStack();
- pickBoundsStack = new PStack();
-
- pickBoundsStack.push(screenPickBounds);
-
- // pick again
- topCamera.fullPick(this);
-
- // make sure top camera is pushed.
- if (getNodeStackReference().size() == 0) {
- pushNode(topCamera);
- pushTransform(topCamera.getTransformReference(false));
- }
-
- return getPickedNode();
- }
-
- /**
- * Get the top camera on the pick path. This is the camera that originated the
- * pick action.
- */
- public PCamera getTopCamera() {
- return topCamera;
- }
-
- /**
- * Get the bottom camera on the pick path. This may be different then the top
- * camera if internal cameras are in use.
- */
- public PCamera getBottomCamera() {
- if (bottomCamera == null) {
- for (int i = nodeStack.size() - 1; i >= 0; i--) {
- PNode each = (PNode) nodeStack.get(i);
- if (each instanceof PCamera) {
- bottomCamera = (PCamera) each;
- return bottomCamera;
- }
- }
- }
- return bottomCamera;
- }
-
- public PStack getNodeStackReference() {
- return nodeStack;
- }
-
- //****************************************************************
- // Path Transform
- //****************************************************************
-
- public double getScale() {
- PTS[0] = 0;//x1
- PTS[1] = 0;//y1
- PTS[2] = 1;//x2
- PTS[3] = 0;//y2
-
- int count = transformStack.size();
- for (int i = 0; i < count; i++) {
- PAffineTransform each = ((PTuple)transformStack.get(i)).transform;
- if (each != null)
- each.transform(PTS, 0, PTS, 0, 2);
- }
-
- return Point2D.distance(PTS[0], PTS[1], PTS[2], PTS[3]);
- }
-
- public void pushTransform(PAffineTransform aTransform) {
- transformStack.push(new PTuple(getPickedNode(), aTransform));
- if (aTransform != null) {
- Rectangle2D newPickBounds = (Rectangle2D) getPickBounds().clone();
- aTransform.inverseTransform(newPickBounds, newPickBounds);
- pickBoundsStack.push(newPickBounds);
- }
- }
-
- public void popTransform(PAffineTransform aTransform) {
- transformStack.pop();
- if (aTransform != null) {
- pickBoundsStack.pop();
- }
- }
-
- public PAffineTransform getPathTransformTo(PNode nodeOnPath) {
- PAffineTransform aTransform = new PAffineTransform();
-
- int count = transformStack.size();
- for (int i = 0; i < count; i++) {
- PTuple each = (PTuple) transformStack.get(i);
- if (each.transform != null) aTransform.concatenate(each.transform);
- if (nodeOnPath == each.node) {
- return aTransform;
- }
- }
-
- throw new RuntimeException("Node could not be found on pick path");
- }
-
- //****************************************************************
- // Process Events - Give each node in the pick path, starting at
- // the bottom most one, a chance to handle the event.
- //****************************************************************
-
- public void processEvent(PInputEvent aEvent, int type) {
- aEvent.setPath(this);
-
- for (int i = nodeStack.size() - 1; i >= 0; i--) {
- PNode each = (PNode) nodeStack.get(i);
-
- EventListenerList list = each.getListenerList();
-
- if (list != null) {
- Object[] listeners = list.getListeners(PInputEventListener.class);
-
- for (int j = 0; j < listeners.length; j++) {
- PInputEventListener listener = (PInputEventListener) listeners[j];
- listener.processEvent(aEvent, type);
- }
- }
- }
- }
-
- //****************************************************************
- // Transforming Geometry - Methods to transform geometry through
- // this path.
- //
- // Note that this is different that just using the
- // PNode.localToGlobal (an other coord system transform methods).
- // The PNode coord system transform methods always go directly up
- // through their parents. The PPickPath coord system transform
- // methods go up through the list of picked nodes instead. And since
- // cameras can pick their layers in addition to their children these
- // two paths may be different.
- //****************************************************************
-
- /**
- * Convert the given point from the canvas coordinates, down through
- * the pick path (and through any camera view transforms applied to the
- * path) to the local coordinates of the given node.
- */
- public Point2D canvasToLocal(Point2D canvasPoint, PNode nodeOnPath) {
- try {
- return getPathTransformTo(nodeOnPath).inverseTransform(canvasPoint, canvasPoint);
- } catch (NoninvertibleTransformException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Convert the given dimension from the canvas coordinates, down through
- * the pick path (and through any camera view transforms applied to the
- * path) to the local coordinates of the given node.
- */
- public Dimension2D canvasToLocal(Dimension2D canvasDimension, PNode nodeOnPath) {
- return getPathTransformTo(nodeOnPath).inverseTransform(canvasDimension, canvasDimension);
- }
-
- /**
- * Convert the given rectangle from the canvas coordinates, down through
- * the pick path (and through any camera view transforms applied to the
- * path) to the local coordinates of the given node.
- */
- public Rectangle2D canvasToLocal(Rectangle2D canvasRectangle, PNode nodeOnPath) {
- return getPathTransformTo(nodeOnPath).inverseTransform(canvasRectangle, canvasRectangle);
- }
-
- /**
- * Used to associated nodes with their transforms on the transform stack.
- */
- private static class PTuple {
- public PNode node;
- public PAffineTransform transform;
-
- public PTuple(PNode n, PAffineTransform t) {
- node = n;
- transform = t;
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PStack.java b/src/main/java/edu/umd/cs/piccolo/util/PStack.java
deleted file mode 100755
index 5634504..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PStack.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.util.ArrayList;
-
-/**
- * PStack this class should be removed when a non thread safe stack is added
- * to the java class libraries.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PStack extends ArrayList {
-
- /**
- *
- */
- private static final long serialVersionUID = 2929656658135843946L;
-
- public PStack() {
- }
-
- public void push(Object o) {
- add(o);
- }
-
- public Object peek() {
- int s = size();
- if (s == 0) {
- return null;
- } else {
- return get(s - 1);
- }
- }
-
- public Object pop() {
- if (size()==0) return null;
- return remove(size() - 1);
- }
-}
-
diff --git a/src/main/java/edu/umd/cs/piccolo/util/PUtil.java b/src/main/java/edu/umd/cs/piccolo/util/PUtil.java
deleted file mode 100755
index 05d7174..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/PUtil.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolo.util;
-
-import java.awt.BasicStroke;
-import java.awt.Stroke;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PRoot;
-
-/**
- * PUtil util methods for the Piccolo framework.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PUtil {
-
- @SuppressWarnings("unchecked")
- public static Iterator NULL_ITERATOR = Collections.EMPTY_LIST.iterator();
- @SuppressWarnings("unchecked")
- public static Enumeration NULL_ENUMERATION = new Enumeration() {
- public boolean hasMoreElements() { return false; }
- public Object nextElement() { return null; }
- };
- public static long DEFAULT_ACTIVITY_STEP_RATE = 20;
- public static int ACTIVITY_SCHEDULER_FRAME_DELAY = 10;
-
- public static OutputStream NULL_OUTPUT_STREAM = new OutputStream() {
- public void close() { }
- public void flush() { }
- public void write(byte[] b) { }
- public void write(byte[] b, int off, int len) { }
- public void write(int b) { }
- };
-
- public static PCamera createBasicScenegraph() {
- PRoot r = new PRoot();
- PLayer l = new PLayer();
- PCamera c = new PCamera();
-
- r.addChild(c);
- r.addChild(l);
- c.addLayer(l);
-
- return c;
- }
-
- public static void writeStroke(Stroke aStroke, ObjectOutputStream out) throws IOException {
- if (aStroke instanceof Serializable) {
- out.writeBoolean(true);
- out.writeBoolean(true);
- out.writeObject(aStroke);
- } else if (aStroke instanceof BasicStroke) {
- out.writeBoolean(true);
- out.writeBoolean(false);
- BasicStroke s = (BasicStroke) aStroke;
-
- float[] dash = s.getDashArray();
-
- if (dash == null) {
- out.write(0);
- } else {
- out.write(dash.length);
- for (int i = 0; i < dash.length; i++) {
- out.writeFloat(dash[i]);
- }
- }
-
- out.writeFloat(s.getLineWidth());
- out.writeInt(s.getEndCap());
- out.writeInt(s.getLineJoin());
- out.writeFloat(s.getMiterLimit());
- out.writeFloat(s.getDashPhase());
- } else {
- out.writeBoolean(false);
- }
- }
-
- public static Stroke readStroke(ObjectInputStream in) throws IOException, ClassNotFoundException {
- boolean wroteStroke = in.readBoolean();
- if (wroteStroke) {
- boolean serializedStroke = in.readBoolean();
- if (serializedStroke) {
- return (Stroke) in.readObject();
- } else {
- float[] dash = null;
- int dashLength = in.read();
-
- if (dashLength != 0) {
- dash = new float[dashLength];
- for (int i = 0; i < dashLength; i++) {
- dash[i] = in.readFloat();
- }
- }
-
- float lineWidth = in.readFloat();
- int endCap = in.readInt();
- int lineJoin = in.readInt();
- float miterLimit = in.readFloat();
- float dashPhase = in.readFloat();
-
- return new BasicStroke(lineWidth, endCap, lineJoin, miterLimit, dash, dashPhase);
- }
- } else {
- return null;
- }
- }
-
- private static final int PATH_IS_DONE = -1;
-
- public static GeneralPath readPath(ObjectInputStream in) throws IOException, ClassNotFoundException {
- GeneralPath path = new GeneralPath();
-
- while(true) {
- int segType = in.readInt();
-
- switch(segType) {
- case PathIterator.SEG_MOVETO:
- path.moveTo(in.readFloat(), in.readFloat());
- break;
-
- case PathIterator.SEG_LINETO:
- path.lineTo(in.readFloat(), in.readFloat());
- break;
-
- case PathIterator.SEG_QUADTO:
- path.quadTo(in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
- break;
-
- case PathIterator.SEG_CUBICTO:
- path.curveTo(in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
- break;
-
- case PathIterator.SEG_CLOSE:
- path.closePath();
- break;
-
- case PATH_IS_DONE:
- return path;
-
- default:
- throw new IOException();
- }
- }
- }
-
- public static void writePath(GeneralPath path, ObjectOutputStream out) throws IOException {
- PathIterator i = path.getPathIterator(null);
- float[] data = new float[6];
-
- while(!i.isDone()) {
- switch(i.currentSegment(data)) {
- case PathIterator.SEG_MOVETO:
- out.writeInt(PathIterator.SEG_MOVETO);
- out.writeFloat(data[0]);
- out.writeFloat(data[1]);
- break;
-
- case PathIterator.SEG_LINETO:
- out.writeInt(PathIterator.SEG_LINETO);
- out.writeFloat(data[0]);
- out.writeFloat(data[1]);
- break;
-
- case PathIterator.SEG_QUADTO:
- out.writeInt(PathIterator.SEG_QUADTO);
- out.writeFloat(data[0]);
- out.writeFloat(data[1]);
- out.writeFloat(data[2]);
- out.writeFloat(data[3]);
- break;
-
- case PathIterator.SEG_CUBICTO:
- out.writeInt(PathIterator.SEG_CUBICTO);
- out.writeFloat(data[0]);
- out.writeFloat(data[1]);
- out.writeFloat(data[2]);
- out.writeFloat(data[3]);
- out.writeFloat(data[4]);
- out.writeFloat(data[5]);
- break;
-
- case PathIterator.SEG_CLOSE :
- out.writeInt(PathIterator.SEG_CLOSE);
- break;
-
- default :
- throw new IOException();
- }
-
- i.next();
- }
-
- out.writeInt(PATH_IS_DONE);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolo/util/package.html b/src/main/java/edu/umd/cs/piccolo/util/package.html
deleted file mode 100755
index c6af443..0000000
--- a/src/main/java/edu/umd/cs/piccolo/util/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This package defines several utility classes that are likely
-to be useful for Piccolo applications. These utility classes are
-also used within the implementation of Piccolo.
-
diff --git a/src/main/java/edu/umd/cs/piccolox/PApplet.java b/src/main/java/edu/umd/cs/piccolox/PApplet.java
deleted file mode 100755
index eb8da9a..0000000
--- a/src/main/java/edu/umd/cs/piccolox/PApplet.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package edu.umd.cs.piccolox;
-
-import javax.swing.JApplet;
-import javax.swing.SwingUtilities;
-
-import edu.umd.cs.piccolo.PCanvas;
-
-/**
- * PApplet is meant to be subclassed by applications that just need a PCanvas
- * embedded in a web page.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PApplet extends JApplet {
-
- /**
- *
- */
- private static final long serialVersionUID = -2441920979147009156L;
- private PCanvas canvas;
-
- public void init() {
- setBackground(null);
-
- canvas = createCanvas();
- getContentPane().add(canvas);
- validate();
- canvas.requestFocus();
- beforeInitialize();
-
- // Manipulation of Piccolo's scene graph should be done from Swings
- // event dispatch thread since Piccolo is not thread safe. This code calls
- // initialize() from that thread once the PFrame is initialized, so you are
- // safe to start working with Piccolo in the initialize() method.
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- PApplet.this.initialize();
- repaint();
- }
- });
- }
-
- public PCanvas getCanvas() {
- return canvas;
- }
-
- public PCanvas createCanvas() {
- return new PCanvas();
- }
-
- //****************************************************************
- // Initialize
- //****************************************************************
-
- /**
- * This method will be called before the initialize() method and will be
- * called on the thread that is constructing this object.
- */
- public void beforeInitialize() {
- }
-
- /**
- * Subclasses should override this method and add their
- * Piccolo initialization code there. This method will be called on the
- * swing event dispatch thread. Note that the constructors of PFrame
- * subclasses may not be complete when this method is called. If you need to
- * initailize some things in your class before this method is called place
- * that code in beforeInitialize();
- */
- public void initialize() {
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/PFrame.java b/src/main/java/edu/umd/cs/piccolox/PFrame.java
deleted file mode 100755
index db4f860..0000000
--- a/src/main/java/edu/umd/cs/piccolox/PFrame.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox;
-
-import java.awt.DisplayMode;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
-import java.awt.Rectangle;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.EventListener;
-import java.util.Iterator;
-
-import javax.swing.JFrame;
-import javax.swing.SwingUtilities;
-
-import edu.umd.cs.piccolo.PCanvas;
-
-/**
- * PFrame is meant to be subclassed by applications that just need a PCanvas in a JFrame.
- * It also includes full screen mode functionality when run in JDK 1.4. These
- * subclasses should override the initialize method and start adding their own
- * code there. Look in the examples package to see lots of uses of PFrame.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PFrame extends JFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = -884659863762387296L;
- private PCanvas canvas;
- private GraphicsDevice graphicsDevice;
- private EventListener escapeFullScreenModeListener;
-
- public PFrame() {
- this("", false, null);
- }
-
- public PFrame(String title, boolean fullScreenMode, PCanvas aCanvas) {
- this(title, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), fullScreenMode, aCanvas);
- }
-
- public PFrame(String title, GraphicsDevice aDevice, final boolean fullScreenMode, final PCanvas aCanvas) {
- super(title, aDevice.getDefaultConfiguration());
-
- graphicsDevice = aDevice;
-
- setBackground(null);
- setBounds(getDefaultFrameBounds());
-
- try {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- } catch (SecurityException e) {} // expected from applets
-
- if (aCanvas == null) {
- canvas = new PCanvas();
- } else {
- canvas = aCanvas;
- }
-
- getContentPane().setLayout(null);
- getContentPane().add(canvas);
- validate();
- setFullScreenMode(fullScreenMode);
- canvas.requestFocus();
- beforeInitialize();
-
- // Make canvas bounds follow containing frame bounds
- addComponentListener(new ComponentAdapter() {
- public void componentResized(java.awt.event.ComponentEvent e) {
- canvas.setBounds(0, 0, getWidth(), getHeight());
- }
- });
-
- // Manipulation of Piccolo's scene graph should be done from Swings
- // event dispatch thread since Piccolo is not thread safe. This code calls
- // initialize() from that thread once the PFrame is initialized, so you are
- // safe to start working with Piccolo in the initialize() method.
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- PFrame.this.initialize();
- repaint();
- }
- });
- }
-
- public PCanvas getCanvas() {
- return canvas;
- }
-
- public Rectangle getDefaultFrameBounds() {
- return new Rectangle(100, 100, 400, 400);
- }
-
- //****************************************************************
- // Full Screen Display Mode
- //****************************************************************
-
- public boolean isFullScreenMode() {
- return graphicsDevice.getFullScreenWindow() != null;
- }
-
- public void setFullScreenMode(boolean fullScreenMode) {
- if (fullScreenMode) {
- addEscapeFullScreenModeListener();
-
- if (isDisplayable()) {
- dispose();
- }
-
- setUndecorated(true);
- setResizable(false);
- graphicsDevice.setFullScreenWindow(this);
-
- if (graphicsDevice.isDisplayChangeSupported()) {
- chooseBestDisplayMode(graphicsDevice);
- }
- validate();
- } else {
- removeEscapeFullScreenModeListener();
-
- if (isDisplayable()) {
- dispose();
- }
-
- setUndecorated(false);
- setResizable(true);
- graphicsDevice.setFullScreenWindow(null);
- validate();
- setVisible(true);
- }
- }
-
- protected void chooseBestDisplayMode(GraphicsDevice device) {
- DisplayMode best = getBestDisplayMode(device);
- if (best != null) {
- device.setDisplayMode(best);
- }
- }
-
- protected DisplayMode getBestDisplayMode(GraphicsDevice device) {
- Iterator itr = getPreferredDisplayModes(device).iterator();
- while (itr.hasNext()) {
- DisplayMode each = (DisplayMode) itr.next();
- DisplayMode[] modes = device.getDisplayModes();
- for (int i = 0; i < modes.length; i++) {
- if (modes[i].getWidth() == each.getWidth() &&
- modes[i].getHeight() == each.getHeight() &&
- modes[i].getBitDepth() == each.getBitDepth()) {
- return each;
- }
- }
- }
-
- return null;
- }
-
- /**
- * By default return the current display mode. Subclasses may override this method
- * to return other modes in the collection.
- */
- protected Collection getPreferredDisplayModes(GraphicsDevice device) {
- ArrayList result = new ArrayList();
-
- result.add(device.getDisplayMode());
- /*result.add(new DisplayMode(640, 480, 32, 0));
- result.add(new DisplayMode(640, 480, 16, 0));
- result.add(new DisplayMode(640, 480, 8, 0));*/
-
- return result;
- }
-
- /**
- * This method adds a key listener that will take this PFrame out of full
- * screen mode when the escape key is pressed. This is called for you
- * automatically when the frame enters full screen mode.
- */
- public void addEscapeFullScreenModeListener() {
- removeEscapeFullScreenModeListener();
- escapeFullScreenModeListener = new KeyAdapter() {
- public void keyPressed(KeyEvent aEvent) {
- if (aEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
- setFullScreenMode(false);
- }
- }
- };
- canvas.addKeyListener((KeyListener)escapeFullScreenModeListener);
- }
-
- /**
- * This method removes the escape full screen mode key listener. It will be
- * called for you automatically when full screen mode exits, but the method
- * has been made public for applications that wish to use other methods for
- * exiting full screen mode.
- */
- public void removeEscapeFullScreenModeListener() {
- if (escapeFullScreenModeListener != null) {
- canvas.removeKeyListener((KeyListener)escapeFullScreenModeListener);
- escapeFullScreenModeListener = null;
- }
- }
-
- //****************************************************************
- // Initialize
- //****************************************************************
-
- /**
- * This method will be called before the initialize() method and will be
- * called on the thread that is constructing this object.
- */
- public void beforeInitialize() {
- }
-
- /**
- * Subclasses should override this method and add their
- * Piccolo initialization code there. This method will be called on the
- * swing event dispatch thread. Note that the constructors of PFrame
- * subclasses may not be complete when this method is called. If you need to
- * initailize some things in your class before this method is called place
- * that code in beforeInitialize();
- */
- public void initialize() {
- }
-
- public static void main(String[] argv) {
- new PFrame();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/activities/PPathActivity.java b/src/main/java/edu/umd/cs/piccolox/activities/PPathActivity.java
deleted file mode 100755
index e38a6df..0000000
--- a/src/main/java/edu/umd/cs/piccolox/activities/PPathActivity.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.activities;
-
-import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
-
-/**
- * PPathActivity is the abstract base class for all path
- * activity interpolators. Path activities interpolate between multiple states
- * over the duration of the activity.
- *
- * Knots are used to determine when in time the activity should move from state
- * to state. Knot values should be increasing in value from 0 to 1 inclusive.
- * This class is based on the Java 3D PathInterpolator object, see that class
- * documentation for more information on the basic concepts used in this classes
- * design.
- *
- * See PPositionPathActivity for a concrete path activity that will animate
- * through a list of points.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public abstract class PPathActivity extends PInterpolatingActivity {
-
- protected float[] knots;
-
- public PPathActivity(long duration, long stepRate, float[] knots) {
- this(duration, stepRate, 0, PInterpolatingActivity.SOURCE_TO_DESTINATION, knots);
- }
-
- public PPathActivity(long duration, long stepRate, int loopCount, int mode, float[] knots) {
- super(duration, stepRate, loopCount, mode);
- setKnots(knots);
- }
-
- public int getKnotsLength() {
- return knots.length;
- }
-
- public void setKnots(float[] knots) {
- this.knots = knots;
- }
-
- public float[] getKnots() {
- return knots;
- }
-
- public void setKnot(int index, float knot) {
- knots[index] = knot;
- }
-
- public float getKnot(int index) {
- return knots[index];
- }
-
- public void setRelativeTargetValue(float zeroToOne) {
- int currentKnotIndex = 0;
-
- while (zeroToOne > knots[currentKnotIndex]) {
- currentKnotIndex++;
- }
-
- int startKnot = currentKnotIndex - 1;
- int endKnot = currentKnotIndex;
-
- if (startKnot < 0) startKnot = 0;
- if (endKnot > getKnotsLength() - 1) endKnot = getKnotsLength() - 1;
-
- float currentRange = knots[endKnot] - knots[startKnot];
- float currentPointOnRange = zeroToOne - knots[startKnot];
- float normalizedPointOnRange = currentPointOnRange;
-
- if (currentRange != 0) {
- normalizedPointOnRange = currentPointOnRange / currentRange;
- }
-
- setRelativeTargetValue(normalizedPointOnRange, startKnot, endKnot);
- }
-
- public abstract void setRelativeTargetValue(float zeroToOne, int startKnot, int endKnot);
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/activities/PPositionPathActivity.java b/src/main/java/edu/umd/cs/piccolox/activities/PPositionPathActivity.java
deleted file mode 100755
index f619a0e..0000000
--- a/src/main/java/edu/umd/cs/piccolox/activities/PPositionPathActivity.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.activities;
-
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-
-import edu.umd.cs.piccolo.activities.PInterpolatingActivity;
-
-/**
- * PPositionPathActivity animates through a sequence of points.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PPositionPathActivity extends PPathActivity {
-
- protected Point2D[] positions;
- protected Target target;
-
- public interface Target {
- public void setPosition(double x, double y);
- }
-
- public PPositionPathActivity(long duration, long stepRate, Target aTarget) {
- this(duration, stepRate, aTarget, null, null);
- }
-
- public PPositionPathActivity(long duration, long stepRate, Target aTarget, float[] knots, Point2D[] positions) {
- this(duration, stepRate, 1, PInterpolatingActivity.SOURCE_TO_DESTINATION, aTarget, knots, positions);
- }
-
- public PPositionPathActivity(long duration, long stepRate, int loopCount, int mode, Target aTarget, float[] knots, Point2D[] positions) {
- super(duration, stepRate, loopCount, mode, knots);
- target = aTarget;
- this.positions = positions;
- }
-
- protected boolean isAnimation() {
- return true;
- }
-
- public Point2D[] getPositions() {
- return positions;
- }
-
- public Point2D getPosition(int index) {
- return positions[index];
- }
-
- public void setPositions(Point2D[] positions) {
- this.positions = positions;
- }
-
- public void setPosition(int index, Point2D position) {
- positions[index] = position;
- }
-
- public void setPositions(GeneralPath path) {
- PathIterator pi = path.getPathIterator(null, 1);
- ArrayList points = new ArrayList();
- float point[] = new float[6];
- float distanceSum = 0;
- float lastMoveToX = 0;
- float lastMoveToY = 0;
-
- while (!pi.isDone()) {
- int type = pi.currentSegment(point);
-
- switch (type) {
- case PathIterator.SEG_MOVETO:
- points.add(new Point2D.Float(point[0], point[1]));
- lastMoveToX = point[0];
- lastMoveToY = point[1];
- break;
-
- case PathIterator.SEG_LINETO:
- points.add(new Point2D.Float(point[0], point[1]));
- break;
-
- case PathIterator.SEG_CLOSE:
- points.add(new Point2D.Float(lastMoveToX, lastMoveToY));
- break;
-
- case PathIterator.SEG_QUADTO:
- case PathIterator.SEG_CUBICTO:
- throw new RuntimeException();
- }
-
- if (points.size() > 1) {
- Point2D last = (Point2D) points.get(points.size() - 2);
- Point2D current = (Point2D) points.get(points.size() - 1);
- distanceSum += last.distance(current);
- }
-
- pi.next();
- }
-
- int size = points.size();
- Point2D newPositions[] = new Point2D[size];
- float newKnots[] = new float[size];
-
- for (int i = 0; i < size; i++) {
- newPositions[i] = (Point2D) points.get(i);
- if (i > 0) {
- float dist = (float) newPositions[i - 1].distance(newPositions[i]);
- newKnots[i] = newKnots[i - 1] + (dist / distanceSum);
- }
- }
-
- setPositions(newPositions);
- setKnots(newKnots);
- }
-
- public void setRelativeTargetValue(float zeroToOne, int startKnot, int endKnot) {
- Point2D start = getPosition(startKnot);
- Point2D end = getPosition(endKnot);
- target.setPosition(start.getX() + (zeroToOne * (end.getX() - start.getX())),
- start.getY() + (zeroToOne * (end.getY() - start.getY())));
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java b/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java
deleted file mode 100755
index df65b4f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.event;
-
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.activities.PTransformActivity;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-
-/**
- * PNavigationEventHandler implements simple focus based navigation. Uses
- * mouse button one or the arrow keys to set a new focus. Animates the canvas
- * view to keep the focus node on the screen and at 100 percent scale with minimal
- * view movement.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PNavigationEventHandler extends PBasicInputEventHandler {
-
- public static final int NORTH = 0;
- public static final int SOUTH = 1;
- public static final int EAST = 2;
- public static final int WEST = 3;
- public static final int IN = 4;
- public static final int OUT = 5;
-
- @SuppressWarnings("unchecked")
- private static Hashtable NODE_TO_GLOBAL_NODE_CENTER_MAPPING = new Hashtable();
-
- private PNode focusNode;
- private PActivity navigationActivity;
-
- public PNavigationEventHandler() {
- super();
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- //****************************************************************
- // Focus Change Events.
- //****************************************************************
-
- public void keyPressed(PInputEvent e) {
- PNode oldLocation = focusNode;
-
- switch (e.getKeyCode()) {
- case KeyEvent.VK_LEFT:
- moveFocusLeft(e);
- break;
-
- case KeyEvent.VK_RIGHT:
- moveFocusRight(e);
- break;
-
- case KeyEvent.VK_UP:
- case KeyEvent.VK_PAGE_UP:
- if (e.isAltDown()) {
- moveFocusOut(e);
- } else {
- moveFocusUp(e);
- }
- break;
-
- case KeyEvent.VK_DOWN:
- case KeyEvent.VK_PAGE_DOWN:
- if (e.isAltDown()) {
- moveFocusIn(e);
- } else {
- moveFocusDown(e);
- }
- break;
- }
-
- if (focusNode != null && oldLocation != focusNode) {
- directCameraViewToFocus(e.getCamera(), focusNode, 500);
- }
- }
-
- public void mousePressed(PInputEvent aEvent) {
- moveFocusToMouseOver(aEvent);
-
- if (focusNode != null) {
- directCameraViewToFocus(aEvent.getCamera(), focusNode, 500);
- aEvent.getInputManager().setKeyboardFocus(aEvent.getPath());
- }
- }
-
- //****************************************************************
- // Focus Movement - Moves the focus the specified direction. Left,
- // right, up, down mean move the focus to the closest sibling of the
- // current focus node that exists in that direction. Move in means
- // move the focus to a child of the current focus, move out means
- // move the focus to the parent of the current focus.
- //****************************************************************
-
- public void moveFocusDown(PInputEvent e) {
- PNode n = getNeighborInDirection(SOUTH);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusIn(PInputEvent e) {
- PNode n = getNeighborInDirection(IN);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusLeft(PInputEvent e) {
- PNode n = getNeighborInDirection(WEST);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusOut(PInputEvent e) {
- PNode n = getNeighborInDirection(OUT);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusRight(PInputEvent e) {
- PNode n = getNeighborInDirection(EAST);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusUp(PInputEvent e) {
- PNode n = getNeighborInDirection(NORTH);
-
- if (n != null) {
- focusNode = n;
- }
- }
-
- public void moveFocusToMouseOver(PInputEvent e) {
- PNode focus = e.getPickedNode();
- if (!(focus instanceof PCamera)) {
- focusNode = focus;
- }
- }
-
- @SuppressWarnings("unchecked")
- public PNode getNeighborInDirection(int aDirection) {
- if (focusNode == null) return null;
-
- NODE_TO_GLOBAL_NODE_CENTER_MAPPING.clear();
-
- Point2D highlightCenter = focusNode.getGlobalFullBounds().getCenter2D();
- NODE_TO_GLOBAL_NODE_CENTER_MAPPING.put(focusNode, highlightCenter);
-
- List l = getNeighbors();
- sortNodesByDistanceFromPoint(l, highlightCenter);
-
- Iterator i = l.iterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (nodeIsNeighborInDirection(each, aDirection)) {
- return each;
- }
- }
-
- return null;
- }
-
- public List getNeighbors() {
- ArrayList result = new ArrayList();
-
- if (focusNode == null) return result;
- if (focusNode.getParent() == null) return result;
-
- PNode focusParent = focusNode.getParent();
-
- Iterator i = focusParent.getChildrenIterator();
-
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (each != focusNode && each.getPickable()) {
- result.add(each);
- }
- }
-
- result.add(focusParent);
-
- i = focusNode.getChildrenIterator();
- while (i.hasNext()) {
- result.add(i.next());
- }
-
- return result;
- }
-
- public boolean nodeIsNeighborInDirection(PNode aNode, int aDirection) {
- switch (aDirection) {
- case IN: {
- return aNode.isDescendentOf(focusNode);
- }
-
- case OUT: {
- return aNode.isAncestorOf(focusNode);
- }
-
- default: {
- if (aNode.isAncestorOf(focusNode) || aNode.isDescendentOf(focusNode)) {
- return false;
- }
- }
- }
-
- Point2D highlightCenter = (Point2D) NODE_TO_GLOBAL_NODE_CENTER_MAPPING.get(focusNode);
- Point2D nodeCenter = (Point2D) NODE_TO_GLOBAL_NODE_CENTER_MAPPING.get(aNode);
-
- double ytest1 = nodeCenter.getX() - highlightCenter.getX() + highlightCenter.getY();
- double ytest2 = -nodeCenter.getX() + highlightCenter.getX() + highlightCenter.getY();
-
- switch (aDirection) {
- case NORTH: {
- if (nodeCenter.getY() < highlightCenter.getY()) {
- if (nodeCenter.getY() < ytest1 && nodeCenter.getY() < ytest2) {
- return true;
- }
- }
- break;
- }
-
- case EAST: {
- if (nodeCenter.getX() > highlightCenter.getX()) {
- if (nodeCenter.getY() < ytest1 && nodeCenter.getY() > ytest2) {
- return true;
- }
- }
- break;
- }
-
- case SOUTH: {
- if (nodeCenter.getY() > highlightCenter.getY()) {
- if (nodeCenter.getY() > ytest1 && nodeCenter.getY() > ytest2) {
- return true;
- }
- }
- break;
- }
- case WEST: {
- if (nodeCenter.getX() < highlightCenter.getX()) {
- if (nodeCenter.getY() > ytest1 && nodeCenter.getY() < ytest2) {
- return true;
- }
- }
- break;
- }
- }
- return false;
- }
-
- @SuppressWarnings("unchecked")
- public void sortNodesByDistanceFromPoint(List aNodesList, final Point2D aPoint) {
- Collections.sort(aNodesList, new Comparator() {
- public int compare(Object o1, Object o2) {
- PNode each1 = (PNode) o1;
- PNode each2 = (PNode) o2;
- Point2D each1Center = each1.getGlobalFullBounds().getCenter2D();
- Point2D each2Center = each2.getGlobalFullBounds().getCenter2D();
-
- NODE_TO_GLOBAL_NODE_CENTER_MAPPING.put(each1, each1Center);
- NODE_TO_GLOBAL_NODE_CENTER_MAPPING.put(each2, each2Center);
-
- double distance1 = aPoint.distance(each1Center);
- double distance2 = aPoint.distance(each2Center);
-
- if (distance1 < distance2) {
- return -1;
- } else if (distance1 == distance2) {
- return 0;
- } else {
- return 1;
- }
- }
- });
- }
-
- //****************************************************************
- // Canvas Movement - The canvas view is updated so that the current
- // focus remains visible on the screen at 100 percent scale.
- //****************************************************************
-
- protected PActivity animateCameraViewTransformTo(final PCamera aCamera, AffineTransform aTransform, int duration) {
- boolean wasOldAnimation = false;
-
- // first stop any old animations.
- if (navigationActivity != null) {
- navigationActivity.terminate();
- wasOldAnimation = true;
- }
-
- if (duration == 0) {
- aCamera.setViewTransform(aTransform);
- return null;
- }
-
- AffineTransform source = aCamera.getViewTransformReference();
-
- if (!source.equals(aTransform)) {
- navigationActivity = aCamera.animateViewToTransform(aTransform, duration);
- ((PTransformActivity)navigationActivity).setSlowInSlowOut(!wasOldAnimation);
- return navigationActivity;
- }
-
- return null;
- }
-
- public PActivity directCameraViewToFocus(PCamera aCamera, PNode aFocusNode, int duration) {
- focusNode = aFocusNode;
- AffineTransform originalViewTransform = aCamera.getViewTransform();
-
- // Scale the canvas to include
- PDimension d = new PDimension(1, 0);
- focusNode.globalToLocal(d);
-
- double scaleFactor = d.getWidth() / aCamera.getViewScale();
- Point2D scalePoint = focusNode.getGlobalFullBounds().getCenter2D();
- if (scaleFactor != 1) {
- aCamera.scaleViewAboutPoint(scaleFactor, scalePoint.getX(), scalePoint.getY());
- }
-
- // Pan the canvas to include the view bounds with minimal canvas
- // movement.
- aCamera.animateViewToPanToBounds(focusNode.getGlobalFullBounds(), 0);
-
- // Get rid of any white space. The canvas may be panned and
- // zoomed in to do this. But make sure not stay constrained by max
- // magnification.
- //fillViewWhiteSpace(aCamera);
-
- AffineTransform resultingTransform = aCamera.getViewTransform();
- aCamera.setViewTransform(originalViewTransform);
-
- // Animate the canvas so that it ends up with the given
- // view transform.
- return animateCameraViewTransformTo(aCamera, resultingTransform, duration);
- }
-
- protected void fillViewWhiteSpace(PCamera aCamera) {
- PBounds rootBounds = aCamera.getRoot().getFullBoundsReference();
- PBounds viewBounds = aCamera.getViewBounds();
-
- if (!rootBounds.contains(aCamera.getViewBounds())) {
- aCamera.animateViewToPanToBounds(rootBounds, 0);
- aCamera.animateViewToPanToBounds(focusNode.getGlobalFullBounds(), 0);
-
- // center content.
- double dx = 0;
- double dy = 0;
- viewBounds = aCamera.getViewBounds();
-
- if (viewBounds.getWidth() > rootBounds.getWidth()) { // then center along x axis.
- double boundsCenterX = rootBounds.getMinX() + (rootBounds.getWidth() / 2);
- double viewBoundsCenterX = viewBounds.getMinX() + (viewBounds.getWidth() / 2);
- dx = viewBoundsCenterX - boundsCenterX;
- }
-
- if (viewBounds.getHeight() > rootBounds.getHeight()) { // then center along y axis.
- double boundsCenterY = rootBounds.getMinY() + (rootBounds.getHeight() / 2);
- double viewBoundsCenterY = viewBounds.getMinY() + (viewBounds.getHeight() / 2);
- dy = viewBoundsCenterY - boundsCenterY;
- }
- aCamera.translateView(dx, dy);
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PNotification.java b/src/main/java/edu/umd/cs/piccolox/event/PNotification.java
deleted file mode 100755
index 3d437d8..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PNotification.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- *
- * This class PNotification center is derived from the class
- * NSNotification from:
- *
- * Wotonomy: OpenStep design patterns for pure Java
- * applications. Copyright (C) 2000 Blacksmith, Inc.
- */
-package edu.umd.cs.piccolox.event;
-
-import java.util.Map;
-
-/**
- * PNotification objects encapsulate information so that it can be
- * broadcast to other objects by a PNotificationCenter. A PNotification contains a
- * name, an object, and an optional properties map. The name is a tag
- * identifying the notification. The object is any object that the poster of the
- * notification wants to send to observers of that notification (typically, it
- * is the object that posted the notification). The properties map stores other
- * related objects, if any.
- *
- * You don't usually create your own notifications directly. The
- * PNotificationCenter method postNotification() allow you to conveniently post a
- * notification without creating it first.
- *
- * @author Jesse Grosjean
- */
-public class PNotification {
-
- protected String name;
- protected Object source;
- protected Map properties;
-
- public PNotification(String name, Object source, Map properties) {
- this.name = name;
- this.source = source;
- this.properties = properties;
- }
-
- /**
- * Return the name of the notification. This is the same as the name used to
- * register with the notfication center.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Return the object associated with this notification. This is most often
- * the same object that posted the notfication. It may be null.
- */
- public Object getObject() {
- return source;
- }
-
- /**
- * Return a property associated with the notfication.
- */
- public Object getProperty(Object key) {
- if (properties != null) {
- return properties.get(key);
- }
- return null;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java b/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
deleted file mode 100755
index 994dd7b..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- *
- * This class PNotificationCenter center is derived from the class
- * NSNotificationCenter from:
- *
- * Wotonomy: OpenStep design patterns for pure Java
- * applications. Copyright (C) 2000 Blacksmith, Inc.
- */
-package edu.umd.cs.piccolox.event;
-
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * PNotificationCenter provides a way for objects that don't know about
- * each other to communicate. It receives PNotification objects and broadcasts
- * them to all interested listeners. Unlike standard Java events, the event
- * listeners don't need to know about the event source, and the event source
- * doesn't need to maintain the list of listeners.
- *
- * Listeners of the notfications center are held by weak references. So the
- * notfication center will not create garbage collection problems as standard
- * java event listeners do.
- *
- * @author Jesse Grosjean
- */
-@SuppressWarnings("unchecked")
-public class PNotificationCenter {
-
- public static final Object NULL_MARKER = new Object();
-
- protected static PNotificationCenter DEFAULT_CENTER;
-
- protected HashMap listenersMap;
- protected ReferenceQueue keyQueue;
-
- public static PNotificationCenter defaultCenter() {
- if (DEFAULT_CENTER == null) {
- DEFAULT_CENTER = new PNotificationCenter();
- }
- return DEFAULT_CENTER;
- }
-
- private PNotificationCenter() {
- listenersMap = new HashMap();
- keyQueue = new ReferenceQueue();
- }
-
- //****************************************************************
- // Add Listener Methods
- //****************************************************************
-
- /**
- * Registers the 'listener' to receive notifications with the name
- * 'notificationName' and/or containing 'object'. When a matching
- * notification is posted the callBackMethodName message will be sent to the
- * listener with a single PNotification argument. If notificationName is null
- * then the listener will receive all notifications with an object matching
- * 'object'. If 'object' is null the listener will receive all notifications
- * with the name 'notificationName'.
- */
- public void addListener(Object listener, String callbackMethodName, String notificationName, Object object) {
- processKeyQueue();
-
- Object name = notificationName;
- Method method = null;
-
- try {
- method = listener.getClass().getMethod(callbackMethodName, new Class[] { PNotification.class });
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- return;
- }
-
- if (name == null) name = NULL_MARKER;
- if (object == null) object = NULL_MARKER;
-
- Object key = new CompoundKey(name, object);
- Object value = new CompoundValue(listener, method);
-
- List list = (List) listenersMap.get(key);
- if (list == null) {
- list = new ArrayList();
- listenersMap.put(new CompoundKey(name, object, keyQueue), list);
- }
-
- if (!list.contains(value)) {
- list.add(value);
- }
- }
-
- //****************************************************************
- // Remove Listener Methods
- //****************************************************************
-
- /**
- * Removes the listener so that it no longer recives notfications from this
- * notfication center.
- */
- public void removeListener(Object listener) {
- processKeyQueue();
-
- Iterator i = new LinkedList(listenersMap.keySet()).iterator();
- while (i.hasNext()) {
- removeListener(listener, i.next());
- }
- }
-
- /**
- * Removes the listeners as the listener of notifications matching
- * notificationName and object. If listener is null all listeners matching
- * notificationName and object are removed. If notificationName is null the
- * listener will be removed from all notifications containing the object. If
- * the object is null then the listener will be removed from all
- * notifications matching notficationName.
- */
- public void removeListener(Object listener, String notificationName, Object object) {
- processKeyQueue();
-
- List keys = matchingKeys(notificationName, object);
- Iterator it = keys.iterator();
- while (it.hasNext()) {
- removeListener(listener, it.next());
- }
- }
-
- //****************************************************************
- // Post PNotification Methods
- //****************************************************************
-
- /**
- * Post a new notfication with notificationName and object. The object is
- * typically the object posting the notification. The object may be null.
- */
- public void postNotification(String notificationName, Object object) {
- postNotification(notificationName, object, null);
- }
-
- /**
- * Creates a notification with the name notificationName, associates it with
- * the object, and posts it to this notification center. The object is
- * typically the object posting the notification. It may be nil.
- */
- public void postNotification(String notificationName, Object object, Map userInfo) {
- postNotification(new PNotification(notificationName, object, userInfo));
- }
-
- /**
- * Post the notification to this notification center. Most often clients will
- * instead use one of this classes convenience postNotifcations methods.
- */
- public void postNotification(PNotification aNotification) {
- List mergedListeners = new LinkedList();
- List listenersList;
-
- Object name = aNotification.getName();
- Object object = aNotification.getObject();
-
- if (name != null) {
- if (object != null) { // both are specified
- listenersList = (List) listenersMap.get(new CompoundKey(name, object));
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
- listenersList = (List) listenersMap.get(new CompoundKey(name, NULL_MARKER));
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
- listenersList = (List) listenersMap.get(new CompoundKey(NULL_MARKER, object));
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
- } else { // object is null
- listenersList = (List) listenersMap.get(new CompoundKey(name, NULL_MARKER));
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
- }
- } else if (object != null) { // name is null
- listenersList = (List) listenersMap.get(new CompoundKey(NULL_MARKER, object));
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
- }
-
- Object key = new CompoundKey(NULL_MARKER, NULL_MARKER);
- listenersList = (List) listenersMap.get(key);
- if (listenersList != null) {
- mergedListeners.addAll(listenersList);
- }
-
- CompoundValue value;
- Iterator it = mergedListeners.iterator();
-
- while (it.hasNext()) {
- value = (CompoundValue) it.next();
- if (value.get() == null) {
- it.remove();
- } else {
- try {
- value.getMethod().invoke(value.get(), new Object[] { aNotification });
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- //****************************************************************
- // Implementation classes and methods
- //****************************************************************
-
- protected List matchingKeys(String name, Object object) {
- List result = new LinkedList();
-
- Iterator it = listenersMap.keySet().iterator();
- while (it.hasNext()) {
- CompoundKey key = (CompoundKey) it.next();
- if ((name == null) || (name == key.name())) {
- if ((object == null) || (object == key.get())) {
- result.add(key);
- }
- }
- }
-
- return result;
- }
-
- protected void removeListener(Object listener, Object key) {
- if (listener == null) {
- listenersMap.remove(key);
- return;
- }
-
- List list = (List) listenersMap.get(key);
- if (list == null)
- return;
-
- Iterator it = list.iterator();
- while (it.hasNext()) {
- Object observer = ((CompoundValue) it.next()).get();
- if ((observer == null) || (listener == observer)) {
- it.remove();
- }
- }
-
- if (list.size() == 0) {
- listenersMap.remove(key);
- }
- }
-
- protected void processKeyQueue() {
- CompoundKey key;
- while ((key = (CompoundKey) keyQueue.poll()) != null) {
- listenersMap.remove(key);
- }
- }
-
- protected static class CompoundKey extends WeakReference {
-
- private Object name;
- private int hashCode;
-
- public CompoundKey(Object aName, Object anObject) {
- super(anObject);
- name = aName;
- hashCode = aName.hashCode() + anObject.hashCode();
- }
-
- public CompoundKey(Object aName, Object anObject, ReferenceQueue aQueue) {
- super(anObject, aQueue);
- name = aName;
- hashCode = aName.hashCode() + anObject.hashCode();
- }
-
- public Object name() {
- return name;
- }
-
- public int hashCode() {
- return hashCode;
- }
-
- public boolean equals(Object anObject) {
- if (this == anObject) return true;
- CompoundKey key = (CompoundKey) anObject;
- if (name == key.name || (name != null && name.equals(key.name))) {
- Object object = get();
- if (object != null) {
- if ( object == (key.get())) {
- return true;
- }
- }
- }
- return false;
- }
-
- public String toString() {
- return "[CompoundKey:" + name() + ":" + get() + "]";
- }
- }
-
- protected static class CompoundValue extends WeakReference {
-
- protected int hashCode;
- protected Method method;
-
- public CompoundValue(Object object, Method method) {
- super(object);
- hashCode = object.hashCode();
- this.method = method;
- }
-
- public Method getMethod() {
- return method;
- }
-
- public int hashCode() {
- return hashCode;
- }
-
- public boolean equals(Object object) {
- if (this == object) return true;
- CompoundValue value = (CompoundValue) object;
- if (method == value.method || (method != null && method.equals(value.method))) {
- Object o = get();
- if (o != null) {
- if (o == value.get()) {
- return true;
- }
- }
- }
- return false;
- }
-
- public String toString() {
- return "[CompoundValue:" + get() + ":" + getMethod().getName() + "]";
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java b/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
deleted file mode 100755
index 2ea304f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.event;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Paint;
-import java.awt.Stroke;
-import java.awt.event.KeyEvent;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PNodeFilter;
-import edu.umd.cs.piccolox.handles.PBoundsHandle;
-
-/**
- * PSelectionEventHandler
provides standard interaction for selection. Clicking
- * selects the object under the cursor. Shift-clicking allows multiple objects to be
- * selected. Dragging offers marquee selection. Pressing the delete key deletes
- * the selection by default.
- * @version 1.0
- * @author Ben Bederson
- */
-
-//@SuppressWarnings("unchecked")
-public class PSelectionEventHandler extends PDragSequenceEventHandler {
-
- public static final String SELECTION_CHANGED_NOTIFICATION = "SELECTION_CHANGED_NOTIFICATION";
-
- final static int DASH_WIDTH = 5;
- final static int NUM_STROKES = 10;
-
- private HashMap selection = null; // The current selection
- private List selectableParents = null; // List of nodes whose children can be selected
- private PPath marquee = null;
- private PNode marqueeParent = null; // Node that marquee is added to as a child
- private Point2D presspt = null;
- private Point2D canvasPressPt = null;
- private float strokeNum = 0;
- private Stroke[] strokes = null;
- private HashMap allItems = null; // Used within drag handler temporarily
- private ArrayList unselectList = null; // Used within drag handler temporarily
- private HashMap marqueeMap = null;
- private PNode pressNode = null; // Node pressed on (or null if none)
- private boolean deleteKeyActive = true; // True if DELETE key should delete selection
- private Paint marqueePaint;
- private float marqueePaintTransparency = 1.0f;
-
- /**
- * Creates a selection event handler.
- * @param marqueeParent The node to which the event handler dynamically adds a marquee
- * (temporarily) to represent the area being selected.
- * @param selectableParent The node whose children will be selected
- * by this event handler.
- */
- public PSelectionEventHandler(PNode marqueeParent, PNode selectableParent) {
- this.marqueeParent = marqueeParent;
- this.selectableParents = new ArrayList();
- this.selectableParents.add(selectableParent);
- init();
- }
-
- /**
- * Creates a selection event handler.
- * @param marqueeParent The node to which the event handler dynamically adds a marquee
- * (temporarily) to represent the area being selected.
- * @param selectableParents A list of nodes whose children will be selected
- * by this event handler.
- */
- public PSelectionEventHandler(PNode marqueeParent, List selectableParents) {
- this.marqueeParent = marqueeParent;
- this.selectableParents = selectableParents;
- init();
- }
-
- protected void init() {
- float[] dash = { DASH_WIDTH, DASH_WIDTH };
- strokes = new Stroke[NUM_STROKES];
- for (int i = 0; i < NUM_STROKES; i++) {
- strokes[i] = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, i);
- }
-
- selection = new HashMap();
- allItems = new HashMap();
- unselectList = new ArrayList();
- marqueeMap = new HashMap();
- }
-
- ///////////////////////////////////////////////////////
- // Public static methods for manipulating the selection
- ///////////////////////////////////////////////////////
-
- public void select(Collection items) {
- boolean changes = false;
- Iterator itemIt = items.iterator();
- while (itemIt.hasNext()) {
- PNode node = (PNode)itemIt.next();
- changes |= internalSelect(node);
- }
- if (changes) {
- postSelectionChanged();
- }
- }
-
- public void select(Map items) {
- select( items.keySet() );
- }
-
- private boolean internalSelect( PNode node ) {
- if (isSelected(node)) {
- return false;
- }
-
- selection.put(node, Boolean.TRUE);
- decorateSelectedNode(node);
- return true;
- }
-
- private void postSelectionChanged()
- {
- PNotificationCenter.defaultCenter().postNotification(SELECTION_CHANGED_NOTIFICATION, this);
- }
-
- public void select(PNode node) {
- if (internalSelect(node)) {
- postSelectionChanged();
- }
- }
-
- public void decorateSelectedNode(PNode node) {
- PBoundsHandle.addBoundsHandlesTo(node);
- }
-
- public void unselect(Collection items) {
- boolean changes = false;
- Iterator itemIt = items.iterator();
- while (itemIt.hasNext()) {
- PNode node = (PNode)itemIt.next();
- changes |= internalUnselect(node);
- }
- if (changes) {
- postSelectionChanged();
- }
- }
-
- private boolean internalUnselect( PNode node ) {
- if (!isSelected(node)) {
- return false;
- }
-
- undecorateSelectedNode(node);
- selection.remove(node);
- return true;
- }
-
- public void unselect(PNode node) {
- if( internalUnselect(node) ) {
- postSelectionChanged();
- }
- }
-
- public void undecorateSelectedNode(PNode node) {
- PBoundsHandle.removeBoundsHandlesFrom(node);
- }
-
- public void unselectAll() {
- // Because unselect() removes from selection, we need to
- // take a copy of it first so it isn't changed while we're iterating
- ArrayList sel = new ArrayList(selection.keySet());
- unselect( sel );
- }
-
- public boolean isSelected(PNode node) {
- if ((node != null) && (selection.containsKey(node))) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns a copy of the currently selected nodes.
- */
- public Collection getSelection() {
- ArrayList sel = new ArrayList(selection.keySet());
- return sel;
- }
-
- /**
- * Gets a reference to the currently selected nodes. You should not modify or store
- * this collection.
- */
- public Collection getSelectionReference()
- {
- return Collections.unmodifiableCollection( selection.keySet() );
- }
-
- /**
- * Determine if the specified node is selectable (i.e., if it is a child
- * of the one the list of selectable parents.
- */
- protected boolean isSelectable(PNode node) {
- boolean selectable = false;
-
- Iterator parentsIt = selectableParents.iterator();
- while (parentsIt.hasNext()) {
- PNode parent = (PNode)parentsIt.next();
- if (parent.getChildrenReference().contains(node)) {
- selectable = true;
- break;
- }
- else if (parent instanceof PCamera) {
- for(int i=0; i<((PCamera)parent).getLayerCount(); i++) {
- PLayer layer = ((PCamera)parent).getLayer(i);
- if (layer.getChildrenReference().contains(node)) {
- selectable = true;
- break;
- }
- }
- }
- }
-
- return selectable;
- }
-
- //////////////////////////////////////////////////////
- // Methods for modifying the set of selectable parents
- //////////////////////////////////////////////////////
-
- public void addSelectableParent(PNode node) {
- selectableParents.add(node);
- }
-
- public void removeSelectableParent(PNode node) {
- selectableParents.remove(node);
- }
-
- public void setSelectableParent(PNode node) {
- selectableParents.clear();
- selectableParents.add(node);
- }
-
- public void setSelectableParents(Collection c) {
- selectableParents.clear();
- selectableParents.addAll(c);
- }
-
- public Collection getSelectableParents() {
- return new ArrayList(selectableParents);
- }
-
- ////////////////////////////////////////////////////////
- // The overridden methods from PDragSequenceEventHandler
- ////////////////////////////////////////////////////////
-
- protected void startDrag(PInputEvent e) {
- super.startDrag(e);
-
- initializeSelection(e);
-
- if (isMarqueeSelection(e)) {
- initializeMarquee(e);
-
- if (!isOptionSelection(e)) {
- startMarqueeSelection(e);
- }
- else {
- startOptionMarqueeSelection(e);
- }
- }
- else {
- if (!isOptionSelection(e)) {
- startStandardSelection(e);
- } else {
- startStandardOptionSelection(e);
- }
- }
- }
-
- protected void drag(PInputEvent e) {
- super.drag(e);
-
- if (isMarqueeSelection(e)) {
- updateMarquee(e);
-
- if (!isOptionSelection(e)) {
- computeMarqueeSelection(e);
- }
- else {
- computeOptionMarqueeSelection(e);
- }
- } else {
- dragStandardSelection(e);
- }
- }
-
- protected void endDrag(PInputEvent e) {
- super.endDrag(e);
-
- if (isMarqueeSelection(e)) {
- endMarqueeSelection(e);
- }
- else {
- endStandardSelection(e);
- }
- }
-
- ////////////////////////////
- // Additional methods
- ////////////////////////////
-
- public boolean isOptionSelection(PInputEvent pie) {
- return pie.isShiftDown();
- }
-
- protected boolean isMarqueeSelection(PInputEvent pie) {
- return (pressNode == null);
- }
-
- protected void initializeSelection(PInputEvent pie) {
- canvasPressPt = pie.getCanvasPosition();
- presspt = pie.getPosition();
- pressNode = pie.getPath().getPickedNode();
- if (pressNode instanceof PCamera) {
- pressNode = null;
- }
- }
-
- protected void initializeMarquee(PInputEvent e) {
- marquee = PPath.createRectangle((float)presspt.getX(), (float)presspt.getY(), 0, 0);
- marquee.setPaint(marqueePaint);
- marquee.setTransparency(marqueePaintTransparency);
- marquee.setStrokePaint(Color.black);
- marquee.setStroke(strokes[0]);
- marqueeParent.addChild(marquee);
-
- marqueeMap.clear();
- }
-
- protected void startOptionMarqueeSelection(PInputEvent e) {
- }
-
- protected void startMarqueeSelection(PInputEvent e) {
- unselectAll();
- }
-
- protected void startStandardSelection(PInputEvent pie) {
- // Option indicator not down - clear selection, and start fresh
- if (!isSelected(pressNode)) {
- unselectAll();
-
- if (isSelectable(pressNode)) {
- select(pressNode);
- }
- }
- }
-
- protected void startStandardOptionSelection(PInputEvent pie) {
- // Option indicator is down, toggle selection
- if (isSelectable(pressNode)) {
- if (isSelected(pressNode)) {
- unselect(pressNode);
- } else {
- select(pressNode);
- }
- }
- }
-
- protected void updateMarquee(PInputEvent pie) {
- PBounds b = new PBounds();
-
- if (marqueeParent instanceof PCamera) {
- b.add(canvasPressPt);
- b.add(pie.getCanvasPosition());
- }
- else {
- b.add(presspt);
- b.add(pie.getPosition());
- }
-
- marquee.globalToLocal(b);
- marquee.setPathToRectangle((float) b.x, (float) b.y, (float) b.width, (float) b.height);
- b.reset();
- b.add(presspt);
- b.add(pie.getPosition());
-
- allItems.clear();
- PNodeFilter filter = createNodeFilter(b);
- Iterator parentsIt = selectableParents.iterator();
- while (parentsIt.hasNext()) {
- PNode parent = (PNode) parentsIt.next();
-
- Collection items;
- if (parent instanceof PCamera) {
- items = new ArrayList();
- for(int i=0; i<((PCamera)parent).getLayerCount(); i++) {
- ((PCamera)parent).getLayer(i).getAllNodes(filter,items);
- }
- }
- else {
- items = parent.getAllNodes(filter, null);
- }
-
- Iterator itemsIt = items.iterator();
- while (itemsIt.hasNext()) {
- allItems.put(itemsIt.next(), Boolean.TRUE);
- }
- }
- }
-
- protected void computeMarqueeSelection(PInputEvent pie) {
- unselectList.clear();
- // Make just the items in the list selected
- // Do this efficiently by first unselecting things not in the list
- Iterator selectionEn = selection.keySet().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
- if (!allItems.containsKey(node)) {
- unselectList.add(node);
- }
- }
- unselect(unselectList);
-
- // Then select the rest
- selectionEn = allItems.keySet().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
- if (!selection.containsKey(node) && !marqueeMap.containsKey(node) && isSelectable(node)) {
- marqueeMap.put(node,Boolean.TRUE);
- }
- else if (!isSelectable(node)) {
- selectionEn.remove();
- }
- }
-
- select(allItems);
- }
-
- protected void computeOptionMarqueeSelection(PInputEvent pie) {
- unselectList.clear();
- Iterator selectionEn = selection.keySet().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
- if (!allItems.containsKey(node) && marqueeMap.containsKey(node)) {
- marqueeMap.remove(node);
- unselectList.add(node);
- }
- }
- unselect(unselectList);
-
-
- // Then select the rest
- selectionEn = allItems.keySet().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
- if (!selection.containsKey(node) && !marqueeMap.containsKey(node) && isSelectable(node)) {
- marqueeMap.put(node,Boolean.TRUE);
- }
- else if (!isSelectable(node)) {
- selectionEn.remove();
- }
- }
-
- select(allItems);
- }
-
- protected PNodeFilter createNodeFilter(PBounds bounds) {
- return new BoundsFilter(bounds);
- }
-
- protected PBounds getMarqueeBounds() {
- if (marquee != null) {
- return marquee.getBounds();
- }
- return new PBounds();
- }
-
- protected void dragStandardSelection(PInputEvent e) {
- // There was a press node, so drag selection
- PDimension d = e.getCanvasDelta();
- e.getTopCamera().localToView(d);
-
- PDimension gDist = new PDimension();
- Iterator selectionEn = getSelection().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
-
- gDist.setSize(d);
- node.getParent().globalToLocal(gDist);
- node.offset(gDist.getWidth(), gDist.getHeight());
- }
- }
-
- protected void endMarqueeSelection(PInputEvent e) {
- // Remove marquee
- allItems.clear();
- marqueeMap.clear();
- marquee.removeFromParent();
- marquee = null;
- }
-
- protected void endStandardSelection(PInputEvent e) {
- pressNode = null;
- }
-
- /**
- * This gets called continuously during the drag, and is used to animate the marquee
- */
- protected void dragActivityStep(PInputEvent aEvent) {
- if (marquee != null) {
- float origStrokeNum = strokeNum;
- strokeNum = (strokeNum + 0.5f) % NUM_STROKES; // Increment by partial steps to slow down animation
- if ((int)strokeNum != (int)origStrokeNum) {
- marquee.setStroke(strokes[(int)strokeNum]);
- }
- }
- }
-
- /**
- * Delete selection when delete key is pressed (if enabled)
- */
- public void keyPressed(PInputEvent e) {
- switch (e.getKeyCode()) {
- case KeyEvent.VK_DELETE:
- if (deleteKeyActive) {
- Iterator selectionEn = selection.keySet().iterator();
- while (selectionEn.hasNext()) {
- PNode node = (PNode) selectionEn.next();
- node.removeFromParent();
- }
- selection.clear();
- }
- }
- }
-
- public boolean getSupportDeleteKey() {
- return deleteKeyActive;
- }
-
- public boolean isDeleteKeyActive() {
- return deleteKeyActive;
- }
-
- /**
- * Specifies if the DELETE key should delete the selection
- */
- public void setDeleteKeyActive(boolean deleteKeyActive) {
- this.deleteKeyActive = deleteKeyActive;
- }
-
- //////////////////////
- // Inner classes
- //////////////////////
-
- protected class BoundsFilter implements PNodeFilter {
- PBounds localBounds = new PBounds();
- PBounds bounds;
-
- protected BoundsFilter(PBounds bounds) {
- this.bounds = bounds;
- }
-
- public boolean accept(PNode node) {
- localBounds.setRect(bounds);
- node.globalToLocal(localBounds);
-
- boolean boundsIntersects = node.intersects(localBounds);
- boolean isMarquee = (node == marquee);
- return (node.getPickable() && boundsIntersects && !isMarquee && !selectableParents.contains(node) && !isCameraLayer(node));
- }
-
- public boolean acceptChildrenOf(PNode node) {
- return selectableParents.contains(node) || isCameraLayer(node);
- }
-
- public boolean isCameraLayer(PNode node) {
- if (node instanceof PLayer) {
- for(Iterator i=selectableParents.iterator(); i.hasNext();) {
- PNode parent = (PNode)i.next();
- if (parent instanceof PCamera) {
- if (((PCamera)parent).indexOfLayer((PLayer)node) != -1) {
- return true;
- }
- }
- }
- }
- return false;
- }
- }
-
- /**
- * Indicates the color used to paint the marquee.
- * @return the paint for interior of the marquee
- */
- public Paint getMarqueePaint() {
- return marqueePaint;
- }
-
- /**
- * Sets the color used to paint the marquee.
- * @param paint the paint color
- */
- public void setMarqueePaint(Paint paint) {
- this.marqueePaint = paint;
- }
-
- /**
- * Indicates the transparency level for the interior of the marquee.
- * @return Returns the marquee paint transparency, zero to one
- */
- public float getMarqueePaintTransparency() {
- return marqueePaintTransparency;
- }
-
- /**
- * Sets the transparency level for the interior of the marquee.
- * @param marqueePaintTransparency The marquee paint transparency to set.
- */
- public void setMarqueePaintTransparency(float marqueePaintTransparency) {
- this.marqueePaintTransparency = marqueePaintTransparency;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java b/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
deleted file mode 100755
index 988f3e9..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
- package edu.umd.cs.piccolox.event;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Insets;
-import java.awt.RenderingHints;
-import java.awt.event.InputEvent;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-
-import javax.swing.JTextPane;
-import javax.swing.SwingUtilities;
-import javax.swing.border.CompoundBorder;
-import javax.swing.border.EmptyBorder;
-import javax.swing.border.LineBorder;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-import javax.swing.text.Document;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.SimpleAttributeSet;
-import javax.swing.text.StyleConstants;
-import javax.swing.text.StyledDocument;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolox.nodes.PStyledText;
-
-/**
- * @author Lance Good
- */
-public class PStyledTextEventHandler extends PBasicInputEventHandler {
-
- protected PCanvas canvas;
-
- protected JTextComponent editor;
-
- protected DocumentListener docListener;
-
- protected PStyledText editedText;
-
- /**
- * Basic constructor for PStyledTextEventHandler
- */
- public PStyledTextEventHandler(PCanvas canvas) {
- super();
-
- this.canvas = canvas;
- initEditor(createDefaultEditor());
- }
-
- /**
- * Constructor for PStyledTextEventHandler that allows an editor to be specified
- */
- public PStyledTextEventHandler(PCanvas canvas, JTextComponent editor) {
- super();
-
- this.canvas = canvas;
- initEditor(editor);
- }
-
- protected void initEditor(JTextComponent newEditor) {
- editor = newEditor;
-
- canvas.setLayout(null);
- canvas.add(editor);
- editor.setVisible(false);
-
- docListener = createDocumentListener();
- }
-
- protected JTextComponent createDefaultEditor() {
- JTextPane tComp = new JTextPane() {
-
- /**
- *
- */
- private static final long serialVersionUID = 3313849526807646999L;
-
- /**
- * Set some rendering hints - if we don't then the rendering can be inconsistent. Also,
- * Swing doesn't work correctly with fractional metrics.
- */
- public void paint(Graphics g) {
- Graphics2D g2 = (Graphics2D)g;
-
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
-
- super.paint(g);
- }
- };
- tComp.setBorder(new CompoundBorder(new LineBorder(Color.black),new EmptyBorder(3,3,3,3)));
- return tComp;
- }
-
- protected DocumentListener createDocumentListener() {
- return new DocumentListener() {
- public void removeUpdate(DocumentEvent e) {
- reshapeEditorLater();
- }
-
- public void insertUpdate(DocumentEvent e) {
- reshapeEditorLater();
- }
-
- public void changedUpdate(DocumentEvent e) {
- reshapeEditorLater();
- }
- };
- }
-
- public PStyledText createText() {
- PStyledText newText = new PStyledText();
-
- Document doc = editor.getUI().getEditorKit(editor).createDefaultDocument();
- if (doc instanceof StyledDocument) {
- if (!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontFamily)
- || !doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontSize)) {
-
- Font eFont = editor.getFont();
- SimpleAttributeSet sas = new SimpleAttributeSet();
- sas.addAttribute(StyleConstants.FontFamily, eFont.getFamily());
- sas.addAttribute(StyleConstants.FontSize, new Integer(eFont.getSize()));
-
- ((StyledDocument) doc).setParagraphAttributes(0, doc.getLength(), sas, false);
- }
- }
- newText.setDocument(doc);
-
- return newText;
- }
-
- public void mousePressed(PInputEvent inputEvent) {
- PNode pickedNode = inputEvent.getPickedNode();
-
- stopEditing();
-
- if (pickedNode instanceof PStyledText) {
- startEditing(inputEvent,(PStyledText)pickedNode);
- }
- else if (pickedNode instanceof PCamera) {
- PStyledText newText = createText();
- Insets pInsets = newText.getInsets();
- canvas.getLayer().addChild(newText);
- newText.translate(inputEvent.getPosition().getX()-pInsets.left,inputEvent.getPosition().getY()-pInsets.top);
- startEditing(inputEvent, newText);
- }
- }
-
- public void startEditing(PInputEvent event, PStyledText text) {
- // Get the node's top right hand corner
- Insets pInsets = text.getInsets();
- Point2D nodePt = new Point2D.Double(text.getX()+pInsets.left,text.getY()+pInsets.top);
- text.localToGlobal(nodePt);
- event.getTopCamera().viewToLocal(nodePt);
-
- // Update the editor to edit the specified node
- editor.setDocument(text.getDocument());
- editor.setVisible(true);
-
- Insets bInsets = editor.getBorder().getBorderInsets(editor);
- editor.setLocation((int)nodePt.getX()-bInsets.left,(int)nodePt.getY()-bInsets.top);
- reshapeEditorLater();
-
- dispatchEventToEditor(event);
- canvas.repaint();
-
- text.setEditing(true);
- text.getDocument().addDocumentListener(docListener);
- editedText = text;
- }
-
- public void stopEditing() {
- if (editedText != null) {
- editedText.getDocument().removeDocumentListener(docListener);
- editedText.setEditing(false);
-
- if (editedText.getDocument().getLength() == 0) {
- editedText.removeFromParent();
- }
- else {
- editedText.syncWithDocument();
- }
-
- editor.setVisible(false);
- canvas.repaint();
-
- editedText = null;
- }
- }
-
- public void dispatchEventToEditor(final PInputEvent e) {
- // We have to nest the mouse press in two invoke laters so that it is
- // fired so that the component has been completely validated at the new size
- // and the mouse event has the correct offset
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- MouseEvent me =
- new MouseEvent(
- editor,
- MouseEvent.MOUSE_PRESSED,
- e.getWhen(),
- e.getModifiers() | InputEvent.BUTTON1_MASK,
- (int) (e.getCanvasPosition().getX() - editor.getX()),
- (int) (e.getCanvasPosition().getY() - editor.getY()),
- 1,
- false);
- editor.dispatchEvent(me);
- }
- });
- }
- });
- }
-
-
- public void reshapeEditor() {
- if (editedText != null) {
- // Update the size to fit the new document - note that it is a 2 stage process
- Dimension prefSize = editor.getPreferredSize();
-
- Insets pInsets = editedText.getInsets();
- Insets jInsets = editor.getInsets();
-
- int width = (editedText.getConstrainWidthToTextWidth()) ? (int)prefSize.getWidth() : (int)(editedText.getWidth()-pInsets.left-pInsets.right+jInsets.left+jInsets.right+3.0);
- prefSize.setSize(width,prefSize.getHeight());
- editor.setSize(prefSize);
-
- prefSize = editor.getPreferredSize();
- int height = (editedText.getConstrainHeightToTextHeight()) ? (int)prefSize.getHeight() : (int)(editedText.getHeight()-pInsets.top-pInsets.bottom+jInsets.top+jInsets.bottom+3.0);
- prefSize.setSize(width,height);
- editor.setSize(prefSize);
- }
- }
-
- /**
- * Sometimes we need to invoke this later because the document events seem to get fired
- * before the text is actually incorporated into the document
- */
- protected void reshapeEditorLater() {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- reshapeEditor();
- }
- });
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/event/PZoomToEventHandler.java b/src/main/java/edu/umd/cs/piccolox/event/PZoomToEventHandler.java
deleted file mode 100755
index 9a07a14..0000000
--- a/src/main/java/edu/umd/cs/piccolox/event/PZoomToEventHandler.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.event;
-
-import java.awt.event.InputEvent;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * PZoomToEventHandler is used to zoom the camera view to the node
- * clicked on with button one.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PZoomToEventHandler extends PBasicInputEventHandler {
-
- public PZoomToEventHandler() {
- setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- }
-
- public void mousePressed(PInputEvent aEvent) {
- zoomTo(aEvent);
- }
-
- protected void zoomTo(final PInputEvent aEvent) {
- PBounds zoomToBounds;
- PNode picked = aEvent.getPickedNode();
-
- if (picked instanceof PCamera) {
- PCamera c = (PCamera) picked;
- zoomToBounds = c.getUnionOfLayerFullBounds();
- } else {
- zoomToBounds = picked.getGlobalFullBounds();
- }
-
- aEvent.getCamera().animateViewToCenterBounds(zoomToBounds, true, 500);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java b/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java
deleted file mode 100755
index 9c8b945..0000000
--- a/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.handles;
-
-import java.awt.Cursor;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import javax.swing.SwingConstants;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPickPath;
-import edu.umd.cs.piccolox.util.PBoundsLocator;
-
-/**
- * PBoundsHandle a handle for resizing the bounds of another node. If a
- * bounds handle is dragged such that the other node's width or height becomes
- * negative then the each drag handle's locator assciated with that
- * other node is "flipped" so that they are attached to and dragging a different
- * corner of the nodes bounds.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PBoundsHandle extends PHandle {
-
- /**
- *
- */
- private static final long serialVersionUID = -2382456447746838274L;
- private transient PBasicInputEventHandler handleCursorHandler;
-
- public static void addBoundsHandlesTo(PNode aNode) {
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createEastLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createWestLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createNorthLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createSouthLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(aNode)));
- aNode.addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(aNode)));
- }
-
- public static void addStickyBoundsHandlesTo(PNode aNode, PCamera camera) {
- camera.addChild(new PBoundsHandle(PBoundsLocator.createEastLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createWestLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createNorthLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createSouthLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(aNode)));
- camera.addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(aNode)));
- }
-
- public static void removeBoundsHandlesFrom(PNode aNode) {
- ArrayList handles = new ArrayList();
-
- Iterator i = aNode.getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (each instanceof PBoundsHandle) {
- handles.add(each);
- }
- }
- aNode.removeChildren(handles);
- }
-
- public PBoundsHandle(PBoundsLocator aLocator) {
- super(aLocator);
- }
-
- protected void installHandleEventHandlers() {
- super.installHandleEventHandlers();
- handleCursorHandler = new PBasicInputEventHandler() {
- boolean cursorPushed = false;
- public void mouseEntered(PInputEvent aEvent) {
- if (!cursorPushed) {
- aEvent.pushCursor(getCursorFor(((PBoundsLocator)getLocator()).getSide()));
- cursorPushed = true;
- }
- }
- public void mouseExited(PInputEvent aEvent) {
- PPickPath focus = aEvent.getInputManager().getMouseFocus();
- if (cursorPushed) {
- if (focus == null || focus.getPickedNode() != PBoundsHandle.this) {
- aEvent.popCursor();
- cursorPushed = false;
- }
- }
- }
- public void mouseReleased(PInputEvent event) {
- if (cursorPushed) {
- event.popCursor();
- cursorPushed = false;
- }
- }
- };
- addInputEventListener(handleCursorHandler);
- }
-
- /**
- * Return the event handler that is responsible for setting the mouse
- * cursor when it enters/exits this handle.
- */
- public PBasicInputEventHandler getHandleCursorEventHandler() {
- return handleCursorHandler;
- }
-
- public void startHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
- l.getNode().startResizeBounds();
- }
-
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
-
- PNode n = l.getNode();
- PBounds b = n.getBounds();
-
- PNode parent = getParent();
- if (parent != n && parent instanceof PCamera) {
- ((PCamera)parent).localToView(aLocalDimension);
- }
-
- localToGlobal(aLocalDimension);
- n.globalToLocal(aLocalDimension);
-
- double dx = aLocalDimension.getWidth();
- double dy = aLocalDimension.getHeight();
-
- switch (l.getSide()) {
- case SwingConstants.NORTH:
- b.setRect(b.x, b.y + dy, b.width, b.height - dy);
- break;
-
- case SwingConstants.SOUTH:
- b.setRect(b.x, b.y, b.width, b.height + dy);
- break;
-
- case SwingConstants.EAST:
- b.setRect(b.x, b.y, b.width + dx, b.height);
- break;
-
- case SwingConstants.WEST:
- b.setRect(b.x + dx, b.y, b.width - dx, b.height);
- break;
-
- case SwingConstants.NORTH_WEST:
- b.setRect(b.x + dx, b.y + dy, b.width - dx, b.height - dy);
- break;
-
- case SwingConstants.SOUTH_WEST:
- b.setRect(b.x + dx, b.y, b.width - dx, b.height + dy);
- break;
-
- case SwingConstants.NORTH_EAST:
- b.setRect(b.x, b.y + dy, b.width + dx, b.height - dy);
- break;
-
- case SwingConstants.SOUTH_EAST:
- b.setRect(b.x, b.y, b.width + dx, b.height + dy);
- break;
- }
-
- boolean flipX = false;
- boolean flipY = false;
-
- if (b.width < 0) {
- flipX = true;
- b.width = -b.width;
- b.x -= b.width;
- }
-
- if (b.height < 0) {
- flipY = true;
- b.height = -b.height;
- b.y -= b.height;
- }
-
- if (flipX || flipY) {
- flipSiblingBoundsHandles(flipX, flipY);
- }
-
- n.setBounds(b);
- }
-
- public void endHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
- l.getNode().endResizeBounds();
- }
-
- public void flipSiblingBoundsHandles(boolean flipX, boolean flipY) {
- Iterator i = getParent().getChildrenIterator();
- while (i.hasNext()) {
- Object each = i.next();
- if (each instanceof PBoundsHandle) {
- ((PBoundsHandle)each).flipHandleIfNeeded(flipX, flipY);
- }
- }
- }
-
- public void flipHandleIfNeeded(boolean flipX, boolean flipY) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
-
- if (flipX || flipY) {
- switch (l.getSide()) {
- case SwingConstants.NORTH: {
- if (flipY) {
- l.setSide(SwingConstants.SOUTH);
- }
- break;
- }
-
- case SwingConstants.SOUTH: {
- if (flipY) {
- l.setSide(SwingConstants.NORTH);
- }
- break;
- }
-
- case SwingConstants.EAST: {
- if (flipX) {
- l.setSide(SwingConstants.WEST);
- }
- break;
- }
-
- case SwingConstants.WEST: {
- if (flipX) {
- l.setSide(SwingConstants.EAST);
- }
- break;
- }
-
- case SwingConstants.NORTH_WEST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.SOUTH_EAST);
- } else if (flipX) {
- l.setSide(SwingConstants.NORTH_EAST);
- } else if (flipY) {
- l.setSide(SwingConstants.SOUTH_WEST);
- }
-
- break;
- }
-
- case SwingConstants.SOUTH_WEST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.NORTH_EAST);
- } else if (flipX) {
- l.setSide(SwingConstants.SOUTH_EAST);
- } else if (flipY) {
- l.setSide(SwingConstants.NORTH_WEST);
- }
- break;
- }
-
- case SwingConstants.NORTH_EAST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.SOUTH_WEST);
- } else if (flipX) {
- l.setSide(SwingConstants.NORTH_WEST);
- } else if (flipY) {
- l.setSide(SwingConstants.SOUTH_EAST);
- }
- break;
- }
-
- case SwingConstants.SOUTH_EAST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.NORTH_WEST);
- } else if (flipX) {
- l.setSide(SwingConstants.SOUTH_WEST);
- } else if (flipY) {
- l.setSide(SwingConstants.NORTH_EAST);
- }
- break;
- }
- }
- }
-
- // reset locator to update layout
- setLocator(l);
- }
-
- public Cursor getCursorFor(int side) {
- switch (side) {
- case SwingConstants.NORTH:
- return new Cursor(Cursor.N_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH:
- return new Cursor(Cursor.S_RESIZE_CURSOR);
-
- case SwingConstants.EAST:
- return new Cursor(Cursor.E_RESIZE_CURSOR);
-
- case SwingConstants.WEST:
- return new Cursor(Cursor.W_RESIZE_CURSOR);
-
- case SwingConstants.NORTH_WEST:
- return new Cursor(Cursor.NW_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH_WEST:
- return new Cursor(Cursor.SW_RESIZE_CURSOR);
-
- case SwingConstants.NORTH_EAST:
- return new Cursor(Cursor.NE_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH_EAST:
- return new Cursor(Cursor.SE_RESIZE_CURSOR);
- }
- return null;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/handles/PHandle.java b/src/main/java/edu/umd/cs/piccolox/handles/PHandle.java
deleted file mode 100755
index d842ba9..0000000
--- a/src/main/java/edu/umd/cs/piccolox/handles/PHandle.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.handles;
-
-import java.awt.Color;
-import java.awt.Shape;
-import java.awt.event.InputEvent;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Point2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolox.util.PLocator;
-import edu.umd.cs.piccolox.util.PNodeLocator;
-
-/**
- * PHandle is used to modify some aspect of Piccolo when it
- * is dragged. Each handle has a PLocator that it uses to automatically position
- * itself. See PBoundsHandle for an example of a handle that resizes the bounds
- * of another node.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PHandle extends PPath {
-
- /**
- *
- */
- private static final long serialVersionUID = -2878500552013676075L;
- public static float DEFAULT_HANDLE_SIZE = 8;
- public static Shape DEFAULT_HANDLE_SHAPE = new Ellipse2D.Float(0f, 0f, DEFAULT_HANDLE_SIZE, DEFAULT_HANDLE_SIZE);
- public static Color DEFAULT_COLOR = Color.white;
-
- private PLocator locator;
- private transient PDragSequenceEventHandler handleDragger;
-
- /**
- * Construct a new handle that will use the given locator
- * to locate itself on its parent node.
- */
- public PHandle(PLocator aLocator) {
- super(DEFAULT_HANDLE_SHAPE);
- locator = aLocator;
- setPaint(DEFAULT_COLOR);
- installHandleEventHandlers();
- }
-
- protected void installHandleEventHandlers() {
- handleDragger = new PDragSequenceEventHandler() {
- protected void startDrag(PInputEvent event) {
- super.startDrag(event);
- startHandleDrag(event.getPositionRelativeTo(PHandle.this), event);
- }
- protected void drag(PInputEvent event) {
- super.drag(event);
- PDimension aDelta = event.getDeltaRelativeTo(PHandle.this);
- if (aDelta.getWidth() != 0 || aDelta.getHeight() != 0) {
- dragHandle(aDelta, event);
- }
- }
- protected void endDrag(PInputEvent event) {
- super.endDrag(event);
- endHandleDrag(event.getPositionRelativeTo(PHandle.this), event);
- }
- };
-
- addPropertyChangeListener(PNode.PROPERTY_TRANSFORM, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- relocateHandle();
- }
- });
-
- handleDragger.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- handleDragger.getEventFilter().setMarksAcceptedEventsAsHandled(true);
- handleDragger.getEventFilter().setAcceptsMouseEntered(false);
- handleDragger.getEventFilter().setAcceptsMouseExited(false);
- handleDragger.getEventFilter().setAcceptsMouseMoved(false); // no need for moved events for handle interaction,
- // so reject them so we don't consume them
- addInputEventListener(handleDragger);
- }
-
- /**
- * Return the event handler that is responsible for the drag handle
- * interaction.
- */
- public PDragSequenceEventHandler getHandleDraggerHandler() {
- return handleDragger;
- }
-
- /**
- * Get the locator that this handle uses to position itself on its
- * parent node.
- */
- public PLocator getLocator() {
- return locator;
- }
-
- /**
- * Set the locator that this handle uses to position itself on its
- * parent node.
- */
- public void setLocator(PLocator aLocator) {
- locator = aLocator;
- invalidatePaint();
- relocateHandle();
- }
-
- //****************************************************************
- // Handle Dragging - These are the methods the subclasses should
- // normally override to give a handle unique behavior.
- //****************************************************************
-
- /**
- * Override this method to get notified when the handle starts to get dragged.
- */
- public void startHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- }
-
- /**
- * Override this method to get notified as the handle is dragged.
- */
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- }
-
- /**
- * Override this method to get notified when the handle stops getting dragged.
- */
- public void endHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- }
-
- //****************************************************************
- // Layout - When a handle's parent's layout changes the handle
- // invalidates its own layout and then repositions itself on its
- // parents bounds using its locator to determine that new
- // position.
- //****************************************************************
-
- public void setParent(PNode newParent) {
- super.setParent(newParent);
- relocateHandle();
- }
-
- public void parentBoundsChanged() {
- relocateHandle();
- }
-
- /**
- * Force this handle to relocate itself using its locator.
- */
- public void relocateHandle() {
- if (locator != null) {
- PBounds b = getBoundsReference();
- Point2D aPoint = locator.locatePoint(null);
-
- if (locator instanceof PNodeLocator) {
- PNode located = ((PNodeLocator)locator).getNode();
- PNode parent = getParent();
-
- located.localToGlobal(aPoint);
- globalToLocal(aPoint);
-
- if (parent != located && parent instanceof PCamera) {
- ((PCamera)parent).viewToLocal(aPoint);
- }
- }
-
- double newCenterX = aPoint.getX();
- double newCenterY = aPoint.getY();
-
- if (newCenterX != b.getCenterX() ||
- newCenterY != b.getCenterY()) {
-
- centerBoundsOnPoint(newCenterX, newCenterY);
- }
- }
- }
-
- //****************************************************************
- // Serialization
- //****************************************************************
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- installHandleEventHandlers();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/handles/PStickyHandleManager.java b/src/main/java/edu/umd/cs/piccolox/handles/PStickyHandleManager.java
deleted file mode 100755
index 58a3d59..0000000
--- a/src/main/java/edu/umd/cs/piccolox/handles/PStickyHandleManager.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.handles;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-public class PStickyHandleManager extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -8318684481678765927L;
- private PNode target;
- private PCamera camera;
-
- public PStickyHandleManager(PCamera newCamera, PNode newTarget) {
- setCameraTarget(newCamera, newTarget);
- PBoundsHandle.addBoundsHandlesTo(this);
- }
-
- public void setCameraTarget(PCamera newCamera, PNode newTarget) {
- camera = newCamera;
- camera.addChild(this);
- target = newTarget;
- }
-
- public boolean setBounds(double x, double y, double width, double height) {
- PBounds b = new PBounds(x, y, width, height);
- camera.localToGlobal(b);
- camera.localToView(b);
- target.globalToLocal(b);
- target.setBounds(b);
- return super.setBounds(x, y, width, height);
- }
-
- protected boolean getBoundsVolatile() {
- return true;
- }
-
- public PBounds getBoundsReference() {
- PBounds targetBounds = target.getFullBounds();
- camera.viewToLocal(targetBounds);
- camera.globalToLocal(targetBounds);
- PBounds bounds = super.getBoundsReference();
- bounds.setRect(targetBounds);
- return super.getBoundsReference();
- }
-
- public void startResizeBounds() {
- super.startResizeBounds();
- target.startResizeBounds();
- }
-
- public void endResizeBounds() {
- super.endResizeBounds();
- target.endResizeBounds();
- }
-
- public boolean pickAfterChildren(PPickPath pickPath) {
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java b/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java
deleted file mode 100755
index 81fb850..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.*;
-import java.awt.geom.*;
-import edu.umd.cs.piccolo.*;
-import edu.umd.cs.piccolo.util.*;
-import edu.umd.cs.piccolox.*;
-
-/**
- * This is a simple node that draws a "3D" rectangle within the bounds of the node.
- * Drawing a 3D rectangle in a zooming environment is a little tricky because
- * if you just use the regular (Java2D) 3D rectangle, the 3D borders get scaled,
- * and that is ugly. This version always draws the 3D border at fixed 2 pixel width.
- *
- * @author Ben Bederson
- */
-public class P3DRect extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -7574230646662130862L;
- private Color topLeftOuterColor;
- private Color topLeftInnerColor;
- private Color bottomRightInnerColor;
- private Color bottomRightOuterColor;
- private GeneralPath path;
- private Stroke stroke;
- private boolean raised;
-
- public P3DRect() {
- raised = true;
- stroke = new BasicStroke(0);
- path = new GeneralPath();
- }
-
- public P3DRect(Rectangle2D bounds) {
- this(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight());
- }
-
- public P3DRect(double x, double y, double width, double height) {
- this();
- setBounds(x, y, width, height);
- }
-
- public void setRaised(boolean raised) {
- this.raised = raised;
- setPaint(getPaint());
- }
-
- public boolean getRaised() {
- return raised;
- }
-
- protected void paint(PPaintContext paintContext) {
- Graphics2D g2 = paintContext.getGraphics();
-
- double x = getX();
- double y = getY();
- double width = getWidth();
- double height = getHeight();
- double magX = g2.getTransform().getScaleX();
- double magY = g2.getTransform().getScaleY();
- double dx = (float)(1.0 / magX);
- double dy = (float)(1.0 / magY);
- PBounds bounds = getBounds();
-
- g2.setPaint(getPaint());
- g2.fill(bounds);
- g2.setStroke(stroke);
-
- path.reset();
- path.moveTo((float)(x+width), (float)y);
- path.lineTo((float)x, (float)y);
- path.lineTo((float)x, (float)(y+height));
- g2.setPaint(topLeftOuterColor);
- g2.draw(path);
-
- path.reset();
- path.moveTo((float)(x+width), (float)(y+dy));
- path.lineTo((float)(x+dx), (float)(y+dy));
- path.lineTo((float)(x+dx), (float)(y+height));
- g2.setPaint(topLeftInnerColor);
- g2.draw(path);
-
- path.reset();
- path.moveTo((float)(x+width), (float)(y));
- path.lineTo((float)(x+width), (float)(y+height));
- path.lineTo((float)(x), (float)(y+height));
- g2.setPaint(bottomRightOuterColor);
- g2.draw(path);
-
- path.reset();
- path.moveTo((float)(x+width-dx), (float)(y+dy));
- path.lineTo((float)(x+width-dx), (float)(y+height-dy));
- path.lineTo((float)(x), (float)(y+height-dy));
- g2.setPaint(bottomRightInnerColor);
- g2.draw(path);
- }
-
- public void setPaint(Paint newPaint) {
- super.setPaint(newPaint);
-
- if (newPaint instanceof Color) {
- Color color = (Color)newPaint;
-
- if (raised) {
- topLeftOuterColor = color.brighter();
- topLeftInnerColor = topLeftOuterColor.brighter();
- bottomRightInnerColor = color.darker();
- bottomRightOuterColor = bottomRightInnerColor.darker();
- } else {
- topLeftOuterColor = color.darker();
- topLeftInnerColor = topLeftOuterColor.darker();
- bottomRightInnerColor = color.brighter();
- bottomRightOuterColor = bottomRightInnerColor.brighter();
- }
- } else {
- topLeftOuterColor = null;
- topLeftInnerColor = null;
- bottomRightInnerColor = null;
- bottomRightOuterColor = null;
- }
- }
-
- public static void main(String[] args) {
- new PFrame() {
- /**
- *
- */
- private static final long serialVersionUID = -7439065550171542462L;
-
- public void initialize() {
- getCanvas().setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
-
- P3DRect rect1 = new P3DRect(50, 50, 100, 100);
- rect1.setPaint(new Color(239, 235, 222));
-
- P3DRect rect2 = new P3DRect(50, 50, 100, 100);
- rect2.setPaint(new Color(239, 235, 222));
- rect2.translate(110, 0);
- rect2.setRaised(false);
-
- getCanvas().getLayer().addChild(rect1);
- getCanvas().getLayer().addChild(rect2);
- }
- };
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java b/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java
deleted file mode 100755
index 5880435..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Created on Mar 4, 2005
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.Color;
-import java.awt.GraphicsEnvironment;
-import java.awt.Paint;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.activities.PTransformActivity;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PUtil;
-
-/**
- * An extension to PCamera that provides a fast image based animationToCenterBounds method
- *
- * @author Lance Good
- */
-public class PCacheCamera extends PCamera {
-
- /**
- *
- */
- private static final long serialVersionUID = 5646895869430890836L;
- private BufferedImage paintBuffer;
- private boolean imageAnimate;
- private PBounds imageAnimateBounds;
-
- /**
- * Get the buffer used to provide fast image based animation
- */
- protected BufferedImage getPaintBuffer() {
- PBounds fRef = getFullBoundsReference();
- if (paintBuffer == null || paintBuffer.getWidth() < fRef.getWidth() || paintBuffer.getHeight() < fRef.getHeight()) {
- paintBuffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage((int)Math.ceil(fRef.getWidth()),(int)Math.ceil(fRef.getHeight()));
- }
- return paintBuffer;
- }
-
- /**
- * Caches the information necessary to animate from the current view bounds to the
- * specified centerBounds
- */
- private AffineTransform cacheViewBounds(Rectangle2D centerBounds, boolean scaleToFit) {
- PBounds viewBounds = getViewBounds();
-
- // Initialize the image to the union of the current and destination bounds
- PBounds imageBounds = new PBounds(viewBounds);
- imageBounds.add(centerBounds);
-
- animateViewToCenterBounds(imageBounds,scaleToFit,0);
-
- imageAnimateBounds = getViewBounds();
-
- // Now create the actual cache image that we will use to animate fast
-
- BufferedImage buffer = getPaintBuffer();
- Paint fPaint = Color.white;
- if (getPaint() != null) {
- fPaint = getPaint();
- }
- toImage(buffer,fPaint);
-
- // Do this after the painting above!
- imageAnimate = true;
-
- // Return the bounds to the previous viewbounds
- animateViewToCenterBounds(viewBounds,scaleToFit,0);
-
- // The code below is just copied from animateViewToCenterBounds to create the
- // correct transform to center the specified bounds
-
- PDimension delta = viewBounds.deltaRequiredToCenter(centerBounds);
- PAffineTransform newTransform = getViewTransform();
- newTransform.translate(delta.width, delta.height);
-
- if (scaleToFit) {
- double s = Math.min(viewBounds.getWidth() / centerBounds.getWidth(), viewBounds.getHeight() / centerBounds.getHeight());
- newTransform.scaleAboutPoint(s, centerBounds.getCenterX(), centerBounds.getCenterY());
- }
-
- return newTransform;
- }
-
- /**
- * Turns off the fast image animation and does any other applicable cleanup
- */
- private void clearViewCache() {
- imageAnimate = false;
- imageAnimateBounds = null;
- }
-
- /**
- * Mimics the standard animateViewToCenterBounds but uses a cached image for performance
- * rather than re-rendering the scene at each step
- */
- public PTransformActivity animateStaticViewToCenterBoundsFast(Rectangle2D centerBounds, boolean shouldScaleToFit, long duration) {
- if (duration == 0) {
- return animateViewToCenterBounds(centerBounds,shouldScaleToFit,duration);
- }
-
- AffineTransform newViewTransform = cacheViewBounds(centerBounds,shouldScaleToFit);
-
- return animateStaticViewToTransformFast(newViewTransform, duration);
- }
-
- /**
- * This copies the behavior of the standard animateViewToTransform but clears the cache
- * when it is done
- */
- protected PTransformActivity animateStaticViewToTransformFast(AffineTransform destination, long duration) {
- if (duration == 0) {
- setViewTransform(destination);
- return null;
- }
-
- PTransformActivity.Target t = new PTransformActivity.Target() {
- public void setTransform(AffineTransform aTransform) {
- PCacheCamera.this.setViewTransform(aTransform);
- }
- public void getSourceMatrix(double[] aSource) {
- getViewTransformReference().getMatrix(aSource);
- }
- };
-
- PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destination) {
- protected void activityFinished() {
- clearViewCache();
- repaint();
- super.activityFinished();
- }
- };
-
- PRoot r = getRoot();
- if (r != null) {
- r.getActivityScheduler().addActivity(ta);
- }
-
- return ta;
- }
-
- /**
- * Overrides the camera's full paint method to do the fast rendering when possible
- */
- public void fullPaint(PPaintContext paintContext) {
- if (imageAnimate) {
- PBounds fRef = getFullBoundsReference();
- PBounds viewBounds = getViewBounds();
- double scale = getFullBoundsReference().getWidth()/imageAnimateBounds.getWidth();
- double xOffset = (viewBounds.getX()-imageAnimateBounds.getX())*scale;
- double yOffset = (viewBounds.getY()-imageAnimateBounds.getY())*scale;
- double scaleW = viewBounds.getWidth()*scale;
- double scaleH = viewBounds.getHeight()*scale;
- paintContext.getGraphics().drawImage(paintBuffer,0,0,(int)Math.ceil(fRef.getWidth()),(int)Math.ceil(fRef.getHeight()),
- (int)Math.floor(xOffset),(int)Math.floor(yOffset),(int)Math.ceil(xOffset+scaleW),(int)Math.ceil(yOffset+scaleH),null);
- }
- else {
- super.fullPaint(paintContext);
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java b/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java
deleted file mode 100755
index 6b69ce7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.geom.Rectangle2D;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PClip is a simple node that applies a clip before rendering or picking its
- * children. PClip is a subclass of PPath, the clip applies is the GeneralPath wrapped
- * by its super class. See piccolo/examples ClipExample.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PClip extends PPath {
-
- /**
- *
- */
- private static final long serialVersionUID = 837100163134537101L;
-
- public PBounds computeFullBounds(PBounds dstBounds) {
- if (dstBounds == null) dstBounds = new PBounds();
- dstBounds.reset();
- dstBounds.add(getBoundsReference());
- localToParent(dstBounds);
- return dstBounds;
- }
-
- public void repaintFrom(PBounds localBounds, PNode childOrThis) {
- if (childOrThis != this) {
- Rectangle2D.intersect(getBoundsReference(), localBounds, localBounds);
- super.repaintFrom(localBounds, childOrThis);
- } else {
- super.repaintFrom(localBounds, childOrThis);
- }
- }
-
- protected void paint(PPaintContext paintContext) {
- Paint p = getPaint();
- if (p != null) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(p);
- g2.fill(getPathReference());
- }
- paintContext.pushClip(getPathReference());
- }
-
- protected void paintAfterChildren(PPaintContext paintContext) {
- paintContext.popClip(getPathReference());
- if (getStroke() != null && getStrokePaint() != null) {
- Graphics2D g2 = paintContext.getGraphics();
- g2.setPaint(getStrokePaint());
- g2.setStroke(getStroke());
- g2.draw(getPathReference());
- }
- }
-
- public boolean fullPick(PPickPath pickPath) {
- if (getPickable() && fullIntersects(pickPath.getPickBounds())) {
- pickPath.pushNode(this);
- pickPath.pushTransform(getTransformReference(false));
-
- if (pick(pickPath)) {
- return true;
- }
-
- if (getChildrenPickable() && getPathReference().intersects(pickPath.getPickBounds())) {
- int count = getChildrenCount();
- for (int i = count - 1; i >= 0; i--) {
- PNode each = getChild(i);
- if (each.fullPick(pickPath))
- return true;
- }
- }
-
- if (pickAfterChildren(pickPath)) {
- return true;
- }
-
- pickPath.popTransform(getTransformReference(false));
- pickPath.popNode(this);
- }
-
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java b/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java
deleted file mode 100755
index 8d66327..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PComposite is a simple node that makes a group of nodes appear to
- * be a single node when picking and interacting. There is also partial
- * (commented out) support for resizing the child node to fit when this
- * nodes bounds are set.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PComposite extends PNode {
-
- /*
- public boolean setBounds(double x, double y, double width, double height) {
- PBounds childBounds = getUnionOfChildrenBounds(null);
-
- double dx = x - childBounds.x;
- double dy = y - childBounds.y;
- double sx = width / childBounds.width;
- double sy = height / childBounds.height;
- double scale = sx > sy ? sx : sy;
-
- Iterator i = getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- each.offset(dx, dy);
- each.scaleAboutPoint(scale, each.getBoundsReference().x, each.getBoundsReference().y);
- }
-
- return super.setBounds(x, y, width, height);
- }
-
- protected void layoutChildren() {
- getBoundsReference().setRect(getUnionOfChildrenBounds(null));
- }
- */
-
- /**
- *
- */
- private static final long serialVersionUID = -6413230863512586045L;
-
- /**
- * Return true if this node or any pickable descendends are picked. If
- * a pick occurs the pickPath is modified so that this node is always returned
- * as the picked node, event if it was a decendent node that initialy reported the
- * pick.
- */
- public boolean fullPick(PPickPath pickPath) {
- if (super.fullPick(pickPath)) {
- PNode picked = pickPath.getPickedNode();
-
- // this code won't work with internal cameras, because it doesn't pop
- // the cameras view transform.
- while (picked != this) {
- pickPath.popTransform(picked.getTransformReference(false));
- pickPath.popNode(picked);
- picked = pickPath.getPickedNode();
- }
-
- return true;
- }
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java b/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java
deleted file mode 100755
index 5f073ba..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.Color;
-import java.awt.Paint;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragEventHandler;
-import edu.umd.cs.piccolo.nodes.PPath;
-
-/**
- * PLens is a simple default lens implementation for Piccolo. See piccolo/examples
- * LensExample for one possible use of this lens. Lens's are often application
- * specific, it may be easiest to study this code, and then implement your own custom
- * lens using the general principles illustrated here.
- *
- * The basic design here is to add a PCamera as the child of a Pnode (the lens node). The camera is
- * the viewing part of the lens, and the node is the title bar that can be used to
- * move the lens around. Users of this lens will probably want to set up some lens
- * specific event handler and attach it to the camera.
- *
- * A lens also needs a layer that it will look at (it should not be the same as the layer
- * that it's added to because then it will draw itself in a recursive loop. Last of all
- * the PLens will need to be added to the PCanvas layer (so that it can be seen
- * by the main camera).
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PLens extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 4775398283849582953L;
- public static double LENS_DRAGBAR_HEIGHT = 20;
- public static Paint DEFAULT_DRAGBAR_PAINT = Color.DARK_GRAY;
- public static Paint DEFAULT_LENS_PAINT = Color.LIGHT_GRAY;
-
- private PPath dragBar;
- private PCamera camera;
- private PDragEventHandler lensDragger;
-
- public PLens() {
- dragBar = PPath.createRectangle(0, 0, 100, 100); // Drag bar gets resized to fit the available space, so any rectangle will do here
- dragBar.setPaint(DEFAULT_DRAGBAR_PAINT);
- dragBar.setPickable(false); // This forces drag events to percolate up to PLens object
- addChild(dragBar);
-
- camera = new PCamera();
- camera.setPaint(DEFAULT_LENS_PAINT);
- addChild(camera);
-
- // create an event handler to drag the lens around. Note that this event
- // handler consumes events in case another conflicting event handler has been
- // installed higher up in the heirarchy.
- lensDragger = new PDragEventHandler();
- lensDragger.getEventFilter().setMarksAcceptedEventsAsHandled(true);
- addInputEventListener(lensDragger);
-
- // When this PLens is dragged around adjust the cameras view transform.
- addPropertyChangeListener(PNode.PROPERTY_TRANSFORM, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- camera.setViewTransform(getInverseTransform());
- }
- });
- }
-
- public PLens(PLayer layer) {
- this();
- addLayer(0, layer);
- }
-
- public PCamera getCamera() {
- return camera;
- }
-
- public PPath getDragBar() {
- return dragBar;
- }
-
- public PDragEventHandler getLensDraggerHandler() {
- return lensDragger;
- }
-
- public void addLayer(int index, PLayer layer) {
- camera.addLayer(index, layer);
- }
-
- public void removeLayer(PLayer layer) {
- camera.removeLayer(layer);
- }
-
- // when the lens is resized this method gives us a chance to layout the lenses
- // camera child appropriately.
- protected void layoutChildren() {
- dragBar.setPathToRectangle((float)getX(), (float)getY(), (float)getWidth(), (float)LENS_DRAGBAR_HEIGHT);
- camera.setBounds(getX(), getY() + LENS_DRAGBAR_HEIGHT, getWidth(), getHeight() - LENS_DRAGBAR_HEIGHT);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PLine.java b/src/main/java/edu/umd/cs/piccolox/nodes/PLine.java
deleted file mode 100755
index c53bbc1..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PLine.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Stroke;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-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.PPaintContext;
-import edu.umd.cs.piccolo.util.PUtil;
-import edu.umd.cs.piccolox.util.LineShape;
-
-/**
- * PLine a class for drawing multisegment lines.
- * Submitted by Hallvard Traetteberg.
- */
-public class PLine extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 7894340974402696321L;
- private static final PAffineTransform TEMP_TRANSFORM = new PAffineTransform();
- private static final BasicStroke DEFAULT_STROKE = new BasicStroke(1.0f);
- private static final Color DEFAULT_STROKE_PAINT = Color.black;
-
- private transient LineShape line;
- private transient Stroke stroke;
- private Paint strokePaint;
-
- public PLine(LineShape line) {
- strokePaint = DEFAULT_STROKE_PAINT;
- stroke = DEFAULT_STROKE;
- if (line == null) {
- line = new LineShape(null);
- }
- this.line = line;
- }
-
- public PLine() {
- this(null);
- }
-
- public PLine(LineShape line, Stroke aStroke) {
- this(line);
- stroke = aStroke;
- }
-
- //****************************************************************
- // Stroke
- //****************************************************************
-
- public Paint getStrokePaint() {
- return strokePaint;
- }
-
- public void setStrokePaint(Paint aPaint) {
- Paint old = strokePaint;
- strokePaint = aPaint;
- invalidatePaint();
- firePropertyChange(PPath.PROPERTY_CODE_STROKE_PAINT, PPath.PROPERTY_STROKE_PAINT, old, strokePaint);
- }
-
- public Stroke getStroke() {
- return stroke;
- }
-
- public void setStroke(Stroke aStroke) {
- Stroke old = stroke;
- stroke = aStroke;
- updateBoundsFromLine();
- invalidatePaint();
- firePropertyChange(PPath.PROPERTY_CODE_STROKE, PPath.PROPERTY_STROKE, old, stroke);
- }
-
- //****************************************************************
- // Bounds
- //****************************************************************
-
- public boolean setBounds(double x, double y, double width, double height) {
- if (line == null || !super.setBounds(x, y, width, height)) {
- return false;
- }
-
- Rectangle2D lineBounds = line.getBounds2D();
- Rectangle2D lineStrokeBounds = getLineBoundsWithStroke();
- double strokeOutset = Math.max(lineStrokeBounds.getWidth() - lineBounds.getWidth(),
- lineStrokeBounds.getHeight() - lineBounds.getHeight());
-
- x += strokeOutset / 2;
- y += strokeOutset / 2;
- width -= strokeOutset;
- height -= strokeOutset;
-
- TEMP_TRANSFORM.setToIdentity();
- TEMP_TRANSFORM.translate(x, y);
- TEMP_TRANSFORM.scale(width / lineBounds.getWidth(), height / lineBounds.getHeight());
- TEMP_TRANSFORM.translate(-lineBounds.getX(), -lineBounds.getY());
- line.transformPoints(TEMP_TRANSFORM);
-
- return true;
- }
-
- public boolean intersects(Rectangle2D aBounds) {
- if (super.intersects(aBounds)) {
- if (line.intersects(aBounds)) {
- return true;
- } else if (stroke != null && strokePaint != null) {
- return stroke.createStrokedShape(line).intersects(aBounds);
- }
- }
- return false;
- }
-
- public Rectangle2D getLineBoundsWithStroke() {
- if (stroke != null) {
- return stroke.createStrokedShape(line).getBounds2D();
- } else {
- return line.getBounds2D();
- }
- }
-
- public void updateBoundsFromLine() {
- if (line.getPointCount() == 0) {
- resetBounds();
- } else {
- Rectangle2D b = getLineBoundsWithStroke();
- super.setBounds(b.getX(), b.getY(), b.getWidth(), b.getHeight());
- }
- }
-
- //****************************************************************
- // Painting
- //****************************************************************
-
- protected void paint(PPaintContext paintContext) {
- Graphics2D g2 = paintContext.getGraphics();
-
- if (stroke != null && strokePaint != null) {
- g2.setPaint(strokePaint);
- g2.setStroke(stroke);
- g2.draw(line);
- }
- }
-
- public LineShape getLineReference() {
- return line;
- }
-
- public int getPointCount() {
- return line.getPointCount();
- }
-
- public Point2D getPoint(int i, Point2D dst) {
- if (dst == null) {
- dst = new Point2D.Double();
- }
- return line.getPoint(i, dst);
- }
-
- protected void lineChanged() {
- firePropertyChange(PPath.PROPERTY_CODE_PATH, PPath.PROPERTY_PATH, null, line);
- updateBoundsFromLine();
- invalidatePaint();
- }
-
- public void setPoint(int i, double x, double y) {
- line.setPoint(i, x, y);
- lineChanged();
- }
-
- public void addPoint(int i, double x, double y) {
- line.addPoint(i, x, y);
- lineChanged();
- }
-
- public void removePoints(int i, int n) {
- line.removePoints(i, n);
- lineChanged();
- }
-
- public void removeAllPoints() {
- line.removePoints(0, line.getPointCount());
- lineChanged();
- }
-
- //****************************************************************
- // Serialization
- //****************************************************************
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
- PUtil.writeStroke(stroke, out);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- stroke = PUtil.readStroke(in);
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PNodeCache.java b/src/main/java/edu/umd/cs/piccolox/nodes/PNodeCache.java
deleted file mode 100755
index 4b4d00f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PNodeCache.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.geom.Dimension2D;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PNodeCache caches a visual representation of it's children
- * into an image and uses this cached image for painting instead of
- * painting it's children directly. This is intended to be used in
- * two ways.
- *
- * First it can be used as a simple optimization technique. If a node
- * has many descendents it may be faster to paint the cached image
- * representation instead of painting each node.
- *
- * Second PNodeCache provides a place where "image" effects such as
- * blurring and drop shadows can be added to the Piccolo scene graph.
- * This can be done by overriding the method createImageCache and
- * returing an image with the desired effect applied.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PNodeCache extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 3405487448820578710L;
- private transient Image imageCache;
- private boolean validatingCache;
-
- /**
- * Override this method to customize the image cache creation process. For
- * example if you want to create a shadow effect you would do that here. Fill
- * in the cacheOffsetRef if needed to make your image cache line up with the
- * nodes children.
- */
- public Image createImageCache(Dimension2D cacheOffsetRef) {
- return toImage();
- }
-
- public Image getImageCache() {
- if (imageCache == null) {
- PDimension cacheOffsetRef = new PDimension();
- validatingCache = true;
- resetBounds();
- imageCache = createImageCache(cacheOffsetRef);
- PBounds b = getFullBoundsReference();
- setBounds(b.getX() + cacheOffsetRef.getWidth(),
- b.getY() + cacheOffsetRef.getHeight(),
- imageCache.getWidth(null),
- imageCache.getHeight(null));
- validatingCache = false;
- }
- return imageCache;
- }
-
- public void invalidateCache() {
- imageCache = null;
- }
-
- public void invalidatePaint() {
- if (!validatingCache) {
- super.invalidatePaint();
- }
- }
-
- public void repaintFrom(PBounds localBounds, PNode childOrThis) {
- if (!validatingCache) {
- super.repaintFrom(localBounds, childOrThis);
- invalidateCache();
- }
- }
-
- public void fullPaint(PPaintContext paintContext) {
- if (validatingCache) {
- super.fullPaint(paintContext);
- } else {
- Graphics2D g2 = paintContext.getGraphics();
- g2.drawImage(getImageCache(), (int) getX(), (int) getY(), null);
- }
- }
-
- protected boolean pickAfterChildren(PPickPath pickPath) {
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java b/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
deleted file mode 100755
index 1ae8db6..0000000
--- a/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java
+++ /dev/null
@@ -1,684 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.nodes;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-import java.awt.Insets;
-import java.awt.font.FontRenderContext;
-import java.awt.font.LineBreakMeasurer;
-import java.awt.font.TextAttribute;
-import java.awt.font.TextLayout;
-import java.awt.geom.Line2D;
-import java.awt.geom.Rectangle2D;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import javax.swing.text.AttributeSet;
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.Document;
-import javax.swing.text.Element;
-import javax.swing.text.StyleConstants;
-import javax.swing.text.StyleContext;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * @author Lance Good
- */
-public class PStyledText extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -8002221443235028076L;
- protected static FontRenderContext SWING_FRC = new FontRenderContext(null,true,false);
- protected static Line2D paintLine = new Line2D.Double();
-
- protected Document document;
- protected transient ArrayList stringContents;
- protected transient LineInfo[] lines;
-
- protected boolean editing;
- protected Insets insets = new Insets(0,0,0,0);
- protected boolean constrainHeightToTextHeight = true;
- protected boolean constrainWidthToTextWidth = true;
-
- /**
- * Constructor for PStyledText.
- */
- public PStyledText() {
- super();
- }
-
- /**
- * Controls whether this node changes its width to fit the width
- * of its text. If flag is true it does; if flag is false it doesn't
- */
- public void setConstrainWidthToTextWidth(boolean constrainWidthToTextWidth) {
- this.constrainWidthToTextWidth = constrainWidthToTextWidth;
- recomputeLayout();
- }
-
- /**
- * Controls whether this node changes its height to fit the height
- * of its text. If flag is true it does; if flag is false it doesn't
- */
- public void setConstrainHeightToTextHeight(boolean constrainHeightToTextHeight) {
- this.constrainHeightToTextHeight = constrainHeightToTextHeight;
- recomputeLayout();
- }
-
- /**
- * Controls whether this node changes its width to fit the width
- * of its text. If flag is true it does; if flag is false it doesn't
- */
- public boolean getConstrainWidthToTextWidth() {
- return constrainWidthToTextWidth;
- }
-
- /**
- * Controls whether this node changes its height to fit the height
- * of its text. If flag is true it does; if flag is false it doesn't
- */
- public boolean getConstrainHeightToTextHeight() {
- return constrainHeightToTextHeight;
- }
-
- /**
- * Get the document for this PStyledText
- */
- public Document getDocument() {
- return document;
- }
-
- /**
- * Set the document on this PStyledText
- */
- public void setDocument(Document document) {
- // Save the document
- this.document = document;
-
- syncWithDocument();
- }
-
-
- public void syncWithDocument() {
- // The paragraph start and end indices
- ArrayList pEnds = null;
-
- // The current position in the specified range
- int pos = 0;
-
- // First get the actual text and stick it in an Attributed String
- try {
-
- stringContents = new ArrayList();
- pEnds = new ArrayList();
-
- String s = document.getText(0,document.getLength());
- StringTokenizer tokenizer = new StringTokenizer(s,"\n",true);
-
- // lastNewLine is used to detect the case when two newlines follow in direct succession
- // & lastNewLine should be true to start in case the first character is a newline
- boolean lastNewLine = true;
- for(int i=0; tokenizer.hasMoreTokens(); i++) {
- String token = tokenizer.nextToken();
-
- // If the token
- if (token.equals("\n")) {
- if (lastNewLine) {
- stringContents.add(new AttributedString(" "));
- pEnds.add(new RunInfo(pos,pos+1));
-
- pos = pos + 1;
-
- lastNewLine = true;
- }
- else {
- pos = pos + 1;
-
- lastNewLine = true;
- }
- }
- // If the token is empty - create an attributed string with a single space
- // since LineBreakMeasurers don't work with an empty string
- // - note that this case should only arise if the document is empty
- else if (token.equals("")) {
- stringContents.add(new AttributedString(" "));
- pEnds.add(new RunInfo(pos,pos));
-
- lastNewLine = false;
- }
- // This is the normal case - where we have some text
- else {
- stringContents.add(new AttributedString(token));
- pEnds.add(new RunInfo(pos,pos+token.length()));
-
- // Increment the position
- pos = pos+token.length();
-
- lastNewLine = false;
- }
- }
-
- // Add one more newline if the last character was a newline
- if (lastNewLine) {
- stringContents.add(new AttributedString(" "));
- pEnds.add(new RunInfo(pos,pos+1));
-
- lastNewLine = false;
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
-
- // The default style context - which will be reused
- StyleContext style = StyleContext.getDefaultStyleContext();
-
- RunInfo pEnd = null;
- for (int i = 0; i < stringContents.size(); i++) {
- pEnd = (RunInfo)pEnds.get(i);
- pos = pEnd.runStart;
-
- // The current element will be used as a temp variable while searching
- // for the leaf element at the current position
- Element curElement = null;
-
- // Small assumption here that there is one root element - can fix
- // for more general support later
- Element rootElement = document.getDefaultRootElement();
-
- // If the string is length 0 then we just need to add the attributes once
- if (pEnd.runStart != pEnd.runLimit) {
- // OK, now we loop until we find all the leaf elements in the range
- while (pos < pEnd.runLimit) {
-
- // Before each pass, start at the root
- curElement = rootElement;
-
- // Now we descend the hierarchy until we get to a leaf
- while (!curElement.isLeaf()) {
- curElement =
- curElement.getElement(curElement.getElementIndex(pos));
- }
-
- // These are the mandatory attributes
-
- AttributeSet attributes = curElement.getAttributes();
- Color foreground = style.getForeground(attributes);
-
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.FOREGROUND,
- foreground,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
-
- Font font = (attributes.isDefined(StyleConstants.FontSize) || attributes.isDefined(StyleConstants.FontFamily)) ? style.getFont(attributes) : null;
- if (font == null) {
- if (document instanceof DefaultStyledDocument) {
- font = style.getFont(((DefaultStyledDocument)document).getCharacterElement(pos).getAttributes());
- if (font == null) {
- font = style.getFont(((DefaultStyledDocument)document).getParagraphElement(pos).getAttributes());
- }
- if (font == null) {
- font = style.getFont(rootElement.getAttributes());
- }
- }
- else {
- font = style.getFont(rootElement.getAttributes());
- }
- }
- if (font != null) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.FONT,
- font,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- // These are the optional attributes
-
- Color background = (attributes.isDefined(StyleConstants.Background)) ? style.getBackground(attributes) : null;
- if (background != null) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.BACKGROUND,
- background,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- boolean underline = StyleConstants.isUnderline(attributes);
- if (underline) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.UNDERLINE,
- Boolean.TRUE,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- boolean strikethrough = StyleConstants.isStrikeThrough(attributes);
- if (strikethrough) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.STRIKETHROUGH,
- Boolean.TRUE,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- // And set the position to the end of the given attribute
- pos = curElement.getEndOffset();
- }
- }
- else {
- // Before each pass, start at the root
- curElement = rootElement;
-
- // Now we descend the hierarchy until we get to a leaf
- while (!curElement.isLeaf()) {
- curElement =
- curElement.getElement(curElement.getElementIndex(pos));
- }
-
- // These are the mandatory attributes
-
- AttributeSet attributes = curElement.getAttributes();
- Color foreground = style.getForeground(attributes);
-
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.FOREGROUND,
- foreground,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
-
- // These are the optional attributes
-
- Font font = (attributes.isDefined(StyleConstants.FontSize) || attributes.isDefined(StyleConstants.FontFamily)) ? style.getFont(attributes) : null;
- if (font == null) {
- if (document instanceof DefaultStyledDocument) {
- font = style.getFont(((DefaultStyledDocument)document).getCharacterElement(pos).getAttributes());
- if (font == null) {
- font = style.getFont(((DefaultStyledDocument)document).getParagraphElement(pos).getAttributes());
- }
- if (font == null) {
- font = style.getFont(rootElement.getAttributes());
- }
- }
- else {
- font = style.getFont(rootElement.getAttributes());
- }
- }
- if (font != null) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.FONT,
- font,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- Color background = (attributes.isDefined(StyleConstants.Background)) ? style.getBackground(attributes) : null;
- if (background != null) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.BACKGROUND,
- background,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- boolean underline = StyleConstants.isUnderline(attributes);
- if (underline) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.UNDERLINE,
- Boolean.TRUE,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
-
- boolean strikethrough = StyleConstants.isStrikeThrough(attributes);
- if (strikethrough) {
- ((AttributedString)stringContents.get(i)).addAttribute(
- TextAttribute.STRIKETHROUGH,
- Boolean.TRUE,
- (int)Math.max(0,curElement.getStartOffset()-pEnd.runStart),
- (int)Math.min(pEnd.runLimit-pEnd.runStart,curElement.getEndOffset()-pEnd.runStart));
- }
- }
- }
-
- recomputeLayout();
- }
-
- /**
- * Compute the bounds of the text wrapped by this node. The text layout
- * is wrapped based on the bounds of this node. If the shrinkBoundsToFit parameter
- * is true then after the text has been laid out the bounds of this node are shrunk
- * to fit around those text bounds.
- */
- public void recomputeLayout() {
- if (stringContents == null) return;
-
- ArrayList linesList = new ArrayList();
-
- double textWidth = 0;
- double textHeight = 0;
-
- for(int i=0; i breakList = null;
-
- // First we have to do an initial pass with a LineBreakMeasurer to
- // find out where Swing is going to break the lines - i.e.
- // because it doesn't use fractional metrics
-
- measurer = new LineBreakMeasurer(itr, SWING_FRC);
- breakList = new ArrayList();
- while(measurer.getPosition() < itr.getEndIndex()) {
- if (constrainWidthToTextWidth) {
- measurer.nextLayout(Float.MAX_VALUE);
- }
- else {
- measurer.nextLayout((float)Math.ceil(getWidth()-insets.left-insets.right));
- }
-
- breakList.add(new Integer(measurer.getPosition()));
- }
-
- measurer = new LineBreakMeasurer(itr, PPaintContext.RENDER_QUALITY_HIGH_FRC);
-
- // Need to change the lineinfo data structure to know about multiple
- // text layouts per line
-
- LineInfo lineInfo = null;
- boolean newLine = true;
- double lineWidth = 0;
- while (measurer.getPosition() < itr.getEndIndex()) {
- TextLayout aTextLayout = null;
-
- if (newLine) {
- newLine = false;
-
- // Add in the old line dimensions
- double lineHeight = (lineInfo == null) ? 0 : lineInfo.maxAscent+lineInfo.maxDescent+lineInfo.leading;
- textHeight = textHeight+lineHeight;
- textWidth = Math.max(textWidth,lineWidth);
-
- // Now create a new line
- lineInfo = new LineInfo();
- linesList.add(lineInfo);
- }
-
- int lineEnd = ((Integer)breakList.get(0)).intValue();
- if (lineEnd <= itr.getRunLimit()) {
- breakList.remove(0);
- newLine = true;
- }
-
- aTextLayout = measurer.nextLayout(Float.MAX_VALUE,Math.min(lineEnd,itr.getRunLimit()),false);
-
- SegmentInfo sInfo = new SegmentInfo();
- sInfo.font = (Font)itr.getAttribute(TextAttribute.FONT);
- sInfo.foreground = (Color)itr.getAttribute(TextAttribute.FOREGROUND);
- sInfo.background = (Color)itr.getAttribute(TextAttribute.BACKGROUND);
- sInfo.underline = (Boolean)itr.getAttribute(TextAttribute.UNDERLINE);
- sInfo.layout = aTextLayout;
-
- FontMetrics metrics = StyleContext.getDefaultStyleContext().getFontMetrics((Font)itr.getAttribute(TextAttribute.FONT));
- lineInfo.maxAscent = Math.max(lineInfo.maxAscent,metrics.getMaxAscent());
- lineInfo.maxDescent = Math.max(lineInfo.maxDescent,metrics.getMaxDescent());
- lineInfo.leading = Math.max(lineInfo.leading,metrics.getLeading());
-
- lineInfo.segments.add(sInfo);
-
- itr.setIndex(measurer.getPosition());
- lineWidth = lineWidth+aTextLayout.getAdvance();
- }
-
- double lineHeight = (lineInfo == null) ? 0 : lineInfo.maxAscent+lineInfo.maxDescent+lineInfo.leading;
- textHeight = textHeight+lineHeight;
- textWidth = Math.max(textWidth,lineWidth);
- }
-
- lines = (LineInfo[])linesList.toArray(new LineInfo[0]);
-
- if (constrainWidthToTextWidth || constrainHeightToTextHeight) {
- double newWidth = getWidth();
- double newHeight = getHeight();
-
- if (constrainWidthToTextWidth) {
- newWidth = textWidth + insets.left + insets.right;
- }
-
- if (constrainHeightToTextHeight) {
- newHeight = Math.max(textHeight,getInitialFontHeight()) + insets.top + insets.bottom;
- }
-
- super.setBounds(getX(), getY(), newWidth, newHeight);
- }
- }
-
- /**
- * Get the height of the font at the beginning of the document
- */
- public double getInitialFontHeight() {
-
- // Small assumption here that there is one root element - can fix
- // for more general support later
- Element rootElement = document.getDefaultRootElement();
-
- // The current element will be used as a temp variable while searching
- // for the leaf element at the current position
- Element curElement = rootElement;
-
- // Now we descend the hierarchy until we get to a leaf
- while (!curElement.isLeaf()) {
- curElement = curElement.getElement(curElement.getElementIndex(0));
- }
-
- StyleContext context = StyleContext.getDefaultStyleContext();
- Font font = context.getFont(curElement.getAttributes());
-
- FontMetrics curFM = context.getFontMetrics(font);
-
- return curFM.getMaxAscent() + curFM.getMaxDescent() + curFM.getLeading();
- }
-
- protected void paint(PPaintContext paintContext) {
- float x = (float) (getX() + insets.left);
- float y = (float) (getY() + insets.top);
- float bottomY = (float) (getY() + getHeight() - insets.bottom);
-
- if (lines == null || lines.length == 0) {
- return;
- }
-
- Graphics2D g2 = paintContext.getGraphics();
-
- if (getPaint() != null) {
- g2.setPaint(getPaint());
- g2.fill(getBoundsReference());
- }
-
- float curX;
- for (int i=0; i segments;
- public double maxAscent;
- public double maxDescent;
- public double leading;
-
- public LineInfo() {
- segments = new ArrayList();
- }
- }
-
- protected static class SegmentInfo {
- public TextLayout layout;
- public Font font;
- public Color foreground;
- public Color background;
- public Boolean underline;
-
- public SegmentInfo() {
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java b/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java
deleted file mode 100755
index a943fa7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * Copyright (C) 1998-2000 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.pswing;
-
-import java.awt.Rectangle;
-import java.awt.geom.Rectangle2D;
-import java.io.Serializable;
-import java.util.Vector;
-
-import javax.swing.ComboBoxModel;
-import javax.swing.JComboBox;
-import javax.swing.plaf.basic.BasicComboBoxUI;
-import javax.swing.plaf.basic.BasicComboPopup;
-import javax.swing.plaf.basic.ComboPopup;
-
-/**
- * The PComboBox is used instead of a JComboBox in a Piccolo scene graph.
- * This PComboBox won't work properly if it is located in an abnormal hierarchy of Cameras.
- * Support is provided for only one (or zero) view transforms.
- *
- * A ComboBox for use in Piccolo. This still has an associated JPopupMenu
- * (which is always potentially heavyweight depending on component location
- * relative to containing window borders.) However, this ComboBox places
- * the PopupMenu component of the ComboBox in the appropriate position
- * relative to the permanent part of the ComboBox. The PopupMenu is never
- * transformed.
- *
- * This class was not designed for subclassing. If different behavior
- * is required, it seems more appropriate to subclass JComboBox directly
- * using this class as a model.
- *
- * NOTE: There is currently a known bug, namely, if the ComboBox receives
- * focus through 'tab' focus traversal and the keyboard is used to interact
- * with the ComboBox, there may be unexpected results.
- *
- *
- * Warning: Serialized objects of this class will not be
- * compatible with future Piccolo releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Piccolo. A future release of Piccolo will provide support for long
- * term persistence.
- *
- * @author Lance Good
- */
-public class PComboBox extends JComboBox implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 4945060951140634207L;
- private PSwing pSwing;
- private PSwingCanvas canvas;
-
- /**
- * Creates a PComboBox that takes its items from an existing ComboBoxModel.
- *
- * @param model The ComboBoxModel from which the list will be created
- */
- public PComboBox( ComboBoxModel model ) {
- super( model );
- init();
- }
-
- /**
- * Creates a PComboBox that contains the elements in the specified array.
- *
- * @param items The items to populate the PComboBox list
- */
- public PComboBox( final Object items[] ) {
- super( items );
- init();
- }
-
- /**
- * Creates a PComboBox that contains the elements in the specified Vector.
- *
- * @param items The items to populate the PComboBox list
- */
- @SuppressWarnings("unchecked")
- public PComboBox( Vector items ) {
- super( items );
- init();
- }
-
- /**
- * Create an empty PComboBox
- */
- public PComboBox() {
- super();
- init();
- }
-
- /**
- * Substitue our UI for the default
- */
- private void init() {
- setUI( new PBasicComboBoxUI() );
- }
-
- /**
- * Clients must set the PSwing and PSwingCanvas environment for this PComboBox to work properly.
- *
- * @param pSwing
- * @param canvas
- */
- public void setEnvironment( PSwing pSwing, PSwingCanvas canvas ) {
- this.pSwing = pSwing;
- this.canvas = canvas;
- }
-
- /**
- * The substitute look and feel - used to capture the mouse
- * events on the arrowButton and the component itself and
- * to create our PopupMenu rather than the default
- */
- protected class PBasicComboBoxUI extends BasicComboBoxUI {
-
- /**
- * Create our Popup instead of theirs
- */
- protected ComboPopup createPopup() {
- PBasicComboPopup popup = new PBasicComboPopup( comboBox );
- popup.getAccessibleContext().setAccessibleParent( comboBox );
- return popup;
- }
- }
-
- /**
- * The substitute ComboPopupMenu that places itself correctly
- * in Piccolo.
- */
- protected class PBasicComboPopup extends BasicComboPopup {
-
- /**
- *
- */
- private static final long serialVersionUID = -141057997038239140L;
-
-
- /**
- * @param combo The parent ComboBox
- */
- public PBasicComboPopup( JComboBox combo ) {
- super( combo );
- }
-
-
- /**
- * Computes the bounds for the Popup in Piccolo if a
- * PMouseEvent has been received. Otherwise, it uses the
- * default algorithm for placing the popup.
- *
- * @param px corresponds to the x coordinate of the popup
- * @param py corresponds to the y coordinate of the popup
- * @param pw corresponds to the width of the popup
- * @param ph corresponds to the height of the popup
- * @return The bounds for the PopupMenu
- */
- protected Rectangle computePopupBounds( int px, int py, int pw, int ph ) {
- Rectangle2D r = getNodeBoundsInCanvas();
- Rectangle sup = super.computePopupBounds( px, py, pw, ph );
- return new Rectangle( (int)r.getX(), (int)r.getMaxY(), (int)sup.getWidth(), (int)sup.getHeight() );
- }
- }
-
- private Rectangle2D getNodeBoundsInCanvas() {
- if( pSwing == null || canvas == null ) {
- throw new RuntimeException( "PComboBox.setEnvironment( swing, pCanvas );//has to be done manually at present" );
- }
- Rectangle2D r1c = pSwing.getBounds();
- pSwing.localToGlobal( r1c );
- canvas.getCamera().globalToLocal( r1c );
- r1c = canvas.getCamera().getViewTransform().createTransformedShape( r1c ).getBounds2D();
- return r1c;
- }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
deleted file mode 100755
index 0f7dda4..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java
+++ /dev/null
@@ -1,550 +0,0 @@
-/**
- * Copyright (C) 1998-2000 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/*
- This message was sent to Sun on August 27, 1999
-
- -----------------------------------------------
-
- We are currently developing Piccolo, a "scenegraph" for use in 2D graphics.
- One of our ultimate goals is to support Swing lightweight components
- within Piccolo, whose graphical space supports arbitray affine transforms.
- The challenge in this pursuit is getting the components to respond and
- render properly though not actually displayed in a standard Java component
- hierarchy.
-
-
- The first issues involved making the Swing components focusable and
- showing. This was accomplished by adding the Swing components to a 0x0
- JComponent which was in turn added to our main Piccolo application component.
- To our good fortune, a Java component is showing merely if it and its
- ancestors are showing and not based on whether it is ACTUALLY visible.
- Likewise, focus in a JComponent depends merely on the component's
- containing window having focus.
-
-
- The second issue involved capturing the repaint calls on a Swing
- component. Normally, for a repaint and the consequent call to
- paintImmediately, a Swing component obtains the Graphics object necessary
- to render itself through the Java component heirarchy. However, for Piccolo
- we would like the component to render using a Graphics object that Piccolo
- may have arbitrarily transformed in some way. By capturing in the
- RepaintManager the repaint calls made on our special Swing components, we
- are able to redirect the repaint requests through the Piccolo architecture to
- put the Graphics in its proper context. Unfortunately, this means that
- if the Swing component contains other Swing components, then any repaint
- requests made by one of these nested components must go through
- the Piccolo architecture then through the top level Swing component
- down to the nested Swing component. This normally doesn't cause a
- problem. However, if calling paint on one of these nested
- children causes a call to repaint then an infinite loop ensues. This does
- in fact happen in the Swing components that use cell renderers. Before
- the cell renderer is painted, it is invalidated and consequently
- repainted. We solved this problem by putting a lock on repaint calls for
- a component while that component is painting. (A similar problem faced
- the Swing team over this same issue. They solved it by inserting a
- CellRendererPane to capture the renderer's invalidate calls.)
-
-
- Another issue arose over the forwarding of mouse events to the Swing
- components. Since our Swing components are not actually displayed on
- screen in the standard manner, we must manually dispatch any MouseEvents
- we want the component to receive. Hence, we needed to find the deepest
- visible component at a particular location that accepts MouseEvents.
- Finding the deepest visible component at a point was achieved with the
- "findComponentAt" method in java.awt.Container. With the
- "getListeners(Class listenerType)" method added in JDK1.3 Beta we are able
- to determine if the component has any Mouse Listeners. However, we haven't
- yet found a way to determine if MouseEvents have been specifically enabled
- for a component. The package private method "eventEnabled" in
- java.awt.Component does exactly what we want but is, of course,
- inaccessible. In order to dispatch events correctly we would need a
- public accessor to the method "boolean eventEnabled(AWTEvent)" in
- java.awt.Component.
-
-
- Still another issue involves the management of cursors when the mouse is
- over a Swing component in our application. To the Java mechanisms, the
- mouse never appears to enter the bounds of the Swing components since they
- are contained by a 0x0 JComponent. Hence, we must manually change the
- cursor when the mouse enters one of the Swing components in our
- application. This generally works but becomes a problem if the Swing
- component's cursor changes while we are over that Swing component (for
- instance, if you resize a Table Column). In order to manage cursors
- properly, we would need setCursor to fire property change events.
-
-
- With the above fixes, most Swing components work. The only Swing
- components that are definitely broken are ToolTips and those that rely on
- JPopupMenu. In order to implement ToolTips properly, we would need to have
- a method in ToolTipManager that allows us to set the current manager, as
- is possible with RepaintManager. In order to implement JPopupMenu, we
- will likely need to reimplement JPopupMenu to function in Piccolo with
- a transformed Graphics and to insert itself in the proper place in the
- Piccolo scenegraph.
-
-*/
-
-
-/**
- * PSwing is used to add Swing Components to a Piccolo canvas.
- *
- * Example: adding a swing JButton to a PCanvas:
- *
- * PSwingCanvas canvas = new PSwingCanvas();
- * JButton button = new JButton("Button");
- * swing = new PSwing(canvas, button);
- * canvas.getLayer().addChild(swing);
- *
- *
- * NOTE: PSwing has the current limitation that it does not listen for
- * Container events. This is only an issue if you create a PSwing
- * and later add Swing components to the PSwing's component hierarchy
- * that do not have double buffering turned off or have a smaller font
- * size than the minimum font size of the original PSwing's component
- * hierarchy.
- *
- * For instance, the following bit of code will give unexpected
- * results:
- *
- * JPanel panel = new JPanel();
- * PSwing swing = new PSwing(panel);
- * JPanel newChild = new JPanel();
- * newChild.setDoubleBuffered(true);
- * panel.add(newChild);
- *
- *
- * NOTE: PSwing cannot be correctly interacted with through multiple cameras.
- * There is no support for it yet.
- *
- * NOTE: PSwing is java.io.Serializable.
- *
- * Warning: Serialized objects of this class will not be
- * compatible with future Piccolo releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Piccolo. A future release of Piccolo will provide support for long
- * term persistence.
- *
- * @author Sam R. Reid
- * @author Benjamin B. Bederson
- * @author Lance E. Good
- *
- * 3-23-2007 edited to automatically detect PCamera/PSwingCanvas to allow single-arg constructor usage
- */
-public class PSwing extends PNode implements Serializable, PropertyChangeListener {
-
-
- /**
- *
- */
- private static final long serialVersionUID = -4395225274564660293L;
- /**
- * Used as a hashtable key for this object in the Swing component's
- * client properties.
- */
- public static final String PSWING_PROPERTY = "PSwing";
- private static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform();
- private static PBounds TEMP_REPAINT_BOUNDS2 = new PBounds();
-
- /**
- * The cutoff at which the Swing component is rendered greek
- */
- private double renderCutoff = 0.3;
- private JComponent component = null;
- private double minFontSize = Double.MAX_VALUE;
- private Stroke defaultStroke = new BasicStroke();
- private Font defaultFont = new Font( "Serif", Font.PLAIN, 12 );
- private BufferedImage buffer;
- private static final Color BUFFER_BACKGROUND_COLOR = new Color( 0, 0, 0, 0 );
- private PSwingCanvas canvas;
-
- ////////////////////////////////////////////////////////////
- ///////Following fields are for automatic canvas/camera detection
- ////////////////////////////////////////////////////////////
- /*/keep track of which nodes we've attached listeners to since no built in support in PNode*/
- private ArrayList listeningTo = new ArrayList();
-
- /*The parent listener for camera/canvas changes*/
- private PropertyChangeListener parentListener = new PropertyChangeListener() {
- public void propertyChange( PropertyChangeEvent evt ) {
- PNode source = (PNode)evt.getSource();
- PNode parent = source.getParent();
- if( parent != null ) {
- listenForCanvas( parent );
- }
-
- }
- };
-
- /**
- * Constructs a new visual component wrapper for the Swing component.
- *
- * @param component The swing component to be wrapped
- */
- public PSwing(JComponent component) {
- this.component = component;
- component.putClientProperty( PSWING_PROPERTY, this );
- init( component );
- component.revalidate();
- component.addPropertyChangeListener( new PropertyChangeListener() {
- public void propertyChange( PropertyChangeEvent evt ) {
- reshape();
- }
- } );
- reshape();
- listenForCanvas( this );
- }
-
- /**
- * Deprecated constructor for application code still depending on this signature.
- * @param pSwingCanvas
- * @param component
- * @deprecated
- */
- public PSwing(PSwingCanvas pSwingCanvas, JComponent component) {
- this(component);
- }
-
- /**
- * Ensures the bounds of the underlying component are accurate, and sets the bounds of this PNode.
- */
- void reshape() {
- component.setBounds( 0, 0, component.getPreferredSize().width, component.getPreferredSize().height );
- setBounds( 0, 0, component.getPreferredSize().width, component.getPreferredSize().height );
- }
-
- /**
- * Determines if the Swing component should be rendered normally or
- * as a filled rectangle.
- *
- * The transform, clip, and composite will be set appropriately when this object
- * is rendered. It is up to this object to restore the transform, clip, and composite of
- * the Graphics2D if this node changes any of them. However, the color, font, and stroke are
- * unspecified by Piccolo. This object should set those things if they are used, but
- * they do not need to be restored.
- *
- * @param renderContext Contains information about current render.
- */
- public void paint( PPaintContext renderContext ) {
- Graphics2D g2 = renderContext.getGraphics();
-
- if( defaultStroke == null ) {
- defaultStroke = new BasicStroke();
- }
- g2.setStroke( defaultStroke );
-
- if( defaultFont == null ) {
- defaultFont = new Font( "Serif", Font.PLAIN, 12 );
- }
-
- g2.setFont( defaultFont );
-
- if( component.getParent() == null ) {
-// pSwingCanvas.getSwingWrapper().add( component );
- component.revalidate();
- }
-
- if( shouldRenderGreek( renderContext ) ) {
- paintAsGreek( g2 );
- }
- else {
- paint( g2 );
- }
-
- }
-
- protected boolean shouldRenderGreek( PPaintContext renderContext ) {
- return ( renderContext.getScale() < renderCutoff
-// && pSwingCanvas.getInteracting()
- ) ||
- minFontSize * renderContext.getScale() < 0.5;
- }
-
- /**
- * Paints the Swing component as greek.
- *
- * @param g2 The graphics used to render the filled rectangle
- */
- public void paintAsGreek( Graphics2D g2 ) {
- Color background = component.getBackground();
- Color foreground = component.getForeground();
- Rectangle2D rect = getBounds();
-
- if( background != null ) {
- g2.setColor( background );
- }
- g2.fill( rect );
-
- if( foreground != null ) {
- g2.setColor( foreground );
- }
- g2.draw( rect );
- }
-
- /**
- * Remove from the SwingWrapper; throws an exception if no canvas is associated with this PSwing.
- */
- public void removeFromSwingWrapper() {
- if( canvas != null && Arrays.asList( this.canvas.getSwingWrapper().getComponents() ).contains( component ) ) {
- this.canvas.getSwingWrapper().remove( component );
- }
- }
-
- /**
- * Renders to a buffered image, then draws that image to the
- * drawing surface associated with g2 (usually the screen).
- *
- * @param g2 graphics context for rendering the JComponent
- */
- public void paint( Graphics2D g2 ) {
- if( component.getBounds().isEmpty() ) {
- // The component has not been initialized yet.
- return;
- }
-
- PSwingRepaintManager manager = (PSwingRepaintManager)RepaintManager.currentManager( component );
- manager.lockRepaint( component );
-
- Graphics2D bufferedGraphics = null;
- if( !isBufferValid() ) {
- // Get the graphics context associated with a new buffered image.
- // Use TYPE_INT_ARGB_PRE so that transparent components look good on Windows.
- buffer = new BufferedImage( component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE );
- bufferedGraphics = buffer.createGraphics();
- }
- else {
- // Use the graphics context associated with the existing buffered image
- bufferedGraphics = buffer.createGraphics();
- // Clear the buffered image to prevent artifacts on Macintosh
- bufferedGraphics.setBackground( BUFFER_BACKGROUND_COLOR );
- bufferedGraphics.clearRect( 0, 0, component.getWidth(), component.getHeight() );
- }
-
- // Start with the rendering hints from the provided graphics context
- bufferedGraphics.setRenderingHints( g2.getRenderingHints() );
-
- //PSwing sometimes causes JComponent text to render with "..." when fractional font metrics are enabled. These are now always disabled for the offscreen buffer.
- bufferedGraphics.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF );
-
- // Draw the component to the buffer
- component.paint( bufferedGraphics );
-
- // Draw the buffer to g2's associated drawing surface
- g2.drawRenderedImage( buffer, IDENTITY_TRANSFORM );
-
- manager.unlockRepaint( component );
- }
-
- /**
- * Tells whether the buffer for the image of the Swing components
- * is currently valid.
- *
- * @return true if the buffer is currently valid
- */
- private boolean isBufferValid() {
- return !( buffer == null || buffer.getWidth() != component.getWidth() || buffer.getHeight() != component.getHeight() );
- }
-
- /**
- * Repaints the specified portion of this visual component
- * Note that the input parameter may be modified as a result of this call.
- *
- * @param repaintBounds
- */
- public void repaint( PBounds repaintBounds ) {
- Shape sh = getTransform().createTransformedShape( repaintBounds );
- TEMP_REPAINT_BOUNDS2.setRect( sh.getBounds2D() );
- repaintFrom( TEMP_REPAINT_BOUNDS2, this );
- }
-
- /**
- * Sets the Swing component's bounds to its preferred bounds
- * unless it already is set to its preferred size. Also
- * updates the visual components copy of these bounds
- */
- public void computeBounds() {
- reshape();
-// if( !component.getBounds().isEmpty() ) {
-// Dimension d = component.getPreferredSize();
-// getBoundsReference().setRect( 0, 0, d.getWidth(), d.getHeight() );
-// if( !component.getSize().equals( d ) ) {
-// component.setBounds( 0, 0, (int)d.getWidth(), (int)d.getHeight() );
-// }
-// }
- }
-
- /**
- * Returns the Swing component that this visual component wraps
- *
- * @return The Swing component that this visual component wraps
- */
- public JComponent getComponent() {
- return component;
- }
-
- /**
- * We need to turn off double buffering of Swing components within
- * Piccolo since all components contained within a native container
- * use the same buffer for double buffering. With normal Swing
- * widgets this is fine, but for Swing components within Piccolo this
- * causes problems. This function recurses the component tree
- * rooted at c, and turns off any double buffering in use. It also
- * updates the minimum font size based on the font size of c and adds
- * a property change listener to listen for changes to the font.
- *
- * @param c The Component to be recursively unDoubleBuffered
- */
- void init( Component c ) {
- Component[] children = null;
- if( c instanceof Container ) {
- children = ( (Container)c ).getComponents();
- }
-
- if( c.getFont() != null ) {
- minFontSize = Math.min( minFontSize, c.getFont().getSize() );
- }
-
- if( children != null ) {
- for( int j = 0; j < children.length; j++ ) {
- init( children[j] );
- }
- }
-
- if( c instanceof JComponent ) {
- ( (JComponent)c ).setDoubleBuffered( false );
- c.addPropertyChangeListener( "font", this );
- c.addComponentListener( new ComponentAdapter() {
- public void componentResized( ComponentEvent e ) {
- computeBounds();
- }
-
- public void componentShown( ComponentEvent e ) {
- computeBounds();
- }
- } );
- }
- }
-
- /**
- * Listens for changes in font on components rooted at this PSwing
- */
- public void propertyChange( PropertyChangeEvent evt ) {
- if( component.isAncestorOf( (Component)evt.getSource() ) &&
- ( (Component)evt.getSource() ).getFont() != null ) {
- minFontSize = Math.min( minFontSize, ( (Component)evt.getSource() ).getFont().getSize() );
- }
- }
-
- private void readObject( ObjectInputStream in ) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- init( component );
- }
-
- ////////////////////////////////////////////////////////////
- ///////Start methods for automatic canvas detection
- ////////////////////////////////////////////////////////////
- /**
- * Attaches a listener to the specified node and all its parents to listen
- * for a change in the PSwingCanvas. Only PROPERTY_PARENT listeners are added
- * so this code wouldn't handle if a PLayer were viewed by a different PCamera
- * since that constitutes a child change.
- * @param node The child node at which to begin a parent-based traversal for adding listeners.
- */
- private void listenForCanvas( PNode node ) {
- //need to get the full tree for this node
- PNode p = node;
- while( p != null ) {
- listenToNode( p );
-
- PNode parent = p;
-// System.out.println( "parent = " + parent.getClass() );
- if( parent instanceof PLayer ) {
- PLayer player = (PLayer)parent;
-// System.out.println( "Found player: with " + player.getCameraCount() + " cameras" );
- for( int i = 0; i < player.getCameraCount(); i++ ) {
- PCamera cam = player.getCamera( i );
- if( cam.getComponent() instanceof PSwingCanvas ) {
- updateCanvas( (PSwingCanvas)cam.getComponent() );
- break;
- }
- }
- }
- p = p.getParent();
- }
- }
-
- /**
- * Attach a listener to the specified node, if one has not already been attached.
- * @param node the node to listen to for parent/pcamera/pcanvas changes
- */
- private void listenToNode( PNode node ) {
-// System.out.println( "listeningTo.size() = " + listeningTo.size() );
- if( !listeningTo( node ) ) {
- listeningTo.add( node );
- node.addPropertyChangeListener( PNode.PROPERTY_PARENT, parentListener );
- }
- }
-
- /**
- * Determine whether this PSwing is already listening to the specified node for camera/canvas changes.
- * @param node the node to check
- * @return true if this PSwing is already listening to the specified node for camera/canvas changes
- */
- private boolean listeningTo( PNode node ) {
- for( int i = 0; i < listeningTo.size(); i++ ) {
- PNode pNode = (PNode)listeningTo.get( i );
- if( pNode == node ) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Removes this PSwing from previous PSwingCanvas (if any), and ensure that this PSwing is attached to the new PSwingCanvas.
- * @param newCanvas the new PSwingCanvas (may be null)
- */
- private void updateCanvas( PSwingCanvas newCanvas ) {
- if( newCanvas != canvas ) {
- if( canvas != null ) {
- canvas.removePSwing( this );
- }
- if( newCanvas != null ) {
- canvas = newCanvas;
- canvas.addPSwing( this );
- reshape();
- repaint();
- canvas.invalidate();
- canvas.revalidate();
- canvas.repaint();
- }
- }
- }
- ////////////////////////////////////////////////////////////
- ///////End methods for automatic canvas detection
- ////////////////////////////////////////////////////////////
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java
deleted file mode 100755
index 6d35498..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright 2003-2005, University of Colorado */
-
-/*
- * CVS Info -
- * Filename : $Source$
- * Branch : $Name$
- * Modified by : $Author: samreid $
- * Revision : $Revision: 13998 $
- * Date modified : $Date: 2007-03-22 17:51:34 -0600 (Thu, 22 Mar 2007) $
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.PCanvas;
-
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * The PSwingCanvas is a PCanvas that can display Swing components with the PSwing adapter.
- *
- * @author Benjamin B. Bederson
- * @author Sam R. Reid
- * @author Lance E. Good
- */
-
-public class PSwingCanvas extends PCanvas {
- /**
- *
- */
- private static final long serialVersionUID = 7715640353133096920L;
- public static final String SWING_WRAPPER_KEY = "Swing Wrapper";
- private static PSwingRepaintManager pSwingRepaintManager = new PSwingRepaintManager();
-
- private SwingWrapper swingWrapper;
- private PSwingEventHandler swingEventHandler;
-
- /**
- * Construct a new PSwingCanvas.
- */
- public PSwingCanvas() {
- swingWrapper = new SwingWrapper( this );
- add( swingWrapper );
- RepaintManager.setCurrentManager( pSwingRepaintManager );
- pSwingRepaintManager.addPSwingCanvas( this );
-
- swingEventHandler = new PSwingEventHandler( this, getCamera() );//todo or maybe getCameraLayer() or getRoot()?
- swingEventHandler.setActive( true );
- }
-
- JComponent getSwingWrapper() {
- return swingWrapper;
- }
-
- public void addPSwing( PSwing pSwing ) {
- swingWrapper.add( pSwing.getComponent() );
- }
-
- public void removePSwing( PSwing pSwing ) {
- swingWrapper.remove( pSwing.getComponent() );
- }
-
- private static class SwingWrapper extends JComponent {
- /**
- *
- */
- private static final long serialVersionUID = 3859942401645713762L;
- private PSwingCanvas pSwingCanvas;
-
- public SwingWrapper( PSwingCanvas pSwingCanvas ) {
- this.pSwingCanvas = pSwingCanvas;
- setSize( new Dimension( 0, 0 ) );
- setPreferredSize( new Dimension( 0, 0 ) );
- putClientProperty( SWING_WRAPPER_KEY, SWING_WRAPPER_KEY );
- }
-
- public PSwingCanvas getpSwingCanvas() {
- return pSwingCanvas;
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
deleted file mode 100755
index ee777c9..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/**
- * Copyright (C) 1998-2000 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.InputEvent;
-import java.awt.event.MouseEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Point2D;
-
-/**
- * Event handler to send MousePressed, MouseReleased, MouseMoved,
- * MouseClicked, and MouseDragged events on Swing components within
- * a PCanvas.
- *
- * @author Ben Bederson
- * @author Lance Good
- * @author Sam Reid
- */
-public class PSwingEventHandler implements PInputEventListener {
-
- private PNode listenNode = null; //used to listen to for events
- private boolean active = false; //True when event handlers are set active.
-
- // The previous component - used to generate mouseEntered and
- // mouseExited events
- private Component prevComponent = null;
-
- // Previous points used in generating mouseEntered and mouseExited events
- private Point2D prevPoint = null;
- private Point2D prevOff = null;
-
- private boolean recursing = false;//to avoid accidental recursive handling
-
- private ButtonData leftButtonData = new ButtonData();
- private ButtonData rightButtonData = new ButtonData();
- private ButtonData middleButtonData = new ButtonData();
-
- private PSwingCanvas canvas;
-
- /**
- * Constructs a new PSwingEventHandler for the given canvas,
- * and a node that will recieve the mouse events.
- *
- * @param canvas the canvas associated with this PSwingEventHandler.
- * @param node the node the mouse listeners will be attached to.
- */
- public PSwingEventHandler( PSwingCanvas canvas, PNode node ) {
- this.canvas = canvas;
- listenNode = node;
- }
-
- /**
- * Constructs a new PSwingEventHandler for the given canvas.
- */
- public PSwingEventHandler( PSwingCanvas canvas ) {
- this.canvas = canvas;
- }
-
- /**
- * Sets whether this event handler can fire events.
- *
- * @param active
- */
- void setActive( boolean active ) {
- if( this.active && !active ) {
- if( listenNode != null ) {
- this.active = false;
- listenNode.removeInputEventListener( this );
- }
- }
- else if( !this.active && active ) {
- if( listenNode != null ) {
- this.active = true;
- listenNode.addInputEventListener( this );
- }
- }
- }
-
- /**
- * Determines if this event handler is active.
- *
- * @return True if active
- */
- public boolean isActive() {
- return active;
- }
-
- /**
- * Finds the component at the specified location (must be showing).
- *
- * @param c
- * @param x
- * @param y
- * @return the component at the specified location.
- */
- private Component findShowingComponentAt( Component c, int x, int y ) {
- if( !c.contains( x, y ) ) {
- return null;
- }
-
- if( c instanceof Container ) {
- Container contain = ( (Container)c );
- int ncomponents = contain.getComponentCount();
- Component component[] = contain.getComponents();
-
- for( int i = 0; i < ncomponents; i++ ) {
- Component comp = component[i];
- if( comp != null ) {
- Point p = comp.getLocation();
- if( comp instanceof Container ) {
- comp = findShowingComponentAt( comp, x - (int)p.getX(), y - (int)p.getY() );
- }
- else {
- comp = comp.getComponentAt( x - (int)p.getX(), y - (int)p.getY() );
- }
- if( comp != null && comp.isShowing() ) {
- return comp;
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Determines if any Swing components in Piccolo
- * should receive the given MouseEvent and
- * forwards the event to that component.
- * However, mouseEntered and mouseExited are independent of the buttons.
- * Also, notice the notes on mouseEntered and mouseExited.
- *
- * @param pSwingMouseEvent
- * @param aEvent
- */
- void dispatchEvent( PSwingMouseEvent pSwingMouseEvent, PInputEvent aEvent ) {
- Component comp = null;
- Point2D pt = null;
- PNode pickedNode = pSwingMouseEvent.getPath().getPickedNode();
-
- // The offsets to put the event in the correct context
- int offX = 0;
- int offY = 0;
-
- PNode currentNode = pSwingMouseEvent.getCurrentNode();
-
- if( currentNode instanceof PSwing ) {
-
- PSwing swing = (PSwing)currentNode;
- PNode grabNode = pickedNode;
-
- if( grabNode.isDescendentOf( canvas.getRoot() ) ) {
- pt = new Point2D.Double( pSwingMouseEvent.getX(), pSwingMouseEvent.getY() );
- cameraToLocal( pSwingMouseEvent.getPath().getTopCamera(), pt, grabNode );
- prevPoint = new Point2D.Double( pt.getX(), pt.getY() );
-
- // This is only partially fixed to find the deepest
- // component at pt. It needs to do something like
- // package private method:
- // Container.getMouseEventTarget(int,int,boolean)
- comp = findShowingComponentAt( swing.getComponent(), (int)pt.getX(), (int)pt.getY() );
-
- // We found the right component - but we need to
- // get the offset to put the event in the component's
- // coordinates
- if( comp != null && comp != swing.getComponent() ) {
- for( Component c = comp; c != swing.getComponent(); c = c.getParent() ) {
- offX += c.getLocation().getX();
- offY += c.getLocation().getY();
- }
- }
-
- // Mouse Pressed gives focus - effects Mouse Drags and
- // Mouse Releases
- if( comp != null && pSwingMouseEvent.getID() == MouseEvent.MOUSE_PRESSED ) {
- if( SwingUtilities.isLeftMouseButton( pSwingMouseEvent ) ) {
- leftButtonData.setState( swing, pickedNode, comp, offX, offY );
- }
- else if( SwingUtilities.isMiddleMouseButton( pSwingMouseEvent ) ) {
- middleButtonData.setState( swing, pickedNode, comp, offX, offY );
- }
- else if( SwingUtilities.isRightMouseButton( pSwingMouseEvent ) ) {
- rightButtonData.setState( swing, pickedNode, comp, offX, offY );
- }
- }
- }
- }
-
- // This first case we don't want to give events to just
- // any Swing component - but to the one that got the
- // original mousePressed
- if( pSwingMouseEvent.getID() == MouseEvent.MOUSE_DRAGGED ||
- pSwingMouseEvent.getID() == MouseEvent.MOUSE_RELEASED ) {
-
- // LEFT MOUSE BUTTON
- if( SwingUtilities.isLeftMouseButton( pSwingMouseEvent ) && leftButtonData.getFocusedComponent() != null ) {
- handleButton( pSwingMouseEvent, aEvent, leftButtonData );
- }
-
- // MIDDLE MOUSE BUTTON
- if( SwingUtilities.isMiddleMouseButton( pSwingMouseEvent ) && middleButtonData.getFocusedComponent() != null )
- {
- handleButton( pSwingMouseEvent, aEvent, middleButtonData );
- }
-
- // RIGHT MOUSE BUTTON
- if( SwingUtilities.isRightMouseButton( pSwingMouseEvent ) && rightButtonData.getFocusedComponent() != null )
- {
- handleButton( pSwingMouseEvent, aEvent, rightButtonData );
- }
- }
- // This case covers the cases mousePressed, mouseClicked,
- // and mouseMoved events
- else if( ( pSwingMouseEvent.getID() == MouseEvent.MOUSE_PRESSED ||
- pSwingMouseEvent.getID() == MouseEvent.MOUSE_CLICKED ||
- pSwingMouseEvent.getID() == MouseEvent.MOUSE_MOVED ) &&
- ( comp != null ) ) {
-
- MouseEvent e_temp = new MouseEvent( comp,
- pSwingMouseEvent.getID(),
- pSwingMouseEvent.getWhen(),
- pSwingMouseEvent.getModifiers(),
- (int)pt.getX() - offX,
- (int)pt.getY() - offY,
- pSwingMouseEvent.getClickCount(),
- pSwingMouseEvent.isPopupTrigger() );
-
- PSwingMouseEvent e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
- dispatchEvent( comp, e2 );
- pSwingMouseEvent.consume();
- }
-
- // Now we need to check if an exit or enter event needs to
- // be dispatched - this code is independent of the mouseButtons.
- // I tested in normal Swing to see the correct behavior.
- if( prevComponent != null ) {
- // This means mouseExited
-
- // This shouldn't happen - since we're only getting node events
- if( comp == null || pSwingMouseEvent.getID() == MouseEvent.MOUSE_EXITED ) {
- MouseEvent e_temp = createExitEvent( pSwingMouseEvent );
-
- PSwingMouseEvent e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
-
- dispatchEvent( prevComponent, e2 );
- prevComponent = null;
-
- if( pSwingMouseEvent.getID() == MouseEvent.MOUSE_EXITED ) {
- pSwingMouseEvent.consume();
- }
- }
-
- // This means mouseExited prevComponent and mouseEntered comp
- else if( prevComponent != comp ) {
- MouseEvent e_temp = createExitEvent( pSwingMouseEvent );
- PSwingMouseEvent e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
- dispatchEvent( prevComponent, e2 );
-
- e_temp = createEnterEvent( comp, pSwingMouseEvent, offX, offY );
- e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
- comp.dispatchEvent( e2 );
- }
- }
- else {
- // This means mouseEntered
- if( comp != null ) {
- MouseEvent e_temp = createEnterEvent( comp, pSwingMouseEvent, offX, offY );
- PSwingMouseEvent e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
- dispatchEvent( comp, e2 );
- }
- }
-
- //todo add cursors
-// // We have to manager our own Cursors since this is normally
-// // done on the native side
-// if( comp != cursorComponent &&
-// focusNodeLeft == null &&
-// focusNodeMiddle == null &&
-// focusNodeRight == null ) {
-// if( comp != null ) {
-// cursorComponent = comp;
-// canvas.setCursor( comp.getCursor(), false );
-// }
-// else {
-// cursorComponent = null;
-// canvas.resetCursor();
-// }
-// }
-
- // Set the previous variables for next time
- prevComponent = comp;
-
- if( comp != null ) {
- prevOff = new Point2D.Double( offX, offY );
- }
- }
-
- private MouseEvent createEnterEvent( Component comp, PSwingMouseEvent e1, int offX, int offY ) {
- return new MouseEvent( comp, MouseEvent.MOUSE_ENTERED,
- e1.getWhen(), 0,
- (int)prevPoint.getX() - offX, (int)prevPoint.getY() - offY,
- e1.getClickCount(), e1.isPopupTrigger() );
- }
-
- private MouseEvent createExitEvent( PSwingMouseEvent e1 ) {
- return new MouseEvent( prevComponent, MouseEvent.MOUSE_EXITED,
- e1.getWhen(), 0,
- (int)prevPoint.getX() - (int)prevOff.getX(), (int)prevPoint.getY() - (int)prevOff.getY(),
- e1.getClickCount(), e1.isPopupTrigger() );
- }
-
- private void handleButton( PSwingMouseEvent e1, PInputEvent aEvent, ButtonData buttonData ) {
- Point2D pt;
- if( buttonData.getPNode().isDescendentOf( canvas.getRoot() ) ) {
- pt = new Point2D.Double( e1.getX(), e1.getY() );
- cameraToLocal( e1.getPath().getTopCamera(), pt, buttonData.getPNode() );
- //todo this probably won't handle viewing through multiple cameras.
- MouseEvent e_temp = new MouseEvent( buttonData.getFocusedComponent(),
- e1.getID(), e1.getWhen(), e1.getModifiers(),
- (int)pt.getX() - buttonData.getOffsetX(),
- (int)pt.getY() - buttonData.getOffsetY(),
- e1.getClickCount(), e1.isPopupTrigger() );
-
- PSwingMouseEvent e2 = PSwingMouseEvent.createMouseEvent( e_temp.getID(), e_temp, aEvent );
- dispatchEvent( buttonData.getFocusedComponent(), e2 );
- }
- else {
- dispatchEvent( buttonData.getFocusedComponent(), e1 );
- }
- //buttonData.getPSwing().repaint(); //Experiment with SliderExample (from Martin) suggests this line is unnecessary, and a serious problem in performance.
- e1.consume();
- if( e1.getID() == MouseEvent.MOUSE_RELEASED ) {
- buttonData.mouseReleased();
- }
- }
-
- private void dispatchEvent( final Component target, final PSwingMouseEvent event ) {
- SwingUtilities.invokeLater( new Runnable() {
- public void run() {
- target.dispatchEvent( event );
- }
- } );
- }
-
- private void cameraToLocal( PCamera topCamera, Point2D pt, PNode node ) {
- AffineTransform inverse = null;
- try {
- inverse = topCamera.getViewTransform().createInverse();
- }
- catch( NoninvertibleTransformException e ) {
- e.printStackTrace();
- }
-
- /* Only apply the camera's view transform when this node is a descendant of PLayer */
- PNode searchNode = node;
- do {
- searchNode = searchNode.getParent();
- if (searchNode instanceof PLayer) {
- inverse.transform( pt, pt );
- break;
- }
- } while(searchNode != null);
-
- if( node != null ) {
- node.globalToLocal( pt );
- }
- return;
- }
-
- /**
- * Process a piccolo event and (if active) dispatch the corresponding Swing event.
- *
- * @param aEvent
- * @param type
- */
- public void processEvent( PInputEvent aEvent, int type ) {
- if(aEvent.isMouseEvent()) {
- InputEvent sourceSwingEvent = aEvent.getSourceSwingEvent();
- if (sourceSwingEvent instanceof MouseEvent) {
- MouseEvent swingMouseEvent = (MouseEvent) sourceSwingEvent;
- PSwingMouseEvent pSwingMouseEvent = PSwingMouseEvent.createMouseEvent( swingMouseEvent.getID(), swingMouseEvent, aEvent );
- if( !recursing ) {
- recursing = true;
- dispatchEvent( pSwingMouseEvent, aEvent );
- recursing = false;
- }
- } else {
- new Exception("PInputEvent.getSourceSwingEvent was not a MouseEvent. Actual event: " + sourceSwingEvent + ", class=" + sourceSwingEvent.getClass().getName() ).printStackTrace();
- }
- }
-
-/* if( !( EventQueue.getCurrentEvent() instanceof MouseEvent ) ) {
- new Exception( "EventQueue.getCurrentEvent was not a MouseEvent, consider making PInputEvent.getSourceSwingEvent public. Actual event: " + EventQueue.getCurrentEvent() + ", class=" + EventQueue.getCurrentEvent().getClass().getName() ).printStackTrace();
- }
- if( aEvent.isMouseEvent() && EventQueue.getCurrentEvent() instanceof MouseEvent ) {
- MouseEvent sourceSwingEvent = (MouseEvent)EventQueue.getCurrentEvent();
- PSwingMouseEvent pSwingMouseEvent = PSwingMouseEvent.createMouseEvent( sourceSwingEvent.getID(), sourceSwingEvent, aEvent );
- if( !recursing ) {
- recursing = true;
- dispatchEvent( pSwingMouseEvent, aEvent );
- recursing = false;
- }
- }
-*/
- }
-
- /**
- * Internal Utility class for handling button interactivity.
- */
- private static class ButtonData {
- private PSwing focusPSwing = null;
- private PNode focusNode = null;
- private Component focusComponent = null;
- private int focusOffX = 0;
- private int focusOffY = 0;
-
- public void setState( PSwing swing, PNode visualNode, Component comp, int offX, int offY ) {
- focusPSwing = swing;
- focusComponent = comp;
- focusNode = visualNode;
- focusOffX = offX;
- focusOffY = offY;
- }
-
- public Component getFocusedComponent() {
- return focusComponent;
- }
-
- public PNode getPNode() {
- return focusNode;
- }
-
- public int getOffsetX() {
- return focusOffX;
- }
-
- public int getOffsetY() {
- return focusOffY;
- }
-
- public PSwing getPSwing() {
- return focusPSwing;
- }
-
- public void mouseReleased() {
- focusComponent = null;
- focusNode = null;
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java
deleted file mode 100755
index 6a60508..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * Copyright (C) 1998-2000 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-import java.awt.*;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.geom.Point2D;
-import java.io.Serializable;
-
-/**
- * PMouseEvent is an event which indicates that a mouse action occurred in a node.
- *
- * This low-level event is generated by a node object for:
- *
- * Mouse Events
- *
- * a mouse button is pressed
- * a mouse button is released
- * a mouse button is clicked (pressed and released)
- * the mouse cursor enters a node
- * the mouse cursor exits a node
- *
- *
- * A PMouseEvent object is passed to every PMouseListener
- * or PMouseAdapter
object which registered to receive
- * the "interesting" mouse events using the component's
- * addMouseListener
method.
- * (PMouseAdapter
objects implement the
- * PMouseListener
interface.) Each such listener object
- * gets a PMouseEvent
containing the mouse event.
- *
- * Warning: Serialized objects of this class will not be
- * compatible with future Piccolo releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Piccolo. A future release of Piccolo will provide support for long
- * term persistence.
- *
- * @author Benjamin B. Bederson
- * @author Sam R. Reid
- * @author Lance E. Good
- */
-public class PSwingMouseEvent extends MouseEvent implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 2755932380308414055L;
- private int id;
- private PInputEvent event;
-
- /**
- * Constructs a new PMouse event from a Java MouseEvent.
- *
- * @param id The event type (MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED, MOUSE_ENTERED, MOUSE_EXITED)
- * @param e The original Java mouse event
- * when in MOUSE_RELEASED events.
- */
- protected PSwingMouseEvent( int id, MouseEvent e, PInputEvent event ) {
- super( (Component)e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger() );
- this.id = id;
- this.event = event;
- }
-
- /**
- * Creates and returns a new PMouse event from a Java MouseEvent.
- *
- * @param id The event type (MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED, MOUSE_ENTERED, MOUSE_EXITED, MOUSE_MOVED, MOUSE_DRAGGED)
- * @param e The original Java mouse event
- * when in MOUSE_DRAGGED and MOUSE_RELEASED events.
- */
- public static PSwingMouseEvent createMouseEvent( int id,
- MouseEvent e,
- PInputEvent pEvent ) {
- if( id == PSwingMouseEvent.MOUSE_MOVED ||
- id == PSwingMouseEvent.MOUSE_DRAGGED ) {
- return new PSwingMouseMotionEvent( id, e, pEvent );
- }
- else {
- return new PSwingMouseEvent( id, e, pEvent );
- }
- }
-
- /**
- * Returns the x,y position of the event in the local coordinate system of the node
- * the event occurred on.
- *
- * @return a Point2D object containing the x and y coordinates local to the node.
- */
- public Point2D getLocalPoint() {
- return new Point2D.Double( getX(), getY() );
- }
-
- /**
- * Returns the horizontal x position of the event in the local coordinate system
- * of the node the event occurred on.
- *
- * @return x a double indicating horizontal position local to the node.
- */
- public double getLocalX() {
- return getLocalPoint().getX();
- }
-
- /**
- * Returns the vertical y position of the event in the local coordinate system
- * of the node the event occurred on.
- *
- * @return y a double indicating vertical position local to the node.
- */
- public double getLocalY() {
- return getLocalPoint().getY();
- }
-
- /**
- * Determine the event type.
- *
- * @return the id
- */
- public int getID() {
- return id;
- }
-
- /**
- * Determine the node the event originated at. If an event percolates
- * up the tree and is handled by an event listener higher up in the
- * tree than the original node that generated the event, this returns
- * the original node. For mouse drag and release events, this is the
- * node that the original matching press event went to - in other words,
- * the event is 'grabbed' by the originating node.
- *
- * @return the node
- */
- public PNode getNode() {
- return event.getPickedNode();
- }
-
- /**
- * Determine the path the event took from the PCanvas down to the visual component.
- *
- * @return the path
- */
- public PPickPath getPath() {
- return event.getPath();
- }
-
- /**
- * Determine the node the event originated at. If an event percolates
- * up the tree and is handled by an event listener higher up in the
- * tree than the original node that generated the event, this returns
- * the original node. For mouse drag and release events, this is the
- * node that the original matching press event went to - in other words,
- * the event is 'grabbed' by the originating node.
- *
- * @return the node
- */
- public PNode getGrabNode() {
- return event.getPickedNode();
- }
-
- /**
- * Return the path from the PCanvas down to the currently grabbed object.
- *
- * @return the path
- */
- public PPickPath getGrabPath() {
- return getPath();
- }
-
- /**
- * Get the current node that is under the cursor. This may return a different result then getGrabNode() when
- * in a MOUSE_RELEASED or MOUSE_DRAGGED event.
- *
- * @return the current node.
- */
- public PNode getCurrentNode() {
- return event.getPickedNode();
- }
-
- /**
- * Get the path from the PCanvas down to the visual component currently under the mouse.This may
- * give a different result then getGrabPath() durring a MOUSE_DRAGGED or MOUSE_RELEASED operation.
- *
- * @return the current path.
- */
- public PPickPath getCurrentPath() {
- return getPath();
- }
-
- /**
- * Calls appropriate method on the listener based on this events ID.
- *
- * @param listener the MouseListener or MouseMotionListener to dispatch to.
- */
- public void dispatchTo( Object listener ) {
- if( listener instanceof MouseListener ) {
- MouseListener mouseListener = (MouseListener)listener;
- switch( getID() ) {
- case PSwingMouseEvent.MOUSE_CLICKED:
- mouseListener.mouseClicked( this );
- break;
- case PSwingMouseEvent.MOUSE_ENTERED:
- mouseListener.mouseEntered( this );
- break;
- case PSwingMouseEvent.MOUSE_EXITED:
- mouseListener.mouseExited( this );
- break;
- case PSwingMouseEvent.MOUSE_PRESSED:
- mouseListener.mousePressed( this );
- break;
- case PSwingMouseEvent.MOUSE_RELEASED:
- mouseListener.mouseReleased( this );
- break;
- default:
- throw new RuntimeException( "PMouseEvent with bad ID" );
- }
- }
- else {
- MouseMotionListener mouseMotionListener = (MouseMotionListener)listener;
- switch( getID() ) {
- case PSwingMouseEvent.MOUSE_DRAGGED:
- mouseMotionListener.mouseDragged( this );
- break;
- case PSwingMouseEvent.MOUSE_MOVED:
- mouseMotionListener.mouseMoved( this );
- break;
- default:
- throw new RuntimeException( "PMouseMotionEvent with bad ID" );
- }
- }
- }
-
- /**
- * Set the souce of this event. As the event is fired up the tree the source of the
- * event will keep changing to reflect the scenegraph object that is firing the event.
- *
- * @param aSource
- */
- public void setSource( Object aSource ) {
- source = aSource;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java
deleted file mode 100755
index 9b74531..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Copyright (C) 1998-2000 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.event.PInputEvent;
-
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionListener;
-
-/**
- * PMouseMotionEvent is an event which indicates that a mouse motion action occurred in a node.
- *
- * This low-level event is generated by a node object for:
- *
- * Mouse Motion Events
- *
- * the mouse is moved
- * the mouse is dragged
- *
- *
- *
- * A PMouseEvent object is passed to every PMouseMotionListener
- * or PMouseMotionAdapter
object which registered to receive
- * mouse motion events using the component's addMouseMotionListener
- * method. (PMouseMotionAdapter
objects implement the
- * PMouseMotionListener
interface.) Each such listener object
- * gets a PMouseEvent
containing the mouse motion event.
- *
- *
- * Warning: Serialized objects of this class will not be
- * compatible with future Piccolo releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Piccolo. A future release of Piccolo will provide support for long
- * term persistence.
- *
- * @author Benjamin B. Bederson
- * @author Sam R. Reid
- * @author Lance E. Good
- */
-public class PSwingMouseMotionEvent extends PSwingMouseEvent {
-
- /**
- *
- */
- private static final long serialVersionUID = 9218542961494015103L;
-
- /**
- * Constructs a new PMouse event from a Java MouseEvent.
- *
- * @param id The event type (MOUSE_MOVED, MOUSE_DRAGGED)
- * @param e The original Java mouse event
- * when in MOUSE_DRAGGED events.
- */
- protected PSwingMouseMotionEvent( int id, MouseEvent e, PInputEvent event ) {
- super( id, e, event );
- }
-
- /**
- * Calls appropriate method on the listener based on this events ID.
- *
- * @param listener the target for dispatch.
- */
- public void dispatchTo( Object listener ) {
- MouseMotionListener mouseMotionListener = (MouseMotionListener)listener;
- switch( getID() ) {
- case PSwingMouseEvent.MOUSE_DRAGGED:
- mouseMotionListener.mouseDragged( this );
- break;
- case PSwingMouseEvent.MOUSE_MOVED:
- mouseMotionListener.mouseMoved( this );
- break;
- default:
- throw new RuntimeException( "PMouseMotionEvent with bad ID" );
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java b/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java
deleted file mode 100755
index 03e5624..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/* Copyright 2003-2005, University of Colorado */
-
-/*
- * CVS Info -
- * Filename : $Source: /fs/cvs/piccolo/piccolo/extras/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java,v $
- * Branch : $Name: $
- * Modified by : $Author: jesse $
- * Revision : $Revision: 1.1 $
- * Date modified : $Date: 2006/01/05 16:54:26 $
- */
-package edu.umd.cs.piccolox.pswing;
-
-import edu.umd.cs.piccolo.util.PBounds;
-
-import javax.swing.*;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Vector;
-
-/**
- * This RepaintManager replaces the default Swing implementation, and
- * is used to intercept and repaint dirty regions of PSwing components.
- *
- * This is an internal class used by Piccolo to support Swing components
- * in Piccolo. This should not be instantiated, though all the public
- * methods of javax.swing.RepaintManager may still be called and
- * perform in the expected manner.
- *
- * PBasicRepaint Manager is an extension of RepaintManager that traps
- * those repaints called by the Swing components that have been added
- * to the PCanvas and passes these repaints to the
- * SwingVisualComponent rather than up the component hierarchy as
- * usually happens.
- *
- * Also traps revalidate calls made by the Swing components added
- * to the PCanvas to reshape the applicable Visual Component.
- *
- * Also keeps a list of PSwings that are painting. This
- * disables repaint until the component has finished painting. This is
- * to address a problem introduced by Swing's CellRendererPane which is
- * itself a work-around. The problem is that JTable's, JTree's, and
- * JList's cell renderers need to be validated before repaint. Since
- * we have to repaint the entire Swing component hierarchy (in the case
- * of a Swing component group used as a Piccolo visual component). This
- * causes an infinite loop. So we introduce the restriction that no
- * repaints can be triggered by a call to paint.
- *
- * @author Benjamin B. Bederson
- * @author Lance E. Good
- * @author Sam R. Reid
- */
-public class PSwingRepaintManager extends RepaintManager {
- private ArrayList swingWrappers = new ArrayList();
-
- // The components that are currently painting
- // This needs to be a vector for thread safety
- private Vector paintingComponents = new Vector();
-
- /**
- * Locks repaint for a particular (Swing) component displayed by
- * PCanvas
- *
- * @param c The component for which the repaint is to be locked
- */
- public void lockRepaint( JComponent c ) {
- paintingComponents.addElement( c );
- }
-
- /**
- * Unlocks repaint for a particular (Swing) component displayed by
- * PCanvas
- *
- * @param c The component for which the repaint is to be unlocked
- */
- public void unlockRepaint( JComponent c ) {
- synchronized( paintingComponents ) {
- paintingComponents.removeElementAt( paintingComponents.lastIndexOf( c ) );
- }
- }
-
- /**
- * Returns true if repaint is currently locked for a component and
- * false otherwise
- *
- * @param c The component for which the repaint status is desired
- * @return Whether the component is currently painting
- */
- public boolean isPainting( JComponent c ) {
- return paintingComponents.contains( c );
- }
-
- /**
- * This is the method "repaint" now calls in the Swing components.
- * Overridden to capture repaint calls from those Swing components
- * which are being used as Piccolo visual components and to call the Piccolo
- * repaint mechanism rather than the traditional Component hierarchy
- * repaint mechanism. Otherwise, behaves like the superclass.
- *
- * @param c Component to be repainted
- * @param x X coordinate of the dirty region in the component
- * @param y Y coordinate of the dirty region in the component
- * @param w Width of the dirty region in the component
- * @param h Height of the dirty region in the component
- */
- public synchronized void addDirtyRegion( JComponent c, int x, int y, final int w, final int h ) {
-// System.out.println( "PSwingCanvas$PBasicRepaintManager.addDirtyRegion, c="+c.getClass()+", rect=["+x+", "+y+", "+w+", " +", "+h+"], c="+c);
- boolean captureRepaint = false;
- JComponent capturedComponent = null;
- int captureX = x, captureY = y;
-
- // We have to check to see if the PCanvas
- // (ie. the SwingWrapper) is in the components ancestry. If so,
- // we will want to capture that repaint. However, we also will
- // need to translate the repaint request since the component may
- // be offset inside another component.
- for( Component comp = c; comp != null && comp.isLightweight() && !captureRepaint; comp = comp.getParent() ) {
- if( swingWrappers.contains( comp.getParent() ) ) {
- if( comp instanceof JComponent ) {
- captureRepaint = true;
- capturedComponent = (JComponent)comp;
- }
- }
- else {
- // Adds to the offset since the component is nested
- captureX += comp.getLocation().getX();
- captureY += comp.getLocation().getY();
- }
- }
-
- // Now we check to see if we should capture the repaint and act
- // accordingly
- if( captureRepaint ) {
- if( !isPainting( capturedComponent ) ) {
- final PSwing vis = (PSwing)capturedComponent.getClientProperty( PSwing.PSWING_PROPERTY );
- if( vis != null ) {
- final int repaintX = captureX;
- final int repaintY = captureY;
- Runnable repainter = new Runnable() {
- public void run() {
- vis.repaint( new PBounds( (double)repaintX, (double)repaintY, (double)w, (double)h ) );
- }
- };
- SwingUtilities.invokeLater( repainter );
- }
- }
- }
- else {
- super.addDirtyRegion( c, x, y, w, h );
- }
- }
-
- /**
- * This is the method "revalidate" calls in the Swing components.
- * Overridden to capture revalidate calls from those Swing components
- * being used as Piccolo visual components and to update Piccolo's visual
- * component wrapper bounds (these are stored separately from the
- * Swing component). Otherwise, behaves like the superclass.
- *
- * @param invalidComponent The Swing component that needs validation
- */
- public synchronized void addInvalidComponent( JComponent invalidComponent ) {
- final JComponent capturedComponent = invalidComponent;
-
- if( capturedComponent.getParent() != null &&
- capturedComponent.getParent() instanceof JComponent &&
- ( (JComponent)capturedComponent.getParent() ).getClientProperty( PSwingCanvas.SWING_WRAPPER_KEY ) != null )
- {
-
- Runnable validater = new Runnable() {
- public void run() {
- capturedComponent.validate();
- PSwing swing = (PSwing)capturedComponent.getClientProperty( PSwing.PSWING_PROPERTY );
- swing.reshape();
- }
- };
- SwingUtilities.invokeLater( validater );
- }
- else {
- super.addInvalidComponent( invalidComponent );
- }
- }
-
- void addPSwingCanvas( PSwingCanvas swingWrapper ) {
- swingWrappers.add( swingWrapper.getSwingWrapper() );
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/readme.txt b/src/main/java/edu/umd/cs/piccolox/pswing/readme.txt
deleted file mode 100755
index 3bdb2fa..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/readme.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-This directory contains source and examples for embedding Swing components in a Piccolo hierarchy. This code was ported from a Jazz implementation.
-
-Example usage:
-
- JSlider js = new JSlider( 0, 100 );
- PSwing pSwing = new PSwing( pswingCanvas, js );
- l.addChild( pSwing );
-
-Known Issues
-o Handling cursors on Swing components is not yet supported.
-o Creation of a PSwing currently requires an instance of the PSwingCanvas in which the component will appear. Future versions could delete this requirement, so that the constructor is simply PSwing(JComponent), and the PSwing can appear in many PSwingCanvases.
-
-This code has been tested in a variety of situations by 4 or 5 independent users, but with more users, some bugs will be most likely be exposed. (This code comes with NO WARRANTY, etc.)
-
-Sam Reid
-reids@colorado.edu
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/pswing/tests/TestPSwing.java b/src/main/java/edu/umd/cs/piccolox/pswing/tests/TestPSwing.java
deleted file mode 100755
index ae0fa4a..0000000
--- a/src/main/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/src/main/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java b/src/main/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java
deleted file mode 100755
index a31cb16..0000000
--- a/src/main/java/edu/umd/cs/piccolox/pswing/tests/TestPSwingFull.java
+++ /dev/null
@@ -1,440 +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 {
- /**
- *
- */
- private static final long serialVersionUID = 4529210389081684327L;
-
- 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!" ) {
-
- /**
- *
- */
- private static final long serialVersionUID = -998980341187242055L;
-
- public void actionPerformed( ActionEvent e ) {
- }
- };
-
- Action hand = new AbstractAction( "Hi!" ) {
- /**
- *
- */
- private static final long serialVersionUID = 1268083650658523689L;
-
- public void actionPerformed( ActionEvent e ) {
- }
- };
- Action select = new AbstractAction( "There!" ) {
- /**
- *
- */
- private static final long serialVersionUID = 8741388750734409436L;
-
- 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 {
- /**
- *
- */
- private static final long serialVersionUID = 3074746647968002463L;
-
- public ZVisualLeaf( PNode node ) {
- addChild( node );
- }
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java b/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java
deleted file mode 100755
index 50588ba..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Created on Mar 4, 2005
- */
-package edu.umd.cs.piccolox.swing;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolox.nodes.PCacheCamera;
-
-/**
- * An extension of PCanvas that automatically installs a PCacheCamera
- * @author Lance Good
- */
-public class PCacheCanvas extends PCanvas {
- /**
- *
- */
- private static final long serialVersionUID = -7072328989941869712L;
-
- protected PCamera createDefaultCamera() {
- PRoot r = new PRoot();
- PLayer l = new PLayer();
- PCamera c = new PCacheCamera();
-
- r.addChild(c);
- r.addChild(l);
- c.addLayer(l);
-
- return c;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java b/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
deleted file mode 100755
index 072f12c..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swing;
-
-import java.awt.Dimension;
-import java.awt.Point;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.swing.JScrollPane;
-
-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.PRoot;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * The default scroll director implementation. This default implementation
- * follows the widely accepted model of scrolling - namely the scrollbars
- * control the movement of the window over the document rather than the movement
- * of the document under the window.
- *
- * @author Lance Good
- */
-public class PDefaultScrollDirector implements PScrollDirector, PropertyChangeListener {
-
- /**
- * The viewport that signals this scroll director
- */
- protected PViewport viewPort;
-
- /**
- * The scrollpane that contains the viewport
- */
- protected PScrollPane scrollPane;
-
- /**
- * The canvas that this class directs
- */
- protected PCanvas view;
-
- /**
- * The canvas' camera
- */
- protected PCamera camera;
-
- /**
- * The canvas' root
- */
- protected PRoot root;
-
- /**
- * Flag to indicate when scrolling is currently in progress
- */
- protected boolean scrollInProgress = false;
-
- /**
- * The default constructor
- */
- public PDefaultScrollDirector() {
- }
-
- /**
- * Installs the scroll director and adds the appropriate listeners
- * @param viewPort The viewport on which this director directs
- * @param view The ZCanvas that the viewport looks at
- */
- public void install(PViewport viewPort, final PCanvas view) {
- this.scrollPane = (PScrollPane) viewPort.getParent();
- this.viewPort = viewPort;
- this.view = view;
-
- if (view != null) {
- this.camera = view.getCamera();
- this.root = view.getRoot();
- }
-
- if (camera != null) {
- camera.addPropertyChangeListener(this);
- }
- if (root != null) {
- root.addPropertyChangeListener(this);
- }
-
- if (scrollPane != null) {
- scrollPane.revalidate();
- }
- }
-
- /**
- * Uninstall the scroll director from the viewport
- */
- public void unInstall() {
- viewPort = null;
- view = null;
-
- if (camera != null) {
- camera.removePropertyChangeListener(this);
- }
- if (root != null) {
- root.removePropertyChangeListener(this);
- }
-
- camera = null;
- root = null;
- }
-
- /**
- * Get the View position given the specified camera bounds
- * @param viewBounds The bounds for which the view position will be computed
- * @return The view position
- */
- public Point getViewPosition(Rectangle2D viewBounds) {
- Point pos = new Point();
- if (camera != null) {
- // First we compute the union of all the layers
- PBounds layerBounds = new PBounds();
- List layers = camera.getLayersReference();
- for(Iterator i=layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer)i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- camera.viewToLocal(layerBounds);
- layerBounds.add(viewBounds);
-
- pos.setLocation((int) (viewBounds.getX() - layerBounds.getX() + 0.5), (int) (viewBounds.getY() - layerBounds.getY() + 0.5));
- }
-
- return pos;
- }
-
- /**
- * Get the size of the view based on the specified camera bounds
- * @param viewBounds The view bounds for which the view size will be computed
- * @return The view size
- */
- public Dimension getViewSize(Rectangle2D viewBounds) {
- Dimension size = new Dimension();
- if (camera != null) {
- // First we compute the union of all the layers
- PBounds bounds = new PBounds();
- List layers = camera.getLayersReference();
- for(Iterator i=layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer)i.next();
- bounds.add(layer.getFullBoundsReference());
- }
-
- // Then we put the bounds into camera coordinates and
- // union the camera bounds
- if (!bounds.isEmpty()) {
- camera.viewToLocal(bounds);
- }
- bounds.add(viewBounds);
-
- size.setSize((int) (bounds.getWidth() + 0.5), (int) (bounds.getHeight() + 0.5));
- }
-
- return size;
- }
-
- /**
- * Set the view position in a manner consistent with standardized scrolling
- * @param x The new x position
- * @param y The new y position
- */
- public void setViewPosition(double x, double y) {
- if (camera != null) {
- // If a scroll is in progress - we ignore new scrolls -
- // if we didn't, since the scrollbars depend on the camera location
- // we can end up with an infinite loop
- if (!scrollInProgress) {
- scrollInProgress = true;
-
- // Get the union of all the layers' bounds
- PBounds layerBounds = new PBounds();
- List layers = camera.getLayersReference();
- for(Iterator i=layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer)i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- PAffineTransform at = camera.getViewTransform();
- at.transform(layerBounds,layerBounds);
-
- // Union the camera bounds
- PBounds viewBounds = camera.getBoundsReference();
- layerBounds.add(viewBounds);
-
- // Now find the new view position in view coordinates
- Point2D newPoint = new Point2D.Double(layerBounds.getX() + x, layerBounds.getY() + y);
-
- // Now transform the new view position into global coords
- camera.localToView(newPoint);
-
- // Compute the new matrix values to put the camera at the
- // correct location
- double newX = - (at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
- double newY = - (at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
-
- at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
-
- // Now actually set the camera's transform
- camera.setViewTransform(at);
- scrollInProgress = false;
- }
- }
- }
-
- /**
- * Invoked when the camera's view changes, or the bounds of the root or camera changes
- */
- public void propertyChange(PropertyChangeEvent pce) {
- boolean isRelevantViewEvent = (PCamera.PROPERTY_VIEW_TRANSFORM == pce.getPropertyName());
- boolean isRelevantBoundsEvent = (PNode.PROPERTY_BOUNDS == pce.getPropertyName() || PNode.PROPERTY_FULL_BOUNDS == pce.getPropertyName()) && (pce.getSource() == camera || pce.getSource() == view.getRoot());
- if (isRelevantViewEvent || isRelevantBoundsEvent) {
- if (shouldRevalidateScrollPane()) {
- scrollPane.revalidate();
- }
- else {
- viewPort.fireStateChanged();
- }
- }
- }
-
- /**
- * Should the ScrollPane be revalidated. This occurs when either the
- * scrollbars are showing and should be remove or are not showing and should
- * be added.
- *
- * @return Whether the scroll pane should be revalidated
- */
- public boolean shouldRevalidateScrollPane() {
- if (camera != null) {
- if (scrollPane.getHorizontalScrollBarPolicy() != JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
- && scrollPane.getVerticalScrollBarPolicy() != JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED) {
- return false;
- }
-
- // Get the union of all the layers' bounds
- PBounds layerBounds = new PBounds();
- List layers = camera.getLayersReference();
- for(Iterator i=layers.iterator(); i.hasNext();) {
- PLayer layer = (PLayer)i.next();
- layerBounds.add(layer.getFullBoundsReference());
- }
-
- // Put into camera coordinates
- camera.viewToLocal(layerBounds);
-
- // And union with the camera bounds
- PBounds cameraBounds = camera.getBoundsReference();
- layerBounds.add(cameraBounds);
-
- // Truncate these to ints before comparing since
- // that's what the ScrollPane uses
- int layerWidth = (int) (layerBounds.getWidth() + 0.5);
- int layerHeight = (int) (layerBounds.getHeight() + 0.5);
- int cameraWidth = (int) (cameraBounds.getWidth() + 0.5);
- int cameraHeight = (int) (cameraBounds.getHeight() + 0.5);
-
- if ((scrollPane.getHorizontalScrollBar().isShowing() && layerWidth <= cameraWidth)
- || (!scrollPane.getHorizontalScrollBar().isShowing() && layerWidth > cameraWidth)
- || (scrollPane.getVerticalScrollBar().isShowing() && layerHeight <= cameraHeight)
- || (!scrollPane.getVerticalScrollBar().isShowing() && layerHeight > cameraHeight)) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java b/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java
deleted file mode 100755
index 87c4f03..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swing;
-
-import java.awt.*;
-import java.awt.geom.*;
-
-import edu.umd.cs.piccolo.PCanvas;
-
-/**
- * The interface an application can implement to control scrolling in a
- * PScrollPane->PViewport->ZCanvas component hierarchy.
- * @see PDefaultScrollDirector
- * @author Lance Good
- */
-public interface PScrollDirector {
-
- /**
- * Installs the scroll director
- * @param viewport The viewport on which this director directs
- * @param view The ZCanvas that the viewport looks at
- */
- public void install(PViewport viewport, PCanvas view);
-
- /**
- * Uninstall the scroll director
- */
- public void unInstall();
-
- /**
- * Get the View position given the specified camera bounds
- * @param viewBounds The bounds for which the view position will be computed
- * @return The view position
- */
- public Point getViewPosition(Rectangle2D viewBounds);
-
-
- /**
- * Set the view position
- * @param x The new x position
- * @param y The new y position
- */
- public void setViewPosition(double x, double y);
-
- /**
- * Get the size of the view based on the specified camera bounds
- * @param viewBounds The view bounds for which the view size will be computed
- * @return The view size
- */
- public Dimension getViewSize(Rectangle2D viewBounds);
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java b/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java
deleted file mode 100755
index 6a82f32..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swing;
-
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.JScrollPane;
-import javax.swing.JViewport;
-import javax.swing.Scrollable;
-import javax.swing.SwingConstants;
-import javax.swing.plaf.ScrollPaneUI;
-
-/**
- * A simple extension to a standard scroll pane that uses the jazz version
- * of the viewport by default. Also uses the jazz version of ScrollPaneLayout
- *
- * @author Lance Good
- */
-public class PScrollPane extends JScrollPane {
-
- /**
- *
- */
- private static final long serialVersionUID = -341190578603764154L;
-
- // A reusable null action
- protected PNullAction nullAction = null;
-
- // Are key actions disabled on this component?
- protected boolean disableKeyActions = false;
-
- /**
- * Pass on the constructor info to the super
- */
- public PScrollPane(Component view, int vsbPolicy, int hsbPolicy) {
- super(view, vsbPolicy, hsbPolicy);
-
- // Set the layout and sync it with the scroll pane
- PScrollPaneLayout layout = new PScrollPaneLayout.UIResource();
- setLayout(layout);
- layout.syncWithScrollPane(this);
- }
-
- /**
- * Pass on the constructor info to the super
- */
- public PScrollPane(Component view) {
- this(view, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
- }
-
- /**
- * Pass on the constructor info to the super
- */
- public PScrollPane(int vsbPolicy, int hsbPolicy) {
- this(null, vsbPolicy, hsbPolicy);
- }
-
- /**
- * Pass on the constructor info to the super
- */
- public PScrollPane() {
- this(null, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
- }
-
- /**
- * Disable or enable key actions on this PScrollPane
- * @param disable true disables key actions, false enables key actions
- */
- public void setKeyActionsDisabled(boolean disable) {
- if (disable && this.disableKeyActions != disable) {
- this.disableKeyActions = disable;
- disableKeyActions();
- }
- else if (!disable && this.disableKeyActions != disable) {
- this.disableKeyActions = disable;
- installCustomKeyActions();
- }
- }
-
- /**
- * Sets the UI
- */
- public void setUI(ScrollPaneUI ui) {
- super.setUI(ui);
-
- if (!disableKeyActions) {
- installCustomKeyActions();
- }
- else {
- disableKeyActions();
- }
- }
-
- /**
- * Install custom key actions (in place of the Swing defaults) to
- * correctly scroll the view
- */
- protected void installCustomKeyActions() {
- ActionMap map = getActionMap();
-
- map.put("scrollUp", new PScrollAction("scrollUp", SwingConstants.VERTICAL, -1, true));
- map.put("scrollDown", new PScrollAction("scrollDown", SwingConstants.VERTICAL, 1, true));
- map.put("scrollLeft", new PScrollAction("scrollLeft", SwingConstants.HORIZONTAL, -1, true));
-
- map.put("scrollRight", new PScrollAction("ScrollRight", SwingConstants.HORIZONTAL, 1, true));
- map.put("unitScrollRight", new PScrollAction("UnitScrollRight", SwingConstants.HORIZONTAL, 1, false));
- map.put("unitScrollLeft", new PScrollAction("UnitScrollLeft", SwingConstants.HORIZONTAL, -1, false));
- map.put("unitScrollUp", new PScrollAction("UnitScrollUp", SwingConstants.VERTICAL, -1, false));
- map.put("unitScrollDown", new PScrollAction("UnitScrollDown", SwingConstants.VERTICAL, 1, false));
-
- map.put("scrollEnd", new PScrollEndAction("ScrollEnd"));
- map.put("scrollHome", new PScrollHomeAction("ScrollHome"));
- }
-
- /**
- * Disables key actions on this PScrollPane
- */
- protected void disableKeyActions() {
- ActionMap map = getActionMap();
-
- if (nullAction == null) {
- nullAction = new PNullAction();
- }
-
- map.put("scrollUp", nullAction);
- map.put("scrollDown", nullAction);
- map.put("scrollLeft", nullAction);
- map.put("scrollRight", nullAction);
- map.put("unitScrollRight", nullAction);
- map.put("unitScrollLeft", nullAction);
- map.put("unitScrollUp", nullAction);
- map.put("unitScrollDown", nullAction);
- map.put("scrollEnd", nullAction);
- map.put("scrollHome", nullAction);
- }
-
- /**
- * Overridden to create the Jazz viewport
- * @return The jazz version of the viewport
- */
- protected JViewport createViewport() {
- return new PViewport();
- }
-
- /**
- * Action to scroll left/right/up/down.
- * Modified from javax.swing.plaf.basic.BasicScrollPaneUI.ScrollAction
- *
- * Gets the view parameters (position and size) from the Viewport
- * rather than directly from the view - also only performs its actions
- * when the relevant scrollbar is visible
- */
- protected static class PScrollAction extends AbstractAction {
- /**
- *
- */
- private static final long serialVersionUID = -1498806394922227134L;
- /** Direction to scroll. */
- protected int orientation;
- /** 1 indicates scroll down, -1 up. */
- protected int direction;
- /** True indicates a block scroll, otherwise a unit scroll. */
- private boolean block;
-
- protected PScrollAction(String name, int orientation, int direction, boolean block) {
- super(name);
- this.orientation = orientation;
- this.direction = direction;
- this.block = block;
- }
-
- public void actionPerformed(ActionEvent e) {
- JScrollPane scrollpane = (JScrollPane) e.getSource();
- // LEG: Modification to only perform these actions if the relevant
- // scrollbar is actually showing
- if ((orientation == SwingConstants.VERTICAL && scrollpane.getVerticalScrollBar().isShowing())
- || (orientation == SwingConstants.HORIZONTAL && scrollpane.getHorizontalScrollBar().isShowing())) {
-
- JViewport vp = scrollpane.getViewport();
- Component view;
- if (vp != null && (view = vp.getView()) != null) {
- Rectangle visRect = vp.getViewRect();
- // LEG: Modification to query the viewport for the
- // view size rather than going directly to the view
- Dimension vSize = vp.getViewSize();
- int amount;
-
- if (view instanceof Scrollable) {
- if (block) {
- amount = ((Scrollable) view).getScrollableBlockIncrement(visRect, orientation, direction);
- }
- else {
- amount = ((Scrollable) view).getScrollableUnitIncrement(visRect, orientation, direction);
- }
- }
- else {
- if (block) {
- if (orientation == SwingConstants.VERTICAL) {
- amount = visRect.height;
- }
- else {
- amount = visRect.width;
- }
- }
- else {
- amount = 10;
- }
- }
- if (orientation == SwingConstants.VERTICAL) {
- visRect.y += (amount * direction);
- if ((visRect.y + visRect.height) > vSize.height) {
- visRect.y = Math.max(0, vSize.height - visRect.height);
- }
- else if (visRect.y < 0) {
- visRect.y = 0;
- }
- }
- else {
- visRect.x += (amount * direction);
- if ((visRect.x + visRect.width) > vSize.width) {
- visRect.x = Math.max(0, vSize.width - visRect.width);
- }
- else if (visRect.x < 0) {
- visRect.x = 0;
- }
- }
- vp.setViewPosition(visRect.getLocation());
- }
- }
- }
- }
-
- /**
- * Action to scroll to x,y location of 0,0.
- * Modified from javax.swing.plaf.basic.BasicScrollPaneUI.ScrollEndAction
- *
- * Only performs the event if a scrollbar is visible
- */
- private static class PScrollHomeAction extends AbstractAction {
- /**
- *
- */
- private static final long serialVersionUID = -1017251042643719141L;
-
- protected PScrollHomeAction(String name) {
- super(name);
- }
-
- public void actionPerformed(ActionEvent e) {
- JScrollPane scrollpane = (JScrollPane) e.getSource();
- // LEG: Modification to only perform these actions if one of the
- // scrollbars is actually showing
- if (scrollpane.getVerticalScrollBar().isShowing() || scrollpane.getHorizontalScrollBar().isShowing()) {
- JViewport vp = scrollpane.getViewport();
- if (vp != null && vp.getView() != null) {
- vp.setViewPosition(new Point(0, 0));
- }
- }
- }
- }
-
- /**
- * Action to scroll to last visible location.
- * Modified from javax.swing.plaf.basic.BasicScrollPaneUI.ScrollEndAction
- *
- * Gets the view size from the viewport rather than directly from the view
- * - also only performs the event if a scrollbar is visible
- */
- protected static class PScrollEndAction extends AbstractAction {
- /**
- *
- */
- private static final long serialVersionUID = 3606507213816114575L;
-
- protected PScrollEndAction(String name) {
- super(name);
- }
-
- public void actionPerformed(ActionEvent e) {
- JScrollPane scrollpane = (JScrollPane) e.getSource();
- // LEG: Modification to only perform these actions if one of the
- // scrollbars is actually showing
- if (scrollpane.getVerticalScrollBar().isShowing() || scrollpane.getHorizontalScrollBar().isShowing()) {
-
- JViewport vp = scrollpane.getViewport();
- if (vp != null && vp.getView() != null) {
-
- Rectangle visRect = vp.getViewRect();
- // LEG: Modification to query the viewport for the
- // view size rather than going directly to the view
- Dimension size = vp.getViewSize();
- vp.setViewPosition(new Point(size.width - visRect.width, size.height - visRect.height));
- }
- }
- }
- }
-
- /**
- * An action to do nothing - put into an action map to keep it
- * from looking to its parent
- */
- protected static class PNullAction extends AbstractAction {
- /**
- *
- */
- private static final long serialVersionUID = -2419361551219425859L;
-
- public void actionPerformed(ActionEvent e) {
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java b/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java
deleted file mode 100755
index ac4c9c3..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swing;
-
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Insets;
-import java.awt.Rectangle;
-
-import javax.swing.JScrollPane;
-import javax.swing.ScrollPaneLayout;
-import javax.swing.border.Border;
-
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * A subclass of ScrollPaneLayout that looks at the Viewport for sizing
- * information rather than View. Also queries the Viewport for sizing
- * information after each decision about scrollbar visiblity
- *
- * @author Lance Good
- */
-public class PScrollPaneLayout extends ScrollPaneLayout {
-
- /**
- *
- */
- private static final long serialVersionUID = 7969497208454898728L;
-
- /**
- * MODIFIED FROM javax.swing.ScrollPaneLayout.layoutContainer
- *
- * This is largely the same as ScrollPaneLayout.layoutContainer but
- * obtains the preferred view size from the viewport rather than directly
- * from the view so the viewport can get the preferred size from the
- * PScrollDirector
- * @param parent the Container to lay out
- */
- public void layoutContainer(Container parent) {
- /* Sync the (now obsolete) policy fields with the
- * JScrollPane.
- */
- JScrollPane scrollPane = (JScrollPane) parent;
- vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
- hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
-
- Rectangle availR = scrollPane.getBounds();
- availR.x = availR.y = 0;
-
- Insets insets = parent.getInsets();
- availR.x = insets.left;
- availR.y = insets.top;
- availR.width -= insets.left + insets.right;
- availR.height -= insets.top + insets.bottom;
-
- /* Get the scrollPane's orientation.
- */
- boolean leftToRight = scrollPane.getComponentOrientation().isLeftToRight();
-
- /* If there's a visible column header remove the space it
- * needs from the top of availR. The column header is treated
- * as if it were fixed height, arbitrary width.
- */
-
- Rectangle colHeadR = new Rectangle(0, availR.y, 0, 0);
-
- if ((colHead != null) && (colHead.isVisible())) {
- int colHeadHeight = colHead.getPreferredSize().height;
- colHeadR.height = colHeadHeight;
- availR.y += colHeadHeight;
- availR.height -= colHeadHeight;
- }
-
- /* If there's a visible row header remove the space it needs
- * from the left or right of availR. The row header is treated
- * as if it were fixed width, arbitrary height.
- */
-
- Rectangle rowHeadR = new Rectangle(0, 0, 0, 0);
-
- if ((rowHead != null) && (rowHead.isVisible())) {
- int rowHeadWidth = rowHead.getPreferredSize().width;
- rowHeadR.width = rowHeadWidth;
- availR.width -= rowHeadWidth;
- if (leftToRight) {
- rowHeadR.x = availR.x;
- availR.x += rowHeadWidth;
- }
- else {
- rowHeadR.x = availR.x + availR.width;
- }
- }
-
- /* If there's a JScrollPane.viewportBorder, remove the
- * space it occupies for availR.
- */
-
- Border viewportBorder = scrollPane.getViewportBorder();
- Insets vpbInsets;
- if (viewportBorder != null) {
- vpbInsets = viewportBorder.getBorderInsets(parent);
- availR.x += vpbInsets.left;
- availR.y += vpbInsets.top;
- availR.width -= vpbInsets.left + vpbInsets.right;
- availR.height -= vpbInsets.top + vpbInsets.bottom;
- }
- else {
- vpbInsets = new Insets(0, 0, 0, 0);
- }
-
- /* At this point availR is the space available for the viewport
- * and scrollbars. rowHeadR is correct except for its height and y
- * and colHeadR is correct except for its width and x. Once we're
- * through computing the dimensions of these three parts we can
- * go back and set the dimensions of rowHeadR.height, rowHeadR.y,
- * colHeadR.width, colHeadR.x and the bounds for the corners.
- *
- * We'll decide about putting up scrollbars by comparing the
- * viewport views preferred size with the viewports extent
- * size (generally just its size). Using the preferredSize is
- * reasonable because layout proceeds top down - so we expect
- * the viewport to be layed out next. And we assume that the
- * viewports layout manager will give the view it's preferred
- * size.
- */
-
- Dimension extentSize = (viewport != null) ? viewport.toViewCoordinates(availR.getSize()) : new Dimension(0, 0);
-
- PBounds cameraBounds = new PBounds(0, 0, extentSize.getWidth(), extentSize.getHeight());
-
- // LEG: Modification to ask the viewport for the view size rather
- // than asking the view directly
- Dimension viewPrefSize = (viewport != null) ? ((PViewport) viewport).getViewSize(cameraBounds) : new Dimension(0, 0);
-
- /* If there's a vertical scrollbar and we need one, allocate
- * space for it (we'll make it visible later). A vertical
- * scrollbar is considered to be fixed width, arbitrary height.
- */
-
- Rectangle vsbR = new Rectangle(0, availR.y - vpbInsets.top, 0, 0);
-
- boolean vsbNeeded;
- if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
- vsbNeeded = true;
- }
- else if (vsbPolicy == VERTICAL_SCROLLBAR_NEVER) {
- vsbNeeded = false;
- }
- else { // vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
-
- vsbNeeded = (viewPrefSize.height > extentSize.height);
- }
-
- if ((vsb != null) && vsbNeeded) {
- adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
- extentSize = viewport.toViewCoordinates(availR.getSize());
-
- // LEG: Modification because the view's preferred size needs to
- // be recomputed because the extent may have changed
- cameraBounds.setRect(0, 0, extentSize.getWidth(), extentSize.getHeight());
- viewPrefSize = ((PViewport) viewport).getViewSize(cameraBounds);
- }
-
- /* If there's a horizontal scrollbar and we need one, allocate
- * space for it (we'll make it visible later). A horizontal
- * scrollbar is considered to be fixed height, arbitrary width.
- */
-
- Rectangle hsbR = new Rectangle(availR.x - vpbInsets.left, 0, 0, 0);
- boolean hsbNeeded;
- if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
- hsbNeeded = true;
- }
- else if (hsbPolicy == HORIZONTAL_SCROLLBAR_NEVER) {
- hsbNeeded = false;
- }
- else { // hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
- hsbNeeded = (viewPrefSize.width > extentSize.width);
- }
-
- if ((hsb != null) && hsbNeeded) {
- adjustForHSB(true, availR, hsbR, vpbInsets);
-
- /* If we added the horizontal scrollbar then we've implicitly
- * reduced the vertical space available to the viewport.
- * As a consequence we may have to add the vertical scrollbar,
- * if that hasn't been done so already. Ofcourse we
- * don't bother with any of this if the vsbPolicy is NEVER.
- */
-
- if ((vsb != null) && !vsbNeeded && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
-
- extentSize = viewport.toViewCoordinates(availR.getSize());
-
- // LEG: Modification because the view's preferred size needs to
- // be recomputed because the extent may have changed
- cameraBounds.setRect(0, 0, extentSize.getWidth(), extentSize.getHeight());
- viewPrefSize = ((PViewport) viewport).getViewSize(cameraBounds);
-
- vsbNeeded = viewPrefSize.height > extentSize.height;
-
- if (vsbNeeded) {
- adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
- }
- }
- }
-
- /* Set the size of the viewport first, and then recheck the Scrollable
- * methods. Some components base their return values for the Scrollable
- * methods on the size of the Viewport, so that if we don't
- * ask after resetting the bounds we may have gotten the wrong
- * answer.
- */
-
- if (viewport != null) {
- viewport.setBounds(availR);
- }
-
- /* We now have the final size of the viewport: availR.
- * Now fixup the header and scrollbar widths/heights.
- */
- vsbR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
- hsbR.width = availR.width + vpbInsets.left + vpbInsets.right;
- rowHeadR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
- rowHeadR.y = availR.y - vpbInsets.top;
- colHeadR.width = availR.width + vpbInsets.left + vpbInsets.right;
- colHeadR.x = availR.x - vpbInsets.left;
-
- /* Set the bounds of the remaining components. The scrollbars
- * are made invisible if they're not needed.
- */
-
- if (rowHead != null) {
- rowHead.setBounds(rowHeadR);
- }
-
- if (colHead != null) {
- colHead.setBounds(colHeadR);
- }
-
- if (vsb != null) {
- if (vsbNeeded) {
- vsb.setVisible(true);
- vsb.setBounds(vsbR);
- }
- else {
- vsb.setVisible(false);
- }
- }
-
- if (hsb != null) {
- if (hsbNeeded) {
- hsb.setVisible(true);
- hsb.setBounds(hsbR);
- }
- else {
- hsb.setVisible(false);
- }
- }
-
- if (lowerLeft != null) {
- lowerLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, hsbR.y, leftToRight ? rowHeadR.width : vsbR.width, hsbR.height);
- }
-
- if (lowerRight != null) {
- lowerRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, hsbR.y, leftToRight ? vsbR.width : rowHeadR.width, hsbR.height);
- }
-
- if (upperLeft != null) {
- upperLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, colHeadR.y, leftToRight ? rowHeadR.width : vsbR.width, colHeadR.height);
- }
-
- if (upperRight != null) {
- upperRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, colHeadR.y, leftToRight ? vsbR.width : rowHeadR.width, colHeadR.height);
- }
- }
-
- /**
- * Copied FROM javax.swing.ScrollPaneLayout.adjustForVSB
- *
- * This method is called from ScrollPaneLayout.layoutContainer and is
- * private in ScrollPaneLayout so it was copied here
- */
- protected void adjustForVSB(boolean wantsVSB, Rectangle available, Rectangle vsbR, Insets vpbInsets, boolean leftToRight) {
- int vsbWidth = vsb.getPreferredSize().width;
- if (wantsVSB) {
- available.width -= vsbWidth;
- vsbR.width = vsbWidth;
-
- if (leftToRight) {
- vsbR.x = available.x + available.width + vpbInsets.right;
- }
- else {
- vsbR.x = available.x - vpbInsets.left;
- available.x += vsbWidth;
- }
- }
- else {
- available.width += vsbWidth;
- }
- }
-
- /**
- * Copied FROM javax.swing.ScrollPaneLayout.adjustForHSB
- *
- * This method is called from ScrollPaneLayout.layoutContainer and is
- * private in ScrollPaneLayout so it was copied here
- */
- protected void adjustForHSB(boolean wantsHSB, Rectangle available, Rectangle hsbR, Insets vpbInsets) {
- int hsbHeight = hsb.getPreferredSize().height;
- if (wantsHSB) {
- available.height -= hsbHeight;
- hsbR.y = available.y + available.height + vpbInsets.bottom;
- hsbR.height = hsbHeight;
- }
- else {
- available.height += hsbHeight;
- }
- }
-
- /**
- * The UI resource version of PScrollPaneLayout. It isn't clear why
- * Swing does this in ScrollPaneLayout but we'll do it here too just
- * to be safe.
- */
- public static class UIResource extends PScrollPaneLayout implements javax.swing.plaf.UIResource {
-
- /**
- *
- */
- private static final long serialVersionUID = -3779861242960209738L;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java b/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java
deleted file mode 100755
index cf4214f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swing;
-
-import java.awt.*;
-import java.awt.geom.*;
-import javax.swing.*;
-
-import edu.umd.cs.piccolo.PCanvas;
-import edu.umd.cs.piccolo.util.PBounds;
-
-/**
- * A subclass of JViewport that talks to the scroll director to negotiate
- * the view positions and sizes.
- *
- * @author Lance Good
- */
-public class PViewport extends JViewport {
-
- /**
- *
- */
- private static final long serialVersionUID = -2019150420505046006L;
- /**
- * Controls what happens when scrolling occurs
- */
- PScrollDirector scrollDirector;
-
- /**
- * Pass constructor info to super
- */
- public PViewport() {
- super();
-
- setScrollDirector(createScrollDirector());
- }
-
- /**
- * Subclassers can override this to install a different
- * layout manager (or null
) in the constructor. Returns
- * a new ViewportLayout
object.
- *
- * @return a LayoutManager
- */
- protected LayoutManager createLayoutManager() {
- return new PViewportLayout();
- }
-
- /**
- * Subclassers can override this to install a different scroll director
- * in the constructor. Returns a new PScrollDirector
object.
- * @return a PScrollDirector
- */
- protected PScrollDirector createScrollDirector() {
- return new PDefaultScrollDirector();
- }
-
- /**
- * Set the scroll director on this viewport
- * @param scrollDirector The new scroll director
- */
- public void setScrollDirector(PScrollDirector scrollDirector) {
- if (this.scrollDirector != null) {
- this.scrollDirector.unInstall();
- }
- this.scrollDirector = scrollDirector;
- if (scrollDirector != null) {
- this.scrollDirector.install(this, (PCanvas) getView());
- }
- }
-
- /**
- * @return The scroll director on this viewport
- */
- public PScrollDirector getScrollDirector() {
- return scrollDirector;
- }
-
- /**
- * Overridden to throw an exception if the view is not a ZCanvas
- * @param view The new view - it better be a ZCanvas!
- */
- public void setView(Component view) {
- if (!(view instanceof PCanvas)) {
- throw new UnsupportedOperationException("PViewport only supports ZCanvas");
- }
-
- super.setView(view);
-
- if (scrollDirector != null) {
- scrollDirector.install(this, (PCanvas) view);
- }
- }
-
- /**
- * Sets the view coordinates that appear in the upper left
- * hand corner of the viewport, does nothing if there's no view.
- *
- * @param p a Point
object giving the upper left coordinates
- */
- public void setViewPosition(Point p) {
- if (getView() == null) {
- return;
- }
-
- double oldX = 0, oldY = 0, x = p.x, y = p.y;
-
- Point2D vp = getViewPosition();
- if (vp != null) {
- oldX = vp.getX();
- oldY = vp.getY();
- }
-
- /**
- * Send the scroll director the exact view position and let it
- * interpret it as needed
- */
- double newX = x;
- double newY = y;
-
- if ((oldX != newX) || (oldY != newY)) {
- scrollUnderway = true;
-
- scrollDirector.setViewPosition(newX, newY);
-
- fireStateChanged();
- }
- }
-
- /**
- * Gets the view position from the scroll director based on the current
- * extent size
- * @return The new view position
- */
- public Point getViewPosition() {
- if (scrollDirector != null) {
- Dimension extent = getExtentSize();
- return scrollDirector.getViewPosition(new PBounds(0, 0, extent.getWidth(), extent.getHeight()));
- }
- else {
- return null;
- }
- }
-
- /**
- * Gets the view size from the scroll director based on the current
- * extent size
- * @return The new view size
- */
- public Dimension getViewSize() {
- Dimension extent = getExtentSize();
- return scrollDirector.getViewSize(new PBounds(0, 0, extent.getWidth(), extent.getHeight()));
- }
-
- /**
- * Gets the view size from the scroll director based on the specified
- * extent size
- * @param r The extent size from which the view is computed
- * @return The new view size
- */
- public Dimension getViewSize(Rectangle2D r) {
- return scrollDirector.getViewSize(r);
- }
-
- /**
- * Notifies all ChangeListeners
when the views
- * size, position, or the viewports extent size has changed.
- */
- public void fireStateChanged() {
- super.fireStateChanged();
- }
-
- /**
- * A simple layout manager to give the ZCanvas the same size as the
- * Viewport
- */
- public static class PViewportLayout extends ViewportLayout {
- /**
- *
- */
- private static final long serialVersionUID = -5221138131790082814L;
-
- /**
- * Called when the specified container needs to be laid out.
- *
- * @param parent the container to lay out
- */
- public void layoutContainer(Container parent) {
- JViewport vp = (JViewport) parent;
- Component view = vp.getView();
-
- if (view == null) {
- return;
- }
-
- Dimension extentSize = vp.getSize();
-
- vp.setViewSize(extentSize);
- }
-
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandle.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandle.java
deleted file mode 100755
index ee9e9c7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandle.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Cursor;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import javax.swing.SwingConstants;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolo.util.PPickPath;
-import edu.umd.cs.piccolox.util.PBoundsLocator;
-
-/**
- * PBoundsHandle a handle for resizing the bounds of another node. If a
- * bounds handle is dragged such that the other node's width or height becomes
- * negative then the each drag handle's locator assciated with that
- * other node is "flipped" so that they are attached to and dragging a different
- * corner of the nodes bounds.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PSWTBoundsHandle extends PSWTHandle {
-
- /**
- *
- */
- private static final long serialVersionUID = -174809422532014280L;
- private PBasicInputEventHandler handleCursorHandler;
-
- public static void addBoundsHandlesTo(PNode aNode) {
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createEastLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createWestLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthEastLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthWestLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthEastLocator(aNode)));
- aNode.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthWestLocator(aNode)));
- }
-
- public static void addStickyBoundsHandlesTo(PNode aNode, PCamera camera) {
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createEastLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createWestLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthEastLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createNorthWestLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthEastLocator(aNode)));
- camera.addChild(new PSWTBoundsHandle(PBoundsLocator.createSouthWestLocator(aNode)));
- }
-
- public static void removeBoundsHandlesFrom(PNode aNode) {
- ArrayList handles = new ArrayList();
-
- Iterator i = aNode.getChildrenIterator();
- while (i.hasNext()) {
- PNode each = (PNode) i.next();
- if (each instanceof PSWTBoundsHandle) {
- handles.add(each);
- }
- }
- aNode.removeChildren(handles);
- }
-
- public PSWTBoundsHandle(PBoundsLocator aLocator) {
- super(aLocator);
- }
-
- protected void installHandleEventHandlers() {
- super.installHandleEventHandlers();
- handleCursorHandler = new PBasicInputEventHandler() {
- boolean cursorPushed = false;
- public void mouseEntered(PInputEvent aEvent) {
- if (!cursorPushed) {
- aEvent.pushCursor(getCursorFor(((PBoundsLocator)getLocator()).getSide()));
- cursorPushed = true;
- }
- }
- public void mouseExited(PInputEvent aEvent) {
- PPickPath focus = aEvent.getInputManager().getMouseFocus();
- if (cursorPushed) {
- if (focus == null || focus.getPickedNode() != PSWTBoundsHandle.this) {
- aEvent.popCursor();
- cursorPushed = false;
- }
- }
- }
- public void mouseReleased(PInputEvent event) {
- if (cursorPushed) {
- event.popCursor();
- cursorPushed = false;
- }
- }
- };
- addInputEventListener(handleCursorHandler);
- }
-
- /**
- * Return the event handler that is responsible for setting the mouse
- * cursor when it enters/exits this handle.
- */
- public PBasicInputEventHandler getHandleCursorEventHandler() {
- return handleCursorHandler;
- }
-
- public void startHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
- l.getNode().startResizeBounds();
- }
-
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
-
- PNode n = l.getNode();
- PBounds b = n.getBounds();
-
- PNode parent = getParent();
- if (parent != n && parent instanceof PCamera) {
- ((PCamera)parent).localToView(aLocalDimension);
- }
-
- localToGlobal(aLocalDimension);
- n.globalToLocal(aLocalDimension);
-
- double dx = aLocalDimension.getWidth();
- double dy = aLocalDimension.getHeight();
-
- switch (l.getSide()) {
- case SwingConstants.NORTH:
- b.setRect(b.x, b.y + dy, b.width, b.height - dy);
- break;
-
- case SwingConstants.SOUTH:
- b.setRect(b.x, b.y, b.width, b.height + dy);
- break;
-
- case SwingConstants.EAST:
- b.setRect(b.x, b.y, b.width + dx, b.height);
- break;
-
- case SwingConstants.WEST:
- b.setRect(b.x + dx, b.y, b.width - dx, b.height);
- break;
-
- case SwingConstants.NORTH_WEST:
- b.setRect(b.x + dx, b.y + dy, b.width - dx, b.height - dy);
- break;
-
- case SwingConstants.SOUTH_WEST:
- b.setRect(b.x + dx, b.y, b.width - dx, b.height + dy);
- break;
-
- case SwingConstants.NORTH_EAST:
- b.setRect(b.x, b.y + dy, b.width + dx, b.height - dy);
- break;
-
- case SwingConstants.SOUTH_EAST:
- b.setRect(b.x, b.y, b.width + dx, b.height + dy);
- break;
- }
-
- boolean flipX = false;
- boolean flipY = false;
-
- if (b.width < 0) {
- flipX = true;
- b.width = -b.width;
- b.x -= b.width;
- }
-
- if (b.height < 0) {
- flipY = true;
- b.height = -b.height;
- b.y -= b.height;
- }
-
- if (flipX || flipY) {
- flipSiblingBoundsHandles(flipX, flipY);
- }
-
- n.setBounds(b);
- }
-
- public void endHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
- l.getNode().endResizeBounds();
- }
-
- public void flipSiblingBoundsHandles(boolean flipX, boolean flipY) {
- Iterator i = getParent().getChildrenIterator();
- while (i.hasNext()) {
- Object each = i.next();
- if (each instanceof PSWTBoundsHandle) {
- ((PSWTBoundsHandle)each).flipHandleIfNeeded(flipX, flipY);
- }
- }
- }
-
- public void flipHandleIfNeeded(boolean flipX, boolean flipY) {
- PBoundsLocator l = (PBoundsLocator) getLocator();
-
- if (flipX || flipY) {
- switch (l.getSide()) {
- case SwingConstants.NORTH: {
- if (flipY) {
- l.setSide(SwingConstants.SOUTH);
- }
- break;
- }
-
- case SwingConstants.SOUTH: {
- if (flipY) {
- l.setSide(SwingConstants.NORTH);
- }
- break;
- }
-
- case SwingConstants.EAST: {
- if (flipX) {
- l.setSide(SwingConstants.WEST);
- }
- break;
- }
-
- case SwingConstants.WEST: {
- if (flipX) {
- l.setSide(SwingConstants.EAST);
- }
- break;
- }
-
- case SwingConstants.NORTH_WEST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.SOUTH_EAST);
- } else if (flipX) {
- l.setSide(SwingConstants.NORTH_EAST);
- } else if (flipY) {
- l.setSide(SwingConstants.SOUTH_WEST);
- }
-
- break;
- }
-
- case SwingConstants.SOUTH_WEST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.NORTH_EAST);
- } else if (flipX) {
- l.setSide(SwingConstants.SOUTH_EAST);
- } else if (flipY) {
- l.setSide(SwingConstants.NORTH_WEST);
- }
- break;
- }
-
- case SwingConstants.NORTH_EAST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.SOUTH_WEST);
- } else if (flipX) {
- l.setSide(SwingConstants.NORTH_WEST);
- } else if (flipY) {
- l.setSide(SwingConstants.SOUTH_EAST);
- }
- break;
- }
-
- case SwingConstants.SOUTH_EAST: {
- if (flipX && flipY) {
- l.setSide(SwingConstants.NORTH_WEST);
- } else if (flipX) {
- l.setSide(SwingConstants.SOUTH_WEST);
- } else if (flipY) {
- l.setSide(SwingConstants.NORTH_EAST);
- }
- break;
- }
- }
- }
-
- // reset locator to update layout
- setLocator(l);
- }
-
- public Cursor getCursorFor(int side) {
- switch (side) {
- case SwingConstants.NORTH:
- return new Cursor(Cursor.N_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH:
- return new Cursor(Cursor.S_RESIZE_CURSOR);
-
- case SwingConstants.EAST:
- return new Cursor(Cursor.E_RESIZE_CURSOR);
-
- case SwingConstants.WEST:
- return new Cursor(Cursor.W_RESIZE_CURSOR);
-
- case SwingConstants.NORTH_WEST:
- return new Cursor(Cursor.NW_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH_WEST:
- return new Cursor(Cursor.SW_RESIZE_CURSOR);
-
- case SwingConstants.NORTH_EAST:
- return new Cursor(Cursor.NE_RESIZE_CURSOR);
-
- case SwingConstants.SOUTH_EAST:
- return new Cursor(Cursor.SE_RESIZE_CURSOR);
- }
- return null;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java
deleted file mode 100755
index db8fcd2..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java
+++ /dev/null
@@ -1,603 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.event.InputEvent;
-import java.awt.geom.Rectangle2D;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Composite;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PComponent;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PRoot;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-import edu.umd.cs.piccolo.event.PPanEventHandler;
-import edu.umd.cs.piccolo.event.PZoomEventHandler;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PStack;
-
-/**
- * PCanvas is a simple Swing component that can be used to embed
- * Piccolo into a Java Swing application. Canvas's view the Piccolo scene
- * graph through a camera. The canvas manages screen updates coming from
- * this camera, and forwards swing mouse and keyboard events to the camera.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PSWTCanvas extends Composite implements PComponent {
-
- public static PSWTCanvas CURRENT_CANVAS = null;
-
- private Image backBuffer;
- private boolean doubleBuffered = true;
-
- private PCamera camera;
- private PStack cursorStack;
- private Cursor curCursor;
- private int interacting;
- private int defaultRenderQuality;
- private int animatingRenderQuality;
- private int interactingRenderQuality;
- private PPanEventHandler panEventHandler;
- private PZoomEventHandler zoomEventHandler;
- private boolean paintingImmediately;
- private boolean animatingOnLastPaint;
-
- /**
- * Construct a canvas with the basic scene graph consisting of a
- * root, camera, and layer. Event handlers for zooming and panning
- * are automatically installed.
- */
- public PSWTCanvas(Composite parent, int style) {
- super(parent,style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
-
- CURRENT_CANVAS = this;
- cursorStack = new PStack();
- setCamera(createBasicSceneGraph());
- installInputSources();
- setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
- setAnimatingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- setInteractingRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
- panEventHandler = new PPanEventHandler();
- zoomEventHandler = new PZoomEventHandler();
- addInputEventListener(panEventHandler);
- addInputEventListener(zoomEventHandler);
-
- // Add a paint listener to call paint
- addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent pe) {
- paintComponent(pe.gc,pe.x,pe.y,pe.width,pe.height);
- }
- });
-
- // Keep track of the references so we can dispose of the Fonts and Colors
- SWTGraphics2D.incrementGCCount();
- addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent de) {
- getRoot().getActivityScheduler().removeAllActivities();
- SWTGraphics2D.decrementGCCount();
- }
- });
- }
-
- //****************************************************************
- // Basic - Methods for accessing common piccolo nodes.
- //****************************************************************
-
- /**
- * Get the pan event handler associated with this canvas. This event handler
- * is set up to get events from the camera associated with this canvas by
- * default.
- */
- public PPanEventHandler getPanEventHandler() {
- return panEventHandler;
- }
-
- /**
- * Get the zoom event handler associated with this canvas. This event handler
- * is set up to get events from the camera associated with this canvas by
- * default.
- */
- public PZoomEventHandler getZoomEventHandler() {
- return zoomEventHandler;
- }
-
- /**
- * Return the camera associated with this canvas. All input events from this canvas
- * go through this camera. And this is the camera that paints this canvas.
- */
- public PCamera getCamera() {
- return camera;
- }
-
- /**
- * Set the camera associated with this canvas. All input events from this canvas
- * go through this camera. And this is the camera that paints this canvas.
- */
- public void setCamera(PCamera newCamera) {
- if (camera != null) {
- camera.setComponent(null);
- }
-
- camera = newCamera;
-
- if (camera != null) {
- camera.setComponent(this);
-
- Rectangle swtRect = getBounds();
-
- camera.setBounds(new Rectangle2D.Double(swtRect.x,swtRect.y,swtRect.width,swtRect.height));
- }
- }
-
- /**
- * Return root for this canvas.
- */
- public PRoot getRoot() {
- return camera.getRoot();
- }
-
- /**
- * Return layer for this canvas.
- */
- public PLayer getLayer() {
- return camera.getLayer(0);
- }
-
- /**
- * Add an input listener to the camera associated with this canvas.
- */
- public void addInputEventListener(PInputEventListener listener) {
- getCamera().addInputEventListener(listener);
- }
-
- /**
- * Remove an input listener to the camera associated with this canvas.
- */
- public void removeInputEventListener(PInputEventListener listener) {
- getCamera().removeInputEventListener(listener);
- }
-
- public PCamera createBasicSceneGraph() {
- PRoot r = new PSWTRoot(this);
- PLayer l = new PLayer();
- PCamera c = new PCamera();
-
- r.addChild(c);
- r.addChild(l);
- c.addLayer(l);
-
- return c;
- }
-
- //****************************************************************
- // Painting
- //****************************************************************
-
- /**
- * Return true if this canvas has been marked as interacting. If so
- * the canvas will normally render at a lower quality that is faster.
- */
- public boolean getInteracting() {
- return interacting > 0;
- }
-
- /**
- * Return true if any activities that respond with true to the method
- * isAnimating were run in the last PRoot.processInputs() loop. This
- * values is used by this canvas to determine the render quality
- * to use for the next paint.
- */
- public boolean getAnimating() {
- return getRoot().getActivityScheduler().getAnimating();
- }
-
- /**
- * Set if this canvas is interacting. If so the canvas will normally
- * render at a lower quality that is faster.
- */
- public void setInteracting(boolean isInteracting) {
- if (isInteracting) {
- interacting++;
- } else {
- interacting--;
- }
-
- if (!getInteracting()) {
- repaint();
- }
- }
-
- /**
- * Get whether this canvas should use double buffering - the default is no double buffering
- */
- public boolean getDoubleBuffered() {
- return doubleBuffered;
- }
-
- /**
- * Set whether this canvas should use double buffering - the default is no double buffering
- */
- public void setDoubleBuffered(boolean dBuffered) {
- this.doubleBuffered = dBuffered;
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas.
- * The default value is PPaintContext.HIGH_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setDefaultRenderQuality(int requestedQuality) {
- defaultRenderQuality = requestedQuality;
- repaint();
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas
- * when it is animating. The default value is PPaintContext.LOW_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setAnimatingRenderQuality(int requestedQuality) {
- animatingRenderQuality = requestedQuality;
- repaint();
- }
-
- /**
- * Set the render quality that should be used when rendering this canvas
- * when it is interacting. The default value is PPaintContext.LOW_QUALITY_RENDERING.
- *
- * @param requestedQuality supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
- */
- public void setInteractingRenderQuality(int requestedQuality) {
- interactingRenderQuality = requestedQuality;
- repaint();
- }
-
- /**
- * Set the canvas cursor, and remember the previous cursor on the
- * cursor stack.
- */
- public void pushCursor(java.awt.Cursor cursor) {
- Cursor aCursor = null;
- if (cursor.getType() == java.awt.Cursor.N_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZEN);
- }
- else if (cursor.getType() == java.awt.Cursor.NE_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZENE);
- }
- else if (cursor.getType() == java.awt.Cursor.NW_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZENW);
- }
- else if (cursor.getType() == java.awt.Cursor.S_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZES);
- }
- else if (cursor.getType() == java.awt.Cursor.SE_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZESE);
- }
- else if (cursor.getType() == java.awt.Cursor.SW_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZESW);
- }
- else if (cursor.getType() == java.awt.Cursor.E_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZEE);
- }
- else if (cursor.getType() == java.awt.Cursor.W_RESIZE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZEW);
- }
- else if (cursor.getType() == java.awt.Cursor.TEXT_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_IBEAM);
- }
- else if (cursor.getType() == java.awt.Cursor.HAND_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_HAND);
- }
- else if (cursor.getType() == java.awt.Cursor.MOVE_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_SIZEALL);
- }
- else if (cursor.getType() == java.awt.Cursor.CROSSHAIR_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_CROSS);
- }
- else if (cursor.getType() == java.awt.Cursor.WAIT_CURSOR) {
- aCursor = new Cursor(this.getDisplay(),SWT.CURSOR_WAIT);
- }
-
- if (aCursor != null) {
- if (curCursor != null) {
- cursorStack.push(curCursor);
- }
- curCursor = aCursor;
- setCursor(aCursor);
- }
- }
-
- /**
- * Pop the cursor on top of the cursorStack and set it as the
- * canvas cursor.
- */
- public void popCursor() {
- if (curCursor != null) {
- // We must manually dispose of cursors under SWT
- curCursor.dispose();
- }
-
- if (!cursorStack.isEmpty()) {
- curCursor = (Cursor)cursorStack.pop();
- }
- else {
- curCursor = null;
- }
-
- // This sets the cursor back to default
- setCursor(curCursor);
- }
-
- //****************************************************************
- // Code to manage connection to Swing. There appears to be a bug in
- // swing where it will occasionally send to many mouse pressed or mouse
- // released events. Below we attempt to filter out those cases before
- // they get delivered to the Piccolo framework.
- //****************************************************************
-
- private boolean isButton1Pressed;
- private boolean isButton2Pressed;
- private boolean isButton3Pressed;
-
- /**
- * This method installs mouse and key listeners on the canvas that forward
- * those events to piccolo.
- */
- protected void installInputSources() {
- this.addMouseListener(new MouseListener() {
- public void mouseDown(MouseEvent me) {
- boolean shouldBalanceEvent = false;
-
- switch (me.button) {
- case 1:
- if (isButton1Pressed) {
- shouldBalanceEvent = true;
- }
- isButton1Pressed = true;
- break;
- case 2:
- if (isButton2Pressed) {
- shouldBalanceEvent = true;
- }
- isButton2Pressed = true;
- break;
- case 3:
- if (isButton3Pressed) {
- shouldBalanceEvent = true;
- }
- isButton3Pressed = true;
- break;
- }
-
- if (shouldBalanceEvent) {
- java.awt.event.MouseEvent balanceEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_RELEASED,1);
- sendInputEventToInputManager(balanceEvent, java.awt.event.MouseEvent.MOUSE_RELEASED);
- }
-
- java.awt.event.MouseEvent balanceEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_PRESSED,1);
- sendInputEventToInputManager(balanceEvent, java.awt.event.MouseEvent.MOUSE_PRESSED);
- }
-
- public void mouseUp(MouseEvent me) {
- boolean shouldBalanceEvent = false;
-
- switch (me.button) {
- case 1:
- if (!isButton1Pressed) {
- shouldBalanceEvent = true;
- }
- isButton1Pressed = false;
- break;
- case 2:
- if (!isButton2Pressed) {
- shouldBalanceEvent = true;
- }
- isButton2Pressed = false;
- break;
- case 3:
- if (!isButton3Pressed) {
- shouldBalanceEvent = true;
- }
- isButton3Pressed = false;
- break;
- }
-
- if (shouldBalanceEvent) {
- java.awt.event.MouseEvent balanceEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_PRESSED,1);
- sendInputEventToInputManager(balanceEvent, java.awt.event.MouseEvent.MOUSE_PRESSED);
- }
-
- java.awt.event.MouseEvent balanceEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_RELEASED,1);
- sendInputEventToInputManager(balanceEvent, java.awt.event.MouseEvent.MOUSE_RELEASED);
- }
-
- public void mouseDoubleClick(final MouseEvent me) {
- // This doesn't work with click event types for some reason - it has to do with how
- // the click and release events are ordered, I think
- java.awt.event.MouseEvent inputEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_PRESSED,2);
- sendInputEventToInputManager(inputEvent, java.awt.event.MouseEvent.MOUSE_PRESSED);
- inputEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_RELEASED,2);
- sendInputEventToInputManager(inputEvent, java.awt.event.MouseEvent.MOUSE_RELEASED);
- }
- });
-
- this.addMouseMoveListener(new MouseMoveListener() {
- public void mouseMove(MouseEvent me) {
- if (isButton1Pressed || isButton2Pressed || isButton3Pressed) {
- java.awt.event.MouseEvent inputEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_DRAGGED,1);
- sendInputEventToInputManager(inputEvent, java.awt.event.MouseEvent.MOUSE_DRAGGED);
- }
- else {
- java.awt.event.MouseEvent inputEvent = new PSWTMouseEvent(me,java.awt.event.MouseEvent.MOUSE_MOVED,1);
- sendInputEventToInputManager(inputEvent, java.awt.event.MouseEvent.MOUSE_MOVED);
- }
- }
- });
-
- this.addKeyListener(new KeyListener() {
- public void keyPressed(KeyEvent ke) {
- java.awt.event.KeyEvent inputEvent = new PSWTKeyEvent(ke,java.awt.event.KeyEvent.KEY_PRESSED);
- sendInputEventToInputManager(inputEvent, java.awt.event.KeyEvent.KEY_PRESSED);
- }
-
- public void keyReleased(KeyEvent ke) {
- java.awt.event.KeyEvent inputEvent = new PSWTKeyEvent(ke,java.awt.event.KeyEvent.KEY_RELEASED);
- sendInputEventToInputManager(inputEvent, java.awt.event.KeyEvent.KEY_RELEASED);
- }
- });
-
- }
-
- protected void sendInputEventToInputManager(InputEvent e, int type) {
- getRoot().getDefaultInputManager().processEventFromCamera(e, type, getCamera());
- }
-
- public void setBounds(int x, int y, final int w, final int h) {
- camera.setBounds(camera.getX(), camera.getY(), w, h);
-
- if (backBuffer == null || backBuffer.getBounds().width < w || backBuffer.getBounds().height < h) {
- backBuffer = new Image(getDisplay(),w,h);
- }
-
- super.setBounds(x, y, w, h);
- }
-
- public void repaint() {
- super.redraw();
- }
-
- public void repaint(PBounds bounds) {
- bounds.expandNearestIntegerDimensions();
- bounds.inset(-1, -1);
-
- redraw((int)bounds.x,
- (int)bounds.y,
- (int)bounds.width,
- (int)bounds.height,
- true);
- }
-
- public void paintComponent(GC gc, int x, int y, int w, int h) {
- PDebug.startProcessingOutput();
-
- GC imageGC = null;
- Graphics2D g2 = null;
- if (doubleBuffered) {
- imageGC = new GC(backBuffer);
- g2 = new SWTGraphics2D(imageGC,getDisplay());
- }
- else {
- g2 = new SWTGraphics2D(gc,getDisplay());
- }
-
- g2.setColor(Color.white);
- g2.setBackground(Color.white);
-
- Rectangle rect = getBounds();
- g2.fillRect(0,0,rect.width,rect.height);
-
- // This fixes a problem with standard debugging of region management in SWT
- if (PDebug.debugRegionManagement) {
- Rectangle r = gc.getClipping();
- Rectangle2D r2 = new Rectangle2D.Double(r.x,r.y,r.width,r.height);
- g2.setBackground(PDebug.getDebugPaintColor());
- g2.fill(r2);
- }
-
- // create new paint context and set render quality
- PPaintContext paintContext = new PPaintContext(g2);
- if (getInteracting() || getAnimating()) {
- if (interactingRenderQuality > animatingRenderQuality) {
- paintContext.setRenderQuality(interactingRenderQuality);
- } else {
- paintContext.setRenderQuality(animatingRenderQuality);
- }
- } else {
- paintContext.setRenderQuality(defaultRenderQuality);
- }
-
- // paint piccolo
- camera.fullPaint(paintContext);
-
- // if switched state from animating to not animating invalidate the entire
- // screen so that it will be drawn with the default instead of animating
- // render quality.
- if (!getAnimating() && animatingOnLastPaint) {
- repaint();
- }
- animatingOnLastPaint = getAnimating();
-
- boolean region = PDebug.debugRegionManagement;
- PDebug.debugRegionManagement = false;
- PDebug.endProcessingOutput(g2);
- PDebug.debugRegionManagement = region;
-
- if (doubleBuffered) {
- gc.drawImage(backBuffer,0,0);
-
- // Dispose of the allocated image gc
- imageGC.dispose();
- }
- }
-
- public void paintImmediately() {
- if (paintingImmediately) {
- return;
- }
-
- paintingImmediately = true;
- redraw();
- update();
- paintingImmediately = false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java
deleted file mode 100755
index b0bb952..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Color;
-import java.awt.Shape;
-import java.awt.event.InputEvent;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Point2D;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
-import edu.umd.cs.piccolox.util.PLocator;
-import edu.umd.cs.piccolox.util.PNodeLocator;
-
-/**
- * PHandle is used to modify some aspect of Piccolo when it
- * is dragged. Each handle has a PLocator that it uses to automatically position
- * itself. See PBoundsHandle for an example of a handle that resizes the bounds
- * of another node.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PSWTHandle extends PSWTPath {
-
- /**
- *
- */
- private static final long serialVersionUID = 4518137105565992918L;
- public static float DEFAULT_HANDLE_SIZE = 8;
- public static Shape DEFAULT_HANDLE_SHAPE = new Ellipse2D.Float(0f, 0f, DEFAULT_HANDLE_SIZE, DEFAULT_HANDLE_SIZE);
- public static Color DEFAULT_COLOR = Color.white;
-
- private PLocator locator;
- private PDragSequenceEventHandler handleDragger;
-
- /**
- * Construct a new handle that will use the given locator
- * to locate itself on its parent node.
- */
- public PSWTHandle(PLocator aLocator) {
- super(DEFAULT_HANDLE_SHAPE);
- locator = aLocator;
- setPaint(DEFAULT_COLOR);
- installHandleEventHandlers();
- }
-
- protected void installHandleEventHandlers() {
- handleDragger = new PDragSequenceEventHandler() {
- protected void startDrag(PInputEvent event) {
- super.startDrag(event);
- startHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event);
- }
- protected void drag(PInputEvent event) {
- super.drag(event);
- PDimension aDelta = event.getDeltaRelativeTo(PSWTHandle.this);
- if (aDelta.getWidth() != 0 || aDelta.getHeight() != 0) {
- dragHandle(aDelta, event);
- }
- }
- protected void endDrag(PInputEvent event) {
- super.endDrag(event);
- endHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event);
- }
- };
-
- addPropertyChangeListener(PNode.PROPERTY_TRANSFORM, new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- relocateHandle();
- }
- });
-
- handleDragger.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
- handleDragger.getEventFilter().setMarksAcceptedEventsAsHandled(true);
- handleDragger.getEventFilter().setAcceptsMouseEntered(false);
- handleDragger.getEventFilter().setAcceptsMouseExited(false);
- handleDragger.getEventFilter().setAcceptsMouseMoved(false); // no need for moved events for handle interaction,
- // so reject them so we don't consume them
- addInputEventListener(handleDragger);
- }
-
- /**
- * Return the event handler that is responsible for the drag handle
- * interaction.
- */
- public PDragSequenceEventHandler getHandleDraggerHandler() {
- return handleDragger;
- }
-
- /**
- * Get the locator that this handle uses to position itself on its
- * parent node.
- */
- public PLocator getLocator() {
- return locator;
- }
-
- /**
- * Set the locator that this handle uses to position itself on its
- * parent node.
- */
- public void setLocator(PLocator aLocator) {
- locator = aLocator;
- invalidatePaint();
- relocateHandle();
- }
-
- //****************************************************************
- // Handle Dragging - These are the methods the subclasses should
- // normally override to give a handle unique behavior.
- //****************************************************************
-
- /**
- * Override this method to get notified when the handle starts to get dragged.
- */
- public void startHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- }
-
- /**
- * Override this method to get notified as the handle is dragged.
- */
- public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) {
- }
-
- /**
- * Override this method to get notified when the handle stops getting dragged.
- */
- public void endHandleDrag(Point2D aLocalPoint, PInputEvent aEvent) {
- }
-
- //****************************************************************
- // Layout - When a handle's parent's layout changes the handle
- // invalidates its own layout and then repositions itself on its
- // parents bounds using its locator to determine that new
- // position.
- //****************************************************************
-
- public void setParent(PNode newParent) {
- super.setParent(newParent);
- relocateHandle();
- }
-
- public void parentBoundsChanged() {
- relocateHandle();
- }
-
- /**
- * Force this handle to relocate itself using its locator.
- */
- public void relocateHandle() {
- if (locator != null) {
- PBounds b = getBoundsReference();
- Point2D aPoint = locator.locatePoint(null);
-
- if (locator instanceof PNodeLocator) {
- PNode located = ((PNodeLocator)locator).getNode();
- PNode parent = getParent();
-
- located.localToGlobal(aPoint);
- globalToLocal(aPoint);
-
- if (parent != located && parent instanceof PCamera) {
- ((PCamera)parent).viewToLocal(aPoint);
- }
- }
-
- double newCenterX = aPoint.getX();
- double newCenterY = aPoint.getY();
-
- if (newCenterX != b.getCenterX() ||
- newCenterY != b.getCenterY()) {
- centerBoundsOnPoint(newCenterX, newCenterY);
- }
- }
- }
-
- //****************************************************************
- // Serialization
- //****************************************************************
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
- installHandleEventHandlers();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTImage.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTImage.java
deleted file mode 100755
index 6d581a7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTImage.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PImage;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * PImage is a wrapper around a java.awt.Image. If this node is
- * copied or serialized that image will be converted into a BufferedImage if
- * it is not already one.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PSWTImage extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 8805632167207685870L;
-
- private transient PSWTCanvas canvas;
-
- private transient Image image;
-
- public PSWTImage(PSWTCanvas canvas) {
- super();
-
- this.canvas = canvas;
- canvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent de) {
- if (image != null) {
- image.dispose();
- }
- }
- });
- }
-
- public PSWTImage(PSWTCanvas canvas, Image newImage) {
- this(canvas);
- setImage(newImage);
- }
-
- public PSWTImage(PSWTCanvas canvas, String fileName) {
- this(canvas);
- setImage(fileName);
- }
-
- /**
- * Returns the image that is shown by this node.
- * @return the image that is shown by this node
- */
- public Image getImage() {
- return image;
- }
-
- /**
- * Set the image that is wrapped by this PImage node. This method will also load
- * the image using a MediaTracker before returning. And if the this PImage is
- * accelerated that I'm will be copied into an accelerated image if needed. Note
- * that this may cause undesired results with images that have transparent regions,
- * for those cases you may want to set the PImage to be not accelerated.
- */
- public void setImage(String fileName) {
- setImage(new Image(canvas.getDisplay(),fileName));
- }
-
- /**
- * Set the image that is wrapped by this PImage node. This method will also load
- * the image using a MediaTracker before returning. And if the this PImage is
- * accelerated that I'm will be copied into an accelerated image if needed. Note
- * that this may cause undesired results with images that have transparent regions,
- * for those cases you may want to set the PImage to be not accelerated.
- */
- public void setImage(Image newImage) {
- Image old = image;
- image = newImage;
-
- if (image != null) {
- Rectangle bounds = getImage().getBounds();
- setBounds(0, 0, bounds.width, bounds.height);
- invalidatePaint();
- } else {
- image = null;
- }
-
- firePropertyChange(PImage.PROPERTY_CODE_IMAGE, PImage.PROPERTY_IMAGE, old, image);
- }
-
- protected void paint(PPaintContext paintContext) {
- if (getImage() != null) {
- Rectangle r = image.getBounds();
- double iw = r.width;
- double ih = r.height;
- PBounds b = getBoundsReference();
- SWTGraphics2D g2 = (SWTGraphics2D)paintContext.getGraphics();
-
- if (b.x != 0 || b.y != 0 || b.width != iw || b.height != ih) {
- g2.translate(b.x, b.y);
- g2.scale(b.width / iw, b.height / ih);
- g2.drawImage(image, 0, 0);
- g2.scale(iw / b.width, ih / b.height);
- g2.translate(-b.x, -b.y);
- } else {
- g2.drawImage(image, 0, 0);
- }
- }
- }
-
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("image=" + (image == null ? "null" : image.toString()));
-
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java
deleted file mode 100755
index e40df03..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Component;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Widget;
-
-/**
- * Overridden to wrap an SWT KeyEvent
- *
- * @author Lance Good
- */
-public class PSWTKeyEvent extends KeyEvent {
-
- /**
- *
- */
- private static final long serialVersionUID = 2030870828552080042L;
-
- static Component fakeSrc = new Component() {
-
- /**
- *
- */
- private static final long serialVersionUID = 1205379003504325954L;};
-
- org.eclipse.swt.events.KeyEvent swtEvent;
-
- public PSWTKeyEvent(org.eclipse.swt.events.KeyEvent ke, int eventType) {
- super(fakeSrc, eventType, ke.time, 0, ke.keyCode, ke.character, KeyEvent.KEY_LOCATION_STANDARD);
-
- swtEvent = ke;
- }
-
- public Object getSource() {
- return swtEvent.getSource();
- }
-
- public boolean isShiftDown() {
- return (swtEvent.stateMask & SWT.SHIFT) != 0;
- }
-
- public boolean isControlDown() {
- return (swtEvent.stateMask & SWT.CONTROL) != 0;
- }
-
- public boolean isAltDown() {
- return (swtEvent.stateMask & SWT.ALT) != 0;
- }
-
- public int getModifiers() {
- int modifiers = 0;
-
- if (swtEvent != null) {
- if ((swtEvent.stateMask & SWT.ALT) != 0) {
- modifiers = modifiers | InputEvent.ALT_MASK;
- }
- if ((swtEvent.stateMask & SWT.CONTROL) != 0) {
- modifiers = modifiers | InputEvent.CTRL_MASK;
- }
- if ((swtEvent.stateMask & SWT.SHIFT) != 0) {
- modifiers = modifiers | InputEvent.SHIFT_MASK;
- }
- }
-
- return modifiers;
- }
-
- public int getModifiersEx() {
- int modifiers = 0;
-
- if (swtEvent != null) {
- if ((swtEvent.stateMask & SWT.ALT) != 0) {
- modifiers = modifiers | InputEvent.ALT_MASK;
- }
- if ((swtEvent.stateMask & SWT.CONTROL) != 0) {
- modifiers = modifiers | InputEvent.CTRL_MASK;
- }
- if ((swtEvent.stateMask & SWT.SHIFT) != 0) {
- modifiers = modifiers | InputEvent.SHIFT_MASK;
- }
- }
-
- return modifiers;
- }
-
- public boolean isActionKey() {
- return false;
- }
-
- ///////////////////////////
- // THE SWT SPECIFIC EVENTS
- ///////////////////////////
-
- public Widget getWidget() {
- return swtEvent.widget;
- }
-
- public Display getDisplay() {
- return swtEvent.display;
- }
-
- public Object getData() {
- return swtEvent.data;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java
deleted file mode 100755
index 7877411..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Component;
-import java.awt.event.InputEvent;
-import java.awt.event.MouseEvent;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Widget;
-
-/**
- * Overridden to wrap an SWT MouseEvent
- *
- * @author Lance Good
- */
-public class PSWTMouseEvent extends MouseEvent {
-
- /**
- *
- */
- private static final long serialVersionUID = -7827240340000613613L;
-
- static Component fakeSrc = new Component() {
-
- /**
- *
- */
- private static final long serialVersionUID = 5065096386658285798L;};
-
- protected org.eclipse.swt.events.MouseEvent swtEvent;
-
- protected int clickCount;
-
- public PSWTMouseEvent(org.eclipse.swt.events.MouseEvent me, int type, int clickCount) {
- super(fakeSrc,type, me.time, 0, me.x, me.y, clickCount, (me.button == 3), me.button);
-
- this.swtEvent = me;
- this.clickCount = clickCount;
- }
-
- public Object getSource() {
- return swtEvent.getSource();
- }
-
- public int getClickCount() {
- return clickCount;
- }
-
- public int getButton() {
- switch (swtEvent.button) {
- case 1:
- return MouseEvent.BUTTON1;
- case 2:
- return MouseEvent.BUTTON2;
- case 3:
- return MouseEvent.BUTTON3;
- default:
- return MouseEvent.NOBUTTON;
- }
- }
-
- public boolean isShiftDown() {
- return (swtEvent.stateMask & SWT.SHIFT) != 0;
- }
-
- public boolean isControlDown() {
- return (swtEvent.stateMask & SWT.CONTROL) != 0;
- }
-
- public boolean isAltDown() {
- return (swtEvent.stateMask & SWT.ALT) != 0;
- }
-
- public int getModifiers() {
- int modifiers = 0;
-
- if (swtEvent != null) {
- if ((swtEvent.stateMask & SWT.ALT) != 0) {
- modifiers = modifiers | InputEvent.ALT_MASK;
- }
- if ((swtEvent.stateMask & SWT.CONTROL) != 0) {
- modifiers = modifiers | InputEvent.CTRL_MASK;
- }
- if ((swtEvent.stateMask & SWT.SHIFT) != 0) {
- modifiers = modifiers | InputEvent.SHIFT_MASK;
- }
- if (swtEvent.button == 1 ||
- (swtEvent.stateMask & SWT.BUTTON1) != 0) {
- modifiers = modifiers | InputEvent.BUTTON1_MASK;
- }
- if (swtEvent.button == 2 ||
- (swtEvent.stateMask & SWT.BUTTON2) != 0) {
- modifiers = modifiers | InputEvent.BUTTON2_MASK;
- }
- if (swtEvent.button == 3 ||
- (swtEvent.stateMask & SWT.BUTTON3) != 0) {
- modifiers = modifiers | InputEvent.BUTTON3_MASK;
- }
- }
-
- return modifiers;
- }
-
- public int getModifiersEx() {
- int modifiers = 0;
-
- if (swtEvent != null) {
- if ((swtEvent.stateMask & SWT.ALT) != 0) {
- modifiers = modifiers | InputEvent.ALT_MASK;
- }
- if ((swtEvent.stateMask & SWT.CONTROL) != 0) {
- modifiers = modifiers | InputEvent.CTRL_MASK;
- }
- if ((swtEvent.stateMask & SWT.SHIFT) != 0) {
- modifiers = modifiers | InputEvent.SHIFT_MASK;
- }
- if (swtEvent.button == 1 ||
- (swtEvent.stateMask & SWT.BUTTON1) != 0) {
- modifiers = modifiers | InputEvent.BUTTON1_MASK;
- }
- if (swtEvent.button == 2 ||
- (swtEvent.stateMask & SWT.BUTTON2) != 0) {
- modifiers = modifiers | InputEvent.BUTTON2_MASK;
- }
- if (swtEvent.button == 3 ||
- (swtEvent.stateMask & SWT.BUTTON3) != 0) {
- modifiers = modifiers | InputEvent.BUTTON3_MASK;
- }
- }
-
- return modifiers;
- }
-
-
- ///////////////////////////
- // THE SWT SPECIFIC EVENTS
- ///////////////////////////
-
- public Widget getWidget() {
- return swtEvent.widget;
- }
-
- public Display getDisplay() {
- return swtEvent.display;
- }
-
- public Object getData() {
- return swtEvent.data;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java
deleted file mode 100755
index ea73716..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Paint;
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RoundRectangle2D;
-
-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;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * PPath is a wrapper around a java.awt.geom.GeneralPath. The
- * setBounds method works by scaling the path to fit into the specified
- * bounds. This normally works well, but if the specified base bounds
- * get too small then it is impossible to expand the path shape again since
- * all its numbers have tended to zero, so application code may need to take
- * this into consideration.
- *
- * One option that applications have is to call startResizeBounds
before
- * starting an interaction that may make the bounds very small, and calling
- * endResizeBounds
when this interaction is finished. When this is done
- * PPath will use a copy of the original path to do the resizing so the numbers
- * in the path wont loose resolution.
- *
- * This class also provides methods for constructing common shapes using a
- * general path.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PSWTPath extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -4125283808953133945L;
-
- /**
- * The property name that identifies a change of this node's path.
- * In any property change event the new value will be a reference to
- * this node's path, but old value will always be null.
- */
- public static final String PROPERTY_SHAPE = "shape";
-
- private static final double BOUNDS_TOLERANCE = 0.01;
- private static final Rectangle2D.Float TEMP_RECTANGLE = new Rectangle2D.Float();
- private static final RoundRectangle2D.Float TEMP_ROUNDRECTANGLE = new RoundRectangle2D.Float();
- private static final Ellipse2D.Float TEMP_ELLIPSE = new Ellipse2D.Float();
- private static final Color DEFAULT_STROKE_PAINT = Color.black;
- private static final BasicStroke BASIC_STROKE = new BasicStroke();
- private static final float PEN_WIDTH = 1f;
-
- private Paint strokePaint;
-
- boolean updatingBoundsFromPath;
- Shape origShape;
- Shape shape;
-
- PAffineTransform internalXForm;
- AffineTransform inverseXForm;
-
- double[] shapePts;
-
- public static PSWTPath createRectangle(float x, float y, float width, float height) {
- TEMP_RECTANGLE.setFrame(x, y, width, height);
- PSWTPath result = new PSWTPath(TEMP_RECTANGLE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PSWTPath createRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight) {
- TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight);
- PSWTPath result = new PSWTPath(TEMP_ROUNDRECTANGLE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PSWTPath createEllipse(float x, float y, float width, float height) {
- TEMP_ELLIPSE.setFrame(x, y, width, height);
- PSWTPath result = new PSWTPath(TEMP_ELLIPSE);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PSWTPath createPolyline(Point2D[] points) {
- PSWTPath result = new PSWTPath();
- result.setPathToPolyline(points);
- result.setPaint(Color.white);
- return result;
- }
-
- public static PSWTPath createPolyline(float[] xp, float[] yp) {
- PSWTPath result = new PSWTPath();
- result.setPathToPolyline(xp, yp);
- result.setPaint(Color.white);
- return result;
- }
-
- public PSWTPath() {
- strokePaint = DEFAULT_STROKE_PAINT;
- }
-
- public PSWTPath(Shape aShape) {
- this();
- setShape(aShape);
- }
-
- //****************************************************************
- // Stroke
- //****************************************************************
-
- public Paint getStrokePaint() {
- return strokePaint;
- }
-
- public void setStrokeColor(Paint aPaint) {
- Paint old = strokePaint;
- strokePaint = aPaint;
- invalidatePaint();
- firePropertyChange(PPath.PROPERTY_CODE_STROKE_PAINT, PPath.PROPERTY_STROKE_PAINT, old, strokePaint);
- }
-
- /**
- * Set the bounds of this path. This method works by scaling the path
- * to fit into the specified bounds. This normally works well, but if
- * the specified base bounds get too small then it is impossible to
- * expand the path shape again since all its numbers have tended to zero,
- * so application code may need to take this into consideration.
- */
- protected void internalUpdateBounds(double x, double y, double width, double height) {
- if (updatingBoundsFromPath) return;
- if (origShape == null) return;
-
- Rectangle2D pathBounds = origShape.getBounds2D();
-
- if (Math.abs(x-pathBounds.getX())/x < BOUNDS_TOLERANCE &&
- Math.abs(y-pathBounds.getY())/y < BOUNDS_TOLERANCE &&
- Math.abs(width-pathBounds.getWidth())/width < BOUNDS_TOLERANCE &&
- Math.abs(height-pathBounds.getHeight())/height < BOUNDS_TOLERANCE) {
- return;
- }
-
- if (internalXForm == null) {
- internalXForm = new PAffineTransform();
- }
- internalXForm.setToIdentity();
- internalXForm.translate(x, y);
- internalXForm.scale(width / pathBounds.getWidth(), height / pathBounds.getHeight());
- internalXForm.translate(-pathBounds.getX(), -pathBounds.getY());
-
- try {
- inverseXForm = internalXForm.createInverse();
- }
- catch (Exception e) {
- }
- }
-
-
- public boolean intersects(Rectangle2D aBounds) {
- if (super.intersects(aBounds)) {
-
- if (internalXForm != null) {
- aBounds = new PBounds(aBounds);
- internalXForm.inverseTransform(aBounds,aBounds);
- }
-
- if (getPaint() != null && shape.intersects(aBounds)) {
- return true;
- } else if (strokePaint != null) {
- return BASIC_STROKE.createStrokedShape(shape).intersects(aBounds);
- }
- }
- return false;
- }
-
- public void updateBoundsFromPath() {
- updatingBoundsFromPath = true;
-
- if (origShape == null) {
- resetBounds();
- } else {
- Rectangle2D b = origShape.getBounds2D();
-
- // Note that this pen width code does not really work for SWT since it assumes
- // that the pen width scales - in actuality it does not. However, the fix would
- // be to have volatile bounds for all shapes which isn't a nice alternative
- super.setBounds(b.getX()-PEN_WIDTH,
- b.getY()-PEN_WIDTH,
- b.getWidth()+2*PEN_WIDTH,
- b.getHeight()+2*PEN_WIDTH);
- }
- updatingBoundsFromPath = false;
- }
-
- //****************************************************************
- // Painting
- //****************************************************************
-
- protected void paint(PPaintContext paintContext) {
- Paint p = getPaint();
- SWTGraphics2D g2 = (SWTGraphics2D)paintContext.getGraphics();
-
- if (internalXForm != null) {
- g2.transform(internalXForm);
- }
-
- if (p != null) {
- g2.setBackground((Color)p);
-
- double lineWidth = g2.getTransformedLineWidth();
- if (shape instanceof Rectangle2D) {
- g2.fillRect(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth);
- }
- else if (shape instanceof Ellipse2D) {
- g2.fillOval(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth);
- }
- else if (shape instanceof Arc2D) {
- g2.fillArc(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth,shapePts[4],shapePts[5]);
- }
- else if (shape instanceof RoundRectangle2D) {
- g2.fillRoundRect(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth,shapePts[4],shapePts[5]);
- }
- else {
- g2.fillPolygon(shapePts);
- }
- }
-
- if (strokePaint != null) {
- g2.setColor((Color)strokePaint);
-
- double lineWidth = g2.getTransformedLineWidth();
- if (shape instanceof Rectangle2D) {
- g2.drawRect(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth);
- }
- else if (shape instanceof Ellipse2D) {
- g2.drawOval(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth);
- }
- else if (shape instanceof Arc2D) {
- g2.drawArc(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth,shapePts[4],shapePts[5]);
- }
- else if (shape instanceof RoundRectangle2D) {
- g2.drawRoundRect(shapePts[0]+lineWidth/2,shapePts[1]+lineWidth/2,shapePts[2]-lineWidth,shapePts[3]-lineWidth,shapePts[4],shapePts[5]);
- }
- else {
- // TODO The bounds may be incorrect for polylines at the moment - resulting in graphics turds at some scales
- g2.drawPolyline(shapePts);
- }
- }
-
- if (inverseXForm != null) {
- g2.transform(inverseXForm);
- }
- }
-
- public void setShape(Shape aShape) {
- this.shape = cloneShape(aShape);
- this.origShape = shape;
- updateShapePoints(aShape);
-
- firePropertyChange(PPath.PROPERTY_CODE_PATH, PPath.PROPERTY_PATH, null, shape);
- updateBoundsFromPath();
- invalidatePaint();
- }
-
- public void updateShapePoints(Shape aShape) {
- if (aShape instanceof Rectangle2D) {
- if (shapePts == null || shapePts.length < 4) {
- shapePts = new double[4];
- }
-
- shapePts[0] = ((Rectangle2D)shape).getX();
- shapePts[1] = ((Rectangle2D)shape).getY();
- shapePts[2] = ((Rectangle2D)shape).getWidth();
- shapePts[3] = ((Rectangle2D)shape).getHeight();
- }
- else if (aShape instanceof Ellipse2D) {
- if (shapePts == null || shapePts.length < 4) {
- shapePts = new double[4];
- }
-
- shapePts[0] = ((Ellipse2D)shape).getX();
- shapePts[1] = ((Ellipse2D)shape).getY();
- shapePts[2] = ((Ellipse2D)shape).getWidth();
- shapePts[3] = ((Ellipse2D)shape).getHeight();
- }
- else if (aShape instanceof Arc2D) {
- if (shapePts == null || shapePts.length < 6) {
- shapePts = new double[6];
- }
-
- shapePts[0] = ((Arc2D)shape).getX();
- shapePts[1] = ((Arc2D)shape).getY();
- shapePts[2] = ((Arc2D)shape).getWidth();
- shapePts[3] = ((Arc2D)shape).getHeight();
- shapePts[4] = ((Arc2D)shape).getAngleStart();
- shapePts[5] = ((Arc2D)shape).getAngleExtent();
- }
- else if (aShape instanceof RoundRectangle2D) {
- if (shapePts == null || shapePts.length < 6) {
- shapePts = new double[6];
- }
-
- shapePts[0] = ((RoundRectangle2D)shape).getX();
- shapePts[1] = ((RoundRectangle2D)shape).getY();
- shapePts[2] = ((RoundRectangle2D)shape).getWidth();
- shapePts[3] = ((RoundRectangle2D)shape).getHeight();
- shapePts[4] = ((RoundRectangle2D)shape).getArcWidth();
- shapePts[5] = ((RoundRectangle2D)shape).getArcHeight();
- }
- else {
- shapePts = SWTShapeManager.shapeToPolyline(shape);
- }
- }
-
- public Shape cloneShape(Shape aShape) {
- if (aShape instanceof Rectangle2D) {
- return new PBounds((Rectangle2D)aShape);
- }
- else if (aShape instanceof Ellipse2D) {
- Ellipse2D e2 = (Ellipse2D)aShape;
- return new Ellipse2D.Double(e2.getX(),e2.getY(),e2.getWidth(),e2.getHeight());
- }
- else if (aShape instanceof Arc2D) {
- Arc2D a2 = (Arc2D)aShape;
- return new Arc2D.Double(a2.getX(),a2.getY(),a2.getWidth(),a2.getHeight(),a2.getAngleStart(),a2.getAngleExtent(),a2.getArcType());
- }
- else if (aShape instanceof RoundRectangle2D) {
- RoundRectangle2D r2 = (RoundRectangle2D)aShape;
- return new RoundRectangle2D.Double(r2.getX(),r2.getY(),r2.getWidth(),r2.getHeight(),r2.getArcWidth(),r2.getArcHeight());
- }
- else if (aShape instanceof Line2D) {
- Line2D l2 = (Line2D)aShape;
- return new Line2D.Double(l2.getP1(),l2.getP2());
- }
- else {
- new Exception().printStackTrace();
- GeneralPath aPath = new GeneralPath();
- aPath.append(aShape,false);
- return aPath;
- }
- }
-
- public void setPathToRectangle(float x, float y, float width, float height) {
- TEMP_RECTANGLE.setFrame(x, y, width, height);
- setShape(TEMP_RECTANGLE);
- }
-
- public void setPathToRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight){
- TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight);
- setShape(TEMP_ROUNDRECTANGLE);
- }
-
- public void setPathToEllipse(float x, float y, float width, float height) {
- TEMP_ELLIPSE.setFrame(x, y, width, height);
- setShape(TEMP_ELLIPSE);
- }
-
- public void setPathToPolyline(Point2D[] points) {
- GeneralPath path = new GeneralPath();
- path.reset();
- path.moveTo((float)points[0].getX(), (float)points[0].getY());
- for (int i = 1; i < points.length; i++) {
- path.lineTo((float)points[i].getX(), (float)points[i].getY());
- }
- setShape(path);
- }
-
- public void setPathToPolyline(float[] xp, float[] yp) {
- GeneralPath path = new GeneralPath();
- path.reset();
- path.moveTo(xp[0], yp[0]);
- for (int i = 1; i < xp.length; i++) {
- path.lineTo(xp[i], yp[i]);
- }
- setShape(path);
- }
-
- //****************************************************************
- // Debugging - methods for debugging
- //****************************************************************
-
- /**
- * Returns a string representing the state of this node. This method is
- * intended to be used only for debugging purposes, and the content and
- * format of the returned string may vary between implementations. The
- * returned string may be empty but may not be null
.
- *
- * @return a string representation of this node's state
- */
- protected String paramString() {
- StringBuffer result = new StringBuffer();
-
- result.append("path=" + (shape == null ? "null" : shape.toString()));
- result.append(",strokePaint=" + (strokePaint == null ? "null" : strokePaint.toString()));
- result.append(',');
- result.append(super.paramString());
-
- return result.toString();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java
deleted file mode 100755
index 3192b6e..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2002-@year@ by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory
- * www.cs.umd.edu/hcil by Jesse Grosjean under the supervision of Ben Bederson.
- * The Piccolo website is www.cs.umd.edu/hcil/piccolo
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.event.ActionListener;
-import javax.swing.Timer;
-
-import org.eclipse.swt.widgets.Composite;
-
-import edu.umd.cs.piccolo.PRoot;
-
-/**
- * PSWTRoot is a subclass of PRoot that is designed to work in the SWT
- * environment. In particular it uses SWTTimers and the SWT event dispatch
- * thread. With the current setup only a single PSWTCanvas is expected to be
- * connected to a root.
- *
- * @version 1.1
- * @author Jesse Grosjean
- */
-public class PSWTRoot extends PRoot {
-
- /**
- *
- */
- private static final long serialVersionUID = 279975594597435770L;
- private Composite composite;
-
- public PSWTRoot(Composite composite) {
- this.composite = composite;
- }
-
- public Timer createTimer(int delay, ActionListener listener) {
- return new SWTTimer(composite.getDisplay(),delay,listener);
- }
-
- public void scheduleProcessInputsIfNeeded() {
- if (!Thread.currentThread().equals(composite.getDisplay().getThread())) {
- return;
- }
-
- if (!processInputsScheduled && !processingInputs &&
- (getFullBoundsInvalid() || getChildBoundsInvalid() || getPaintInvalid() || getChildPaintInvalid())) {
-
- processInputsScheduled = true;
- composite.getDisplay().asyncExec(new Runnable() {
- public void run() {
- processInputs();
- processInputsScheduled = false;
- }
- });
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java
deleted file mode 100755
index 0b91cbe..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Color;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.event.PSelectionEventHandler;
-
-/**
- * Modified to use SWT paths instead of normal paths
- * @version 1.0
- * @author Lance Good
- */
-public class PSWTSelectionEventHandler extends PSelectionEventHandler {
-
- PSWTPath marquee;
- PNode marqueeParent;
- Point2D pressPt;
- Point2D canvasPressPt;
-
- /**
- * Creates a selection event handler.
- * @param marqueeParent The node to which the event handler dynamically adds a marquee
- * (temporarily) to represent the area being selected.
- * @param selectableParent The node whose children will be selected
- * by this event handler.
- */
- public PSWTSelectionEventHandler(PNode marqueeParent, PNode selectableParent) {
- super(new PNode(),selectableParent);
- this.marqueeParent = marqueeParent;
- }
-
- /**
- * Creates a selection event handler.
- * @param marqueeParent The node to which the event handler dynamically adds a marquee
- * (temporarily) to represent the area being selected.
- * @param selectableParents A list of nodes whose children will be selected
- * by this event handler.
- */
- public PSWTSelectionEventHandler(PNode marqueeParent, List selectableParents) {
- super(new PNode(),selectableParents);
- this.marqueeParent = marqueeParent;
- }
-
- public void decorateSelectedNode(PNode node) {
- PSWTBoundsHandle.addBoundsHandlesTo(node);
- }
-
- public void undecorateSelectedNode(PNode node) {
- PSWTBoundsHandle.removeBoundsHandlesFrom(node);
- }
-
- protected void initializeSelection(PInputEvent pie) {
- super.initializeSelection(pie);
- pressPt = pie.getPosition();
- canvasPressPt = pie.getCanvasPosition();
- }
-
- protected void initializeMarquee(PInputEvent e) {
- super.initializeMarquee(e);
-
- marquee = new PSWTPath(new Rectangle2D.Float((float)pressPt.getX(), (float)pressPt.getY(), 0, 0)) {
- /**
- *
- */
- private static final long serialVersionUID = 824610437279489415L;
-
- protected void paint(PPaintContext paintContext) {
- SWTGraphics2D s2g = (SWTGraphics2D)paintContext.getGraphics();
- s2g.gc.setLineStyle(SWT.LINE_DASH);
- super.paint(paintContext);
- s2g.gc.setLineStyle(SWT.LINE_SOLID);
- }
- };
- marquee.setStrokeColor(Color.black);
- marquee.setPaint(null);
- marqueeParent.addChild(marquee);
- }
-
- protected void updateMarquee(PInputEvent pie) {
- super.updateMarquee(pie);
-
- PBounds b = new PBounds();
-
- if (marqueeParent instanceof PCamera) {
- b.add(canvasPressPt);
- b.add(pie.getCanvasPosition());
- }
- else {
- b.add(pressPt);
- b.add(pie.getPosition());
- }
-
- marquee.setPathToRectangle((float) b.x, (float) b.y, (float) b.width, (float) b.height);
- b.reset();
- b.add(pressPt);
- b.add(pie.getPosition());
- }
-
- protected PBounds getMarqueeBounds() {
- if (marquee != null) {
- return marquee.getBounds();
- }
- return new PBounds();
- }
-
- protected void endMarqueeSelection(PInputEvent e) {
- super.endMarqueeSelection(e);
-
- // Remove marquee
- marquee.removeFromParent();
- marquee = null;
- }
-
- /**
- * This gets called continuously during the drag, and is used to animate the marquee
- */
- protected void dragActivityStep(PInputEvent aEvent) {
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java
deleted file mode 100755
index a57118e..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.swt;
-
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-public class PSWTStickyHandleManager extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = -5848154334769247698L;
- private PNode target;
- private PCamera camera;
-
- public PSWTStickyHandleManager(PCamera newCamera, PNode newTarget) {
- setCameraTarget(newCamera, newTarget);
- PSWTBoundsHandle.addBoundsHandlesTo(this);
- }
-
- public void setCameraTarget(PCamera newCamera, PNode newTarget) {
- camera = newCamera;
- camera.addChild(this);
- target = newTarget;
- }
-
- public boolean setBounds(double x, double y, double width, double height) {
- PBounds b = new PBounds(x, y, width, height);
- camera.localToGlobal(b);
- camera.localToView(b);
- target.globalToLocal(b);
- target.setBounds(b);
- return super.setBounds(x, y, width, height);
- }
-
- protected boolean getBoundsVolatile() {
- return true;
- }
-
- public PBounds getBoundsReference() {
- PBounds targetBounds = target.getFullBounds();
- camera.viewToLocal(targetBounds);
- camera.globalToLocal(targetBounds);
- PBounds bounds = super.getBoundsReference();
- bounds.setRect(targetBounds);
- return super.getBoundsReference();
- }
-
- public void startResizeBounds() {
- super.startResizeBounds();
- target.startResizeBounds();
- }
-
- public void endResizeBounds() {
- super.endResizeBounds();
- target.endResizeBounds();
- }
-
- public boolean pickAfterChildren(PPickPath pickPath) {
- return false;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/PSWTText.java b/src/main/java/edu/umd/cs/piccolox/swt/PSWTText.java
deleted file mode 100755
index 4cd2644..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/PSWTText.java
+++ /dev/null
@@ -1,528 +0,0 @@
-/**
- * Copyright (C) 1998-1999 by University of Maryland, College Park, MD 20742, USA
- * All rights reserved.
- */
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.geom.*;
-import java.util.*;
-
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Display;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PPaintContext;
-
-/**
- * PSWTText creates a visual component to support text. Multiple lines can
- * be entered, and basic editing is supported. A caret is drawn,
- * and can be repositioned with mouse clicks. The text object is positioned
- * so that its upper-left corner is at the origin, though this can be changed
- * with the translate methods.
- *
- * Warning: Serialized and ZSerialized objects of this class will not be
- * compatible with future Jazz releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Jazz. A future release of Jazz will provide support for long
- * term persistence.
- */
-public class PSWTText extends PNode {
-
- /**
- *
- */
- private static final long serialVersionUID = 6639779723093125731L;
-
- /**
- * Below this magnification render text as 'greek'.
- */
- static protected final double DEFAULT_GREEK_THRESHOLD = 5.5;
-
- /**
- * Default color of text rendered as 'greek'.
- */
- static protected final Color DEFAULT_GREEK_COLOR = Color.gray;
-
- /**
- * Default font name of text.
- */
- static protected final String DEFAULT_FONT_NAME = "Helvetica";
-
- /**
- * Default font style for text.
- */
- static protected final int DEFAULT_FONT_STYLE = Font.PLAIN;
-
- /**
- * Default font size for text.
- */
- static protected final int DEFAULT_FONT_SIZE = 12;
-
- /**
- * Default font for text.
- */
- static protected final Font DEFAULT_FONT = new Font(DEFAULT_FONT_NAME, DEFAULT_FONT_STYLE, DEFAULT_FONT_SIZE);
-
- /**
- * Default color for text.
- */
- static protected final Color DEFAULT_PEN_COLOR = Color.black;
-
- /**
- * Default text when new text area is created.
- */
- static protected final String DEFAULT_TEXT = "";
-
- /**
- * Default padding
- */
- static protected final int DEFAULT_PADDING = 2;
-
- /**
- * Below this magnification text is rendered as greek.
- */
- protected double greekThreshold = DEFAULT_GREEK_THRESHOLD;
-
- /**
- * Color for greek text.
- */
- protected Color greekColor = DEFAULT_GREEK_COLOR;
-
- /**
- * Current pen color.
- */
- protected Color penColor = DEFAULT_PEN_COLOR;
-
- /**
- * Current text font.
- */
- protected Font font = DEFAULT_FONT;
-
- /**
- * The amount of padding on each side of the text
- */
- protected int padding = DEFAULT_PADDING;
-
-
- /**
- * Each vector element is one line of text.
- */
- protected ArrayList lines = new ArrayList();
-
-
- /**
- * Translation offset X.
- */
- protected double translateX = 0.0;
-
- /**
- * Translation offset Y.
- */
- protected double translateY = 0.0;
-
- /**
- * Default constructor for PSWTTest.
- */
- public PSWTText() {
- this("", DEFAULT_FONT);
- }
-
- /**
- * PSWTTest constructor with initial text.
- * @param str The initial text.
- */
- public PSWTText(String str) {
- this(str, DEFAULT_FONT);
- }
-
- /**
- * PSWTTest constructor with initial text and font.
- * @param str The initial text.
- * @param font The font for this PSWTText component.
- */
- public PSWTText(String str, Font font) {
- setText(str);
- this.font = font;
-
- recomputeBounds();
- }
-
- //****************************************************************************
- //
- // Get/Set and pairs
- //
- //***************************************************************************
-
- /**
- * Returns the current pen color.
- */
- public Color getPenColor() {return penColor;}
-
- /**
- * Sets the current pen color.
- * @param color use this color.
- */
- public void setPenColor(Color color) {
- penColor = color;
- repaint();
- }
-
- /**
- * Returns the current pen paint.
- */
- public Paint getPenPaint() {
- return penColor;
- }
-
- /**
- * Sets the current pen paint.
- * @param aPaint use this paint.
- */
- public void setPenPaint(Paint aPaint) {
- penColor = (Color)aPaint;
- }
-
- /**
- * Returns the current background color.
- */
- public Color getBackgroundColor() {
- return (Color)getPaint();
- }
-
- /**
- * Sets the current background color.
- * @param color use this color.
- */
- public void setBackgroundColor(Color color) {
- super.setPaint(color);
- }
-
- /**
- * Returns the current greek threshold. Below this magnification
- * text is rendered as 'greek'.
- */
- public double getGreekThreshold() {return greekThreshold;}
-
- /**
- * Sets the current greek threshold. Below this magnification
- * text is rendered as 'greek'.
- * @param threshold compared to renderContext magnification.
- */
- public void setGreekThreshold(double threshold) {
- greekThreshold = threshold;
- repaint();
- }
-
- /**
- * Returns the current font.
- */
- public Font getFont() {return font;}
-
- /**
- * Return the text within this text component.
- * Multline text is returned as a single string
- * where each line is separated by a newline character.
- * Single line text does not have any newline characters.
- */
- public String getText() {
- String line;
- String result = new String();
- int lineNum = 0;
-
- for (Iterator i = lines.iterator() ; i.hasNext() ; ) {
- if (lineNum > 0) {
- result += '\n';
- }
- line = (String)i.next();
- result += line;
- lineNum++;
- }
-
- return result;
- }
-
- /**
- * Sets the font for the text.
- *
- * Warning: Java has a serious bug in that it does not support very small
- * fonts. In particular, fonts that are less than about a pixel high just don't work.
- * Since in Jazz, it is common to create objects of arbitrary sizes, and then scale them,
- * an application can easily create a text object with a very small font by accident.
- * The workaround for this bug is to create a larger font for the text object, and
- * then scale the node down correspondingly.
- * @param aFont use this font.
- */
- public void setFont(Font aFont) {
- font = aFont;
-
- recomputeBounds();
- }
-
- /**
- * Sets the text of this visual component to str. Multiple lines
- * of text are separated by a newline character.
- * @param str use this string.
- */
- public void setText(String str) {
- int pos = 0;
- int index;
- boolean done = false;
- lines = new ArrayList();
- do {
- index = str.indexOf('\n', pos);
- if (index == -1) {
- lines.add(str);
- done = true;
- } else {
- lines.add(str.substring(0, index));
- str = str.substring(index + 1);
- }
- } while (!done);
-
- recomputeBounds();
- }
-
- /**
- * Set text translation offset X.
- * @param x the X translation.
- */
- public void setTranslateX(double x) {
- setTranslation(x, translateY);
- }
-
- /**
- * Get the X offset translation.
- * @return the X translation.
- */
- public double getTranslateX() {
- return translateX;
- }
-
- /**
- * Set text translation offset Y.
- * @param y the Y translation.
- */
- public void setTranslateY(double y) {
- setTranslation(translateX, y);
- }
-
- /**
- * Get the Y offset translation.
- * @return the Y translation.
- */
- public double getTranslateY() {
- return translateY;
- }
-
- /**
- * Set the text translation offset to the specified position.
- * @param x the X-coord of translation
- * @param y the Y-coord of translation
- */
- public void setTranslation(double x, double y) {
- translateX = x;
- translateY = y;
-
- recomputeBounds();
- }
-
- /**
- * Set the text translation offset to point p.
- * @param p The translation offset.
- */
- public void setTranslation(Point2D p) {
- setTranslation(p.getX(), p.getY());
- }
-
- /**
- * Get the text translation offset.
- * @return The translation offset.
- */
- public Point2D getTranslation() {
- Point2D p = new Point2D.Double(translateX, translateY);
- return p;
- }
-
- /**
- * Renders the text object.
- *
- * The transform, clip, and composite will be set appropriately when this object
- * is rendered. It is up to this object to restore the transform, clip, and composite of
- * the Graphics2D if this node changes any of them. However, the color, font, and stroke are
- * unspecified by Jazz. This object should set those things if they are used, but
- * they do not need to be restored.
- *
- * @param ppc Contains information about current render.
- */
- public void paint(PPaintContext ppc) {
- Graphics2D g2 = ppc.getGraphics();
- AffineTransform at = null;
- boolean translated = false;
- if (!lines.isEmpty()) {
-
- if ((translateX != 0.0) || (translateY != 0.0)) {
- at = g2.getTransform(); // save transform
- g2.translate(translateX, translateY);
- translated = true;
- }
-
- // If font too small and not antialiased, then greek
- double renderedFontSize = font.getSize() * ppc.getScale();
- // BBB: HACK ALERT - July 30, 1999
- // This is a workaround for a bug in Sun JDK 1.2.2 where
- // fonts that are rendered at very small magnifications show up big!
- // So, we render as greek if requested (that's normal)
- // OR if the font is very small (that's the workaround)
- if ((renderedFontSize < 0.5) ||
- (renderedFontSize < greekThreshold)) {
- paintAsGreek(ppc);
- } else {
- paintAsText(ppc);
- }
- if (translated) {
- g2.setTransform(at); // restore transform
- }
- }
- }
-
- /**
- * Paints this object as greek.
- * @param ppc The graphics context to paint into.
- */
- public void paintAsGreek(PPaintContext ppc) {
- Graphics2D g2 = ppc.getGraphics();
-
- if (greekColor != null) {
- g2.setBackground(greekColor);
- ((SWTGraphics2D)g2).fillRect(0,0,getWidth(),getHeight());
- }
- }
-
- /**
- * Paints this object normally (show it's text).
- * Note that the entire text gets rendered so that it's upper
- * left corner appears at the origin of this local object.
- * @param ppc The graphics context to paint into.
- */
- public void paintAsText(PPaintContext ppc) {
- SWTGraphics2D sg2 = (SWTGraphics2D)ppc.getGraphics();
-
- if (getPaint() != null) {
- sg2.setBackground((Color)getPaint());
- Rectangle2D rect = new Rectangle2D.Double(0.0, 0.0, getWidth(), getHeight());
- sg2.fillRect(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight());
- }
-
-
- sg2.translate(padding,padding);
-
- double scale = Math.min(sg2.getTransform().getScaleX(),sg2.getTransform().getScaleY());
- double dSize = scale*font.getSize();
- double fixupScale = Math.floor(dSize)/dSize;
-
- // This moves the text size down to the next closest integer size - to help it stay in
- // it's alloted bounds. This is because SWT only supports integer font metrics
- sg2.scale(fixupScale,fixupScale);
-
-
- // Render each line of text
- // Note that the entire text gets rendered so that it's upper left corner
- // appears at the origin of this local object.
- sg2.setColor(penColor);
- sg2.setFont(font);
-
- int lineNum = 0;
- String line;
- double y;
-
- FontMetrics metrics = sg2.getSWTFontMetrics();
-
- for (Iterator i = lines.iterator() ; i.hasNext() ; ) {
- line = (String)i.next();
-
- // ADDED BY LEG ON 2/25/03 - BUG CAUSING PROBLEMS AT CERTAIN
- // SCALES WHEN LINE WAS EMPTY
- line = (line.equals("")) ? " " : line;
-
- y = (lineNum * metrics.getHeight());
-
- sg2.drawString(line, (double)0, (double)y);
-
- lineNum++;
- }
-
- sg2.scale(1/fixupScale,1/fixupScale);
-
- sg2.translate(-padding,-padding);
- }
-
- /**
- * Notifies this object that it has changed and that it
- * should update its notion of its bounding box.
- */
- protected void recomputeBounds() {
- Point bds;
- double lineWidth;
- double maxWidth = 0.0;
- double height;
-
- height = 0.0;
-
- boolean hasText = true;
- if ((lines.size() == 1) && (((String)lines.get(0)).equals(""))) {
- hasText = false;
- }
-
- GC gc = new GC(Display.getDefault());
- SWTGraphics2D g2 = new SWTGraphics2D(gc,Display.getDefault());
- g2.setFont(font);
- FontMetrics fm = g2.getSWTFontMetrics();
-
- if (!lines.isEmpty() && hasText) {
- String line;
- int lineNum = 0;
- for (Iterator i = lines.iterator() ; i.hasNext() ; ) {
- line = (String)i.next();
-
-
- // Find the longest line in the text
- bds = gc.stringExtent(line);
- lineWidth = bds.x;
-
- if (lineWidth > maxWidth) {
- maxWidth = lineWidth;
- }
- // Find the heighest line in the text
- if (lineNum == 0) {
- height += fm.getAscent()+fm.getDescent()+fm.getLeading();
- } else {
- height += fm.getHeight();
- }
-
- lineNum++;
- }
- } else {
- // If no text, then we want to have the bounds of a space character,
- // so get those bounds here
- bds = gc.stringExtent(" ");
- maxWidth = bds.x;
- height = bds.y;
- }
-
- gc.dispose();
-
- // Finally, set the bounds of this text
- setBounds(translateX,translateY,maxWidth+2*DEFAULT_PADDING,height+2*DEFAULT_PADDING);
- }
-
- protected void internalUpdateBounds(double x, double y, double width, double height) {
- recomputeBounds();
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java b/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java
deleted file mode 100755
index 8e33e07..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java
+++ /dev/null
@@ -1,944 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RoundRectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
-import java.awt.image.ImageObserver;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
-import java.text.AttributedCharacterIterator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.GC;
-
-/**
- * An extension to Graphics2D to support an SWT Piccolo Canvas with little modification to the current Piccolo architecture
- *
- * There is an outstanding SWT bug request #33319 for more efficient polyline/polygon rendering methods. It also appears that
- * most of the code below could be made obselete by bug fix #6490
- *
- * A lot of this may also be duplicated in GEF - the eclipse Graphical Editor Framework
- *
- * @author Lance Good
- */
-public class SWTGraphics2D extends Graphics2D {
-
- protected static int CACHE_COUNT = 0;
- protected static HashMap FONT_CACHE = new HashMap();
- protected static HashMap COLOR_CACHE = new HashMap();
- protected static HashMap SHAPE_CACHE = new HashMap();
- protected static BufferedImage BUFFER = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
-
- static Point PT = new Point();
- static Rectangle2D RECT = new Rectangle2D.Double();
- static Rectangle2D LINE_RECT = new Rectangle2D.Double();
- static org.eclipse.swt.graphics.Rectangle SWT_RECT = new org.eclipse.swt.graphics.Rectangle(0,0,0,0);
-
- protected GC gc;
- protected Device device;
- protected AffineTransform transform = new AffineTransform();
- protected org.eclipse.swt.graphics.Font curFont;
- protected double lineWidth = 1.0;
-
- /**
- * Constructor for SWTGraphics2D.
- */
- public SWTGraphics2D(GC gc, Device device) {
- super();
-
- this.gc = gc;
- this.device = device;
- }
-
- ////////////////////
- // GET CLIP
- ////////////////////
-
- /**
- * @see java.awt.Graphics#getClipBounds()
- */
- public Rectangle getClipBounds() {
- org.eclipse.swt.graphics.Rectangle rect = gc.getClipping();
- Rectangle aRect = new Rectangle(rect.x,rect.y,rect.width,rect.height);
- try {
- SWTShapeManager.transform(aRect,transform.createInverse());
- } catch (Exception e) {e.printStackTrace();}
- return aRect;
- }
-
- public void clipRect(int x, int y, int width, int height) {
- RECT.setRect(x,y,width,height);
- SWTShapeManager.transform(RECT,transform);
- SWTShapeManager.awtToSWT(RECT,SWT_RECT);
-
- org.eclipse.swt.graphics.Rectangle clip = gc.getClipping();
- clip = clip.intersection(SWT_RECT);
-
- gc.setClipping(clip);
- }
-
- public void setClip(int x, int y, int width, int height) {
- RECT.setRect(x,y,width,height);
- SWTShapeManager.transform(RECT,transform);
- SWTShapeManager.awtToSWT(RECT,SWT_RECT);
-
- gc.setClipping(SWT_RECT);
- }
-
- /**
- * This method isn't really supported by SWT - so will use the shape bounds
- */
- public void clip(Shape s) {
- Rectangle2D clipBds = s.getBounds2D();
- SWTShapeManager.transform(clipBds,transform);
- SWTShapeManager.awtToSWT(clipBds,SWT_RECT);
-
- org.eclipse.swt.graphics.Rectangle clip = gc.getClipping();
- clip = clip.intersection(SWT_RECT);
-
- gc.setClipping(SWT_RECT);
- }
-
- /**
- * This method isn't really supported by SWT - so will use the shape bounds
- */
- public void setClip(Shape clip) {
- if (clip == null) {
- gc.setClipping((org.eclipse.swt.graphics.Rectangle)null);
- }
- else {
- Rectangle2D clipBds = clip.getBounds2D();
- SWTShapeManager.transform(clipBds,transform);
- SWTShapeManager.awtToSWT(clipBds,SWT_RECT);
-
- gc.setClipping(SWT_RECT);
- }
- }
-
- public Shape getClip() {
- org.eclipse.swt.graphics.Rectangle rect = gc.getClipping();
- Rectangle2D aRect = new Rectangle2D.Double(rect.x,rect.y,rect.width,rect.height);
- try {
- SWTShapeManager.transform(aRect,transform.createInverse());
- } catch (Exception e) {e.printStackTrace();}
- return aRect;
- }
-
- /////////////////////
- // DEVICE SPECIFIC
- /////////////////////
-
-
- public GraphicsConfiguration getDeviceConfiguration() {
- return ((Graphics2D)BUFFER.getGraphics()).getDeviceConfiguration();
- }
-
-
- ////////////////
- // COLOR METHODS
- ////////////////
-
- public Paint getPaint() {
- return getColor();
- }
-
- public void setPaint(Paint paint) {
- if (paint instanceof Color) {
- setColor((Color)paint);
- }
- }
-
- public Color getColor() {
- org.eclipse.swt.graphics.Color color = gc.getForeground();
- Color awtColor = new Color(color.getRed(),color.getGreen(),color.getBlue());
- return awtColor;
- }
-
- public void setColor(Color c) {
- org.eclipse.swt.graphics.Color cachedColor = (org.eclipse.swt.graphics.Color)COLOR_CACHE.get(c);
- if (cachedColor == null) {
- cachedColor = new org.eclipse.swt.graphics.Color(device,c.getRed(),c.getGreen(),c.getBlue());
- COLOR_CACHE.put(c,cachedColor);
- }
- gc.setForeground(cachedColor);
- }
-
- public void setColor(org.eclipse.swt.graphics.Color c) {
- gc.setForeground(c);
- }
-
- public void setBackground(Color c) {
- org.eclipse.swt.graphics.Color cachedColor = (org.eclipse.swt.graphics.Color)COLOR_CACHE.get(c);
- if (cachedColor == null) {
- cachedColor = new org.eclipse.swt.graphics.Color(device,c.getRed(),c.getGreen(),c.getBlue());
- COLOR_CACHE.put(c,cachedColor);
- }
- gc.setBackground(cachedColor);
- }
-
- public void setBackground(org.eclipse.swt.graphics.Color c) {
- gc.setBackground(c);
- }
-
- public Color getBackground() {
- org.eclipse.swt.graphics.Color color = gc.getBackground();
- Color awtColor = new Color(color.getRed(),color.getGreen(),color.getBlue());
- return awtColor;
- }
-
- ////////////////
- // FONT METHODS
- ////////////////
-
- public org.eclipse.swt.graphics.Font getSWTFont() {
- return curFont;
- }
-
- public org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics() {
- gc.setFont(curFont);
- return gc.getFontMetrics();
- }
-
- public Font getFont() {
- if (curFont != null) {
- int style = Font.PLAIN;
-
- FontData[] fd = curFont.getFontData();
- if (fd.length > 0) {
- if ((fd[0].getStyle() & SWT.BOLD) != 0) {
- style = style | Font.BOLD;
- }
- if ((fd[0].getStyle() & SWT.ITALIC) != 0) {
- style = style | SWT.ITALIC;
- }
-
- return new Font(fd[0].getName(),style,fd[0].height);
- }
- return null;
- }
- else {
- return null;
- }
- }
-
- public void setFont(Font font) {
- String fontString = "name="+font.getFamily()+";bold="+font.isBold()+";italic="+font.isItalic()+";size="+font.getSize();
-
- curFont = getFont(fontString);
- }
-
- public void setFont(org.eclipse.swt.graphics.Font font) {
- curFont = font;
- }
-
- public org.eclipse.swt.graphics.Font getFont(String fontString) {
- org.eclipse.swt.graphics.Font cachedFont = (org.eclipse.swt.graphics.Font)FONT_CACHE.get(fontString);
- if (cachedFont == null) {
- int style = 0;
- if (fontString.indexOf("bold=true") != -1) {
- style = style | SWT.BOLD;
- }
- if (fontString.indexOf("italic=true") != -1) {
- style = style | SWT.ITALIC;
- }
-
- String name = fontString.substring(0,fontString.indexOf(";"));
- String size = fontString.substring(fontString.lastIndexOf(";")+1,fontString.length());
- int sizeInt = 12;
- try {
- sizeInt = Integer.parseInt(size.substring(size.indexOf("=")+1,size.length()));
- }
- catch (Exception e) {e.printStackTrace();}
-
- cachedFont = new org.eclipse.swt.graphics.Font(device,name.substring(name.indexOf("=")+1,name.length()),sizeInt,style);
- FONT_CACHE.put(fontString,cachedFont);
- }
- return cachedFont;
- }
-
- protected org.eclipse.swt.graphics.Font getTransformedFont() {
- if (curFont != null) {
- FontData fontData = curFont.getFontData()[0];
- int height = fontData.getHeight();
- RECT.setRect(0,0,height,height);
- SWTShapeManager.transform(RECT,transform);
- height = (int)(RECT.getHeight()+0.5);
-
- String fontString = "name="+fontData.getName()+";bold="+((fontData.getStyle() & SWT.BOLD) != 0)+";italic="+((fontData.getStyle() & SWT.ITALIC) != 0)+";size="+height;
- return getFont(fontString);
- }
- return null;
- }
-
- ///////////////////////////
- // AFFINE TRANSFORM METHODS
- ///////////////////////////
-
- public void translate(int x, int y) {
- transform.translate(x,y);
- }
-
- public void translate(double tx, double ty) {
- transform.translate(tx,ty);
- }
-
- public void rotate(double theta) {
- transform.rotate(theta);
- }
-
- public void rotate(double theta, double x, double y) {
- transform.rotate(theta,x,y);
- }
-
- public void scale(double sx, double sy) {
- transform.scale(sx,sy);
- }
-
- public void shear(double shx, double shy) {
- transform.shear(shx,shy);
- }
-
- public void transform(AffineTransform Tx) {
- transform.concatenate(Tx);
- }
-
- public void setTransform(AffineTransform Tx) {
- transform = (AffineTransform)Tx.clone();
- }
-
- public AffineTransform getTransform() {
- return (AffineTransform)transform.clone();
- }
-
- ///////////////////////////////
- // DRAWING AND FILLING METHODS
- ///////////////////////////////
-
- public void clearRect(int x, int y, int width, int height) {
- fillRect(x,y,width,height);
- }
-
- public void draw(Shape s) {
- if (s instanceof Rectangle2D) {
- Rectangle2D r2 = (Rectangle2D)s;
- drawRect(r2.getX(),r2.getY(),r2.getWidth(),r2.getHeight());
- }
- else if (s instanceof Ellipse2D) {
- Ellipse2D e2 = (Ellipse2D)s;
- drawOval(e2.getX(),e2.getY(),e2.getWidth(),e2.getHeight());
- }
- else if (s instanceof RoundRectangle2D) {
- RoundRectangle2D r2 = (RoundRectangle2D)s;
- drawRoundRect(r2.getX(),r2.getY(),r2.getWidth(),r2.getHeight(),r2.getArcWidth(),r2.getArcHeight());
- }
- else if (s instanceof Arc2D) {
- Arc2D a2 = (Arc2D)s;
- drawArc(a2.getX(),a2.getY(),a2.getWidth(),a2.getHeight(),a2.getAngleStart(),a2.getAngleExtent());
- }
- else {
- double[] pts = (double[])SHAPE_CACHE.get(s);
-
- if (pts == null) {
- pts = SWTShapeManager.shapeToPolyline(s);
- SHAPE_CACHE.put(s,pts);
- }
-
- drawPolyline(pts);
- }
- }
-
- public void fill(Shape s) {
- if (s instanceof Rectangle2D) {
- Rectangle2D r2 = (Rectangle2D)s;
- fillRect(r2.getX(),r2.getY(),r2.getWidth(),r2.getHeight());
- }
- else if (s instanceof Ellipse2D) {
- Ellipse2D e2 = (Ellipse2D)s;
- fillOval(e2.getX(),e2.getY(),e2.getWidth(),e2.getHeight());
- }
- else if (s instanceof RoundRectangle2D) {
- RoundRectangle2D r2 = (RoundRectangle2D)s;
- fillRoundRect(r2.getX(),r2.getY(),r2.getWidth(),r2.getHeight(),r2.getArcWidth(),r2.getArcHeight());
- }
- else if (s instanceof Arc2D) {
- Arc2D a2 = (Arc2D)s;
- fillArc(a2.getX(),a2.getY(),a2.getWidth(),a2.getHeight(),a2.getAngleStart(),a2.getAngleExtent());
- }
- else {
- double[] pts = (double[])SHAPE_CACHE.get(s);
-
- if (pts == null) {
- pts = SWTShapeManager.shapeToPolyline(s);
- SHAPE_CACHE.put(s,pts);
- }
-
- fillPolygon(pts);
- }
- }
-
- public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
- int[] ptArray = new int[2*nPoints];
- for(int i=0; i i=FONT_CACHE.values().iterator(); i.hasNext();) {
- org.eclipse.swt.graphics.Font font = (org.eclipse.swt.graphics.Font)i.next();
- font.dispose();
- }
- for(Iterator i=COLOR_CACHE.values().iterator(); i.hasNext();) {
- org.eclipse.swt.graphics.Color color = (org.eclipse.swt.graphics.Color)i.next();
- color.dispose();
- }
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java b/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java
deleted file mode 100755
index 41a7655..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * @author Lance Good
- */
-public class SWTShapeManager {
-
- static AffineTransform IDENTITY_XFORM = new AffineTransform();
- static Point2D aPoint = new Point2D.Double();
- static ArrayList segList = new ArrayList();
- static double[] pts = new double[8];
-
-
- /**
- * Apply the specified transform to the specified rectangle, modifying the rect.
- * @param rect The rectangle to be transformed
- * @param at The transform to use to transform the rectangle
- */
- public static void transform(Rectangle2D rect, AffineTransform at) {
- // First, transform all 4 corners of the rectangle
- pts[0] = rect.getX(); // top left corner
- pts[1] = rect.getY();
- pts[2] = rect.getX() + rect.getWidth(); // top right corner
- pts[3] = rect.getY();
- pts[4] = rect.getX() + rect.getWidth(); // bottom right corner
- pts[5] = rect.getY() + rect.getHeight();
- pts[6] = rect.getX(); // bottom left corner
- pts[7] = rect.getY() + rect.getHeight();
- at.transform(pts, 0, pts, 0, 4);
-
- // Then, find the bounds of those 4 transformed points.
- double minX = pts[0];
- double minY = pts[1];
- double maxX = pts[0];
- double maxY = pts[1];
- int i;
- for (i=1; i<4; i++) {
- if (pts[2*i] < minX) {
- minX = pts[2*i];
- }
- if (pts[2*i+1] < minY) {
- minY = pts[2*i+1];
- }
- if (pts[2*i] > maxX) {
- maxX = pts[2*i];
- }
- if (pts[2*i+1] > maxY) {
- maxY = pts[2*i+1];
- }
- }
- rect.setRect(minX, minY, maxX - minX, maxY - minY);
- }
-
- public static void awtToSWT(Rectangle2D aRect, Rectangle sRect) {
- sRect.x = (int)(aRect.getX()+0.5);
- sRect.y = (int)(aRect.getY()+0.5);
- sRect.width = (int)(aRect.getWidth()+0.5);
- sRect.height = (int)(aRect.getHeight()+0.5);
- }
-
- public static double[] shapeToPolyline(Shape s) {
- segList.clear();
- aPoint.setLocation(0,0);
-
- PathIterator pi = s.getPathIterator(IDENTITY_XFORM,0.000000001);
- while (!pi.isDone()) {
- int segType = pi.currentSegment(pts);
- switch (segType) {
- case PathIterator.SEG_MOVETO:
- aPoint.setLocation(pts[0],pts[1]);
- segList.add(new Point2D.Double(pts[0],pts[1]));
- break;
- case PathIterator.SEG_LINETO:
- segList.add(new Point2D.Double(pts[0],pts[1]));
- break;
- case PathIterator.SEG_CLOSE:
- segList.add(new Point2D.Double(aPoint.getX(),aPoint.getY()));
- break;
- }
- pi.next();
- }
-
- double[] polyObj = new double[2*segList.size()];
- for(int i=0; i=0; i-=2) {
- if (listeners[i]==ActionListener.class) {
- ((ActionListener)listeners[i+1]).actionPerformed(e);
- }
- }
- }
-
-
- /**
- * Returns the timer queue.
- */
- SWTTimerQueue timerQueue() {
- return SWTTimerQueue.sharedInstance(display);
- }
-
-
- /**
- * Sets the Timer
's delay, the number of milliseconds
- * between successive action events.
- *
- * @param delay the delay in milliseconds
- * @see #setInitialDelay
- */
- public void setDelay(int delay) {
- if (delay < 0) {
- throw new IllegalArgumentException("Invalid delay: " + delay);
- }
- else {
- this.delay = delay;
- }
- }
-
-
- /**
- * Returns the delay, in milliseconds,
- * between firings of action events.
- *
- * @see #setDelay
- * @see #getInitialDelay
- */
- public int getDelay() {
- return delay;
- }
-
-
- /**
- * Sets the Timer
's initial delay,
- * which by default is the same as the between-event delay.
- * This is used only for the first action event.
- * Subsequent action events are spaced
- * using the delay property.
- *
- * @param initialDelay the delay, in milliseconds,
- * between the invocation of the start
- * method and the first action event
- * fired by this timer
- *
- * @see #setDelay
- */
- public void setInitialDelay(int initialDelay) {
- if (initialDelay < 0) {
- throw new IllegalArgumentException("Invalid initial delay: " +
- initialDelay);
- }
- else {
- this.initialDelay = initialDelay;
- }
- }
-
-
- /**
- * Returns the Timer
's initial delay.
- *
- * @see #setInitialDelay
- * @see #setDelay
- */
- public int getInitialDelay() {
- return initialDelay;
- }
-
-
- /**
- * If flag
is false
,
- * instructs the Timer
to send only one
- * action event to its listeners.
- *
- * @param flag specify false
to make the timer
- * stop after sending its first action event
- */
- public void setRepeats(boolean flag) {
- repeats = flag;
- }
-
-
- /**
- * Returns true
(the default)
- * if the Timer
will send
- * an action event
- * to its listeners multiple times.
- *
- * @see #setRepeats
- */
- public boolean isRepeats() {
- return repeats;
- }
-
-
- /**
- * Sets whether the Timer
coalesces multiple pending
- * ActionEvent
firings.
- * A busy application may not be able
- * to keep up with a Timer
's event generation,
- * causing multiple
- * action events to be queued. When processed,
- * the application sends these events one after the other, causing the
- * Timer
's listeners to receive a sequence of
- * events with no delay between them. Coalescing avoids this situation
- * by reducing multiple pending events to a single event.
- * Timer
s
- * coalesce events by default.
- *
- * @param flag specify false
to turn off coalescing
- */
- public void setCoalesce(boolean flag) {
- boolean old = coalesce;
- coalesce = flag;
- if (!old && coalesce) {
- // We must do this as otherwise if the Timer once notified
- // in !coalese mode notify will be stuck to true and never
- // become false.
- cancelEventOverride();
- }
- }
-
-
- /**
- * Returns true
if the Timer
coalesces
- * multiple pending action events.
- *
- * @see #setCoalesce
- */
- public boolean isCoalesce() {
- return coalesce;
- }
-
-
- /**
- * Starts the Timer
,
- * causing it to start sending action events
- * to its listeners.
- *
- * @see #stop
- */
- public void start() {
- timerQueue().addTimer(this,
- System.currentTimeMillis() + getInitialDelay());
- }
-
-
- /**
- * Returns true
if the Timer
is running.
- *
- * @see #start
- */
- public boolean isRunning() {
- return timerQueue().containsTimer(this);
- }
-
-
- /**
- * Stops the Timer
,
- * causing it to stop sending action events
- * to its listeners.
- *
- * @see #start
- */
- public void stop() {
- timerQueue().removeTimer(this);
- cancelEventOverride();
- }
-
-
- /**
- * Restarts the Timer
,
- * canceling any pending firings and causing
- * it to fire with its initial delay.
- */
- public void restart() {
- stop();
- start();
- }
-
-
- /**
- * Resets the internal state to indicate this Timer shouldn't notify
- * any of its listeners. This does not stop a repeatable Timer from
- * firing again, use stop
for that.
- */
- synchronized void cancelEventOverride() {
- notify = false;
- }
-
-
- synchronized void postOverride() {
- if (notify == false || !coalesce) {
- notify = true;
- display.asyncExec(doPostEvent);
- }
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java b/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java
deleted file mode 100755
index cc158b2..0000000
--- a/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java
+++ /dev/null
@@ -1,268 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import org.eclipse.swt.widgets.Display;
-
-/**
- * @author Lance Good
- */
-public class SWTTimerQueue implements Runnable {
- static SWTTimerQueue instance;
-
- Display display = null;
-
- SWTTimer firstTimer;
- boolean running;
-
- /**
- * Constructor for TimerQueue.
- */
- public SWTTimerQueue(Display display) {
- super();
-
- this.display = display;
-
- // Now start the TimerQueue thread.
- start();
- }
-
-
- public static SWTTimerQueue sharedInstance(Display display) {
- if (instance == null) {
- instance = new SWTTimerQueue(display);
- }
- return instance;
- }
-
-
- synchronized void start() {
- if (running) {
- throw new RuntimeException("Can't start a TimerQueue " +
- "that is already running");
- }
- else {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- Thread timerThread = new Thread(SWTTimerQueue.this,
- "TimerQueue");
- timerThread.setDaemon(true);
- timerThread.setPriority(Thread.NORM_PRIORITY);
- timerThread.start();
- }
- });
- running = true;
- }
- }
-
-
- synchronized void stop() {
- running = false;
- notify();
- }
-
-
- synchronized void addTimer(SWTTimer timer, long expirationTime) {
- SWTTimer previousTimer;
- SWTTimer nextTimer;
-
- // If the Timer is already in the queue, then ignore the add.
- if (timer.running) {
- return;
- }
-
- previousTimer = null;
- nextTimer = firstTimer;
-
- // Insert the Timer into the linked list in the order they will
- // expire. If two timers expire at the same time, put the newer entry
- // later so they expire in the order they came in.
-
- while (nextTimer != null) {
- if (nextTimer.expirationTime > expirationTime) break;
-
- previousTimer = nextTimer;
- nextTimer = nextTimer.nextTimer;
- }
-
- if (previousTimer == null) {
- firstTimer = timer;
- }
- else {
- previousTimer.nextTimer = timer;
- }
-
- timer.expirationTime = expirationTime;
- timer.nextTimer = nextTimer;
- timer.running = true;
- notify();
- }
-
-
- synchronized void removeTimer(SWTTimer timer) {
- SWTTimer previousTimer;
- SWTTimer nextTimer;
- boolean found;
-
- if (!timer.running) return;
-
- previousTimer = null;
- nextTimer = firstTimer;
- found = false;
-
- while (nextTimer != null) {
- if (nextTimer == timer) {
- found = true;
- break;
- }
-
- previousTimer = nextTimer;
- nextTimer = nextTimer.nextTimer;
- }
-
- if (!found) return;
-
- if (previousTimer == null) {
- firstTimer = timer.nextTimer;
- }
- else {
- previousTimer.nextTimer = timer.nextTimer;
- }
-
- timer.expirationTime = 0;
- timer.nextTimer = null;
- timer.running = false;
- }
-
-
- synchronized boolean containsTimer(SWTTimer timer) {
- return timer.running;
- }
-
-
- /**
- * If there are a ton of timers, this method may never return. It loops
- * checking to see if the head of the Timer list has expired. If it has,
- * it posts the Timer and reschedules it if necessary.
- */
- synchronized long postExpiredTimers() {
- SWTTimer timer;
- long currentTime;
- long timeToWait;
-
- // The timeToWait we return should never be negative and only be zero
- // when we have no Timers to wait for.
-
- do {
- timer = firstTimer;
- if (timer == null) return 0;
-
- currentTime = System.currentTimeMillis();
- timeToWait = timer.expirationTime - currentTime;
-
- if (timeToWait <= 0) {
- try {
- timer.postOverride(); // have timer post an event
- }
- catch (SecurityException e) {
- }
-
- // Remove the timer from the queue
- removeTimer(timer);
-
- // This tries to keep the interval uniform at
- // the cost of drift.
- if (timer.isRepeats()) {
- addTimer(timer, currentTime + timer.getDelay());
- }
-
- // Allow other threads to call addTimer() and removeTimer()
- // even when we are posting Timers like mad. Since the wait()
- // releases the lock, be sure not to maintain any state
- // between iterations of the loop.
-
- try {
- wait(1);
- }
- catch (InterruptedException e) {
- }
- }
- } while (timeToWait <= 0);
-
- return timeToWait;
- }
-
-
- public synchronized void run() {
- long timeToWait;
-
- try {
- while (running) {
- timeToWait = postExpiredTimers();
- try {
- wait(timeToWait);
- }
- catch (InterruptedException e) {
- }
- }
- }
- catch (ThreadDeath td) {
- running = false;
- // Mark all the timers we contain as not being queued.
- SWTTimer timer = firstTimer;
- while (timer != null) {
- timer.cancelEventOverride();
- timer = timer.nextTimer;
- }
- display.asyncExec(new SWTTimerQueueRestart(display));
- throw td;
- }
- }
-
-
- public synchronized String toString() {
- StringBuffer buf;
- SWTTimer nextTimer;
-
- buf = new StringBuffer();
- buf.append("TimerQueue (");
-
- nextTimer = firstTimer;
- while (nextTimer != null) {
- buf.append(nextTimer.toString());
-
- nextTimer = nextTimer.nextTimer;
- if (nextTimer != null) buf.append(", ");
- }
-
- buf.append(")");
- return buf.toString();
- }
-
-
- /**
- * Runnable that will message the shared instance of the Timer Queue
- * to restart.
- */
- protected static class SWTTimerQueueRestart implements Runnable {
- boolean attemptedStart;
-
- Display display = null;
-
- public SWTTimerQueueRestart(Display display) {
- this.display = display;
- }
-
- public synchronized void run() {
- // Only try and restart the q once.
- if(!attemptedStart) {
- SWTTimerQueue q = SWTTimerQueue.sharedInstance(display);
-
- synchronized(q) {
- if(!q.running)
- q.start();
- }
- attemptedStart = true;
- }
- }
- }
-
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/LineShape.java b/src/main/java/edu/umd/cs/piccolox/util/LineShape.java
deleted file mode 100755
index 272188f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/LineShape.java
+++ /dev/null
@@ -1,264 +0,0 @@
-package edu.umd.cs.piccolox.util;
-
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-public class LineShape implements Shape, MutablePoints
-{
- private MutablePoints points;
- private Rectangle2D bounds = new Rectangle2D.Double();
-
- public LineShape(MutablePoints points) {
- setPoints(points);
- }
-
- public void setPoints(MutablePoints points) {
- if (points == null) {
- points = new XYArray();
- }
- this.points = points;
- }
-
- // from Points
-
- public int getPointCount() {
- return points.getPointCount();
- }
-
- public double getX(int i) { return points.getX(i); }
- public double getY(int i) { return points.getY(i); }
-
- public Point2D getPoint(int i, Point2D dst) {
- return points.getPoint(i, dst);
- }
-
- public Rectangle2D getBounds(Rectangle2D dst) {
- points.getBounds(dst);
- return dst;
- }
-
- // from MutablePoints
-
- public void updateBounds() {
- bounds.setRect(0.0d, 0.0d, 0.0d, 0.0d);
- points.getBounds(bounds);
- }
-
- public void setPoint(int i, double x, double y) {
- points.setPoint(i, x, y);
- updateBounds();
- }
-
- public void addPoint(int pos, double x, double y) {
- points.addPoint(pos, x, y);
- updateBounds();
- }
-
- public void removePoints(int pos, int num) {
- points.removePoints(pos, num);
- updateBounds();
- }
-
- public void transformPoints(AffineTransform trans) {
- XYArray newPoints = new XYArray(points.getPointCount());
- newPoints.appendPoints(points);
- newPoints.transformPoints(trans);
- points = newPoints;
- }
-
- //
-
- public Rectangle getBounds() {
- return new Rectangle((int)bounds.getX(), (int)bounds.getY(), (int)bounds.getWidth(), (int)bounds.getHeight());
- }
-
- public Rectangle2D getBounds2D() {
- return bounds;
- }
-
- public static boolean contains(double x, double y, double x1, double y1, double x2, double y2,
- boolean min, boolean max,
- double d)
- {
- double dx = x2 - x1, dy = y2 - y1;
- double dx2 = dx * dx, dy2 = dy * dy;
- double p;
- if (dx != 0) {
- p = (((x - x1) / dx) + ((dy * (y - y1)) / dx2)) / (1 + (dy2 / dx2));
- }
- else if (dy != 0) {
- p = (((y - y1) / dy) + ((dx * (x - x1)) / dy2)) / (1 + (dx2 / dy2));
- }
- else {
- return false;
- }
- if (max && p > 1.0) {
- return false;
- }
- else if (min && p < 0.0) {
- return false;
- }
- dx = (p * dx) + x1 - x; dy = (p * dy) + y1 - y;
- double len = dx * dx + dy * dy;
- return (len < d);
- }
-
- public boolean contains(double x, double y, double d) {
- double x1, y1, x2, y2;
- if (points.getPointCount() == 0) {
- return false;
- }
- x2 = points.getX(0);
- y2 = points.getX(0);
- for (int i = 0; i < points.getPointCount(); i++) {
- x1 = x2;
- y1 = y2;
- x2 = points.getX(i);
- y2 = points.getX(i);
- if (contains(x, y, x1, y1, x2, y2, false, false, d)) {
- return true;
- }
- }
- return false;
- }
- public boolean contains(double x, double y) {
- return contains(x, y, 2.0d);
- }
-
- public boolean contains(Point2D p) {
- return contains(p.getX(), p.getY());
- }
-
- public static boolean intersects(double x1, double y1, double x2, double y2,
- double x3, double y3, double x4, double y4,
- boolean min1, boolean max1,
- boolean min2, boolean max2)
- {
- double dx1 = x2 - x1, dy1 = y2 - y1, dx2 = x4 - x3, dy2 = y4 - y3;
- double d, p2, p1;
-
- if (dy1 != 0.0) {
- d = dx1 / dy1;
- p2 = (x3 - x1 + (d * (y1 - y3))) / ((d * dy2) - dx2);
- p1 = (dy2 * p2 + y3 - y1) / dy1;
- }
- else if (dy2 != 0.0) {
- d = dx2 / dy2;
- p1 = (x1 - x3 + (d * (y3 - y1))) / ((d * dy1) - dx1);
- p2 = (dy1 * p1 + y1 - y3) / dy2;
- }
- else if (dx1 != 0.0) {
- d = dy1 / dx1;
- p2 = (y3 - y1 + (d * (x1 - x3))) / ((d * dx2) - dy2);
- p1 = (dx2 * p2 + x3 - x1) / dx1;
- }
- else if (dx2 != 0.0) {
- d = dy2 / dx2;
- p1 = (y1 - y3 + (d * (x3 - x1))) / ((d * dx1) - dy1);
- p2 = (dx1 * p1 + x1 - x3) / dx2;
- }
- else {
- return false;
- }
- return (((! min1) || (p1 >= 0.0)) && ((! max1) || (p1 <= 1.0)) &&
- ((! min2) || (p2 >= 0.0)) && ((! max2) || (p2 <= 1.0)));
- }
-
- public boolean intersects(double x, double y, double w, double h) {
- double x1, y1, x2, y2;
- if (points.getPointCount() == 0) {
- return false;
- }
- x2 = points.getX(0);
- y2 = points.getY(0);
- for (int i = 0; i < points.getPointCount(); i++) {
- x1 = x2;
- y1 = y2;
- x2 = points.getX(i);
- y2 = points.getY(i);
- if (intersects(x, y, x + w, y, x1, y1, x2, y2, true, true, true, true) ||
- intersects(x + w, y, x + w, y + h, x1, y1, x2, y2, true, true, true, true) ||
- intersects(x + w, y + h, x, y + h, x1, y1, x2, y2, true, true, true, true) ||
- intersects(x, y + h, x, y, x1, y1, x2, y2, true, true, true, true)) {
- return true;
- }
- }
- return false;
- }
-
- public boolean intersects(Rectangle2D r) {
- return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
- }
-
- public boolean contains(double x, double y, double w, double h) {
- return contains(x, y) && contains(x + w, y) && contains(x, y + h) && contains(x + w, y + h);
- }
-
- public boolean contains(Rectangle2D r) {
- return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
- }
-
- //
-
- //
-
- public PathIterator getPathIterator(AffineTransform at) {
- return new LinePathIterator(points, at);
- }
-
- public PathIterator getPathIterator(AffineTransform at, double flatness) {
- return new LinePathIterator(points, at);
- }
-
- private static class LinePathIterator implements PathIterator {
-
- private Points points;
- private AffineTransform trans;
- private int i = 0;
-
- public LinePathIterator(Points points, AffineTransform trans) {
- this.points = points;
- this.trans = trans;
- }
-
- public int getWindingRule() {
- return GeneralPath.WIND_EVEN_ODD;
- }
-
- public boolean isDone() {
- return i >= points.getPointCount();
- }
-
- public void next() {
- i++;
- }
-
- private Point2D tempPoint = new Point2D.Double();
-
- private void currentSegment() {
- tempPoint.setLocation(points.getX(i), points.getY(i));
- if (trans != null) {
- trans.transform(tempPoint, tempPoint);
- }
- }
-
- public int currentSegment(float[] coords) {
- currentSegment();
- coords[0] = (float)tempPoint.getX();
- coords[1] = (float)tempPoint.getY();
- return (i == 0 ? PathIterator.SEG_MOVETO : PathIterator.SEG_LINETO);
- }
-
- public int currentSegment(double[] coords) {
- currentSegment();
- coords[0] = tempPoint.getX();
- coords[1] = tempPoint.getY();
- return (i == 0 ? PathIterator.SEG_MOVETO : PathIterator.SEG_LINETO);
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java b/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java
deleted file mode 100755
index 42a6ed3..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package edu.umd.cs.piccolox.util;
-
-import java.awt.geom.AffineTransform;
-
-public interface MutablePoints extends Points
-{
- public void setPoint(int i, double x, double y);
- public void addPoint(int pos, double x, double y);
- public void removePoints(int pos, int num);
- public void transformPoints(AffineTransform t);
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java b/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java
deleted file mode 100755
index 0527af5..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.util;
-
-import java.awt.geom.Rectangle2D;
-
-import javax.swing.SwingConstants;
-
-import edu.umd.cs.piccolo.PNode;
-
-/**
- * PBoundsLocator is a locator that locates points on the
- * bounds of a node.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PBoundsLocator extends PNodeLocator {
-
- /**
- *
- */
- private static final long serialVersionUID = 4475874959685465872L;
- private int side;
-
- public static PBoundsLocator createCenterLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.CENTER);
- }
-
- public static PBoundsLocator createEastLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.EAST);
- }
-
- public static PBoundsLocator createNorthEastLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.NORTH_EAST);
- }
-
- public static PBoundsLocator createNorthWestLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.NORTH_WEST);
- }
-
- public static PBoundsLocator createNorthLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.NORTH);
- }
-
- public static PBoundsLocator createSouthLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.SOUTH);
- }
-
- public static PBoundsLocator createWestLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.WEST);
- }
-
- public static PBoundsLocator createSouthWestLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.SOUTH_WEST);
- }
-
- public static PBoundsLocator createSouthEastLocator(PNode node) {
- return new PBoundsLocator(node, SwingConstants.SOUTH_EAST);
- }
-
- public PBoundsLocator(PNode node, int aSide) {
- super(node);
- side = aSide;
- }
-
- public int getSide() {
- return side;
- }
-
- public void setSide(int side) {
- this.side = side;
- }
-
- public double locateX() {
- Rectangle2D aBounds = node.getBoundsReference();
-
- switch (side) {
- case SwingConstants.NORTH_WEST :
- case SwingConstants.SOUTH_WEST :
- case SwingConstants.WEST :
- return aBounds.getX();
-
- case SwingConstants.NORTH_EAST :
- case SwingConstants.SOUTH_EAST :
- case SwingConstants.EAST :
- return aBounds.getX() + aBounds.getWidth();
-
- case SwingConstants.NORTH :
- case SwingConstants.SOUTH :
- case SwingConstants.CENTER :
- return aBounds.getX() + (aBounds.getWidth() / 2);
- }
- return -1;
- }
-
- public double locateY() {
- Rectangle2D aBounds = node.getBoundsReference();
-
- switch (side) {
- case SwingConstants.EAST :
- case SwingConstants.WEST :
- case SwingConstants.CENTER :
- return aBounds.getY() + (aBounds.getHeight() / 2);
-
- case SwingConstants.SOUTH :
- case SwingConstants.SOUTH_WEST :
- case SwingConstants.SOUTH_EAST :
- return aBounds.getY() + aBounds.getHeight();
-
- case SwingConstants.NORTH_WEST :
- case SwingConstants.NORTH_EAST :
- case SwingConstants.NORTH :
- return aBounds.getY();
- }
- return -1;
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java b/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java
deleted file mode 100755
index f7e503f..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.util;
-
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Rectangle2D;
-import java.io.Serializable;
-
-import sun.dc.path.FastPathProducer;
-import sun.dc.path.PathConsumer;
-import sun.dc.path.PathException;
-import sun.dc.pr.PathDasher;
-import sun.dc.pr.PathStroker;
-import sun.dc.pr.Rasterizer;
-
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PDebug;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * PFixedWidthStroke is the same as java.awt.BasicStroke except that PFixedWidthStroke
- * has a fixed width on the screen so that even when the canvas view is zooming its
- * width stays the same in canvas coordinates. Note that this stroke draws in the inside of
- * the stroked shape, instead of the normal draw on center behavior.
- *
- * @see edu.umd.cs.piccolo.nodes.PPath
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PFixedWidthStroke implements Stroke, Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 6530057357716931107L;
- private static PAffineTransform TEMP_TRANSFORM = new PAffineTransform();
- private static GeneralPath TEMP_PATH = new GeneralPath(GeneralPath.WIND_NON_ZERO);
-
- public final static int JOIN_MITER = 0;
- public final static int JOIN_ROUND = 1;
- public final static int JOIN_BEVEL = 2;
- public final static int CAP_BUTT = 0;
- public final static int CAP_ROUND = 1;
- public final static int CAP_SQUARE = 2;
-
- private float width;
- private int join;
- private int cap;
- private float miterlimit;
- private float dash[];
- private float dash_phase;
-
- public static final int RasterizerCaps[] = {
- Rasterizer.BUTT, Rasterizer.ROUND, Rasterizer.SQUARE
- };
-
- public static final int RasterizerCorners[] = {
- Rasterizer.MITER, Rasterizer.ROUND, Rasterizer.BEVEL
- };
-
- public class FillAdapter implements PathConsumer {
- boolean closed;
- GeneralPath path;
-
- public FillAdapter() {
- path = TEMP_PATH;
- path.reset();
- }
-
- public Shape getShape() {
- return path;
- }
-
- public void beginPath() {}
-
- public void beginSubpath(float x0, float y0) {
- if (closed) {
- path.closePath();
- closed = false;
- }
- path.moveTo(x0, y0);
- }
-
- public void appendLine(float x1, float y1) {
- path.lineTo(x1, y1);
- }
-
- public void appendQuadratic(float xm, float ym, float x1, float y1) {
- path.quadTo(xm, ym, x1, y1);
- }
-
- public void appendCubic(float xm, float ym,
- float xn, float yn,
- float x1, float y1) {
- path.curveTo(xm, ym, xn, yn, x1, y1);
- }
-
- public void closedSubpath() {
- closed = true;
- }
-
- public void endPath() {
- if (closed) {
- path.closePath();
- closed = false;
- }
- }
-
- public void useProxy(FastPathProducer proxy)
- throws PathException {
- proxy.sendTo(this);
- }
-
- public long getCPathConsumer() {
- return 0;
- }
-
- public void dispose() {
- }
-
- public PathConsumer getConsumer() {
- return null;
- }
- }
-
- public PFixedWidthStroke() {
- this(1.0f, CAP_SQUARE, JOIN_MITER, 10.0f, null, 0.0f);
- }
-
- public PFixedWidthStroke(float width) {
- this(width, CAP_SQUARE, JOIN_MITER, 10.0f, null, 0.0f);
- }
-
- public PFixedWidthStroke(float width, int cap, int join) {
- this(width, cap, join, 10.0f, null, 0.0f);
- }
-
- public PFixedWidthStroke(float width, int cap, int join, float miterlimit) {
- this(width, cap, join, miterlimit, null, 0.0f);
- }
-
- public PFixedWidthStroke(float width, int cap, int join, float miterlimit, float dash[], float dash_phase) {
- if (width < 0.0f) {
- throw new IllegalArgumentException("negative width");
- }
- if (cap != CAP_BUTT && cap != CAP_ROUND && cap != CAP_SQUARE) {
- throw new IllegalArgumentException("illegal end cap value");
- }
- if (join == JOIN_MITER) {
- if (miterlimit < 1.0f) {
- throw new IllegalArgumentException("miter limit < 1");
- }
- } else if (join != JOIN_ROUND && join != JOIN_BEVEL) {
- throw new IllegalArgumentException("illegal line join value");
- }
- if (dash != null) {
- if (dash_phase < 0.0f) {
- throw new IllegalArgumentException("negative dash phase");
- }
- boolean allzero = true;
- for (int i = 0; i < dash.length; i++) {
- float d = dash[i];
- if (d > 0.0) {
- allzero = false;
- } else if (d < 0.0) {
- throw new IllegalArgumentException("negative dash length");
- }
- }
-
- if (allzero) {
- throw new IllegalArgumentException("dash lengths all zero");
- }
- }
- this.width = width;
- this.cap = cap;
- this.join = join;
- this.miterlimit = miterlimit;
- if (dash != null) {
- this.dash = (float []) dash.clone();
- }
- this.dash_phase = dash_phase;
- }
-
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public Shape createStrokedShape(Shape s) {
- FillAdapter filler = new FillAdapter();
- PathStroker stroker = new PathStroker(filler);
- PathConsumer consumer;
-
- // Fixed Width Additions, always stroke path inside shape.
- // Also keeps dashes fixed when zooming (thanks to Shawn Castrianni - Dec 2006)
- float fixedScale = 1.0f;
-
- if (PDebug.getProcessingOutput()) {
- if (PPaintContext.CURRENT_PAINT_CONTEXT != null) {
- fixedScale = 1.0f / (float)PPaintContext.CURRENT_PAINT_CONTEXT.getScale();
- }
- } else {
- if (PPickPath.CURRENT_PICK_PATH != null) {
- fixedScale = 1.0f / (float)PPickPath.CURRENT_PICK_PATH.getScale();
- }
- }
- float fixedWidth = width * fixedScale;
-
- Rectangle2D bounds = s.getBounds2D();
- double scale = 1.0;
-
- if (bounds.getWidth() > bounds.getHeight()) {
- if (bounds.getWidth() != 0) {
- scale = (bounds.getWidth()-fixedWidth)/bounds.getWidth();
- }
- } else {
- if (bounds.getHeight() != 0) {
- scale = (bounds.getHeight()-fixedWidth)/bounds.getHeight();
- }
- }
-
- TEMP_TRANSFORM.setToIdentity();
- TEMP_TRANSFORM.scaleAboutPoint(scale, bounds.getCenterX(), bounds.getCenterY());
- stroker.setPenDiameter(fixedWidth);
- PathIterator pi = s.getPathIterator(TEMP_TRANSFORM);
-
- stroker.setPenT4(null);
- stroker.setCaps(RasterizerCaps[cap]);
- stroker.setCorners(RasterizerCorners[join], miterlimit);
- if (dash != null) {
- //Fixed Width Additions
- float fixedDash[] = new float[dash.length];
- for (int i = 0; i < dash.length; i++) {
- fixedDash[i] = dash[i] * fixedScale;
- }
- float fixedDashPhase = dash_phase * fixedScale;
- PathDasher dasher = new PathDasher(stroker);
- dasher.setDash(fixedDash, fixedDashPhase);
- dasher.setDashT4(null);
- consumer = dasher;
- } else {
- consumer = stroker;
- }
-
- try {
- consumer.beginPath();
- boolean pathClosed = false;
- float mx = 0.0f;
- float my = 0.0f;
- float point[] = new float[6];
-
- while (!pi.isDone()) {
- int type = pi.currentSegment(point);
- if (pathClosed == true) {
- pathClosed = false;
- if (type != PathIterator.SEG_MOVETO) {
- // Force current point back to last moveto point
- consumer.beginSubpath(mx, my);
- }
- }
- switch (type) {
- case PathIterator.SEG_MOVETO:
- mx = point[0];
- my = point[1];
- consumer.beginSubpath(point[0], point[1]);
- break;
- case PathIterator.SEG_LINETO:
- consumer.appendLine(point[0], point[1]);
- break;
- case PathIterator.SEG_QUADTO:
- // Quadratic curves take two points
- consumer.appendQuadratic(point[0], point[1],
- point[2], point[3]);
- break;
- case PathIterator.SEG_CUBICTO:
- // Cubic curves take three points
- consumer.appendCubic(point[0], point[1],
- point[2], point[3],
- point[4], point[5]);
- break;
- case PathIterator.SEG_CLOSE:
- consumer.closedSubpath();
- pathClosed = true;
- break;
- }
- pi.next();
- }
-
- consumer.endPath();
-
- consumer.dispose(); // hack to fix memory leak, shouldn't be neccessary but is.
- } catch (PathException e) {
- throw new InternalError("Unable to Stroke shape ("+
- e.getMessage()+")");
- }
-
- return filler.getShape();
- }
-
- public boolean equals(Object obj) {
- if (!(obj instanceof PFixedWidthStroke)) {
- return false;
- }
-
- PFixedWidthStroke bs = (PFixedWidthStroke) obj;
- if (width != bs.width) {
- return false;
- }
-
- if (join != bs.join) {
- return false;
- }
-
- if (cap != bs.cap) {
- return false;
- }
-
- if (miterlimit != bs.miterlimit) {
- return false;
- }
-
- if (dash != null) {
- if (dash_phase != bs.dash_phase) {
- return false;
- }
-
- if (!java.util.Arrays.equals(dash, bs.dash)) {
- return false;
- }
- } else if (bs.dash != null) {
- return false;
- }
-
- return true;
- }
-
- public float[] getDashArray() {
- if (dash == null) {
- return null;
- }
-
- return (float[]) dash.clone();
- }
-
- public float getDashPhase() {
- return dash_phase;
- }
-
- public int getEndCap() {
- return cap;
- }
-
- public int getLineJoin() {
- return join;
- }
-
- public float getLineWidth() {
- return width;
- }
-
- public float getMiterLimit() {
- return miterlimit;
- }
-
- public int hashCode() {
- int hash = Float.floatToIntBits(width);
- hash = hash * 31 + join;
- hash = hash * 31 + cap;
- hash = hash * 31 + Float.floatToIntBits(miterlimit);
- if (dash != null) {
- hash = hash * 31 + Float.floatToIntBits(dash_phase);
- for (int i = 0; i < dash.length; i++) {
- hash = hash * 31 + Float.floatToIntBits(dash[i]);
- }
- }
- return hash;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/edu/umd/cs/piccolox/util/PLocator.java b/src/main/java/edu/umd/cs/piccolox/util/PLocator.java
deleted file mode 100755
index ee51de8..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/PLocator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.util;
-
-import java.awt.geom.Point2D;
-import java.io.Serializable;
-
-/**
- * PLocator provides an abstraction for locating points. Subclasses such
- * as PNodeLocator and PBoundsLocator specialize this behavior by locating
- * points on nodes, or on the bounds of nodes.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public abstract class PLocator implements Serializable {
-
- public PLocator() {
- }
-
- public Point2D locatePoint(Point2D aDstPoint) {
- if (aDstPoint == null) {
- aDstPoint = new Point2D.Double();
- }
- aDstPoint.setLocation(locateX(), locateY());
- return aDstPoint;
- }
-
- public abstract double locateX();
-
- public abstract double locateY();
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java b/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java
deleted file mode 100755
index d6b1b31..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */package edu.umd.cs.piccolox.util;
-
-import edu.umd.cs.piccolo.PNode;
-
-/**
- * PNodeLocator provides an abstraction for locating points on a node.
- * Points are located in the local corrdinate system of the node. The default
- * behavior is to locate the center point of the nodes bounds. The node where
- * the point is located is stored internal to this locator (as an instance
- * varriable). If you want to use the same locator to locate center points on
- * many different nodes you will need to call setNode() before asking for each
- * location.
- *
- * @version 1.0
- * @author Jesse Grosjean
- */
-public class PNodeLocator extends PLocator {
-
- /**
- *
- */
- private static final long serialVersionUID = 6914011424522333523L;
- protected PNode node;
-
- public PNodeLocator(PNode node) {
- setNode(node);
- }
-
- public PNode getNode() {
- return node;
- }
-
- public void setNode(PNode node) {
- this.node = node;
- }
-
- public double locateX() {
- return node.getBoundsReference().getCenterX();
- }
-
- public double locateY() {
- return node.getBoundsReference().getCenterY();
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java b/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java
deleted file mode 100755
index e330740..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2002-@year@, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
- * and the following disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the University of Maryland nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Piccolo was written at the Human-Computer Interaction Laboratory www.cs.umd.edu/hcil by Jesse Grosjean
- * under the supervision of Ben Bederson. The Piccolo website is www.cs.umd.edu/hcil/piccolo.
- */
-package edu.umd.cs.piccolox.util;
-
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPickPath;
-
-/**
- * Experimental class for detecting occlusions.
- *
- * @author Jesse Grosjean
- */
-public class POcclusionDetection {
-
- /**
- * Traverse from the bottom right of the scene graph (top visible node)
- * up the tree determining which parent nodes are occluded by their children
- * nodes. Note that this is only detecting a subset of occlusions (parent, child),
- * others such as overlapping siblings or cousins are not detected.
- */
- public void detectOccusions(PNode n, PBounds parentBounds) {
- detectOcclusions(n, new PPickPath(null, parentBounds));
- }
-
- public void detectOcclusions(PNode n, PPickPath pickPath) {
- if (n.fullIntersects(pickPath.getPickBounds())) {
- pickPath.pushTransform(n.getTransformReference(false));
-
- int count = n.getChildrenCount();
- for (int i = count - 1; i >= 0; i--) {
- PNode each = (PNode) n.getChild(i);
- if (n.getOccluded()) {
- // if n has been occuded by a previous decendent then
- // this child must also be occuded
- each.setOccluded(true);
- } else {
- // see if child each occludes n
- detectOcclusions(each, pickPath);
- }
- }
-
- // see if n occudes it's parents
- if (!n.getOccluded()) {
- if (n.intersects(pickPath.getPickBounds())) {
- if (n.isOpaque(pickPath.getPickBounds())) {
- PNode p = n.getParent();
- while (p != null && !p.getOccluded()) {
- p.setOccluded(true);
- }
- }
- }
- }
-
- pickPath.popTransform(n.getTransformReference(false));
- }
- }
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/Points.java b/src/main/java/edu/umd/cs/piccolox/util/Points.java
deleted file mode 100755
index 10180f7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/Points.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package edu.umd.cs.piccolox.util;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-public interface Points
-{
- public int getPointCount();
-
- public double getX(int i);
- public double getY(int i);
- public Point2D getPoint(int i, Point2D dst);
-
- public Rectangle2D getBounds(Rectangle2D dst);
-}
diff --git a/src/main/java/edu/umd/cs/piccolox/util/XYArray.java b/src/main/java/edu/umd/cs/piccolox/util/XYArray.java
deleted file mode 100755
index d8410d7..0000000
--- a/src/main/java/edu/umd/cs/piccolox/util/XYArray.java
+++ /dev/null
@@ -1,197 +0,0 @@
-package edu.umd.cs.piccolox.util;
-
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-public class XYArray implements MutablePoints
-{
- // the coordinates are stored as alternating x and y pairs
-
- private double[] points = null;
-
- // the number of valid x, y pairs,
- // i.e. not the length of the points array
-
- private int numPoints = 0;
-
- public int getPointCount() { return numPoints;}
-
- // normalize an index, negative counts from end
-
- private int i(int i) {
- if (i < 0) {
- i = numPoints + i;
- }
- if (i >= numPoints) {
- throw new IllegalArgumentException("The point index " + i + " is not below " + numPoints);
- }
- return i;
- }
-
- // various get and set methods
-
- // from Points
-
- public double getX(int i)
- {
- i = i(i);
- return points[i*2];
- }
- public double getY(int i)
- {
- i = i(i);
- return points[i*2 + 1];
- }
- public Point2D getPoint(int i, Point2D dst) {
- i = i(i);
- dst.setLocation(points[i*2], points[i*2 + 1]);
- return dst;
- }
-
- public void setX(int i, double x)
- {
- i = i(i);
- points[i*2] = x;
- }
- public void setY(int i, double y)
- {
- i = i(i);
- points[i*2 + 1] = y;
- }
-
- public void setPoint(int i, double x, double y)
- {
- i = i(i);
- points[i*2] = x;
- points[i*2 + 1] = y;
- }
-
- public void setPoint(int i, Point2D pt)
- {
- setPoint(i, pt.getX(), pt.getY());
- }
-
- public void transformPoints(AffineTransform t)
- {
- t.transform(points, 0, points, 0, numPoints);
- }
-
- public Rectangle2D getBounds(Rectangle2D dst)
- {
- int i = 0;
- if (dst.isEmpty() && getPointCount() > 0) {
- dst.setRect(getX(i), getY(i), 1.0d, 1.0d);
- i++;
- }
- while (i < getPointCount()) {
- dst.add(getX(i), getY(i));
- i++;
- }
- return dst;
- }
-
- //
-
- // initialization of points array
-
- public static double[] initPoints(double[] points, int n, double[] old)
- {
- if (points == null || n * 2 > points.length) {
- points = new double[n * 2];
- }
- if (old != null && points != old) {
- System.arraycopy(old, 0, points, 0, Math.min(old.length, n * 2));
- }
- return(points);
- }
-
- private void initPoints(double[] points, int n)
- {
- this.points = initPoints(points, n, this.points);
- numPoints = (points != null ? points.length / 2 : 0);
- }
-
- // constructors
-
- public XYArray(double[] points) {
- initPoints(points, points.length / 2);
- }
- public XYArray(int n) {
- initPoints(null, n);
- }
- public XYArray() {
- this(0);
- }
-
- // adding points to points array
-
- public void addPoints(int pos, Points pts, int start, int end)
- {
- if (end < 0) {
- end = pts.getPointCount() + end + 1;
- }
- int n = numPoints + end - start;
- points = initPoints(points, n, points);
- int pos1 = pos * 2, pos2 = (pos + end - start) * 2, len = (numPoints - pos) * 2;
- System.arraycopy(points, pos1, points, pos2, len);
- numPoints = n;
- if (pts == null) {
- return;
- }
- for (int count = 0; start < end; count++, start++) {
- setPoint(pos + count, pts.getX(start), pts.getY(start));
- }
- }
- public void addPoints(int pos, Points pts) {
- addPoints(pos, pts, 0, pts.getPointCount());
- }
-
- public void appendPoints(Points pts)
- { addPoints(numPoints, pts);}
-
- public static XYArray copyPoints(Points pts)
- {
- XYArray newList = new XYArray(pts.getPointCount());
- newList.appendPoints(pts);
- return newList;
- }
-
- // from MutablePoints
-
- public void addPoint(int pos, double x, double y)
- {
- addPoints(pos, null, 0, 1);
- setPoint(pos, x, y);
- }
-
- public void addPoint(int pos, Point2D pt)
- {
- addPoint(pos, pt.getX(), pt.getY());
- }
-
- public void removePoints(int pos, int num)
- {
- num = Math.min(num, numPoints - pos);
- if (num <= 0)
- return;
- System.arraycopy(points, (pos + num) * 2, points, pos * 2, (numPoints - (pos + num)) * 2);
- numPoints -= num;
- }
- public void removeAllPoints()
- { removePoints(0, numPoints);}
-
- //
-
- public Object clone()
- {
- XYArray ps = null;
- try { ps = (XYArray)(super.clone());}
- catch (CloneNotSupportedException e) {}
- if (ps != null) {
- ps.points = initPoints(ps.points, numPoints, points);
- ps.numPoints = numPoints;
- }
- return(ps);
- }
-}
diff --git a/src/main/java/jaist/css/covis/AnchorGarden.java b/src/main/java/jaist/css/covis/AnchorGarden.java
index b98b3f3..cca24a4 100644
--- a/src/main/java/jaist/css/covis/AnchorGarden.java
+++ b/src/main/java/jaist/css/covis/AnchorGarden.java
@@ -14,16 +14,16 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PInputManager;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.event.PInputEventListener;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PPaintContext;
-import edu.umd.cs.piccolox.event.PZoomToEventHandler;
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PInputManager;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.event.PInputEventListener;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PPaintContext;
+import org.piccolo2d.extras.event.PZoomToEventHandler;
import jaist.css.covis.cls.Covis_Object;
import jaist.css.covis.cls.Informer;
import jaist.css.covis.fm.FlowMenu_TMRG;
diff --git a/src/main/java/jaist/css/covis/CoVisBuffer.java b/src/main/java/jaist/css/covis/CoVisBuffer.java
index e9e9c5a..fc04705 100644
--- a/src/main/java/jaist/css/covis/CoVisBuffer.java
+++ b/src/main/java/jaist/css/covis/CoVisBuffer.java
@@ -9,8 +9,8 @@
import javax.swing.JCheckBox;
import javax.swing.Timer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PPath;
import jaist.css.covis.cls.Anchor;
import jaist.css.covis.cls.ClassField;
import jaist.css.covis.cls.ClassFieldMenu;
diff --git a/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java b/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java
index 9541ea6..2e8e37a 100644
--- a/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java
+++ b/src/main/java/jaist/css/covis/CoVisWindow_SelectionRegionHandler.java
@@ -9,11 +9,11 @@
import java.util.Collection;
import java.util.Hashtable;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PBounds;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PBounds;
/**
* Selectableを範囲選択
@@ -23,7 +23,7 @@
public class CoVisWindow_SelectionRegionHandler extends PDragSequenceEventHandler {
AnchorGarden viewer;
- PPath selection;
+ PPPath selection;
private Stroke[] strokes = null;
@@ -88,7 +88,7 @@
//しかし,選択範囲の赤枠はカメラにつける
cmp = e.getPositionRelativeTo(viewer.getCanvas().getCamera());
- selection = new PPath();
+ selection = new PPPath();
selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), 0, 0);
selection.setStrokePaint(Color.red);//赤
selection.setPaint(null);
diff --git a/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java b/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java
index eb03f93..eb942ff 100644
--- a/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java
+++ b/src/main/java/jaist/css/covis/CoVisWindow_ZoomRegionHandler.java
@@ -6,13 +6,13 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PAffineTransform;
-import edu.umd.cs.piccolo.util.PBounds;
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.util.PAffineTransform;
+import org.piccolo2d.util.PBounds;
import jaist.css.covis.util.BUtil;
import jaist.css.covis.util.FramePopup;
@@ -24,7 +24,7 @@
public class CoVisWindow_ZoomRegionHandler extends PDragSequenceEventHandler {
AnchorGarden viewer;
- PPath selection;
+ PPPath selection;
PNode target;
@@ -62,7 +62,7 @@
target = e.getPickedNode();
cmp = e.getPositionRelativeTo(viewer.getCanvas().getCamera());
max_ext_cp = cmp; // 初期化
- selection = new PPath();
+ selection = new PPPath();
selection.setPathToRectangle((float) cmp.getX(), (float) cmp.getY(), 0,
0);
selection.setStrokePaint(Color.blue);//青色
diff --git a/src/main/java/jaist/css/covis/CoversTransparencyControl.java b/src/main/java/jaist/css/covis/CoversTransparencyControl.java
index 0d8bc06..5e6e64e 100644
--- a/src/main/java/jaist/css/covis/CoversTransparencyControl.java
+++ b/src/main/java/jaist/css/covis/CoversTransparencyControl.java
@@ -2,7 +2,7 @@
import java.util.ArrayList;
-import edu.umd.cs.piccolo.PNode;
+import org.piccolo2d.PNode;
public class CoversTransparencyControl implements Runnable {
Thread transparencyThread = null;
diff --git a/src/main/java/jaist/css/covis/MyPPanEventHandler.java b/src/main/java/jaist/css/covis/MyPPanEventHandler.java
index b0977a1..f3a46f6 100644
--- a/src/main/java/jaist/css/covis/MyPPanEventHandler.java
+++ b/src/main/java/jaist/css/covis/MyPPanEventHandler.java
@@ -1,8 +1,8 @@
package jaist.css.covis;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.util.PDimension;
/**
* ATNWindow右上メニューの[pan]
diff --git a/src/main/java/jaist/css/covis/PPPath.java b/src/main/java/jaist/css/covis/PPPath.java
new file mode 100644
index 0000000..f1511c7
--- /dev/null
+++ b/src/main/java/jaist/css/covis/PPPath.java
@@ -0,0 +1,66 @@
+package jaist.css.covis;
+
+import java.awt.Shape;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Stroke;
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+import java.util.List;
+import java.awt.geom.Ellipse2D;
+
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PPath;
+
+/**
+ * 以前のPiccolo PPathとの互換性をとるためのクラス
+ */
+public class PPPath extends PPath.Double {
+ private static final Rectangle2D.Float TEMP_RECTANGLE = new Rectangle2D.Float();
+ private static final Ellipse2D.Float TEMP_ELLIPSE = new Ellipse2D.Float();
+ private static final BasicStroke DEFAULT_STROKE = new BasicStroke(1.0f);
+ private static final Color DEFAULT_STROKE_PAINT = Color.black;
+ private transient Stroke stroke;
+ public PPPath(){
+ super(new Path2D.Float());
+ // setStrokePaint(DEFAULT_STROKE_PAINT);
+ // setStroke(DEFAULT_STROKE);
+ setPaint(null);
+ }
+ public PPPath(Shape aShape) {
+ this(aShape, DEFAULT_STROKE);
+ }
+ public PPPath(Shape aShape, Stroke aStroke) {
+ this();
+ stroke = aStroke;
+ if (aShape != null) append(aShape, false);
+ }
+ public void setPathTo(final Shape aShape) {
+ this.getPath().reset();
+ append(aShape, false);
+ }
+ public void setPathToRectangle(float x, float y, float width, float height){
+ TEMP_RECTANGLE.setFrame(x, y, width, height);
+ setPathTo(TEMP_RECTANGLE);
+ }
+ public void setPathToEllipse(float x, float y, float width, float height) {
+ TEMP_ELLIPSE.setFrame(x, y, width, height);
+ setPathTo(TEMP_ELLIPSE);
+ }
+ /**
+ * Return a reference to the list used to manage this node's
+ * children. This list should not be modified.
+ *
+ * @return reference to the children list
+ */
+ // public List getChildrenReference() {
+ // if (children == null) {
+ // children = new ArrayList();
+ // }
+ // return children;
+ // }
+ // public PInterpolatingActivity animateToStrokeColor(final Color destColor, final long duration) {
+ // return super.animateToColor(destColor, duration);
+
+ // }
+}
diff --git a/src/main/java/jaist/css/covis/PPickEventHandler.java b/src/main/java/jaist/css/covis/PPickEventHandler.java
index 79e9756..551588b 100644
--- a/src/main/java/jaist/css/covis/PPickEventHandler.java
+++ b/src/main/java/jaist/css/covis/PPickEventHandler.java
@@ -2,10 +2,10 @@
import java.util.ArrayList;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PDragSequenceEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PDragSequenceEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.util.PDimension;
/**
* ATNWindow右上メニューの[pick]
@@ -43,7 +43,7 @@
if (targetPN != null){
PDimension d = e.getDeltaRelativeTo(window.canvas.getLayer());
targetPN.translate(d.getWidth(), d.getHeight());
- targetPN.moveToFront();
+ targetPN.raiseToTop();//TODO: moveToFront();
if (targetPN instanceof Selectable){
Selectable sel = (Selectable)targetPN;
diff --git a/src/main/java/jaist/css/covis/RootBuffer.java b/src/main/java/jaist/css/covis/RootBuffer.java
index 6e5d1fb..ea6cd62 100644
--- a/src/main/java/jaist/css/covis/RootBuffer.java
+++ b/src/main/java/jaist/css/covis/RootBuffer.java
@@ -3,9 +3,9 @@
import java.util.ArrayList;
import java.util.HashSet;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.PLayer;
-import edu.umd.cs.piccolo.PRoot;
+import org.piccolo2d.PCamera;
+import org.piccolo2d.PLayer;
+import org.piccolo2d.PRoot;
/**
* ATNBuffer(バッファ)のスーパークラス.画面表示モデルのルート(root), および表示レイヤ(layer)を持つ.
diff --git a/src/main/java/jaist/css/covis/RootWindow.java b/src/main/java/jaist/css/covis/RootWindow.java
index f0ed524..e2a6c6a 100644
--- a/src/main/java/jaist/css/covis/RootWindow.java
+++ b/src/main/java/jaist/css/covis/RootWindow.java
@@ -23,9 +23,9 @@
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.event.PInputEventFilter;
-import edu.umd.cs.piccolo.util.PBounds;
+import org.piccolo2d.PCamera;
+import org.piccolo2d.event.PInputEventFilter;
+import org.piccolo2d.util.PBounds;
import jaist.css.covis.cls.ClassFieldMenu;
import jaist.css.covis.util.MyPCanvas;
import jaist.css.covis.util.MyPFrame;
diff --git a/src/main/java/jaist/css/covis/Selectable.java b/src/main/java/jaist/css/covis/Selectable.java
index 80853c8..e1aa8cf 100644
--- a/src/main/java/jaist/css/covis/Selectable.java
+++ b/src/main/java/jaist/css/covis/Selectable.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.Hashtable;
-import edu.umd.cs.piccolo.PNode;
+import org.piccolo2d.PNode;
public interface Selectable {
boolean isSelected();
diff --git a/src/main/java/jaist/css/covis/ToolTipProvider.java b/src/main/java/jaist/css/covis/ToolTipProvider.java
index a4569c5..cd8acf8 100644
--- a/src/main/java/jaist/css/covis/ToolTipProvider.java
+++ b/src/main/java/jaist/css/covis/ToolTipProvider.java
@@ -1,6 +1,6 @@
package jaist.css.covis;
-import edu.umd.cs.piccolo.PNode;
+import org.piccolo2d.PNode;
public interface ToolTipProvider {
PNode getToolTipNode();
diff --git a/src/main/java/jaist/css/covis/ViewerKeyEventListener.java b/src/main/java/jaist/css/covis/ViewerKeyEventListener.java
index 9fe7c35..42b1b37 100644
--- a/src/main/java/jaist/css/covis/ViewerKeyEventListener.java
+++ b/src/main/java/jaist/css/covis/ViewerKeyEventListener.java
@@ -4,10 +4,10 @@
import java.awt.event.KeyListener;
import java.util.Hashtable;
-import edu.umd.cs.piccolo.PCamera;
-import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.util.PBounds;
+import org.piccolo2d.PCamera;
+import org.piccolo2d.event.PBasicInputEventHandler;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.util.PBounds;
import jaist.css.covis.pui.PMenuItem_Abstract;
import jaist.css.covis.util.BUtil;
diff --git a/src/main/java/jaist/css/covis/cls/Anchor.java b/src/main/java/jaist/css/covis/cls/Anchor.java
index 43c01f6..d562efe 100644
--- a/src/main/java/jaist/css/covis/cls/Anchor.java
+++ b/src/main/java/jaist/css/covis/cls/Anchor.java
@@ -1,19 +1,20 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.ToolTipProvider;
import java.awt.BasicStroke;
import java.awt.Color;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PDimension;
-class AnchorTab extends PPath implements Move, ToolTipProvider {
+class AnchorTab extends PPPath implements Move, ToolTipProvider {
private static final long serialVersionUID = 3651392444867276102L;
Anchor anchor;
PNode tooltip;
@@ -56,7 +57,7 @@
}
}
-public class Anchor extends PPath implements Runnable, DragNotice {
+public class Anchor extends PPPath implements Runnable, DragNotice {
private static final long serialVersionUID = -8491055463977967303L;
// Variable var;
public Covis_Object destObject;
@@ -169,9 +170,11 @@
boolean isTypeMatch = true;
toFront(System.currentTimeMillis());
PBounds pb = anchortab.getGlobalBounds();
- for(PNode co: buffer.objField.getAllNodes()){
+ var collection = buffer.objField.getAllNodes();
+ for(var co: collection){
if (!(co instanceof Covis_Object)) continue;
- PBounds cob = co.getGlobalBounds();
+ PNode pco = (PNode)co;
+ PBounds cob = pco.getGlobalBounds();
if (cob.contains(pb) || pb.intersects(cob)){
Covis_Object candidate = (Covis_Object) co;
// type が candidate のスーパークラス(type hoge = candidateができる)ならtrue
diff --git a/src/main/java/jaist/css/covis/cls/ClassField.java b/src/main/java/jaist/css/covis/cls/ClassField.java
index 990f182..315425b 100644
--- a/src/main/java/jaist/css/covis/cls/ClassField.java
+++ b/src/main/java/jaist/css/covis/cls/ClassField.java
@@ -5,12 +5,11 @@
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
-import java.util.List;
import javax.swing.Timer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PText;
public class ClassField extends Field {
private static final long serialVersionUID = 3524513728998576206L;
@@ -27,9 +26,9 @@
}
public ArrayList getTypeNodes(){
- List col = new ArrayList(getChildrenReference());
+ var col = getChildrenReference();
ArrayList ret = new ArrayList();
- for(PNode p: col) {
+ for(var p: col) {
if (p instanceof ClassStamp){
ClassStamp v = (ClassStamp)p;
ret.add(v);
diff --git a/src/main/java/jaist/css/covis/cls/ClassStamp.java b/src/main/java/jaist/css/covis/cls/ClassStamp.java
index 2258b79..e674efb 100644
--- a/src/main/java/jaist/css/covis/cls/ClassStamp.java
+++ b/src/main/java/jaist/css/covis/cls/ClassStamp.java
@@ -1,6 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.Selectable;
import java.awt.BasicStroke;
@@ -10,12 +11,12 @@
import java.util.List;
import java.util.TreeMap;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
-public class ClassStamp extends PPath implements Layoutable, Selectable, Move {
+public class ClassStamp extends PPPath implements Layoutable, Selectable, Move {
public static BasicStroke roundrectStroke = new BasicStroke(4f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f);
private static final long serialVersionUID = -2274392520995258292L;
@@ -53,7 +54,7 @@
addAttribute("dragLayout", this);
- handle = new PPath(this.getPathReference());
+ handle = new PPPath(this.getPathReference());
handle.addAttribute("moveTargetY", this);
handle.addAttribute("dragLayout", this);
handle.setTransparency(0.0f);
@@ -61,7 +62,7 @@
handle.setStrokePaint(Color.red);
handle.setStroke(roundrectStroke);
handle.setPickable(true);
- handle.moveToFront();
+ handle.raiseToTop();
handle.addAttribute("info", "ClassStamp handle");
handle.addAttribute("selectable", this);
handle.addAttribute("exclusiveSelectable", stamps);
@@ -90,9 +91,12 @@
}
public void layoutExceptOne(PNode operationNode, int dur) {
- List col = getChildrenReference();
- TreeMap map = new TreeMap();
- for(PNode p: col) map.put(p.getYOffset(), p);
+ var col = getChildrenReference();
+ TreeMap map = new TreeMap();
+ for(var o: col) {
+ PNode p = (PNode)o;
+ map.put((int)p.getYOffset(), p);
+ }
double offsetx = 10;
double endx = 10;
diff --git a/src/main/java/jaist/css/covis/cls/ClickHandler.java b/src/main/java/jaist/css/covis/cls/ClickHandler.java
index 8f62f5e..6e12fa2 100644
--- a/src/main/java/jaist/css/covis/cls/ClickHandler.java
+++ b/src/main/java/jaist/css/covis/cls/ClickHandler.java
@@ -1,7 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.fm.FlowMenu_TMRG;
-import edu.umd.cs.piccolo.event.PInputEvent;
+import org.piccolo2d.event.PInputEvent;
public interface ClickHandler {
public void clicked(PInputEvent e, FlowMenu_TMRG fmenu);
diff --git a/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java b/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java
index f1d5ff4..70f08ef 100644
--- a/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java
+++ b/src/main/java/jaist/css/covis/cls/CovisObj_TransparencyControl.java
@@ -1,6 +1,6 @@
package jaist.css.covis.cls;
-import edu.umd.cs.piccolo.PNode;
+import org.piccolo2d.PNode;
public class CovisObj_TransparencyControl implements Runnable {
Thread transparencyThread = null;
diff --git a/src/main/java/jaist/css/covis/cls/Covis_Array.java b/src/main/java/jaist/css/covis/cls/Covis_Array.java
index a238bbf..5bf4a82 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_Array.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_Array.java
@@ -13,9 +13,9 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
public class Covis_Array extends Covis_Object {
private static final long serialVersionUID = 8131819427660903628L;
diff --git a/src/main/java/jaist/css/covis/cls/Covis_BTree.java b/src/main/java/jaist/css/covis/cls/Covis_BTree.java
index 4612bb6..6dbcba8 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_BTree.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_BTree.java
@@ -19,7 +19,7 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.nodes.PText;
public class Covis_BTree extends Covis_Object {
diff --git a/src/main/java/jaist/css/covis/cls/Covis_Frac.java b/src/main/java/jaist/css/covis/cls/Covis_Frac.java
index d2e1b43..45dd813 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_Frac.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_Frac.java
@@ -19,8 +19,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
public class Covis_Frac extends Covis_Object {
diff --git a/src/main/java/jaist/css/covis/cls/Covis_LinkList.java b/src/main/java/jaist/css/covis/cls/Covis_LinkList.java
index 38da98c..c3c5656 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_LinkList.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_LinkList.java
@@ -19,7 +19,7 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.nodes.PText;
public class Covis_LinkList extends Covis_Object {
diff --git a/src/main/java/jaist/css/covis/cls/Covis_Object.java b/src/main/java/jaist/css/covis/cls/Covis_Object.java
index 99e0be7..569ca38 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_Object.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_Object.java
@@ -1,5 +1,6 @@
package jaist.css.covis.cls;
+import java.lang.Double;
import jaist.css.covis.CoVisBuffer;
import jaist.css.covis.ToolTipProvider;
import jaist.css.covis.hist.CVHist_New;
@@ -17,10 +18,10 @@
import javax.swing.JFrame;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.activities.PActivity;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.activities.PActivity;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
public class Covis_Object extends Covis_Type implements ToolTipProvider, ToFront, Move {
public static BasicStroke basicStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f);
@@ -245,11 +246,11 @@
}
public int attachPointOffset(Anchor mya) {
if (anchors_incoming.size()==1) return 0;
- TreeMap map = new TreeMap();
+ TreeMap map = new TreeMap();
for(Anchor p: anchors_incoming) {
double y = p.getGlobalTranslation().getY();
while(map.get(y)!=null) y+=0.01;
- map.put(y, p);
+ map.put((int)y, p);
}
int yy = 0;
for(Anchor a: map.values()){
diff --git a/src/main/java/jaist/css/covis/cls/Covis_String.java b/src/main/java/jaist/css/covis/cls/Covis_String.java
index cabbee2..53ef4e6 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_String.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_String.java
@@ -6,7 +6,7 @@
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.nodes.PText;
public class Covis_String extends Covis_Object {
private static final long serialVersionUID = 8131819427660903628L;
diff --git a/src/main/java/jaist/css/covis/cls/Covis_Type.java b/src/main/java/jaist/css/covis/cls/Covis_Type.java
index d7fb105..7caa7ce 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_Type.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_Type.java
@@ -1,17 +1,17 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import java.awt.Color;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
+import org.piccolo2d.PNode;
@SuppressWarnings("serial")
-public abstract class Covis_Type extends PPath {
+public abstract class Covis_Type extends PPPath {
public CoVisBuffer buffer;
public abstract String getClsName();
diff --git a/src/main/java/jaist/css/covis/cls/Covis_char.java b/src/main/java/jaist/css/covis/cls/Covis_char.java
index c8c7b18..8889d37 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_char.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_char.java
@@ -4,7 +4,7 @@
import java.awt.Color;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.nodes.PText;
public class Covis_char extends Covis_primitive {
private static final long serialVersionUID = 8131819427660903628L;
diff --git a/src/main/java/jaist/css/covis/cls/Covis_int.java b/src/main/java/jaist/css/covis/cls/Covis_int.java
index 13cceaf..d164078 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_int.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_int.java
@@ -4,8 +4,8 @@
import java.awt.Color;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PText;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PText;
public class Covis_int extends Covis_primitive {
private static final long serialVersionUID = 8131819427660903628L;
diff --git a/src/main/java/jaist/css/covis/cls/Covis_primitive.java b/src/main/java/jaist/css/covis/cls/Covis_primitive.java
index 447bb51..36bf75d 100644
--- a/src/main/java/jaist/css/covis/cls/Covis_primitive.java
+++ b/src/main/java/jaist/css/covis/cls/Covis_primitive.java
@@ -14,9 +14,9 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
public class Covis_primitive extends Covis_Type implements ToolTipProvider, ToFront, Move {
public static BasicStroke basicStroke = new BasicStroke(3f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f);
@@ -183,11 +183,11 @@
}
public int attachPointOffset(Anchor mya) {
if (anchors_incoming.size()==1) return 0;
- TreeMap map = new TreeMap();
+ TreeMap map = new TreeMap();
for(Anchor p: anchors_incoming) {
double y = p.getGlobalTranslation().getY();
while(map.get(y)!=null) y+=0.01;
- map.put(y, p);
+ map.put((int)y, p);
}
int yy = 0;
for(Anchor a: map.values()){
diff --git a/src/main/java/jaist/css/covis/cls/DragNotice.java b/src/main/java/jaist/css/covis/cls/DragNotice.java
index 274361c..1911815 100644
--- a/src/main/java/jaist/css/covis/cls/DragNotice.java
+++ b/src/main/java/jaist/css/covis/cls/DragNotice.java
@@ -1,7 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
-import edu.umd.cs.piccolo.event.PInputEvent;
+import org.piccolo2d.event.PInputEvent;
public interface DragNotice {
public void setDragNotice(boolean f);
diff --git a/src/main/java/jaist/css/covis/cls/Field.java b/src/main/java/jaist/css/covis/cls/Field.java
index 764a80f..b272e21 100644
--- a/src/main/java/jaist/css/covis/cls/Field.java
+++ b/src/main/java/jaist/css/covis/cls/Field.java
@@ -5,12 +5,13 @@
import java.util.List;
import java.util.TreeMap;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
-public class Field extends PPath implements Layoutable , Move{
+import jaist.css.covis.PPPath;
+
+public class Field extends PPPath implements Layoutable , Move{
private static final long serialVersionUID = 3524513728998576206L;
public String typeName; // Variable, Object, Class
@@ -47,11 +48,11 @@
public void layoutExceptOne(PNode operationNode, int dur) {
List col = getChildrenReference();
- TreeMap map = new TreeMap();
+ TreeMap map = new TreeMap();
for(PNode p: col) {
double y = p.getYOffset();
- while(map.get(y)!=null) y+=0.001;
- if (p != caption) map.put(y, p);
+ while(map.get((int)y)!=null) y+=0.001;
+ if (p != caption) map.put((int)y, p);
}
double offsetx = 10;
diff --git a/src/main/java/jaist/css/covis/cls/Layoutable.java b/src/main/java/jaist/css/covis/cls/Layoutable.java
index d5e7bd1..add3608 100644
--- a/src/main/java/jaist/css/covis/cls/Layoutable.java
+++ b/src/main/java/jaist/css/covis/cls/Layoutable.java
@@ -1,6 +1,6 @@
package jaist.css.covis.cls;
-import edu.umd.cs.piccolo.PNode;
+import org.piccolo2d.PNode;
public interface Layoutable {
public void layout(int dur);
diff --git a/src/main/java/jaist/css/covis/cls/Move.java b/src/main/java/jaist/css/covis/cls/Move.java
index e04ed21..a14baa1 100644
--- a/src/main/java/jaist/css/covis/cls/Move.java
+++ b/src/main/java/jaist/css/covis/cls/Move.java
@@ -1,6 +1,6 @@
package jaist.css.covis.cls;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.util.PDimension;
public interface Move {
public void move(PDimension d);
diff --git a/src/main/java/jaist/css/covis/cls/ObjectField.java b/src/main/java/jaist/css/covis/cls/ObjectField.java
index 45004cf..a77b50d 100644
--- a/src/main/java/jaist/css/covis/cls/ObjectField.java
+++ b/src/main/java/jaist/css/covis/cls/ObjectField.java
@@ -1,6 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.ToolTipProvider;
import jaist.css.covis.fm.FlowMenu_TMRG;
@@ -10,16 +11,17 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
+import java.util.ListIterator;
import java.util.TreeMap;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PDimension;
-public class ObjectField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
+public class ObjectField extends PPPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
private static final long serialVersionUID = 3524513728998576206L;
public static PNode nullToolTip = new PNode();
public String typeName; // Variable, Object, Class
@@ -59,12 +61,13 @@
}
public void layoutExceptOne(PNode operationNode, int dur) {
- List col = getChildrenReference();
- TreeMap map = new TreeMap();
- for(PNode p: col) {
- if (p != caption) map.put(p.getYOffset(), p);
+ ListIterator lite = getChildrenIterator();
+ TreeMap map = new TreeMap();
+ while(lite.hasNext()){
+ PNode p = (PNode)lite.next();
+ if (p != caption) map.put((int)p.getYOffset(), p);
}
-
+
double offsetx = 10;
double endx = 10;
double offsety = 10;
@@ -130,7 +133,9 @@
public void move(PDimension d){
translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作
- for(PNode p: getChildrenReference()) {
+ var lite = getChildrenIterator();
+ while(lite.hasNext()){
+ PNode p = (PNode)lite.next();
if (p instanceof Move) ((Move)p).move(new PDimension());
}
}
diff --git a/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java b/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java
index 9c04417..bd86687 100644
--- a/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java
+++ b/src/main/java/jaist/css/covis/cls/PNodeBoundsIntersectsFilter.java
@@ -1,8 +1,8 @@
package jaist.css.covis.cls;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PBounds;
-import edu.umd.cs.piccolo.util.PNodeFilter;
+import org.piccolo2d.PNode;
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PNodeFilter;
/**
* 引数に与えたノードの領域が,boundsの領域に完全に入っているかどうかを調べるフィルタ
diff --git a/src/main/java/jaist/css/covis/cls/RefLink.java b/src/main/java/jaist/css/covis/cls/RefLink.java
index afb1ee7..c527950 100644
--- a/src/main/java/jaist/css/covis/cls/RefLink.java
+++ b/src/main/java/jaist/css/covis/cls/RefLink.java
@@ -1,21 +1,21 @@
package jaist.css.covis.cls;
+import jaist.css.covis.PPPath;
import jaist.css.covis.fm.FlowMenu_TMRG;
import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.util.PDimension;
/**
* アンカータブと変数などとをつなぐ「線」
* @author miuramo
*/
-public class RefLink extends PPath implements LinkMovable, ClickHandler {
+public class RefLink extends PPPath implements LinkMovable, ClickHandler {
private static final long serialVersionUID = 6035096413162581382L;
PNode src;
diff --git a/src/main/java/jaist/css/covis/cls/StaticField.java b/src/main/java/jaist/css/covis/cls/StaticField.java
index b1db9e0..df6f07a 100644
--- a/src/main/java/jaist/css/covis/cls/StaticField.java
+++ b/src/main/java/jaist/css/covis/cls/StaticField.java
@@ -1,6 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.ToolTipProvider;
import jaist.css.covis.fm.FlowMenu_TMRG;
@@ -11,13 +12,13 @@
import java.util.List;
import java.util.TreeMap;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
-public class StaticField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
+public class StaticField extends PPPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
private static final long serialVersionUID = -6949546345615986003L;
public static PNode nullToolTip = new PNode();
public String typeName; // Variable, Object, Class
@@ -57,12 +58,13 @@
}
public void layoutExceptOne(PNode operationNode, int dur) {
- List col = getChildrenReference();
- TreeMap map = new TreeMap();
- for(PNode p: col) {
+ List col = getChildrenReference();
+ TreeMap map = new TreeMap();
+ for(Object o: col) {
+ PNode p = (PNode)o;
double y = p.getYOffset();
while(map.get(y)!=null) y+=0.001;
- if (p != caption) map.put(y, p);
+ if (p != caption) map.put((int)y, p);
}
double offsetx = 10;
@@ -133,7 +135,9 @@
public void move(PDimension d){
translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作
- for(PNode p: getChildrenReference()) {
+ List children = getChildrenReference();
+ for(Object o: children) {
+ PNode p = (PNode)o;
if (p instanceof Move) ((Move)p).move(new PDimension());
}
}
diff --git a/src/main/java/jaist/css/covis/cls/VarField.java b/src/main/java/jaist/css/covis/cls/VarField.java
index 55ff8eb..ccaa8f0 100644
--- a/src/main/java/jaist/css/covis/cls/VarField.java
+++ b/src/main/java/jaist/css/covis/cls/VarField.java
@@ -1,6 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.ToolTipProvider;
import jaist.css.covis.fm.FlowMenu_TMRG;
@@ -16,13 +17,13 @@
import javax.swing.Timer;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.event.PInputEvent;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.event.PInputEvent;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
-public class VarField extends PPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
+public class VarField extends PPPath implements Layoutable , ToolTipProvider, ClickHandler, Move {
private static final long serialVersionUID = 3524513728998576206L;
public static PNode nullToolTip = new PNode();
public String typeName; // Variable, Object, Class
@@ -83,9 +84,9 @@
public void layoutExceptOne(PNode operationNode, int dur) {
List col = getChildrenReference();
- TreeMap map = new TreeMap();
+ TreeMap map = new TreeMap();
for(PNode p: col) {
- if (p != caption) map.put(p.getYOffset(), p);
+ if (p != caption) map.put((int)p.getYOffset(), p);
}
double offsetx = 10;
@@ -189,8 +190,7 @@
}
public boolean checkExistName(String input, Variable variable) {
- List col = getChildrenReference();
- for(PNode p: col) {
+ for(var p: getChildrenReference()) {
if (p instanceof Variable){
Variable v = (Variable)p;
if (v.getBaseVarName().equals(input) && v != variable) return true;
@@ -201,7 +201,7 @@
public void move(PDimension d){
translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作
- for(PNode p: getChildrenReference()) {
+ for(var p: getChildrenReference()) {
if (p instanceof Move) ((Move)p).move(new PDimension());
}
}
diff --git a/src/main/java/jaist/css/covis/cls/Variable.java b/src/main/java/jaist/css/covis/cls/Variable.java
index 63ae87d..58784f0 100644
--- a/src/main/java/jaist/css/covis/cls/Variable.java
+++ b/src/main/java/jaist/css/covis/cls/Variable.java
@@ -1,6 +1,7 @@
package jaist.css.covis.cls;
import jaist.css.covis.CoVisBuffer;
+import jaist.css.covis.PPPath;
import jaist.css.covis.Selectable;
import jaist.css.covis.hist.CVHist_Var;
@@ -18,13 +19,14 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.nodes.PPath;
-import edu.umd.cs.piccolo.nodes.PText;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.nodes.PPath;
+import org.piccolo2d.nodes.PText;
+import org.piccolo2d.util.PDimension;
-public class Variable extends PPath implements Layoutable, Selectable, ToFront , Move{
- public static BasicStroke roundrectStroke = new BasicStroke(6f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 90.0f);
+public class Variable extends PPPath implements Layoutable, Selectable, ToFront, Move {
+ public static BasicStroke roundrectStroke = new BasicStroke(6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
+ 90.0f);
private static final long serialVersionUID = -2274392520995258292L;
@@ -32,16 +34,16 @@
public Class> type;
public Class> elementType;
boolean isArray = false;
- // public Covis_Object cv_class_for_tooptip;
- // public static Variable selected_stamp;
- // public static ArrayList stamps;
- // static{
- // stamps = new ArrayList();
- // }
+ // public Covis_Object cv_class_for_tooptip;
+ // public static Variable selected_stamp;
+ // public static ArrayList stamps;
+ // static{
+ // stamps = new ArrayList();
+ // }
private boolean isSelected;
-
+
public boolean isEnabled = true;
- public Covis_Type object = null;//これがあるとMember
+ public Covis_Type object = null;// これがあるとMember
PPath handle;
PText caption;
@@ -56,27 +58,30 @@
public CoVisBuffer buffer;
public static float top = 0;
-
- public void setVarName_Base(String s){
+
+ public void setVarName_Base(String s) {
varname_base = s;
-// varnames.add(s);
+ // varnames.add(s);
}
- public boolean isEnabled(){
+
+ public boolean isEnabled() {
return isEnabled;
}
- public void setEnabled(boolean b){
+
+ public void setEnabled(boolean b) {
isEnabled = b;
anchor.setAnchorEnabled(b);
}
- public Variable(Covis_Type co, JFrame frame, CoVisBuffer buf, boolean isMember){
+
+ public Variable(Covis_Type co, JFrame frame, CoVisBuffer buf, boolean isMember) {
cv_class = co;
buffer = buf;
varnames = new HashSet();
- if (cv_class instanceof Covis_Array){
+ if (cv_class instanceof Covis_Array) {
// 型(クラス・プリミティブ)選択
String s;
- if (((Covis_Array)cv_class).elementClassStr == null){
- s = (String)JOptionPane.showInputDialog(
+ if (((Covis_Array) cv_class).elementClassStr == null) {
+ s = (String) JOptionPane.showInputDialog(
frame,
"Choose Type of the Array",
"Choose Type",
@@ -85,24 +90,24 @@
ClassStamp.possibilities,
Covis_Array.lastSelectedClass);
if ((s != null) && (s.length() > 0)) {
- // System.out.println(s+" Selected.");
+ // System.out.println(s+" Selected.");
Covis_Array.lastSelectedClass = s;
} else {
type = null;
}
} else {
- s = ((Covis_Array)cv_class).elementClassStr;
+ s = ((Covis_Array) cv_class).elementClassStr;
}
try {
- Class> c = Class.forName("jaist.css.covis.cls.Covis_"+s);
+ Class> c = Class.forName("jaist.css.covis.cls.Covis_" + s);
Constructor> constructor = c.getConstructor(CoVisBuffer.class, boolean.class);
- cv_class = (Covis_Type) constructor.newInstance(buffer,true);
+ cv_class = (Covis_Type) constructor.newInstance(buffer, true);
type = Array.newInstance(c, 4).getClass();
elementType = cv_class.getClass();
- System.out.println("array "+type.toString());
- System.out.println("ele "+elementType.toString());
+ System.out.println("array " + type.toString());
+ System.out.println("ele " + elementType.toString());
isArray = true;
} catch (ClassNotFoundException e) {
e.printStackTrace();
@@ -123,21 +128,21 @@
type = cv_class.getClass();
elementType = type;
}
- setPathToRectangle(0,0,250,40);
+ setPathToRectangle(0, 0, 250, 40);
setPaint(cv_class.getClassColor());
setStrokePaint(Color.gray);
setStroke(new BasicStroke(1));
- // co.setScale(0.3f);
- // addChild(cv_class);
- // layout(0);
+ // co.setScale(0.3f);
+ // addChild(cv_class);
+ // layout(0);
- addAttribute("info", "ClassStamp "+this.toString());
- // addAttribute("selectable", this);
+ addAttribute("info", "ClassStamp " + this.toString());
+ // addAttribute("selectable", this);
addAttribute("moveTargetY", this);
addAttribute("dragLayout", this);
- handle = new PPath(this.getPathReference());
+ handle = new PPPath(this.getPathReference());
handle.addAttribute("moveTargetY", this);
handle.addAttribute("dragLayout", this);
handle.setTransparency(0.0f);
@@ -145,39 +150,39 @@
handle.setStrokePaint(Color.red);
handle.setStroke(roundrectStroke);
handle.setPickable(true);
- handle.moveToFront();
+ handle.raiseToTop();
handle.addAttribute("info", "ClassStamp handle");
- // handle.addAttribute("selectable", this);
- // handle.addAttribute("exclusiveSelectable", stamps);
+ // handle.addAttribute("selectable", this);
+ // handle.addAttribute("exclusiveSelectable", stamps);
addChild(handle);
- if (!isMember){
+ if (!isMember) {
varname_base = cv_class.getNextVarName(isArray);
- caption = new PText(getTypeName()+" "+varname_base);
+ caption = new PText(getTypeName() + " " + varname_base);
caption.scale(2.2f);
- caption.setOffset(10,3);
+ caption.setOffset(10, 3);
caption.addAttribute("moveTargetY", this);
caption.addAttribute("dragLayout", this);
addChild(caption);
caption.addAttribute("popupMenu", new VariableMenu(this));
}
- if (cv_class instanceof Covis_Object || isArray){
+ if (cv_class instanceof Covis_Object || isArray) {
anchor = new Anchor(type, this);
anchor.setVarName(varname_base);
addChild(anchor);
- anchor.setOffset(245,30);
- if (!isMember){
+ anchor.setOffset(245, 30);
+ if (!isMember) {
anchor.setAnchorEnabled(true);
}
} else {
// プリミティブなので,1つだけ追加
Covis_primitive prim = (Covis_primitive) cv_class;
addChild(prim);
- prim.setPathToRectangle(0,0,30,(float)getHeight());
+ prim.setPathToRectangle(0, 0, 30, (float) getHeight());
prim.setStroke(new BasicStroke(2));
prim.justify();
- prim.setOffset(getWidth()-prim.getWidth(), (getHeight()-prim.getHeight())/2);
+ prim.setOffset(getWidth() - prim.getWidth(), (getHeight() - prim.getHeight()) / 2);
prim.addAttribute("moveTargetY", this);
prim.addAttribute("dragLayout", this);
prim.valueText.addAttribute("moveTargetY", this);
@@ -187,38 +192,45 @@
addAttribute("popupMenu", new VariableMenu(this));
handle.addAttribute("popupMenu", new VariableMenu(this));
- // stamps.add(this);
+ // stamps.add(this);
}
- public String getTypeName(){
- if (!isArray){
- // if (type.isAssignableFrom(Covis_Object.class)){
+
+ public String getTypeName() {
+ if (!isArray) {
+ // if (type.isAssignableFrom(Covis_Object.class)){
return cv_class.getClsName();
} else {
- return cv_class.getClsName()+"[]";
+ return cv_class.getClsName() + "[]";
}
}
- public void layout(int dur){
+ public void layout(int dur) {
layoutExceptOne(null, dur);
}
public void layoutExceptOne(PNode operationNode, int dur) {
- List col = getChildrenReference();
- TreeMap map = new TreeMap();
- for(PNode p: col) map.put(p.getYOffset(), p);
+ var col = getChildrenReference();
+ TreeMap map = new TreeMap();
+ for (var o : col) {
+ PNode p = (PNode) o;
+ map.put((int) p.getYOffset(), p);
+ }
double offsetx = 10;
double endx = 10;
double offsety = 10;
double endy = 10;
- double maxx = 0, maxy = 0;
- for(PNode p : map.values()){
- // p.setOffset(offsetx, offsety);
+ double maxx = 0, maxy = 0;
+ for (PNode p : map.values()) {
+ // p.setOffset(offsetx, offsety);
double px = p.getFullBounds().width;
double py = p.getFullBounds().height;
- if (maxx < offsetx + endx + px) maxx = offsetx + endx + px;
- if (maxy < offsety + endy + py) maxy = offsety + endy + py;
- if (operationNode != p) p.animateToPositionScaleRotation(offsetx, offsety+top, 1, 0, dur);
+ if (maxx < offsetx + endx + px)
+ maxx = offsetx + endx + px;
+ if (maxy < offsety + endy + py)
+ maxy = offsety + endy + py;
+ if (operationNode != p)
+ p.animateToPositionScaleRotation(offsetx, offsety + top, 1, 0, dur);
offsety += py;
offsety += 10;
}
@@ -235,9 +247,14 @@
public void setSelected(boolean f, ArrayList list) {
isSelected = f;
- if (f) handle.setTransparency(0.8f); else handle.setTransparency(0.0f);
- if (f && list != null && !list.contains(this)) list.add(this);
- if (!f && list != null && list.contains(this)) list.remove(this);
+ if (f)
+ handle.setTransparency(0.8f);
+ else
+ handle.setTransparency(0.0f);
+ if (f && list != null && !list.contains(this))
+ list.add(this);
+ if (!f && list != null && list.contains(this))
+ list.remove(this);
}
public PNode theNode() {
@@ -249,53 +266,60 @@
}
public void removeLabel(Hashtable trash) {
- if (trash != null) trash.put(this, getParent());
+ if (trash != null)
+ trash.put(this, getParent());
removeFromParent();
}
- // public PNode getToolTipNode(){
- // if (cv_class_for_tooptip == null) {
- // cv_class_for_tooptip = cv_class.Covis_clone();
- // cv_class_for_tooptip.setScale(0.5f);
- // }
- // return cv_class_for_tooptip;
- // }
+ // public PNode getToolTipNode(){
+ // if (cv_class_for_tooptip == null) {
+ // cv_class_for_tooptip = cv_class.Covis_clone();
+ // cv_class_for_tooptip.setScale(0.5f);
+ // }
+ // return cv_class_for_tooptip;
+ // }
public String getBaseVarName() {
return varname_base;
}
- public void addVarNames(String prefix){
-// System.out.println("Variable.addVarNames"+prefix);
+
+ public void addVarNames(String prefix) {
+ // System.out.println("Variable.addVarNames"+prefix);
varnames.add(prefix);
}
- public String getVarName(){
+
+ public String getVarName() {
StringBuffer sb = new StringBuffer();
- for(String s: getVarNamesAry()){
- sb.append(s+"\n");
+ for (String s : getVarNamesAry()) {
+ sb.append(s + "\n");
}
- if (sb.length()==0) return sb.toString();
- return sb.toString().substring(0, sb.toString().length()-1);
+ if (sb.length() == 0)
+ return sb.toString();
+ return sb.toString().substring(0, sb.toString().length() - 1);
}
- public ArrayList getVarNamesAry(){
+
+ public ArrayList getVarNamesAry() {
ArrayList news = new ArrayList();
- if (this instanceof VariableM){
+ if (this instanceof VariableM) {
String sepdot = ".";
- if (object instanceof Covis_Array) sepdot = "";
-
- for(String s: varnames){
- news.add(s+sepdot+varname_base);
+ if (object instanceof Covis_Array)
+ sepdot = "";
+
+ for (String s : varnames) {
+ news.add(s + sepdot + varname_base);
}
} else {
news.add(varname_base);
}
return news;
}
- public void clearVarNamesAry(){
+
+ public void clearVarNamesAry() {
varnames.clear();
}
- // この変数を削除する
+ // この変数を削除する
public void dispose() {
- if (anchor != null && anchor.destObject != null){
+ if (anchor != null && anchor.destObject != null) {
anchor.destObject.detach(anchor);
}
Layoutable layout = (Layoutable) getParent();
@@ -303,27 +327,33 @@
layout.layout(200);
}
- // 変数名変更
+ // 変数名変更
public String rename(JFrame f) {
String input;
- while (true){
+ while (true) {
if (isArray) {
- input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+"[] variable.", varname_base);
+ input = JOptionPane.showInputDialog(f, "Input new name for " + cv_class.getClsName() + "[] variable.",
+ varname_base);
} else {
- input = JOptionPane.showInputDialog(f, "Input new name for "+cv_class.getClsName()+" variable.", varname_base);
+ input = JOptionPane.showInputDialog(f, "Input new name for " + cv_class.getClsName() + " variable.",
+ varname_base);
}
- if (input == null) return null;
- if (input.equals("")) return null;
+ if (input == null)
+ return null;
+ if (input.equals(""))
+ return null;
// 変数名重複チェック
// 親に聞くのが一番
VarField parent = (VarField) getParent();
if (parent.checkExistName(input, this)) {
- JOptionPane.showMessageDialog(null, "Same name is already used.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(null, "Same name is already used.\n\nPlease input other name.",
+ "Rename Error", JOptionPane.WARNING_MESSAGE);
continue;
}
- if (!input.matches("^[a-zA-Z_][a-zA-Z0-9]*")){
- JOptionPane.showMessageDialog(null, "Name should start with alphabet or _.\n\nPlease input other name.", "Rename Error", JOptionPane.WARNING_MESSAGE);
+ if (!input.matches("^[a-zA-Z_][a-zA-Z0-9]*")) {
+ JOptionPane.showMessageDialog(null, "Name should start with alphabet or _.\n\nPlease input other name.",
+ "Rename Error", JOptionPane.WARNING_MESSAGE);
continue;
}
break;
@@ -333,57 +363,75 @@
if (anchor != null) {
anchor.setVarName(varname_base);
}
- caption.setText(getTypeName()+" "+varname_base);
- if (anchor != null && anchor.destObject != null){
- anchor.destObject.tooltip = null; //変数名ツールチップを再構築
+ caption.setText(getTypeName() + " " + varname_base);
+ if (anchor != null && anchor.destObject != null) {
+ anchor.destObject.tooltip = null; // 変数名ツールチップを再構築
}
return varname_base;
}
- public void toFront(){
+
+ public void toFront() {
toFront(System.currentTimeMillis());
}
+
public void toFront(long ts) {
- if (toFront_ts == ts) return;
+ if (toFront_ts == ts)
+ return;
toFront_ts = ts;
PNode parent = getParent();
- if (parent != null){
- // removeFromParent();
+ if (parent != null) {
+ // removeFromParent();
parent.addChild(this);
- if (parent instanceof ToFront) ((ToFront)parent).toFront(ts);
+ if (parent instanceof ToFront)
+ ((ToFront) parent).toFront(ts);
}
}
- public void move(PDimension d){
- translate(d.getWidth(), d.getHeight()); //履歴に関係ない動作
- if (anchor != null) anchor.start_RewindThread();
+
+ public void move(PDimension d) {
+ translate(d.getWidth(), d.getHeight()); // 履歴に関係ない動作
+ if (anchor != null)
+ anchor.start_RewindThread();
}
+
public String getConstructorInfo() {
- if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+varname_base+";";
- else return getTypeName()+" "+varname_base+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので
+ if (cv_class instanceof Covis_Object || isArray)
+ return getTypeName() + " " + varname_base + ";";
+ else
+ return getTypeName() + " " + varname_base + " = " + ((Covis_primitive) cv_class).value + ";"; // getValue()にすると,''がとれてしまうので
}
+
public void setCVHist(CVHist_Var _cvhist) {
cvhist = _cvhist;
}
+
public String getEditValueInfo() {
- if (cv_class instanceof Covis_Object || isArray) return getTypeName()+" "+varname_base+";";
- else return varname_base+" = "+((Covis_primitive)cv_class).value+";"; //getValue()にすると,''がとれてしまうので
+ if (cv_class instanceof Covis_Object || isArray)
+ return getTypeName() + " " + varname_base + ";";
+ else
+ return varname_base + " = " + ((Covis_primitive) cv_class).value + ";"; // getValue()にすると,''がとれてしまうので
}
+
public void appendVarNameRecursive(Hashtable checked) {
-// System.out.println(varname_base);
- if (anchor == null) return;
- if (anchor.destObject != null){
-// if (checked.containsKey(this.hashCode())) return;
-// checked.put(this.hashCode(), this);
-// System.out.println("V append "+getVarName());
+ // System.out.println(varname_base);
+ if (anchor == null)
+ return;
+ if (anchor.destObject != null) {
+ // if (checked.containsKey(this.hashCode())) return;
+ // checked.put(this.hashCode(), this);
+ // System.out.println("V append "+getVarName());
anchor.destObject.appendVarNameRecursive(this, checked);
- }
+ }
}
-
- public static String getShortestName(ArrayList src){
- if (src.size()==0) return null;
- if (src.size()==1) return src.get(0);
+
+ public static String getShortestName(ArrayList src) {
+ if (src.size() == 0)
+ return null;
+ if (src.size() == 1)
+ return src.get(0);
String temp = src.get(0);
- for(String s: src){
- if (s.length() < temp.length()) temp = s;
+ for (String s : src) {
+ if (s.length() < temp.length())
+ temp = s;
}
return temp;
}
diff --git a/src/main/java/jaist/css/covis/cls/VariableM.java b/src/main/java/jaist/css/covis/cls/VariableM.java
index 74eeb23..666cdd6 100644
--- a/src/main/java/jaist/css/covis/cls/VariableM.java
+++ b/src/main/java/jaist/css/covis/cls/VariableM.java
@@ -11,8 +11,8 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
-import edu.umd.cs.piccolo.PNode;
-import edu.umd.cs.piccolo.util.PDimension;
+import org.piccolo2d.PNode;
+import org.piccolo2d.util.PDimension;
public class VariableM extends Variable{
private static final long serialVersionUID = 1922932400458120787L;
@@ -93,10 +93,12 @@
}
public void layoutExceptOne(PNode operationNode, int dur) {
- List col = getChildrenReference();
- TreeMap map = new TreeMap();
- for(PNode p: col) map.put(p.getYOffset(), p);
-
+ var col = getChildrenReference();
+ TreeMap map = new TreeMap