1
2 package hoplugins.trainingExperience.ui.model;
3
4 import hoplugins.TrainingExperience;
5
6 import hoplugins.trainingExperience.constants.Skills;
7 import hoplugins.trainingExperience.ui.bar.VerticalIndicator;
8
9 import plugins.IHOMiniModel;
10 import plugins.ISpieler;
11
12 import java.util.Vector;
13
14 import javax.swing.JPanel;
15 import javax.swing.table.AbstractTableModel;
16
17
18 /***
19 * Table Model for the main table showing training results
20 *
21 * @author Mag. Bernhard Hödl AH - Solutions Augsten & Hödl OEG Neubachgasse 12 A - 2325 Himberg
22 * Tabellenmodel und Daten für die dargestellte Tabelle für das HO Plungin
23 */
24 public class OutputTableModel extends AbstractTableModel {
25
26
27 /*** TODO Missing Parameter Documentation */
28 private static final String DEFAULT_VALUE = "";
29
30
31
32 private IHOMiniModel p_IHMM_HOMiniModel = null;
33
34
35 private Vector p_V_columnNames = null;
36
37
38 private Vector p_V_data = null;
39
40
41
42 /***
43 * Constructor
44 *
45 * @param p_IHMM_HOMiniModel
46 */
47 public OutputTableModel(IHOMiniModel p_IHMM_HOMiniModel) {
48 this.p_IHMM_HOMiniModel = p_IHMM_HOMiniModel;
49
50 p_V_data = p_IHMM_HOMiniModel.getAllSpieler();
51
52 p_V_columnNames = new Vector();
53
54
55 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Spieler")));
56 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Alter")));
57 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("BestePosition")));
58 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Torwart")));
59 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Verteidigung")));
60 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Spielaufbau")));
61 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Passpiel")));
62 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Fluegelspiel")));
63 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Torschuss")));
64 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Standards")));
65 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("Kondition")));
66 p_V_columnNames.add(new String(this.p_IHMM_HOMiniModel.getResource().getProperty("ID")));
67 }
68
69
70
71
72
73
74 public Class getColumnClass(int c) {
75 if ((c > 2) && (c < 11)) {
76 return JPanel.class;
77 }
78
79 return getValueAt(0, c).getClass();
80 }
81
82
83
84
85 public int getColumnCount() {
86 return p_V_columnNames.size();
87 }
88
89
90
91
92 public String getColumnName(int c) {
93 return (String) p_V_columnNames.get(c);
94 }
95
96
97
98
99 public int getRowCount() {
100 return p_V_data.size();
101 }
102
103 /***
104 * Returns as toolTip for the cell, the last skillup for the proper player and skill
105 *
106 * @param rowIndex
107 * @param columnIndex
108 *
109 * @return toolTip
110 */
111 public Object getToolTipAt(int rowIndex, int columnIndex) {
112 VerticalIndicator vi = (VerticalIndicator) getValueAt(rowIndex, columnIndex);
113
114 return vi.getToolTipText();
115 }
116
117
118
119
120 public Object getValueAt(int rowIndex, int columnIndex) {
121 try {
122 ISpieler spieler = (ISpieler) p_V_data.get(rowIndex);
123
124 switch (columnIndex) {
125 case 0:
126 return spieler.getName();
127
128 case 1:
129 return Integer.toString(spieler.getAlter());
130
131 case 2:
132 return p_IHMM_HOMiniModel.getHelper().getNameForPosition(spieler
133 .getIdealPosition())
134 + " (" + spieler.getIdealPosStaerke(true) + ")";
135
136
137 case 3:
138 return createIcon(spieler, ISpieler.SKILL_TORWART);
139
140 case 4:
141 return createIcon(spieler, ISpieler.SKILL_VERTEIDIGUNG);
142
143 case 5:
144 return createIcon(spieler, ISpieler.SKILL_SPIELAUFBAU);
145
146 case 6:
147 return createIcon(spieler, ISpieler.SKILL_PASSSPIEL);
148
149 case 7:
150 return createIcon(spieler, ISpieler.SKILL_FLUEGEL);
151
152 case 8:
153 return createIcon(spieler, ISpieler.SKILL_TORSCHUSS);
154
155 case 9:
156 return createIcon(spieler, ISpieler.SKILL_STANDARDS);
157
158 case 10:
159 return createIcon(spieler, ISpieler.SKILL_KONDITION);
160
161 case 11:
162 return Integer.toString(spieler.getSpielerID());
163
164 default:
165 return DEFAULT_VALUE;
166 }
167 } catch (Exception e) {
168 return DEFAULT_VALUE;
169 }
170 }
171
172 /***
173 * Refill the table with the new training based on the last changes
174 */
175 public void fillWithData() {
176 p_V_data = p_IHMM_HOMiniModel.getAllSpieler();
177 fireTableDataChanged();
178 }
179
180 /***
181 * Method that returns the offset in Training point
182 *
183 * @param player player to be considered
184 * @param skill skill trained
185 *
186 * @return training point offset, if any
187 */
188 private double getOffset(ISpieler player, int skill) {
189 int coTrainer = TrainingExperience.getStaffPanel().getCoTrainerNumber();
190 int keeperTrainer = TrainingExperience.getStaffPanel().getKeeperTrainerNumber();
191 int trainer = TrainingExperience.getStaffPanel().getTrainerLevelNumber();
192
193 double offset = player.getSubskill4SkillWithOffset(skill);
194 int length = player.getDauerTraining(Skills.getTrainedSkillCode(skill), coTrainer,
195 keeperTrainer, trainer, 100);
196
197 return offset * length;
198 }
199
200 /***
201 * Create a VerticalIndicator object
202 *
203 * @param spieler object from which create the indicator
204 * @param skillIndex points to skillup
205 *
206 * @return the VerticalIndicator object
207 */
208 private VerticalIndicator createIcon(ISpieler spieler, int skillIndex) {
209 double point = getOffset(spieler, skillIndex);
210 VerticalIndicator vi = new VerticalIndicator(p_IHMM_HOMiniModel.getHelper().round(point, 1),
211 spieler.getDauerTraining(Skills
212 .getTrainedSkillCode(skillIndex),
213 TrainingExperience.getStaffPanel()
214 .getCoTrainerNumber(),
215 TrainingExperience.getStaffPanel()
216 .getKeeperTrainerNumber(),
217 TrainingExperience.getStaffPanel()
218 .getTrainerLevelNumber(),
219 p_IHMM_HOMiniModel.getTeam()
220 .getTrainingslevel()));
221
222 return vi;
223 }
224 }