View Javadoc

1   /*
2    * Created on Nov 11, 2004 
3    * Original filename was DelayedCard.java
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 	 * (non-Javadoc)
104 	 * 
105 	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
106 	 */
107 	public void mouseClicked(MouseEvent e) {
108 		// Nothing to do
109 	}
110 
111 	/*
112 	 * (non-Javadoc)
113 	 * 
114 	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
115 	 */
116 	public void mousePressed(MouseEvent e) {
117 		// Nothing to do
118 	}
119 
120 	/*
121 	 * (non-Javadoc)
122 	 * 
123 	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
124 	 */
125 	public void mouseReleased(MouseEvent e) {
126 		// Nothing to do
127 	}
128 
129 	/*
130 	 * (non-Javadoc)
131 	 * 
132 	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
133 	 */
134 	public void mouseEntered(MouseEvent e) {
135 		// Nothing to do
136 	}
137 
138 	public void mouseExited(MouseEvent e) {
139 		// Nothing to do
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 }