svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / AndamiEventQueue.java @ 41312
History | View | Annotate | Download (3.3 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.andami.ui; |
||
25 | |||
26 | import java.awt.AWTEvent; |
||
27 | import java.awt.EventQueue; |
||
28 | import java.awt.event.MouseEvent; |
||
29 | |||
30 | import javax.swing.JOptionPane; |
||
31 | |||
32 | import org.gvsig.andami.PluginServices; |
||
33 | import org.gvsig.andami.messages.Messages; |
||
34 | import org.gvsig.andami.messages.NotificationManager; |
||
35 | import org.slf4j.Logger; |
||
36 | import org.slf4j.LoggerFactory; |
||
37 | |||
38 | |||
39 | |||
40 | /**
|
||
41 | * DOCUMENT ME!
|
||
42 | *
|
||
43 | * @author Fernando Gonz?lez Cort?s
|
||
44 | */
|
||
45 | public class AndamiEventQueue extends EventQueue { |
||
46 | private static Logger logger = LoggerFactory.getLogger(AndamiEventQueue.class); |
||
47 | |||
48 | protected void dispatchEvent(AWTEvent event){ |
||
49 | try{
|
||
50 | super.dispatchEvent(event);
|
||
51 | } catch(RuntimeException e){ |
||
52 | |||
53 | if (canShowWindow(e, event)) {
|
||
54 | NotificationManager.addError(e);//Messages.getString("PluginServices.Bug en el c?digo"), e);
|
||
55 | } else {
|
||
56 | try {
|
||
57 | PluginServices.getMainFrame().getStatusBar().message(e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
||
58 | } catch(Throwable ex) { |
||
59 | // Ignora cualquier error que se produzca intentando mostrar el mensaje de error y nos
|
||
60 | // conformaremos con que este en el log.
|
||
61 | } |
||
62 | logger.info("Error dispaching event",e);
|
||
63 | } |
||
64 | |||
65 | } catch (Error e){ |
||
66 | NotificationManager.addError( |
||
67 | Messages.getString("Error de la applicacion. \nEs conveniente que salga de la aplicaci?n\n\n"+e.getLocalizedMessage()), e);
|
||
68 | } |
||
69 | } |
||
70 | |||
71 | private boolean canShowWindow(Throwable th, AWTEvent event) { |
||
72 | |||
73 | try {
|
||
74 | if( event instanceof MouseEvent ) { |
||
75 | MouseEvent me = (MouseEvent)event; |
||
76 | if( me.getButton() == 0 && me.getClickCount()==0 ) { |
||
77 | // Intentamos que los errores que se produzcan con los eventos de movimiento del raton
|
||
78 | // no provoquen la aparicion de la ventana de errores ya que llega a bloquear al usuario.
|
||
79 | // Intentaremos sacarlos en la barra de estado si podemos.
|
||
80 | return false; |
||
81 | } |
||
82 | } |
||
83 | StackTraceElement[] stack_ee = th.getStackTrace(); |
||
84 | for (int i=0; i<stack_ee.length; i++) { |
||
85 | StackTraceElement se = stack_ee[i];
|
||
86 | if (se.getClassName().startsWith("org.gvsig.fmap.mapcontrol.MapControl")) { |
||
87 | return false; |
||
88 | } |
||
89 | } |
||
90 | } catch (Throwable t) { |
||
91 | |||
92 | } |
||
93 | return true; |
||
94 | |||
95 | } |
||
96 | } |