X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2FAbstractTextGUIThread.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2FAbstractTextGUIThread.java;h=0000000000000000000000000000000000000000;hp=f4a00163ded8a3524f703a77320219e715bf37cf;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hpb=a73a906356c971b080c36368e71a15d87e8b8d31 diff --git a/src/com/googlecode/lanterna/gui2/AbstractTextGUIThread.java b/src/com/googlecode/lanterna/gui2/AbstractTextGUIThread.java deleted file mode 100644 index f4a0016..0000000 --- a/src/com/googlecode/lanterna/gui2/AbstractTextGUIThread.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.googlecode.lanterna.gui2; - -import java.io.IOException; -import java.util.Queue; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * Created by martin on 20/06/15. - */ -public abstract class AbstractTextGUIThread implements TextGUIThread { - - protected final TextGUI textGUI; - protected final Queue customTasks; - protected ExceptionHandler exceptionHandler; - - public AbstractTextGUIThread(TextGUI textGUI) { - this.exceptionHandler = new ExceptionHandler() { - @Override - public boolean onIOException(IOException e) { - e.printStackTrace(); - return true; - } - - @Override - public boolean onRuntimeException(RuntimeException e) { - e.printStackTrace(); - return true; - } - }; - this.textGUI = textGUI; - this.customTasks = new LinkedBlockingQueue(); - } - - @Override - public void invokeLater(Runnable runnable) throws IllegalStateException { - customTasks.add(runnable); - } - - @Override - public void setExceptionHandler(ExceptionHandler exceptionHandler) { - if(exceptionHandler == null) { - throw new IllegalArgumentException("Cannot call setExceptionHandler(null)"); - } - this.exceptionHandler = exceptionHandler; - } - - @Override - public synchronized boolean processEventsAndUpdate() throws IOException { - if(getThread() != Thread.currentThread()) { - throw new IllegalStateException("Calling processEventAndUpdate outside of GUI thread"); - } - textGUI.processInput(); - while(!customTasks.isEmpty()) { - Runnable r = customTasks.poll(); - if(r != null) { - r.run(); - } - } - if(textGUI.isPendingUpdate()) { - textGUI.updateScreen(); - return true; - } - return false; - } - - @Override - public void invokeAndWait(final Runnable runnable) throws IllegalStateException, InterruptedException { - if(Thread.currentThread() == getThread()) { - runnable.run(); - } - else { - final CountDownLatch countDownLatch = new CountDownLatch(1); - invokeLater(new Runnable() { - @Override - public void run() { - try { - runnable.run(); - } - finally { - countDownLatch.countDown(); - } - } - }); - countDownLatch.await(); - } - } -}