1 |
package skrueger.geotools; |
2 |
|
3 |
import javax.swing.JLabel; |
4 |
|
5 |
import schmitzm.geotools.gui.SelectableXMapPane; |
6 |
import schmitzm.geotools.gui.XMapPaneEvent; |
7 |
import schmitzm.geotools.map.event.JMapPaneListener; |
8 |
|
9 |
public class CrsLabel extends JLabel { |
10 |
|
11 |
private JMapPaneListener listenForCrsChange = new JMapPaneListener() { |
12 |
|
13 |
@Override |
14 |
public void performMapPaneEvent(XMapPaneEvent e) { |
15 |
updateCrs(); |
16 |
} |
17 |
}; |
18 |
|
19 |
private final SelectableXMapPane mapPane; |
20 |
|
21 |
CrsLabel(SelectableXMapPane mapPane) { |
22 |
super(); |
23 |
this.mapPane = mapPane; |
24 |
|
25 |
mapPane.addMapPaneListener(listenForCrsChange); |
26 |
|
27 |
updateCrs(); |
28 |
} |
29 |
|
30 |
public void updateCrs() { |
31 |
try { |
32 |
setText("CRS:" |
33 |
+ mapPane.getMapContext().getCoordinateReferenceSystem() |
34 |
.getName().toString()); |
35 |
} catch (Exception e) { |
36 |
setText("CRS:" + "NONE"); |
37 |
} |
38 |
} |
39 |
|
40 |
@Override |
41 |
protected void finalize() throws Throwable { |
42 |
super.finalize(); |
43 |
if (mapPane != null) |
44 |
mapPane.removeMapPaneListener(listenForCrsChange); |
45 |
} |
46 |
|
47 |
} |