All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jsoar.debugger.SwingCompletionHandler Maven / Gradle / Ivy

/*
 * Copyright (c) 2009  Dave Ray 
 *
 * Created on Mar 21, 2009
 */
package org.jsoar.debugger;

import javax.swing.SwingUtilities;

import org.jsoar.runtime.CompletionHandler;

/**
 * Wrap a completion handler in logic to ensure that it executes on the 
 * Swing event thread. Do not interact with the Soar agent in this unless
 * rewrapping in a {@code ThreadedAgent.execute}
 * 
 * @author ray
 */
public class SwingCompletionHandler implements CompletionHandler
{
    private final CompletionHandler inner;
    
    public static  CompletionHandler newInstance(CompletionHandler inner) 
    {
        return new SwingCompletionHandler(inner);
    }
    
    private SwingCompletionHandler(CompletionHandler inner)
    {
        this.inner = inner;
    }
    
    /* (non-Javadoc)
     * @see org.jsoar.runtime.Result#finish(java.lang.Object)
     */
    @Override
    public void finish(final T result)
    {
        if(SwingUtilities.isEventDispatchThread())
        {
            inner.finish(result);
        }
        else
        {
            SwingUtilities.invokeLater(() -> inner.finish(result));
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy