1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.magicproject.clickable.targetable.card;
24
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.event.MouseEvent;
30 import java.awt.event.MouseListener;
31 import java.util.List;
32
33 import javax.swing.JLabel;
34
35 import net.sf.magicproject.clickable.ability.Ability;
36 import net.sf.magicproject.clickable.ability.TriggeredAbility;
37 import net.sf.magicproject.clickable.targetable.Targetable;
38 import net.sf.magicproject.modifier.Unregisterable;
39
40 /***
41 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
42 * @since 0.80
43 * @since 0.86 A second targetable can be saved
44 */
45 public class DelayedCard extends JLabel implements MouseListener,
46 Unregisterable {
47
48 /***
49 * Creates a new instance of DelayedCard <br>
50 *
51 * @param ability
52 * The main ability of this delayed card. This ability is registered
53 * to the listeners until one of the 'until' abilities unregister it.
54 * @param abilities
55 * This is the list linked abilities corresponding to the 'until'
56 * part of this delayed card. Each one of these abilities is supposed
57 * to unregister from the listeners the main ability.
58 * @param registers
59 * the registers of this card. These registers must have been fixed
60 * previously.
61 * @param saved
62 * the saved targetable.
63 * @param saved2
64 * the second saved targetable.
65 */
66 public DelayedCard(TriggeredAbility ability, List<Ability> abilities,
67 int[] registers, Targetable saved, Targetable saved2) {
68 super();
69 this.ability = ability;
70 this.abilities = abilities;
71 ability.setDelayedCard(this);
72 setPreferredSize(new Dimension(TriggeredCard.cardWidth,
73 TriggeredCard.cardHeight));
74 setSize(new Dimension(TriggeredCard.cardWidth, TriggeredCard.cardHeight));
75 this.registers = registers;
76 this.saved = saved;
77 this.saved2 = saved2;
78 }
79
80 /***
81 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
82 */
83 @Override
84 public void paintComponent(Graphics g) {
85 Graphics2D g2D = (Graphics2D) g;
86 g2D.drawImage(ability.getCard().scaledImage(), null, null);
87
88 g2D.setColor(Color.BLACK);
89 g2D.drawRect(0, 0, CardFactory.cardWidth - 1, CardFactory.cardHeight - 1);
90 g2D.dispose();
91 }
92
93 /***
94 * Remove from the event manager this listener.
95 */
96 public void removeFromManager() {
97 for (Ability ability : abilities) {
98 ability.removeFromManager();
99 }
100 }
101
102
103
104
105
106
107 public void mouseClicked(MouseEvent e) {
108
109 }
110
111
112
113
114
115
116 public void mousePressed(MouseEvent e) {
117
118 }
119
120
121
122
123
124
125 public void mouseReleased(MouseEvent e) {
126
127 }
128
129
130
131
132
133
134 public void mouseEntered(MouseEvent e) {
135
136 }
137
138 public void mouseExited(MouseEvent e) {
139
140 }
141
142 public MCard getCard() {
143 return ability.getCard();
144 }
145
146 /***
147 * The main ability of this delayed card. This ability is registered to the
148 * listeners until one of the 'until' abilities unregister it.
149 */
150 private TriggeredAbility ability;
151
152 /***
153 * This is the list linked abilities corresponding to the 'until' part of this
154 * delayed card. Each one of these abilities is supposed to unregister from
155 * the listeners the main ability.
156 */
157 private List<Ability> abilities;
158
159 /***
160 * The saved targetable when this delayed card has been created
161 */
162 public Targetable saved;
163
164 /***
165 * The second saved targetable when this delayed card has been created
166 */
167 public Targetable saved2;
168
169 /***
170 * the registers of this card. These registers must have been fixed
171 * previously.
172 */
173 public int[] registers;
174 }