root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / DefaultCoordinateReferenceSystemSelectorComponent.java @ 852
History | View | Annotate | Download (7.74 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 java.awt.event.KeyAdapter; |
30 |
import java.awt.event.KeyEvent; |
31 |
import javax.swing.JComponent; |
32 |
import javax.swing.event.ListDataEvent; |
33 |
import javax.swing.event.ListDataListener; |
34 |
import javax.swing.event.ListSelectionEvent; |
35 |
import javax.swing.event.ListSelectionListener; |
36 |
|
37 |
import org.slf4j.Logger; |
38 |
import org.slf4j.LoggerFactory; |
39 |
|
40 |
import org.gvsig.proj.CoordinateReferenceSystem; |
41 |
import org.gvsig.proj.catalog.CRSDefinition; |
42 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
43 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingManager; |
44 |
import org.gvsig.proj.swing.impl.DefaultCoordinateReferenceSystemSelectorComponentView; |
45 |
|
46 |
/**
|
47 |
* Default implementation for the
|
48 |
* {@link CoordinateReferenceSystemSelectorComponent}.
|
49 |
*
|
50 |
* @author gvSIG Team
|
51 |
* @version $Id$
|
52 |
*/
|
53 |
public class DefaultCoordinateReferenceSystemSelectorComponent |
54 |
extends DefaultCoordinateReferenceSystemSelectorComponentView
|
55 |
//implements CoordinateReferenceSystemSelectorComponent
|
56 |
{ |
57 |
|
58 |
private static final Logger LOG = LoggerFactory |
59 |
.getLogger(DefaultCoordinateReferenceSystemSelectorComponent.class); |
60 |
|
61 |
private static final long serialVersionUID = 2965442763236823977L; |
62 |
|
63 |
private final CoordinateReferenceSystemSwingManager uimanager; |
64 |
|
65 |
private CodeListModel codeModel;
|
66 |
|
67 |
private AuthorityComboBoxModel authorityModel;
|
68 |
|
69 |
public DefaultCoordinateReferenceSystemSelectorComponent(
|
70 |
final DefaultCoordinateReferenceSystemSwingManager uimanager) {
|
71 |
|
72 |
this.uimanager = uimanager;
|
73 |
this.initComponents();
|
74 |
} |
75 |
|
76 |
private void initComponents() { |
77 |
|
78 |
this.lblAutority.setText(uimanager.getTranslation("authority") + ":"); |
79 |
this.lblCode.setText(uimanager.getTranslation("code") + ":"); |
80 |
this.lblDefinition.setText(uimanager.getTranslation("definition") + ":"); |
81 |
this.btnSearch.setText(uimanager.getTranslation("Search")); |
82 |
|
83 |
authorityModel = new AuthorityComboBoxModel(uimanager.getCatalogManager());
|
84 |
this.cboAuthority.setModel(authorityModel);
|
85 |
|
86 |
codeModel = new CodeListModel(uimanager.getCatalogManager(), authorityModel);
|
87 |
this.lstCodes.setModel(codeModel);
|
88 |
codeModel.addListDataListener(new ListDataListener() { |
89 |
|
90 |
@Override
|
91 |
public void intervalRemoved(ListDataEvent e) { |
92 |
// Nothing to do
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public void intervalAdded(ListDataEvent e) { |
97 |
// Nothing to do
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public void contentsChanged(ListDataEvent e) { |
102 |
// A new code has been selected
|
103 |
txtDefinition.setText("");
|
104 |
CoordinateReferenceSystem crs = |
105 |
getSelectedCoordinateReferenceSystem(); |
106 |
if (crs != null) { |
107 |
/* cmi tmp
|
108 |
try {
|
109 |
txtDefinition.setText(crs.getDefinition().toWKT());
|
110 |
} catch (org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException e1) {
|
111 |
// TODO Auto-generated catch block
|
112 |
e1.printStackTrace();
|
113 |
} catch (UnsupportedOperationException e1) {
|
114 |
// TODO Auto-generated catch block
|
115 |
e1.printStackTrace();
|
116 |
}*/
|
117 |
} |
118 |
} |
119 |
}); |
120 |
|
121 |
this.btnSearch.addActionListener(new ActionListener() { |
122 |
|
123 |
@Override
|
124 |
public void actionPerformed(ActionEvent ae) { |
125 |
codeModel.applyFilter(txtCode.getText()); |
126 |
} |
127 |
}); |
128 |
this.txtCode.addKeyListener(new KeyAdapter() { |
129 |
|
130 |
@Override
|
131 |
public void keyTyped(KeyEvent e) { |
132 |
if( e.getKeyChar()=='\n') { |
133 |
codeModel.applyFilter(txtCode.getText()); |
134 |
} else if( e.getKeyChar()=='\033') { |
135 |
txtCode.setText("");
|
136 |
codeModel.applyFilter("");
|
137 |
} |
138 |
|
139 |
super.keyTyped(e); //To change body of generated methods, choose Tools | Templates. |
140 |
} |
141 |
}); |
142 |
|
143 |
lstCodes.addListSelectionListener(new ListSelectionListener() { |
144 |
|
145 |
@Override
|
146 |
public void valueChanged(ListSelectionEvent e) { |
147 |
CoordinateReferenceSystem crs = getSelectedCoordinateReferenceSystem(); |
148 |
if( crs == null ) { |
149 |
txtDefinition.setText("");
|
150 |
} else {/* cmi tmp |
151 |
try {
|
152 |
txtDefinition.setText(crs.getDefinition().toWKT());
|
153 |
} catch (org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException e1) {
|
154 |
// TODO Auto-generated catch block
|
155 |
e1.printStackTrace();
|
156 |
} catch (UnsupportedOperationException e1) {
|
157 |
// TODO Auto-generated catch block
|
158 |
e1.printStackTrace();
|
159 |
} */
|
160 |
} |
161 |
} |
162 |
}); |
163 |
|
164 |
} |
165 |
|
166 |
// cmi tmp @Override
|
167 |
public JComponent asJComponent() { |
168 |
return this; |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public Dimension getPreferredSize() { |
173 |
Dimension dim = super.getPreferredSize(); |
174 |
if( dim.width<350 ) { |
175 |
dim.width = 350;
|
176 |
} |
177 |
return dim;
|
178 |
} |
179 |
|
180 |
public CoordinateReferenceSystem getSelectedCoordinateReferenceSystem() {
|
181 |
CoordinateReferenceSystem crs = null;
|
182 |
String authority = authorityModel.getSelectedAuthority();
|
183 |
String code = (String) this.lstCodes.getSelectedValue(); |
184 |
if (authority != null && code != null) { |
185 |
/* cmi tmp
|
186 |
try {
|
187 |
CRSDefinition def = uimanager.getCatalogManager().getCRSDefinition(authority+":"+code);
|
188 |
return uimanager.getCRSManager().getCoordinateReferenceSystem(def);
|
189 |
} catch (UnsupportedCoordinateReferenceSystemException e) {
|
190 |
LOG.error("Could not find CRS with authority: " + authority
|
191 |
+ " and code: " + code, e);
|
192 |
} catch (org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException e) {
|
193 |
// TODO Auto-generated catch block
|
194 |
e.printStackTrace();
|
195 |
} catch (CoordinateReferenceSystemException e) {
|
196 |
// TODO Auto-generated catch block
|
197 |
e.printStackTrace();
|
198 |
}*/
|
199 |
} |
200 |
return crs;
|
201 |
} |
202 |
|
203 |
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { |
204 |
if (crs != null) { |
205 |
CRSDefinition definition;/*
|
206 |
try {
|
207 |
definition = crs.getDefinition();
|
208 |
authorityModel.setSelectedAuthority(definition.getAuthorityName());
|
209 |
this.lstCodes.setSelectedValue(definition.getIdentifier(), true);
|
210 |
this.txtDefinition.setText(definition.toWKT());
|
211 |
} catch (org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException
|
212 |
| UnsupportedOperationException e) {
|
213 |
// TODO Auto-generated catch block
|
214 |
e.printStackTrace();
|
215 |
}*/
|
216 |
} |
217 |
} |
218 |
} |