diff --git a/src/main/java/schule/ngb/zm/Options.java b/src/main/java/schule/ngb/zm/Options.java index 3560fc6..7f574ec 100644 --- a/src/main/java/schule/ngb/zm/Options.java +++ b/src/main/java/schule/ngb/zm/Options.java @@ -42,7 +42,8 @@ public final class Options { STOPPED, TERMINATED, IDLE, - DELAYED + DELAYED, + DISPATCHING } /** diff --git a/src/main/java/schule/ngb/zm/Zeichenmaschine.java b/src/main/java/schule/ngb/zm/Zeichenmaschine.java index c23995b..664464d 100644 --- a/src/main/java/schule/ngb/zm/Zeichenmaschine.java +++ b/src/main/java/schule/ngb/zm/Zeichenmaschine.java @@ -410,17 +410,20 @@ public class Zeichenmaschine extends Constants { public void windowClosing( WindowEvent e ) { if( running ) { running = false; - teardown(); - cleanup(); + mainThread.interrupt(); + //teardown(); + //cleanup(); } // Give the app a minimum amount of time to shut down // then kill it. - try { - Thread.sleep(5); - } catch( InterruptedException ex ) { - } finally { - quit(true); + while( state != Options.AppState.TERMINATED ) { + Thread.yield(); + if( Thread.interrupted() ) { + break; + } } + // Quit + quit(true); } }); @@ -996,7 +999,7 @@ public class Zeichenmaschine extends Constants { updateState = Options.AppState.DELAYED; Thread.sleep(ms - sub, (int) (timer % 1000000L)); - } catch( InterruptedException ex ) { + } catch( InterruptedException ignored ) { // Nothing } finally { updateState = oldState; @@ -1198,10 +1201,12 @@ public class Zeichenmaschine extends Constants { } /* - * Mouse handling + * Input handling */ private void enqueueEvent( InputEvent evt ) { - eventQueue.add(evt); + if( updateState != Options.AppState.DELAYED ) { + eventQueue.add(evt); + } if( isPaused() || isStopped() ) { dispatchEvents(); @@ -1209,7 +1214,7 @@ public class Zeichenmaschine extends Constants { } private void dispatchEvents() { - synchronized( eventQueue ) { + //synchronized( eventQueue ) { while( !eventQueue.isEmpty() ) { InputEvent evt = eventQueue.poll(); @@ -1230,7 +1235,7 @@ public class Zeichenmaschine extends Constants { break; } } - } + //} } private void handleKeyEvent( KeyEvent evt ) { @@ -1469,10 +1474,11 @@ public class Zeichenmaschine extends Constants { // Call to draw() updateState = Options.AppState.DRAWING; Zeichenmaschine.this.draw(); - updateState = Options.AppState.IDLE; + updateState = Options.AppState.DISPATCHING; // Send latest input events after finishing draw // since these may also block dispatchEvents(); + updateState = Options.AppState.IDLE; } }); } @@ -1481,6 +1487,11 @@ public class Zeichenmaschine extends Constants { while( updateThreadExecutor.isRunning() && !updateThreadExecutor.isWaiting() ) { Thread.yield(); + + if( Thread.interrupted() ) { + running = false; + break; + } } // Display the current buffer content