View Javadoc

1   // %1126721330760: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 java.awt.BorderLayout;
10  import java.awt.Color;
11  
12  import java.text.NumberFormat;
13  
14  import javax.swing.BorderFactory;
15  import javax.swing.JLabel;
16  import javax.swing.JPanel;
17  import javax.swing.SwingConstants;
18  
19  
20  /***
21   * Pane to show totals for transfers of your own team.
22   *
23   * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
24   */
25  public class TotalsPanel extends JPanel {
26      //~ Static fields/initializers -----------------------------------------------------------------
27  
28      private static final NumberFormat FORMAT = NumberFormat.getIntegerInstance();
29  
30      //~ Instance fields ----------------------------------------------------------------------------
31  
32      private JLabel buyAvgPrice = new JLabel("", SwingConstants.RIGHT); //$NON-NLS-1$
33      private JLabel buyTotPrice = new JLabel("", SwingConstants.RIGHT); //$NON-NLS-1$
34      private JLabel diffTotPrice = new JLabel("", SwingConstants.RIGHT); //$NON-NLS-1$
35      private JLabel sellAvgPrice = new JLabel("", SwingConstants.RIGHT); //$NON-NLS-1$
36      private JLabel sellTotPrice = new JLabel("", SwingConstants.RIGHT); //$NON-NLS-1$
37  
38      //~ Constructors -------------------------------------------------------------------------------
39  
40      /***
41       * Creates a TotalsPanel.
42       *
43       * @param title Name for the type of transfers.
44       */
45      public TotalsPanel(String title) {
46          this(title, "");
47      }
48  
49      /***
50       * Creates a TotalsPanel.
51       *
52       * @param titel Name for the type of transfers.
53       * @param currency Currency symbol
54       */
55      public TotalsPanel(String titel, String currency) {
56          super(new BorderLayout());
57  
58          FORMAT.setGroupingUsed(true);
59          FORMAT.setMaximumFractionDigits(0);
60  
61          final double[][] sizes = {
62                                 {10, 75, 20, 75, 20, 75, 10},
63                                 {20, 20, 20, 10, 20}
64                             };
65  
66          final JPanel panel = Commons.getModel().getGUI().createImagePanel();
67          panel.setOpaque(false);
68  
69          final TableLayout layout = new TableLayout(sizes);
70          panel.setLayout(layout);
71          panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY),
72                                                           titel));
73  
74          panel.add(new JLabel(PluginProperty.getString("Total"), SwingConstants.CENTER), "3, 0"); //$NON-NLS-1$ //$NON-NLS-2$
75          panel.add(new JLabel(Commons.getModel().getResource().getProperty("Durchschnitt"),
76                               SwingConstants.CENTER), "5, 0"); //$NON-NLS-1$ //$NON-NLS-2$
77  
78          panel.add(new JLabel(PluginProperty.getString("Purchases"), SwingConstants.LEFT), "1, 1"); //$NON-NLS-1$ //$NON-NLS-2$
79          panel.add(new JLabel(currency, SwingConstants.RIGHT), "2, 1"); //$NON-NLS-1$
80          panel.add(buyTotPrice, "3, 1"); //$NON-NLS-1$
81          panel.add(new JLabel(currency, SwingConstants.RIGHT), "4, 1"); //$NON-NLS-1$
82          panel.add(buyAvgPrice, "5, 1"); //$NON-NLS-1$
83  
84          panel.add(new JLabel(PluginProperty.getString("Sales"), SwingConstants.LEFT), "1, 2"); //$NON-NLS-1$ //$NON-NLS-2$
85          panel.add(new JLabel(currency, SwingConstants.RIGHT), "2, 2"); //$NON-NLS-1$
86          panel.add(sellTotPrice, "3, 2"); //$NON-NLS-1$
87          panel.add(new JLabel(currency, SwingConstants.RIGHT), "4, 2"); //$NON-NLS-1$
88          panel.add(sellAvgPrice, "5, 2"); //$NON-NLS-1$
89  
90          panel.add(new JLabel(PluginProperty.getString("Difference"), SwingConstants.LEFT), "1, 4"); //$NON-NLS-1$ //$NON-NLS-2$
91          panel.add(new JLabel(currency, SwingConstants.RIGHT), "2, 4"); //$NON-NLS-1$
92          panel.add(diffTotPrice, "3, 4"); //$NON-NLS-1$
93  
94          add(panel, BorderLayout.CENTER);
95          setOpaque(false);
96      }
97  
98      //~ Methods ------------------------------------------------------------------------------------
99  
100     /***
101      * Sets the total values.
102      *
103      * @param buyTot Total value for BUY transfers.
104      * @param buyAvg Average value for BUY transfers.
105      * @param sellTot Total value for SELL transfers.
106      * @param sellAvg Average value for SELL transfers.
107      */
108     public final void setValues(int buyTot, double buyAvg, int sellTot, double sellAvg) {
109         buyTotPrice.setText(FORMAT.format(buyTot));
110         buyAvgPrice.setText(FORMAT.format(buyAvg));
111         sellTotPrice.setText(FORMAT.format(sellTot));
112         sellAvgPrice.setText(FORMAT.format(sellAvg));
113 
114         final int diffTot = sellTot - buyTot;
115         diffTotPrice.setText(FORMAT.format(diffTot));
116     }
117 }