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