1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.clickable;
20
21 import java.awt.Color;
22 import java.awt.event.MouseEvent;
23 import java.awt.event.MouseListener;
24 import java.util.List;
25
26 import javax.swing.JComponent;
27
28 import net.sf.magicproject.clickable.targetable.card.CardFactory;
29
30 /***
31 * Any clickable component. This component can be highlighted, and relavant
32 * mouse action are sent to the other players.
33 *
34 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35 * @since 0.54
36 */
37 public abstract class Clickable extends JComponent implements MouseListener {
38
39 /***
40 * Creates a new instance of MClickable <br>
41 */
42 protected Clickable() {
43 super();
44 setBorder(null);
45 setFocusable(false);
46 setRequestFocusEnabled(false);
47 setFocusCycleRoot(false);
48 }
49
50 /***
51 * send to opponent the message indicating that we've clicked on this
52 * component
53 */
54 public abstract void sendClickToOpponent();
55
56 /***
57 * The border will be highligthed to yellow
58 *
59 * @param highlightedZone
60 * the set of highlighted zone.
61 */
62 public void highLight(boolean... highlightedZone) {
63 highLight(CardFactory.ACTIVATED_COLOR);
64 }
65
66 /***
67 * Remove any color of the border
68 */
69 public void disHighLight() {
70 if (isHighLighted) {
71 isHighLighted = false;
72 repaint();
73 }
74 }
75
76 /***
77 * The border will be highligted to highLightedColor
78 *
79 * @param highLightColor
80 * is the new border's color
81 */
82 protected void highLight(Color highLightColor) {
83 this.highLightColor = highLightColor;
84 isHighLighted = true;
85 repaint();
86 }
87
88 /***
89 * dishighlight the list of targetable
90 *
91 * @param list
92 * the list of targetable to dishighlight.
93 */
94 public static void disHighlight(List<? extends Clickable> list) {
95 for (Clickable clickable : list) {
96 clickable.disHighLight();
97 }
98 }
99
100 /***
101 * color of current highligth color
102 */
103 public Color highLightColor;
104
105 /***
106 * is this card is highlighted
107 */
108 public boolean isHighLighted;
109
110 public void mouseClicked(MouseEvent e) {
111
112 }
113
114 public void mouseEntered(MouseEvent e) {
115
116 }
117
118 public void mouseExited(MouseEvent e) {
119
120 }
121
122 public void mousePressed(MouseEvent e) {
123
124 }
125
126 public void mouseReleased(MouseEvent e) {
127
128 }
129 }