2
2
3
3
import fi .helsinki .cs .tmc .core .domain .Exercise ;
4
4
import fi .helsinki .cs .tmc .core .domain .submission .SubmissionResult ;
5
-
6
- import java .awt .Component ;
7
-
8
5
import fi .helsinki .cs .tmc .core .domain .submission .FeedbackAnswer ;
9
6
import fi .helsinki .cs .tmc .core .domain .submission .FeedbackQuestion ;
10
7
import fi .helsinki .cs .tmc .ui .feedback .FeedbackQuestionPanel ;
11
8
import fi .helsinki .cs .tmc .ui .feedback .FeedbackQuestionPanelFactory ;
12
9
10
+ import com .google .common .base .Optional ;
11
+
12
+ import java .awt .Component ;
13
13
import java .awt .Font ;
14
14
import java .awt .event .ActionEvent ;
15
15
import java .awt .event .ActionListener ;
16
+ import java .net .MalformedURLException ;
17
+ import java .net .URI ;
16
18
import java .net .URL ;
17
19
import java .util .ArrayList ;
18
20
import java .util .List ;
25
27
import javax .swing .JDialog ;
26
28
import javax .swing .JLabel ;
27
29
import javax .swing .JPanel ;
30
+
28
31
import org .apache .commons .lang3 .StringEscapeUtils ;
29
32
import org .apache .commons .lang3 .StringUtils ;
30
33
import org .openide .awt .HtmlBrowser ;
31
34
32
- import static fi .helsinki .cs .tmc .ui .Boxer .*;
35
+ import static fi .helsinki .cs .tmc .ui .Boxer .hbox ;
36
+ import static fi .helsinki .cs .tmc .ui .Boxer .hglue ;
33
37
34
38
public class SuccessfulSubmissionDialog extends JDialog {
35
-
39
+
36
40
private static final Logger log = Logger .getLogger (SuccessfulSubmissionDialog .class .getName ());
37
-
41
+
38
42
private JButton okButton ;
39
-
43
+ private JButton showSubmissionButton ;
44
+
40
45
private List <FeedbackQuestionPanel > feedbackQuestionPanels ;
41
46
42
47
public SuccessfulSubmissionDialog (Exercise exercise , SubmissionResult result ) {
43
48
this .setTitle (exercise .getName () + " passed" );
44
-
49
+
45
50
JPanel contentPane = new JPanel ();
46
51
contentPane .setBorder (BorderFactory .createEmptyBorder (8 , 8 , 8 , 8 ));
47
52
contentPane .setLayout (new BoxLayout (contentPane , BoxLayout .Y_AXIS ));
48
53
setContentPane (contentPane );
49
-
54
+
50
55
addYayLabel ();
51
56
addVSpace (6 );
52
57
if (exercise .requiresReview () && !result .getMissingReviewPoints ().isEmpty ()) {
@@ -59,17 +64,17 @@ public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result) {
59
64
addVSpace (20 );
60
65
addFeedbackQuestions (result ); //TODO: maybe put in box
61
66
addVSpace (10 );
62
- addOkButton ( );
63
-
67
+ addButtons ( result );
68
+
64
69
pack ();
65
70
}
66
-
71
+
67
72
public void addOkListener (ActionListener okListener ) {
68
73
this .okButton .addActionListener (okListener );
69
74
}
70
-
75
+
71
76
public List <FeedbackAnswer > getFeedbackAnswers () {
72
- List <FeedbackAnswer > answers = new ArrayList <FeedbackAnswer >();
77
+ List <FeedbackAnswer > answers = new ArrayList <>();
73
78
for (FeedbackQuestionPanel panel : feedbackQuestionPanels ) {
74
79
FeedbackAnswer answer = panel .getAnswer ();
75
80
if (answer != null ) {
@@ -78,42 +83,42 @@ public List<FeedbackAnswer> getFeedbackAnswers() {
78
83
}
79
84
return answers ;
80
85
}
81
-
86
+
82
87
private void addVSpace (int height ) {
83
88
add (Box .createVerticalStrut (height ));
84
89
}
85
-
90
+
86
91
private Box leftAligned (Component component ) {
87
92
return hbox (component , hglue ());
88
93
}
89
-
94
+
90
95
private void addYayLabel () {
91
96
JLabel yayLabel = new JLabel ("All tests passed on the server." );
92
-
97
+
93
98
Font font = yayLabel .getFont ();
94
99
font = font .deriveFont (Font .BOLD , font .getSize2D () * 1.2f );
95
100
yayLabel .setFont (font );
96
-
101
+
97
102
yayLabel .setForeground (new java .awt .Color (0 , 153 , 51 ));
98
103
yayLabel .setIcon (ConvenientDialogDisplayer .getDefault ().getSmileyIcon ());
99
-
104
+
100
105
getContentPane ().add (leftAligned (yayLabel ));
101
106
}
102
-
107
+
103
108
private void addRequiresReviewLabels () {
104
109
JLabel lbl1 = new JLabel ("This exercise requires a code review." );
105
110
JLabel lbl2 = new JLabel ("It will have a yellow marker until it's accepted by an instructor." );
106
111
getContentPane ().add (leftAligned (lbl1 ));
107
112
getContentPane ().add (leftAligned (lbl2 ));
108
113
}
109
-
114
+
110
115
private void addPointsLabel (SubmissionResult result ) {
111
116
JLabel pointsLabel = new JLabel (getPointsMsg (result ));
112
117
pointsLabel .setFont (pointsLabel .getFont ().deriveFont (Font .BOLD ));
113
-
118
+
114
119
getContentPane ().add (leftAligned (pointsLabel ));
115
120
}
116
-
121
+
117
122
private String getPointsMsg (SubmissionResult result ) {
118
123
if (!result .getPoints ().isEmpty ()) {
119
124
String msg = "Points permanently awarded: " + StringUtils .join (result .getPoints (), ", " ) + "." ;
@@ -131,19 +136,19 @@ private void addModelSolutionButton(SubmissionResult result) {
131
136
public void actionPerformed (ActionEvent ev ) {
132
137
try {
133
138
HtmlBrowser .URLDisplayer .getDefault ().showURLExternal (new URL (solutionUrl ));
134
- } catch (Exception ex ) {
139
+ } catch (MalformedURLException ex ) {
135
140
ConvenientDialogDisplayer .getDefault ().displayError ("Failed to open browser.\n " + ex .getMessage ());
136
141
}
137
142
}
138
143
});
139
-
144
+
140
145
getContentPane ().add (leftAligned (solutionButton ));
141
146
}
142
147
}
143
148
144
149
private void addFeedbackQuestions (SubmissionResult result ) {
145
- this .feedbackQuestionPanels = new ArrayList <FeedbackQuestionPanel >();
146
-
150
+ this .feedbackQuestionPanels = new ArrayList <>();
151
+
147
152
if (!result .getFeedbackQuestions ().isEmpty () && result .getFeedbackAnswerUrl () != null ) {
148
153
for (FeedbackQuestion question : result .getFeedbackQuestions ()) {
149
154
try {
@@ -153,12 +158,12 @@ private void addFeedbackQuestions(SubmissionResult result) {
153
158
log .warning (e .getMessage ());
154
159
}
155
160
}
156
-
161
+
157
162
if (!feedbackQuestionPanels .isEmpty ()) { // Some failsafety
158
163
JLabel feedbackLabel = new JLabel ("Feedback (leave empty to not send)" );
159
164
feedbackLabel .setFont (feedbackLabel .getFont ().deriveFont (Font .BOLD ));
160
165
getContentPane ().add (leftAligned (feedbackLabel ));
161
-
166
+
162
167
for (FeedbackQuestionPanel panel : feedbackQuestionPanels ) {
163
168
getContentPane ().add (leftAligned (panel ));
164
169
}
@@ -167,17 +172,45 @@ private void addFeedbackQuestions(SubmissionResult result) {
167
172
}
168
173
}
169
174
}
170
-
171
- private void addOkButton () {
175
+
176
+ private void addButtons (SubmissionResult result ) {
177
+ JPanel buttonPane = new JPanel ();
178
+ buttonPane .setLayout (new BoxLayout (buttonPane , BoxLayout .LINE_AXIS ));
179
+
180
+ Optional <URI > submissionUrl = Optional .absent ();
181
+ final String submissionUrlString = result .getSubmissionUrl ();
182
+ if (submissionUrlString != null && !submissionUrlString .isEmpty ()) {
183
+ submissionUrl = Optional .of (URI .create (submissionUrlString ));
184
+ }
185
+ addShowSubmissionButton (buttonPane , submissionUrl );
186
+ addOkButton (buttonPane );
187
+ getContentPane ().add (buttonPane );
188
+ }
189
+
190
+ private void addOkButton (JPanel buttonPane ) {
172
191
okButton = new JButton ("OK" );
173
- okButton .addActionListener (new ActionListener () {
192
+ okButton .addActionListener ((ActionEvent e ) -> {
193
+ setVisible (false );
194
+ dispose ();
195
+ });
196
+ buttonPane .add (hbox (hglue (), okButton ));
197
+ }
198
+
199
+ private void addShowSubmissionButton (JPanel buttonPane , Optional <URI > submissionUrl ) {
200
+ if (!submissionUrl .isPresent ()) {
201
+ return ;
202
+ }
203
+ showSubmissionButton = new JButton ("View submission in browser" );
204
+ showSubmissionButton .setAction (new AbstractAction ("View submission in browser" ) {
174
205
@ Override
175
- public void actionPerformed (ActionEvent e ) {
176
- setVisible (false );
177
- dispose ();
206
+ public void actionPerformed (ActionEvent ae ) {
207
+ try {
208
+ HtmlBrowser .URLDisplayer .getDefault ().showURLExternal (submissionUrl .get ().toURL ());
209
+ } catch (MalformedURLException ex ) {
210
+ ConvenientDialogDisplayer .getDefault ().displayError ("Failed to open browser.\n " + ex .getMessage ());
211
+ }
178
212
}
179
213
});
180
- getContentPane () .add (hbox ( hglue (), okButton ) );
214
+ buttonPane .add (showSubmissionButton );
181
215
}
182
-
183
216
}
0 commit comments