Revision 12065
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/DiagSignalHandler.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
package org.gvsig.rastertools; |
|
20 |
|
|
21 |
import java.awt.BorderLayout; |
|
22 |
import java.awt.event.ActionEvent; |
|
23 |
import java.awt.event.ActionListener; |
|
24 |
|
|
25 |
import javax.swing.JButton; |
|
26 |
import javax.swing.JFrame; |
|
27 |
import javax.swing.JLabel; |
|
28 |
import javax.swing.JPanel; |
|
29 |
|
|
30 |
import sun.misc.Signal; |
|
31 |
import sun.misc.SignalHandler; |
|
32 |
/** |
|
33 |
* Prueba de manejador de se?ales SIGALRM lanzadas desde las librer?as nativas. |
|
34 |
* |
|
35 |
* @version 30/03/2007 |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class DiagSignalHandler implements SignalHandler { |
|
39 |
// private SignalHandler oldHandler; |
|
40 |
private static boolean active = false; |
|
41 |
|
|
42 |
//Static method to install the signal handler |
|
43 |
public static DiagSignalHandler install(String signalName) { |
|
44 |
Signal diagSignal = new Signal(signalName); |
|
45 |
DiagSignalHandler diagHandler = new DiagSignalHandler(); |
|
46 |
// diagHandler.oldHandler = |
|
47 |
Signal.handle(diagSignal, diagHandler); |
|
48 |
return diagHandler; |
|
49 |
} |
|
50 |
|
|
51 |
// Signal handler method |
|
52 |
public void handle(Signal sig) { |
|
53 |
if (active) |
|
54 |
return; |
|
55 |
active = true; |
|
56 |
JFrame frame = new JFrame(); |
|
57 |
frame.setSize(410, 200); |
|
58 |
JPanel p = new JPanel(); |
|
59 |
JLabel l = new JLabel("Su gvSIG ha petado convenientemente. Enga, ?A cascarla!"); |
|
60 |
p.setLayout(new BorderLayout()); |
|
61 |
JButton b = new JButton("Cerrar"); |
|
62 |
b.addActionListener(new ActionListener() { |
|
63 |
public void actionPerformed(ActionEvent e) { |
|
64 |
System.exit(0); |
|
65 |
} |
|
66 |
}); |
|
67 |
p.add(l, BorderLayout.CENTER); |
|
68 |
JPanel p1 = new JPanel(); |
|
69 |
p1.add(b); |
|
70 |
p.add(p1, BorderLayout.SOUTH); |
|
71 |
|
|
72 |
frame.getContentPane().add(p); |
|
73 |
frame.show(); |
|
74 |
System.out.println("Handler called for signal " + sig); |
|
75 |
} |
|
76 |
} |
Also available in: Unified diff