diff --git a/swt/src/build/conf/checkstyle.xml b/swt/src/build/conf/checkstyle.xml index d12343e..8948914 100644 --- a/swt/src/build/conf/checkstyle.xml +++ b/swt/src/build/conf/checkstyle.xml @@ -3,174 +3,167 @@ "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> - + - the Java Language Specification at + http://java.sun.com/docs/books/jls/second_edition/html/index.html - + the Sun Code Conventions at http://java.sun.com/docs/codeconv/ - the + Javadoc guidelines at + http://java.sun.com/j2se/javadoc/writingdoccomments/index.html - the + JDK Api documentation http://java.sun.com/j2se/docs/api/index.html - + some best practices Checkstyle is very configurable. Be sure to read + the documentation at http://checkstyle.sf.net (or in your downloaded + distribution). Most Checks are configurable, be sure to consult the + documentation. To completely disable a check, just comment it out or + delete it from the file. Finally, it is worth reading the + documentation. + --> - - - + + + - - - + + + - + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - + + + + + + - + diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java index 0cf17ec..2f80bc6 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTCanvas.java @@ -72,6 +72,10 @@ * @author Jesse Grosjean */ public class PSWTCanvas extends Composite implements PComponent { + private static final int SWT_BUTTON1 = 1; + private static final int SWT_BUTTON2 = 2; + private static final int SWT_BUTTON3 = 3; + /** * Terrible Singleton instance of the PSWTCanvas. Falsely assumes you will * only have one of these per application. @@ -505,11 +509,13 @@ } private boolean backBufferNeedsResizing(final int newWidth, final int newHeight) { - if (!doubleBuffered) + if (!doubleBuffered) { return false; + } - if (backBuffer == null) + if (backBuffer == null) { return true; + } return backBuffer.getBounds().width < newWidth || backBuffer.getBounds().height < newHeight; } @@ -655,19 +661,19 @@ boolean shouldBalanceEvent = false; switch (mouseEvent.button) { - case 1: + case SWT_BUTTON1: if (isButton1Pressed) { shouldBalanceEvent = true; } isButton1Pressed = true; break; - case 2: + case SWT_BUTTON2: if (isButton2Pressed) { shouldBalanceEvent = true; } isButton2Pressed = true; break; - case 3: + case SWT_BUTTON3: if (isButton3Pressed) { shouldBalanceEvent = true; } @@ -691,19 +697,19 @@ boolean shouldBalanceEvent = false; switch (me.button) { - case 1: + case SWT_BUTTON1: if (!isButton1Pressed) { shouldBalanceEvent = true; } isButton1Pressed = false; break; - case 2: + case SWT_BUTTON2: if (!isButton2Pressed) { shouldBalanceEvent = true; } isButton2Pressed = false; break; - case 3: + case SWT_BUTTON3: if (!isButton3Pressed) { shouldBalanceEvent = true; } diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java index ee23719..95c3330 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTHandle.java @@ -59,13 +59,12 @@ * @author Jesse Grosjean */ public class PSWTHandle extends PSWTPath { - - /** - * - */ private static final long serialVersionUID = 1L; + /** The Default Size of a handle not including its border. */ public static float DEFAULT_HANDLE_SIZE = 8; + /** The default shape to use when drawing handles. Default is an ellipse. */ public static Shape DEFAULT_HANDLE_SHAPE = new Ellipse2D.Float(0f, 0f, DEFAULT_HANDLE_SIZE, DEFAULT_HANDLE_SIZE); + /** The default color to use when drawing a handle. (white) */ public static Color DEFAULT_COLOR = Color.white; private PLocator locator; @@ -74,6 +73,8 @@ /** * Construct a new handle that will use the given locator to locate itself * on its parent node. + * + * @param aLocator locator to use when positioning this handle */ public PSWTHandle(final PLocator aLocator) { super(DEFAULT_HANDLE_SHAPE); @@ -82,26 +83,12 @@ installHandleEventHandlers(); } + /** + * Installs the handler that will reposition the handle when it is dragged, + * and invoke appropriate call backs. + */ protected void installHandleEventHandlers() { - handleDragger = new PDragSequenceEventHandler() { - protected void startDrag(final PInputEvent event) { - super.startDrag(event); - startHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event); - } - - protected void drag(final PInputEvent event) { - super.drag(event); - final PDimension aDelta = event.getDeltaRelativeTo(PSWTHandle.this); - if (aDelta.getWidth() != 0 || aDelta.getHeight() != 0) { - dragHandle(aDelta, event); - } - } - - protected void endDrag(final PInputEvent event) { - super.endDrag(event); - endHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event); - } - }; + handleDragger = new HandleDragHandler(); addPropertyChangeListener(PNode.PROPERTY_TRANSFORM, new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { @@ -109,12 +96,6 @@ } }); - handleDragger.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK)); - handleDragger.getEventFilter().setMarksAcceptedEventsAsHandled(true); - handleDragger.getEventFilter().setAcceptsMouseEntered(false); - handleDragger.getEventFilter().setAcceptsMouseExited(false); - // no need for moved events for handle interaction, - handleDragger.getEventFilter().setAcceptsMouseMoved(false); // so reject them so we don't consume them addInputEventListener(handleDragger); } @@ -122,6 +103,8 @@ /** * Return the event handler that is responsible for the drag handle * interaction. + * + * @return handler responsible for responding to drag events */ public PDragSequenceEventHandler getHandleDraggerHandler() { return handleDragger; @@ -130,6 +113,8 @@ /** * Get the locator that this handle uses to position itself on its parent * node. + * + * @return locator used to position this handle */ public PLocator getLocator() { return locator; @@ -138,6 +123,8 @@ /** * Set the locator that this handle uses to position itself on its parent * node. + * + * @param aLocator used to position this handle */ public void setLocator(final PLocator aLocator) { locator = aLocator; @@ -153,12 +140,20 @@ /** * Override this method to get notified when the handle starts to get * dragged. + * + * @param aLocalPoint point at which dragging was started relative to the + * handle's coordinate system + * @param aEvent event representing the start of the drag */ public void startHandleDrag(final Point2D aLocalPoint, final PInputEvent aEvent) { } /** * Override this method to get notified as the handle is dragged. + * + * @param aLocalDimension magnitude of the dragHandle event in the + * dimensions of the handle's coordinate system. + * @param aEvent event representing the drag */ public void dragHandle(final PDimension aLocalDimension, final PInputEvent aEvent) { } @@ -166,6 +161,10 @@ /** * Override this method to get notified when the handle stops getting * dragged. + * + * @param aLocalPoint point at which dragging was ended relative to the + * handle's coordinate system + * @param aEvent event representing the end of the drag */ public void endHandleDrag(final Point2D aLocalPoint, final PInputEvent aEvent) { } @@ -179,7 +178,7 @@ /** {@inheritDoc} */ public void setParent(final PNode newParent) { - super.setParent(newParent); + super.setParent(newParent); relocateHandle(); } @@ -225,4 +224,33 @@ in.defaultReadObject(); installHandleEventHandlers(); } + + private final class HandleDragHandler extends PDragSequenceEventHandler { + public HandleDragHandler() { + final PInputEventFilter filter = new PInputEventFilter(InputEvent.BUTTON1_MASK); + setEventFilter(filter); + filter.setMarksAcceptedEventsAsHandled(true); + filter.setAcceptsMouseEntered(false); + filter.setAcceptsMouseExited(false); + filter.setAcceptsMouseMoved(false); + } + + protected void startDrag(final PInputEvent event) { + super.startDrag(event); + startHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event); + } + + protected void drag(final PInputEvent event) { + super.drag(event); + final PDimension aDelta = event.getDeltaRelativeTo(PSWTHandle.this); + if (aDelta.getWidth() != 0 || aDelta.getHeight() != 0) { + dragHandle(aDelta, event); + } + } + + protected void endDrag(final PInputEvent event) { + super.endDrag(event); + endHandleDrag(event.getPositionRelativeTo(PSWTHandle.this), event); + } + } } \ No newline at end of file diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java index 31bbf66..9e826e0 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTKeyEvent.java @@ -37,49 +37,52 @@ import org.eclipse.swt.widgets.Widget; /** - * Overridden to wrap an SWT KeyEvent + * Overridden to wrap an SWT KeyEvent as a swing KeyEvent. * * @author Lance Good */ public class PSWTKeyEvent extends KeyEvent { - - /** - * - */ private static final long serialVersionUID = 1L; - static Component fakeSrc = new Component() { - - /** - * - */ - private static final long serialVersionUID = 1L; + private static Component fakeSrc = new Component() { }; - org.eclipse.swt.events.KeyEvent swtEvent; + private org.eclipse.swt.events.KeyEvent swtEvent; + /** + * Creates an object that wraps a SWT Key event. Making it queriable from + * Piccolo2d as though it were a Swing one. + * + * @param ke key event object + * @param eventType type of key event + */ public PSWTKeyEvent(final org.eclipse.swt.events.KeyEvent ke, final int eventType) { super(fakeSrc, eventType, ke.time, 0, ke.keyCode, ke.character, KeyEvent.KEY_LOCATION_STANDARD); swtEvent = ke; } + /** {@inheritDoc} */ public Object getSource() { return swtEvent.getSource(); } + /** {@inheritDoc} */ public boolean isShiftDown() { return (swtEvent.stateMask & SWT.SHIFT) != 0; } + /** {@inheritDoc} */ public boolean isControlDown() { return (swtEvent.stateMask & SWT.CONTROL) != 0; } + /** {@inheritDoc} */ public boolean isAltDown() { return (swtEvent.stateMask & SWT.ALT) != 0; } + /** {@inheritDoc} */ public int getModifiers() { int modifiers = 0; @@ -98,6 +101,7 @@ return modifiers; } + /** {@inheritDoc} */ public int getModifiersEx() { int modifiers = 0; @@ -116,22 +120,34 @@ return modifiers; } + /** {@inheritDoc} */ public boolean isActionKey() { return false; } - // ///////////////////////// - // THE SWT SPECIFIC EVENTS - // ///////////////////////// - + /** + * Returns the widget from which the event was emitted. + * + * @return source widget + */ public Widget getWidget() { return swtEvent.widget; } + /** + * Return the display on which the interaction occurred. + * + * @return display on which the interaction occurred + */ public Display getDisplay() { return swtEvent.display; } + /** + * Return the associated SWT data for the event. + * + * @return data associated to the SWT event + */ public Object getData() { return swtEvent.data; } diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java index fa94507..c6c4c8e 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTMouseEvent.java @@ -37,69 +37,81 @@ import org.eclipse.swt.widgets.Widget; /** - * Overridden to wrap an SWT MouseEvent + * Overridden to wrap an SWT MouseEvent as a Swing MouseEvent. * * @author Lance Good */ public class PSWTMouseEvent extends MouseEvent { + private static final int SWT_BUTTON1 = 1; + private static final int SWT_BUTTON2 = 2; + private static final int SWT_BUTTON3 = 3; - /** - * - */ private static final long serialVersionUID = 1L; - static Component fakeSrc = new Component() { - - /** - * - */ - private static final long serialVersionUID = 1L; + private static Component fakeSrc = new Component() { }; + /** Event being wrapped. */ protected org.eclipse.swt.events.MouseEvent swtEvent; + /** Number times the mouse was clicked in relation to the wrapped event. */ protected int clickCount; + /** + * Constructs a PSWTMouseEvent that wraps the provided SWT MouseEvent as a + * Swing one. + * + * @param me Mouse Event being wrapped + * @param type event type + * @param clickCount number of times the mouse has been clicked + */ public PSWTMouseEvent(final org.eclipse.swt.events.MouseEvent me, final int type, final int clickCount) { - super(fakeSrc, type, me.time, 0, me.x, me.y, clickCount, me.button == 3, me.button); + super(fakeSrc, type, me.time, 0, me.x, me.y, clickCount, me.button == SWT_BUTTON3, me.button); swtEvent = me; this.clickCount = clickCount; } + /** {@inheritDoc} */ public Object getSource() { return swtEvent.getSource(); } + /** {@inheritDoc} */ public int getClickCount() { return clickCount; } + /** {@inheritDoc} */ public int getButton() { switch (swtEvent.button) { - case 1: + case SWT_BUTTON1: return MouseEvent.BUTTON1; - case 2: + case SWT_BUTTON2: return MouseEvent.BUTTON2; - case 3: + case SWT_BUTTON3: return MouseEvent.BUTTON3; default: return MouseEvent.NOBUTTON; } } + /** {@inheritDoc} */ public boolean isShiftDown() { return (swtEvent.stateMask & SWT.SHIFT) != 0; } + /** {@inheritDoc} */ public boolean isControlDown() { return (swtEvent.stateMask & SWT.CONTROL) != 0; } + /** {@inheritDoc} */ public boolean isAltDown() { return (swtEvent.stateMask & SWT.ALT) != 0; } + /** {@inheritDoc} */ public int getModifiers() { int modifiers = 0; @@ -113,13 +125,13 @@ if ((swtEvent.stateMask & SWT.SHIFT) != 0) { modifiers = modifiers | InputEvent.SHIFT_MASK; } - if (swtEvent.button == 1 || (swtEvent.stateMask & SWT.BUTTON1) != 0) { + if (swtEvent.button == SWT_BUTTON1 || (swtEvent.stateMask & SWT.BUTTON1) != 0) { modifiers = modifiers | InputEvent.BUTTON1_MASK; } - if (swtEvent.button == 2 || (swtEvent.stateMask & SWT.BUTTON2) != 0) { + if (swtEvent.button == SWT_BUTTON2 || (swtEvent.stateMask & SWT.BUTTON2) != 0) { modifiers = modifiers | InputEvent.BUTTON2_MASK; } - if (swtEvent.button == 3 || (swtEvent.stateMask & SWT.BUTTON3) != 0) { + if (swtEvent.button == SWT_BUTTON3 || (swtEvent.stateMask & SWT.BUTTON3) != 0) { modifiers = modifiers | InputEvent.BUTTON3_MASK; } } @@ -127,6 +139,7 @@ return modifiers; } + /** {@inheritDoc} */ public int getModifiersEx() { int modifiers = 0; @@ -140,13 +153,13 @@ if ((swtEvent.stateMask & SWT.SHIFT) != 0) { modifiers = modifiers | InputEvent.SHIFT_DOWN_MASK; } - if (swtEvent.button == 1 || (swtEvent.stateMask & SWT.BUTTON1) != 0) { + if (swtEvent.button == SWT_BUTTON1 || (swtEvent.stateMask & SWT.BUTTON1) != 0) { modifiers = modifiers | InputEvent.BUTTON1_DOWN_MASK; } - if (swtEvent.button == 2 || (swtEvent.stateMask & SWT.BUTTON2) != 0) { + if (swtEvent.button == SWT_BUTTON2 || (swtEvent.stateMask & SWT.BUTTON2) != 0) { modifiers = modifiers | InputEvent.BUTTON2_DOWN_MASK; } - if (swtEvent.button == 3 || (swtEvent.stateMask & SWT.BUTTON3) != 0) { + if (swtEvent.button == SWT_BUTTON3 || (swtEvent.stateMask & SWT.BUTTON3) != 0) { modifiers = modifiers | InputEvent.BUTTON3_DOWN_MASK; } } @@ -154,18 +167,29 @@ return modifiers; } - // ///////////////////////// - // THE SWT SPECIFIC EVENTS - // ///////////////////////// - + /** + * Returns the widget from which the event was emitted. + * + * @return source widget + */ public Widget getWidget() { return swtEvent.widget; } + /** + * Return the display on which the interaction occurred. + * + * @return display on which the interaction occurred + */ public Display getDisplay() { return swtEvent.display; } + /** + * Return the associated SWT data for the event. + * + * @return data associated to the SWT event + */ public Object getData() { return swtEvent.data; } diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java index 1747e4f..00d47c5 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTRoot.java @@ -47,21 +47,33 @@ * @author Jesse Grosjean */ public class PSWTRoot extends PRoot { - - /** - * - */ private static final long serialVersionUID = 1L; private final Composite composite; + /** + * Constructs a PSWTRoot attached to the provided composite. + * + * @param composite composite PSWTRoot is responsible for + */ public PSWTRoot(final Composite composite) { this.composite = composite; } + /** + * Creates a timer that will fire the listener every delay milliseconds. + * + * @param delay time in milliseconds between firings of listener + * @param listener listener to be fired + * + * @return the created timer + */ public Timer createTimer(final int delay, final ActionListener listener) { return new SWTTimer(composite.getDisplay(), delay, listener); } + /** + * Processes Inputs if any kind of IO needs to be done. + */ public void scheduleProcessInputsIfNeeded() { if (!Thread.currentThread().equals(composite.getDisplay().getThread())) { return; diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java index aa17a50..4bd4b38 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTSelectionEventHandler.java @@ -43,7 +43,7 @@ import edu.umd.cs.piccolox.event.PSelectionEventHandler; /** - * Modified to use SWT paths instead of normal paths + * Modified to use SWT paths instead of normal paths. * * @version 1.0 * @author Lance Good @@ -81,20 +81,32 @@ this.marqueeParent = marqueeParent; } + /** + * Modifies the provided node so that it is displayed as selected. + * + * @param node node to be decorated + */ public void decorateSelectedNode(final PNode node) { PSWTBoundsHandle.addBoundsHandlesTo(node); } + /** + * Undoes any modifications to the provided node so that it is not displayed as selected. + * + * @param node node to be undecorated + */ public void undecorateSelectedNode(final PNode node) { PSWTBoundsHandle.removeBoundsHandlesFrom(node); } + /** {@inheritDoc} */ protected void initializeSelection(final PInputEvent pie) { super.initializeSelection(pie); pressPt = pie.getPosition(); canvasPressPt = pie.getCanvasPosition(); } + /** {@inheritDoc} */ protected void initializeMarquee(final PInputEvent e) { super.initializeMarquee(e); @@ -116,6 +128,7 @@ marqueeParent.addChild(marquee); } + /** {@inheritDoc} */ protected void updateMarquee(final PInputEvent pie) { super.updateMarquee(pie); @@ -136,6 +149,7 @@ b.add(pie.getPosition()); } + /** {@inheritDoc} */ protected PBounds getMarqueeBounds() { if (marquee != null) { return marquee.getBounds(); @@ -143,18 +157,15 @@ return new PBounds(); } + /** {@inheritDoc} */ protected void endMarqueeSelection(final PInputEvent e) { super.endMarqueeSelection(e); - // Remove marquee marquee.removeFromParent(); marquee = null; } - /** - * This gets called continuously during the drag, and is used to animate the - * marquee - */ + /** {@inheritDoc} */ protected void dragActivityStep(final PInputEvent aEvent) { } } \ No newline at end of file diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java index 74486ec..27abe0e 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTStickyHandleManager.java @@ -33,26 +33,39 @@ import edu.umd.cs.piccolo.util.PBounds; import edu.umd.cs.piccolo.util.PPickPath; +/** + * A class for managing the position of a sticky handle. + */ public class PSWTStickyHandleManager extends PNode { - - /** - * - */ private static final long serialVersionUID = 1L; private PNode target; private PCamera camera; - public PSWTStickyHandleManager(final PCamera newCamera, final PNode newTarget) { - setCameraTarget(newCamera, newTarget); + /** + * Creates a sticky handle that will be displayed on the given camera and + * will update the provided target. + * + * @param camera camera on which to display the sticky handle + * @param target target being controlled by the handle + */ + public PSWTStickyHandleManager(final PCamera camera, final PNode target) { + setCameraTarget(camera, target); PSWTBoundsHandle.addBoundsHandlesTo(this); } + /** + * Changes the associated camera and target for this sticky handle. + * + * @param newCamera new camera onto which this handle should appear + * @param newTarget new target which this handle will control + */ public void setCameraTarget(final PCamera newCamera, final PNode newTarget) { camera = newCamera; camera.addChild(this); target = newTarget; } + /** {@inheritDoc} */ public boolean setBounds(final double x, final double y, final double width, final double height) { final PBounds b = new PBounds(x, y, width, height); camera.localToGlobal(b); @@ -62,10 +75,17 @@ return super.setBounds(x, y, width, height); } + /** + * Always returns true to ensure that they will always be displayed + * appropriately. + * + * @return true + */ protected boolean getBoundsVolatile() { return true; } + /** {@inheritDoc} */ public PBounds getBoundsReference() { final PBounds targetBounds = target.getFullBounds(); camera.viewToLocal(targetBounds); @@ -75,16 +95,27 @@ return super.getBoundsReference(); } + /** {@inheritDoc} */ public void startResizeBounds() { super.startResizeBounds(); target.startResizeBounds(); } + /** {@inheritDoc} */ public void endResizeBounds() { super.endResizeBounds(); target.endResizeBounds(); } + /** + * Since PSWTStickyHandle manager is not visible on screen, it just returns + * false when it is asked to be repainted. + * + * @param pickPath path of this node in which the interaction occurred that + * required the repaint + * + * @return always false + */ public boolean pickAfterChildren(final PPickPath pickPath) { return false; } diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java index dd9f67a..855c364 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTShapeManager.java @@ -41,11 +41,10 @@ * @author Lance Good */ public class SWTShapeManager { - - static AffineTransform IDENTITY_XFORM = new AffineTransform(); - static Point2D aPoint = new Point2D.Double(); - static ArrayList segList = new ArrayList(); - static double[] pts = new double[8]; + private static AffineTransform IDENTITY_XFORM = new AffineTransform(); + private static Point2D aPoint = new Point2D.Double(); + private static ArrayList segList = new ArrayList(); + private static double[] pts = new double[8]; /** * Apply the specified transform to the specified rectangle, modifying the @@ -89,6 +88,13 @@ rect.setRect(minX, minY, maxX - minX, maxY - minY); } + /** + * Populates the SWT rectangle with the provided Swing Rectangle2D's + * coordinates. Rounding up to the nearest integer. + * + * @param aRect awt rectangle to extract coordinates from + * @param sRect swt rectangle to populate + */ public static void awtToSWT(final Rectangle2D aRect, final Rectangle sRect) { sRect.x = (int) (aRect.getX() + 0.5); sRect.y = (int) (aRect.getY() + 0.5); @@ -96,11 +102,19 @@ sRect.height = (int) (aRect.getHeight() + 0.5); } - public static double[] shapeToPolyline(final Shape s) { + /** + * Converts the provided shape into an array of point coordinates given as + * one dimensional array with this format: x1,y1,x2,y3,.... + * + * @param shape shape to convert + * @return point coordinates given as one dimensional array with this + * format: x1,y1,x2,y3,... + */ + public static double[] shapeToPolyline(final Shape shape) { segList.clear(); aPoint.setLocation(0, 0); - final PathIterator pi = s.getPathIterator(IDENTITY_XFORM, 0.000000001); + final PathIterator pi = shape.getPathIterator(IDENTITY_XFORM, 0.000000001); while (!pi.isDone()) { final int segType = pi.currentSegment(pts); switch (segType) { @@ -128,6 +142,14 @@ return polyObj; } + /** + * Transforms the given points by the transform provided, leaving the + * original points untouched. + * + * @param pts points to transform + * @param at transform to apply + * @return transformed coordinates given in format x1,y2,x2,y2,... + */ public static int[] transform(final double[] pts, final AffineTransform at) { final int[] intPts = new int[pts.length]; for (int i = 0; i < pts.length / 2; i++) { diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimer.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimer.java index 340fe26..cde5412 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimer.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimer.java @@ -324,7 +324,7 @@ /** * @param running the running to set */ - public void setRunning(boolean running) { + public void setRunning(final boolean running) { this.running = running; } diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java index 95b95ef..a5f715b 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTTimerQueue.java @@ -212,8 +212,14 @@ return null; } + /** + * Returns true if this timer queue contains the given timer. + * + * @param timer timer being checked + * @return true if timer is scheduled in this queue + */ synchronized boolean containsTimer(final SWTTimer timer) { - //TODO: making this use isRunning without causing an infinite loop + // TODO: making this use isRunning without causing an infinite loop return timer.running; } @@ -221,8 +227,11 @@ * If there are a ton of timers, this method may never return. It loops * checking to see if the head of the Timer list has expired. If it has, it * posts the Timer and reschedules it if necessary. + * + * @return how long the app can take before it should invoke this method + * again. */ - synchronized long postExpiredTimers() { + private synchronized long postExpiredTimers() { SWTTimer timer; long currentTime; long timeToWait; @@ -265,14 +274,17 @@ wait(1); } catch (final InterruptedException e) { - + // Nothing to do } } } while (timeToWait <= 0); return timeToWait; } - + + /** + * Dispatches work to timers until the queue is told to stop running. + */ public synchronized void run() { long timeToWait; @@ -283,6 +295,7 @@ wait(timeToWait); } catch (final InterruptedException e) { + // Nothing to do } } } @@ -335,15 +348,24 @@ private final Display display; + /** + * Constructs a QueueRestart Runnable that will message the Timer Queue + * to Restart. + * + * @param display display associated with the SWTTimerQueue + */ public SWTTimerQueueRestart(final Display display) { this.display = display; } - public synchronized void run() { + /** + * Attempts to restart the queue associated with the display. + */ + public synchronized void run() { if (attemptedStart) { return; } - + final SWTTimerQueue q = SWTTimerQueue.sharedInstance(display); synchronized (q) {