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

jadex.bdi.planlib.GuiCreator Maven / Gradle / Ivy

Go to download

The Jadex applib BDI package contain ready to use functionalities for BDI agents mostly in form of modules called capabilities.

There is a newer version: 2.4
Show newest version
package jadex.bdi.planlib;

import jadex.commons.SUtil;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

/**
 *  The gui creator.
 *  Note! The Gui cannot be itself a JFrame because this
 *  might lead to deadlocks. new JFrame() should only be called
 *  from Swing thread. As "new JFrame()" is content of a belief
 *  it is executed in the agent's thread. 
 */
public class GuiCreator
{
	//-------- attributes --------

	/** The gui. */
	protected JFrame frame;

	//-------- constructors --------

	/**
	 *  Create a new clock.
	 */
	public GuiCreator(final Class frameclass, final Class[] argclasses, final Object[] args)
	{
		SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					Constructor con = frameclass.getConstructor(argclasses);
					frame = (JFrame)con.newInstance(args);
				}
				catch(InvocationTargetException e)
				{
					throw e.getTargetException() instanceof RuntimeException
						? (RuntimeException)e.getTargetException() : new RuntimeException(e.getTargetException());
				}
				catch(RuntimeException e)
				{
					throw e;
				}
				catch(Exception e)
				{
					throw new RuntimeException(e);
				}
			}
		});
	}
	
	/**
	 *  Create a new clock.
	 */
	public GuiCreator(final Method createmethod, final Class[] argclasses, final Object[] args)
	{
		SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					frame = (JFrame)createmethod.invoke(null, args);
				}
				catch(Exception e)
				{
					throw new RuntimeException(e);
				}
			}
		});
	}

	//-------- methods --------

	/**
	 *  Get the frame.
	 *  @return The frame. 
	 */
	public JFrame getFrame()
	{
		return frame;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy