diff --git a/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java b/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java index 3d3cdb0..f477623 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java +++ b/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java @@ -688,12 +688,16 @@ /** * Prints the entire scene regardless of what the viewable area is. * - * @param g Graphics context onto which to paint the scene for printing + * @param graphics Graphics context onto which to paint the scene for printing */ - public void printAll(final Graphics g) { - final Graphics2D g2 = (Graphics2D) g; + public void printAll(final Graphics graphics) { + if (!(graphics instanceof Graphics2D)) { + throw new IllegalArgumentException("Provided graphics context is not a Graphics2D object"); + } + + final Graphics2D g2 = (Graphics2D) graphics; - final PBounds clippingRect = new PBounds(g.getClipBounds()); + final PBounds clippingRect = new PBounds(graphics.getClipBounds()); clippingRect.expandNearestIntegerDimensions(); final PBounds originalCameraBounds = getCamera().getBounds(); diff --git a/core/src/main/java/edu/umd/cs/piccolo/PNode.java b/core/src/main/java/edu/umd/cs/piccolo/PNode.java index 0563633..3a0ed55 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/PNode.java +++ b/core/src/main/java/edu/umd/cs/piccolo/PNode.java @@ -2940,7 +2940,7 @@ } else { scale = image.getHeight() / nodeHeight; - } + } g2.scale(scale, scale); break; case FILL_STRATEGY_EXACT_FIT: @@ -2997,6 +2997,11 @@ if (pageIndex != 0) { return NO_SUCH_PAGE; } + + if (!(graphics instanceof Graphics2D)) { + throw new IllegalArgumentException("Provided graphics context is not a Graphics2D object"); + } + final Graphics2D g2 = (Graphics2D) graphics; final PBounds imageBounds = getFullBounds(); diff --git a/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java b/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java index 5aa0c77..455593d 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java +++ b/core/src/main/java/edu/umd/cs/piccolo/activities/PActivityScheduler.java @@ -55,9 +55,9 @@ */ public class PActivityScheduler implements Serializable { private static final long serialVersionUID = 1L; + private transient Timer activityTimer = null; private final PRoot root; - private final List activities; - private transient Timer activityTimer; + private final List activities; private boolean activitiesChanged; private boolean animating; private final ArrayList processingActivities; 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 4e26bfc..c7faffc 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 @@ -468,8 +468,7 @@ * @param camera the camera to be transformed */ protected void fillViewWhiteSpace(final PCamera camera) { - final PBounds rootBounds = camera.getRoot().getFullBoundsReference(); - PBounds viewBounds = camera.getViewBounds(); + final PBounds rootBounds = camera.getRoot().getFullBoundsReference(); if (rootBounds.contains(camera.getViewBounds())) { return; @@ -481,7 +480,8 @@ // center content. double dx = 0; double dy = 0; - viewBounds = camera.getViewBounds(); + + PBounds viewBounds = camera.getViewBounds(); if (viewBounds.getWidth() > rootBounds.getWidth()) { // then center along x axis. 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 3f0c48a..b3033ca 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 @@ -66,7 +66,7 @@ public static final Object NULL_MARKER = new Object(); /** Singleton instance of the notification center. */ - protected static PNotificationCenter DEFAULT_CENTER; + protected volatile static PNotificationCenter DEFAULT_CENTER; /** A map of listeners keyed by NotificationKey objects. */ protected HashMap listenersMap; 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 eab37f1..3d4213e 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 @@ -360,15 +360,19 @@ * inconsistent. Also, Swing doesn't work correctly with fractional * metrics. */ - public void paint(final Graphics g) { - final Graphics2D g2 = (Graphics2D) g; + public void paint(final Graphics graphics) { + if (!(graphics instanceof Graphics2D)) { + throw new IllegalArgumentException("Provided graphics context is not a Graphics2D object"); + } + + final Graphics2D g2 = (Graphics2D) graphics; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); - super.paint(g); + super.paint(graphics); } } } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java index 95bd462..4011d18 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java @@ -226,7 +226,6 @@ - paragraphRange.startIndex), Math.min(paragraphRange.length(), curElement.getEndOffset() - paragraphRange.startIndex)); - // These are the optional attributes final Font font = extractFont(styleContext, pos, rootElement, attributes); applyFontAttribute(paragraphRange, attributedString, curElement, font); applyBackgroundAttribute(styleContext, paragraphRange, attributedString, curElement, attributes); @@ -249,15 +248,10 @@ - paragraphRange.startIndex)); final Font font = extractFont(styleContext, pos, rootElement, attributes); - applyFontAttribute(paragraphRange, attributedString, curElement, font); - - // These are the optional attributes - + applyFontAttribute(paragraphRange, attributedString, curElement, font); applyBackgroundAttribute(styleContext, paragraphRange, attributedString, curElement, attributes); - applyUnderlineAttribute(paragraphRange, attributedString, curElement, attributes); - - applyStrikeThroughAttribute(paragraphRange, attributedString, curElement, attributes); + applyStrikeThroughAttribute(paragraphRange, attributedString, curElement, attributes); // And set the position to the end of the given attribute pos = curElement.getEndOffset(); @@ -333,23 +327,14 @@ private Font extractFont(final StyleContext style, final int pos, final Element rootElement, final AttributeSet attributes) { - Font font; + Font font = null; if (attributes.isDefined(StyleConstants.FontSize) || attributes.isDefined(StyleConstants.FontFamily)) { font = style.getFont(attributes); } - else { - font = null; - } if (font == null) { if (document instanceof DefaultStyledDocument) { - font = style.getFont(((DefaultStyledDocument) document).getCharacterElement(pos).getAttributes()); - if (font == null) { - font = style.getFont(((DefaultStyledDocument) document).getParagraphElement(pos).getAttributes()); - if (font == null) { - font = style.getFont(rootElement.getAttributes()); - } - } + font = extractFontFromDefaultStyledDocument((DefaultStyledDocument) document, style, pos, rootElement); } else { font = style.getFont(rootElement.getAttributes()); @@ -358,6 +343,18 @@ return font; } + private Font extractFontFromDefaultStyledDocument(final DefaultStyledDocument styledDocument, + final StyleContext style, final int pos, final Element rootElement) { + Font font = style.getFont(styledDocument.getCharacterElement(pos).getAttributes()); + if (font == null) { + font = style.getFont(styledDocument.getParagraphElement(pos).getAttributes()); + if (font == null) { + font = style.getFont(rootElement.getAttributes()); + } + } + return font; + } + private ArrayList extractParagraphRanges(final String documentString) { // The paragraph start and end indices final ArrayList paragraphRanges = new ArrayList(); @@ -502,7 +499,7 @@ textWidth = Math.max(textWidth, lineWidth); } - lines = (LineInfo[]) linesList.toArray(new LineInfo[0]); + lines = (LineInfo[]) linesList.toArray(new LineInfo[linesList.size()]); constrainDimensionsIfNeeded(textWidth, textHeight); } 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 4019c64..1eb1f8a 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 @@ -242,7 +242,7 @@ * @param pce property change event to examine */ public void propertyChange(final PropertyChangeEvent pce) { - final boolean isRelevantViewEvent = PCamera.PROPERTY_VIEW_TRANSFORM == pce.getPropertyName(); + final boolean isRelevantViewEvent = PCamera.PROPERTY_VIEW_TRANSFORM.equals(pce.getPropertyName()); final boolean isRelevantBoundsEvent = isBoundsChangedEvent(pce) && (pce.getSource() == camera || pce.getSource() == view.getRoot()); @@ -257,7 +257,7 @@ } private boolean isBoundsChangedEvent(final PropertyChangeEvent pce) { - return PNode.PROPERTY_BOUNDS == pce.getPropertyName() || PNode.PROPERTY_FULL_BOUNDS == pce.getPropertyName(); + return PNode.PROPERTY_BOUNDS.equals(pce.getPropertyName()) || PNode.PROPERTY_FULL_BOUNDS.equals(pce.getPropertyName()); } /** 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 a5f715b..7f22153 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 @@ -99,7 +99,7 @@ */ synchronized void stop() { running = false; - notify(); + notifyAll(); } /** @@ -117,7 +117,7 @@ timer.setExpirationTime(expirationTime); timer.setRunning(true); - notify(); + notifyAll(); } }