-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestResultLayout.java
284 lines (242 loc) · 9.38 KB
/
TestResultLayout.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//Displays results from various test types
//calculates scores and disiplays correct answers
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Map.Entry;
import java.awt.GridLayout;
import javax.swing.border.LineBorder;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class TestResultLayout extends GUI_Page
{
private static int SCORE_WIDTH = 250;
private static int SCORE_HEIGHT = 30;
public static int TEST_RESULT_WIDTH = 300;
public static int TEST_RESULT_HEIGHT = 500;
private static int QUES_LABEL_WIDTH = 250;
private static int RES_LABEL_WIDTH = 300;
private static int RES_LABEL_HEIGHT = 100;
private int printButtonWidth = 100;
private int defaultTextSize = 22;
private int scoreTextSize = 36;
public static TestType testType;
private String pipImagePath = "pip_image.png";
public void activate()
{
GUI.addComponent( new HomeButton() );
ActionButton printbtn = new ActionButton("Print");
//TODO: printbtn.addIcon("add print image path");
printbtn.setLocation( GUI.SCREEN_WIDTH - (printButtonWidth + HomeButton.home_btn_size + GUI.BUFFER_SIZE_LG*3), GUI.BUFFER_SIZE );
printbtn.setSize(printButtonWidth, HomeButton.home_btn_size);
printbtn.addMouseListener( new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
try
{
Robot robot = new Robot();
String format = ".png";
String fileName = "tuwe_sc" + new java.util.Date() + format;
Rectangle screenRect = GUI.root.getBounds();//new Rectangle(5,5,GUI.SCREEN_WIDTH-5, GUI.SCREEN_HEIGHT-5);
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, format, new File(fileName));
System.out.println("Screenshot captured");
new Thread(new PrintActionListener(screenFullImage)).start();
} catch (AWTException | IOException ex) {
System.err.println(ex);
}
}
} );
GUI.addComponent(printbtn);
JPanel mainContainer = new JPanel();
mainContainer.setLocation( GUI.BUFFER_SIZE_LG, GUI.BUFFER_SIZE_LG*2 );
mainContainer.setSize( GUI.SCREEN_WIDTH - GUI.BUFFER_SIZE_LG*3, GUI.SCREEN_HEIGHT - GUI.BUFFER_SIZE_LG*4 );
mainContainer.setBackground( Color.black );
GridLayout mainLayout = new GridLayout(1,3);
mainLayout.setHgap( GUI.BUFFER_SIZE_LG );
mainContainer.setLayout( mainLayout );
GUI.addComponent( mainContainer );
//******************** Score Panel - Start - ****************************************//
JPanel scoreContainer = new JPanel();
scoreContainer.setLayout( new BoxLayout(scoreContainer, BoxLayout.Y_AXIS ));
scoreContainer.setBorder( new LineBorder(Color.LIGHT_GRAY, 2) );
scoreContainer.setBackground( Color.black );
//add empty rigidbody as blank filler
scoreContainer.add( Box.createRigidArea(new Dimension(0,GUI.BUFFER_SIZE_LG)) );
JLabel header = makeLabel( "YOU DID GREAT!!", "Calibri", defaultTextSize);
header.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( header );
//add empty rigidbody as blank filler
scoreContainer.add( Box.createRigidArea(new Dimension(0,GUI.BUFFER_SIZE_LG)) );
JLabel rewardGraphic = new JLabel( Resource_Manager.getRandomRewardImage());//"Add Reward Graphic");
rewardGraphic.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( rewardGraphic );
//add empty rigidbody as blank filler
scoreContainer.add( Box.createRigidArea(new Dimension(0,GUI.BUFFER_SIZE_LG)) );
JLabel topic = makeLabel(Module.getActiveModule().topic + ":", "Verdana", 22);
topic.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( topic );
JLabel subTopic = makeLabel(Module.getActiveModule().subTopic, "Verdana", 22);
subTopic.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( subTopic );
//add empty rigidbody as blank filler
scoreContainer.add( Box.createRigidArea(new Dimension(0,GUI.BUFFER_SIZE_LG)) );
JLabel scoreText = makeLabel("Score: ", "Calibri", 36);
scoreText.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( scoreText );
int score = 0;
if(testType == TestType.MULTI)
{
score = TestHelper.currentScore;
}
else if(testType == TestType.RNG)
{
score = TestMathLayout.getScore();
}
else //if(testType == TestType.RNG_SHAPE)
{
score = TestCountLayout.getScore();
}
JLabel scoreValue = makeLabel( String.valueOf(score), "Calibri", 38);
//Add Score to user ProfileAddr
UserProfile.addScore( Module.getActiveModule().pageKey, score);
scoreValue.setAlignmentX( Component.CENTER_ALIGNMENT );
scoreContainer.add( scoreValue );
mainContainer.add( scoreContainer );
//******************** Score Panel - End - ****************************************//
//Question Container
JPanel questionContainer = new JPanel();
questionContainer.setBackground(Color.black);
GridLayout gridLayout;
if(testType == TestType.MULTI)
{
gridLayout = new GridLayout(TestHelper.testAnswers.size(),1);
}
else if(testType == TestType.RNG)
{
gridLayout = new GridLayout(TestMathLayout.currentTest.size(),1);
}
else //testType == RNG_SHAPE
{
gridLayout = new GridLayout(TestCountLayout.currentTest.size(),1);
}
gridLayout.setHgap( GUI.BUFFER_SIZE_LG );
questionContainer.setLayout(gridLayout);
mainContainer.add( questionContainer );
//Answer Container
JPanel answerContainer = new JPanel();
answerContainer.setBackground(Color.black);
answerContainer.setLayout( gridLayout );
mainContainer.add( answerContainer );
//User Answer Container
JPanel userAnswerContainer = new JPanel();
userAnswerContainer.setBackground( Color.black );
userAnswerContainer.setLayout( gridLayout );
mainContainer.add( userAnswerContainer );
if( testType == TestType.MULTI )
{
int i = 0;
for (String key : TestHelper.testAnswers)
{
questionContainer.add( makeTextArea("Quesiton: " + String.valueOf(i+1) ));
AnswerKey ak = Resource_Manager.getAnswerKeys(key); //Get answers for question
int userAnser = TestHelper.currentTestAnswers.get(key); //Get user entered answer for question
if(userAnser < 0)
{
answerContainer.add( makeTextArea("Not Answered") );
}
else
{
if(ak.correctAnswerIndex != userAnser)
{
JPanel correctAnswerPanel = makeTextArea( "Correct Answer: " + ak.answers[ak.correctAnswerIndex] );
correctAnswerPanel.setBorder( new LineBorder(Color.green, 2) );
answerContainer.add( correctAnswerPanel );
userAnswerContainer.add( makeTextArea( "Your Answer: " + ak.answers[userAnser] ));
}
else
{
answerContainer.add( makeTextArea( "Correct!" ));
}
}
i++;
}
}
else if( testType == TestType.RNG)
{
//System.out.printf("Implement This %d", TestMathLayout.currentTest.size());
int i = 0;
for(AnswerKey ak : TestMathLayout.currentTest)
{
questionContainer.add( makeTextArea(String.valueOf(++i) + ". " + ak.question ));
answerContainer.add( makeTextArea(" = " + ak.correctAnswer ));
if(ak.userAnswer < 0)
{
userAnswerContainer.add( makeTextArea("Not Answered") );
}
else if( ak.userAnswer == ak.correctAnswer )
{
userAnswerContainer.add( makeTextArea( "Correct!" ));
}
else
{
JPanel textPanel = makeTextArea( "X - " + ak.correctAnswer );
textPanel.setBorder( new LineBorder(Color.red, 2) );
userAnswerContainer.add( textPanel );
}
}
}
else if(testType == TestType.RNG_SHAPE)
{
for(AnswerKey ak : TestCountLayout.currentTest)
{
questionContainer.add(makeShapeContainer(ak.correctAnswer));
if(ak.userAnswer < 0)
{
userAnswerContainer.add( makeTextArea("Not Answered") );
}
else if( ak.userAnswer == ak.correctAnswer )
{
userAnswerContainer.add( makeTextArea( "Correct!" ));
}
else
{
JPanel textPanel = makeTextArea( "X - " + ak.correctAnswer );
textPanel.setBorder( new LineBorder(Color.red, 2) );
userAnswerContainer.add( textPanel );
}
}
}
}
private JPanel makeTextArea(String text){
JPanel textAreaContainer = new JPanel();
textAreaContainer.setLayout(new BorderLayout());
JTextArea textArea = new JTextArea(text, 3, 25);
textArea.setFont(new Font("Calibri", Font.BOLD, defaultTextSize));
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
textArea.setEditable(false);
textArea.setBackground( Color.black );
textArea.setForeground( Color.white );
textAreaContainer.add(textArea);
return textAreaContainer;
}
private JLabel makeLabel(String text, String fontName, int fontSize){
JLabel label = new JLabel(text);
label.setBackground( Color.black );
label.setForeground( Color.white );
label.setFont( new Font(fontName, Font.BOLD, fontSize));
return label;
}
private JPanel makeShapeContainer(int amt){
JPanel container = new JPanel();
container.setBackground( Color.black );
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
for(int i = 0; i < amt; i++){
container.add(new JLabel(Resource_Manager.getScaledImageFromPath(pipImagePath, 32, 32)));
}
return container;
}
}
enum TestType { MULTI, RNG, RNG_SHAPE }