1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.cb.jset.client;
21
22 import org.cb.jset.SetGameBoardListener;
23 import org.cb.jset.CardProperties;
24 import org.cb.jset.CardSet;
25
26 import javax.swing.event.EventListenerList;
27
28 /***
29 * An abstract <code>SetGame</code>, responsible of the event management.
30 *
31 * @author jerome@coffeebreaks.org - last modified by $LastModifiedBy$
32 * @version $Id: AbstractGame.java 123 2004-04-14 23:45:53Z jerome $
33 */
34 public abstract class AbstractGame implements SetGame
35 {
36 protected final EventListenerList _listenerList = new EventListenerList();
37
38
39 public void addBoardListener(final SetGameBoardListener listener)
40 {
41 _listenerList.add(SetGameBoardListener.class, listener);
42 }
43
44 public void removeBoardListener(final SetGameBoardListener listener)
45 {
46 _listenerList.remove(SetGameBoardListener.class, listener);
47 }
48
49 public void addGameListener(final SetGameListener listener)
50 {
51 _listenerList.add(SetGameListener.class, listener);
52 }
53
54 public void removeGameListener(final SetGameListener listener)
55 {
56 _listenerList.remove(SetGameListener.class, listener);
57 }
58
59
60 protected void fireGameChange(final GameEvent event)
61 {
62
63 final Object[] listeners = _listenerList.getListenerList();
64
65
66 for (int i = listeners.length - 2; i >= 0; i -= 2)
67 {
68 if (listeners[i] == SetGameListener.class)
69 {
70 ((SetGameListener) listeners[i + 1]).gameChange(event);
71 }
72 }
73 }
74
75 protected void fireCardsAdded(final CardProperties[] cards)
76 {
77
78 final Object[] listeners = _listenerList.getListenerList();
79
80
81 for (int i = listeners.length - 2; i >= 0; i -= 2)
82 {
83 if (listeners[i] == SetGameBoardListener.class)
84 {
85 ((SetGameBoardListener) listeners[i + 1]).cardsAdded(cards);
86 }
87 }
88 }
89
90 protected void fireSetRemoved(final CardSet set)
91 {
92
93 final Object[] listeners = _listenerList.getListenerList();
94
95
96 for (int i = listeners.length - 2; i >= 0; i -= 2)
97 {
98 if (listeners[i] == SetGameBoardListener.class)
99 {
100 ((SetGameBoardListener) listeners[i + 1]).setRemoved(set);
101 }
102 }
103 }
104 }