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 e60ba9e..b43ad75 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 @@ -55,8 +55,8 @@ private Color topLeftInnerColor; private Color bottomRightInnerColor; private Color bottomRightOuterColor; - private final GeneralPath path; - private final transient Stroke stroke; + private transient GeneralPath path = null; + private transient Stroke stroke = null; private boolean raised; /** @@ -64,8 +64,6 @@ */ public P3DRect() { raised = true; - stroke = new BasicStroke(0); - path = new GeneralPath(); } /** @@ -118,6 +116,14 @@ * @param paintContext context in which the paiting should occur */ protected void paint(final PPaintContext paintContext) { + // lazy init: + if (stroke == null) { + stroke = new BasicStroke(0); + } + if (path == null) { + path = new GeneralPath(); + } + final Graphics2D g2 = paintContext.getGraphics(); final double x = getX(); @@ -208,6 +214,8 @@ } /** + * TODO can we remove this? + * * @deprecated since it has been moved to P3DRectExample. * * @param args Command line arguments diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java index d448d5e..344e54a 100644 --- a/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java @@ -39,7 +39,6 @@ public void testClone() { P3DRect rect = new P3DRect(10, 10, 10, 10); rect.setPaint(Color.BLUE); - // FIXME breaks on jdk < 1.6 as GeneralPath field isn't transient nor serializable P3DRect cloned = (P3DRect) rect.clone(); assertNotNull(cloned); assertEquals(Color.BLUE, cloned.getPaint());