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.PluginProperty;
9
10 import hoplugins.trainingExperience.constants.Skills;
11 import hoplugins.trainingExperience.ui.renderer.SkillupTableRenderer;
12
13 import plugins.ISkillup;
14 import plugins.ISpieler;
15
16 import java.awt.BorderLayout;
17
18 import java.util.Arrays;
19 import java.util.Iterator;
20 import java.util.Vector;
21
22 import javax.swing.JLabel;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25
26
27 /***
28 * Panel of past skillups table ("Training History")
29 */
30 public class SkillupPanel extends JPanel {
31
32
33 private BaseTableModel tableModel;
34 private SkillupTable table;
35 private String[] columns = {
36 PluginProperty.getString("Type"),
37 PluginProperty.getString("Week"),
38 Commons.getModel().getResource().getProperty("Season"),
39 "", "", ""
40 };
41
42
43
44 /***
45 * Creates a new SkillupPanel object.
46 */
47 public SkillupPanel() {
48 jbInit();
49 }
50
51
52
53 /***
54 * Add a row to the table
55 *
56 * @param skillup The skillup object to be added
57 */
58 public void addRow(ISkillup skillup) {
59 Vector v = new Vector();
60
61 v.add(Skills.getSkillDescription(skillup.getType()) + ": "
62 + Commons.getModel().getHelper().getNameForSkill(skillup.getValue(), true));
63 v.add("" + skillup.getHtWeek());
64 v.add("" + skillup.getHtSeason());
65 v.add("" + skillup.getTrainType());
66 v.add("" + skillup.getDate());
67 v.add("" + skillup.getType());
68 tableModel.insertRow(0, v);
69 }
70
71 /***
72 * Populate the table
73 *
74 * @param player the selected training situation
75 */
76 public void reload(ISpieler player) {
77
78 tableModel = new BaseTableModel(new Vector(), new Vector(Arrays.asList(columns)));
79 table.setModel(tableModel);
80
81 if (player == null) {
82 return;
83 }
84
85
86 for (Iterator iter = TrainingExperience.getSkillupManager().getTrainedSkillups().iterator();
87 iter.hasNext();) {
88
89 addRow((ISkillup) iter.next());
90 }
91
92 setColumnWidth(1, 30);
93 setColumnWidth(2, 30);
94 setColumnWidth(3, 0);
95 setColumnWidth(4, 0);
96 setColumnWidth(5, 0);
97 table.getTableHeader().getColumnModel().getColumn(3).setMaxWidth(0);
98 table.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(0);
99 table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(0);
100 }
101
102 /***
103 * Resize the column
104 *
105 * @param col column to resize
106 * @param width new width
107 */
108 private void setColumnWidth(int col, int width) {
109 table.getTableHeader().getColumnModel().getColumn(col).setWidth(width);
110 table.getTableHeader().getColumnModel().getColumn(col).setPreferredWidth(width);
111 table.getTableHeader().getColumnModel().getColumn(col).setMaxWidth(200);
112 table.getTableHeader().getColumnModel().getColumn(col).setMinWidth(0);
113 }
114
115 /***
116 * Initialize the object layout
117 */
118 private void jbInit() {
119 Vector data = new Vector();
120
121 tableModel = new BaseTableModel(data, new Vector(Arrays.asList(columns)));
122 table = new SkillupTable(tableModel);
123 table.setDefaultRenderer(Object.class, new SkillupTableRenderer());
124
125 setColumnWidth(1, 30);
126 setColumnWidth(2, 30);
127 setColumnWidth(3, 0);
128 setColumnWidth(4, 0);
129 setColumnWidth(5, 0);
130 table.getTableHeader().getColumnModel().getColumn(3).setMaxWidth(0);
131 table.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(0);
132 table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(0);
133
134 JScrollPane scrollPane = new JScrollPane(table);
135
136 scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
137 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
138
139 JPanel headerPanel = Commons.getModel().getGUI().createImagePanel();
140
141 headerPanel.setOpaque(false);
142
143 JLabel l = new JLabel(PluginProperty.getString("TrainingHistory"), JLabel.CENTER);
144
145 l.setOpaque(false);
146 headerPanel.add(l, BorderLayout.CENTER);
147
148 setLayout(new BorderLayout());
149 add(headerPanel, BorderLayout.NORTH);
150 add(scrollPane, BorderLayout.CENTER);
151 }
152 }