Revision: 1104
Author: heuermh
Date: Fri Feb 18 08:22:35 2011
Log: applying patch and unit test from Issue 206 to clear caches
http://code.google.com/p/piccolo2d/source/detail?r=1104
Added:
/piccolo2d.java/trunk/swt/src/test/java/org/piccolo2d/extras/swt/SWTGraphics2DTest.java
Modified:
/piccolo2d.java/trunk/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/swt/src/test/java/org/piccolo2d/extras/swt/SWTGraphics2DTest.java
Fri Feb 18 08:22:35 2011
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008-2011, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * 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 org.piccolo2d.extras.swt;
+
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for SWTGraphics2D.
+ */
+public class SWTGraphics2DTest extends TestCase {
+
+ private Shell shell;
+
+ /** {@inheritDoc} */
+ public void setUp() {
+ shell = new Shell(Display.getDefault());
+ shell.setLayout(new FillLayout());
+ }
+
+ public void testCacheCleanup() {
+ PSWTCanvas canvas = new PSWTCanvas(shell, 0);
+ PSWTText text = new PSWTText("test");
+ canvas.getLayer().addChild(text);
+ canvas.dispose();
+ canvas = new PSWTCanvas(shell, 0);
+
+ //If caches return disposed object this will fail
+ text = new PSWTText("test");
+ }
+}
=======================================
---
/piccolo2d.java/trunk/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java
Fri Aug 27 09:46:51 2010
+++
/piccolo2d.java/trunk/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java
Fri Feb 18 08:22:35 2011
@@ -1518,15 +1518,17 @@
final org.eclipse.swt.graphics.Font font =
(org.eclipse.swt.graphics.Font) i.next();
font.dispose();
}
+ FONT_CACHE.clear();
for (final Iterator i = COLOR_CACHE.values().iterator();
i.hasNext();) {
final org.eclipse.swt.graphics.Color color =
(org.eclipse.swt.graphics.Color) i.next();
color.dispose();
}
+ COLOR_CACHE.clear();
for (final Iterator i = SHAPE_CACHE.values().iterator();
i.hasNext();) {
final Path path = (Path) i.next();
path.dispose();
}
+ SHAPE_CACHE.clear();
}
}
-
-}
+}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en