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.zone;
20  
21  import java.awt.Color;
22  import java.awt.Dimension;
23  import java.awt.FlowLayout;
24  import java.awt.event.HierarchyBoundsListener;
25  import java.awt.event.HierarchyEvent;
26  
27  import javax.swing.JScrollPane;
28  
29  import net.sf.magicproject.clickable.Clickable;
30  import net.sf.magicproject.clickable.targetable.card.CardFactory;
31  import net.sf.magicproject.token.IdZones;
32  import net.sf.magicproject.tools.Configuration;
33  import net.sf.magicproject.ui.layout.FlowLayout2;
34  
35  /***
36   * The hand zone. This zone is the zone the spells are played from.
37   * 
38   * @author Fabrice Daugan
39   * @since 0.2d
40   * @since 0.3 feature "reverseImage" implemented
41   * @since 0.4 you can now change wallpaper/color of this MZone and setting are
42   *        saved.
43   */
44  public class Hand extends MZone implements HierarchyBoundsListener {
45  
46  	/***
47  	 * The zone name.
48  	 */
49  	public static final String ZONE_NAME = "hand";
50  
51  	/***
52  	 * create a new instance of Hand
53  	 * 
54  	 * @param superPanel
55  	 *          scroll panel containing this panel
56  	 * @param reverseImage
57  	 *          if true the backpicture will be reversed
58  	 * @since 0.3 feature "reverseImage" implemented
59  	 * @see IdZones
60  	 */
61  	Hand(JScrollPane superPanel, boolean reverseImage) {
62  		super(IdZones.HAND, new FlowLayout(), superPanel, reverseImage, ZONE_NAME);
63  		setMinimumSize(new Dimension(90, 60));
64  		updateLayouts(this,
65  				(Configuration.getBoolean("reverseSide", false) || Configuration
66  						.getBoolean("reverseArt", true))
67  						&& reverseImage);
68  		addHierarchyBoundsListener(this);
69  	}
70  
71  	public void ancestorMoved(HierarchyEvent evt) {
72  		// Ignore this event
73  	}
74  
75  	public void ancestorResized(HierarchyEvent evt) {
76  		updatePanel();
77  	}
78  
79  	/***
80  	 * update this hand
81  	 */
82  	@Override
83  	public void updatePanel() {
84  		int count = getComponentCount();
85  		if (count == 0) {
86  			count = 1;
87  		}
88  		int nbPerLine = getParent().getWidth() / (CardFactory.cardWidth + 5);
89  		if (nbPerLine > 0) {
90  			setPreferredSize(new Dimension(getParent().getWidth(),
91  					(CardFactory.cardHeight + 5) * (count + nbPerLine - 1) / nbPerLine));
92  		}
93  		superPanel.setViewportView(this);
94  	}
95  
96  	/***
97  	 * 
98  	 */
99  	@Override
100 	public void updateReversed() {
101 		// need to update?
102 		if ((Configuration.getBoolean("reverseSide", false) || Configuration
103 				.getBoolean("reverseArt", true))
104 				&& reverseImage
105 				&& getLayout() instanceof FlowLayout
106 				|| !((Configuration.getBoolean("reverseSide", false) || Configuration
107 						.getBoolean("reverseArt", true)) && reverseImage)
108 				&& getLayout() instanceof FlowLayout2) {
109 			updateLayouts(this,
110 					(Configuration.getBoolean("reverseSide", false) || Configuration
111 							.getBoolean("reverseArt", true))
112 							&& reverseImage);
113 		}
114 		updatePanel();
115 	}
116 
117 	/***
118 	 * Dishighlight all cards of this zone manager
119 	 */
120 	@Override
121 	public void disHighLightAll() {
122 		for (int i = getComponentCount(); i-- > 0;) {
123 			((Clickable) getComponent(i)).disHighLight();
124 		}
125 	}
126 
127 	/***
128 	 * Dishighlight only this component, not the components of this zone.
129 	 */
130 	@Override
131 	public void disHighLight() {
132 		// nothing to do
133 	}
134 
135 	/***
136 	 * Highlight only this component, not the components of this zone. Use instead
137 	 * the specific highlight color of the desired zone.
138 	 * 
139 	 * @param targetColor
140 	 */
141 	@Override
142 	public void highLight(Color targetColor) {
143 		// nothing to do
144 	}
145 
146 }