root / org.gvsig.proj / trunk / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / DefaultCoordinateReferenceSystemSelectorComponent.java @ 476
History | View | Annotate | Download (5.15 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 2
|
9 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.proj.swing.impl; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import javax.swing.JComponent; |
30 |
import javax.swing.event.ListDataEvent; |
31 |
import javax.swing.event.ListDataListener; |
32 |
|
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
import org.gvsig.proj.CoordinateReferenceSystem; |
37 |
import org.gvsig.proj.CoordinateReferenceSystemNotFoundException; |
38 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
39 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingManager; |
40 |
|
41 |
/**
|
42 |
* Default implementation for the
|
43 |
* {@link CoordinateReferenceSystemSelectorComponent}.
|
44 |
*
|
45 |
* @author gvSIG Team
|
46 |
* @version $Id$
|
47 |
*/
|
48 |
public class DefaultCoordinateReferenceSystemSelectorComponent extends DefaultCoordinateReferenceSystemSelectorComponentView |
49 |
implements CoordinateReferenceSystemSelectorComponent {
|
50 |
|
51 |
private static final Logger LOG = LoggerFactory |
52 |
.getLogger(DefaultCoordinateReferenceSystemSelectorComponent.class); |
53 |
|
54 |
private static final long serialVersionUID = 2965442763236823977L; |
55 |
|
56 |
private final CoordinateReferenceSystemSwingManager uimanager; |
57 |
|
58 |
private CodeListModel codeModel;
|
59 |
|
60 |
private AuthorityComboBoxModel authorityModel;
|
61 |
|
62 |
public DefaultCoordinateReferenceSystemSelectorComponent(
|
63 |
final DefaultCoordinateReferenceSystemSwingManager uimanager) {
|
64 |
|
65 |
this.uimanager = uimanager;
|
66 |
this.initComponents();
|
67 |
} |
68 |
|
69 |
private void initComponents() { |
70 |
|
71 |
this.lblAutority.setText(uimanager.getTranslation("authority") + ":"); |
72 |
this.lblCode.setText(uimanager.getTranslation("code") + ":"); |
73 |
this.lblDefinition.setText(uimanager.getTranslation("definition") + ":"); |
74 |
this.btnSearch.setText(uimanager.getTranslation("Search")); |
75 |
|
76 |
authorityModel = new AuthorityComboBoxModel(uimanager.getManager());
|
77 |
this.cboAuthority.setModel(authorityModel);
|
78 |
|
79 |
codeModel = new CodeListModel(uimanager.getManager(), authorityModel);
|
80 |
this.lstCodes.setModel(codeModel);
|
81 |
codeModel.addListDataListener(new ListDataListener() { |
82 |
|
83 |
@Override
|
84 |
public void intervalRemoved(ListDataEvent e) { |
85 |
// Nothing to do
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void intervalAdded(ListDataEvent e) { |
90 |
// Nothing to do
|
91 |
} |
92 |
|
93 |
@Override
|
94 |
public void contentsChanged(ListDataEvent e) { |
95 |
// A new code has been selected
|
96 |
txtDefinition.setText("");
|
97 |
CoordinateReferenceSystem crs = |
98 |
getSelectedCoordinateReferenceSystem(); |
99 |
if (crs != null) { |
100 |
txtDefinition.setText(crs.getDefinition()); |
101 |
} |
102 |
} |
103 |
}); |
104 |
|
105 |
this.btnSearch.addActionListener(new ActionListener() { |
106 |
|
107 |
@Override
|
108 |
public void actionPerformed(ActionEvent ae) { |
109 |
codeModel.applyFilter(txtCode.getText()); |
110 |
} |
111 |
}); |
112 |
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public JComponent asJComponent() { |
117 |
return this; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public Dimension getPreferredSize() { |
122 |
Dimension dim = super.getPreferredSize(); |
123 |
if( dim.width<350 ) { |
124 |
dim.width = 350;
|
125 |
} |
126 |
return dim;
|
127 |
} |
128 |
|
129 |
public CoordinateReferenceSystem getSelectedCoordinateReferenceSystem() {
|
130 |
CoordinateReferenceSystem crs = null;
|
131 |
String authority = authorityModel.getSelectedAuthority();
|
132 |
String code = (String) this.lstCodes.getSelectedValue(); |
133 |
if (authority != null && code != null) { |
134 |
try {
|
135 |
crs = uimanager.getManager().getCoordinateReferenceSystem( |
136 |
authority, code |
137 |
); |
138 |
} catch (CoordinateReferenceSystemNotFoundException e) {
|
139 |
LOG.error("Could not find CRS with authority: " + authority
|
140 |
+ " and code: " + code, e);
|
141 |
} |
142 |
} |
143 |
return crs;
|
144 |
} |
145 |
|
146 |
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { |
147 |
if (crs != null) { |
148 |
authorityModel.setSelectedAuthority(crs.getAuthorityName()); |
149 |
this.lstCodes.setSelectedValue(crs.getCode(), true); |
150 |
} |
151 |
} |
152 |
} |