root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / CRSSelectionDialog.java @ 8149
History | View | Annotate | Download (8.77 KB)
1 |
package org.gvsig.crs.gui; |
---|---|
2 |
|
3 |
import java.awt.CardLayout; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.event.ItemEvent; |
7 |
import java.awt.event.ItemListener; |
8 |
import java.awt.event.TextEvent; |
9 |
import java.awt.event.TextListener; |
10 |
|
11 |
import javax.swing.JOptionPane; |
12 |
import javax.swing.JPanel; |
13 |
import javax.swing.ListSelectionModel; |
14 |
import javax.swing.event.DocumentEvent; |
15 |
import javax.swing.event.DocumentListener; |
16 |
import javax.swing.event.ListSelectionEvent; |
17 |
import javax.swing.event.ListSelectionListener; |
18 |
|
19 |
import org.cresques.cts.IProjection; |
20 |
import org.gvsig.crs.ICrs; |
21 |
import org.gvsig.crs.persistence.CrsData; |
22 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
23 |
|
24 |
import com.iver.andami.PluginServices; |
25 |
import com.iver.andami.ui.mdiManager.IWindow; |
26 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
27 |
|
28 |
/**
|
29 |
* Di?logo contenedor para la selecci?n de CRS.
|
30 |
* (para el CRS de la vista)
|
31 |
*/
|
32 |
public class CRSSelectionDialog extends JPanel implements IWindow, ActionListener, ListSelectionListener, ItemListener, DocumentListener { |
33 |
|
34 |
private static final long serialVersionUID = 1L; |
35 |
|
36 |
JPanel contentPane = null; |
37 |
public CRSMainPanel vp = null; |
38 |
private IProjection lastProj = null; |
39 |
int code = 0; |
40 |
String dataSource = ""; |
41 |
|
42 |
private boolean okPressed = false; |
43 |
|
44 |
public CRSSelectionDialog(){
|
45 |
super();
|
46 |
initialize(); |
47 |
} |
48 |
|
49 |
public void initialize(){ |
50 |
vp = new CRSMainPanel();
|
51 |
vp.getJComboOptions().addItemListener(this);
|
52 |
this.add(getContentPanel(), null); |
53 |
listenerTablas(); |
54 |
vp.getJButtonAccept().addActionListener(this);
|
55 |
vp.getJButtonCancel().addActionListener(this);
|
56 |
vp.esp.getJTextOpen().getDocument().addDocumentListener(this);
|
57 |
} |
58 |
|
59 |
public boolean isOkPressed() { return okPressed; } |
60 |
|
61 |
public CRSMainPanel getProjPanel() {
|
62 |
return (CRSMainPanel) getContentPanel();
|
63 |
} |
64 |
|
65 |
public JPanel getContentPanel() { |
66 |
if (contentPane == null) { |
67 |
contentPane = vp; |
68 |
|
69 |
} |
70 |
return contentPane;
|
71 |
} |
72 |
|
73 |
public void listenerTablas(){ |
74 |
ListSelectionModel rowSM = vp.ep.getJTable().getSelectionModel();
|
75 |
rowSM.addListSelectionListener(this);
|
76 |
|
77 |
ListSelectionModel rowSMiau = vp.iau.getJTable().getSelectionModel();
|
78 |
rowSMiau.addListSelectionListener(this);
|
79 |
|
80 |
ListSelectionModel rowSMrecents = vp.rp.getJTable().getSelectionModel();
|
81 |
rowSMrecents.addListSelectionListener(this);
|
82 |
} |
83 |
|
84 |
public void setCode(int cod){ |
85 |
code = cod; |
86 |
} |
87 |
|
88 |
public int getCode(){ |
89 |
return code;
|
90 |
} |
91 |
|
92 |
public IProjection getProjection() {
|
93 |
return (IProjection) getProjPanel().getProjection();
|
94 |
} |
95 |
/**
|
96 |
* @param proj
|
97 |
*/
|
98 |
public void setProjection(IProjection proj) { |
99 |
lastProj = proj; |
100 |
getProjPanel().setProjection(proj); |
101 |
} |
102 |
|
103 |
public String getProjectionAbrev(){ |
104 |
return (String) getProjPanel().getProjection().getAbrev(); |
105 |
} |
106 |
|
107 |
public void actionPerformed(ActionEvent e) { |
108 |
if (e.getSource() == vp.getJButtonAccept()){
|
109 |
lastProj = getProjection(); |
110 |
setDataSource(vp.getDataSource()); |
111 |
if (lastProj != null){ |
112 |
/*
|
113 |
* Actualizar recientes...
|
114 |
*/
|
115 |
String authority = ((ICrs)lastProj).getCrsWkt().getAuthority()[0]; |
116 |
String wkt = ((ICrs)lastProj).getWKT();
|
117 |
String name = ((ICrs)lastProj).getCrsWkt().getName();
|
118 |
int code = ((ICrs)lastProj).getCode();
|
119 |
CrsData crsData = new CrsData(authority,code,name,wkt);
|
120 |
RecentCRSsPersistence persistence = new RecentCRSsPersistence(RecentCRSsPersistence.pluginClassInstance);
|
121 |
persistence.addCrsData(crsData); |
122 |
|
123 |
|
124 |
PluginServices.getMDIManager().closeWindow(CRSSelectionDialog.this); |
125 |
okPressed = true;
|
126 |
} |
127 |
else {
|
128 |
okPressed = false;
|
129 |
} |
130 |
} |
131 |
|
132 |
if (e.getSource() == vp.getJButtonCancel()){
|
133 |
setProjection(lastProj); |
134 |
PluginServices.getMDIManager().closeWindow(CRSSelectionDialog.this); |
135 |
okPressed = false;
|
136 |
} |
137 |
} |
138 |
|
139 |
public void setDataSource(String sour){ |
140 |
dataSource = sour; |
141 |
} |
142 |
|
143 |
public String getDataSource(){ |
144 |
return dataSource;
|
145 |
} |
146 |
|
147 |
public WindowInfo getWindowInfo() {
|
148 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
149 |
m_viewinfo.setTitle(PluginServices.getText(this, "Nuevo CRS")); |
150 |
return m_viewinfo;
|
151 |
} |
152 |
|
153 |
public void valueChanged(ListSelectionEvent e) { |
154 |
if (e.getSource() == vp.rp.getJTable().getSelectionModel()){
|
155 |
ListSelectionModel lsm = (ListSelectionModel)e.getSource(); |
156 |
|
157 |
if (lsm.isSelectionEmpty()) {
|
158 |
vp.rp.selectedRowTable = -1;
|
159 |
vp.rp.setCodeCRS(-1);
|
160 |
vp.getJButtonAccept().setEnabled(false);
|
161 |
setCode(0);
|
162 |
|
163 |
} |
164 |
else {
|
165 |
vp.rp.selectedRowTable = lsm.getMinSelectionIndex(); |
166 |
|
167 |
vp.rp.setCodeCRS(Integer.parseInt((String)vp.rp.sorter.getValueAt(vp.rp.selectedRowTable,1))); |
168 |
vp.rp.setWKT((String)vp.rp.sorter.getValueAt(vp.rp.selectedRowTable,0)); |
169 |
setCode(vp.rp.getCodeCRS()); |
170 |
vp.getJButtonAccept().setEnabled(true);
|
171 |
} |
172 |
} |
173 |
|
174 |
if (e.getSource() == vp.iau.getJTable().getSelectionModel()){
|
175 |
ListSelectionModel lsm = (ListSelectionModel)e.getSource(); |
176 |
|
177 |
if (lsm.isSelectionEmpty()) {
|
178 |
vp.iau.selectedRowTable = -1;
|
179 |
vp.iau.setCodeCRS(-1);
|
180 |
vp.getJButtonAccept().setEnabled(false);
|
181 |
setCode(0);
|
182 |
|
183 |
} |
184 |
else {
|
185 |
vp.iau.selectedRowTable = lsm.getMinSelectionIndex(); |
186 |
String cadWKT = (String)vp.iau.sorter.getValueAt(vp.iau.selectedRowTable,1); |
187 |
|
188 |
vp.iau.setCodeCRS(Integer.parseInt((String)vp.iau.sorter.getValueAt(vp.iau.selectedRowTable,0))); |
189 |
cadWKT = cadWKT.substring(0, cadWKT.length()-1) + ", AUTHORITY[\"IAU2000\","+ vp.iau.getCodeCRS()+"]]"; |
190 |
vp.iau.setWKT(cadWKT); |
191 |
setCode(vp.iau.getCodeCRS()); |
192 |
vp.getJButtonAccept().setEnabled(true);
|
193 |
} |
194 |
} |
195 |
|
196 |
if (e.getSource() == vp.ep.getJTable().getSelectionModel()){
|
197 |
String[] not_soported = {"engineering", "vertical", "compound", "geocentric"}; |
198 |
boolean soported = true; |
199 |
ListSelectionModel lsm = (ListSelectionModel)e.getSource(); |
200 |
|
201 |
if (lsm.isSelectionEmpty()) {
|
202 |
vp.ep.selectedRowTable = -1;
|
203 |
vp.ep.setCodeCRS(-1);
|
204 |
vp.getJButtonAccept().setEnabled(false);
|
205 |
vp.ep.getInfoCrs().setEnabled(false);
|
206 |
setCode(0);
|
207 |
|
208 |
} |
209 |
else {
|
210 |
vp.ep.selectedRowTable = lsm.getMinSelectionIndex(); |
211 |
String crs_kind = (String)vp.ep.sorter.getValueAt(vp.ep.selectedRowTable,2); |
212 |
for (int i = 0; i < not_soported.length; i++) { |
213 |
if (crs_kind.equals(not_soported[i])){
|
214 |
soported = false;
|
215 |
} |
216 |
} |
217 |
if (soported){
|
218 |
vp.ep.setCodeCRS(Integer.parseInt((String)vp.ep.sorter.getValueAt(vp.ep.selectedRowTable,0))); |
219 |
vp.ep.setWKT(); |
220 |
setCode(vp.ep.epsg_code); |
221 |
vp.getJButtonAccept().setEnabled(true);
|
222 |
|
223 |
} |
224 |
else {
|
225 |
JOptionPane.showMessageDialog(CRSSelectionDialog.this, "CRS no soportado.", "Warning...", |
226 |
JOptionPane.WARNING_MESSAGE);
|
227 |
vp.ep.setCodeCRS(-1);
|
228 |
setCode(0);
|
229 |
vp.getJButtonAccept().setEnabled(false);
|
230 |
vp.ep.getInfoCrs().setEnabled(false);
|
231 |
} |
232 |
vp.ep.getInfoCrs().setEnabled(true);
|
233 |
|
234 |
} |
235 |
} |
236 |
} |
237 |
|
238 |
public void itemStateChanged(ItemEvent e) { |
239 |
CardLayout cl = (CardLayout)(vp.jPanelMain.getLayout()); |
240 |
String op = (String)e.getItem(); |
241 |
if (op.equals("EPSG")){ |
242 |
vp.ep.connection(); |
243 |
if(vp.ep.getJTable().getSelectedRowCount()>0) |
244 |
vp.getJButtonAccept().setEnabled(true);
|
245 |
else
|
246 |
vp.getJButtonAccept().setEnabled(false);
|
247 |
|
248 |
} else if (op.equals("IAU2000")) { |
249 |
vp.iau.connection(); |
250 |
if(vp.iau.getJTable().getSelectedRowCount()>0) |
251 |
vp.getJButtonAccept().setEnabled(true);
|
252 |
else
|
253 |
vp.getJButtonAccept().setEnabled(false);
|
254 |
}else if (op.equals("Recientes")) { |
255 |
if(vp.rp.getJTable().getSelectedRowCount()>0) |
256 |
vp.getJButtonAccept().setEnabled(true);
|
257 |
else
|
258 |
vp.getJButtonAccept().setEnabled(false);
|
259 |
} |
260 |
else if (op.equals("ESRI")) { |
261 |
if(vp.esp.getJTextOpen().getText().length()>0) |
262 |
vp.getJButtonAccept().setEnabled(true);
|
263 |
else
|
264 |
vp.getJButtonAccept().setEnabled(false);
|
265 |
} |
266 |
cl.show(vp.jPanelMain, (String)e.getItem());
|
267 |
vp.setDataSource((String)e.getItem());
|
268 |
} |
269 |
|
270 |
|
271 |
|
272 |
public void changedUpdate(DocumentEvent e) { |
273 |
|
274 |
} |
275 |
|
276 |
private void update(DocumentEvent e) { |
277 |
if( e.getDocument() == vp.esp.getJTextOpen().getDocument()){
|
278 |
if(vp.esp.getJTextOpen().getText().length()>0) |
279 |
vp.getJButtonAccept().setEnabled(true);
|
280 |
else
|
281 |
vp.getJButtonAccept().setEnabled(false);
|
282 |
} |
283 |
} |
284 |
|
285 |
public void insertUpdate(DocumentEvent e) { |
286 |
update(e); |
287 |
} |
288 |
|
289 |
public void removeUpdate(DocumentEvent e) { |
290 |
update(e); |
291 |
} |
292 |
} |