-
Notifications
You must be signed in to change notification settings - Fork 0
/
DashboardPanel.java
107 lines (86 loc) · 4.33 KB
/
DashboardPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @version 1.0.0, 8 May 2023
* @author Andrew Kim and Dylan Nguyen
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class DashboardPanel extends JPanel {
public DashboardPanel() {
super();
setBackground(new Color(255, 255, 255));
}
public void reload() {
removeAll();
revalidate();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
Border border = BorderFactory.createLineBorder(Color.BLACK);
// top panel
JPanel overviewPanel = new JPanel();
overviewPanel.setLayout(new GridLayout(0, 1));
overviewPanel.setPreferredSize(new Dimension(10000, Options.getFont().getSize() * 7));
overviewPanel.add(
new ScaledLabel("Overview - " + Portfolio.getSystemName(), (int) (Options.getFont().getSize() * 1.5)));
overviewPanel.add(new ScaledLabel("Your balance is: $ " + Portfolio.getBalance()));
overviewPanel.add(new ScaledLabel("Your net worth is: $ " + Portfolio.getTotalNetworth()));
overviewPanel
.add(new ScaledLabel("Your total profit is: $ " + Stock.round(Portfolio.getTotalNetworth() - 10000)));
overviewPanel.add(new ScaledLabel(
"Intra-day update count: " + Broker.getStock("AAPL").getPriceHistory().getDayHistory().size() + "/30"));
overviewPanel.add(new ScaledLabel("Date: " + Broker.getDate()));
overviewPanel.setBorder(border);
overviewPanel.setMaximumSize(new Dimension(10000, Options.getFont().getSize() * 10));
add(overviewPanel);
// bottom panel
JPanel stocksOverviewPanel = new JPanel();
stocksOverviewPanel.setLayout(new BoxLayout(stocksOverviewPanel, BoxLayout.PAGE_AXIS));
stocksOverviewPanel.add(new ScaledLabel("Assets", (int) (Options.getFont().getSize() * 1.5)));
stocksOverviewPanel.setBorder(border);
JPanel stocksHeaderLabel = new JPanel();
stocksHeaderLabel.setLayout(new GridLayout(0, 7));
stocksHeaderLabel.setMaximumSize(new Dimension(10000, Options.getFont().getSize()));
stocksHeaderLabel.add(new ScaledLabel("Stock"));
stocksHeaderLabel.add(new ScaledLabel("Shares"));
stocksHeaderLabel.add(new ScaledLabel("Cost"));
stocksHeaderLabel.add(new ScaledLabel("Price"));
stocksHeaderLabel.add(new ScaledLabel("Day Change"));
stocksHeaderLabel.add(new ScaledLabel("Total Invested"));
stocksHeaderLabel.add(new ScaledLabel("% of Portfolio"));
stocksOverviewPanel.add(stocksHeaderLabel);
// metrics for owned stocks
for (String ticker : Portfolio.getOwnedStocks().keySet()) {
if (Portfolio.getOwnedStocks().get(ticker) == 0)
continue;
JPanel row = new JPanel();
row.setLayout(new GridLayout(0, 7));
row.setMaximumSize(new Dimension(10000, Options.getFont().getSize()));
// ticker ot stock
row.add(new ScaledLabel(ticker));
// number of shares owned
row.add(new ScaledLabel("" + Portfolio.getOwnedStocks().get(ticker)));
// average amount spent on stock
row.add(new ScaledLabel("$" + Portfolio.averageSpentOnStock(ticker)));
// current stock price
row.add(new ScaledLabel("$" + Broker.getStock(ticker).getTransactionPrice()));
// change in stock price
row.add(new ScaledLabel(Broker.getStock(ticker).getDayChangeFormatted()));
// total value invested in stock
double totalValue = Portfolio.getOwnedStocks().get(ticker) * Broker.getStock(ticker).getTransactionPrice();
row.add(new ScaledLabel("$" + Stock.round(totalValue)));
// percent of portfolio
row.add(new ScaledLabel(100 * Stock.round(totalValue / Portfolio.getTotalNetworth()) + "%"));
stocksOverviewPanel.add(row);
}
if (Portfolio.getOwnedStocks().keySet().size() == 0) {
JPanel row = new JPanel();
row.add(new ScaledLabel("No stocks owned"));
stocksOverviewPanel.add(row);
}
stocksOverviewPanel.setMaximumSize(new Dimension(10000, 10000));
add(stocksOverviewPanel);
}
}