View Javadoc

1   // %1126721330323:hoplugins.transfers.ui%
2   package hoplugins.transfers.ui;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.ui.info.clearthought.layout.TableLayout;
7   import hoplugins.commons.utils.PluginProperty;
8   
9   import hoplugins.transfers.dao.DividerDAO;
10  import hoplugins.transfers.dao.TransfersDAO;
11  import hoplugins.transfers.ui.controller.DividerListener;
12  import hoplugins.transfers.vo.TransferTotals;
13  
14  import java.awt.BorderLayout;
15  
16  import java.util.List;
17  
18  import javax.swing.BorderFactory;
19  import javax.swing.ButtonGroup;
20  import javax.swing.ButtonModel;
21  import javax.swing.JLabel;
22  import javax.swing.JPanel;
23  import javax.swing.JRadioButton;
24  import javax.swing.JScrollPane;
25  import javax.swing.JSeparator;
26  import javax.swing.JSpinner;
27  import javax.swing.JSplitPane;
28  import javax.swing.SpinnerNumberModel;
29  import javax.swing.SwingConstants;
30  import javax.swing.event.ChangeEvent;
31  import javax.swing.event.ChangeListener;
32  
33  
34  /***
35   * Pane to show transfer histry information for your own team.
36   *
37   * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
38   */
39  public class HistoryPane extends JSplitPane {
40      //~ Instance fields ----------------------------------------------------------------------------
41  
42      private ButtonModel spinSeason;
43      private JLabel amountTransfers = new JLabel("", SwingConstants.RIGHT);
44      private JLabel amountTransfersIn = new JLabel("", SwingConstants.RIGHT);
45      private JLabel amountTransfersOut = new JLabel("", SwingConstants.RIGHT);
46      private JSpinner spinner = new JSpinner();
47      private List transfers;
48      private PlayerDetailPanel playerDetailPanel = new PlayerDetailPanel();
49      private TeamTransfersPane transferPane;
50      private TotalsPanel pricePanel;
51      private TotalsPanel tsiPanel;
52  
53      //~ Constructors -------------------------------------------------------------------------------
54  
55      /***
56       * Creates an instance of the HistoryPane
57       */
58      public HistoryPane() {
59          super(JSplitPane.VERTICAL_SPLIT);
60  
61          // Create side panel
62          final double[][] sizes = {
63                                 {TableLayout.PREFERRED, TableLayout.FILL},
64                                 {
65                                     TableLayout.PREFERRED, 10, TableLayout.PREFERRED,
66                                     TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED,
67                                     TableLayout.PREFERRED
68                                 }
69                             };
70          final JPanel sidePanel = Commons.getModel().getGUI().createImagePanel();
71          sidePanel.setLayout(new TableLayout(sizes));
72          sidePanel.setOpaque(false);
73  
74          final JPanel filterPanel = Commons.getModel().getGUI().createImagePanel();
75          filterPanel.setLayout(new TableLayout(new double[][]{
76                                                    {
77                                                        10, TableLayout.PREFERRED, 50,
78                                                        TableLayout.FILL, 10
79                                                    },
80                                                    {10, TableLayout.PREFERRED, TableLayout.PREFERRED}
81                                                }));
82  
83          final JRadioButton rb1 = new JRadioButton(PluginProperty.getString("AllSeason")); //$NON-NLS-1$
84          rb1.setFocusable(false);
85          rb1.setOpaque(false);
86  
87          final JRadioButton rb2 = new JRadioButton(Commons.getModel().getResource().getProperty("Season")); //$NON-NLS-1$
88          spinSeason = rb2.getModel();
89          rb2.setFocusable(false);
90          rb2.setOpaque(false);
91  
92          if (Commons.getModel().getBasics().getSeason() > 0) {
93              spinner.setModel(new SpinnerNumberModel(Commons.getModel().getBasics().getSeason(), 1,
94                                                      Commons.getModel().getBasics().getSeason(), 1));
95          } else {
96              rb2.setEnabled(false);
97              spinner.setModel(new SpinnerNumberModel());
98          }
99  
100         spinner.setFocusable(false);
101         spinner.setEnabled(false);
102         spinner.addChangeListener(new ChangeListener() {
103                 public void stateChanged(ChangeEvent e) {
104                     refresh();
105                 }
106             });
107 
108         rb1.setSelected(true);
109         rb1.addChangeListener(new ChangeListener() {
110                 public void stateChanged(ChangeEvent e) {
111                     spinner.setEnabled(false);
112                     refresh();
113                 }
114             });
115         rb2.addChangeListener(new ChangeListener() {
116                 public void stateChanged(ChangeEvent e) {
117                     spinner.setEnabled(true);
118                     refresh();
119                 }
120             });
121 
122         filterPanel.add(rb1, "1, 1, 2, 1"); //$NON-NLS-1$
123         filterPanel.add(rb2, "1, 2"); //$NON-NLS-1$
124         filterPanel.add(spinner, "2, 2"); //$NON-NLS-1$
125 
126         final ButtonGroup bg = new ButtonGroup();
127         bg.add(rb1);
128         bg.add(rb2);
129 
130         final JPanel amountPanel = Commons.getModel().getGUI().createImagePanel();
131         amountPanel.setLayout(new TableLayout(new double[][]{
132                                                   {.25, 75, 25, .5, 75, 25, .25},
133                                                   {10, 20, 20}
134                                               }));
135 
136         final JLabel amTrans = new JLabel(PluginProperty.getString("Transfers") + ":", SwingConstants.LEFT);
137         final JLabel amTransIn = new JLabel(PluginProperty.getString("In") + ":", SwingConstants.LEFT);
138         amTransIn.setIcon(Icon.IN);
139 
140         final JLabel amTransOut = new JLabel(PluginProperty.getString("Out") + ":", SwingConstants.LEFT);
141         amTransOut.setIcon(Icon.OUT);
142         amountPanel.add(amTrans, "1, 1");
143         amountPanel.add(amountTransfers, "2, 1");
144         amountPanel.add(amTransIn, "4, 1");
145         amountPanel.add(amountTransfersIn, "5, 1");
146         amountPanel.add(amTransOut, "4, 2");
147         amountPanel.add(amountTransfersOut, "5, 2");
148 
149         pricePanel = new TotalsPanel(PluginProperty.getString("Price"),
150                                      Commons.getModel().getXtraDaten().getCurrencyName()); //$NON-NLS-1$
151         tsiPanel = new TotalsPanel(PluginProperty.getString("TSI")); //$NON-NLS-1$
152 
153         sidePanel.add(filterPanel, "0, 0");
154         sidePanel.add(new JSeparator(), "0, 2");
155         sidePanel.add(amountPanel, "0, 4");
156         sidePanel.add(pricePanel, "0, 5");
157         sidePanel.add(tsiPanel, "0, 6");
158 
159         final JScrollPane sidePane = new JScrollPane(sidePanel);
160         sidePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
161         sidePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
162         sidePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
163 
164         // Create the top panel and add it to the split pane
165         final JPanel topPanel = Commons.getModel().getGUI().createImagePanel();
166         topPanel.setLayout(new BorderLayout());
167 
168         transferPane = new TeamTransfersPane(playerDetailPanel);
169 
170         topPanel.add(transferPane, BorderLayout.CENTER);
171         topPanel.add(sidePane, BorderLayout.WEST);
172 
173         setDividerLocation(DividerDAO.getDividerPosition("HistoryTabDivider")); //$NON-NLS-1$
174         addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
175                                   new DividerListener("HistoryTabDivider")); //$NON-NLS-1$
176 
177         setLeftComponent(topPanel);
178         setRightComponent(playerDetailPanel);
179 
180         refresh();
181     }
182 
183     //~ Methods ------------------------------------------------------------------------------------
184 
185     /***
186      * Refresh the displayed information.
187      */
188     public final void refresh() {
189         if (spinSeason.isSelected()) {
190             final SpinnerNumberModel model = (SpinnerNumberModel) this.spinner.getModel();
191             this.transfers = TransfersDAO.getTransfers(model.getNumber().intValue(), true, true);
192         } else {
193             this.transfers = TransfersDAO.getTransfers(0, true, true);
194         }
195 
196         final TransferTotals totals = TransferTotals.calculateTotals(transfers);
197         pricePanel.setValues(totals.getBuyPriceTotal(), totals.getBuyPriceAvg(),
198                              totals.getSellPriceTotal(), totals.getSellPriceAvg());
199         amountTransfers.setText(Integer.toString(totals.getAmountSell() + totals.getAmountBuy()));
200         amountTransfersIn.setText(Integer.toString(totals.getAmountBuy()));
201         amountTransfersOut.setText(Integer.toString(totals.getAmountSell()));
202         tsiPanel.setValues(totals.getBuyTsiTotal(), totals.getBuyTsiAvg(),
203                            totals.getSellTsiTotal(), totals.getSellTsiAvg());
204         pricePanel.revalidate();
205 
206         transferPane.refresh(this.transfers);
207     }
208 }