1
2 package hoplugins.trainingExperience.ui;
3
4 import hoplugins.Commons;
5 import hoplugins.TrainingExperience;
6
7 import hoplugins.commons.ui.BaseTableModel;
8 import hoplugins.commons.utils.ListUtil;
9 import hoplugins.commons.utils.PluginProperty;
10
11 import hoplugins.trainingExperience.ui.renderer.TrainingRecapRenderer;
12
13 import plugins.IFutureTrainingManager;
14 import plugins.ISkillup;
15 import plugins.ISpieler;
16
17 import java.awt.BorderLayout;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.SortedSet;
24 import java.util.Vector;
25
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JTable;
29 import javax.swing.ListSelectionModel;
30
31
32 /***
33 * Recap Panel when future preview of skillups is shown ("Prediction" tab, "Training Recap"
34 * table").
35 *
36 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
37 */
38 public class TrainingRecapPanel extends JPanel {
39
40
41 /*** TODO Missing Parameter Documentation */
42 public static final int FUTURE_WEEKS = 16;
43
44
45
46 private BaseTableModel tableModel;
47
48
49 private TrainingRecapTable recapTable;
50
51
52
53 /***
54 * Creates a new TrainingRecapPanel object.
55 */
56 public TrainingRecapPanel() {
57 super();
58 reload();
59 }
60
61
62
63 /***
64 * Reload the panel
65 */
66 public void reload() {
67 jbInit();
68
69
70 Vector columns = getColumns();
71
72
73 List trainings = TrainingExperience.getTrainPanel().getFutureTrainings();
74
75 Vector v = Commons.getModel().getAllSpieler();
76
77 List players = new ArrayList();
78
79 for (Iterator iter = v.iterator(); iter.hasNext();) {
80 ISpieler player = (ISpieler) iter.next();
81 IFutureTrainingManager ftm = Commons.getModel().getFutureTrainingManager(player,
82 trainings,
83 TrainingExperience.getStaffPanel()
84 .getCoTrainerNumber(),
85 TrainingExperience.getStaffPanel()
86 .getKeeperTrainerNumber(),
87 TrainingExperience.getStaffPanel()
88 .getTrainerLevelNumber());
89 List su = ftm.getFutureSkillups();
90
91
92 if (su.size() == 0) {
93 continue;
94 }
95
96 HashMap maps = new HashMap();
97
98 for (Iterator iterator = su.iterator(); iterator.hasNext();) {
99 ISkillup skillup = (ISkillup) iterator.next();
100
101 maps.put(skillup.getHtSeason() + " " + skillup.getHtWeek(), skillup);
102 }
103
104 Vector row = new Vector();
105
106 row.add(player.getName());
107 row.add("" + player.getAlter());
108
109 for (int i = 0; i < FUTURE_WEEKS; i++) {
110 ISkillup s = (ISkillup) maps.get(columns.get(i + 2));
111
112 if (s == null) {
113 row.add("");
114 } else {
115 row.add(s.getType() + " " + s.getValue());
116 }
117 }
118
119 row.add(Integer.toString(player.getSpielerID()));
120
121
122 players.add(row);
123
124
125 }
126
127
128 SortedSet sorted = ListUtil.getSortedSet(players, new TrainingComparator());
129
130
131 for (Iterator iter = sorted.iterator(); iter.hasNext();) {
132 Vector row = (Vector) iter.next();
133
134 tableModel.addRow(row);
135 }
136
137 updateUI();
138 }
139
140 /***
141 * Get Columns name
142 *
143 * @return List of string
144 */
145 private Vector getColumns() {
146 Vector columns = new Vector();
147
148 columns.add(Commons.getModel().getResource().getProperty("Spieler"));
149 columns.add(Commons.getModel().getResource().getProperty("Alter"));
150
151 int actualSeason = Commons.getModel().getBasics().getSeason();
152 int actualWeek = Commons.getModel().getBasics().getSpieltag();
153
154
155 try {
156 if (Commons.getModel().getXtraDaten().getTrainingDate().after(Commons.getModel()
157 .getXtraDaten()
158 .getSeriesMatchDate())) {
159 actualWeek++;
160
161 if (actualWeek == 17) {
162 actualWeek = 1;
163 actualSeason++;
164 }
165 }
166 } catch (Exception e1) {
167
168 }
169
170 for (int i = 0; i < FUTURE_WEEKS; i++) {
171
172 int week = (actualWeek + i) - 1;
173 int season = actualSeason + (week / 16);
174
175 week = (week % 16) + 1;
176
177 columns.add(season + " " + week);
178 }
179
180 columns.add(Commons.getModel().getResource().getProperty("ID"));
181
182 return columns;
183 }
184
185 /***
186 * Initialize the GUI
187 */
188 private void jbInit() {
189 removeAll();
190 setOpaque(false);
191 setLayout(new BorderLayout());
192
193 JPanel panel = Commons.getModel().getGUI().createImagePanel();
194
195 panel.setOpaque(false);
196 panel.setLayout(new BorderLayout());
197
198 JLabel title = new JLabel(PluginProperty.getString("Recap"), JLabel.CENTER);
199
200 title.setOpaque(false);
201 panel.add(title, BorderLayout.NORTH);
202
203 Vector columns = getColumns();
204
205 tableModel = new BaseTableModel(new Vector(), columns);
206
207 JTable table = new JTable(tableModel);
208
209 table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
210 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
211
212 recapTable = new TrainingRecapTable(table, 2);
213
214 recapTable.getScrollTable().setDefaultRenderer(Object.class, new TrainingRecapRenderer());
215
216 JTable scrollTable = recapTable.getScrollTable();
217
218
219 int lastSTCol = scrollTable.getColumnCount() - 1;
220
221 scrollTable.getTableHeader().getColumnModel().getColumn(lastSTCol).setPreferredWidth(0);
222 scrollTable.getTableHeader().getColumnModel().getColumn(lastSTCol).setMinWidth(0);
223 scrollTable.getTableHeader().getColumnModel().getColumn(lastSTCol).setMaxWidth(0);
224
225 JTable lockedTable = recapTable.getLockedTable();
226 lockedTable.getSelectionModel().addListSelectionListener(new PlayerSelectionListener(scrollTable,
227 lastSTCol));
228 panel.add(recapTable, BorderLayout.CENTER);
229 recapTable.getScrollTable().getTableHeader().setReorderingAllowed(false);
230
231
232 panel.add(new TrainingLegendPanel(), BorderLayout.SOUTH);
233 add(panel, BorderLayout.CENTER);
234 }
235 }