1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
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
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
144 }
145
146 }