1
2
3
4
5
6
7 package hoplugins.teamAnalyzer.ui;
8
9 import hoplugins.Commons;
10
11 import hoplugins.commons.utils.PluginProperty;
12
13 import hoplugins.teamAnalyzer.SystemManager;
14 import hoplugins.teamAnalyzer.ht.CHPPManager;
15 import hoplugins.teamAnalyzer.manager.MatchManager;
16 import hoplugins.teamAnalyzer.ui.model.UiFilterTableModel;
17 import hoplugins.teamAnalyzer.util.MatchUtil;
18 import hoplugins.teamAnalyzer.vo.Match;
19
20 import java.awt.BorderLayout;
21 import java.awt.event.MouseAdapter;
22 import java.awt.event.MouseEvent;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Vector;
29
30 import javax.swing.JPanel;
31 import javax.swing.JScrollPane;
32 import javax.swing.JTable;
33 import javax.swing.table.DefaultTableModel;
34
35
36 /***
37 * TODO Missing Class Documentation
38 *
39 * @author TODO Author Name
40 */
41 public class ManualFilterPanel extends JPanel {
42
43
44 /*** TODO Missing Parameter Documentation */
45 private static final Vector COLUMN_NAMES = new Vector(Arrays.asList(new Object[]{
46 "",
47 PluginProperty
48 .getString("RecapPanel.Game"),
49 PluginProperty
50 .getString("Type"),
51 PluginProperty
52 .getString("RecapPanel.Result"),
53 PluginProperty
54 .getString("Week"),
55 Commons.getModel()
56 .getResource()
57 .getProperty("Season"),
58 "", ""
59 }));
60
61
62
63 /*** TODO Missing Parameter Documentation */
64 List availableMatches = new ArrayList();
65 private DefaultTableModel tableModel;
66 private JTable table;
67
68
69
70 /***
71 * Creates a new instance of ManualFilterPanel
72 */
73 public ManualFilterPanel() {
74 jbInit();
75 }
76
77
78
79 /***
80 * TODO Missing Method Documentation
81 */
82 public void reload() {
83 tableModel = new UiFilterTableModel(new Vector(), COLUMN_NAMES);
84 table.setModel(tableModel);
85 availableMatches = MatchManager.getAllMatches();
86
87 Vector rowData;
88
89 for (Iterator iter = availableMatches.iterator(); iter.hasNext();) {
90 List matchIds = new ArrayList();
91 Match element = (Match) iter.next();
92
93 rowData = new Vector();
94
95 boolean isAvailable = Commons.getModel().getHelper().existsMatchInDB(element.getMatchId());
96 boolean isSelected = SystemManager.getFilter().getMatches().contains(""
97 + element
98 .getMatchId());
99
100 rowData.add(Boolean.valueOf(isSelected));
101
102 if (MatchUtil.isHome(element)) {
103 rowData.add(element.getAwayTeam());
104 rowData.add(Commons.getModel().getHelper().getImageIcon4Spieltyp(element
105 .getMatchType()));
106 rowData.add(element.getHomeGoals() + " - " + element.getAwayGoals());
107 } else {
108 rowData.add("*" + element.getHomeTeam());
109 rowData.add(Commons.getModel().getHelper().getImageIcon4Spieltyp(element
110 .getMatchType()));
111 rowData.add(element.getAwayGoals() + " - " + element.getHomeGoals());
112 }
113
114 rowData.add(element.getWeek() + "");
115 rowData.add(element.getSeason() + "");
116
117 if ((CHPPManager.isDownloadAllowed(element)) || isAvailable) {
118 rowData.add("true");
119 matchIds.add("");
120 } else {
121 rowData.add("false");
122 matchIds.add(element);
123 }
124
125 rowData.add("" + element.getMatchType());
126 tableModel.addRow(rowData);
127 }
128
129 addTableListener();
130
131 table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(20);
132 table.getTableHeader().getColumnModel().getColumn(0).setPreferredWidth(20);
133 table.getTableHeader().getColumnModel().getColumn(1).setPreferredWidth(90);
134 table.getTableHeader().getColumnModel().getColumn(2).setPreferredWidth(20);
135 table.getTableHeader().getColumnModel().getColumn(3).setPreferredWidth(40);
136 table.getTableHeader().getColumnModel().getColumn(4).setPreferredWidth(40);
137 table.getTableHeader().getColumnModel().getColumn(5).setPreferredWidth(40);
138 table.getTableHeader().getColumnModel().getColumn(6).setMaxWidth(0);
139 table.getTableHeader().getColumnModel().getColumn(6).setMinWidth(0);
140 table.getTableHeader().getColumnModel().getColumn(6).setPreferredWidth(0);
141 table.getTableHeader().getColumnModel().getColumn(6).setWidth(0);
142 table.getTableHeader().getColumnModel().getColumn(7).setMaxWidth(0);
143 table.getTableHeader().getColumnModel().getColumn(7).setMinWidth(0);
144 table.getTableHeader().getColumnModel().getColumn(7).setPreferredWidth(0);
145 table.getTableHeader().getColumnModel().getColumn(7).setWidth(0);
146 }
147
148 /***
149 * TODO Missing Method Documentation
150 */
151 protected void setFilter() {
152 List list = new ArrayList();
153 int i = 0;
154
155 for (Iterator iter = availableMatches.iterator(); iter.hasNext();) {
156 Match element = (Match) iter.next();
157 boolean isSelected = ((Boolean) tableModel.getValueAt(i, 0)).booleanValue();
158 boolean isAvailable = Boolean.valueOf((String) tableModel.getValueAt(i, 6))
159 .booleanValue();
160
161 if (isSelected && isAvailable) {
162 list.add("" + element.getMatchId());
163 }
164
165 i++;
166 }
167
168 SystemManager.getFilter().setMatches(list);
169 }
170
171 /***
172 * TODO Missing Method Documentation
173 */
174 private void addTableListener() {
175 table.addMouseListener(new MouseAdapter() {
176 public void mouseReleased(MouseEvent e) {
177 if (e.getClickCount() == 2) {
178 boolean downloadDone = false;
179 int row = table.getSelectedRow();
180 String status = (String) tableModel.getValueAt(row, 6);
181
182 if (!status.equalsIgnoreCase("true")) {
183 int id = ((Match) availableMatches.get(row)).getMatchId();
184
185 downloadDone = Commons.getModel().getHelper().downloadMatchData(id);
186 }
187
188 e.consume();
189
190 if (downloadDone) {
191 tableModel.setValueAt("true", row, 6);
192 }
193
194 updateUI();
195 }
196 }
197 });
198 }
199
200 /***
201 * TODO Missing Method Documentation
202 */
203 private void jbInit() {
204 JPanel main = Commons.getModel().getGUI().createImagePanel();
205
206 main.setLayout(new BorderLayout());
207 setLayout(new BorderLayout());
208 setOpaque(false);
209
210 Vector data = new Vector();
211
212 tableModel = new UiFilterTableModel(data, COLUMN_NAMES);
213 table = new JTable(tableModel);
214 table.setDefaultRenderer(Object.class, new ManualFilterTableRenderer());
215
216 JScrollPane pane = new JScrollPane(table);
217
218 main.add(pane, BorderLayout.CENTER);
219 add(main);
220 }
221 }