Lines 43-54
Link Here
|
43 |
package org.openide.awt; |
43 |
package org.openide.awt; |
44 |
|
44 |
|
45 |
import java.awt.event.ActionListener; |
45 |
import java.awt.event.ActionListener; |
|
|
46 |
import java.util.ArrayList; |
47 |
import java.util.List; |
48 |
import java.util.Map; |
46 |
import java.util.logging.Level; |
49 |
import java.util.logging.Level; |
47 |
import java.util.logging.Logger; |
50 |
import java.util.logging.Logger; |
48 |
import javax.swing.Icon; |
51 |
import javax.swing.Icon; |
|
|
52 |
import javax.swing.ImageIcon; |
49 |
import javax.swing.JComponent; |
53 |
import javax.swing.JComponent; |
50 |
import org.openide.awt.StatusDisplayer.Message; |
54 |
import org.openide.awt.StatusDisplayer.Message; |
|
|
55 |
import org.openide.util.ImageUtilities; |
51 |
import org.openide.util.Lookup; |
56 |
import org.openide.util.Lookup; |
|
|
57 |
import org.openide.util.NbBundle; |
52 |
|
58 |
|
53 |
/** |
59 |
/** |
54 |
* Creates and shows clickable notifications in the main status line. |
60 |
* Creates and shows clickable notifications in the main status line. |
Lines 63-76
Link Here
|
63 |
* Priority of Notification |
69 |
* Priority of Notification |
64 |
*/ |
70 |
*/ |
65 |
public static enum Priority { |
71 |
public static enum Priority { |
66 |
HIGH, |
72 |
HIGH(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_high.png"))), //NOI18N |
67 |
NORMAL, |
73 |
NORMAL(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_normal.png"))), //NOI18N |
68 |
LOW, |
74 |
LOW(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_low.png"))), //NOI18N |
69 |
/** Priority that shows the notification without details. |
75 |
/** Priority that shows the notification without details. |
70 |
* Details shall be shown only later, per user request. |
76 |
* Details shall be shown only later, per user request. |
71 |
* @since 7.18 |
77 |
* @since 7.18 |
72 |
*/ |
78 |
*/ |
73 |
SILENT |
79 |
SILENT(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_silent.png"))); //NOI18N |
|
|
80 |
|
81 |
private final Icon icon; |
82 |
|
83 |
private Priority(Icon icon) { |
84 |
this.icon = icon; |
85 |
} |
86 |
|
87 |
/** |
88 |
* Returns priority icon |
89 |
* |
90 |
* @since 7.57 |
91 |
*/ |
92 |
public Icon getIcon() { |
93 |
return icon; |
94 |
} |
95 |
} |
96 |
|
97 |
/** |
98 |
* Category of Notification, displayed in Notifications TC. Use one of the defaults categories (INFO, WARNING, ERROR) or create a custom category. |
99 |
* |
100 |
* To create a custom add following code to your <code>layer.xml</code>: |
101 |
* <pre> |
102 |
* {@code |
103 |
* <folder name="Notification"> |
104 |
* <folder name="Category"> |
105 |
* <file name="categoryA.instance"> |
106 |
* <attr name="instanceCreate" methodvalue="org.openide.awt.NotificationDisplayer.createCategory"/> |
107 |
* |
108 |
* <attr name="localizingBundle" stringvalue="org.modules.mymodule.Bundle"/> <!-- Bundle file with used keys--> |
109 |
* <attr name="categoryName" stringvalue="categoryA_name/> <!-- Actual category name--> |
110 |
* <attr name="diplayNameKey" stringvalue="categoryA_displayName_key"/> <!-- Key to the Bundle file--> |
111 |
* <attr name="descriptionKey" stringvalue="categoryA_description_key"/> <!-- Key to the Bundle file--> |
112 |
* </file> |
113 |
* </folder> |
114 |
* </folder> |
115 |
* } |
116 |
* </pre> |
117 |
* |
118 |
* @since 7.57 |
119 |
*/ |
120 |
public static final class Category implements Comparable<Category>{ |
121 |
|
122 |
public static final Category INFO = new Category("default_category_info", NbBundle.getMessage(NotificationDisplayer.class, "INFO_CATEGORY"), //NOI18N |
123 |
NbBundle.getMessage(NotificationDisplayer.class, "INFO_CATEGORY_DESCRIPTION")); //NOI18N |
124 |
public static final Category WARNING = new Category("default_category_warning", NbBundle.getMessage(NotificationDisplayer.class, "WARNING_CATEGORY"), //NOI18N |
125 |
NbBundle.getMessage(NotificationDisplayer.class, "WARNING_CATEGORY_DESCRIPTION")); //NOI18N |
126 |
public static final Category ERROR = new Category("default_category_error", NbBundle.getMessage(NotificationDisplayer.class, "ERROR_CATEGORY"), //NOI18N |
127 |
NbBundle.getMessage(NotificationDisplayer.class, "ERROR_CATEGORY_DESCRIPTION")); //NOI18N |
128 |
|
129 |
private final String name; |
130 |
private final String displayName; |
131 |
private final String description; |
132 |
private int index; |
133 |
|
134 |
Category(String name, String displayName, String description) { |
135 |
this.name = name; |
136 |
this.displayName = displayName; |
137 |
this.description = description; |
138 |
} |
139 |
|
140 |
/** |
141 |
* Returns category name - unique id |
142 |
* |
143 |
* @since 7.57 |
144 |
*/ |
145 |
public String getName() { |
146 |
return name; |
147 |
} |
148 |
|
149 |
/** |
150 |
* Returns category display name |
151 |
* |
152 |
* @since 7.57 |
153 |
*/ |
154 |
public String getDisplayName() { |
155 |
return displayName; |
156 |
} |
157 |
|
158 |
void setIndex(int index) { |
159 |
this.index = index; |
160 |
} |
161 |
|
162 |
/** |
163 |
* Returns category description |
164 |
* |
165 |
* @since 7.57 |
166 |
*/ |
167 |
public String getDescription() { |
168 |
return description; |
169 |
} |
170 |
|
171 |
@Override |
172 |
public int compareTo(Category other) { |
173 |
return index - other.index; |
174 |
} |
175 |
|
176 |
/** |
177 |
* Returns all available categories |
178 |
* |
179 |
* @since 7.57 |
180 |
*/ |
181 |
public static List<Category> getCategories() { |
182 |
return NotificationCategoryFactory.getInstance().getCategories(); |
183 |
} |
184 |
|
185 |
static List<Category> getDefaultCategories() { |
186 |
List<Category> defaultCategories = new ArrayList<Category>(); |
187 |
defaultCategories.add(ERROR); |
188 |
defaultCategories.add(WARNING); |
189 |
defaultCategories.add(INFO); |
190 |
return defaultCategories; |
191 |
} |
74 |
} |
192 |
} |
75 |
|
193 |
|
76 |
/** |
194 |
/** |
Lines 120-125
Link Here
|
120 |
String detailsText, ActionListener detailsAction, Priority priority); |
238 |
String detailsText, ActionListener detailsAction, Priority priority); |
121 |
|
239 |
|
122 |
/** |
240 |
/** |
|
|
241 |
* Create and show new notification. |
242 |
* @param title Notification title. Html is not supported, any html tags will |
243 |
* be escaped. |
244 |
* @param icon Notification icon |
245 |
* @param detailsText Detailed description of the notification. If detailsAction |
246 |
* is non-null then this text will be presented as a clickable link. Html is |
247 |
* not supported, any html tags will be escaped. |
248 |
* @param detailsAction Action to invoke when user click details text or null. |
249 |
* @param priority Notification priority |
250 |
* @param category Notification category. |
251 |
* @return New notification. |
252 |
* @since 7.57 |
253 |
*/ |
254 |
public Notification notify(String title, Icon icon, |
255 |
String detailsText, ActionListener detailsAction, Priority priority, Category category) { |
256 |
return notify(title, icon, detailsText, detailsAction, priority); |
257 |
} |
258 |
|
259 |
/** |
260 |
* Create and show new notification. |
261 |
* |
262 |
* @param title Notification title. Html is not supported, any html tags will be escaped. |
263 |
* @param icon Notification icon |
264 |
* @param detailsText Detailed description of the notification. If detailsAction |
265 |
* is non-null then this text will be presented as a clickable link. Html is |
266 |
* not supported, any html tags will be escaped. |
267 |
* @param detailsAction Action to invoke when user click details text or null. |
268 |
* @param priority Notification priority |
269 |
* @param categoryName Notification category name, refers to a custom category created in e.g. layer.xml. |
270 |
* @return New notification. |
271 |
* @since 7.57 |
272 |
*/ |
273 |
public Notification notify(String title, Icon icon, |
274 |
String detailsText, ActionListener detailsAction, Priority priority, String categoryName) { |
275 |
return notify(title, icon, detailsText, detailsAction, priority, NotificationCategoryFactory.getInstance().getCategory(categoryName)); |
276 |
} |
277 |
|
278 |
/** |
123 |
* Create and show new notification with customized content. |
279 |
* Create and show new notification with customized content. |
124 |
* @param title Notification title. Html is not supported, any html tags will |
280 |
* @param title Notification title. Html is not supported, any html tags will |
125 |
* be escaped. |
281 |
* be escaped. |
Lines 127-133
Link Here
|
127 |
* @param balloonDetails Component that will show below notification title |
283 |
* @param balloonDetails Component that will show below notification title |
128 |
* in a balloon. |
284 |
* in a balloon. |
129 |
* @param popupDetails Component that will show below notification title |
285 |
* @param popupDetails Component that will show below notification title |
130 |
* in notifications popup list. |
286 |
* in notifications list. |
131 |
* @param priority Notification priority. |
287 |
* @param priority Notification priority. |
132 |
* @return New notification. |
288 |
* @return New notification. |
133 |
*/ |
289 |
*/ |
Lines 135-140
Link Here
|
135 |
JComponent balloonDetails, JComponent popupDetails, Priority priority); |
291 |
JComponent balloonDetails, JComponent popupDetails, Priority priority); |
136 |
|
292 |
|
137 |
/** |
293 |
/** |
|
|
294 |
* Create and show new notification with customized content. |
295 |
* @param title Notification title. Html is not supported, any html tags will |
296 |
* be escaped. |
297 |
* @param icon Notification icon |
298 |
* @param balloonDetails Component that will show below notification title |
299 |
* in a balloon. |
300 |
* @param popupDetails Component that will show below notification title |
301 |
* in notifications list. |
302 |
* @param priority Notification priority. |
303 |
* @param category Notification category. |
304 |
* @return New notification. |
305 |
* @since 7.57 |
306 |
*/ |
307 |
public Notification notify(String title, Icon icon, |
308 |
JComponent balloonDetails, JComponent popupDetails, Priority priority, Category category) { |
309 |
return notify(title, icon, balloonDetails, popupDetails, priority); |
310 |
} |
311 |
|
312 |
/** |
313 |
Create and show new notification with customized content. |
314 |
* @param title Notification title. Html is not supported, any html tags will |
315 |
* be escaped. |
316 |
* @param icon Notification icon |
317 |
* @param balloonDetails Component that will show below notification title |
318 |
* in a balloon. |
319 |
* @param popupDetails Component that will show below notification title |
320 |
* in notifications list. |
321 |
* @param priority Notification priority. |
322 |
* @param categoryName Notification category name, refers to a custom category created in e.g. layer.xml. |
323 |
* @return New notification. |
324 |
* @since 7.57 |
325 |
*/ |
326 |
public Notification notify(String title, Icon icon, |
327 |
JComponent balloonDetails, JComponent popupDetails, Priority priority, String categoryName) { |
328 |
return notify(title, icon, balloonDetails, popupDetails, priority, NotificationCategoryFactory.getInstance().getCategory(categoryName)); |
329 |
} |
330 |
|
331 |
static Category createCategory(Map<String, String> attrs) { |
332 |
return NotificationCategoryFactory.create(attrs); |
333 |
} |
334 |
|
335 |
/** |
138 |
* Simple implementation of NotificationDisplayer which shows the notifications |
336 |
* Simple implementation of NotificationDisplayer which shows the notifications |
139 |
* on the main status line. |
337 |
* on the main status line. |
140 |
*/ |
338 |
*/ |