Revision 35160 trunk/libraries/libCorePlugin/src/com/iver/core/NotificationDialog.java
NotificationDialog.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.core; |
42 | 42 |
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.Component; |
|
45 |
import java.awt.Dimension; |
|
46 |
import java.awt.FlowLayout; |
|
47 |
import java.awt.Font; |
|
48 |
import java.awt.GridBagConstraints; |
|
49 |
import java.awt.GridBagLayout; |
|
50 |
import java.io.File; |
|
51 |
|
|
43 | 52 |
import com.iver.andami.PluginServices; |
44 | 53 |
import com.iver.andami.messages.MessageEvent; |
45 | 54 |
import com.iver.andami.messages.NotificationListener; |
... | ... | |
47 | 56 |
import com.iver.andami.ui.mdiManager.IWindow; |
48 | 57 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
49 | 58 |
|
59 |
import javax.swing.ImageIcon; |
|
50 | 60 |
import javax.swing.JButton; |
61 |
import javax.swing.JLabel; |
|
51 | 62 |
import javax.swing.JPanel; |
52 | 63 |
import javax.swing.JScrollPane; |
53 | 64 |
import javax.swing.JTextArea; |
... | ... | |
58 | 69 |
* Graphic interface that appears to show an error. |
59 | 70 |
* |
60 | 71 |
* @author Vicente Caballero Navarro |
72 |
* @author jldominguez |
|
61 | 73 |
*/ |
62 | 74 |
public class NotificationDialog extends JPanel implements IWindow, SingletonWindow, |
63 | 75 |
NotificationListener { |
76 |
|
|
77 |
private static final Font ERR_MSG_FONT = new Font("Monospaced", Font.BOLD, 11); |
|
78 |
private static final Font MSG_FONT = new Font("Dialog", Font.PLAIN, 12); |
|
79 |
private static final int ERR_MSG_MAX_LEN = 96; |
|
80 |
|
|
81 |
private static boolean userWantsToSeeNotifications = true; |
|
82 |
|
|
83 |
/* |
|
64 | 84 |
private JButton bDetails = null; |
65 | 85 |
private JPanel pDescription = null; |
66 | 86 |
private JTextArea txtDescription = null; |
67 | 87 |
private JButton bNoDetails = null; |
68 | 88 |
private JButton bAcept = null; |
69 | 89 |
private JScrollPane pScrollDescription = null; |
70 |
private int width = 470; |
|
71 |
private int height = 175; |
|
90 |
*/ |
|
91 |
|
|
92 |
private JPanel south0Panel = null; |
|
93 |
private JPanel center0Panel = null; |
|
94 |
private JPanel center0west1Panel = null; |
|
95 |
private JPanel center0center1Panel = null; |
|
96 |
private JTextArea descriptionText = null; |
|
97 |
private JTextArea originalMsgText = null; |
|
98 |
|
|
99 |
private static ImageIcon errorIcon = null; |
|
100 |
private static ImageIcon messageIcon = null; |
|
101 |
private static String log_file = "<USER_FOLDER>" + File.separator + "gvsig" + File.separator + "gvSIG.log"; |
|
102 |
|
|
103 |
static { |
|
104 |
|
|
105 |
log_file = System.getProperty("user.home") + File.separator + "gvsig" + File.separator + "gvSIG.log"; |
|
106 |
errorIcon = new ImageIcon(NotificationDialog.class |
|
107 |
.getClassLoader().getResource("images/gvsig_error.png")); |
|
108 |
messageIcon = new ImageIcon(NotificationDialog.class |
|
109 |
.getClassLoader().getResource("images/gvsig_feedback.png")); |
|
110 |
} |
|
111 |
|
|
112 |
private JButton acceptButton = null; |
|
113 |
private JButton acceptNoShowButton = null; |
|
72 | 114 |
|
73 | 115 |
/** |
74 | 116 |
* This is the default constructor |
... | ... | |
82 | 124 |
* This method initializes this |
83 | 125 |
*/ |
84 | 126 |
private void initialize() { |
85 |
Consola.consolaFrame.setSize(new java.awt.Dimension(457, 150));
|
|
127 |
Consola.consolaFrame.setSize(new java.awt.Dimension(500, 250));
|
|
86 | 128 |
Consola.consolaFrame.setLocation(new java.awt.Point(11, 140)); |
87 | 129 |
Consola.consolaFrame.setVisible(false); |
88 |
this.setLayout(null); |
|
89 |
this.setSize(width, height); |
|
90 |
this.add(getBDetails(), null); |
|
91 |
this.add(getPDescription(), null); |
|
92 |
this.add(Consola.consolaFrame, null); |
|
93 |
this.add(getDNoDetails(), null); |
|
94 |
this.add(getBAcept(), null); |
|
130 |
|
|
131 |
this.setLayout(new BorderLayout()); |
|
132 |
this.setSize(ConsolaFrame.WIDTH, ConsolaFrame.HEIGHT); |
|
133 |
|
|
134 |
add(this.getCenter0Panel(), BorderLayout.CENTER); |
|
135 |
add(this.getSouth0Panel(), BorderLayout.SOUTH); |
|
136 |
// this.add(getBDetails(), null); |
|
137 |
// this.add(getPDescription(), null); |
|
138 |
// this.add(Consola.consolaFrame, null); |
|
139 |
// this.add(getDNoDetails(), null); |
|
140 |
// this.add(getBAcept(), null); |
|
95 | 141 |
} |
96 | 142 |
|
97 | 143 |
/** |
... | ... | |
99 | 145 |
* |
100 | 146 |
* @return javax.swing.JButton |
101 | 147 |
*/ |
148 |
|
|
149 |
/* |
|
102 | 150 |
private JButton getBDetails() { |
103 | 151 |
if (bDetails == null) { |
104 | 152 |
bDetails = new JButton(); |
... | ... | |
120 | 168 |
|
121 | 169 |
return bDetails; |
122 | 170 |
} |
171 |
*/ |
|
172 |
|
|
123 | 173 |
|
124 | 174 |
/** |
125 | 175 |
* This method initializes pDescription |
126 | 176 |
* |
127 | 177 |
* @return javax.swing.JPanel |
128 | 178 |
*/ |
179 |
/* |
|
129 | 180 |
private JPanel getPDescription() { |
130 | 181 |
if (pDescription == null) { |
131 | 182 |
pDescription = new JPanel(); |
... | ... | |
139 | 190 |
|
140 | 191 |
return pDescription; |
141 | 192 |
} |
193 |
*/ |
|
142 | 194 |
|
143 | 195 |
/** |
144 | 196 |
* This method initializes txtDescription |
145 | 197 |
* |
146 | 198 |
* @return javax.swing.JTextArea |
147 | 199 |
*/ |
200 |
/* |
|
148 | 201 |
private JTextArea getTxtDescription() { |
149 | 202 |
if (txtDescription == null) { |
150 | 203 |
txtDescription = new JTextArea(); |
... | ... | |
156 | 209 |
|
157 | 210 |
return txtDescription; |
158 | 211 |
} |
212 |
*/ |
|
213 |
|
|
159 | 214 |
|
160 | 215 |
/** |
161 | 216 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getModel() |
... | ... | |
170 | 225 |
public WindowInfo getWindowInfo() { |
171 | 226 |
WindowInfo info = new WindowInfo(WindowInfo.MODELESSDIALOG | |
172 | 227 |
WindowInfo.ICONIFIABLE); |
173 |
info.setWidth(width);
|
|
174 |
info.setHeight(height);
|
|
228 |
info.setWidth(ConsolaFrame.WIDTH + 10);
|
|
229 |
info.setHeight(ConsolaFrame.HEIGHT + 30);
|
|
175 | 230 |
info.setTitle(PluginServices.getText(this, "titulo_consola")); |
176 | 231 |
|
177 | 232 |
return info; |
... | ... | |
181 | 236 |
* @see com.iver.mdiApp.NotificationListener#errorEvent(java.lang.String) |
182 | 237 |
*/ |
183 | 238 |
public void errorEvent(MessageEvent e) { |
184 |
if (e.getMessages() != null) { |
|
185 |
for (int i = 0; i < e.getMessages().length; i++) { |
|
186 |
txtDescription.setText(e.getMessages()[i]); |
|
187 |
} |
|
239 |
|
|
240 |
if (!userWantsToSeeNotifications) { |
|
241 |
return; |
|
242 |
} |
|
243 |
|
|
244 |
String aux = "[-]"; |
|
245 |
if (e.getMessages() != null && e.getMessages().length > 0 && e.getMessages()[0] != null) { |
|
246 |
aux = e.getMessages()[0]; |
|
247 |
|
|
248 |
if (aux.length() > ERR_MSG_MAX_LEN) { |
|
249 |
aux = aux.substring(0, ERR_MSG_MAX_LEN) |
|
250 |
+ "... (" + (aux.length()-ERR_MSG_MAX_LEN) + " more)" ; |
|
251 |
} |
|
188 | 252 |
} |
253 |
|
|
254 |
getTextDescription().setText(aux); |
|
255 |
aux = "[-]"; |
|
189 | 256 |
|
257 |
if (e.getExceptions() != null && e.getExceptions().length > 0) { |
|
258 |
aux = getInnerMostMessage(e.getExceptions()[0]); |
|
259 |
if (aux.length() > ERR_MSG_MAX_LEN) { |
|
260 |
aux = aux.substring(0, ERR_MSG_MAX_LEN) |
|
261 |
+ "... (" + (aux.length()-ERR_MSG_MAX_LEN) + " more)" ; |
|
262 |
} |
|
263 |
} |
|
264 |
getOriginalErrorText().setText(aux); |
|
265 |
|
|
266 |
// this.doLayout(); |
|
190 | 267 |
PluginServices.getMDIManager().restoreCursor(); |
191 | 268 |
if (SwingUtilities.isEventDispatchThread()) { |
192 |
PluginServices.getMDIManager().addWindow(this); |
|
269 |
PluginServices.getMDIManager().addCentredWindow(this);
|
|
193 | 270 |
} else { |
194 | 271 |
SwingUtilities.invokeLater(new Runnable() { |
195 | 272 |
public void run() { |
196 |
PluginServices.getMDIManager().addWindow(NotificationDialog.this); |
|
273 |
PluginServices.getMDIManager().addCentredWindow(NotificationDialog.this);
|
|
197 | 274 |
} |
198 | 275 |
}); |
199 | 276 |
} |
200 | 277 |
|
201 | 278 |
} |
202 | 279 |
|
203 |
/** |
|
280 |
private String getInnerMostMessage(Throwable thr) { |
|
281 |
return getInnerMostMessage(thr, 5); |
|
282 |
} |
|
283 |
|
|
284 |
private String getInnerMostMessage(Throwable thr, int maxrec) { |
|
285 |
|
|
286 |
if (thr == null) { |
|
287 |
return "[--]"; |
|
288 |
} else { |
|
289 |
if (thr.getCause() == null || thr.getCause() == thr || maxrec == 0) { |
|
290 |
|
|
291 |
StackTraceElement[] trace = thr.getStackTrace(); |
|
292 |
String tracestr = "-"; |
|
293 |
if (trace != null && trace.length > 0 && trace[0].getFileName() != null) { |
|
294 |
tracestr = trace[0].getFileName(); |
|
295 |
} |
|
296 |
|
|
297 |
if (thr.getMessage() == null) { |
|
298 |
return thr.getClass().getSimpleName() + " (" + tracestr + ")"; |
|
299 |
} else { |
|
300 |
return (thr.getClass().getSimpleName() + ": " + thr.getMessage()) + " (" + tracestr + ")"; |
|
301 |
} |
|
302 |
} else { |
|
303 |
return getInnerMostMessage(thr.getCause(), maxrec-1); |
|
304 |
} |
|
305 |
|
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
204 | 310 |
* @see com.iver.mdiApp.NotificationListener#warningEvent(java.lang.String) |
205 | 311 |
*/ |
206 | 312 |
public void warningEvent(MessageEvent e) { |
... | ... | |
217 | 323 |
* |
218 | 324 |
* @return javax.swing.JButton |
219 | 325 |
*/ |
326 |
/* |
|
220 | 327 |
private JButton getDNoDetails() { |
221 | 328 |
if (bNoDetails == null) { |
222 | 329 |
bNoDetails = new JButton(); |
... | ... | |
238 | 345 |
|
239 | 346 |
return bNoDetails; |
240 | 347 |
} |
348 |
*/ |
|
241 | 349 |
|
242 | 350 |
/** |
243 | 351 |
* This method initializes bAcept |
244 | 352 |
* |
245 | 353 |
* @return javax.swing.JButton |
246 | 354 |
*/ |
355 |
|
|
356 |
/* |
|
247 | 357 |
private JButton getBAcept() { |
248 | 358 |
if (bAcept == null) { |
249 | 359 |
bAcept = new JButton(); |
... | ... | |
258 | 368 |
|
259 | 369 |
return bAcept; |
260 | 370 |
} |
371 |
*/ |
|
261 | 372 |
|
262 | 373 |
/** |
263 | 374 |
* This method initializes pScrollDescription |
264 | 375 |
* |
265 | 376 |
* @return javax.swing.JScrollPane |
266 | 377 |
*/ |
378 |
|
|
379 |
/* |
|
267 | 380 |
private JScrollPane getPScrollDescription() { |
268 | 381 |
if (pScrollDescription == null) { |
269 | 382 |
pScrollDescription = new JScrollPane(); |
... | ... | |
274 | 387 |
|
275 | 388 |
return pScrollDescription; |
276 | 389 |
} |
390 |
*/ |
|
277 | 391 |
|
278 | 392 |
public Object getWindowProfile() { |
279 | 393 |
return WindowInfo.PROPERTIES_PROFILE; |
280 | 394 |
} |
395 |
|
|
396 |
public JPanel getSouth0Panel() { |
|
397 |
if (south0Panel == null) { |
|
398 |
south0Panel = new JPanel(); |
|
399 |
south0Panel.setLayout(new FlowLayout()); |
|
400 |
south0Panel.add(this.getAcceptButton()); |
|
401 |
south0Panel.add(this.getAcceptNoShowButton()); |
|
402 |
} |
|
403 |
return south0Panel; |
|
404 |
} |
|
405 |
|
|
406 |
|
|
407 |
public JPanel getCenter0Panel() { |
|
408 |
if (center0Panel == null) { |
|
409 |
center0Panel = new JPanel(); |
|
410 |
center0Panel.setLayout(new BorderLayout()); |
|
411 |
center0Panel.add(getCenter0center1Panel(), BorderLayout.CENTER); |
|
412 |
center0Panel.add(getCenter0west1Panel(), BorderLayout.WEST); |
|
413 |
} |
|
414 |
return center0Panel; |
|
415 |
} |
|
416 |
|
|
417 |
|
|
418 |
public JPanel getCenter0west1Panel() { |
|
419 |
if (center0west1Panel == null) { |
|
420 |
center0west1Panel = new JPanel(); |
|
421 |
center0west1Panel.setLayout(new GridBagLayout()); |
|
422 |
GridBagConstraints c = new GridBagConstraints(); |
|
423 |
c.fill = GridBagConstraints.BOTH; |
|
424 |
c.gridx = 0; |
|
425 |
// =========================== |
|
426 |
c.gridy = 0; |
|
427 |
c.anchor = GridBagConstraints.PAGE_END; |
|
428 |
center0west1Panel.add(new JLabel(errorIcon), c); |
|
429 |
c.gridy = 1; |
|
430 |
center0west1Panel.add(new JLabel(" "), c); |
|
431 |
c.gridy = 2; |
|
432 |
c.anchor = GridBagConstraints.PAGE_START; |
|
433 |
center0west1Panel.add(new JLabel(messageIcon), c); |
|
434 |
} |
|
435 |
return center0west1Panel; |
|
436 |
} |
|
437 |
|
|
438 |
|
|
439 |
public JPanel getCenter0center1Panel() { |
|
440 |
if (center0center1Panel == null) { |
|
441 |
|
|
442 |
center0center1Panel = new JPanel(); |
|
443 |
center0center1Panel.setLayout(new GridBagLayout()); |
|
444 |
GridBagConstraints c = new GridBagConstraints(); |
|
445 |
c.weightx = 1; |
|
446 |
c.fill = GridBagConstraints.HORIZONTAL; |
|
447 |
c.gridx = 0; |
|
448 |
// =========================== |
|
449 |
c.gridy = 0; |
|
450 |
JTextArea tarea1 = new JTextArea(); |
|
451 |
tarea1.setFont(MSG_FONT); |
|
452 |
tarea1.setLineWrap(true); |
|
453 |
tarea1.setWrapStyleWord(true); |
|
454 |
tarea1.setText(PluginServices.getText(this, "gvsig_had_problem_process_failed_send_log_error_message_is")); |
|
455 |
tarea1.setEditable(false); |
|
456 |
tarea1.setBackground(this.getBackground()); |
|
457 |
center0center1Panel.add(tarea1, c); |
|
458 |
|
|
459 |
c.weightx = 0.1; |
|
460 |
c.gridx = 1; |
|
461 |
center0center1Panel.add(new JLabel(" "), c); |
|
462 |
|
|
463 |
c.weightx = 1; |
|
464 |
c.gridx = 0; |
|
465 |
c.gridy = 1; |
|
466 |
center0center1Panel.add(new JLabel(" "), c); |
|
467 |
c.gridy = 2; |
|
468 |
center0center1Panel.add(getTextDescription(), c); |
|
469 |
c.gridy = 3; |
|
470 |
center0center1Panel.add(new JLabel(" "), c); |
|
471 |
c.gridy = 4; |
|
472 |
center0center1Panel.add(getOriginalErrorText(), c); |
|
473 |
c.gridy = 5; |
|
474 |
center0center1Panel.add(new JLabel(" "), c); |
|
475 |
|
|
476 |
c.gridy = 6; |
|
477 |
JTextArea tarea2 = new JTextArea(); |
|
478 |
tarea2.setFont(MSG_FONT); |
|
479 |
tarea2.setWrapStyleWord(true); |
|
480 |
tarea2.setEditable(false); |
|
481 |
tarea2.setLineWrap(true); |
|
482 |
tarea2.setBackground(this.getBackground()); |
|
483 |
tarea2.setText(PluginServices.getText(this, "If_msg_doesnt_help_recommend_send_log_file_in") + ":\n\n" + log_file); |
|
484 |
center0center1Panel.add(tarea2, c); |
|
485 |
} |
|
486 |
return center0center1Panel; |
|
487 |
} |
|
488 |
|
|
489 |
private JTextArea getTextDescription() { |
|
490 |
|
|
491 |
if (descriptionText == null) { |
|
492 |
descriptionText = new JTextArea(); |
|
493 |
// txtDescription.setPreferredSize(new Dimension(320, 80)); |
|
494 |
descriptionText.setFont(ERR_MSG_FONT); |
|
495 |
descriptionText.setLineWrap(true); |
|
496 |
descriptionText.setWrapStyleWord(false); |
|
497 |
descriptionText.setEditable(false); |
|
498 |
descriptionText.setBackground(this.getBackground()); |
|
499 |
} |
|
500 |
return descriptionText; |
|
501 |
} |
|
502 |
|
|
503 |
private JTextArea getOriginalErrorText() { |
|
504 |
|
|
505 |
if (originalMsgText == null) { |
|
506 |
originalMsgText = new JTextArea(); |
|
507 |
// txtDescription.setPreferredSize(new Dimension(320, 80)); |
|
508 |
originalMsgText.setFont(ERR_MSG_FONT); |
|
509 |
originalMsgText.setLineWrap(true); |
|
510 |
originalMsgText.setWrapStyleWord(false); |
|
511 |
originalMsgText.setEditable(false); |
|
512 |
originalMsgText.setBackground(this.getBackground()); |
|
513 |
} |
|
514 |
return originalMsgText; |
|
515 |
} |
|
516 |
|
|
517 |
public JButton getAcceptButton() { |
|
518 |
if (acceptButton == null) { |
|
519 |
acceptButton = new JButton(); |
|
520 |
acceptButton.setText(PluginServices.getText(this,"aceptar")); |
|
521 |
acceptButton.addActionListener(new java.awt.event.ActionListener() { |
|
522 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
523 |
PluginServices.getMDIManager().closeWindow(NotificationDialog.this); |
|
524 |
} |
|
525 |
}); |
|
526 |
|
|
527 |
} |
|
528 |
return acceptButton; |
|
529 |
} |
|
530 |
|
|
531 |
public JButton getAcceptNoShowButton() { |
|
532 |
if (acceptNoShowButton == null) { |
|
533 |
acceptNoShowButton = new JButton(); |
|
534 |
acceptNoShowButton.setText(PluginServices.getText(this,"Dont_show_message_again")); |
|
535 |
acceptNoShowButton.addActionListener(new java.awt.event.ActionListener() { |
|
536 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
537 |
userWantsToSeeNotifications = false; |
|
538 |
PluginServices.getMDIManager().closeWindow(NotificationDialog.this); |
|
539 |
} |
|
540 |
}); |
|
541 |
|
|
542 |
} |
|
543 |
return acceptNoShowButton; |
|
544 |
} |
|
545 |
|
|
281 | 546 |
} // @jve:decl-index=0:visual-constraint="10,10" |
547 |
|
|
548 |
// [eiel-gestion-excepciones] |
Also available in: Unified diff