diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
index 1277755..464c244 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java
@@ -257,20 +257,22 @@
}
}
else if (isPressOrClickOrMove(pSwingMouseEvent) && comp != null) {
- final MouseEvent e_temp = new MouseEvent(comp, pSwingMouseEvent.getID(), mEvent.getWhen(), mEvent
+ final MouseEvent tempEvent = new MouseEvent(comp, pSwingMouseEvent.getID(), mEvent.getWhen(), mEvent
.getModifiers(), point.x - offset.x, point.y - offset.y, mEvent.getClickCount(), mEvent
.isPopupTrigger());
- final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(e_temp.getID(), e_temp, aEvent);
+ final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
dispatchEvent(comp, e2);
}
else if (isWheelEvent(pSwingMouseEvent) && comp != null) {
final MouseWheelEvent mWEvent = (MouseWheelEvent) mEvent;
- final MouseWheelEvent e_temp = new MouseWheelEvent(comp, pSwingMouseEvent.getID(), mEvent.getWhen(), mEvent
- .getModifiers(), point.x - offset.x, point.y - offset.y, mEvent.getClickCount(), mEvent
- .isPopupTrigger(), mWEvent.getScrollType(), mWEvent.getScrollAmount(), mWEvent.getWheelRotation());
+
+ final MouseWheelEvent tempEvent = new MouseWheelEvent(comp, pSwingMouseEvent.getID(), mEvent.getWhen(),
+ mEvent.getModifiers(), point.x - offset.x, point.y - offset.y, mEvent.getClickCount(), mEvent
+ .isPopupTrigger(), mWEvent.getScrollType(), mWEvent.getScrollAmount(), mWEvent
+ .getWheelRotation());
- final PSwingMouseWheelEvent e2 = new PSwingMouseWheelEvent(e_temp.getID(), e_temp, aEvent);
+ final PSwingMouseWheelEvent e2 = new PSwingMouseWheelEvent(tempEvent.getID(), tempEvent, aEvent);
dispatchEvent(comp, e2);
}
@@ -282,9 +284,9 @@
// This shouldn't happen - since we're only getting node events
if (comp == null || pSwingMouseEvent.getID() == MouseEvent.MOUSE_EXITED) {
- final MouseEvent e_temp = createExitEvent(mEvent);
+ final MouseEvent tempEvent = createExitEvent(mEvent);
- final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(e_temp.getID(), e_temp, aEvent);
+ final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
dispatchEvent(previousComponent, e2);
previousComponent = null;
@@ -292,18 +294,18 @@
// This means mouseExited prevComponent and mouseEntered comp
else if (previousComponent != comp) {
- MouseEvent e_temp = createExitEvent(mEvent);
- PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(e_temp.getID(), e_temp, aEvent);
+ MouseEvent tempEvent = createExitEvent(mEvent);
+ PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
dispatchEvent(previousComponent, e2);
- e_temp = createEnterEvent(comp, mEvent, offset.x, offset.y);
- e2 = PSwingMouseEvent.createMouseEvent(e_temp.getID(), e_temp, aEvent);
+ tempEvent = createEnterEvent(comp, mEvent, offset.x, offset.y);
+ e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
comp.dispatchEvent(e2.asMouseEvent());
}
}
else if (comp != null) { // This means mouseEntered
- final MouseEvent e_temp = createEnterEvent(comp, mEvent, offset.x, offset.y);
- final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(e_temp.getID(), e_temp, aEvent);
+ final MouseEvent tempEvent = createEnterEvent(comp, mEvent, offset.x, offset.y);
+ final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
dispatchEvent(comp, e2);
}
@@ -370,7 +372,8 @@
private void handleButton(final PSwingEvent e1, final PInputEvent aEvent, final ButtonData buttonData) {
final MouseEvent m1 = e1.asMouseEvent();
if (involvesSceneNode(buttonData)) {
- // TODO: this probably won't handle viewing through multiple cameras.
+ // TODO: this probably won't handle viewing through multiple
+ // cameras.
final Point2D pt = new Point2D.Double(m1.getX(), m1.getY());
cameraToLocal(e1.getPath().getTopCamera(), pt, buttonData.getPNode());
@@ -459,8 +462,8 @@
}
/**
- * Process a Piccolo2D event and (if active) dispatch the corresponding Swing
- * event.
+ * Process a Piccolo2D event and (if active) dispatch the corresponding
+ * Swing event.
*
* @param aEvent Piccolo2D event being testing for dispatch to swing
* @param type is not used in this method
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java
index 9766a03..0f25df3 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPaneLayout.java
@@ -42,19 +42,15 @@
/**
* 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
+ * information after each decision about scrollbar visiblity.
*
* @author Lance Good
*/
public class PScrollPaneLayout extends ScrollPaneLayout {
-
- /**
- *
- */
private static final long serialVersionUID = 1L;
/**
- * MODIFIED FROM javax.swing.ScrollPaneLayout.layoutContainer
+ * 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
@@ -63,9 +59,7 @@
* @param parent the Container to lay out
*/
public void layoutContainer(final Container parent) {
- /*
- * Sync the (now obsolete) policy fields with the JScrollPane.
- */
+ // Sync the (now obsolete) policy fields with the JScrollPane.
if (!(parent instanceof JScrollPane)) {
throw new IllegalArgumentException("layoutContainer may only be applied to JScrollPanes");
}
@@ -74,7 +68,7 @@
hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
final Rectangle availR = scrollPane.getBounds();
- availR.x = availR.y = 0;
+ availR.setLocation(0, 0);
final Insets insets = parent.getInsets();
availR.x = insets.left;
@@ -82,9 +76,7 @@
availR.width -= insets.left + insets.right;
availR.height -= insets.top + insets.bottom;
- /*
- * Get the scrollPane's orientation.
- */
+ // Get the scrollPane's orientation.
final boolean leftToRight = scrollPane.getComponentOrientation().isLeftToRight();
/*
@@ -153,14 +145,13 @@
* 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);
+ Dimension extentSize = getExtentSize(availR);
final 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);
+ Dimension viewPrefSize = getViewSize(cameraBounds);
/*
* If there's a vertical scrollbar and we need one, allocate space for
@@ -289,31 +280,83 @@
}
if (lowerLeft != null) {
- lowerLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, hsbR.y, leftToRight ? rowHeadR.width : vsbR.width,
- hsbR.height);
+ if (leftToRight) {
+ lowerLeft.setBounds(rowHeadR.x, hsbR.y, rowHeadR.width, hsbR.height);
+ }
+ else {
+ lowerLeft.setBounds(vsbR.x, hsbR.y, vsbR.width, hsbR.height);
+ }
}
if (lowerRight != null) {
- lowerRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, hsbR.y, leftToRight ? vsbR.width : rowHeadR.width,
- hsbR.height);
+ if (leftToRight) {
+ lowerRight.setBounds(vsbR.x, hsbR.y, vsbR.width, hsbR.height);
+ }
+ else {
+ lowerRight.setBounds(rowHeadR.x, hsbR.y, rowHeadR.width, hsbR.height);
+ }
}
if (upperLeft != null) {
- upperLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, colHeadR.y, leftToRight ? rowHeadR.width
- : vsbR.width, colHeadR.height);
+ if (leftToRight) {
+ upperLeft.setBounds(rowHeadR.x, colHeadR.y, rowHeadR.width, colHeadR.height);
+ }
+ else {
+ upperLeft.setBounds(vsbR.x, colHeadR.y, vsbR.width, colHeadR.height);
+ }
}
if (upperRight != null) {
- upperRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, colHeadR.y, leftToRight ? vsbR.width
- : rowHeadR.width, colHeadR.height);
+ if (leftToRight) {
+ upperRight.setBounds(vsbR.x, colHeadR.y, vsbR.width, colHeadR.height);
+ }
+ else {
+ upperRight.setBounds(rowHeadR.x, colHeadR.y, rowHeadR.width, colHeadR.height);
+ }
}
}
/**
- * Copied FROM javax.swing.ScrollPaneLayout.adjustForVSB
+ * @param cameraBounds
+ * @return
+ */
+ private Dimension getViewSize(final PBounds cameraBounds) {
+ Dimension viewPrefSize;
+ if (viewport != null) {
+ viewPrefSize = ((PViewport) viewport).getViewSize(cameraBounds);
+ }
+ else {
+ viewPrefSize = new Dimension(0, 0);
+ }
+ return viewPrefSize;
+ }
+
+ /**
+ * @param availR
+ * @return
+ */
+ private Dimension getExtentSize(final Rectangle availR) {
+ Dimension extentSize;
+ if (viewport != null) {
+ extentSize = viewport.toViewCoordinates(availR.getSize());
+ }
+ else {
+ extentSize = new Dimension(0, 0);
+ }
+ return extentSize;
+ }
+
+ /**
+ * Copied FROM javax.swing.ScrollPaneLayout.adjustForVSB.
*
* This method is called from ScrollPaneLayout.layoutContainer and is
* private in ScrollPaneLayout so it was copied here
+ *
+ * @param wantsVSB whether to account for vertical scrollbar
+ * @param available region to adjust
+ * @param vsbR vertical scroll bar region
+ * @param vpbInsets margin of vertical scroll bars
+ * @param leftToRight orientation of the text LTR or RTL
*/
protected void adjustForVSB(final boolean wantsVSB, final Rectangle available, final Rectangle vsbR,
final Insets vpbInsets, final boolean leftToRight) {
@@ -336,10 +379,15 @@
}
/**
- * Copied FROM javax.swing.ScrollPaneLayout.adjustForHSB
+ * Copied FROM javax.swing.ScrollPaneLayout.adjustForHSB.
*
* This method is called from ScrollPaneLayout.layoutContainer and is
* private in ScrollPaneLayout so it was copied here
+ *
+ * @param wantsHSB whether to account for horizontal scrollbar
+ * @param available region to adjust
+ * @param hsbR vertical scroll bar region
+ * @param vpbInsets margin of the scroll bars
*/
protected void adjustForHSB(final boolean wantsHSB, final Rectangle available, final Rectangle hsbR,
final Insets vpbInsets) {
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java
index 9bd8962..93d349c 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PViewport.java
@@ -50,14 +50,10 @@
*/
public class PViewport extends JViewport {
private static final long serialVersionUID = 1L;
- /**
- * Controls what happens when scrolling occurs
- */
+ /** Controls what happens when scrolling occurs. */
PScrollDirector scrollDirector;
- /**
- * Pass constructor info to super
- */
+ /** Pass constructor info to super. */
public PViewport() {
super();
@@ -79,7 +75,7 @@
* Subclasses can override this to install a different scroll director in
* the constructor. Returns a new PScrollDirector
object.
*
- * @return a PScrollDirector
+ * @return a PScrollDirector
*/
protected PScrollDirector createScrollDirector() {
return new PDefaultScrollDirector();
@@ -101,14 +97,16 @@
}
/**
- * @return The scroll director on this viewport.
+ * Returns the scroll director on this viewport.
+ *
+ * @return The scroll director on this viewport
*/
public PScrollDirector getScrollDirector() {
return scrollDirector;
}
/**
- * Overridden to throw an exception if the view is not a ZCanvas
+ * Overridden to throw an exception if the view is not a PCanvas.
*
* @param view The new view - it better be a ZCanvas!
*/
@@ -138,7 +136,7 @@
* 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
+ * @param p a Point object giving the upper left coordinates
*/
public void setViewPosition(final Point p) {
if (getView() == null) {
@@ -154,10 +152,8 @@
oldY = vp.getY();
}
- /**
- * Send the scroll director the exact view position and let it interpret
- * it as needed
- */
+ // Send the scroll director the exact view position and let it interpret
+ // it as needed
final double newX = x;
final double newY = y;
@@ -172,23 +168,22 @@
/**
* Gets the view position from the scroll director based on the current
- * extent size
+ * extent size.
*
- * @return The new view position
+ * @return The new view's position
*/
public Point getViewPosition() {
- if (scrollDirector != null) {
- final Dimension extent = getExtentSize();
- return scrollDirector.getViewPosition(new PBounds(0, 0, extent.getWidth(), extent.getHeight()));
- }
- else {
+ if (scrollDirector == null) {
return null;
}
+
+ final Dimension extent = getExtentSize();
+ return scrollDirector.getViewPosition(new PBounds(0, 0, extent.getWidth(), extent.getHeight()));
}
/**
* Gets the view size from the scroll director based on the current extent
- * size
+ * size.
*
* @return The new view size
*/
@@ -199,7 +194,7 @@
/**
* Gets the view size from the scroll director based on the specified extent
- * size
+ * size.
*
* @param r The extent size from which the view is computed
* @return The new view size
@@ -209,7 +204,7 @@
}
/**
- * A simple layout manager to give the ZCanvas the same size as the Viewport
+ * 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 = 1L;
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/LineShape.java b/extras/src/main/java/edu/umd/cs/piccolox/util/LineShape.java
index ed2f51d..5b399d4 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/LineShape.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/LineShape.java
@@ -36,6 +36,9 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+/**
+ * A shape that can be used to represent hand drawn lines.
+ */
public class LineShape implements Shape, MutablePoints {
private MutablePoints points;
private final Rectangle2D bounds = new Rectangle2D.Double();
@@ -54,11 +57,13 @@
*
* @param points new Points to use as this shape's path
*/
- public void setPoints(MutablePoints points) {
+ public void setPoints(final MutablePoints points) {
if (points == null) {
- points = new XYArray();
+ this.points = new XYArray();
}
- this.points = points;
+ else {
+ this.points = points;
+ }
}
/**
@@ -214,8 +219,9 @@
double dy = y2 - y1;
// If line is a point then bail out
- if (dx == 0 && dy == 0)
+ if (dx == 0 && dy == 0) {
return false;
+ }
final double dx2 = dx * dx;
final double dy2 = dy * dy;
@@ -400,8 +406,8 @@
* @param height height of defined rectangle
* @return true if rectangle is contained
*/
- public boolean contains(final double x, final double y, final double w, final double h) {
- return contains(x, y) && contains(x + w, y) && contains(x, y + h) && contains(x + w, y + h);
+ public boolean contains(final double x, final double y, final double width, final double height) {
+ return contains(x, y) && contains(x + width, y) && contains(x, y + height) && contains(x + width, y + height);
}
/**
@@ -420,7 +426,6 @@
*
* @param at optional transform to apply to segment before returning it. May
* be null
- * @param iterator for iterating over Line Paths
* @return iterator for iterating segments of this LineShape
*/
public PathIterator getPathIterator(final AffineTransform at) {
@@ -433,7 +438,6 @@
*
* @param at optional transform to apply to segment before returning it. May
* be null
- * @param iterator for iterating over Line Paths
* @param flatness ignored completely
* @return iterator for iterating segments of this LineShape
*/
@@ -463,7 +467,8 @@
/**
* Returns the winding rule being applied when selecting next paths.
*
- * @return GeneralPath.WIND_EVEN_ODD since that's the only policy supported
+ * @return GeneralPath.WIND_EVEN_ODD since that's the only policy
+ * supported
*/
public int getWindingRule() {
return GeneralPath.WIND_EVEN_ODD;
@@ -506,7 +511,12 @@
currentSegment();
coords[0] = (float) tempPoint.getX();
coords[1] = (float) tempPoint.getY();
- return i == 0 ? PathIterator.SEG_MOVETO : PathIterator.SEG_LINETO;
+ if (i == 0) {
+ return PathIterator.SEG_MOVETO;
+ }
+ else {
+ return PathIterator.SEG_LINETO;
+ }
}
/**
@@ -521,7 +531,12 @@
currentSegment();
coords[0] = tempPoint.getX();
coords[1] = tempPoint.getY();
- return i == 0 ? PathIterator.SEG_MOVETO : PathIterator.SEG_LINETO;
+ if (i == 0) {
+ return PathIterator.SEG_MOVETO;
+ }
+ else {
+ return PathIterator.SEG_LINETO;
+ }
}
}
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java b/extras/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java
index ca277df..c1b27cc 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/MutablePoints.java
@@ -30,12 +30,40 @@
import java.awt.geom.AffineTransform;
+/**
+ * Minimal interface that a changeable sequence of points must provide.
+ */
public interface MutablePoints extends Points {
- public void setPoint(int i, double x, double y);
+ /**
+ * Sets the coordinates for the point at the given index.
+ *
+ * @param i index of point
+ * @param x x component of the point's coordinates
+ * @param y y component of the point's coordinates
+ */
+ void setPoint(int i, double x, double y);
- public void addPoint(int pos, double x, double y);
+ /**
+ * Inserts a point at the specified position.
+ *
+ * @param pos position at which to insert the point
+ * @param x x component of the point's coordinates
+ * @param y y component of the point's coordinates
+ */
+ void addPoint(int pos, double x, double y);
- public void removePoints(int pos, int num);
+ /**
+ * Removes a subsequence of points.
+ *
+ * @param pos position to start removing points
+ * @param num number of points to remove
+ */
+ void removePoints(int pos, int num);
- public void transformPoints(AffineTransform t);
+ /**
+ * Modifies all points by applying the transform to them.
+ *
+ * @param t transformto apply to the points
+ */
+ void transformPoints(AffineTransform t);
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java b/extras/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java
index 7b5bd45..8092409 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/PBoundsLocator.java
@@ -43,58 +43,127 @@
* @author Jesse Grosjean
*/
public class PBoundsLocator extends PNodeLocator {
-
- /**
- *
- */
private static final long serialVersionUID = 1L;
private int side;
+ /**
+ * Creates a locator for tracking the east side of the provided node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createEastLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.EAST);
}
+ /**
+ * Creates a locator for tracking the north east corner of the provided
+ * node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createNorthEastLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.NORTH_EAST);
}
+ /**
+ * Creates a locator for tracking the north west corner of the provided
+ * node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createNorthWestLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.NORTH_WEST);
}
+ /**
+ * Creates a locator for tracking the north side of the provided node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createNorthLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.NORTH);
}
+ /**
+ * Creates a locator for tracking the south side of the provided node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createSouthLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.SOUTH);
}
+ /**
+ * Creates a locator for tracking the west side of the provided node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createWestLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.WEST);
}
+ /**
+ * Creates a locator for tracking the south west corner of the provided
+ * node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createSouthWestLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.SOUTH_WEST);
}
+ /**
+ * Creates a locator for tracking the south east corner of the provided
+ * node.
+ *
+ * @param node node to track
+ * @return a new locator
+ */
public static PBoundsLocator createSouthEastLocator(final PNode node) {
return new PBoundsLocator(node, SwingConstants.SOUTH_EAST);
}
+ /**
+ * Constructs a locator for tracking the position on the node provided.
+ *
+ * @param node node to track
+ * @param aSide specified the position on the node to track
+ */
public PBoundsLocator(final PNode node, final int aSide) {
super(node);
side = aSide;
}
+ /**
+ * Returns the side of the node that's being tracked.
+ *
+ * @return tracked side
+ */
public int getSide() {
return side;
}
+ /**
+ * Sets the side to track on the node.
+ *
+ * @param side new side to track
+ */
public void setSide(final int side) {
this.side = side;
}
+ /**
+ * Maps the locator's side to its x position.
+ *
+ * @return x position on side this locator is tracking
+ */
public double locateX() {
final Rectangle2D aBounds = node.getBoundsReference();
@@ -112,10 +181,16 @@
case SwingConstants.NORTH:
case SwingConstants.SOUTH:
return aBounds.getX() + aBounds.getWidth() / 2;
+ default:
+ return -1;
}
- return -1;
}
+ /**
+ * Maps the locator's side to its y position.
+ *
+ * @return y position on side this locator is tracking
+ */
public double locateY() {
final Rectangle2D aBounds = node.getBoundsReference();
@@ -133,7 +208,8 @@
case SwingConstants.NORTH_EAST:
case SwingConstants.NORTH:
return aBounds.getY();
+ default:
+ return -1;
}
- return -1;
}
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java b/extras/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java
index bc91070..56fdafa 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/PFixedWidthStroke.java
@@ -116,6 +116,11 @@
this(new BasicStroke(width, cap, join, miterlimit, dash, dash_phase));
}
+ /**
+ * Throws an exception since PFixedWidthStrokes are not serializable.
+ *
+ * @return never returns anything
+ */
public Object clone() {
throw new UnsupportedOperationException("Not implemented.");
}
@@ -160,10 +165,22 @@
return ((BasicStroke) stroke).getLineWidth();
}
+ /**
+ * Returns the miter limit of this node.
+ *
+ * @return miter limit of this node
+ */
public float getMiterLimit() {
return ((BasicStroke) stroke).getMiterLimit();
}
+ /**
+ * Returns a stroke equivalent to this one, but scaled by the scale
+ * provided.
+ *
+ * @param activeScale scale to apply to the new stoke
+ * @return scaled stroke
+ */
protected Stroke newStroke(final float activeScale) {
if (tmpDash != null) {
for (int i = dash.length - 1; i >= 0; i--) {
@@ -188,6 +205,7 @@
*
* @throws ObjectStreamException doesn't actually throw this at all, why's
* this here?
+ * @return the resolved stroke
*/
protected Object readResolve() throws ObjectStreamException {
return new PFixedWidthStroke((BasicStroke) stroke);
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/PLocator.java b/extras/src/main/java/edu/umd/cs/piccolox/util/PLocator.java
index 636a665..6f3f2e0 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/PLocator.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/PLocator.java
@@ -42,23 +42,45 @@
*/
public abstract class PLocator implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = 1L;
+ /**
+ * Default constructor provided for subclasses. Does nothing by itself.
+ */
public PLocator() {
}
- public Point2D locatePoint(Point2D aDstPoint) {
+ /**
+ * Locates the point this locator is responsible for finding, and stores it
+ * in dstPoints. Should dstPoints be null, it will create a new point and
+ * return it.
+ *
+ * @param aDstPoint output parameter to store the located point
+ * @return the located point
+ */
+ public Point2D locatePoint(final Point2D aDstPoint) {
+ Point2D result;
if (aDstPoint == null) {
- aDstPoint = new Point2D.Double();
+ result = new Point2D.Double();
}
- aDstPoint.setLocation(locateX(), locateY());
- return aDstPoint;
+ else {
+ result = aDstPoint;
+ }
+ result.setLocation(locateX(), locateY());
+ return result;
}
+ /**
+ * Locates the X component of the position this locator finds.
+ *
+ * @return x component of located point
+ */
public abstract double locateX();
+ /**
+ * Locates the Y component of the position this locator finds.
+ *
+ * @return y component of located point
+ */
public abstract double locateY();
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java b/extras/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java
index fdfbd7f..46d8ac6 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/PNodeLocator.java
@@ -44,29 +44,52 @@
* @author Jesse Grosjean
*/
public class PNodeLocator extends PLocator {
-
- /**
- *
- */
private static final long serialVersionUID = 1L;
+
+ /** Node being located by this locator. */
protected PNode node;
+ /**
+ * Constructs a locator responsible for locating the given node.
+ *
+ * @param node node to be located
+ */
public PNodeLocator(final PNode node) {
setNode(node);
}
+ /**
+ * Returns the node being located by this locator.
+ *
+ * @return node being located by this locator
+ */
public PNode getNode() {
return node;
}
+ /**
+ * Changes the node being located by this locator.
+ *
+ * @param node new node to have this locator locate.
+ */
public void setNode(final PNode node) {
this.node = node;
}
+ /**
+ * Locates the left of the target node's bounds.
+ *
+ * @return left of target node's bounds
+ */
public double locateX() {
return node.getBoundsReference().getCenterX();
}
+ /**
+ * Locates the top of the target node's bounds.
+ *
+ * @return top of target node's bounds
+ */
public double locateY() {
return node.getBoundsReference().getCenterY();
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java b/extras/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java
index f6de65d..a132b70 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/POcclusionDetection.java
@@ -44,11 +44,23 @@
* 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.
+ *
+ * @param n node from which to detect occlusions
+ * @param parentBounds bounds of parent node
*/
public void detectOccusions(final PNode n, final PBounds parentBounds) {
detectOcclusions(n, new PPickPath(null, parentBounds));
}
+ /**
+ * Traverse the pick path 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.
+ *
+ * @param node node from which to detect occlusions
+ * @param pickPath Pick Path to traverse
+ */
public void detectOcclusions(final PNode node, final PPickPath pickPath) {
if (!node.fullIntersects(pickPath.getPickBounds())) {
return;
@@ -60,8 +72,8 @@
for (int i = count - 1; i >= 0; i--) {
final PNode each = node.getChild(i);
if (node.getOccluded()) {
- // if n has been occuded by a previous decendent then
- // this child must also be occuded
+ // if n has been occluded by a previous descendant then
+ // this child must also be occluded
each.setOccluded(true);
}
else {
@@ -80,6 +92,13 @@
pickPath.popTransform(node.getTransformReference(false));
}
+ /**
+ * Calculate whether node occludes its parents.
+ *
+ * @param n node to test
+ * @param pickPath pickpath identifying the parents of the node
+ * @return true if parents are occluded by the node
+ */
private boolean nodeOccludesParents(final PNode n, final PPickPath pickPath) {
return !n.getOccluded() && n.intersects(pickPath.getPickBounds()) && n.isOpaque(pickPath.getPickBounds());
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/PSemanticStroke.java b/extras/src/main/java/edu/umd/cs/piccolox/util/PSemanticStroke.java
index 068e6d7..d505f38 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/PSemanticStroke.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/PSemanticStroke.java
@@ -49,22 +49,32 @@
protected final Stroke stroke;
protected PSemanticStroke(final Stroke stroke) {
- this.stroke = recentStroke = stroke;
+ this.stroke = stroke;
+ recentStroke = stroke;
recentScale = 1.0F;
}
/**
* Ask {@link #getActiveScale()}, call {@link #newStroke(float)} if
- * necessary and delegate to {@link Stroke#createStrokedShape(Shape)}
+ * necessary and delegate to {@link Stroke#createStrokedShape(Shape)}.
+ *
+ * @param s
*/
public Shape createStrokedShape(final Shape s) {
final float currentScale = getActiveScale();
if (Math.abs(currentScale - recentScale) > THRESHOLD) {
- recentStroke = newStroke(recentScale = currentScale);
+ recentScale = currentScale;
+ recentStroke = newStroke(recentScale);
}
return recentStroke.createStrokedShape(s);
}
+ /**
+ * Returns true if this stroke is equivalent to the object provided.
+ *
+ * @param obj Object being tested
+ * @return true if object is equivalent
+ */
public boolean equals(final Object obj) {
if (this == obj) {
return true;
@@ -110,8 +120,12 @@
public int hashCode() {
final int prime = 31;
- int result = 1;
- result = prime * result + (stroke == null ? 0 : stroke.hashCode());
+ int result = prime;
+
+ if (stroke != null) {
+ result += stroke.hashCode();
+ }
+
return result;
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/Points.java b/extras/src/main/java/edu/umd/cs/piccolox/util/Points.java
index 23ff2b8..1c5a5f4 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/Points.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/Points.java
@@ -31,14 +31,52 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+/**
+ * Interface for a sequence of points.
+ */
public interface Points {
- public int getPointCount();
+ /**
+ * Returns the number of points in the sequence.
+ *
+ * @return number of points in the sequence
+ */
+ int getPointCount();
- public double getX(int i);
+ /**
+ * Returns the x component of the point at the given index.
+ *
+ * @param i index of desired point
+ *
+ * @return x component of point
+ */
+ double getX(int i);
- public double getY(int i);
+ /**
+ * Returns the y component of the point at the given index.
+ *
+ * @param i index of desired point
+ *
+ * @return y component of point
+ */
+ double getY(int i);
- public Point2D getPoint(int i, Point2D dst);
+ /**
+ * Returns a point representation of the coordinates at the given index.
+ *
+ * @param i index of desired point
+ * @param dst output parameter into which the point's details will be
+ * populated, if null a new one will be created.
+ *
+ * @return a point representation of the coordinates at the given index
+ */
+ Point2D getPoint(int i, Point2D dst);
- public Rectangle2D getBounds(Rectangle2D dst);
+ /**
+ * Returns the bounds of all the points taken as a whole.
+ *
+ * @param dst output parameter to store bounds into, if null a new rectangle
+ * will be created
+ * @return rectangle containing the bounds
+ */
+ Rectangle2D getBounds(Rectangle2D dst);
}
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/ShadowUtils.java b/extras/src/main/java/edu/umd/cs/piccolox/util/ShadowUtils.java
index 9c67b55..49ef01f 100755
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/ShadowUtils.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/ShadowUtils.java
@@ -42,6 +42,8 @@
*/
public final class ShadowUtils {
+ private static final int BLUR_BOUNDS_AFFORDANCE = 4;
+
/**
* Private no-arg constructor.
*/
@@ -71,8 +73,8 @@
if (blurRadius < 1) {
throw new IllegalArgumentException("blur radius must be greater than zero, was " + blurRadius);
}
- int w = src.getWidth(null) + (4 * blurRadius);
- int h = src.getHeight(null) + (4 * blurRadius);
+ int w = src.getWidth(null) + (BLUR_BOUNDS_AFFORDANCE * blurRadius);
+ int h = src.getHeight(null) + (BLUR_BOUNDS_AFFORDANCE * blurRadius);
// paint src image into mask
BufferedImage mask = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
@@ -114,7 +116,7 @@
*/
private static float[] createKernel(final int r) {
int w = (2 * r) + 1;
- float kernel[] = new float[w * w];
+ float[] kernel = new float[w * w];
double m = 2.0d * Math.pow((r / 3.0d), 2);
double n = Math.PI * m;
diff --git a/extras/src/main/java/edu/umd/cs/piccolox/util/XYArray.java b/extras/src/main/java/edu/umd/cs/piccolox/util/XYArray.java
index 8c55b2e..1aed1fc 100644
--- a/extras/src/main/java/edu/umd/cs/piccolox/util/XYArray.java
+++ b/extras/src/main/java/edu/umd/cs/piccolox/util/XYArray.java
@@ -32,11 +32,15 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+/**
+ * Represents a sequence as points that's internally stored as a single array of
+ * point components.
+ */
public class XYArray implements MutablePoints, Cloneable {
/** The coordinates of the points, specifically 2x the number of points. */
private double[] points = null;
- /** the number of valid x, y pairs */
+ /** the number of valid x, y pairs. */
private int numPoints = 0;
/**
@@ -51,7 +55,7 @@
/**
* Constructs an XYArray of the given size.
*
- * @param n numbe rof points XYArray should contain
+ * @param n number of points XYArray should contain
*/
public XYArray(final int n) {
initPoints(null, n);
@@ -79,13 +83,17 @@
* @param i index to be normalized
* @return normalized index
*/
-
private int normalize(final int i) {
if (i >= numPoints) {
throw new IllegalArgumentException("The point index " + i + " is not below " + numPoints);
}
- return i < 0 ? numPoints + i : i;
+ if (i < 0) {
+ return numPoints + i;
+ }
+ else {
+ return i;
+ }
}
/**
@@ -204,26 +212,36 @@
* desired
* @return initialized points
*/
- public static double[] initPoints(double[] points, final int n, final double[] old) {
+ public static double[] initPoints(final double[] points, final int n, final double[] old) {
+ final double[] result;
if (points == null || n * 2 > points.length) {
- points = new double[n * 2];
+ result = new double[n * 2];
}
- if (old != null && points != old) {
- System.arraycopy(old, 0, points, 0, Math.min(old.length, n * 2));
+ else {
+ result = points;
}
- return points;
+ if (old != null && result != old) {
+ System.arraycopy(old, 0, result, 0, Math.min(old.length, n * 2));
+ }
+
+ return result;
}
/**
* Constructs an array of point coordinates for n points.
*
- * @param points array to populate with point values, or null to generate a
- * new array
+ * @param srcPoints array to populate with point values, or null to generate
+ * a new array
* @param n number of points
*/
- private void initPoints(final double[] points, final int n) {
- this.points = initPoints(points, n, this.points);
- numPoints = points != null ? points.length / 2 : 0;
+ private void initPoints(final double[] srcPoints, final int n) {
+ this.points = initPoints(srcPoints, n, this.points);
+ if (srcPoints == null) {
+ numPoints = 0;
+ }
+ else {
+ numPoints = srcPoints.length / 2;
+ }
}
/**
@@ -234,22 +252,26 @@
* @param start the start index within newPoints to start extracting points
* @param end the end index within newPoints to finish extracting points
*/
- public void addPoints(final int index, final Points newPoints, int start, int end) {
+ public void addPoints(final int index, final Points newPoints, final int start, final int end) {
+ final int sanitizedEnd;
if (end < 0) {
- end = newPoints.getPointCount() + end + 1;
+ sanitizedEnd = newPoints.getPointCount() + end + 1;
}
- final int n = numPoints + end - start;
+ else {
+ sanitizedEnd = end;
+ }
+ final int n = numPoints + sanitizedEnd - start;
points = initPoints(points, n, points);
final int pos1 = index * 2;
- final int pos2 = (index + end - start) * 2;
+ final int pos2 = (index + sanitizedEnd - start) * 2;
final int len = (numPoints - index) * 2;
System.arraycopy(points, pos1, points, pos2, len);
numPoints = n;
if (newPoints != null) {
- for (int count = 0; start < end; count++, start++) {
- setPoint(index + count, newPoints.getX(start), newPoints.getY(start));
+ for (int count = 0, currentPos = start; currentPos < sanitizedEnd; count++, currentPos++) {
+ setPoint(index + count, newPoints.getX(currentPos), newPoints.getY(currentPos));
}
}
}
@@ -313,13 +335,12 @@
* @param pos the position to start removing points
* @param num the number of points to remove
*/
- public void removePoints(final int pos, int num) {
- num = Math.min(num, numPoints - pos);
- if (num <= 0) {
- return;
+ public void removePoints(final int pos, final int num) {
+ int sanitizedNum = Math.min(num, numPoints - pos);
+ if (sanitizedNum > 0) {
+ System.arraycopy(points, (pos + sanitizedNum) * 2, points, pos * 2, (numPoints - (pos + sanitizedNum)) * 2);
+ numPoints -= sanitizedNum;
}
- System.arraycopy(points, (pos + num) * 2, points, pos * 2, (numPoints - (pos + num)) * 2);
- numPoints -= num;
}
/**
@@ -344,6 +365,7 @@
ps.numPoints = numPoints;
}
catch (final CloneNotSupportedException e) {
+
}
return ps;