001 package aima.gui.framework; 002 003 /** 004 * Simple controller implementation which extends its base class 005 * by maintaining references to frame and model, and by simple 006 * demo implementations of the required three abstract methods. 007 * @author R. Lunde 008 */ 009 public class AgentAppController implements AgentAppFrame.Controller { 010 protected AgentAppFrame frame; 011 protected AgentAppModel model; 012 /** 013 * Gives the controller access to the frame. This 014 * is useful to display status information. 015 */ 016 public void setFrame(AgentAppFrame frame) { this.frame = frame; } 017 public void setModel(AgentAppModel model) { this.model = model; } 018 019 /** 020 * The associated {@link AgentAppFrame} calls this method 021 * when the clear button is pressed. 022 */ 023 public void clearAgent() { 024 frame.logMessage("clearing..."); 025 frame.logMessage(frame.getSelection().toString()); 026 frame.setStatus("Agent cleared."); 027 } 028 029 /** 030 * The associated {@link AgentAppFrame} calls this method 031 * when the prepare button is pressed, the selection state of 032 * the selectors changes, and also when the run button is pressed 033 * without previously performed preparation. 034 */ 035 public void prepareAgent() { 036 frame.logMessage("preparing..."); 037 frame.logMessage(frame.getSelection().toString()); 038 frame.setStatus("Agent prepared."); 039 } 040 041 /** 042 * The associated {@link AgentAppFrame} calls this method 043 * when the run button is activated. This code runs in a second 044 * thread, which can be stopped by the GUI at any time. 045 */ 046 public void runAgent() { 047 frame.logMessage("running..."); 048 frame.logMessage(frame.getSelection().toString()); 049 frame.modelChanged(); 050 frame.modelChanged(); 051 frame.setStatus("Task completed."); 052 } 053 }