1 package org.argosfields.battlefield;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.eclipse.swt.SWT;
6
7 /***
8 * Context.java
9 *
10 * @author Xavier Cho
11 * @version $Revision: 1.2 $ $Date: 2003/10/27 15:47:42 $
12 */
13 public class Context {
14 private static Log log = LogFactory.getLog(Context.class);
15
16 private State currentState;
17 private BattleFieldView battleFieldView;
18
19 public Context(final BattleFieldView battleFieldView) {
20 if (battleFieldView == null) {
21 SWT.error(SWT.ERROR_NULL_ARGUMENT);
22 }
23
24 this.battleFieldView = battleFieldView;
25
26 setCurrentState(new DefaultState(this));
27 }
28
29 /***
30 * @return
31 */
32 public BattleFieldView getBattleFieldView() {
33 return battleFieldView;
34 }
35
36 protected void setCurrentState(final State state) {
37 if (state == null) {
38 SWT.error(SWT.ERROR_NULL_ARGUMENT);
39 }
40
41 if (log.isDebugEnabled()) {
42 log.debug("Changing state : " + state.getName());
43 }
44
45 synchronized (this) {
46 if (currentState != null) {
47 battleFieldView.removeMouseListener(currentState);
48 battleFieldView.removePaintListener(currentState);
49 battleFieldView.removeKeyListener(currentState);
50 }
51
52 this.currentState = state;
53
54 battleFieldView.addMouseListener(currentState);
55 battleFieldView.addPaintListener(currentState);
56 battleFieldView.addKeyListener(currentState);
57 }
58 }
59
60 /***
61 * @return
62 */
63 public State getCurrentState() {
64 return currentState;
65 }
66 }
This page was automatically generated by Maven