1
2 package hoplugins.teamAnalyzer.ui;
3
4 import hoplugins.Commons;
5
6 import hoplugins.teamAnalyzer.SystemManager;
7 import hoplugins.teamAnalyzer.manager.PlayerDataManager;
8 import hoplugins.teamAnalyzer.util.NameUtil;
9 import hoplugins.teamAnalyzer.vo.PlayerInfo;
10 import hoplugins.teamAnalyzer.vo.SpotLineup;
11
12 import java.awt.BorderLayout;
13 import java.awt.Color;
14 import java.awt.Dimension;
15 import java.awt.Font;
16
17 import java.util.ArrayList;
18
19 import javax.swing.BorderFactory;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22
23
24 /***
25 * TODO Missing Class Documentation
26 *
27 * @author TODO Author Name
28 */
29 public class PlayerPanel extends JPanel {
30
31
32 /*** TODO Missing Parameter Documentation */
33 protected JLabel appearanceField = new JLabel("", JLabel.RIGHT);
34
35 /*** TODO Missing Parameter Documentation */
36 protected JLabel nameField = new JLabel("", JLabel.LEFT);
37
38 /*** TODO Missing Parameter Documentation */
39 protected JLabel positionField = createLabel("", Color.BLACK, 0);
40
41 /*** TODO Missing Parameter Documentation */
42 protected JLabel positionImage = new JLabel();
43
44 /*** TODO Missing Parameter Documentation */
45 protected JLabel specialEventImage = new JLabel();
46
47 /*** TODO Missing Parameter Documentation */
48 protected JPanel ratingPanel = new JPanel();
49
50 /*** TODO Missing Parameter Documentation */
51 protected TacticPanel tacticPanel = new TacticPanel();
52 private JPanel mainPanel;
53 private PlayerInfoPanel infoPanel = new PlayerInfoPanel();
54 private SpotLineup spotLineup;
55
56
57
58 /***
59 * Creates a new PlayerPanel object.
60 */
61 public PlayerPanel() {
62 setLayout(new BorderLayout());
63
64 Font nFont = new Font(nameField.getFont().getFontName(), Font.BOLD,
65 nameField.getFont().getSize());
66
67 nameField.setFont(nFont);
68
69 JPanel details = new JPanel();
70
71 details.setBorder(BorderFactory.createEtchedBorder());
72 details.setBackground(getBackGround());
73 details.setLayout(new BorderLayout());
74
75 JPanel images = new JPanel();
76
77 images.setBackground(getBackGround());
78 images.setLayout(new BorderLayout());
79 images.add(positionImage, BorderLayout.WEST);
80 images.add(specialEventImage, BorderLayout.EAST);
81 details.add(images, BorderLayout.WEST);
82 details.add(nameField, BorderLayout.CENTER);
83 details.add(appearanceField, BorderLayout.EAST);
84
85 JPanel centerPanel = new JPanel();
86
87 centerPanel.setBorder(BorderFactory.createEtchedBorder());
88 centerPanel.setBackground(getBackGround());
89 centerPanel.setLayout(new BorderLayout());
90 centerPanel.add(details, BorderLayout.NORTH);
91 centerPanel.add(ratingPanel, BorderLayout.WEST);
92
93 if (!(this instanceof UserTeamPlayerPanel)) {
94 centerPanel.add(infoPanel, BorderLayout.SOUTH);
95 }
96
97 mainPanel = Commons.getModel().getGUI().createImagePanel();
98 mainPanel.setLayout(new BorderLayout());
99 mainPanel.setBorder(BorderFactory.createRaisedBevelBorder());
100 mainPanel.setPreferredSize(getDefaultSize());
101 mainPanel.add(positionField, BorderLayout.NORTH);
102 mainPanel.add(centerPanel, BorderLayout.CENTER);
103 mainPanel.add(tacticPanel, BorderLayout.SOUTH);
104 add(mainPanel, BorderLayout.CENTER);
105 }
106
107
108
109 /***
110 * TODO Missing Method Documentation
111 *
112 * @return TODO Missing Return Method Documentation
113 */
114 public Color getBackGround() {
115 return Color.WHITE;
116 }
117
118 /***
119 * TODO Missing Method Documentation
120 *
121 * @return TODO Missing Return Method Documentation
122 */
123 public Dimension getDefaultSize() {
124 int height = 60;
125
126 if (!(this instanceof UserTeamPlayerPanel)) {
127 if (SystemManager.getConfig().isShowPlayerInfo()) {
128 height = height + 50;
129 }
130 }
131
132 if (SystemManager.getConfig().isTacticDetail()) {
133 height = height + 50;
134 }
135
136 return new Dimension(180, height);
137 }
138
139 /***
140 * TODO Missing Method Documentation
141 *
142 * @param lineup TODO Missing Method Parameter Documentation
143 * @param week TODO Missing Constructuor Parameter Documentation
144 * @param season TODO Missing Constructuor Parameter Documentation
145 */
146 public void reload(SpotLineup lineup, int week, int season) {
147 spotLineup = lineup;
148 tacticPanel.setVisible(SystemManager.getConfig().isTacticDetail());
149 mainPanel.setPreferredSize(getDefaultSize());
150
151 if (lineup != null) {
152 switch (lineup.getStatus()) {
153 case PlayerDataManager.INJURED:
154 nameField.setForeground(Color.RED);
155 break;
156
157 case PlayerDataManager.SUSPENDED:
158 nameField.setForeground(Color.RED);
159 break;
160
161 case PlayerDataManager.SOLD:
162 nameField.setForeground(Color.BLUE);
163 break;
164
165 default:
166 nameField.setForeground(Color.BLACK);
167 break;
168 }
169
170 nameField.setText(NameUtil.getPlayerDesc(lineup.getName()));
171
172 appearanceField.setText("" + lineup.getAppearance());
173
174 if (SystemManager.getConfig().isShowPlayerInfo()) {
175 PlayerInfo pi = PlayerDataManager.getPlayerInfo(lineup.getPlayerId(), week, season);
176
177 if (pi.getAge() != 0) {
178 infoPanel.setValue(pi);
179 } else {
180 infoPanel.clearData();
181 }
182
183 infoPanel.setVisible(true);
184 }
185
186 int posCode = Commons.getModel().getHelper().getPosition(lineup.getPosition());
187
188 positionImage.setIcon(Commons.getModel().getHelper().getImage4Position(posCode, (byte) 0));
189
190 int specialEvent = PlayerDataManager.getLatestPlayerInfo(lineup.getPlayerId())
191 .getSpecialEvent();
192
193 if (lineup.getPlayerId() == 0) {
194 specialEventImage.setIcon(null);
195 } else {
196 specialEventImage.setIcon(Commons.getModel().getHelper().getImageIcon4Spezialitaet(specialEvent));
197 }
198
199 positionField.setText(Commons.getModel().getHelper().getNameForPosition((byte) lineup
200 .getPosition()));
201 updateRatingPanel(lineup.getRating());
202 tacticPanel.reload(lineup.getTactics());
203 } else {
204 nameField.setText(" ");
205 appearanceField.setText(" ");
206 positionField.setText(" ");
207 infoPanel.setVisible(false);
208 infoPanel.clearData();
209 updateRatingPanel(0);
210 positionImage.setIcon(Commons.getModel().getHelper().getImage4Position(0, (byte) 0));
211 specialEventImage.setIcon(null);
212 tacticPanel.reload(new ArrayList());
213 }
214 }
215
216 /***
217 * TODO Missing Method Documentation
218 *
219 * @param rating TODO Missing Method Parameter Documentation
220 */
221 protected void updateRatingPanel(double rating) {
222 ratingPanel.removeAll();
223 ratingPanel.setLayout(new BorderLayout());
224
225 JPanel starPanel = Commons.getModel().getGUI().createStarPanel((int) Math.round(rating * 2),
226 true);
227
228 starPanel.setBackground(getBackGround());
229 ratingPanel.add(starPanel, BorderLayout.WEST);
230 ratingPanel.setOpaque(true);
231 ratingPanel.setBackground(getBackGround());
232 }
233
234 /***
235 * TODO Missing Method Documentation
236 *
237 * @param text TODO Missing Method Parameter Documentation
238 * @param farbe TODO Missing Method Parameter Documentation
239 * @param Bordertype TODO Missing Method Parameter Documentation
240 *
241 * @return TODO Missing Return Method Documentation
242 */
243 private JLabel createLabel(String text, Color farbe, int Bordertype) {
244 JLabel bla = new JLabel(text);
245
246 bla.setHorizontalAlignment(0);
247 bla.setForeground(farbe);
248 bla.setBorder(BorderFactory.createEtchedBorder(Bordertype));
249
250 return bla;
251 }
252 }