Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal / src / main / java / es / gva / cit / jgdal / DiagSignalHandler.java @ 22081

History | View | Annotate | Download (2.12 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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 es.gva.cit.jgdal;
20
import java.awt.BorderLayout;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
23

    
24
import javax.swing.JButton;
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28

    
29
import sun.misc.Signal;
30
import sun.misc.SignalHandler;
31

    
32
class DiagSignalHandler implements SignalHandler {
33
                         
34
                private SignalHandler oldHandler;
35
                private static boolean active = false;
36

    
37
                //Static method to install the signal handler
38
                public static DiagSignalHandler install(String signalName) {
39
                        Signal diagSignal = new Signal(signalName);
40
                                DiagSignalHandler diagHandler = new DiagSignalHandler();
41
                        diagHandler.oldHandler = Signal.handle(diagSignal,diagHandler);
42
                                return diagHandler;
43
                }
44
                // Signal handler method
45
                public void handle(Signal sig) {
46
        if(active)
47
                return;
48
        active = true;
49
        JFrame frame = new JFrame();
50
        frame.setSize(400, 150);
51
        JPanel p = new JPanel();
52
        JLabel l = new JLabel("SIGSEGV signal handler. Signal: " + sig);
53
        p.setLayout(new BorderLayout());
54
        JButton b = new JButton("Close");
55
        b.addActionListener(new ActionListener() {
56
                public void actionPerformed(ActionEvent e) {
57
                        System.out.println("Handler test");
58
                }
59
        });
60
        p.add(l, BorderLayout.NORTH);
61
        p.add(b, BorderLayout.SOUTH);
62

    
63
        frame.getContentPane().add(p);
64
        frame.show();
65
                 }
66
}