root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / TransformationNadgridsPanel.java @ 8676
History | View | Annotate | Download (11 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
|
3 |
|
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.GridLayout; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
import java.io.File; |
11 |
import java.io.FileNotFoundException; |
12 |
import java.io.IOException; |
13 |
import java.io.RandomAccessFile; |
14 |
|
15 |
import javax.swing.BorderFactory; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JFileChooser; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JRadioButton; |
21 |
import javax.swing.JTextArea; |
22 |
import javax.swing.JTextField; |
23 |
import javax.swing.filechooser.FileFilter; |
24 |
|
25 |
import org.cresques.cts.IProjection; |
26 |
import org.cresques.ui.DefaultDialogPanel; |
27 |
import org.gvsig.crs.CrsException; |
28 |
import org.gvsig.crs.CrsFactory; |
29 |
import org.gvsig.crs.CrsWkt; |
30 |
import org.gvsig.crs.ICrs; |
31 |
|
32 |
import au.com.objectix.jgridshift.GridShiftFile; |
33 |
import au.com.objectix.jgridshift.SubGrid; |
34 |
|
35 |
import com.iver.andami.PluginServices; |
36 |
import com.iver.andami.ui.mdiManager.IWindow; |
37 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
38 |
|
39 |
public class TransformationNadgridsPanel extends DefaultDialogPanel implements IWindow, ActionListener { |
40 |
|
41 |
private static final long serialVersionUID = 1L; |
42 |
|
43 |
private JPanel groupRadioButton = null; |
44 |
private JLabel jLabelChooser = null; |
45 |
private JRadioButton jRadioButtonSource = null; |
46 |
private JRadioButton jRadioButtonTarget = null; |
47 |
|
48 |
private IProjection firstProj;
|
49 |
private String nad = null; |
50 |
String[] targetAuthority; |
51 |
String targetAbrev = ""; |
52 |
String sourceAbrev = ""; |
53 |
|
54 |
private String cadWKT = ""; |
55 |
private int codeEpsg; |
56 |
|
57 |
private JPanel jPanelOpen; |
58 |
private JLabel jLabelOpenGsb; |
59 |
private JTextField jTextOpen; |
60 |
private JFileChooser openFileChooser; |
61 |
private JButton jButtonOpen; |
62 |
//private TreeListContainer treeList = null;
|
63 |
private TreePanel treePanel = null; |
64 |
|
65 |
|
66 |
private JPanel jPanel; |
67 |
private JTextArea jTextAreaInfo; |
68 |
|
69 |
boolean targetNad = false; |
70 |
|
71 |
public TransformationNadgridsPanel() {
|
72 |
//nad = "+nadgrids=sped2et.gsb";
|
73 |
nad = "+nadgrids=sped2et.gsb";
|
74 |
} |
75 |
|
76 |
public JPanel getJPanel(){ |
77 |
if (jPanel == null) { |
78 |
jPanel = new JPanel(); |
79 |
jPanel.setLayout(new GridLayout(1,4)); |
80 |
jPanel.setLayout(new FlowLayout(FlowLayout.LEADING,5,10)); |
81 |
jPanel.setPreferredSize(new Dimension(525, 110)); |
82 |
jPanel.setBorder( |
83 |
BorderFactory.createCompoundBorder(
|
84 |
BorderFactory.createCompoundBorder(
|
85 |
BorderFactory.createTitledBorder("+"+PluginServices.getText(this,"nadgrids")), |
86 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
87 |
jPanel.getBorder())); |
88 |
jPanel.add(getJPanelOpen()); |
89 |
jPanel.add(getJLabelChooser()); |
90 |
jPanel.add(getGroupRadioButton()); |
91 |
initializeTreeList(); |
92 |
jPanel.add(getTreePanel()); |
93 |
} |
94 |
return jPanel;
|
95 |
} |
96 |
|
97 |
private JPanel getGroupRadioButton() { |
98 |
if (groupRadioButton == null) { |
99 |
groupRadioButton = new JPanel(); |
100 |
groupRadioButton.setLayout(new GridLayout(1,0)); |
101 |
groupRadioButton.setPreferredSize(new Dimension(400,30)); |
102 |
groupRadioButton.add(getJRadioButtonSource()); |
103 |
groupRadioButton.add(getJRadioButtonTarget()); |
104 |
} |
105 |
return groupRadioButton;
|
106 |
} |
107 |
|
108 |
private JRadioButton getJRadioButtonSource() { |
109 |
if (jRadioButtonSource == null) { |
110 |
jRadioButtonSource = new JRadioButton(); |
111 |
jRadioButtonSource.setSelected(true);
|
112 |
jRadioButtonSource.addActionListener(this);
|
113 |
} |
114 |
jRadioButtonSource.setText(PluginServices.getText(this,"aplicar_capa") + " " + getSourceAbrev() ); |
115 |
return jRadioButtonSource;
|
116 |
} |
117 |
|
118 |
|
119 |
private JRadioButton getJRadioButtonTarget() { |
120 |
if (jRadioButtonTarget == null) { |
121 |
jRadioButtonTarget = new JRadioButton(); |
122 |
jRadioButtonTarget.setSelected(false);
|
123 |
jRadioButtonTarget.addActionListener(this);
|
124 |
} |
125 |
jRadioButtonTarget.setText(PluginServices.getText(this,"aplicar_vista") + " " + getTargetAbrev()); |
126 |
return jRadioButtonTarget;
|
127 |
} |
128 |
|
129 |
private JLabel getJLabelChooser(){ |
130 |
jLabelChooser = new JLabel(); |
131 |
jLabelChooser.setPreferredSize(new Dimension(400, 20)); |
132 |
jLabelChooser.setText(PluginServices.getText(this, "seleccion_nadgrids")+":"); |
133 |
return jLabelChooser;
|
134 |
} |
135 |
|
136 |
private Component getJTextAreaInfo() { |
137 |
if (jTextAreaInfo == null){ |
138 |
jTextAreaInfo = new JTextArea(); |
139 |
jTextAreaInfo.setLineWrap(true);
|
140 |
jTextAreaInfo.setWrapStyleWord(true);
|
141 |
jTextAreaInfo.setPreferredSize(new Dimension(400, 100)); |
142 |
jTextAreaInfo.setEditable(false);
|
143 |
jTextAreaInfo.setText(getWKT()); |
144 |
} |
145 |
jTextAreaInfo.setText(getWKT()); |
146 |
return jTextAreaInfo;
|
147 |
} |
148 |
|
149 |
private JPanel getJPanelOpen() { |
150 |
if(jPanelOpen == null) { |
151 |
jPanelOpen = new JPanel(); |
152 |
jPanelOpen.setPreferredSize(new Dimension(525,50)); |
153 |
jPanelOpen.setLayout(new GridLayout(2,2)); |
154 |
jPanelOpen.setLayout(new FlowLayout(FlowLayout.LEFT,5,5)); |
155 |
jPanelOpen.add(getJLabelOpenGsb(), null);
|
156 |
jPanelOpen.add(getOpenTextField(), null);
|
157 |
jPanelOpen.add(getJButtonOpen(), null);
|
158 |
} |
159 |
return jPanelOpen;
|
160 |
} |
161 |
|
162 |
private JLabel getJLabelOpenGsb() { |
163 |
if(jLabelOpenGsb == null) { |
164 |
jLabelOpenGsb = new JLabel(); |
165 |
jLabelOpenGsb.setPreferredSize(new Dimension(80,20)); |
166 |
jLabelOpenGsb.setText(PluginServices.getText(this,"abrir")+" .gsb:"); |
167 |
} |
168 |
return jLabelOpenGsb;
|
169 |
} |
170 |
|
171 |
private JTextField getOpenTextField() { |
172 |
if(jTextOpen == null) { |
173 |
jTextOpen = new JTextField(); |
174 |
jTextOpen.setPreferredSize(new Dimension(200,20)); |
175 |
jTextOpen.setText("");
|
176 |
} |
177 |
return jTextOpen;
|
178 |
} |
179 |
|
180 |
private JFileChooser getOpenFileChooser(){ |
181 |
if(openFileChooser == null){ |
182 |
openFileChooser = new JFileChooser(); |
183 |
openFileChooser.setEnabled(false);
|
184 |
openFileChooser.addChoosableFileFilter(new FiltroNadgrids());
|
185 |
} |
186 |
return openFileChooser;
|
187 |
} |
188 |
|
189 |
private JButton getJButtonOpen() { |
190 |
if(jButtonOpen == null) { |
191 |
jButtonOpen = new JButton(); |
192 |
jButtonOpen.setText("");
|
193 |
jButtonOpen.setPreferredSize(new Dimension(20,20)); |
194 |
jButtonOpen.setText("...");
|
195 |
jButtonOpen.addActionListener(this);
|
196 |
} |
197 |
return jButtonOpen;
|
198 |
} |
199 |
|
200 |
public ICrs getProjection() {
|
201 |
ICrs crs; |
202 |
if (jRadioButtonSource.isSelected()){
|
203 |
try {
|
204 |
setNad(false);
|
205 |
crs = new CrsFactory().getCRS(getCode(),
|
206 |
getWKT()); |
207 |
crs.setNadGrid(nad); |
208 |
return crs;
|
209 |
} catch (org.gvsig.crs.CrsException e) {
|
210 |
e.printStackTrace(); |
211 |
} |
212 |
return null; |
213 |
} |
214 |
else {
|
215 |
setNad(true);
|
216 |
try {
|
217 |
crs = new CrsFactory().getCRS(getCode(),
|
218 |
getWKT()); |
219 |
crs.setNadGrid(nad); |
220 |
crs.setNadInTarget(true);
|
221 |
|
222 |
return crs;
|
223 |
} catch (CrsException e) {
|
224 |
e.printStackTrace(); |
225 |
} |
226 |
return null; |
227 |
} |
228 |
} |
229 |
|
230 |
public void setProjection(IProjection proj) { |
231 |
firstProj = proj; |
232 |
} |
233 |
|
234 |
public void setNad(boolean nadg){ |
235 |
targetNad = nadg; |
236 |
} |
237 |
|
238 |
public boolean getNad(){ |
239 |
return targetNad;
|
240 |
} |
241 |
|
242 |
public void setCode(int cod){ |
243 |
codeEpsg = cod; |
244 |
} |
245 |
|
246 |
public int getCode(){ |
247 |
return codeEpsg;
|
248 |
} |
249 |
|
250 |
public void setWKT(String cad){ |
251 |
cadWKT = cad; |
252 |
CrsWkt parser = new CrsWkt(cad);
|
253 |
setSourceAbrev(parser.getAuthority()[0], parser.getAuthority()[1]); |
254 |
getJTextAreaInfo(); |
255 |
getJRadioButtonSource(); |
256 |
} |
257 |
|
258 |
public String getWKT(){ |
259 |
return cadWKT;
|
260 |
} |
261 |
|
262 |
public void setTargetAuthority(String[] authority){ |
263 |
targetAuthority = authority; |
264 |
setTargetAbrev(targetAuthority[0], targetAuthority[1]); |
265 |
getJRadioButtonTarget(); |
266 |
} |
267 |
|
268 |
public String[] getTargetAuthority(){ |
269 |
return targetAuthority;
|
270 |
} |
271 |
|
272 |
public void setTargetAbrev(String fuente, String codigo){ |
273 |
targetAbrev = "(" + fuente + ":" + codigo + ")"; |
274 |
} |
275 |
|
276 |
public String getTargetAbrev() { |
277 |
return targetAbrev;
|
278 |
} |
279 |
|
280 |
public void setSourceAbrev(String fuente, String codigo){ |
281 |
sourceAbrev = "(" + fuente + ":" + codigo + ")"; |
282 |
} |
283 |
|
284 |
public String getSourceAbrev(){ |
285 |
return sourceAbrev;
|
286 |
} |
287 |
|
288 |
public WindowInfo getWindowInfo() {
|
289 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
290 |
m_viewinfo.setTitle(PluginServices.getText(this,"nadgrids")); |
291 |
return m_viewinfo;
|
292 |
} |
293 |
|
294 |
public void actionPerformed(ActionEvent e) { |
295 |
// TODO Auto-generated method stub
|
296 |
if (e.getSource() == this.getJRadioButtonSource()){ |
297 |
jRadioButtonSource.setSelected(true);
|
298 |
jRadioButtonTarget.setSelected(false);
|
299 |
} |
300 |
|
301 |
if (e.getSource() == this.getJRadioButtonTarget()){ |
302 |
jRadioButtonTarget.setSelected(true);
|
303 |
jRadioButtonSource.setSelected(false);
|
304 |
} |
305 |
|
306 |
if (e.getSource() == this.getJButtonOpen()){ |
307 |
jPanelOpen.add(getOpenFileChooser(), null);
|
308 |
//openChooser.setCurrentDirectory(f);
|
309 |
int returnVal = openFileChooser.showOpenDialog(TransformationNadgridsPanel.this);
|
310 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
311 |
File file = openFileChooser.getSelectedFile();
|
312 |
jTextOpen.setText(file.getAbsolutePath()); |
313 |
} |
314 |
} |
315 |
} |
316 |
|
317 |
public TreePanel getTreePanel() {
|
318 |
/*if (treeList == null){
|
319 |
treeList = new TreeListContainer(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb");
|
320 |
treeList.getTree().expandRow(0);
|
321 |
treeList.setComponentSize(530,220);
|
322 |
}
|
323 |
return treeList;*/
|
324 |
if (treePanel == null){ |
325 |
treePanel = new TreePanel(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb"); |
326 |
treePanel.getTree().expandRow(0);
|
327 |
treePanel.setPanelSize(530,220); |
328 |
} |
329 |
return treePanel;
|
330 |
} |
331 |
|
332 |
private void initializeTreeList(){ |
333 |
// leer el fichero nadgrids
|
334 |
RandomAccessFile raFile = null; |
335 |
try {
|
336 |
raFile = new RandomAccessFile("./gvSIG/extensiones/org.gvsig.crs/data/sped2et.gsb","r"); |
337 |
} catch (FileNotFoundException e) { |
338 |
// TODO Auto-generated catch block
|
339 |
e.printStackTrace(); |
340 |
} |
341 |
GridShiftFile gsf = new GridShiftFile();
|
342 |
try {
|
343 |
gsf.loadGridShiftFile(raFile); |
344 |
} catch (IOException e) { |
345 |
// TODO Auto-generated catch block
|
346 |
e.printStackTrace(); |
347 |
} |
348 |
|
349 |
SubGrid subGrid[] = gsf.getSubGridTree();
|
350 |
|
351 |
for (int i=0;i<subGrid.length;i++){ |
352 |
getTreePanel().addClass(subGrid[i].getSubGridName(),i); |
353 |
getTreePanel().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMinLon()),subGrid[i].getSubGridName(), ""); |
354 |
getTreePanel().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()),subGrid[i].getSubGridName(), ""); |
355 |
getTreePanel().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMaxLon()),subGrid[i].getSubGridName(), ""); |
356 |
getTreePanel().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()),subGrid[i].getSubGridName(), ""); |
357 |
getTreePanel().addEntry(PluginServices.getText(this,"node_count")+": "+String.valueOf(subGrid[i].getNodeCount()),subGrid[i].getSubGridName(), ""); |
358 |
getTreePanel().addEntry(PluginServices.getText(this,"detalles")+": "+String.valueOf(subGrid[i].getDetails()),subGrid[i].getSubGridName(), ""); |
359 |
} |
360 |
getTreePanel().getTree().expandRow(0);
|
361 |
getTreePanel().getList().setText(PluginServices.getText(this,"advertencia_nad")); |
362 |
} |
363 |
|
364 |
} |
365 |
|
366 |
class FiltroNadgrids extends FileFilter { |
367 |
|
368 |
final static String gsb = "gsb"; |
369 |
public boolean accept(File f) { |
370 |
if (f.isDirectory()) {
|
371 |
return true; |
372 |
} |
373 |
String s = f.getName();
|
374 |
int i = s.lastIndexOf('.'); |
375 |
|
376 |
if (i > 0 && i < s.length() - 1) { |
377 |
String extension = s.substring(i+1).toLowerCase(); |
378 |
if (gsb.equals(extension)){
|
379 |
return true; |
380 |
} else {
|
381 |
return false; |
382 |
} |
383 |
} |
384 |
return false; |
385 |
} |
386 |
|
387 |
public String getDescription() { |
388 |
return "Archivos .gsb"; |
389 |
} |
390 |
|
391 |
} |