1 package org.argosfields.battlefield;
2
3 import org.argosfields.model.Tile;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.KeyEvent;
6 import org.eclipse.swt.events.KeyListener;
7 import org.eclipse.swt.events.MouseEvent;
8 import org.eclipse.swt.events.MouseListener;
9 import org.eclipse.swt.events.PaintEvent;
10 import org.eclipse.swt.events.PaintListener;
11
12 /***
13 * State.java
14 *
15 * @author Xavier Cho
16 * @version $Revision: 1.2 $ $Date: 2003/12/01 07:38:05 $
17 */
18 public abstract class State
19 implements MouseListener, KeyListener, PaintListener {
20
21 private Context context;
22 private BattleFieldView battleFieldView;
23
24 public State(final Context context) {
25 if (context == null) {
26 SWT.error(SWT.ERROR_NULL_ARGUMENT);
27 }
28
29 this.context = context;
30 }
31
32 public abstract String getName();
33
34 protected Context getContext() {
35 return context;
36 }
37
38 protected Tile getTile(final MouseEvent event) {
39 if (event == null) {
40 SWT.error(SWT.ERROR_NULL_ARGUMENT);
41 }
42
43 BattleFieldView view = context.getBattleFieldView();
44 BattleField field = view.getBattleField();
45
46 Tile tile = null;
47
48 if (field != null) {
49 int index = field.getIndexFromPoint(event.x, event.y);
50 tile = field.getTile(index);
51 }
52
53 return tile;
54 }
55
56 /***
57 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
58 */
59 public void mouseDoubleClick(final MouseEvent event) {
60 }
61
62 /***
63 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
64 */
65 public void mouseDown(final MouseEvent event) {
66 }
67
68 /***
69 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
70 */
71 public void mouseUp(final MouseEvent event) {
72 }
73
74 /***
75 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
76 */
77 public void keyPressed(final KeyEvent event) {
78 }
79
80 /***
81 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
82 */
83 public void keyReleased(final KeyEvent event) {
84 }
85
86 /***
87 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
88 */
89 public void paintControl(final PaintEvent event) {
90 }
91 }
This page was automatically generated by Maven