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

org.jclarion.clarion.swing.gui.LocalClient Maven / Gradle / Ivy

The newest version!
package org.jclarion.clarion.swing.gui;

import javax.swing.SwingUtilities;

import org.jclarion.clarion.swing.AWTBlocker;

public class LocalClient extends GUIModel
{
	@Override
	public void send(final RemoteWidget w, final int command, final Object... params) {
        if (SwingUtilities.isEventDispatchThread() || !w.isGuiCommand(command)) {
        	w.command(command,params);
        } else {
            SwingUtilities.invokeLater(new Runnable() {
            	public void run() {
                	w.command(command,params);            		
            	}
            });
        }
	}

	@Override
	public void send(final RemoteWidget w,final ResponseRunnable nextTask,
			final int command,final Object... params) {
        if (SwingUtilities.isEventDispatchThread() || !w.isGuiCommand(command)) {
        	Object result=w.command(command,params);
        	if (nextTask!=null) nextTask.run(result);
        } else {

        	/*
            SwingUtilities.invokeLater(new Runnable() {
            	public void run() {
                	Object result = w.command(command,params);            		
                	if (nextTask!=null) nextTask.run(result);
            	}
            });
            */
            
           	AWTBlocker.getInstance().runAsSoonAsPossibleOnSwing(
           			new Runnable() {
           				public void run() {
           					Object o = w.command(command,params);
           					if (nextTask!=null) nextTask.run(o);
           				}
           			},w.isModalCommand(command),false);
         }		
	}

	@Override
	public Object sendRecv(final RemoteWidget w,final int command,final Object... params) {
        if (SwingUtilities.isEventDispatchThread() || !w.isGuiCommand(command)) {
        	return w.command(command,params);
        } else {
        	final Object[] result=new Object[1];
           	AWTBlocker.getInstance().runAsSoonAsPossibleOnSwing(
           			new Runnable() {
           				public void run() {
           					result[0]=w.command(command,params);            		
           				}
           			},w.isModalCommand(command),true);
            return result[0];
        }
	}

	@Override
	public void send(RemoteSemaphore rs, Object result) 
	{
		throw new IllegalStateException("Should never be called");
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy