From 3015617d03c23dc0fd9900b97c25700b6df8b5c0 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 12 Jul 2004 12:29:58 +0000 Subject: [PATCH] A ResultListener proxy that invokes callbacks onto the AWT thread. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1462 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/swing/AWTResultListener.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/swing/AWTResultListener.java diff --git a/projects/samskivert/src/java/com/samskivert/swing/AWTResultListener.java b/projects/samskivert/src/java/com/samskivert/swing/AWTResultListener.java new file mode 100644 index 00000000..e5d1a3b3 --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/swing/AWTResultListener.java @@ -0,0 +1,47 @@ +// +// $Id$ + +package com.samskivert.swing; + +import java.awt.EventQueue; + +import com.samskivert.util.ResultListener; + +/** + * Dispatches a {@link ResultListener}'s callbacks on the AWT thread + * regardless of what thread on which they were originally dispatched. + */ +public class AWTResultListener implements ResultListener +{ + /** + * Creates an AWT result listener that will dispatch results to the + * supplied target. + */ + public AWTResultListener (ResultListener target) + { + _target = target; + } + + // documentation inherited from interface + public void requestCompleted (final Object result) + { + EventQueue.invokeLater(new Runnable() { + public void run () { + _target.requestCompleted(result); + } + }); + } + + // documentation inherited from interface + public void requestFailed (final Exception cause) + { + EventQueue.invokeLater(new Runnable() { + public void run () { + _target.requestFailed(cause); + } + }); + } + + /** The result listener for which we are proxying. */ + protected ResultListener _target; +}