Fixed exception on clearing a window (issue 988)

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1028 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
theraysmith@gmail.com 2014-01-29 19:17:04 +00:00
parent 99e1f05952
commit 8eb1218adf

View File

@ -35,6 +35,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.geom.IllegalPathStateException;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.util.concurrent.Semaphore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -66,6 +67,9 @@ public class SVWindow extends JFrame {
/** The top level layer we add our PNodes to (root node). */
PLayer layer;
/** Semaphore that controls access to clearing the layer. */
Semaphore layerSemaphore = new Semaphore(1);
/** The current color of the pen. It is used to draw edges, text, etc. */
Color currentPenColor;
@ -132,7 +136,20 @@ public class SVWindow extends JFrame {
/** Erase all content from the window, but do not destroy it. */
public void clear() {
layer.removeAllChildren();
layerSemaphore.acquireUninterruptibly();
// Manipulation of Piccolo's scene graph should be done from Swings
// event dispatch thread since Piccolo is not thread safe. This code calls
// removeAllChildren() from that thread and releases the semaphore.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
layer.removeAllChildren();
repaint();
layerSemaphore.release();
}
});
// Wait for the clear to complete before continuing.
layerSemaphore.acquireUninterruptibly();
layerSemaphore.release();
}
/**