1
2 package hoplugins.transfers.ui;
3
4 import hoplugins.Commons;
5
6 import hoplugins.commons.ui.DefaultTableSorter;
7
8 import hoplugins.transfers.ui.model.TransferTableModel;
9 import hoplugins.transfers.vo.PlayerTransfer;
10
11 import java.awt.BorderLayout;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Vector;
16
17 import javax.swing.JPanel;
18 import javax.swing.JScrollPane;
19 import javax.swing.JTable;
20 import javax.swing.ListSelectionModel;
21 import javax.swing.event.ListSelectionEvent;
22 import javax.swing.event.ListSelectionListener;
23 import javax.swing.table.TableModel;
24
25
26 /***
27 * Pane to show transfers for your own team.
28 *
29 * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
30 */
31 public class TeamTransfersPane extends JPanel implements ListSelectionListener {
32
33
34 private JTable transferTable;
35 private List transfers = new ArrayList();
36 private PlayerDetailPanel playerDetailPanel;
37
38
39
40 /***
41 * Creates a new TeamTransfersPane object.
42 */
43 public TeamTransfersPane() {
44 super(new BorderLayout());
45
46 final JPanel mainPanel = Commons.getModel().getGUI().createImagePanel();
47 mainPanel.setLayout(new BorderLayout());
48 setOpaque(false);
49 add(mainPanel, BorderLayout.CENTER);
50
51 final TableModel model = new TransferTableModel(new ArrayList());
52 final TeamTransferSorter sorter = new TeamTransferSorter(model);
53 transferTable = new JTable(sorter);
54
55 sorter.setTableHeader(transferTable.getTableHeader());
56
57 final JScrollPane pane = new JScrollPane(transferTable);
58 pane.setOpaque(false);
59 mainPanel.add(pane, BorderLayout.CENTER);
60
61 refresh(new Vector());
62 }
63
64 /***
65 * Creates a new TeamTransfersPane object.
66 *
67 * @param playerDetailPanel TODO Missing Constructuor Parameter Documentation
68 */
69 public TeamTransfersPane(PlayerDetailPanel playerDetailPanel) {
70 this();
71 this.playerDetailPanel = playerDetailPanel;
72
73 transferTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
74 transferTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
75 transferTable.getSelectionModel().addListSelectionListener(this);
76 }
77
78
79
80 /***
81 * Refresh the information on the panel.
82 *
83 * @param transfers List of transfers to show.
84 */
85 public final void refresh(List transfers) {
86 this.transfers = transfers;
87
88 final DefaultTableSorter sorter = (DefaultTableSorter) transferTable.getModel();
89 sorter.setTableModel(new TransferTableModel(transfers));
90
91 transferTable.getColumnModel().getColumn(3).setPreferredWidth(150);
92 transferTable.getColumnModel().getColumn(4).setCellRenderer(new IconCellRenderer());
93 transferTable.getColumnModel().getColumn(4).setMaxWidth(20);
94 transferTable.getColumnModel().getColumn(5).setPreferredWidth(150);
95
96 transferTable.getColumnModel().getColumn(8).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.GREEN));
97 transferTable.getColumnModel().getColumn(8).setPreferredWidth(30);
98 transferTable.getColumnModel().getColumn(9).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.GREEN));
99 transferTable.getColumnModel().getColumn(9).setPreferredWidth(30);
100 transferTable.getColumnModel().getColumn(10).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.GREEN));
101 transferTable.getColumnModel().getColumn(10).setPreferredWidth(30);
102
103 transferTable.getColumnModel().getColumn(11).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
104 transferTable.getColumnModel().getColumn(11).setPreferredWidth(30);
105 transferTable.getColumnModel().getColumn(12).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
106 transferTable.getColumnModel().getColumn(12).setPreferredWidth(30);
107 transferTable.getColumnModel().getColumn(13).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
108 transferTable.getColumnModel().getColumn(13).setPreferredWidth(30);
109 transferTable.getColumnModel().getColumn(14).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
110 transferTable.getColumnModel().getColumn(14).setPreferredWidth(30);
111 transferTable.getColumnModel().getColumn(15).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
112 transferTable.getColumnModel().getColumn(15).setPreferredWidth(30);
113 transferTable.getColumnModel().getColumn(16).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
114 transferTable.getColumnModel().getColumn(16).setPreferredWidth(30);
115 transferTable.getColumnModel().getColumn(17).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
116 transferTable.getColumnModel().getColumn(17).setPreferredWidth(30);
117 transferTable.getColumnModel().getColumn(18).setCellRenderer(new ColorCellRenderer(ColorCellRenderer.YELLOW));
118 transferTable.getColumnModel().getColumn(18).setPreferredWidth(30);
119 }
120
121 /*** {@inheritDoc} */
122 public final void valueChanged(ListSelectionEvent e) {
123 if (!e.getValueIsAdjusting()) {
124 final DefaultTableSorter sorter = (DefaultTableSorter) transferTable.getModel();
125
126 if (transferTable.getSelectedRow() >= 0) {
127 final int index = sorter.modelIndex(transferTable.getSelectedRow());
128 final PlayerTransfer transfer = (PlayerTransfer) this.transfers.get(index);
129 this.playerDetailPanel.setPlayer(transfer.getPlayerId(), transfer.getPlayerName());
130 } else {
131 this.playerDetailPanel.clearPanel();
132 }
133 }
134 }
135 }