root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / TransformationNadgridsPanel.java @ 7823
History | View | Annotate | Download (7.97 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.io.File; |
10 |
|
11 |
import javax.swing.BorderFactory; |
12 |
import javax.swing.JButton; |
13 |
import javax.swing.JFileChooser; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JRadioButton; |
17 |
import javax.swing.JScrollPane; |
18 |
import javax.swing.JTextArea; |
19 |
import javax.swing.JTextField; |
20 |
|
21 |
import org.cresques.cts.IProjection; |
22 |
import org.cresques.ui.DefaultDialogPanel; |
23 |
import org.gvsig.crs.CrsException; |
24 |
import org.gvsig.crs.CrsFactory; |
25 |
import org.gvsig.crs.ICrs; |
26 |
|
27 |
import com.iver.andami.PluginServices; |
28 |
import com.iver.andami.ui.mdiManager.IWindow; |
29 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
30 |
|
31 |
public class TransformationNadgridsPanel extends DefaultDialogPanel implements IWindow { |
32 |
|
33 |
private static final long serialVersionUID = 1L; |
34 |
|
35 |
private JPanel groupRadioButton = null; |
36 |
private JLabel chooserLabel = null; |
37 |
private JRadioButton sourceRadioButton = null; |
38 |
private JRadioButton targetRadioButton = null; |
39 |
|
40 |
private IProjection firstProj;
|
41 |
private String nad = null; |
42 |
|
43 |
private String cadWKT = ""; |
44 |
private int codeEpsg; |
45 |
|
46 |
private JPanel jPaneOpen; |
47 |
private JLabel open_gsb; |
48 |
private JTextField jTextOpen; |
49 |
private JFileChooser openChooser; |
50 |
private JButton jButtonOpen; |
51 |
File f = new File("C:/Archivos de programa/FWTools1.0.0a7/proj_lib"); |
52 |
|
53 |
private JPanel panel; |
54 |
private JLabel wkt; |
55 |
private JTextArea info; |
56 |
private JScrollPane areaScrollPane; |
57 |
boolean targetNad = false; |
58 |
|
59 |
public TransformationNadgridsPanel() {
|
60 |
nad = "+nadgrids=sped2et.gsb";
|
61 |
} |
62 |
|
63 |
public JPanel getJPanel(){ |
64 |
if (panel == null) { |
65 |
panel = new JPanel(); |
66 |
panel.setLayout(new GridLayout(1,4)); |
67 |
panel.setLayout(new FlowLayout(FlowLayout.LEADING,5,10)); |
68 |
panel.setPreferredSize(new Dimension(525, 110)); |
69 |
panel.setBorder( |
70 |
BorderFactory.createCompoundBorder(
|
71 |
BorderFactory.createCompoundBorder(
|
72 |
BorderFactory.createTitledBorder("+nadgrids"), |
73 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
74 |
panel.getBorder())); |
75 |
panel.add(getLabel()); |
76 |
panel.add(getScrollPanelArea()); |
77 |
panel.add(getOpenPanel()); |
78 |
panel.add(getJLabel()); |
79 |
panel.add(getGroupRadioButton()); |
80 |
} |
81 |
return panel;
|
82 |
} |
83 |
|
84 |
private JPanel getGroupRadioButton() { |
85 |
if (groupRadioButton == null) { |
86 |
groupRadioButton = new JPanel(); |
87 |
groupRadioButton.setLayout(new GridLayout(1,0)); |
88 |
groupRadioButton.setPreferredSize(new Dimension(400,30)); |
89 |
groupRadioButton.add(getNadgridsSource()); |
90 |
groupRadioButton.add(getNadgridsTarget()); |
91 |
} |
92 |
return groupRadioButton;
|
93 |
} |
94 |
|
95 |
private JRadioButton getNadgridsSource() { |
96 |
if (sourceRadioButton == null) { |
97 |
sourceRadioButton = new JRadioButton(); |
98 |
sourceRadioButton.setText(PluginServices.getText(this,"Aplicar a fuente"));//setText("By Code EPSG"); |
99 |
sourceRadioButton.setSelected(true);
|
100 |
sourceRadioButton.addActionListener(new java.awt.event.ActionListener() {
|
101 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
102 |
sourceRadioButton_actionPerformed(e); |
103 |
} |
104 |
}); |
105 |
} |
106 |
return sourceRadioButton;
|
107 |
} |
108 |
|
109 |
private void sourceRadioButton_actionPerformed(ActionEvent e) { |
110 |
sourceRadioButton.setSelected(true);
|
111 |
targetRadioButton.setSelected(false);
|
112 |
} |
113 |
|
114 |
private JRadioButton getNadgridsTarget() { |
115 |
if (targetRadioButton == null) { |
116 |
targetRadioButton = new JRadioButton(); |
117 |
targetRadioButton.setText(PluginServices.getText(this,"Aplicar a destino"));//setText("By Code EPSG"); |
118 |
targetRadioButton.setSelected(false);
|
119 |
targetRadioButton.addActionListener(new java.awt.event.ActionListener() {
|
120 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
121 |
targetRadioButton_actionPerformed(e); |
122 |
} |
123 |
}); |
124 |
} |
125 |
return targetRadioButton;
|
126 |
} |
127 |
|
128 |
private void targetRadioButton_actionPerformed(ActionEvent e) { |
129 |
targetRadioButton.setSelected(true);
|
130 |
sourceRadioButton.setSelected(false);
|
131 |
} |
132 |
|
133 |
private JLabel getJLabel(){ |
134 |
chooserLabel = new JLabel(); |
135 |
chooserLabel.setPreferredSize(new Dimension(400, 20)); |
136 |
chooserLabel.setText(PluginServices.getText(this, "Seleccione donde quiere aplicar Nadgrids: ")); |
137 |
return chooserLabel;
|
138 |
} |
139 |
|
140 |
private JScrollPane getScrollPanelArea() { |
141 |
if(areaScrollPane == null) { |
142 |
areaScrollPane = new JScrollPane(getInfo()); |
143 |
areaScrollPane.setVerticalScrollBarPolicy( |
144 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
145 |
areaScrollPane.setPreferredSize(new Dimension(420, 100)); |
146 |
areaScrollPane.setBorder( |
147 |
BorderFactory.createCompoundBorder(
|
148 |
BorderFactory.createCompoundBorder(
|
149 |
BorderFactory.createTitledBorder("Wkt"), |
150 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
151 |
areaScrollPane.getBorder())); |
152 |
} |
153 |
return areaScrollPane;
|
154 |
} |
155 |
|
156 |
private Component getLabel() { |
157 |
if (wkt == null){ |
158 |
wkt = new JLabel(); |
159 |
wkt.setPreferredSize(new Dimension(90, 80)); |
160 |
wkt.setText(PluginServices.getText(this,"Cadena WKT: ")); |
161 |
} |
162 |
return wkt;
|
163 |
} |
164 |
|
165 |
private Component getInfo() { |
166 |
if (info == null){ |
167 |
info = new JTextArea(); |
168 |
info.setLineWrap(true);
|
169 |
info.setWrapStyleWord(true);
|
170 |
info.setPreferredSize(new Dimension(400, 100)); |
171 |
info.setEditable(false);
|
172 |
info.setText(getWKT()); |
173 |
} |
174 |
info.setText(getWKT()); |
175 |
return info;
|
176 |
} |
177 |
|
178 |
private JPanel getOpenPanel() { |
179 |
if(jPaneOpen == null) { |
180 |
jPaneOpen = new JPanel(); |
181 |
jPaneOpen.setPreferredSize(new Dimension(525,50)); |
182 |
jPaneOpen.setLayout(new GridLayout(2,2)); |
183 |
jPaneOpen.setLayout(new FlowLayout(FlowLayout.LEFT,5,5)); |
184 |
jPaneOpen.add(getOpenGsb(), null);
|
185 |
jPaneOpen.add(getOpenTextField(), null);
|
186 |
jPaneOpen.add(getButtonOpen(), null);
|
187 |
} |
188 |
return jPaneOpen;
|
189 |
} |
190 |
|
191 |
private JLabel getOpenGsb() { |
192 |
if(open_gsb == null) { |
193 |
open_gsb = new JLabel(); |
194 |
open_gsb.setPreferredSize(new Dimension(80,20)); |
195 |
open_gsb.setText(PluginServices.getText(this,"Abrir .gsb:")); |
196 |
} |
197 |
return open_gsb;
|
198 |
} |
199 |
|
200 |
private JTextField getOpenTextField() { |
201 |
if(jTextOpen == null) { |
202 |
jTextOpen = new JTextField(); |
203 |
jTextOpen.setPreferredSize(new Dimension(200,20)); |
204 |
jTextOpen.setText("");
|
205 |
} |
206 |
return jTextOpen;
|
207 |
} |
208 |
|
209 |
private JFileChooser getOpen(){ |
210 |
if(openChooser == null){ |
211 |
openChooser = new JFileChooser(); |
212 |
openChooser.setEnabled(false);
|
213 |
} |
214 |
return openChooser;
|
215 |
} |
216 |
|
217 |
private JButton getButtonOpen() { |
218 |
if(jButtonOpen == null) { |
219 |
jButtonOpen = new JButton(); |
220 |
jButtonOpen.setText("");
|
221 |
jButtonOpen.setPreferredSize(new Dimension(20,20)); |
222 |
jButtonOpen.addActionListener(new java.awt.event.ActionListener() {
|
223 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
224 |
Open_actionPerformed(e); |
225 |
} |
226 |
}); |
227 |
} |
228 |
return jButtonOpen;
|
229 |
} |
230 |
|
231 |
private void Open_actionPerformed(ActionEvent e){ |
232 |
jPaneOpen.add(getOpen(), null);
|
233 |
openChooser.setCurrentDirectory(f); |
234 |
int returnVal = openChooser.showOpenDialog(TransformationNadgridsPanel.this);
|
235 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
236 |
File file = openChooser.getSelectedFile();
|
237 |
jTextOpen.setText(file.getAbsolutePath()); |
238 |
} |
239 |
} |
240 |
|
241 |
public ICrs getProjection() {
|
242 |
ICrs crs; |
243 |
if (sourceRadioButton.isSelected()){
|
244 |
try {
|
245 |
setNad(false);
|
246 |
crs = new CrsFactory().getCRS(getCode(),
|
247 |
getWKT(),nad); |
248 |
return crs;
|
249 |
} catch (org.gvsig.crs.CrsException e) {
|
250 |
e.printStackTrace(); |
251 |
} |
252 |
return null; |
253 |
} |
254 |
else {
|
255 |
setNad(true);
|
256 |
try {
|
257 |
crs = new CrsFactory().getCRS(getCode(),
|
258 |
getWKT()); |
259 |
return crs;
|
260 |
} catch (CrsException e) {
|
261 |
e.printStackTrace(); |
262 |
} |
263 |
return null; |
264 |
} |
265 |
} |
266 |
|
267 |
public void setProjection(IProjection proj) { |
268 |
firstProj = proj; |
269 |
} |
270 |
|
271 |
public void setNad(boolean nadg){ |
272 |
targetNad = nadg; |
273 |
} |
274 |
|
275 |
public boolean getNad(){ |
276 |
return targetNad;
|
277 |
} |
278 |
|
279 |
public void setCode(int cod){ |
280 |
codeEpsg = cod; |
281 |
} |
282 |
|
283 |
public int getCode(){ |
284 |
return codeEpsg;
|
285 |
} |
286 |
|
287 |
public void setWKT(String cad){ |
288 |
cadWKT = cad; |
289 |
getInfo(); |
290 |
} |
291 |
|
292 |
public String getWKT(){ |
293 |
return cadWKT;
|
294 |
} |
295 |
|
296 |
public WindowInfo getWindowInfo() {
|
297 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
298 |
m_viewinfo.setTitle(PluginServices.getText(this,"Nadgrids")); |
299 |
return m_viewinfo;
|
300 |
} |
301 |
} |