|
1 | | -package aima.gui.swing.framework; |
2 | | - |
3 | | -import javax.swing.JComponent; |
4 | | - |
5 | | -import aima.core.agent.Environment; |
6 | | -import aima.core.agent.EnvironmentView; |
7 | | - |
8 | | -/** |
9 | | - * Base class for all graphical environment view implementations. |
10 | | - * An environment view visualizes agents in their environment. |
11 | | - * Typically, 2D graphics will be used for visualization. Environment |
12 | | - * changes are communicated to the viewer by means of an observer pattern. |
13 | | - * |
14 | | - * @author Ruediger Lunde |
15 | | - */ |
16 | | -public abstract class AgentAppEnvironmentView |
17 | | -extends JComponent implements EnvironmentView { |
18 | | - |
19 | | - private static final long serialVersionUID = 1L; |
20 | | - /** The environment providing the data to be visualized. */ |
21 | | - protected Environment env; |
22 | | - /** |
23 | | - * If the view provides interactive means to modify the environment, |
24 | | - * this controller should be responsible to initiate the changes. |
25 | | - */ |
26 | | - private AgentAppController controller; |
27 | | - /** Message display is delegated to a separate logger. */ |
28 | | - private MessageLogger logger; |
29 | | - |
30 | | - /** Sets the data source for the viewer. */ |
31 | | - public void setEnvironment(Environment env) { |
32 | | - if (this.env != null) |
33 | | - this.env.removeEnvironmentView(this); |
34 | | - this.env = env; |
35 | | - env.addEnvironmentView(this); |
36 | | - repaint(); |
37 | | - } |
38 | | - |
39 | | - /** Is called by the agent application frame. */ |
40 | | - protected void setController(AgentAppController controller) { |
41 | | - this.controller = controller; |
42 | | - } |
43 | | - |
44 | | - /** |
45 | | - * Provides a controller which is responsible for all |
46 | | - * environment modifications initiated by user interactions. |
47 | | - */ |
48 | | - protected AgentAppController getController() { |
49 | | - return controller; |
50 | | - } |
51 | | - |
52 | | - /** Selects a logger for message display. */ |
53 | | - public void setMessageLogger(MessageLogger logger) { |
54 | | - this.logger = logger; |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * Provides a logger which is responsible for message display. |
59 | | - */ |
60 | | - protected MessageLogger getLogger() { |
61 | | - return logger; |
62 | | - } |
63 | | - |
64 | | - /** Forwards a given message to the selected message logger. */ |
65 | | - public void notify(String msg) { |
66 | | - if (logger != null) |
67 | | - logger.log(msg); |
68 | | - } |
69 | | -} |
| 1 | +package aima.gui.swing.framework; |
| 2 | + |
| 3 | +import javax.swing.JComponent; |
| 4 | + |
| 5 | +import aima.core.agent.Environment; |
| 6 | +import aima.core.agent.EnvironmentView; |
| 7 | + |
| 8 | +/** |
| 9 | + * Base class for all graphical environment view implementations. |
| 10 | + * An environment view visualizes agents in their environment. |
| 11 | + * Typically, 2D graphics will be used for visualization. Environment |
| 12 | + * changes are communicated to the viewer by means of an observer pattern. |
| 13 | + * |
| 14 | + * @author Ruediger Lunde |
| 15 | + */ |
| 16 | +public abstract class AgentAppEnvironmentView |
| 17 | +extends JComponent implements EnvironmentView { |
| 18 | + |
| 19 | + private static final long serialVersionUID = 1L; |
| 20 | + /** The environment providing the data to be visualized. */ |
| 21 | + protected Environment env; |
| 22 | + /** |
| 23 | + * If the view provides interactive means to modify the environment, |
| 24 | + * this controller should be responsible to initiate the changes. |
| 25 | + */ |
| 26 | + private AgentAppController controller; |
| 27 | + /** Message display is delegated to a separate logger. */ |
| 28 | + private MessageLogger logger; |
| 29 | + |
| 30 | + /** Sets the data source for the viewer. */ |
| 31 | + public void setEnvironment(Environment env) { |
| 32 | + if (this.env != null) |
| 33 | + this.env.removeEnvironmentView(this); |
| 34 | + this.env = env; |
| 35 | + env.addEnvironmentView(this); |
| 36 | + repaint(); |
| 37 | + } |
| 38 | + |
| 39 | + /** Is called by the agent application frame. */ |
| 40 | + protected void setController(AgentAppController controller) { |
| 41 | + this.controller = controller; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Provides a controller which is responsible for all |
| 46 | + * environment modifications initiated by user interactions. |
| 47 | + */ |
| 48 | + protected AgentAppController getController() { |
| 49 | + return controller; |
| 50 | + } |
| 51 | + |
| 52 | + /** Selects a logger for message display. */ |
| 53 | + public void setMessageLogger(MessageLogger logger) { |
| 54 | + this.logger = logger; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Provides a logger which is responsible for message display. |
| 59 | + */ |
| 60 | + protected MessageLogger getLogger() { |
| 61 | + return logger; |
| 62 | + } |
| 63 | + |
| 64 | + /** Forwards a given message to the selected message logger. */ |
| 65 | + public void notify(String msg) { |
| 66 | + if (logger != null) |
| 67 | + logger.log(msg); |
| 68 | + } |
| 69 | +} |
0 commit comments