Package jade.gui
Class GuiAgent
- java.lang.Object
-
- jade.core.Agent
-
- jade.gui.GuiAgent
-
- All Implemented Interfaces:
TimerListener,Serializable,Serializable,Runnable
- Direct Known Subclasses:
df
public abstract class GuiAgent extends Agent
When a program instantiates a GUI, the Java programming language starts a new thread, different from the Agent thread. The Agent thread generally is active because it has its tasks to perform and also the GUI thread is active, in respect to the Agent thread, because its behaviour depends on the user actions (e.g. pressing a button, using the nemu bar,...) and not only on the agent task. Therefore, an appropriate mechanism is needed to manage the interaction between these two active threads. It is not a good practice allowing one thread to just call the method of another thread because of the difference in the thread space. What should be done, instead is one thread requesting the other to execute a method, each thread in its one execution space. Since its common to have an agent with a GUI, this class is for this purpose. This class extends thejade.core.Agentclass: at the start-up it instantiate ad ad-hoc behaviour that manages a queue ofjade.gui.GuiEvent,event objects that can be received by other threads. A thread (in particular a GUI)to notify an event to an Agent should create a new Object of typejade.gui.GuiEventand pass it as a parameter to the call of the methodpostGuiEventof thejade.gui.GuiAgentobject. Notice that an object of typeGuiEventhas two mandatory attributes and an optional list of parameters that can be added to the event object. After the methodpostGuiEventis called,the agent reacts by waking up all its active behaviours, and in particular the one that causes the Agent thread to execute the methodonGuiEvent.- Version:
- $Date$ $Revision$
- Author:
- Giovanni Caire - CSELT S.p.A.
- See Also:
Agent,GuiEvent, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jade.core.Agent
Agent.Interrupted
-
-
Field Summary
-
Fields inherited from class jade.core.Agent
AP_ACTIVE, AP_DELETED, AP_IDLE, AP_INITIATED, AP_MAX, AP_MIN, AP_SUSPENDED, AP_WAITING, D_ACTIVE, D_MAX, D_MIN, D_RETIRED, D_SUSPENDED, D_UNKNOWN, MSG_QUEUE_CLASS
-
-
Constructor Summary
Constructors Constructor Description GuiAgent()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidonGuiEvent(GuiEvent ev)Abstract method to handle posted GUI events.voidpostGuiEvent(GuiEvent e)Posts an event from the GUI thread to the agent event queue.-
Methods inherited from class jade.core.Agent
addBehaviour, afterClone, afterMove, beforeClone, beforeMove, blockingReceive, blockingReceive, blockingReceive, blockingReceive, changeStateTo, clean, createMessageQueue, doActivate, doClone, doDelete, doMove, doSuspend, doTimeOut, doWait, doWait, doWake, getAgentState, getAID, getAID, getAMS, getArguments, getBehavioursCnt, getBootProperties, getContainerController, getContentManager, getCurQueueSize, getDefaultDF, getExecutedBehavioursCnt, getGenerateBehaviourEvents, getGenerateMessageEvents, getHap, getHelper, getLocalName, getName, getO2AInterface, getO2AObject, getPostedMessagesCnt, getProperty, getQueueSize, getReceivedMessagesCnt, getSentMessagesCnt, getState, here, isAlive, isRestarting, join, notifyChangeBehaviourState, notifyRestarted, postMessage, putBack, putO2AObject, receive, receive, receive, registerO2AInterface, removeBehaviour, removeTimer, restartLater, restoreBufferedState, restoreFields, run, send, setArguments, setEnabledO2ACommunication, setGenerateBehaviourEvents, setGenerateMessageEvents, setO2AManager, setQueueSize, setup, takeDown, waitUntilStarted, write
-
-
-
-
Method Detail
-
postGuiEvent
public void postGuiEvent(GuiEvent e)
Posts an event from the GUI thread to the agent event queue.- Parameters:
e- The GUI event to post.
-
onGuiEvent
protected abstract void onGuiEvent(GuiEvent ev)
Abstract method to handle posted GUI events. Subclasses ofGuiAgentwill implement their own reactions to GUI events starting with this method.- Parameters:
ev- The GUI event to handle.
-
-