View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 		// Nothing to do
112 	}
113 
114 	public void mouseEntered(MouseEvent e) {
115 		// Nothing to do
116 	}
117 
118 	public void mouseExited(MouseEvent e) {
119 		// Nothing to do
120 	}
121 
122 	public void mousePressed(MouseEvent e) {
123 		// Nothing to do
124 	}
125 
126 	public void mouseReleased(MouseEvent e) {
127 		// Nothing to do
128 	}
129 }