23
23
import org .netbeans .api .project .Project ;
24
24
import org .netbeans .spi .project .ProjectIconAnnotator ;
25
25
import org .openide .util .ChangeSupport ;
26
+ import org .openide .util .Exceptions ;
26
27
import org .openide .util .ImageUtilities ;
27
28
import org .openide .util .lookup .ServiceProvider ;
28
29
@@ -44,7 +45,7 @@ public ExerciseIconAnnotator() {
44
45
this .courses = CourseDb .getInstance ();
45
46
this .projectMediator = ProjectMediator .getInstance ();
46
47
this .iconCache = new HashMap <String , Image >();
47
-
48
+
48
49
eventBus .subscribeDependent (new TmcEventListener () {
49
50
public void receive (CourseDb .ChangedEvent event ) {
50
51
SwingUtilities .invokeLater (new Runnable () {
@@ -64,10 +65,10 @@ public Image annotateIcon(Project nbProject, Image origImg, boolean openedNode)
64
65
if (exercise == null || !exercise .getCourseName ().equals (courses .getCurrentCourseName ())) {
65
66
return origImg ;
66
67
}
67
-
68
+
68
69
//TODO: use ImageUtilities.createDisabledImage for expired exercises.
69
70
//Had some very weird problems with that. Try again some day.
70
-
71
+
71
72
Image img = origImg ;
72
73
try {
73
74
Image annotation = annotationIconForExericse (exercise );
@@ -77,13 +78,13 @@ public Image annotateIcon(Project nbProject, Image origImg, boolean openedNode)
77
78
} catch (IOException e ) {
78
79
log .log (Level .WARNING , "Failed to load exercise icon annotation" , e );
79
80
}
80
-
81
+
81
82
String tooltip = tooltipForExercise (exercise );
82
83
img = ImageUtilities .assignToolTipToImage (img , tooltip );
83
-
84
+
84
85
return img ;
85
86
}
86
-
87
+
87
88
private Image annotationIconForExericse (Exercise exercise ) throws IOException {
88
89
String name = annotationIconNameForExercise (exercise );
89
90
if (name != null ) {
@@ -96,7 +97,7 @@ private Image annotationIconForExericse(Exercise exercise) throws IOException {
96
97
return null ;
97
98
}
98
99
}
99
-
100
+
100
101
private String annotationIconNameForExercise (Exercise exercise ) {
101
102
if (exercise .hasDeadlinePassed ()) {
102
103
return null ;
@@ -110,7 +111,7 @@ private String annotationIconNameForExercise(Exercise exercise) {
110
111
return "black-project-dot.png" ;
111
112
}
112
113
}
113
-
114
+
114
115
private String tooltipForExercise (Exercise exercise ) {
115
116
List <String > parts = new ArrayList <String >();
116
117
if (exercise .isAttempted ()) {
@@ -129,23 +130,23 @@ private String tooltipForExercise(Exercise exercise) {
129
130
parts .add ("code review not yet done" );
130
131
}
131
132
}
132
-
133
+
133
134
} else {
134
135
parts .add ("exercise not yet submitted" );
135
136
}
136
-
137
+
137
138
if (!exercise .isCompleted () && exercise .getDeadline () != null ) {
138
139
DateFormat df = new SimpleDateFormat ("dd.MM.yyyy HH:mm" );
139
140
parts .add ("deadline: " + df .format (exercise .getDeadline ()));
140
141
}
141
-
142
+
142
143
return StringUtils .capitalize (StringUtils .join (parts , " - " ));
143
144
}
144
-
145
+
145
146
public void updateAllIcons () {
146
147
changeSupport .fireChange ();
147
148
}
148
-
149
+
149
150
@ Override
150
151
public void addChangeListener (ChangeListener listener ) {
151
152
changeSupport .addChangeListener (listener );
0 commit comments