Skip to content

Commit

Permalink
Application never stops on Windows
Browse files Browse the repository at this point in the history
fixes #126
  • Loading branch information
sarxos committed Jul 22, 2013
1 parent 48f1d66 commit 0acd38d
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -186,6 +187,23 @@ public Thread newThread(Runnable r) {

}

/**
* This runnable will do nothing more than repaint panel.
*/
private static final class SwingRepainter implements Runnable {

private WebcamPanel panel = null;

public SwingRepainter(WebcamPanel panel) {
this.panel = panel;
}

@Override
public void run() {
panel.repaint();
}
}

/**
* S/N used by Java to serialize beans.
*/
Expand All @@ -211,6 +229,11 @@ public Thread newThread(Runnable r) {
*/
private static final ThreadFactory THREAD_FACTORY = new PanelThreadFactory();

/**
* This runnable will do nothing more than repaint panel.
*/
private final Runnable repaint = new SwingRepainter(this);

/**
* Scheduled executor acting as timer.
*/
Expand Down Expand Up @@ -247,7 +270,7 @@ public void run() {
return;
}

repaint();
repaintPanel();

// loop when starting, to wait for images
while (starting) {
Expand Down Expand Up @@ -348,7 +371,7 @@ private void update() {

// and repaint it

repaint();
repaintPanel();
}
}

Expand Down Expand Up @@ -546,8 +569,8 @@ public void start() {
errored = true;
throw e;
} finally {
repaint();
starting = false;
repaintPanel();
}

}
Expand Down Expand Up @@ -581,10 +604,17 @@ public void stop() {
errored = true;
throw e;
} finally {
repaint();
repaintPanel();
}
}

/**
* Repaint panel in Swing asynchronous manner.
*/
private void repaintPanel() {
SwingUtilities.invokeLater(repaint);
}

/**
* Pause rendering.
*/
Expand Down

0 comments on commit 0acd38d

Please sign in to comment.