Class Spin
- java.lang.Object
-
- spin.Spin
-
public class Spin extends java.lang.ObjectSpin offers a transparent threading solution for developing non-freezing Swing applications.
Let
beanbe a reference to a non-visual (possibly multithreaded) bean implementing the interfaceBeanwhose methods have to be called by a Swing component. You can avoid any freezing by using one line of code:bean = (Bean) Spin.off(bean);
Now each method call onbeanis executed on a separate thread, while the EDT is continuing to dispatch events. All return values or exceptions are handled by Spin and transparently returned to the calling method.For calls from other threads than the EDT to your Swing component you can use the following (being
XYListener any interface your component implements): bean.addXYListener((XYListener)Spin.over(component);Now all required updates to your component (and/or its model) are transparently excuted on the EDT.- See Also:
off(Object),over(Object),ProxyFactory,SpinOffEvaluator,SpinOverEvaluator
-
-
Constructor Summary
Constructors Constructor Description Spin(java.lang.Object object, Evaluator evaluator)Create a Spin wrapper for the given object.Spin(java.lang.Object object, ProxyFactory proxyFactory, Evaluator evaluator)Create a Spin wrapper for the given object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EvaluatorgetDefaultOffEvaluator()Get the default evaluator for spin-off.static EvaluatorgetDefaultOverEvaluator()Get the default evaluator for spin-over.static ProxyFactorygetDefaultProxyFactory()Get the default proxy factory.java.lang.ObjectgetProxy()Get a proxy for the wrapped object.static java.lang.Objectoff(java.lang.Object object)Convenience method to spin-off the given object from Swing.static java.lang.Objectover(java.lang.Object object)Convenience method to spin-over the given object with Swing.static voidsetDefaultOffEvaluator(Evaluator evaluator)Set the default evaluator for spin-off.static voidsetDefaultOverEvaluator(Evaluator evaluator)Set the default evaluator for spin-over.static voidsetDefaultProxyFactory(ProxyFactory factory)Set the default factory of proxies.
-
-
-
Constructor Detail
-
Spin
public Spin(java.lang.Object object, Evaluator evaluator)Create a Spin wrapper for the given object.- Parameters:
object- object to wrapevaluator- evaluator of invocations on the given object
-
Spin
public Spin(java.lang.Object object, ProxyFactory proxyFactory, Evaluator evaluator)Create a Spin wrapper for the given object.- Parameters:
object- object to wrapproxyFactory- factory for a proxyevaluator- evaluator of invocations on the given object
-
-
Method Detail
-
getProxy
public java.lang.Object getProxy()
Get a proxy for the wrapped object.
The returned object can safely be casted to any interface the wrapped object implements.- Returns:
- the new proxy
-
off
public static java.lang.Object off(java.lang.Object object)
Convenience method to spin-off the given object from Swing.
The returned object can safely be casted to any interface the given object implements.
- Parameters:
object- the object to spin-off- Returns:
- proxy for the given object
- See Also:
setDefaultProxyFactory(ProxyFactory),setDefaultOffEvaluator(Evaluator)
-
over
public static java.lang.Object over(java.lang.Object object)
Convenience method to spin-over the given object with Swing.
The returned object can safely be casted to any interface the given object implements.- Parameters:
object- the object to spin-over- Returns:
- proxy for the given object
- See Also:
setDefaultProxyFactory(ProxyFactory),setDefaultOverEvaluator(Evaluator)
-
setDefaultProxyFactory
public static void setDefaultProxyFactory(ProxyFactory factory)
Set the default factory of proxies.- Parameters:
factory- proxy factore to use as default
-
setDefaultOffEvaluator
public static void setDefaultOffEvaluator(Evaluator evaluator)
Set the default evaluator for spin-off.- Parameters:
evaluator- evaluator to use for spin-off
-
setDefaultOverEvaluator
public static void setDefaultOverEvaluator(Evaluator evaluator)
Set the default evaluator for spin-over.- Parameters:
evaluator- evaluator for spin-over
-
getDefaultProxyFactory
public static ProxyFactory getDefaultProxyFactory()
Get the default proxy factory.- Returns:
- the default factory of proxies
-
getDefaultOffEvaluator
public static Evaluator getDefaultOffEvaluator()
Get the default evaluator for spin-off.- Returns:
- evaluator for spin-off
-
getDefaultOverEvaluator
public static Evaluator getDefaultOverEvaluator()
Get the default evaluator for spin-over.- Returns:
- evaluator for spin-over
-
-