svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / TransformationNadgridsPanel.java @ 8627
History | View | Annotate | Download (10.4 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 |
import org.gvsig.gui.beans.treelist.TreeListContainer; |
32 |
|
33 |
import au.com.objectix.jgridshift.GridShiftFile; |
34 |
import au.com.objectix.jgridshift.SubGrid; |
35 |
|
36 |
import com.iver.andami.PluginServices; |
37 |
import com.iver.andami.ui.mdiManager.IWindow; |
38 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
39 |
|
40 |
public class TransformationNadgridsPanel extends DefaultDialogPanel implements IWindow, ActionListener { |
41 |
|
42 |
private static final long serialVersionUID = 1L; |
43 |
|
44 |
private JPanel groupRadioButton = null; |
45 |
private JLabel jLabelChooser = null; |
46 |
private JRadioButton jRadioButtonSource = null; |
47 |
private JRadioButton jRadioButtonTarget = null; |
48 |
|
49 |
private IProjection firstProj;
|
50 |
private String nad = null; |
51 |
String[] targetAuthority; |
52 |
String targetAbrev = ""; |
53 |
String sourceAbrev = ""; |
54 |
|
55 |
private String cadWKT = ""; |
56 |
private int codeEpsg; |
57 |
|
58 |
private JPanel jPanelOpen; |
59 |
private JLabel jLabelOpenGsb; |
60 |
private JTextField jTextOpen; |
61 |
private JFileChooser openFileChooser; |
62 |
private JButton jButtonOpen; |
63 |
private TreeListContainer treeList = 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(getTreeList()); |
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(),nad); |
207 |
return crs;
|
208 |
} catch (org.gvsig.crs.CrsException e) {
|
209 |
e.printStackTrace(); |
210 |
} |
211 |
return null; |
212 |
} |
213 |
else {
|
214 |
setNad(true);
|
215 |
try {
|
216 |
crs = new CrsFactory().getCRS(getCode(),
|
217 |
getWKT()); |
218 |
crs.setNadTarget(nad); |
219 |
|
220 |
return crs;
|
221 |
} catch (CrsException e) {
|
222 |
e.printStackTrace(); |
223 |
} |
224 |
return null; |
225 |
} |
226 |
} |
227 |
|
228 |
public void setProjection(IProjection proj) { |
229 |
firstProj = proj; |
230 |
} |
231 |
|
232 |
public void setNad(boolean nadg){ |
233 |
targetNad = nadg; |
234 |
} |
235 |
|
236 |
public boolean getNad(){ |
237 |
return targetNad;
|
238 |
} |
239 |
|
240 |
public void setCode(int cod){ |
241 |
codeEpsg = cod; |
242 |
} |
243 |
|
244 |
public int getCode(){ |
245 |
return codeEpsg;
|
246 |
} |
247 |
|
248 |
public void setWKT(String cad){ |
249 |
cadWKT = cad; |
250 |
CrsWkt parser = new CrsWkt(cad);
|
251 |
setSourceAbrev(parser.getAuthority()[0], parser.getAuthority()[1]); |
252 |
getJTextAreaInfo(); |
253 |
getJRadioButtonSource(); |
254 |
} |
255 |
|
256 |
public String getWKT(){ |
257 |
return cadWKT;
|
258 |
} |
259 |
|
260 |
public void setTargetAuthority(String[] authority){ |
261 |
targetAuthority = authority; |
262 |
setTargetAbrev(targetAuthority[0], targetAuthority[1]); |
263 |
getJRadioButtonTarget(); |
264 |
} |
265 |
|
266 |
public String[] getTargetAuthority(){ |
267 |
return targetAuthority;
|
268 |
} |
269 |
|
270 |
public void setTargetAbrev(String fuente, String codigo){ |
271 |
targetAbrev = "(" + fuente + ":" + codigo + ")"; |
272 |
} |
273 |
|
274 |
public String getTargetAbrev() { |
275 |
return targetAbrev;
|
276 |
} |
277 |
|
278 |
public void setSourceAbrev(String fuente, String codigo){ |
279 |
sourceAbrev = "(" + fuente + ":" + codigo + ")"; |
280 |
} |
281 |
|
282 |
public String getSourceAbrev(){ |
283 |
return sourceAbrev;
|
284 |
} |
285 |
|
286 |
public WindowInfo getWindowInfo() {
|
287 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
288 |
m_viewinfo.setTitle(PluginServices.getText(this,"nadgrids")); |
289 |
return m_viewinfo;
|
290 |
} |
291 |
|
292 |
public void actionPerformed(ActionEvent e) { |
293 |
// TODO Auto-generated method stub
|
294 |
if (e.getSource() == this.getJRadioButtonSource()){ |
295 |
jRadioButtonSource.setSelected(true);
|
296 |
jRadioButtonTarget.setSelected(false);
|
297 |
} |
298 |
|
299 |
if (e.getSource() == this.getJRadioButtonTarget()){ |
300 |
jRadioButtonTarget.setSelected(true);
|
301 |
jRadioButtonSource.setSelected(false);
|
302 |
} |
303 |
|
304 |
if (e.getSource() == this.getJButtonOpen()){ |
305 |
jPanelOpen.add(getOpenFileChooser(), null);
|
306 |
//openChooser.setCurrentDirectory(f);
|
307 |
int returnVal = openFileChooser.showOpenDialog(TransformationNadgridsPanel.this);
|
308 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
309 |
File file = openFileChooser.getSelectedFile();
|
310 |
jTextOpen.setText(file.getAbsolutePath()); |
311 |
} |
312 |
} |
313 |
} |
314 |
|
315 |
public TreeListContainer getTreeList() {
|
316 |
if (treeList == null){ |
317 |
treeList = new TreeListContainer(PluginServices.getText(this,"grids_en")+": "+"sped2et.gsb"); |
318 |
treeList.getTree().expandRow(0);
|
319 |
treeList.setComponentSize(530,220); |
320 |
} |
321 |
return treeList;
|
322 |
} |
323 |
|
324 |
private void initializeTreeList(){ |
325 |
// leer el fichero nadgrids
|
326 |
RandomAccessFile raFile = null; |
327 |
try {
|
328 |
raFile = new RandomAccessFile("./gvSIG/extensiones/org.gvsig.crs/data/sped2et.gsb","r"); |
329 |
} catch (FileNotFoundException e) { |
330 |
// TODO Auto-generated catch block
|
331 |
e.printStackTrace(); |
332 |
} |
333 |
GridShiftFile gsf = new GridShiftFile();
|
334 |
try {
|
335 |
gsf.loadGridShiftFile(raFile); |
336 |
} catch (IOException e) { |
337 |
// TODO Auto-generated catch block
|
338 |
e.printStackTrace(); |
339 |
} |
340 |
|
341 |
SubGrid subGrid[] = gsf.getSubGridTree();
|
342 |
|
343 |
for (int i=0;i<subGrid.length;i++){ |
344 |
getTreeList().addClass(subGrid[i].getSubGridName(),i); |
345 |
getTreeList().addEntry(PluginServices.getText(this,"long_min")+": "+String.valueOf(subGrid[i].getMinLon()),subGrid[i].getSubGridName(), ""); |
346 |
getTreeList().addEntry(PluginServices.getText(this,"lat_min")+": "+String.valueOf(subGrid[i].getMinLat()),subGrid[i].getSubGridName(), ""); |
347 |
getTreeList().addEntry(PluginServices.getText(this,"long_max")+": "+String.valueOf(subGrid[i].getMaxLon()),subGrid[i].getSubGridName(), ""); |
348 |
getTreeList().addEntry(PluginServices.getText(this,"lat_max")+": "+String.valueOf(subGrid[i].getMaxLat()),subGrid[i].getSubGridName(), ""); |
349 |
} |
350 |
getTreeList().getTree().expandRow(0);
|
351 |
} |
352 |
|
353 |
} |
354 |
|
355 |
class FiltroNadgrids extends FileFilter { |
356 |
|
357 |
final static String gsb = "gsb"; |
358 |
public boolean accept(File f) { |
359 |
if (f.isDirectory()) {
|
360 |
return true; |
361 |
} |
362 |
String s = f.getName();
|
363 |
int i = s.lastIndexOf('.'); |
364 |
|
365 |
if (i > 0 && i < s.length() - 1) { |
366 |
String extension = s.substring(i+1).toLowerCase(); |
367 |
if (gsb.equals(extension)){
|
368 |
return true; |
369 |
} else {
|
370 |
return false; |
371 |
} |
372 |
} |
373 |
return false; |
374 |
} |
375 |
|
376 |
public String getDescription() { |
377 |
return "Archivos .gsb"; |
378 |
} |
379 |
|
380 |
} |