-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatDisplay.java
More file actions
196 lines (173 loc) · 8.1 KB
/
StatDisplay.java
File metadata and controls
196 lines (173 loc) · 8.1 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
public class StatDisplay {
private int StatDisplayType;
static private JLabel Title = new JLabel(" ");
static private JLabel GamesPlayed = new JLabel("Games Played: ");
static private JLabel CurrentStreak = new JLabel("Current Streak: ");
static private JLabel MaxStreak = new JLabel("Max Streak: ");
static private JLabel WinPercentHeader = new JLabel("Win Percent ");
static private JProgressBar WinPercent = new JProgressBar();
static private JLabel GuessDistributionHeader = new JLabel("Guess Distribution ");
static private JLabel[] GuessDistributionLabels = new JLabel[6];
static private JProgressBar[] GuessDistributions = new JProgressBar[6];
static private JLabel HistoryHeader = new JLabel("History ");
static private DefaultTableModel HistoryModel = new DefaultTableModel();
static private JTable History = new JTable(HistoryModel);
static private String data[][];
private String StringType;
static private final int DAILY_MODE = FrameGui.DAILY_MODE;
static private final int PRACTICE_MODE = FrameGui.PRACTICE_MODE;
static private final Color STATS_PANEL_COLOR = new Color(205, 200, 200);
static private final Color HISTORY_COLOR_WIN = new Color(180, 245, 177);
static private final Color HISTORY_COLOR_LOSS = new Color(241, 176, 176);
public StatDisplay(int type) {
StatDisplayType = type;
if (type == DAILY_MODE) {
StringType = "Daily";
}
else {
StringType = "Practice";
}
}
public static void createStatPanel() {
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridy++;
c.ipady = 15;
FrameGui.StatDisplayPanel.add(Title, c);
c.gridy++;
FrameGui.StatDisplayPanel.add(new JLabel(" "), c);
c.gridy++;
c.ipady = 20;
FrameGui.StatDisplayPanel.add(GamesPlayed, c);
c.gridy++;
FrameGui.StatDisplayPanel.add(CurrentStreak, c);
c.gridy++;
FrameGui.StatDisplayPanel.add(MaxStreak, c);
c.ipady = 15;
c.gridy++;
FrameGui.StatDisplayPanel.add(new JLabel(" "), c);
c.gridy++;
FrameGui.StatDisplayPanel.add(WinPercentHeader, c);
c.gridy++;
c.ipady = 10;
FrameGui.StatDisplayPanel.add(WinPercent, c);
WinPercent.setValue(0);
WinPercent.setStringPainted(true);
c.ipady = 15;
c.gridy++;
FrameGui.StatDisplayPanel.add(new JLabel(" "), c);
c.gridy++;
FrameGui.StatDisplayPanel.add(GuessDistributionHeader, c);
c.gridy++;
newGuessDistributions();
c.ipady = 10;
c.gridwidth = GridBagConstraints.RELATIVE;
for(int i = 0; i < GuessDistributionLabels.length; i++) {
FrameGui.StatDisplayPanel.add(GuessDistributionLabels[i], c);
GuessDistributionLabels[i].setFont(GuessDistributionLabels[i].getFont().deriveFont(Font.BOLD, 16));
GuessDistributionLabels[i].setText((i+1)+": ");
FrameGui.StatDisplayPanel.add(GuessDistributions[i], c);
GuessDistributions[i].setValue(0);
GuessDistributions[i].setStringPainted(true);
c.gridy++;
}
c.gridwidth = GridBagConstraints.REMAINDER;
c.ipady = 15;
FrameGui.StatDisplayPanel.add(new JLabel(" "), c);
c.gridy++;
FrameGui.StatDisplayPanel.add(HistoryHeader, c);
c.gridy++;
FrameGui.StatDisplayPanel.add(History, c);
Title.setFont(Title.getFont().deriveFont(Font.BOLD, 18));
GamesPlayed.setFont(GamesPlayed.getFont().deriveFont(Font.BOLD, 14));
CurrentStreak.setFont(CurrentStreak.getFont().deriveFont(Font.BOLD, 14));
MaxStreak.setFont(MaxStreak.getFont().deriveFont(Font.BOLD, 14));
WinPercentHeader.setFont(WinPercentHeader.getFont().deriveFont(Font.BOLD, 16));
GuessDistributionHeader.setFont(GuessDistributionHeader.getFont().deriveFont(Font.BOLD, 16));
HistoryHeader.setFont(HistoryHeader.getFont().deriveFont(Font.BOLD, 16));
FrameGui.StatDisplayPanel.setBackground(STATS_PANEL_COLOR);
FrameGui.StatDisplayScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
FrameGui.StatDisplayScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
FrameGui.StatDisplayScroll.getVerticalScrollBar().setUnitIncrement(8);
FrameGui.Frame.add(FrameGui.StatDisplayScroll);
FrameGui.StatDisplayScroll.setVisible(false);
}
public void openStatDisplay() {
Title.setText(StringType+" Mode Statistics");
HistoryModel.setRowCount(0);
HistoryModel.setColumnCount(0);
FrameGui.StatDisplayScroll.setVisible(true);
data = FrameGui.File.openStats(StatDisplayType);
int numGames = FrameGui.File.getNumGames();
GamesPlayed.setText("Games Played: "+numGames);
CurrentStreak.setText("Current Streak: "+FrameGui.File.getCurrentStreak());
MaxStreak.setText("Max Streak: "+FrameGui.File.getMaxStreak());
WinPercent.setValue((int)Math.round((double)FrameGui.File.getNumWins()/numGames*100));
for(int i = 0; i < GuessDistributions.length; i++) {
GuessDistributions[i].setValue((int)Math.round((double)FrameGui.File.getAttemptsNum(i+1)/numGames*100));
}
History.setEnabled(false);
String column[] = {"#","Word", "Attempts", "Result", "Date", "Time"};
HistoryModel.addColumn(column[0]);
HistoryModel.addColumn(column[1]);
HistoryModel.addColumn(column[2]);
HistoryModel.addColumn(column[3]);
HistoryModel.addColumn(column[4]);
HistoryModel.addColumn(column[5]);
HistoryModel.addRow(column);
if (data == null)
return;
for(int i = data.length-1; i >= 0; i--) {
String numElement = String.valueOf((Integer.valueOf(data[i][4])+1));
String resultText = (data[i][3].equals("W")) ? "Win" : "Loss";
HistoryModel.addRow(
new String[] {
numElement,
data[i][1],
data[i][2],
resultText,
data[i][0].substring(0,10),
data[i][0].substring(10)
});
History.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (row!=0) {
c.setBackground(table.getValueAt(row, 3).equals("Win") ? HISTORY_COLOR_WIN : HISTORY_COLOR_LOSS);
}
return c;
}
});
}
}
public static void closeStatDisplay() {
FrameGui.StatDisplayScroll.setVisible(false);
HistoryModel.setRowCount(0);
HistoryModel.setColumnCount(0);
}
private static void newGuessDistributions() {
for(int i = 0; i < GuessDistributionLabels.length; i++){
GuessDistributionLabels[i] = new JLabel();
}
for(int i = 0; i < GuessDistributions.length; i++){
GuessDistributions[i] = new JProgressBar();
}
}
public static int getScrollPosition() {
return FrameGui.StatDisplayScroll.getVerticalScrollBar().getValue();
}
public static void setScrollPosition(int scrollPosition) {
FrameGui.StatDisplayScroll.getVerticalScrollBar().setValue(scrollPosition);
}
public static void updateScreen() {
int PanelX = FrameGui.width/5;
int PanelY = FrameGui.height/8;
int PanelWidth = FrameGui.width-(2*PanelX);
int PanelHeight = FrameGui.height-(2*PanelY);
FrameGui.StatDisplayScroll.setBounds(PanelX, PanelY, PanelWidth, PanelHeight);
}
}