diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java index 714aa25..4e26bfc 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PNavigationEventHandler.java @@ -59,6 +59,9 @@ * @author Jesse Grosjean */ public class PNavigationEventHandler extends PBasicInputEventHandler { + /** Minum size under which two scales are considered the same. */ + private static final double SCALING_THRESHOLD = 0.0001; + /** Amount of time it takes to animation view from one location to another. */ private static final int NAVIGATION_DURATION = 500; /** The UP direction on the screen. */ public static final int NORTH = 0; @@ -312,19 +315,16 @@ */ public boolean nodeIsNeighborInDirection(final PNode node, final int direction) { switch (direction) { - case IN: { + case IN: return node.isDescendentOf(focusNode); - } - case OUT: { + case OUT: return node.isAncestorOf(focusNode); - } - default: { + default: if (node.isAncestorOf(focusNode) || node.isDescendentOf(focusNode)) { return false; } - } } final Point2D highlightCenter = (Point2D) NODE_TO_GLOBAL_NODE_CENTER_MAPPING.get(focusNode); @@ -334,24 +334,22 @@ final double ytest2 = -nodeCenter.getX() + highlightCenter.getX() + highlightCenter.getY(); switch (direction) { - case NORTH: { + case NORTH: return nodeCenter.getY() < highlightCenter.getY() && nodeCenter.getY() < ytest1 && nodeCenter.getY() < ytest2; - } - case EAST: { + case EAST: return nodeCenter.getX() > highlightCenter.getX() && nodeCenter.getY() < ytest1 && nodeCenter.getY() > ytest2; - } - case SOUTH: { + case SOUTH: return nodeCenter.getY() > highlightCenter.getY() && nodeCenter.getY() > ytest1 && nodeCenter.getY() > ytest2; - } - case WEST: { + + case WEST: return nodeCenter.getX() < highlightCenter.getX() && nodeCenter.getY() > ytest1 && nodeCenter.getY() < ytest2; - } + default: return false; } @@ -437,13 +435,12 @@ focusNode = newFocus; final AffineTransform originalViewTransform = camera.getViewTransform(); - // Scale the canvas to include final PDimension d = new PDimension(1, 0); focusNode.globalToLocal(d); final double scaleFactor = d.getWidth() / camera.getViewScale(); final Point2D scalePoint = focusNode.getGlobalFullBounds().getCenter2D(); - if (Math.abs(1f - scaleFactor) < 0.0001) { + if (Math.abs(1f - scaleFactor) < SCALING_THRESHOLD) { camera.scaleViewAboutPoint(scaleFactor, scalePoint.getX(), scalePoint.getY()); } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java index 39a961f..3f0c48a 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java @@ -71,6 +71,7 @@ /** A map of listeners keyed by NotificationKey objects. */ protected HashMap listenersMap; + /** A queue of NotificationKeys that are available to be garbage collected. */ protected ReferenceQueue keyQueue; /** @@ -410,7 +411,8 @@ * * @param name name of notification * @param object associated object - * @param queue + * @param queue ReferenceQueue in which this NotificationKey will be + * appended once it has been cleared to be garbage collected */ public NotificationKey(final Object name, final Object object, final ReferenceQueue queue) { super(object, queue); diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java index ae8cffc..eab37f1 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java @@ -64,6 +64,8 @@ * @author Lance Good */ public class PStyledTextEventHandler extends PBasicInputEventHandler { + private static final int TEXT_EDIT_PADDING = 3; + /** Canvas onto which this event handler is attached. */ protected PCanvas canvas; @@ -313,7 +315,7 @@ } else { width = (int) (editedText.getWidth() - textInsets.left - textInsets.right + editorInsets.left - + editorInsets.right + 3.0); + + editorInsets.right + TEXT_EDIT_PADDING); } prefSize.setSize(width, prefSize.getHeight()); editor.setSize(prefSize); @@ -325,7 +327,7 @@ } else { height = (int) (editedText.getHeight() - textInsets.top - textInsets.bottom + editorInsets.top - + editorInsets.bottom + 3.0); + + editorInsets.bottom + TEXT_EDIT_PADDING); } prefSize.setSize(width, height); editor.setSize(prefSize); @@ -348,7 +350,9 @@ private static final long serialVersionUID = 1L; public DefaultTextEditor() { - setBorder(new CompoundBorder(new LineBorder(Color.black), new EmptyBorder(3, 3, 3, 3))); + EmptyBorder padding = new EmptyBorder(TEXT_EDIT_PADDING, + TEXT_EDIT_PADDING, TEXT_EDIT_PADDING, TEXT_EDIT_PADDING); + setBorder(new CompoundBorder(new LineBorder(Color.black), padding)); } /** diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java index 00150c3..6e9daa0 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/P3DRect.java @@ -39,7 +39,6 @@ import edu.umd.cs.piccolo.PNode; import edu.umd.cs.piccolo.util.PBounds; import edu.umd.cs.piccolo.util.PPaintContext; -import edu.umd.cs.piccolox.PFrame; /** * This is a simple node that draws a "3D" rectangle within the bounds of the @@ -51,40 +50,73 @@ * @author Ben Bederson */ public class P3DRect extends PNode { - private static final long serialVersionUID = 1L; private Color topLeftOuterColor; private Color topLeftInnerColor; private Color bottomRightInnerColor; private Color bottomRightOuterColor; private final GeneralPath path; - private transient final Stroke stroke; + private final transient Stroke stroke; private boolean raised; + /** + * Constructs a simple P3DRect with empty bounds and a black stroke. + */ public P3DRect() { raised = true; stroke = new BasicStroke(0); path = new GeneralPath(); } + /** + * Constructs a P3DRect with the provided bounds. + * + * @param bounds bounds to assigned to the P3DRect + */ public P3DRect(final Rectangle2D bounds) { this(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } + /** + * Constructs a P3DRect with the bounds provided. + * + * @param x left of bounds + * @param y top of bounds + * @param width width of bounds + * @param height height of bounds + */ public P3DRect(final double x, final double y, final double width, final double height) { this(); setBounds(x, y, width, height); } + /** + * Sets whether this rectangle is raised off the canvas. If set to false, + * this rectangle will appear recessed into the canvas. + * + * @param raised whether the rectangle should be painted as raised or + * recessed + */ public void setRaised(final boolean raised) { this.raised = raised; setPaint(getPaint()); } + /** + * Returns whether this P3DRect is drawn as raised. + * + * @return true if raised + */ public boolean getRaised() { return raised; } + /** + * Paints this rectangle with shaded edges. Making it appear to stand out of + * the page as normal 3D buttons do. + * + * @param paintContext context in which the paiting should occur + */ protected void paint(final PPaintContext paintContext) { final Graphics2D g2 = paintContext.getGraphics(); @@ -92,10 +124,10 @@ final double y = getY(); final double width = getWidth(); final double height = getHeight(); - final double magX = g2.getTransform().getScaleX(); - final double magY = g2.getTransform().getScaleY(); - final double dx = (float) (1.0 / magX); - final double dy = (float) (1.0 / magY); + final double scaleX = g2.getTransform().getScaleX(); + final double scaleY = g2.getTransform().getScaleY(); + final double dx = (float) (1.0 / scaleX); + final double dy = (float) (1.0 / scaleY); final PBounds bounds = getBounds(); g2.setPaint(getPaint()); @@ -131,55 +163,55 @@ g2.draw(path); } + /** + * Changes the paint that will be used to draw this rectangle. This paint is + * used to shade the edges of the rectangle. + * + * @param newPaint the color to use for painting this rectangle + */ public void setPaint(final Paint newPaint) { super.setPaint(newPaint); if (newPaint instanceof Color) { final Color color = (Color) newPaint; - if (raised) { - topLeftOuterColor = color.brighter(); - topLeftInnerColor = topLeftOuterColor.brighter(); - bottomRightInnerColor = color.darker(); - bottomRightOuterColor = bottomRightInnerColor.darker(); + setRaisedEdges(color); } else { - topLeftOuterColor = color.darker(); - topLeftInnerColor = topLeftOuterColor.darker(); - bottomRightInnerColor = color.brighter(); - bottomRightOuterColor = bottomRightInnerColor.brighter(); + setRecessedEdges(color); } } else { - topLeftOuterColor = null; - topLeftInnerColor = null; - bottomRightInnerColor = null; - bottomRightOuterColor = null; + setNoEdges(); } } - //TODO: Move this into an example (if not already) + private void setRaisedEdges(final Color color) { + topLeftOuterColor = color.brighter(); + topLeftInnerColor = topLeftOuterColor.brighter(); + bottomRightInnerColor = color.darker(); + bottomRightOuterColor = bottomRightInnerColor.darker(); + } + + private void setNoEdges() { + topLeftOuterColor = null; + topLeftInnerColor = null; + bottomRightInnerColor = null; + bottomRightOuterColor = null; + } + + private void setRecessedEdges(final Color color) { + topLeftOuterColor = color.darker(); + topLeftInnerColor = topLeftOuterColor.darker(); + bottomRightInnerColor = color.brighter(); + bottomRightOuterColor = bottomRightInnerColor.brighter(); + } + + /** + * @Deprecated since it has been moved to P3DRectExample. + * + * @param args Command line arguments + */ public static void main(final String[] args) { - new PFrame() { - /** - * - */ - private static final long serialVersionUID = 1L; - - public void initialize() { - getCanvas().setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING); - - final P3DRect rect1 = new P3DRect(50, 50, 100, 100); - rect1.setPaint(new Color(239, 235, 222)); - - final P3DRect rect2 = new P3DRect(50, 50, 100, 100); - rect2.setPaint(new Color(239, 235, 222)); - rect2.translate(110, 0); - rect2.setRaised(false); - - getCanvas().getLayer().addChild(rect1); - getCanvas().getLayer().addChild(rect2); - } - }; } } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java index 3c91f9a..4085b7a 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java @@ -46,22 +46,21 @@ /** * An extension to PCamera that provides a fast image based - * animationToCenterBounds method + * animationToCenterBounds method. * * @author Lance Good */ public class PCacheCamera extends PCamera { - /** - * - */ private static final long serialVersionUID = 1L; private transient BufferedImage paintBuffer; private boolean imageAnimate; private PBounds imageAnimateBounds; /** - * Get the buffer used to provide fast image based animation + * Get the buffer used to provide fast image based animation. + * + * @return buffered image used to provide fast image based animation */ protected BufferedImage getPaintBuffer() { final PBounds fRef = getFullBoundsReference(); @@ -90,7 +89,7 @@ /** * Caches the information necessary to animate from the current view bounds - * to the specified centerBounds + * to the specified centerBounds. */ private AffineTransform cacheViewBounds(final Rectangle2D centerBounds, final boolean scaleToFit) { final PBounds viewBounds = getViewBounds(); @@ -136,7 +135,7 @@ } /** - * Turns off the fast image animation and does any other applicable cleanup + * Turns off the fast image animation and does any other applicable cleanup. */ private void clearViewCache() { imageAnimate = false; @@ -145,7 +144,14 @@ /** * Mimics the standard animateViewToCenterBounds but uses a cached image for - * performance rather than re-rendering the scene at each step + * performance rather than re-rendering the scene at each step. + * + * @param centerBounds bounds to which the view should be centered + * @param shouldScaleToFit whether the camera should scale to fit the bounds + * so the cover as large a portion of the canvas without changing + * the aspect ratio + * @param duration milliseconds the animation should last + * @return the scheduled activity, null if duration was 0 */ public PTransformActivity animateStaticViewToCenterBoundsFast(final Rectangle2D centerBounds, final boolean shouldScaleToFit, final long duration) { @@ -160,11 +166,16 @@ /** * This copies the behavior of the standard animateViewToTransform but - * clears the cache when it is done + * clears the cache when it is done. + * + * @param dest the resulting transform that the view should be + * applying when the animation is complete + * @param duration length in milliseconds that the animation should last + * @return the scheduled PTransformActivity, null if duration was 0 */ - protected PTransformActivity animateStaticViewToTransformFast(final AffineTransform destination, final long duration) { + protected PTransformActivity animateStaticViewToTransformFast(final AffineTransform dest, final long duration) { if (duration == 0) { - setViewTransform(destination); + setViewTransform(dest); return null; } @@ -178,7 +189,7 @@ } }; - final PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destination) { + final PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, dest) { protected void activityFinished() { clearViewCache(); repaint(); @@ -196,7 +207,9 @@ /** * Overrides the camera's full paint method to do the fast rendering when - * possible + * possible. + * + * @param paintContext Paint Contex in which the painting is done */ public void fullPaint(final PPaintContext paintContext) { if (imageAnimate) { diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java index 6d352c8..abe2901 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PClip.java @@ -41,28 +41,43 @@ /** * 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. + * GeneralPath wrapped by its super class. See piccolo2d/examples ClipExample. * * @version 1.0 * @author Jesse Grosjean */ public class PClip extends PPath { - - /** - * - */ private static final long serialVersionUID = 1L; - public PBounds computeFullBounds(PBounds dstBounds) { + /** + * Computes the full bounds and stores them in dstBounds, if dstBounds is + * null, create a new Bounds and returns it. + * + * @param dstBounds output parameter where computed bounds will be stored + * @return the computed full bounds + */ + public PBounds computeFullBounds(final PBounds dstBounds) { + final PBounds result; if (dstBounds == null) { - dstBounds = new PBounds(); + result = new PBounds(); } - dstBounds.reset(); - dstBounds.add(getBoundsReference()); - localToParent(dstBounds); - return dstBounds; + else { + result = dstBounds; + result.reset(); + } + + result.add(getBoundsReference()); + localToParent(result); + return result; } + /** + * Callback that receives notification of repaint requests from nodes in + * this node's tree. + * + * @param localBounds region in local coordinations the needs repainting + * @param childOrThis the node that emitted the repaint notification + */ public void repaintFrom(final PBounds localBounds, final PNode childOrThis) { if (childOrThis != this) { Rectangle2D.intersect(getBoundsReference(), localBounds, localBounds); @@ -73,6 +88,12 @@ } } + /** + * Paint's this node as a solid rectangle if paint is provided, clipping + * appropriately. + * + * @param paintContext context into which this node will be painted + */ protected void paint(final PPaintContext paintContext) { final Paint p = getPaint(); if (p != null) { @@ -83,6 +104,12 @@ paintContext.pushClip(getPathReference()); } + /** + * Paints a border around this node if it has a stroke and stroke paint + * provided. + * + * @param paintContext context into which the border will be drawn + */ protected void paintAfterChildren(final PPaintContext paintContext) { paintContext.popClip(getPathReference()); if (getStroke() != null && getStrokePaint() != null) { @@ -93,6 +120,13 @@ } } + /** + * Try to pick this node and all of its descendants if they are visible in + * the clipping region. + * + * @param pickPath the pick path to add the node to if its picked + * @return true if this node or one of its descendants was picked. + */ public boolean fullPick(final PPickPath pickPath) { if (getPickable() && fullIntersects(pickPath.getPickBounds())) { pickPath.pushNode(this); diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java index 988de0c..f497138 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PComposite.java @@ -66,10 +66,13 @@ private static final long serialVersionUID = 1L; /** - * Return true if this node or any pickable descendends are picked. If a + * Return true if this node or any pickable descendants 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 + * as the picked node, event if it was a descendant node that initially * reported the pick. + * + * @param pickPath the pick path to add the nodes to if they are picked + * @return true if this node or one of its descendants was picked */ public boolean fullPick(final PPickPath pickPath) { if (super.fullPick(pickPath)) { diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java index ee5df8f..0634464 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PLens.java @@ -40,12 +40,12 @@ 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 + * PLens is a simple default lens implementation for Piccolo2D. See + * piccolo2d/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 + * 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 @@ -64,18 +64,26 @@ public class PLens extends PNode { private static final long serialVersionUID = 1L; - 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 final PPath dragBar; private final PCamera camera; - private transient final PDragEventHandler lensDragger; + private final transient PDragEventHandler lensDragger; + /** The height of the drag bar. */ + public static double LENS_DRAGBAR_HEIGHT = 20; + + /** Default paint to use for the drag bar. */ + public static Paint DEFAULT_DRAGBAR_PAINT = Color.DARK_GRAY; + + /** Default paint to use when drawing the background of the lens. */ + public static Paint DEFAULT_LENS_PAINT = Color.LIGHT_GRAY; + + /** + * Constructs the default PLens. + */ public PLens() { // Drag bar gets resized to fit the available space, so any rectangle // will do here - dragBar = PPath.createRectangle(0, 0, 100, 100); + dragBar = PPath.createRectangle(0, 0, 1, 1); dragBar.setPaint(DEFAULT_DRAGBAR_PAINT); // This forces drag events to percolate up to PLens object dragBar.setPickable(false); @@ -100,33 +108,66 @@ }); } + /** + * Creates the default PLens and attaches the given layer to it. + * + * @param layer layer to attach to this PLens + */ public PLens(final PLayer layer) { this(); addLayer(0, layer); } + /** + * Returns the camera on which this lens is appearing. + * + * @return camera on which lens is appearing + */ public PCamera getCamera() { return camera; } + /** + * Returns the drag bar for this lens. + * + * @return this lens' drag bar + */ public PPath getDragBar() { return dragBar; } + /** + * Returns the event handler that this lens uses for its drag bar. + * + * @return drag bar's drag event handler + */ public PDragEventHandler getLensDraggerHandler() { return lensDragger; } + /** + * Adds the layer to the camera. + * + * @param index index at which to add the layer to the camera + * @param layer layer to add to the camera + */ public void addLayer(final int index, final PLayer layer) { camera.addLayer(index, layer); } + /** + * Removes the provided layer from the camera. + * + * @param layer layer to be removed + */ public void removeLayer(final PLayer layer) { camera.removeLayer(layer); } - // when the lens is resized this method gives us a chance to layout the - // lenses camera child appropriately. + /** + * 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/extras/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java index c65433b..ac88526 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PComboBox.java @@ -94,7 +94,7 @@ * * @param items The items to populate the PComboBox list */ - public PComboBox(final Object items[]) { + public PComboBox(final Object[] items) { super(items); init(); } @@ -110,7 +110,7 @@ } /** - * Create an empty PComboBox + * Create an empty PComboBox. */ public PComboBox() { super(); @@ -118,7 +118,7 @@ } /** - * Substitue our UI for the default + * Substitute our UI for the default. */ private void init() { setUI(new PBasicComboBoxUI()); @@ -128,23 +128,25 @@ * Clients must set the PSwing and PSwingCanvas environment for this * PComboBox to work properly. * - * @param pSwing - * @param canvas + * @param pSwingNode node that this PComboBox is attached to + * @param canvasEnvirnoment canvas on which the pSwing node is embedded */ - public void setEnvironment(final PSwing pSwing, final PSwingCanvas canvas) { - this.pSwing = pSwing; - this.canvas = canvas; + public void setEnvironment(final PSwing pSwingNode, final PSwingCanvas canvasEnvirnoment) { + this.pSwing = pSwingNode; + this.canvas = canvasEnvirnoment; } /** * 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 + * than the default. */ protected class PBasicComboBoxUI extends BasicComboBoxUI { /** - * Create our Popup instead of theirs + * Create our Popup instead of swing's default. + * + * @return a new ComboPopup */ protected ComboPopup createPopup() { final PBasicComboPopup popup = new PBasicComboPopup(comboBox); @@ -154,24 +156,23 @@ } /** - * The substitute ComboPopupMenu that places itself correctly in Piccolo. + * The substitute ComboPopupMenu that places itself correctly in Piccolo2d. */ protected class PBasicComboPopup extends BasicComboPopup { - - /** - * - */ private static final long serialVersionUID = 1L; /** - * @param combo The parent ComboBox + * Creates a PBasicComboPopup that will position itself correctly in + * relation to the provided JComboBox. + * + * @param combo The associated ComboBox */ public PBasicComboPopup(final JComboBox combo) { super(combo); } /** - * Computes the bounds for the Popup in Piccolo if a PMouseEvent has + * Computes the bounds for the Popup in Piccolo2D if a PMouseEvent has * been received. Otherwise, it uses the default algorithm for placing * the popup. * @@ -200,10 +201,20 @@ return r1c; } + /** + * Returns the associated PSwing node. + * + * @return associated PSwing node + */ public PSwing getPSwing() { return pSwing; } + /** + * Returns the canvas on which the PSwing node is embedded. + * + * @return canvas on which the PSwing node is embedded + */ public PSwingCanvas getCanvas() { return canvas; } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java index 76e9789..e2b9185 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwing.java @@ -150,7 +150,7 @@ */ /** - * PSwing is used to add Swing Components to a Piccolo canvas. + * PSwing is used to add Swing Components to a Piccolo2D canvas. *

* Example: adding a swing JButton to a PCanvas: * @@ -159,8 +159,8 @@ * 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 @@ -190,10 +190,10 @@ *

*

* 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. + * future Piccolo2D releases. The current serialization support is appropriate + * for short term storage or RMI between applications running the same version + * of Piccolo2D. A future release of Piccolo2D will provide support for long + * term persistence. *

* * @author Sam R. Reid @@ -247,7 +247,7 @@ private final List listeningTo = new ArrayList(); /* The parent listener for camera/canvas changes. */ - private transient final PropertyChangeListener parentListener = new PropertyChangeListener() { + private final transient PropertyChangeListener parentListener = new PropertyChangeListener() { /** {@inheritDoc} */ public void propertyChange(final PropertyChangeEvent evt) { final PNode parent = (PNode) evt.getNewValue(); @@ -296,7 +296,12 @@ listenForCanvas(this); } - /** @deprecated by {@link PSwing(JComponent)} */ + /** + * @deprecated by {@link PSwing(JComponent)} + * + * @param swingCanvas canvas on which the PSwing node will be embedded + * @param component not used + */ public PSwing(final PSwingCanvas swingCanvas, final JComponent component) { this(component); } @@ -480,7 +485,7 @@ * Repaints the specified portion of this visual component. Note that the * input parameter may be modified as a result of this call. * - * @param repaintBounds + * @param repaintBounds bounds needing repainting */ public void repaint(final PBounds repaintBounds) { final Shape sh = getTransform().createTransformedShape(repaintBounds); @@ -634,7 +639,7 @@ /** * Clear out all the listeners registered to make sure there are no stray - * references + * references. * * @param fromParent Parent to start with for clearing listeners */ diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java index 2d68151..0727fb6 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingCanvas.java @@ -45,6 +45,7 @@ */ public class PSwingCanvas extends PCanvas { private static final long serialVersionUID = 1L; + /** Key used to store the "Swing Wrapper" as an attribute of the PSwing node. */ public static final String SWING_WRAPPER_KEY = "Swing Wrapper"; private final ChildWrapper swingWrapper; diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEvent.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEvent.java index f63af63..a91c335 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEvent.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEvent.java @@ -11,6 +11,10 @@ import edu.umd.cs.piccolo.PNode; import edu.umd.cs.piccolo.util.PPickPath; +/** + * Interface allowing PSwing events that originated from swing and are destined + * for PSwing nodes must conform to. + */ public interface PSwingEvent { /** * Returns the x,y position of the event in the local coordinate system of @@ -109,11 +113,11 @@ void dispatchTo(Object listener); /** - * 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. + * Set the source 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 + * @param aSource the source of the event */ void setSource(Object aSource); 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 a58729c..1277755 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 @@ -57,8 +57,8 @@ * @author Sam Reid */ public class PSwingEventHandler implements PInputEventListener { - /** Used to listen for events */ - private PNode listenNode = null; + /** Used to listen for events. */ + private PNode listenNode = null; /** Tracks whether this event handler is active. */ private boolean active = false; @@ -75,7 +75,8 @@ /** Previous offset used for mouseEntered and exited events. */ private Point2D previousOffset = null; - private boolean recursing = false;// to avoid accidental recursive handling + /** Used to avoid accidental recursive handling. */ + private boolean recursing = false; /** Used for tracking the left button's state. */ private final ButtonData leftButtonData = new ButtonData(); @@ -94,7 +95,7 @@ * will receive the mouse events. * * @param canvas the canvas associated with this PSwingEventHandler. - * @param node the node the mouse listeners will be attached to. + * @param listenNode the node the mouse listeners will be attached to. */ public PSwingEventHandler(final PSwingCanvas canvas, final PNode listenNode) { this.canvas = canvas; @@ -103,6 +104,8 @@ /** * Constructs a new PSwingEventHandler for the given canvas. + * + * @param canvas to associate this event handler to */ public PSwingEventHandler(final PSwingCanvas canvas) { this.canvas = canvas; @@ -111,7 +114,7 @@ /** * Sets whether this event handler can fire events. * - * @param active + * @param active true if thie event handler can fire events */ void setActive(final boolean active) { if (this.active && !active) { @@ -129,19 +132,20 @@ /** * Returns if this event handler is active. * - * @return True if active + * @return true if can fire events */ public boolean isActive() { return active; } /** - * Finds the component at the specified location (must be showing). + * Finds the best visible component or subcomponent at the specified + * location. * - * @param component - * @param x - * @param y - * @return the component at the specified location. + * @param component component to test children or self for + * @param x x component of location + * @param y y component of location + * @return the component or subcomponent at the specified location. */ private Component findShowingComponentAt(final Component component, final int x, final int y) { if (!component.contains(x, y)) { @@ -176,17 +180,18 @@ } } } + return null; } /** - * Determines if any Swing components in Piccolo should receive the given + * Determines if any Swing components in Piccolo2D 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 + * @param pSwingMouseEvent event being dispatched + * @param aEvent Piccolo2D event translation of the pSwingMouseEvent */ void dispatchEvent(final PSwingEvent pSwingMouseEvent, final PInputEvent aEvent) { final MouseEvent mEvent = pSwingMouseEvent.asMouseEvent(); @@ -365,8 +370,7 @@ 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()); @@ -455,11 +459,11 @@ } /** - * Process a piccolo event and (if active) dispatch the corresponding Swing + * Process a Piccolo2D event and (if active) dispatch the corresponding Swing * event. * - * @param aEvent - * @param type + * @param aEvent Piccolo2D event being testing for dispatch to swing + * @param type is not used in this method */ public void processEvent(final PInputEvent aEvent, final int type) { if (aEvent.isMouseEvent()) { diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java index 9e8cc6f..7197cfc 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseEvent.java @@ -47,11 +47,13 @@ * *

*

@@ -64,10 +66,10 @@ *

*

* 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. + * future Piccolo2d releases. The current serialization support is appropriate + * for short term storage or RMI between applications running the same version + * of Piccolo2d. A future release of Piccolo2d will provide support for long + * term persistence. *

* * @author Benjamin B. Bederson @@ -75,25 +77,24 @@ * @author Lance E. Good */ public class PSwingMouseEvent extends MouseEvent implements Serializable, PSwingEvent { - /** - * - */ private static final long serialVersionUID = 1L; private final int id; - private transient final PInputEvent event; + private final transient 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. + * @param swingEvent The original swing mouse event when in MOUSE_RELEASED + * events. + * @param piccoloEvent used to query about the event's Piccolo context */ - protected PSwingMouseEvent(final int id, final MouseEvent e, final PInputEvent event) { - super((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e - .getClickCount(), e.isPopupTrigger()); + protected PSwingMouseEvent(final int id, final MouseEvent swingEvent, final PInputEvent piccoloEvent) { + super((Component) swingEvent.getSource(), swingEvent.getID(), swingEvent.getWhen(), swingEvent.getModifiers(), + swingEvent.getX(), swingEvent.getY(), swingEvent.getClickCount(), swingEvent.isPopupTrigger()); this.id = id; - this.event = event; + this.event = piccoloEvent; } /** @@ -101,18 +102,21 @@ * * @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. + * @param swingEvent The original swing mouse event when in + * MOUSE_DRAGGED and MOUSE_RELEASED events. + * @param pEvent used to query about the event's Piccolo2d context + * + * @return the constructed PSwingEvent */ - public static PSwingEvent createMouseEvent(final int id, final MouseEvent e, final PInputEvent pEvent) { + public static PSwingEvent createMouseEvent(final int id, final MouseEvent swingEvent, final PInputEvent pEvent) { if (id == MouseEvent.MOUSE_MOVED || id == MouseEvent.MOUSE_DRAGGED) { - return new PSwingMouseMotionEvent(id, e, pEvent); + return new PSwingMouseMotionEvent(id, swingEvent, pEvent); } else if (id == MouseEvent.MOUSE_WHEEL) { - return new PSwingMouseWheelEvent(id, (MouseWheelEvent) e, pEvent); + return new PSwingMouseWheelEvent(id, (MouseWheelEvent) swingEvent, pEvent); } else { - return new PSwingMouseEvent(id, e, pEvent); + return new PSwingMouseEvent(id, swingEvent, pEvent); } } @@ -258,12 +262,18 @@ * of the event will keep changing to reflect the scenegraph object that is * firing the event. * - * @param aSource + * @param newSource the currently reported source of the event (will change + * as event is bubbled up) */ - public void setSource(final Object aSource) { - source = aSource; + public void setSource(final Object newSource) { + source = newSource; } + /** + * Returns this PSwingMouseEvent's MouseEvent. + * + * @return underlying mouse event of this PSwingMouseEvent + */ public MouseEvent asMouseEvent() { return this; } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java index d55f121..13c751d 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseMotionEvent.java @@ -77,10 +77,12 @@ * 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. + * @param swingEvent The original Java mouse event when in MOUSE_DRAGGED events + * @param piccoloEvent Piccolo2d event to use when querying about the event's + * piccolo2d context */ - protected PSwingMouseMotionEvent(final int id, final MouseEvent e, final PInputEvent event) { - super(id, e, event); + protected PSwingMouseMotionEvent(final int id, final MouseEvent swingEvent, final PInputEvent piccoloEvent) { + super(id, swingEvent, piccoloEvent); } /** diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseWheelEvent.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseWheelEvent.java index d5e4737..8b4bfe5 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseWheelEvent.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingMouseWheelEvent.java @@ -58,13 +58,16 @@ * Constructs a new PMouseWheel event from a Java MouseWheelEvent. * * @param id The event type (MOUSE_WHEEL) - * @param e The original Java mouse wheel event. + * @param swingEvent The original swing mouse wheel event. + * @param piccoloEvent Piccolo2D event for use when querying about the + * event's piccolo2d context */ - protected PSwingMouseWheelEvent(final int id, final MouseWheelEvent e, final PInputEvent event) { - super((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e - .getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()); + protected PSwingMouseWheelEvent(final int id, final MouseWheelEvent swingEvent, final PInputEvent piccoloEvent) { + super((Component) swingEvent.getSource(), swingEvent.getID(), swingEvent.getWhen(), swingEvent.getModifiers(), + swingEvent.getX(), swingEvent.getY(), swingEvent.getClickCount(), swingEvent.isPopupTrigger(), + swingEvent.getScrollType(), swingEvent.getScrollAmount(), swingEvent.getWheelRotation()); this.id = id; - this.event = event; + this.event = piccoloEvent; } /** @@ -197,10 +200,10 @@ * of the event will keep changing to reflect the scenegraph object that is * firing the event. * - * @param aSource + * @param newSource the current source of the event to report */ - public void setSource(final Object aSource) { - source = aSource; + public void setSource(final Object newSource) { + source = newSource; } /** diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java index 50960e5..e09a7ad 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingRepaintManager.java @@ -78,7 +78,7 @@ private final Vector paintingComponents = new Vector(); /** - * Locks repaint for a particular (Swing) component displayed by PCanvas + * Locks repaint for a particular (Swing) component displayed by PCanvas. * * @param c The component for which the repaint is to be locked */ @@ -87,7 +87,7 @@ } /** - * Unlocks repaint for a particular (Swing) component displayed by PCanvas + * Unlocks repaint for a particular (Swing) component displayed by PCanvas. * * @param c The component for which the repaint is to be unlocked */ @@ -97,7 +97,7 @@ /** * Returns true if repaint is currently locked for a component and false - * otherwise + * otherwise. * * @param c The component for which the repaint status is desired * @return Whether the component is currently painting diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java index 77eee4b..c05e908 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PCacheCanvas.java @@ -35,16 +35,19 @@ import edu.umd.cs.piccolox.nodes.PCacheCamera; /** - * An extension of PCanvas that automatically installs a PCacheCamera + * An extension of PCanvas that automatically installs a PCacheCamera. * * @author Lance Good */ public class PCacheCanvas extends PCanvas { - /** - * - */ + private static final long serialVersionUID = 1L; + /** + * Creates a default scene with 1 root, 1 layer, and 1 PCacheCamera. + * + * @return constructed scene with PCacheCamera + */ protected PCamera createDefaultCamera() { final PRoot r = new PRoot(); final PLayer l = new PLayer(); diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java index 912382c..4019c64 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java @@ -57,56 +57,44 @@ */ public class PDefaultScrollDirector implements PScrollDirector, PropertyChangeListener { - /** - * The viewport that signals this scroll director - */ + /** The viewport that signals this scroll director. */ protected PViewport viewPort; - /** - * The scrollpane that contains the viewport - */ + /** The scrollpane that contains the viewport. */ protected PScrollPane scrollPane; - /** - * The canvas that this class directs - */ + /** The canvas that this class directs. */ protected PCanvas view; - /** - * The canvas' camera - */ + /** The canvas' camera. */ protected PCamera camera; - /** - * The canvas' root - */ + /** The canvas' root. */ protected PRoot root; - /** - * Flag to indicate when scrolling is currently in progress - */ + /** Flag to indicate when scrolling is currently in progress. */ protected boolean scrollInProgress = false; /** - * The default constructor + * The default constructor. */ public PDefaultScrollDirector() { } /** - * Installs the scroll director and adds the appropriate listeners + * 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 + * @param targetViewPort viewport on which this director directs + * @param targetView PCanvas that the viewport looks at */ - public void install(final PViewport viewPort, final PCanvas view) { - scrollPane = (PScrollPane) viewPort.getParent(); - this.viewPort = viewPort; - this.view = view; + public void install(final PViewport targetViewPort, final PCanvas targetView) { + scrollPane = (PScrollPane) targetViewPort.getParent(); + this.viewPort = targetViewPort; + this.view = targetView; - if (view != null) { - camera = view.getCamera(); - root = view.getRoot(); + if (targetView != null) { + camera = targetView.getCamera(); + root = targetView.getRoot(); } if (camera != null) { @@ -122,7 +110,7 @@ } /** - * Uninstall the scroll director from the viewport + * Uninstall the scroll director from the viewport. */ public void unInstall() { viewPort = null; @@ -140,7 +128,7 @@ } /** - * Get the View position given the specified camera bounds + * 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 @@ -169,7 +157,7 @@ } /** - * Get the size of the view based on the specified camera bounds + * 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 @@ -200,7 +188,7 @@ } /** - * Set the view position in a manner consistent with standardized scrolling + * Set the view position in a manner consistent with standardized scrolling. * * @param x The new x position * @param y The new y position @@ -249,7 +237,9 @@ /** * Invoked when the camera's view changes, or the bounds of the root or - * camera changes + * camera changes. + * + * @param pce property change event to examine */ public void propertyChange(final PropertyChangeEvent pce) { final boolean isRelevantViewEvent = PCamera.PROPERTY_VIEW_TRANSFORM == pce.getPropertyName(); @@ -271,9 +261,9 @@ } /** - * 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. + * Should the ScrollPane be revalidated. This occurs when either the scroll + * bars are showing and should be remove or are not showing and should be + * added. * * @return Whether the scroll pane should be revalidated */ diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java index cbe8c78..fccba5d 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollDirector.java @@ -44,40 +44,40 @@ public interface PScrollDirector { /** - * Installs the scroll director + * 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); + void install(PViewport viewport, PCanvas view); /** - * Uninstall the scroll director + * Uninstall the scroll director. */ - public void unInstall(); + void unInstall(); /** - * Get the View position given the specified camera bounds + * 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 getViewPosition(Rectangle2D viewBounds); /** - * Set the view position + * Set the view position. * * @param x The new x position * @param y The new y position */ - public void setViewPosition(double x, double y); + void setViewPosition(double x, double y); /** - * Get the size of the view based on the specified camera bounds + * 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 getViewSize(Rectangle2D viewBounds); } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java index d334611..5551db8 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PScrollPane.java @@ -50,19 +50,21 @@ */ public class PScrollPane extends JScrollPane { - /** - * - */ private static final long serialVersionUID = 1L; - // A reusable null action + /** A reusable null action. */ protected PNullAction nullAction = null; - // Are key actions disabled on this component? + /** Controls whether key actions are disabled on this component. */ protected boolean disableKeyActions = false; /** - * Pass on the constructor info to the super + * Constructs a scollpane for the provided component with the specified + * scrollbar policies. + * + * @param view component being viewed through the scrollpane + * @param vsbPolicy vertical scroll bar policy + * @param hsbPolicy horizontal scroll bar policy */ public PScrollPane(final Component view, final int vsbPolicy, final int hsbPolicy) { super(view, vsbPolicy, hsbPolicy); @@ -74,28 +76,34 @@ } /** - * Pass on the constructor info to the super + * Constructs a scollpane for the provided component. + * + * @param view component being viewed through the scrollpane */ public PScrollPane(final Component view) { this(view, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED); } /** - * Pass on the constructor info to the super + * Constructs a scollpane not attached to any component with the specified + * scroll bar policies. + * + * @param vsbPolicy vertical scroll bar policy + * @param hsbPolicy horizontal scroll bar policy */ public PScrollPane(final int vsbPolicy, final int hsbPolicy) { this(null, vsbPolicy, hsbPolicy); } /** - * Pass on the constructor info to the super + * Constructs a scollpane not attached to any component. */ public PScrollPane() { this(null, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED); } /** - * Disable or enable key actions on this PScrollPane + * Disable or enable key actions on this PScrollPane. * * @param disable true disables key actions, false enables key actions */ @@ -111,7 +119,9 @@ } /** - * Sets the UI + * Sets the UI. + * + * @param ui the scroll pane ui to associate with this PScollPane */ public void setUI(final ScrollPaneUI ui) { super.setUI(ui); @@ -126,7 +136,7 @@ /** * Install custom key actions (in place of the Swing defaults) to correctly - * scroll the view + * scroll the view. */ protected void installCustomKeyActions() { final ActionMap map = getActionMap(); @@ -146,7 +156,7 @@ } /** - * Disables key actions on this PScrollPane + * Disables key actions on this PScrollPane. */ protected void disableKeyActions() { final ActionMap map = getActionMap(); @@ -168,9 +178,9 @@ } /** - * Overridden to create the Jazz viewport + * Overridden to create the Piccolo2D viewport. * - * @return The jazz version of the viewport + * @return the Piccolo2D version of the viewport */ protected JViewport createViewport() { return new PViewport(); @@ -178,16 +188,14 @@ /** * Action to scroll left/right/up/down. Modified from - * javax.swing.plaf.basic.BasicScrollPaneUI.ScrollAction + * 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 + * relevant scrollbar is visible. */ protected static class PScrollAction extends AbstractAction { - /** - * - */ + private static final int MINIMUM_SCROLL_SIZE = 10; private static final long serialVersionUID = 1L; /** Direction to scroll. */ protected int orientation; @@ -196,6 +204,15 @@ /** True indicates a block scroll, otherwise a unit scroll. */ private final boolean block; + /** + * Constructs a scroll action with the given name in the given + * orientiation stated and in the direction provided. + * + * @param name arbitrary name of action + * @param orientation horizontal or vertical + * @param direction 1 indicates scroll down, -1 up + * @param block true if block scroll as opposed to unit + */ protected PScrollAction(final String name, final int orientation, final int direction, final boolean block) { super(name); this.orientation = orientation; @@ -203,77 +220,90 @@ this.block = block; } - public void actionPerformed(final ActionEvent e) { - final 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()) { + /** + * Performs the scroll action if the action was performed on visible + * scrollbars and if the viewport is valid. + * + * @param event the event responsible for this action being performed + */ + public void actionPerformed(final ActionEvent event) { + final JScrollPane scrollpane = (JScrollPane) event.getSource(); + if (!isScrollEventOnVisibleScrollbars(scrollpane)) { + return; + } - final JViewport vp = scrollpane.getViewport(); - Component view; - if (vp != null && (view = vp.getView()) != null) { - final Rectangle visRect = vp.getViewRect(); - // LEG: Modification to query the viewport for the - // view size rather than going directly to the view - final Dimension vSize = vp.getViewSize(); - int amount; + final JViewport vp = scrollpane.getViewport(); + if (vp == null) { + return; + } - 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()); + Component view = vp.getView(); + if (view == null) { + return; + } + + final Rectangle visRect = vp.getViewRect(); + // LEG: Modification to query the viewport for the + // view size rather than going directly to the view + final Dimension vSize = vp.getViewSize(); + final 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 = MINIMUM_SCROLL_SIZE; + } + } + + 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()); + } + + private boolean isScrollEventOnVisibleScrollbars(final JScrollPane scrollpane) { + return orientation == SwingConstants.VERTICAL && scrollpane.getVerticalScrollBar().isShowing() + || orientation == SwingConstants.HORIZONTAL && scrollpane.getHorizontalScrollBar().isShowing(); } } /** * Action to scroll to x,y location of 0,0. Modified from - * javax.swing.plaf.basic.BasicScrollPaneUI.ScrollEndAction + * javax.swing.plaf.basic.BasicScrollPaneUI.ScrollEndAction. * - * Only performs the event if a scrollbar is visible + * Only performs the event if a scrollbar is visible. */ private static class PScrollHomeAction extends AbstractAction { - /** - * - */ private static final long serialVersionUID = 1L; protected PScrollHomeAction(final String name) { @@ -295,23 +325,30 @@ /** * Action to scroll to last visible location. Modified from - * javax.swing.plaf.basic.BasicScrollPaneUI.ScrollEndAction + * 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 + * also only performs the event if a scrollbar is visible. */ protected static class PScrollEndAction extends AbstractAction { - /** - * - */ private static final long serialVersionUID = 1L; + /** + * Constructs a scroll to end action with the given name. + * + * @param name name to assign to this action + */ protected PScrollEndAction(final String name) { super(name); } - public void actionPerformed(final ActionEvent e) { - final JScrollPane scrollpane = (JScrollPane) e.getSource(); + /** + * Scrolls to the end of the viewport if there are visible scrollbars. + * + * @param event event responsible for the scroll event + */ + public void actionPerformed(final ActionEvent event) { + final JScrollPane scrollpane = (JScrollPane) event.getSource(); // LEG: Modification to only perform these actions if one of the // scrollbars is actually showing if (scrollpane.getVerticalScrollBar().isShowing() || scrollpane.getHorizontalScrollBar().isShowing()) { @@ -331,14 +368,16 @@ /** * An action to do nothing - put into an action map to keep it from looking - * to its parent + * to its parent. */ protected static class PNullAction extends AbstractAction { - /** - * - */ private static final long serialVersionUID = 1L; + /** + * Does nothing. + * + * @param e Event responsible for this action + */ public void actionPerformed(final ActionEvent e) { } }