
jadex.bdi.examples.cleanerworld_classic.environment.EnvironmentGui Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The newest version!
package jadex.bdi.examples.cleanerworld_classic.environment;
import jadex.bdi.examples.cleanerworld_classic.Chargingstation;
import jadex.bdi.examples.cleanerworld_classic.Cleaner;
import jadex.bdi.examples.cleanerworld_classic.Environment;
import jadex.bdi.examples.cleanerworld_classic.Location;
import jadex.bdi.examples.cleanerworld_classic.Waste;
import jadex.bdi.examples.cleanerworld_classic.Wastebin;
import jadex.bdi.runtime.IBDIExternalAccess;
import jadex.bdi.runtime.IBDIInternalAccess;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.types.monitoring.IMonitoringEvent;
import jadex.bridge.service.types.monitoring.IMonitoringService.PublishEventLevel;
import jadex.commons.beans.PropertyChangeEvent;
import jadex.commons.beans.PropertyChangeListener;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.future.IntermediateDefaultResultListener;
import jadex.commons.gui.SGUI;
import jadex.commons.gui.future.SwingIntermediateResultListener;
import jadex.commons.transformation.annotations.Classname;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIDefaults;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* The gui for the cleaner world example.
* Shows the world from the viewpoint of the environment agent.
*/
public class EnvironmentGui extends JFrame
{
//-------- constants --------
/** The image icons. */
private static UIDefaults icons = new UIDefaults(new Object[]
{
"waste", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/waste.png"),
"wastebin", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/wastebin.png"),
"wastebin_full", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/wastebin_full.png"),
"chargingstation", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/chargingstation.png"),
"cleaner", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/cleaner.png"),
"background", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/background.png"),
"background_night", SGUI.makeIcon(EnvironmentGui.class, "/jadex/bdi/examples/cleanerworld_classic/images/background_night.png")
});
//-------- attributes --------
/** The repaint timer. */
protected Timer timer;
//-------- constructors --------
/**
* Create a new gui plan.
*/
public EnvironmentGui(final IBDIExternalAccess agent)
{
super(agent.getComponentIdentifier().getLocalName());
agent.scheduleStep(new IComponentStep()
{
@Classname("disp")
public IFuture execute(IInternalAccess ia)
{
IBDIInternalAccess bia = (IBDIInternalAccess)ia;
// bia.addComponentListener(new TerminationAdapter()
// {
// public void componentTerminated()
// {
// SwingUtilities.invokeLater(new Runnable()
// {
// public void run()
// {
// if(timer!=null)
// timer.stop();
// EnvironmentGui.this.dispose();
// }
// });
// }
// });
bia.subscribeToEvents(IMonitoringEvent.TERMINATION_FILTER, false, PublishEventLevel.COARSE)
.addResultListener(new SwingIntermediateResultListener(new IntermediateDefaultResultListener()
{
public void intermediateResultAvailable(IMonitoringEvent result)
{
if(timer!=null)
timer.stop();
EnvironmentGui.this.dispose();
}
}));
final Environment env = (Environment)bia.getBeliefbase().getBelief("environment").getFact();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
//System.out.println("Now accessing env, GUIPlan: "+env.hashCode());
// Option panel.
JPanel options = new JPanel(new GridBagLayout());
options.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), "Environment Control"));
final JCheckBox daytime = new JCheckBox("", env.getDaytime());
daytime.setHorizontalTextPosition(SwingConstants.LEFT);
final JLabel wastecnt = new JLabel("0");
final JComboBox wastebinchoice = new JComboBox();
Wastebin[] wastebins = env.getWastebins();
for(int i=0; i0 && h>0)
{
for(int y=0; y"
+ cleaners[i].getName()+"
"
+ "battery: " + (int)(cleaners[i].getChargestate()*100.0) + "%
"
+ "waste: " + (cleaners[i].getCarriedWaste()!=null ? "yes" : "no")+"