-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisButtonPanel.java
More file actions
114 lines (93 loc) · 3.79 KB
/
AnalysisButtonPanel.java
File metadata and controls
114 lines (93 loc) · 3.79 KB
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
108
109
110
111
112
113
114
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class AnalysisButtonPanel implements GUI {
private static AnalysisButtonPanel panel;
private JButton showUserTotal;
private JButton showGroupTotal;
private JButton showMessagesTotal;
private JButton showPositivePercentage;
private JPanel analysisPanel;
//singleton so only one analysis panel exists
public static AnalysisButtonPanel panel() {
if (panel == null) {
panel = new AnalysisButtonPanel();
}
return panel;
}
public AnalysisButtonPanel() {
}
//initialize the panel
public void initialize() {
this.showUserTotal = new JButton("Total Users");
this.showGroupTotal = new JButton("Total Groups");
this.showMessagesTotal = new JButton("Total Messages");
this.showPositivePercentage = new JButton("Total Positivity");
this.analysisPanel = new JPanel();
formatPanel();
}
//format the panel
public void formatPanel() {
Border analysisBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE), "Analysis");
analysisPanel.setBorder(analysisBorder);
analysisPanel.setLayout(new GridLayout(2, 2));
analysisPanel.add(showUserTotal);
analysisPanel.add(showGroupTotal);
analysisPanel.add(showMessagesTotal);
analysisPanel.add(showPositivePercentage);
setUpButtonActions();
}
//get the show total users button
public JButton getShowTotalUsersButton() {
return showUserTotal;
}
//get the show total groups button
public JButton getShowTotalGroupsButton() {
return showGroupTotal;
}
//get the show total messages button
public JButton getShowMessagesTotalButton() {
return showMessagesTotal;
}
//get the show positive percentage button
public JButton getShowPositivePercentageButton() {
return showPositivePercentage;
}
//set up the button actions
public void setUpButtonActions() {
getShowTotalUsersButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int totalUsers = Admin.getAdmin().getTotalUsers();
AdminControlPanel.getFrame().showMessage("Total Users: " + totalUsers);
}
});
getShowTotalGroupsButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int totalGroups = Admin.getAdmin().getTotalGroups();
AdminControlPanel.getFrame().showMessage("Total Groups: " + totalGroups);
}
});
getShowMessagesTotalButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int totalMessages = Admin.getAdmin().getTotalMessages();
AdminControlPanel.getFrame().showMessage("Total Messages: " + totalMessages);
}
});
getShowPositivePercentageButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double positivePercentage = Admin.getAdmin().getPositivityPercentage();
AdminControlPanel.getFrame().showMessage("Positive Percentage: " + positivePercentage + "%");
}
});
}
//render the panel
public JPanel render() {
initialize();
return this.analysisPanel;
}
}