diff --git a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java index de9f98b..462e84f 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java +++ b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java @@ -53,9 +53,9 @@ */ public class PInputEventFilter { - public static int ALL_MODIFIERS_MASK = InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK - | InputEvent.BUTTON3_MASK | InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK - | InputEvent.ALT_GRAPH_MASK | InputEvent.META_MASK; + public static int ALL_MODIFIERS_MASK = InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK + | InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK + | InputEvent.META_MASK; private int andMask; private int orMask; diff --git a/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java b/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java index 262cc53..8d995d2 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java +++ b/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java @@ -76,17 +76,24 @@ /** * The property name that identifies a change of this node's text paint (see - * {@link #getTextPaint getTextPaint}). Both old and new value will be set in any - * property change event. + * {@link #getTextPaint getTextPaint}). Both old and new value will be set + * in any property change event. */ public static final String PROPERTY_TEXT_PAINT = "text paint"; public static final int PROPERTY_CODE_TEXT_PAINT = 1 << 21; - /** Default font, 12 point "SansSerif". Will be made final in version 2.0. */ - //public static final Font DEFAULT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 12); jdk 1.6+ + /** + * Default font, 12 point "SansSerif". Will be made final in + * version 2.0. + */ + // public static final Font DEFAULT_FONT = new Font(Font.SANS_SERIF, + // Font.PLAIN, 12); jdk 1.6+ public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 12); - /** Default greek threshold, 5.5d. Will be made final in version 2.0. */ + /** + * Default greek threshold, 5.5d. Will be made final in version + * 2.0. + */ public static double DEFAULT_GREEK_THRESHOLD = 5.5d; /** Default horizontal alignment, Component.LEFT_ALIGNMENT. */ @@ -109,7 +116,6 @@ private boolean constrainWidthToTextWidth = true; private transient TextLayout[] lines; - /** * Create a new text node with no text (""). */ @@ -119,7 +125,7 @@ /** * Create a new text node with the specified text. - * + * * @param text text for this text node */ public PText(final String text) { @@ -127,22 +133,23 @@ setText(text); } - /** @deprecated by {@link #getHorizontalAlignment()} */ public float getJustification() { return getHorizontalAlignment(); } - /** @deprecated by {@link #setHorizontalAlignment(float)} */ + /** @deprecated by {@link #setHorizontalAlignment(float)} */ public void setJustification(final float justification) { setHorizontalAlignment(justification); } /** - * Return the horizontal alignment for this text node. The horizontal alignment will be one of - * Component.LEFT_ALIGNMENT, Component.CENTER_ALIGNMENT, - * or Component.RIGHT_ALIGNMENT. Defaults to {@link #DEFAULT_HORIZONTAL_ALIGNMENT}. - * + * Return the horizontal alignment for this text node. The horizontal + * alignment will be one of Component.LEFT_ALIGNMENT, + * Component.CENTER_ALIGNMENT, or + * Component.RIGHT_ALIGNMENT. Defaults to + * {@link #DEFAULT_HORIZONTAL_ALIGNMENT}. + * * @return the horizontal alignment for this text node */ public float getHorizontalAlignment() { @@ -150,11 +157,13 @@ } /** - * Set the horizontal alignment for this text node to horizontalAlignment. - * + * Set the horizontal alignment for this text node to + * horizontalAlignment. + * * @param horizontalAlignment horizontal alignment, must be one of - * Component.LEFT_ALIGNMENT, Component.CENTER_ALIGNMENT, - * or Component.RIGHT_ALIGNMENT + * Component.LEFT_ALIGNMENT, + * Component.CENTER_ALIGNMENT, or + * Component.RIGHT_ALIGNMENT */ public void setHorizontalAlignment(final float horizontalAlignment) { if (!validHorizontalAlignment(horizontalAlignment)) { @@ -165,16 +174,19 @@ } /** - * Return true if the specified horizontal alignment is one of Component.LEFT_ALIGNMENT, - * Component.CENTER_ALIGNMENT, or Component.RIGHT_ALIGNMENT. - * + * Return true if the specified horizontal alignment is one of + * Component.LEFT_ALIGNMENT, + * Component.CENTER_ALIGNMENT, or + * Component.RIGHT_ALIGNMENT. + * * @param horizontalAlignment horizontal alignment - * @return true if the specified horizontal alignment is one of Component.LEFT_ALIGNMENT, - * Component.CENTER_ALIGNMENT, or Component.RIGHT_ALIGNMENT + * @return true if the specified horizontal alignment is one of + * Component.LEFT_ALIGNMENT, + * Component.CENTER_ALIGNMENT, or + * Component.RIGHT_ALIGNMENT */ private static boolean validHorizontalAlignment(final float horizontalAlignment) { - return Component.LEFT_ALIGNMENT == horizontalAlignment - || Component.CENTER_ALIGNMENT == horizontalAlignment + return Component.LEFT_ALIGNMENT == horizontalAlignment || Component.CENTER_ALIGNMENT == horizontalAlignment || Component.RIGHT_ALIGNMENT == horizontalAlignment; } @@ -189,9 +201,11 @@ /** * Set the paint used to paint this node's text to textPaint. - * - *

This is a bound property.

- * + * + *

+ * This is a bound property. + *

+ * * @param textPaint text paint */ public void setTextPaint(final Paint textPaint) { @@ -205,19 +219,22 @@ } /** - * Return true if this text node should constrain its width to the width of its text. - * Defaults to true. - * - * @return true if this text node should constrain its width to the width of its text + * Return true if this text node should constrain its width to the width of + * its text. Defaults to true. + * + * @return true if this text node should constrain its width to the width of + * its text */ public boolean isConstrainWidthToTextWidth() { return constrainWidthToTextWidth; } /** - * Set to true if this text node should constrain its width the width of its text. - * - * @param constrainWidthToTextWidth true if this text node should constrain its width to the width of its text + * Set to true if this text node should constrain its width the + * width of its text. + * + * @param constrainWidthToTextWidth true if this text node should constrain + * its width to the width of its text */ public void setConstrainWidthToTextWidth(final boolean constrainWidthToTextWidth) { this.constrainWidthToTextWidth = constrainWidthToTextWidth; @@ -225,19 +242,22 @@ } /** - * Return true if this text node should constrain its height to the height of its text. - * Defaults to true. - * - * @return true if this text node should constrain its height to the height of its text + * Return true if this text node should constrain its height to the height + * of its text. Defaults to true. + * + * @return true if this text node should constrain its height to the height + * of its text */ public boolean isConstrainHeightToTextHeight() { return constrainHeightToTextHeight; } /** - * Set to true if this text node should constrain its height the height of its text. - * - * @param constrainHeightToTextHeight true if this text node should constrain its height to the width of its height + * Set to true if this text node should constrain its height + * the height of its text. + * + * @param constrainHeightToTextHeight true if this text node should + * constrain its height to the width of its height */ public void setConstrainHeightToTextHeight(final boolean constrainHeightToTextHeight) { this.constrainHeightToTextHeight = constrainHeightToTextHeight; @@ -245,10 +265,10 @@ } /** - * Return the greek threshold in screen font size. When the screen font size will be - * below this threshold the text is rendered as 'greek' instead of drawing - * the text glyphs. Defaults to {@link DEFAULT_GREEK_THRESHOLD}. - * + * Return the greek threshold in screen font size. When the screen font size + * will be below this threshold the text is rendered as 'greek' instead of + * drawing the text glyphs. Defaults to {@link DEFAULT_GREEK_THRESHOLD}. + * * @return the current greek threshold in screen font size */ public double getGreekThreshold() { @@ -256,9 +276,10 @@ } /** - * Set the greek threshold in screen font size to greekThreshold. When the - * screen font size will be below this threshold the text is rendered as 'greek' instead of drawing the - * text glyphs. + * Set the greek threshold in screen font size to + * greekThreshold. When the screen font size will be below this + * threshold the text is rendered as 'greek' instead of drawing the text + * glyphs. * * @param greekThreshold greek threshold in screen font size */ @@ -268,8 +289,8 @@ } /** - * Return the text for this text node. Defaults to {@link #DEFAULT_TEXT}. - * + * Return the text for this text node. Defaults to {@link #DEFAULT_TEXT}. + * * @return the text for this text node */ public String getText() { @@ -277,11 +298,14 @@ } /** - * Set the text for this node to text. The text will be broken up into multiple - * lines based on the size of the text and the bounds width of this node. - * - *

This is a bound property.

- * + * Set the text for this node to text. The text will be broken + * up into multiple lines based on the size of the text and the bounds width + * of this node. + * + *

+ * This is a bound property. + *

+ * * @param text text for this text node */ public void setText(final String text) { @@ -297,8 +321,8 @@ } /** - * Return the font for this text node. Defaults to {@link #DEFAULT_FONT}. - * + * Return the font for this text node. Defaults to {@link #DEFAULT_FONT}. + * * @return the font for this text node */ public Font getFont() { @@ -306,12 +330,15 @@ } /** - * Set the font for this text node to font. Note that in Piccolo if you want to change - * the size of a text object it's often a better idea to scale the PText node instead of changing the font - * size to get that same effect. Using very large font sizes can slow performance. - * - *

This is a bound property.

- * + * Set the font for this text node to font. Note that in + * Piccolo if you want to change the size of a text object it's often a + * better idea to scale the PText node instead of changing the font size to + * get that same effect. Using very large font sizes can slow performance. + * + *

+ * This is a bound property. + *

+ * * @param font font for this text node */ public void setFont(final Font font) { @@ -389,14 +416,14 @@ } /** - * Compute the next layout using the specified line break measurer, available width, - * and next line break offset. - * + * Compute the next layout using the specified line break measurer, + * available width, and next line break offset. + * * @param lineBreakMeasurer line break measurer * @param availableWidth available width * @param nextLineBreakOffset next line break offset - * @return the next layout computed using the specified line break measurer, available width, - * and next line break offset + * @return the next layout computed using the specified line break measurer, + * available width, and next line break offset */ protected TextLayout computeNextLayout(final LineBreakMeasurer lineBreakMeasurer, final float availableWidth, final int nextLineBreakOffset) { @@ -405,7 +432,7 @@ /** * Paint greek with the specified paint context. - * + * * @param paintContext paint context */ protected void paintGreek(final PPaintContext paintContext) { @@ -414,7 +441,7 @@ /** * Paint text with the specified paint context. - * + * * @param paintContext paint context */ protected void paintText(final PPaintContext paintContext) { diff --git a/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java index a33fe5c..c26f4c7 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java @@ -53,7 +53,6 @@ import edu.umd.cs.piccolo.activities.PTransformActivity; import edu.umd.cs.piccolo.activities.PColorActivity.Target; import edu.umd.cs.piccolo.event.PBasicInputEventHandler; -import edu.umd.cs.piccolo.event.PInputEvent; import edu.umd.cs.piccolo.util.PAffineTransform; import edu.umd.cs.piccolo.util.PAffineTransformException; import edu.umd.cs.piccolo.util.PBounds; @@ -1292,25 +1291,25 @@ node.setOccluded(true); assertTrue(node.getOccluded()); } - + public void testHiddenNodesAreNotPickable() { - PCanvas canvas = new PCanvas(); + final PCanvas canvas = new PCanvas(); canvas.setBounds(0, 0, 400, 400); - canvas.setPreferredSize(new Dimension(400, 400)); - PNode node1 = new PNode(); + canvas.setPreferredSize(new Dimension(400, 400)); + final PNode node1 = new PNode(); node1.setBounds(0, 0, 100, 100); node1.setPaint(Color.RED); - canvas.getLayer().addChild(node1); - - PNode node2 = (PNode) node1.clone(); + canvas.getLayer().addChild(node1); + + final PNode node2 = (PNode) node1.clone(); node2.setPaint(Color.BLUE); - - PLayer layer2 = new PLayer(); + + final PLayer layer2 = new PLayer(); layer2.addChild(node2); layer2.setVisible(false); canvas.getCamera().addLayer(layer2); - - PPickPath path = canvas.getCamera().pick(5, 5, 5); - assertSame(node1, path.getPickedNode()); + + final PPickPath path = canvas.getCamera().pick(5, 5, 5); + assertSame(node1, path.getPickedNode()); } } diff --git a/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java b/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java index fd58842..135e253 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java @@ -1,3 +1,30 @@ +/* + * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its + * contributors may be used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package edu.umd.cs.piccolo.event; import java.awt.event.InputEvent; @@ -16,6 +43,17 @@ filter = new PInputEventFilter(); } + // http://code.google.com/p/piccolo2d/issues/detail?id=116 + public void testPreventCodeCleanFinal() { + final int pre = PInputEventFilter.ALL_MODIFIERS_MASK; + try { + PInputEventFilter.ALL_MODIFIERS_MASK = 0; + } + finally { + PInputEventFilter.ALL_MODIFIERS_MASK = pre; + } + } + public void testAcceptsAlreadyHandledEventsFalseByDefault() { assertFalse(filter.getAcceptsAlreadyHandledEvents()); } diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java index e77a4bc..4d21333 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java @@ -116,37 +116,37 @@ try { textNode.setHorizontalAlignment(-2.0f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(2.0f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(-Float.MAX_VALUE); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(Float.MAX_VALUE); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(-1.00f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(1.00f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } } diff --git a/core/src/test/java/edu/umd/cs/piccolo/util/PUtilTest.java b/core/src/test/java/edu/umd/cs/piccolo/util/PUtilTest.java new file mode 100644 index 0000000..e5746e3 --- /dev/null +++ b/core/src/test/java/edu/umd/cs/piccolo/util/PUtilTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its + * contributors may be used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package edu.umd.cs.piccolo.util; + +import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Iterator; + +import junit.framework.TestCase; + +public class PUtilTest extends TestCase { + + // see http://code.google.com/p/piccolo2d/issues/detail?id=116 + public void testPreventCodeCleanFinal() { + final Enumeration ne = PUtil.NULL_ENUMERATION; + try { + PUtil.NULL_ENUMERATION = null; + } + finally { + PUtil.NULL_ENUMERATION = ne; + } + + final Iterator ni = PUtil.NULL_ITERATOR; + try { + PUtil.NULL_ITERATOR = null; + } + finally { + PUtil.NULL_ITERATOR = ni; + } + + final OutputStream no = PUtil.NULL_OUTPUT_STREAM; + try { + PUtil.NULL_OUTPUT_STREAM = null; + } + finally { + PUtil.NULL_OUTPUT_STREAM = no; + } + } + +}