View Javadoc

1   // %1126721330604:hoplugins.transfers.ui%
2   package hoplugins.transfers.ui;
3   
4   import hoplugins.Commons;
5   import hoplugins.commons.ui.DefaultTableSorter;
6   import hoplugins.commons.ui.info.clearthought.layout.TableLayout;
7   import hoplugins.commons.utils.PluginProperty;
8   import hoplugins.transfers.dao.TransfersDAO;
9   import hoplugins.transfers.ui.model.PlayerTransferTableModel;
10  import hoplugins.transfers.utils.PlayerRetriever;
11  import hoplugins.transfers.vo.PlayerTransfer;
12  
13  import plugins.IHelper;
14  import plugins.ISpieler;
15  
16  import java.awt.BorderLayout;
17  import java.awt.Color;
18  import java.awt.event.ActionEvent;
19  import java.awt.event.ActionListener;
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.Vector;
24  
25  import javax.swing.BorderFactory;
26  import javax.swing.Icon;
27  import javax.swing.JButton;
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  import javax.swing.JScrollPane;
31  import javax.swing.JTable;
32  import javax.swing.SwingConstants;
33  import javax.swing.table.TableModel;
34  
35  
36  /***
37   * Panel for showing detailed information on a player.
38   *
39   * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
40   */
41  public class PlayerDetailPanel extends JPanel implements ActionListener {
42      //~ Instance fields ----------------------------------------------------------------------------
43      private static final String SKILL_KEEPER = Commons.getModel().getResource().getProperty("Torwart");
44      private static final String SKILL_PLAYMAKING = Commons.getModel().getResource().getProperty("Spielaufbau");
45      private static final String SKILL_PASSING = Commons.getModel().getResource().getProperty("Passpiel");
46      private static final String SKILL_WING = Commons.getModel().getResource().getProperty("Fluegelspiel");
47      private static final String SKILL_DEFENSE = Commons.getModel().getResource().getProperty("Verteidigung");
48      private static final String SKILL_SCORING = Commons.getModel().getResource().getProperty("Chancenverwertung");
49      private static final String SKILL_SETPIECES = Commons.getModel().getResource().getProperty("Standards");
50      private static final String SKILL_STAMINA = Commons.getModel().getResource().getProperty("Kondition");
51      private static final String SKILL_EXPERIENCE = Commons.getModel().getResource().getProperty("Erfahrung");
52  
53      private ISpieler player;
54      private JButton updBtn = new JButton();
55      private JLabel age = new JLabel("", SwingConstants.LEFT); //$NON-NLS-1$
56      private JLabel currTSI = new JLabel(PluginProperty.getString("PlayerDetail.NotAvail"),
57                                          SwingConstants.LEFT); //$NON-NLS-1$
58      private JLabel income = new JLabel("", SwingConstants.LEFT); //$NON-NLS-1$
59      private JLabel name = new JLabel("", SwingConstants.LEFT); //$NON-NLS-1$
60      
61      private JLabel skill_defense = new JLabel("", SwingConstants.LEFT);
62      private JLabel skill_experience = new JLabel("", SwingConstants.LEFT);
63      private JLabel skill_keeper = new JLabel("", SwingConstants.LEFT);
64      private JLabel skill_passing = new JLabel("", SwingConstants.LEFT);
65      private JLabel skill_playmaking = new JLabel("", SwingConstants.LEFT);
66      private JLabel skill_scoring = new JLabel("", SwingConstants.LEFT);
67      private JLabel skill_setpieces = new JLabel("", SwingConstants.LEFT);
68      private JLabel skill_stamina = new JLabel("", SwingConstants.LEFT);
69      private JLabel skill_wing = new JLabel("", SwingConstants.LEFT);
70      
71      private JLabel arrow_defense = new JLabel((Icon) null, SwingConstants.CENTER);
72      private JLabel arrow_experience = new JLabel((Icon) null, SwingConstants.CENTER);
73      private JLabel arrow_keeper = new JLabel((Icon) null, SwingConstants.CENTER);
74      private JLabel arrow_passing = new JLabel((Icon) null, SwingConstants.CENTER);
75      private JLabel arrow_playmaking = new JLabel((Icon) null, SwingConstants.CENTER);
76      private JLabel arrow_scoring = new JLabel((Icon) null, SwingConstants.CENTER);
77      private JLabel arrow_setpieces = new JLabel((Icon) null, SwingConstants.CENTER);
78      private JLabel arrow_stamina = new JLabel((Icon) null, SwingConstants.CENTER);
79      private JLabel arrow_wing = new JLabel((Icon) null, SwingConstants.CENTER);
80      private JTable playerTable;
81      private String playerName;
82      private int playerId;
83  
84      //~ Constructors -------------------------------------------------------------------------------
85  
86      /***
87       * Creates a PlayerDetailPanel.
88       */
89      public PlayerDetailPanel() {
90          super(new BorderLayout());
91  
92          final TableModel model = new PlayerTransferTableModel(new ArrayList());
93          final TeamTransferSorter sorter = new TeamTransferSorter(model);
94          playerTable = new JTable(sorter);
95          sorter.setTableHeader(playerTable.getTableHeader());
96  
97          final JScrollPane playerPane = new JScrollPane(playerTable);
98          playerPane.setOpaque(false);
99          add(playerPane, BorderLayout.CENTER);
100 
101         final double[][] sizes = {
102                                {
103                                    10, 50, 150, 20, 75, 50, TableLayout.FILL, 30, 100, 30, 100, 30,
104                                    100, 50, 100, 10
105                                },
106                                {20, 20, 20}
107                            };
108 
109         final JPanel detailPanel = Commons.getModel().getGUI().createImagePanel();
110         detailPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),
111                                                                PluginProperty.getString("PlayerDetail"))); //$NON-NLS-1$
112         detailPanel.setOpaque(false);
113 
114         final TableLayout layout = new TableLayout(sizes);
115         detailPanel.setLayout(layout);
116 
117         detailPanel.add(new JLabel(Commons.getModel().getResource().getProperty("Name"),
118                                    SwingConstants.LEFT), "1, 0"); //$NON-NLS-1$ //$NON-NLS-2$
119         detailPanel.add(name, "2, 0"); //$NON-NLS-1$
120         detailPanel.add(new JLabel(Commons.getModel().getResource().getProperty("Alter"),
121                                    SwingConstants.LEFT), "1, 1"); //$NON-NLS-1$ //$NON-NLS-2$
122         detailPanel.add(age, "2, 1"); //$NON-NLS-1$
123         detailPanel.add(new JLabel(PluginProperty.getString("Income"), SwingConstants.LEFT), "1, 2"); //$NON-NLS-1$ //$NON-NLS-2$
124         detailPanel.add(income, "2, 2"); //$NON-NLS-1$
125 
126         detailPanel.add(new JLabel(PluginProperty.getString("PlayerDetail.CurrentTSI")), "4, 0");
127         detailPanel.add(currTSI, "5, 0");
128 
129         detailPanel.add(arrow_scoring, "7, 0"); //$NON-NLS-1$
130         detailPanel.add(skill_scoring, "8, 0"); //$NON-NLS-1$
131         detailPanel.add(arrow_playmaking, "7, 1"); //$NON-NLS-1$
132         detailPanel.add(skill_playmaking, "8, 1"); //$NON-NLS-1$
133         detailPanel.add(arrow_defense, "7, 2"); //$NON-NLS-1$
134         detailPanel.add(skill_defense, "8, 2"); //$NON-NLS-1$
135 
136         detailPanel.add(arrow_wing, "9, 0"); //$NON-NLS-1$
137         detailPanel.add(skill_wing, "10, 0"); //$NON-NLS-1$
138         detailPanel.add(arrow_passing, "9, 1"); //$NON-NLS-1$
139         detailPanel.add(skill_passing, "10, 1"); //$NON-NLS-1$
140         detailPanel.add(arrow_stamina, "9, 2"); //$NON-NLS-1$
141         detailPanel.add(skill_stamina, "10, 2"); //$NON-NLS-1$
142 
143         detailPanel.add(arrow_keeper, "11, 0"); //$NON-NLS-1$
144         detailPanel.add(skill_keeper, "12, 0"); //$NON-NLS-1$
145         detailPanel.add(arrow_setpieces, "11, 1"); //$NON-NLS-1$
146         detailPanel.add(skill_setpieces, "12, 1"); //$NON-NLS-1$
147         detailPanel.add(arrow_experience, "11, 2"); //$NON-NLS-1$
148         detailPanel.add(skill_experience, "12, 2"); //$NON-NLS-1$
149 
150         updBtn.setEnabled(false);
151         updBtn.setText(PluginProperty.getString("Update"));
152         updBtn.setToolTipText(PluginProperty.getString("UpdTooltip"));
153         updBtn.addActionListener(this);
154         updBtn.setFocusable(false);
155 
156         detailPanel.add(updBtn, "14, 0, 14, 1");
157         add(new JScrollPane(detailPanel), BorderLayout.NORTH);
158         setOpaque(false);
159 
160         clearPanel();
161     }
162 
163     //~ Methods ------------------------------------------------------------------------------------
164 
165     /***
166      * Sets the player to display information for.
167      *
168      * @param playerid Player id
169      * @param playerName Player Name
170      */
171     public final void setPlayer(int playerid, String playerName) {
172         this.player = PlayerRetriever.getPlayer(playerid);
173 
174         if (this.player != null) {
175             this.playerId = player.getSpielerID();
176             this.playerName = player.getName();
177         } else {
178             this.playerId = playerid;
179             this.playerName = playerName;
180         }
181 
182         clearPanel();
183         updatePanel();
184     }
185 
186     /*** {@inheritDoc} */
187     public final void actionPerformed(ActionEvent e) {
188         if (this.playerId > 0) {
189             TransfersDAO.updatePlayerTransfers(this.playerId);
190             updatePanel();
191         }
192     }
193 
194     /***
195      * Clears all information on the panel.
196      */
197     public final void clearPanel() {
198         updBtn.setEnabled(false);
199         name.setText(""); //$NON-NLS-1$
200         age.setText(""); //$NON-NLS-1$
201         income.setText("");
202         currTSI.setText(PluginProperty.getString("PlayerDetail.NotAvail"));
203         
204         skill_keeper.setText(SKILL_KEEPER);
205         skill_playmaking.setText(SKILL_PLAYMAKING);
206         skill_passing.setText(SKILL_PASSING);
207         skill_wing.setText(SKILL_WING);
208         skill_defense.setText(SKILL_DEFENSE);
209         skill_scoring.setText(SKILL_SCORING);
210         skill_setpieces.setText(SKILL_SETPIECES);
211         skill_stamina.setText(SKILL_STAMINA);
212         skill_experience.setText(SKILL_EXPERIENCE);
213         
214         arrow_keeper.setIcon(null);
215         arrow_playmaking.setIcon(null);
216         arrow_passing.setIcon(null);
217         arrow_wing.setIcon(null);
218         arrow_defense.setIcon(null);
219         arrow_scoring.setIcon(null);
220         arrow_setpieces.setIcon(null);
221         arrow_stamina.setIcon(null);
222         arrow_experience.setIcon(null);
223         refreshPlayerTable(new Vector());
224     }
225 
226     /***
227      * Refreshes the table with player transfer information.
228      *
229      * @param values List of player transfers to display.
230      */
231     private void refreshPlayerTable(List values) {
232         final DefaultTableSorter sorter = (DefaultTableSorter) playerTable.getModel();
233         sorter.setTableModel(new PlayerTransferTableModel(values));
234         playerTable.getColumnModel().getColumn(3).setPreferredWidth(150);
235         playerTable.getColumnModel().getColumn(4).setCellRenderer(new IconCellRenderer());
236         playerTable.getColumnModel().getColumn(4).setMaxWidth(20);
237         playerTable.getColumnModel().getColumn(4).setPreferredWidth(150);
238     }
239 
240     /***
241      * Update the detail panel.
242      */
243     private void updatePanel() {
244         if (playerId > 0) {
245             updBtn.setEnabled(true);
246             name.setText(this.playerName);
247 
248             if (player != null) {
249                 age.setText(Integer.toString(this.player.getAlter()));
250 
251                 if (!player.isOld()) {
252                     currTSI.setText(Integer.toString(this.player.getMarkwert()));
253                 }
254 
255                 skill_keeper.setText(SKILL_KEEPER + " (" + player.getTorwart() + ")");
256                 skill_playmaking.setText(SKILL_PLAYMAKING + " (" + player.getSpielaufbau() + ")");
257                 skill_passing.setText(SKILL_PASSING + " (" + player.getPasspiel() + ")");
258                 skill_wing.setText(SKILL_WING + " (" + player.getFluegelspiel() + ")");
259                 skill_defense.setText(SKILL_DEFENSE + " (" + player.getVerteidigung() + ")");
260                 skill_scoring.setText(SKILL_SCORING + " (" + player.getTorschuss() + ")");
261                 skill_setpieces.setText(SKILL_SETPIECES + " (" + player.getStandards() + ")");
262                 skill_stamina.setText(SKILL_STAMINA + " (" + player.getKondition() + ")");
263                 skill_experience.setText(SKILL_EXPERIENCE + " (" + player.getErfahrung() + ")");
264 
265                 final IHelper helper = Commons.getModel().getHelper();
266                 arrow_keeper.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_TORWART)
267                                                                             .size()));
268                 arrow_playmaking.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_SPIELAUFBAU)
269                                                                                 .size()));
270                 arrow_passing.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_PASSSPIEL)
271                                                                              .size()));
272                 arrow_wing.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_FLUEGEL)
273                                                                           .size()));
274                 arrow_defense.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_VERTEIDIGUNG)
275                                                                              .size()));
276                 arrow_scoring.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_TORSCHUSS)
277                                                                              .size()));
278                 arrow_setpieces.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_STANDARDS)
279                                                                                .size()));
280                 arrow_stamina.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_KONDITION)
281                                                                              .size()));
282                 arrow_experience.setIcon(helper.getImageIcon4Veraenderung(player.getAllLevelUp(ISpieler.SKILL_EXPIERIENCE)
283                                                                                 .size()));
284             }
285 
286             final List transfers = TransfersDAO.getTransfers(this.playerId, true);
287             int valIncome = 0;
288             final int teamid = Commons.getModel().getBasics().getTeamId();
289 
290             for (final Iterator iter = transfers.iterator(); iter.hasNext();) {
291                 final PlayerTransfer transfer = (PlayerTransfer) iter.next();
292 
293                 if (transfer.getBuyerid() == teamid) {
294                     valIncome -= transfer.getPrice();
295                 }
296 
297                 if (transfer.getSellerid() == teamid) {
298                     valIncome += transfer.getPrice();
299                 }
300             }
301 
302             income.setText(Commons.getModel().getXtraDaten().getCurrencyName() + " " + valIncome);
303             refreshPlayerTable(transfers);
304         }
305     }
306 }