Revision 11613 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/project/documents/gui/Annotation_Open.java
Annotation_Open.java | ||
---|---|---|
5 | 5 |
import java.awt.GridBagConstraints; |
6 | 6 |
import java.awt.GridBagLayout; |
7 | 7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
|
9 | 8 |
import java.io.File; |
10 | 9 |
import java.io.IOException; |
11 | 10 |
import java.util.ArrayList; |
... | ... | |
49 | 48 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
50 | 49 |
import com.iver.utiles.swing.JComboBox; |
51 | 50 |
|
52 |
|
|
53 | 51 |
/** |
54 | 52 |
* Dialog to open an annotation layer. |
55 |
* |
|
53 |
*
|
|
56 | 54 |
* @author Vicente Caballero Navarro |
57 | 55 |
*/ |
58 | 56 |
public class Annotation_Open extends WizardPanel { |
59 |
private static String lastPath = null; |
|
60 |
private JPanel pGeneral = null; |
|
61 |
private JButton bSelectFile = null; |
|
62 |
private String fName; |
|
63 |
private JTextField tFile; |
|
64 |
private CRSSelectPanel pProyection = null; |
|
65 |
private JPanel pFileSelection; |
|
66 |
private JPanel pControls; |
|
67 |
private JPanel pInPixels; |
|
68 |
private JComboBox cmbInPixels; |
|
69 |
public Annotation_Open() { |
|
70 |
super(); |
|
71 |
initialize(); |
|
72 |
} |
|
57 |
private static String lastPath = null; |
|
73 | 58 |
|
74 |
private void initialize() { |
|
75 |
this.setPreferredSize(new java.awt.Dimension(750, 320)); |
|
76 |
this.setSize(new java.awt.Dimension(510, 311)); |
|
77 |
this.setLocation(new java.awt.Point(0, 0)); |
|
78 |
this.add(getPGeneral(), null); |
|
79 |
this.getBSelectFile().addActionListener(new java.awt.event.ActionListener() { |
|
80 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
81 |
acceptButtonActionPerformed(evt); |
|
82 |
} |
|
83 |
}); |
|
84 |
} |
|
59 |
private JPanel pGeneral = null; |
|
85 | 60 |
|
86 |
/** |
|
87 |
* Evento de pulsado del bot?n de seleccionar fichero |
|
88 |
* |
|
89 |
* @param e |
|
90 |
*/ |
|
91 |
private void acceptButtonActionPerformed(ActionEvent e) { |
|
92 |
//Selector de Fichero que se quiere georeferenciar |
|
93 |
if (e.getSource().equals(this.getBSelectFile())) { |
|
94 |
JFileChooser chooser = new JFileChooser(lastPath); |
|
95 |
chooser.setDialogTitle(PluginServices.getText(this, |
|
96 |
"seleccionar_fichero")); |
|
61 |
private JButton bSelectFile = null; |
|
97 | 62 |
|
98 |
// FileFilter f = new DriverFileFilter("Annotation gvSIG Driver"); |
|
99 |
chooser.addChoosableFileFilter(new FileFilter() { |
|
100 |
public boolean accept(File f) { |
|
101 |
if (f.isDirectory()) { |
|
102 |
return true; |
|
103 |
} |
|
63 |
private String fName; |
|
104 | 64 |
|
105 |
if (isPointShapeType(f)) { |
|
106 |
return f.getAbsolutePath().toLowerCase().endsWith(".shp"); |
|
107 |
} |
|
65 |
private JTextField tFile; |
|
108 | 66 |
|
109 |
return false; |
|
110 |
} |
|
67 |
private CRSSelectPanel pProyection = null; |
|
111 | 68 |
|
112 |
public String getDescription() { |
|
113 |
return PluginServices.getText(this, "Point Shape Files"); |
|
114 |
} |
|
115 |
}); |
|
116 |
chooser.addChoosableFileFilter(new FileFilter() { |
|
117 |
public boolean accept(File f) { |
|
118 |
if (f.isDirectory()) { |
|
119 |
return true; |
|
120 |
} |
|
69 |
private JPanel pFileSelection; |
|
121 | 70 |
|
122 |
String[] files = f.getParentFile().list();
|
|
71 |
private JPanel pControls;
|
|
123 | 72 |
|
124 |
for (int i = 0; i < files.length; i++) { |
|
125 |
if (!files[i].equals(f.getName()) && |
|
126 |
files[i].replaceAll("gva", "shp") |
|
127 |
.toLowerCase().equals(f.getName() |
|
128 |
.toLowerCase())) { |
|
129 |
return (isPointShapeType(f)); |
|
130 |
} |
|
131 |
} |
|
73 |
private JPanel pInPixels; |
|
132 | 74 |
|
133 |
return false; |
|
134 |
} |
|
75 |
private JComboBox cmbInPixels; |
|
135 | 76 |
|
136 |
public String getDescription() {
|
|
137 |
return PluginServices.getText(this, "Annotations");
|
|
138 |
}
|
|
139 |
});
|
|
77 |
public Annotation_Open() {
|
|
78 |
super();
|
|
79 |
initialize();
|
|
80 |
}
|
|
140 | 81 |
|
141 |
int returnVal = chooser.showOpenDialog(this); |
|
82 |
private void initialize() { |
|
83 |
this.setPreferredSize(new java.awt.Dimension(750, 320)); |
|
84 |
this.setSize(new java.awt.Dimension(510, 311)); |
|
85 |
this.setLocation(new java.awt.Point(0, 0)); |
|
86 |
this.add(getPGeneral(), null); |
|
87 |
this.getBSelectFile().addActionListener( |
|
88 |
new java.awt.event.ActionListener() { |
|
89 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
90 |
acceptButtonActionPerformed(evt); |
|
91 |
} |
|
92 |
}); |
|
93 |
} |
|
142 | 94 |
|
143 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
144 |
this.fName = chooser.getSelectedFile().toString(); |
|
95 |
/** |
|
96 |
* Evento de pulsado del bot?n de seleccionar fichero |
|
97 |
* |
|
98 |
* @param e |
|
99 |
*/ |
|
100 |
private void acceptButtonActionPerformed(ActionEvent e) { |
|
101 |
// Selector de Fichero que se quiere georeferenciar |
|
102 |
if (e.getSource().equals(this.getBSelectFile())) { |
|
103 |
JFileChooser chooser = new JFileChooser(lastPath); |
|
104 |
chooser.setDialogTitle(PluginServices.getText(this, |
|
105 |
"seleccionar_fichero")); |
|
145 | 106 |
|
146 |
//FileFilter filter = chooser.getFileFilter(); |
|
147 |
this.getTFile().setText(fName); |
|
148 |
lastPath = chooser.getCurrentDirectory().getAbsolutePath(); |
|
107 |
// FileFilter f = new DriverFileFilter("Annotation gvSIG Driver"); |
|
108 |
chooser.addChoosableFileFilter(new FileFilter() { |
|
109 |
public boolean accept(File f) { |
|
110 |
if (f.isDirectory()) { |
|
111 |
return true; |
|
112 |
} |
|
149 | 113 |
|
150 |
if (PluginServices.getMainFrame() == null) { |
|
151 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose(); |
|
152 |
} else { |
|
153 |
callStateChanged(true); |
|
154 |
// //Creamos la capa y la cargamos |
|
155 |
// try { |
|
156 |
// View theView = null; |
|
157 |
// |
|
158 |
// try { |
|
159 |
// theView = (View) PluginServices.getMDIManager() |
|
160 |
// .getActiveWindow(); |
|
161 |
// } catch (ClassCastException exc) { |
|
162 |
// return; |
|
163 |
// } |
|
164 |
// |
|
165 |
// File fich = new File(fName); |
|
166 |
// boolean ok = loadFileAnnotationLayer(theView.getMapControl(), |
|
167 |
// fich); |
|
168 |
// callStateChanged(ok); |
|
169 |
// } catch (DriverLoadException exc) { |
|
170 |
// NotificationManager.addError("No se pudo acceder a los drivers", |
|
171 |
// exc); |
|
172 |
// } |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
114 |
if (isPointShapeType(f)) { |
|
115 |
return f.getAbsolutePath().toLowerCase().endsWith( |
|
116 |
".shp"); |
|
117 |
} |
|
177 | 118 |
|
178 |
/** |
|
179 |
* This method initializes jTextField |
|
180 |
* |
|
181 |
* @return javax.swing.JTextField |
|
182 |
*/ |
|
183 |
private JTextField getTFile() { |
|
184 |
if (tFile == null) { |
|
185 |
tFile = new JTextField(); |
|
186 |
tFile.setPreferredSize(new java.awt.Dimension(350, 25)); |
|
187 |
} |
|
119 |
return false; |
|
120 |
} |
|
188 | 121 |
|
189 |
return tFile; |
|
190 |
} |
|
122 |
public String getDescription() { |
|
123 |
return PluginServices.getText(this, "Point Shape Files"); |
|
124 |
} |
|
125 |
}); |
|
126 |
chooser.addChoosableFileFilter(new FileFilter() { |
|
127 |
public boolean accept(File f) { |
|
128 |
if (f.isDirectory()) { |
|
129 |
return true; |
|
130 |
} |
|
191 | 131 |
|
192 |
/** |
|
193 |
* This method initializes jPanel |
|
194 |
* |
|
195 |
* @return javax.swing.JPanel |
|
196 |
*/ |
|
197 |
private JPanel getPGeneral() { |
|
198 |
if (pGeneral == null) { |
|
199 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
200 |
gridBagConstraints1.insets = new java.awt.Insets(5, 0, 0, 0); |
|
201 |
gridBagConstraints1.gridy = 3; |
|
202 |
gridBagConstraints1.gridx = 0; |
|
132 |
String[] files = f.getParentFile().list(); |
|
203 | 133 |
|
204 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
205 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); |
|
206 |
gridBagConstraints.gridy = 0; |
|
207 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
|
208 |
gridBagConstraints.gridx = 0; |
|
134 |
for (int i = 0; i < files.length; i++) { |
|
135 |
if (!files[i].equals(f.getName()) |
|
136 |
&& files[i].replaceAll("gva", "shp") |
|
137 |
.toLowerCase().equals( |
|
138 |
f.getName().toLowerCase())) { |
|
139 |
return (isPointShapeType(f)); |
|
140 |
} |
|
141 |
} |
|
209 | 142 |
|
210 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
211 |
gridBagConstraints2.insets = new java.awt.Insets(0, 0, 2, 0); |
|
212 |
gridBagConstraints2.gridy = 1; |
|
213 |
gridBagConstraints2.gridx = 0; |
|
143 |
return false; |
|
144 |
} |
|
214 | 145 |
|
215 |
pGeneral = new JPanel(); |
|
216 |
pGeneral.setLayout(new GridBagLayout()); |
|
217 |
pGeneral.setPreferredSize(new java.awt.Dimension(750, 350)); |
|
218 |
gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH; |
|
219 |
gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH; |
|
220 |
pGeneral.add(getPFileSelection(), gridBagConstraints); |
|
221 |
pGeneral.add(getPControls(), gridBagConstraints1); |
|
222 |
pGeneral.add(getPInPixels(),gridBagConstraints2); |
|
223 |
} |
|
146 |
public String getDescription() { |
|
147 |
return PluginServices.getText(this, "Annotations"); |
|
148 |
} |
|
149 |
}); |
|
224 | 150 |
|
225 |
return pGeneral; |
|
226 |
} |
|
151 |
int returnVal = chooser.showOpenDialog(this); |
|
227 | 152 |
|
228 |
private JPanel getPControls() { |
|
229 |
if (pControls == null) { |
|
230 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
|
231 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
232 |
gridBagConstraints2.gridx = 0; |
|
233 |
gridBagConstraints2.gridy = 1; |
|
234 |
pControls = new JPanel(); |
|
235 |
pControls.setLayout(new GridBagLayout()); |
|
236 |
pControls.setPreferredSize(new java.awt.Dimension(475, 200)); |
|
237 |
pControls.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
238 |
null, "", |
|
239 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
240 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
241 |
gridBagConstraints11.gridx = 0; |
|
242 |
gridBagConstraints11.gridy = 0; |
|
153 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
154 |
this.fName = chooser.getSelectedFile().toString(); |
|
243 | 155 |
|
244 |
// pControls.add(getPCheckUseGeoref(), gridBagConstraints11);
|
|
245 |
pControls.add(getPProyection(), gridBagConstraints2);
|
|
246 |
}
|
|
156 |
// FileFilter filter = chooser.getFileFilter();
|
|
157 |
this.getTFile().setText(fName);
|
|
158 |
lastPath = chooser.getCurrentDirectory().getAbsolutePath();
|
|
247 | 159 |
|
248 |
return pControls; |
|
249 |
} |
|
160 |
if (PluginServices.getMainFrame() == null) { |
|
161 |
((JDialog) (getParent().getParent().getParent().getParent())) |
|
162 |
.dispose(); |
|
163 |
} else { |
|
164 |
callStateChanged(true); |
|
165 |
// //Creamos la capa y la cargamos |
|
166 |
// try { |
|
167 |
// View theView = null; |
|
168 |
// |
|
169 |
// try { |
|
170 |
// theView = (View) PluginServices.getMDIManager() |
|
171 |
// .getActiveWindow(); |
|
172 |
// } catch (ClassCastException exc) { |
|
173 |
// return; |
|
174 |
// } |
|
175 |
// |
|
176 |
// File fich = new File(fName); |
|
177 |
// boolean ok = |
|
178 |
// loadFileAnnotationLayer(theView.getMapControl(), |
|
179 |
// fich); |
|
180 |
// callStateChanged(ok); |
|
181 |
// } catch (DriverLoadException exc) { |
|
182 |
// NotificationManager.addError("No se pudo acceder a los |
|
183 |
// drivers", |
|
184 |
// exc); |
|
185 |
// } |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
250 | 190 |
|
251 |
/** |
|
252 |
* This method initializes jPanel |
|
253 |
* |
|
254 |
* @return javax.swing.JPanel |
|
255 |
*/ |
|
256 |
private JPanel getPFileSelection() { |
|
257 |
if (pFileSelection == null) { |
|
258 |
FlowLayout flowLayout = new FlowLayout(); |
|
259 |
flowLayout.setVgap(10); |
|
260 |
pFileSelection = new JPanel(); |
|
261 |
pFileSelection.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
262 |
null, PluginServices.getText(this, "cargar"), |
|
263 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
264 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
265 |
pFileSelection.setLayout(flowLayout); |
|
266 |
pFileSelection.setPreferredSize(new java.awt.Dimension(475, 70)); |
|
267 |
pFileSelection.add(getTFile(), null); |
|
268 |
pFileSelection.add(getBSelectFile(), null); |
|
269 |
} |
|
191 |
/** |
|
192 |
* This method initializes jTextField |
|
193 |
* |
|
194 |
* @return javax.swing.JTextField |
|
195 |
*/ |
|
196 |
private JTextField getTFile() { |
|
197 |
if (tFile == null) { |
|
198 |
tFile = new JTextField(); |
|
199 |
tFile.setPreferredSize(new java.awt.Dimension(350, 25)); |
|
200 |
} |
|
270 | 201 |
|
271 |
return pFileSelection;
|
|
272 |
}
|
|
202 |
return tFile;
|
|
203 |
}
|
|
273 | 204 |
|
274 |
/** |
|
275 |
* This method initializes jButton |
|
276 |
* |
|
277 |
* @return javax.swing.JButton |
|
278 |
*/ |
|
279 |
private JButton getBSelectFile() { |
|
280 |
if (bSelectFile == null) { |
|
281 |
bSelectFile = new JButton(); |
|
282 |
bSelectFile.setText(PluginServices.getText(this, "cargar")); |
|
283 |
} |
|
205 |
/** |
|
206 |
* This method initializes jPanel |
|
207 |
* |
|
208 |
* @return javax.swing.JPanel |
|
209 |
*/ |
|
210 |
private JPanel getPGeneral() { |
|
211 |
if (pGeneral == null) { |
|
212 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
213 |
gridBagConstraints1.insets = new java.awt.Insets(5, 0, 0, 0); |
|
214 |
gridBagConstraints1.gridy = 3; |
|
215 |
gridBagConstraints1.gridx = 0; |
|
284 | 216 |
|
285 |
return bSelectFile; |
|
286 |
} |
|
217 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
218 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); |
|
219 |
gridBagConstraints.gridy = 0; |
|
220 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
|
221 |
gridBagConstraints.gridx = 0; |
|
287 | 222 |
|
288 |
public void initWizard() { |
|
289 |
// TODO Auto-generated method stub |
|
290 |
} |
|
223 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
224 |
gridBagConstraints2.insets = new java.awt.Insets(0, 0, 2, 0); |
|
225 |
gridBagConstraints2.gridy = 1; |
|
226 |
gridBagConstraints2.gridx = 0; |
|
291 | 227 |
|
292 |
public void execute() { |
|
293 |
//Creamos la capa y la cargamos |
|
294 |
try { |
|
295 |
View theView = null; |
|
228 |
pGeneral = new JPanel(); |
|
229 |
pGeneral.setLayout(new GridBagLayout()); |
|
230 |
pGeneral.setPreferredSize(new java.awt.Dimension(750, 350)); |
|
231 |
gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH; |
|
232 |
gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH; |
|
233 |
pGeneral.add(getPFileSelection(), gridBagConstraints); |
|
234 |
pGeneral.add(getPControls(), gridBagConstraints1); |
|
235 |
pGeneral.add(getPInPixels(), gridBagConstraints2); |
|
236 |
} |
|
296 | 237 |
|
297 |
try { |
|
298 |
theView = (View) PluginServices.getMDIManager() |
|
299 |
.getActiveWindow(); |
|
300 |
} catch (ClassCastException exc) { |
|
301 |
return; |
|
302 |
} |
|
238 |
return pGeneral; |
|
239 |
} |
|
303 | 240 |
|
304 |
File fich = new File(fName); |
|
305 |
boolean ok = loadFileAnnotationLayer(theView.getMapControl(), |
|
306 |
fich); |
|
241 |
private JPanel getPControls() { |
|
242 |
if (pControls == null) { |
|
243 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
|
244 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
245 |
gridBagConstraints2.gridx = 0; |
|
246 |
gridBagConstraints2.gridy = 1; |
|
247 |
pControls = new JPanel(); |
|
248 |
pControls.setLayout(new GridBagLayout()); |
|
249 |
pControls.setPreferredSize(new java.awt.Dimension(475, 200)); |
|
250 |
pControls.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
251 |
null, "", |
|
252 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
253 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, |
|
254 |
null)); |
|
255 |
gridBagConstraints11.gridx = 0; |
|
256 |
gridBagConstraints11.gridy = 0; |
|
307 | 257 |
|
308 |
} catch (DriverLoadException exc) { |
|
309 |
NotificationManager.addError("No se pudo acceder a los drivers", |
|
310 |
exc); |
|
311 |
} |
|
312 |
} |
|
258 |
// pControls.add(getPCheckUseGeoref(), gridBagConstraints11); |
|
259 |
pControls.add(getPProyection(), gridBagConstraints2); |
|
260 |
} |
|
313 | 261 |
|
314 |
public FLayer getLayer() { |
|
315 |
return null; |
|
316 |
} |
|
262 |
return pControls; |
|
263 |
} |
|
317 | 264 |
|
318 |
/** |
|
319 |
* This method initializes jPanel |
|
320 |
* |
|
321 |
* @return javax.swing.JPanel |
|
322 |
*/ |
|
323 |
private CRSSelectPanel getPProyection() { |
|
324 |
if (pProyection == null) { |
|
325 |
pProyection = CRSSelectPanel.getPanel(FOpenDialog.getLastProjection()); |
|
326 |
pProyection.addActionListener(new java.awt.event.ActionListener() { |
|
327 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
328 |
if (pProyection.isOkPressed()) { |
|
329 |
FOpenDialog.setLastProjection(pProyection.getCurProj()); |
|
330 |
} |
|
331 |
} |
|
332 |
}); |
|
333 |
} |
|
265 |
/** |
|
266 |
* This method initializes jPanel |
|
267 |
* |
|
268 |
* @return javax.swing.JPanel |
|
269 |
*/ |
|
270 |
private JPanel getPFileSelection() { |
|
271 |
if (pFileSelection == null) { |
|
272 |
FlowLayout flowLayout = new FlowLayout(); |
|
273 |
flowLayout.setVgap(10); |
|
274 |
pFileSelection = new JPanel(); |
|
275 |
pFileSelection |
|
276 |
.setBorder(javax.swing.BorderFactory |
|
277 |
.createTitledBorder( |
|
278 |
null, |
|
279 |
PluginServices.getText(this, "cargar"), |
|
280 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
281 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, |
|
282 |
null, null)); |
|
283 |
pFileSelection.setLayout(flowLayout); |
|
284 |
pFileSelection.setPreferredSize(new java.awt.Dimension(475, 70)); |
|
285 |
pFileSelection.add(getTFile(), null); |
|
286 |
pFileSelection.add(getBSelectFile(), null); |
|
287 |
} |
|
334 | 288 |
|
335 |
return pProyection; |
|
336 |
} |
|
337 |
/** |
|
338 |
* This method initializes jPanel |
|
339 |
* |
|
340 |
* @return javax.swing.JPanel |
|
341 |
*/ |
|
342 |
private JPanel getPInPixels() { |
|
343 |
if (pInPixels == null) { |
|
344 |
pInPixels = new JPanel();//CRSSelectPanel.getPanel(FOpenDialog.getLastProjection()); |
|
345 |
JLabel lbl=new JLabel(PluginServices.getText(this,"units_of_annotations")); |
|
346 |
pInPixels.add(lbl); |
|
347 |
pInPixels.add(getCmbInPixels()); |
|
348 |
} |
|
289 |
return pFileSelection; |
|
290 |
} |
|
349 | 291 |
|
350 |
return pInPixels; |
|
351 |
} |
|
352 |
private JComboBox getCmbInPixels() { |
|
353 |
if (cmbInPixels==null){ |
|
354 |
cmbInPixels=new JComboBox(); |
|
355 |
cmbInPixels.addItem(PluginServices.getText(this,"pixels")); |
|
356 |
cmbInPixels.addItem(PluginServices.getText(this,"meters")); |
|
357 |
// cmbInPixels.addActionListener(new ActionListener(){ |
|
358 |
// public void actionPerformed(ActionEvent e) { |
|
359 |
// if (e.getSource().equals(PluginServices.getText(this,"pixels"))){ |
|
360 |
// |
|
361 |
// } |
|
362 |
// |
|
363 |
// } |
|
364 |
// |
|
365 |
// }); |
|
366 |
} |
|
367 |
return cmbInPixels; |
|
292 |
/** |
|
293 |
* This method initializes jButton |
|
294 |
* |
|
295 |
* @return javax.swing.JButton |
|
296 |
*/ |
|
297 |
private JButton getBSelectFile() { |
|
298 |
if (bSelectFile == null) { |
|
299 |
bSelectFile = new JButton(); |
|
300 |
bSelectFile.setText(PluginServices.getText(this, "cargar")); |
|
301 |
} |
|
302 |
|
|
303 |
return bSelectFile; |
|
368 | 304 |
} |
369 | 305 |
|
370 |
/* (non-Javadoc) |
|
371 |
* @see com.iver.cit.gvsig.gui.WizardPanel#getTabName() |
|
372 |
*/ |
|
373 |
public String getTabName() { |
|
374 |
return PluginServices.getText(this, "annotation"); |
|
375 |
} |
|
306 |
public void initWizard() { |
|
307 |
// TODO Auto-generated method stub |
|
308 |
} |
|
376 | 309 |
|
377 |
private boolean isPointShapeType(File file) {
|
|
378 |
if (!file.getAbsolutePath().toLowerCase().endsWith(".shp")) {
|
|
379 |
return false;
|
|
380 |
}
|
|
310 |
public void execute() {
|
|
311 |
// Creamos la capa y la cargamos
|
|
312 |
try {
|
|
313 |
View theView = null;
|
|
381 | 314 |
|
382 |
VectorialFileAdapter adapter = new VectorialFileAdapter(file); |
|
383 |
String driverName = "gvSIG shp driver"; |
|
315 |
try { |
|
316 |
theView = (View) PluginServices.getMDIManager() |
|
317 |
.getActiveWindow(); |
|
318 |
} catch (ClassCastException exc) { |
|
319 |
return; |
|
320 |
} |
|
384 | 321 |
|
385 |
try { |
|
386 |
Driver driver = LayerFactory.getDM().getDriver(driverName); |
|
387 |
adapter.setDriver((VectorialDriver) driver); |
|
388 |
} catch (DriverLoadException e) { |
|
389 |
return false; |
|
390 |
} |
|
322 |
File fich = new File(fName); |
|
323 |
boolean ok = loadFileAnnotationLayer(theView.getMapControl(), fich); |
|
391 | 324 |
|
392 |
FLyrVect capa = new FLyrVect(); |
|
393 |
capa.setSource(adapter); |
|
325 |
} catch (DriverLoadException exc) { |
|
326 |
NotificationManager.addError("No se pudo acceder a los drivers", |
|
327 |
exc); |
|
328 |
} |
|
329 |
} |
|
394 | 330 |
|
395 |
int type; |
|
331 |
public FLayer getLayer() { |
|
332 |
return null; |
|
333 |
} |
|
396 | 334 |
|
397 |
try { |
|
398 |
((VectorialFileDriver) capa.getSource().getDriver()).open(file); |
|
399 |
((VectorialFileDriver) capa.getSource().getDriver()).initialize(); |
|
400 |
type = capa.getSource().getShapeType(); |
|
401 |
} catch (DriverIOException e) { |
|
402 |
return false; |
|
403 |
} catch (IOException e) { |
|
404 |
return false; |
|
405 |
} |
|
335 |
/** |
|
336 |
* This method initializes jPanel |
|
337 |
* |
|
338 |
* @return javax.swing.JPanel |
|
339 |
*/ |
|
340 |
private CRSSelectPanel getPProyection() { |
|
341 |
if (pProyection == null) { |
|
342 |
pProyection = CRSSelectPanel.getPanel(FOpenDialog |
|
343 |
.getLastProjection()); |
|
344 |
pProyection.addActionListener(new java.awt.event.ActionListener() { |
|
345 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
346 |
if (pProyection.isOkPressed()) { |
|
347 |
FOpenDialog.setLastProjection(pProyection.getCurProj()); |
|
348 |
} |
|
349 |
} |
|
350 |
}); |
|
351 |
} |
|
406 | 352 |
|
407 |
return (type == FShape.POINT);
|
|
408 |
}
|
|
353 |
return pProyection;
|
|
354 |
}
|
|
409 | 355 |
|
410 |
/**
|
|
411 |
* Adds to mapcontrol all the file based layers selected by user in
|
|
412 |
* fileOpenDialog instance.
|
|
413 |
*
|
|
414 |
* @param mapControl MapControl where we want to add the selected layers
|
|
415 |
* @param file FileOpenDialog where user selected file based layers
|
|
416 |
*
|
|
417 |
* @return boolean flag to report sucess of the operation
|
|
418 |
*/
|
|
419 |
private boolean loadFileAnnotationLayer(MapControl mapControl, File file) {
|
|
420 |
if (file == null) {
|
|
421 |
return false;
|
|
422 |
}
|
|
356 |
/**
|
|
357 |
* This method initializes jPanel
|
|
358 |
*
|
|
359 |
* @return javax.swing.JPanel
|
|
360 |
*/
|
|
361 |
private JPanel getPInPixels() {
|
|
362 |
if (pInPixels == null) {
|
|
363 |
pInPixels = new JPanel();// CRSSelectPanel.getPanel(FOpenDialog.getLastProjection());
|
|
364 |
JLabel lbl = new JLabel(PluginServices.getText(this,
|
|
365 |
"units_of_annotations"));
|
|
366 |
pInPixels.add(lbl);
|
|
367 |
pInPixels.add(getCmbInPixels());
|
|
368 |
}
|
|
423 | 369 |
|
424 |
FLayer lyr = null; |
|
425 |
IProjection proj = FOpenDialog.getLastProjection(); |
|
426 |
String driverName = "gvSIG shp driver"; |
|
427 |
Driver driver = null; // Driver[driverNames.length]; |
|
428 |
ArrayList errors = new ArrayList(); |
|
370 |
return pInPixels; |
|
371 |
} |
|
429 | 372 |
|
430 |
try { |
|
431 |
driver = LayerFactory.getDM().getDriver(driverName); |
|
432 |
} catch (DriverLoadException e) { |
|
433 |
DriverNotLoadedExceptionType type = new DriverNotLoadedExceptionType(); |
|
434 |
type.setDriverName(driverName); |
|
373 |
private JComboBox getCmbInPixels() { |
|
374 |
if (cmbInPixels == null) { |
|
375 |
cmbInPixels = new JComboBox(); |
|
376 |
cmbInPixels.addItem(PluginServices.getText(this, "pixels")); |
|
377 |
cmbInPixels.addItem(PluginServices.getText(this, "meters")); |
|
378 |
// cmbInPixels.addActionListener(new ActionListener(){ |
|
379 |
// public void actionPerformed(ActionEvent e) { |
|
380 |
// if (e.getSource().equals(PluginServices.getText(this,"pixels"))){ |
|
381 |
// |
|
382 |
// } |
|
383 |
// |
|
384 |
// } |
|
385 |
// |
|
386 |
// }); |
|
387 |
} |
|
388 |
return cmbInPixels; |
|
389 |
} |
|
435 | 390 |
|
436 |
DriverException exception = new DriverException(e, type); |
|
437 |
errors.add(exception); |
|
438 |
} |
|
391 |
/* |
|
392 |
* (non-Javadoc) |
|
393 |
* |
|
394 |
* @see com.iver.cit.gvsig.gui.WizardPanel#getTabName() |
|
395 |
*/ |
|
396 |
public String getTabName() { |
|
397 |
return PluginServices.getText(this, "annotation"); |
|
398 |
} |
|
439 | 399 |
|
440 |
// A?adir capas al mapControl se trata como una transaccion |
|
441 |
mapControl.getMapContext().beginAtomicEvent(); |
|
400 |
private boolean isPointShapeType(File file) { |
|
401 |
if (!file.getAbsolutePath().toLowerCase().endsWith(".shp")) { |
|
402 |
return false; |
|
403 |
} |
|
442 | 404 |
|
443 |
String layerName = file.getName(); |
|
444 |
lyr = LayerFactory.createLayer(layerName, (VectorialFileDriver) driver, |
|
445 |
file, proj); |
|
405 |
VectorialFileAdapter adapter = new VectorialFileAdapter(file); |
|
406 |
String driverName = "gvSIG shp driver"; |
|
446 | 407 |
|
447 |
Annotation_Layer al = new Annotation_Layer(); |
|
448 |
LayerListener[] layerListeners = lyr.getLayerListeners(); |
|
408 |
try { |
|
409 |
Driver driver = LayerFactory.getDM().getDriver(driverName); |
|
410 |
adapter.setDriver((VectorialDriver) driver); |
|
411 |
} catch (DriverLoadException e) { |
|
412 |
return false; |
|
413 |
} |
|
449 | 414 |
|
450 |
for (int i = 0; i < layerListeners.length; i++) { |
|
451 |
al.addLayerListener(layerListeners[i]); |
|
452 |
} |
|
415 |
FLyrVect capa = new FLyrVect(); |
|
416 |
capa.setSource(adapter); |
|
453 | 417 |
|
454 |
al.setSource(((FLyrVect) lyr).getSource()); |
|
455 |
al.setProjection(lyr.getProjection()); |
|
456 |
al.setName(layerName); |
|
418 |
int type; |
|
457 | 419 |
|
458 |
try { |
|
459 |
Annotation_Mapping.addAnnotationMapping(al); |
|
460 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
461 |
DriverIOExceptionType type = new DriverIOExceptionType(); |
|
462 |
type.setFile(file); |
|
420 |
try { |
|
421 |
((VectorialFileDriver) capa.getSource().getDriver()).open(file); |
|
422 |
((VectorialFileDriver) capa.getSource().getDriver()).initialize(); |
|
423 |
type = capa.getSource().getShapeType(); |
|
424 |
} catch (DriverIOException e) { |
|
425 |
return false; |
|
426 |
} catch (IOException e) { |
|
427 |
return false; |
|
428 |
} |
|
463 | 429 |
|
464 |
DriverException newException = new DriverException(e, type); |
|
465 |
lyr.addError(newException); |
|
466 |
lyr.setAvailable(false); |
|
467 |
errors.add(newException); |
|
468 |
} |
|
469 |
al.setInPixels(getCmbInPixels().getSelectedItem().equals(PluginServices.getText(this,"pixels"))); |
|
430 |
return (type == FShape.POINT); |
|
431 |
} |
|
470 | 432 |
|
471 |
if (lyr != null) { |
|
472 |
lyr.setVisible(true); |
|
473 |
checkProjection(lyr, mapControl.getViewPort()); |
|
474 |
mapControl.getMapContext().getLayers().addLayer(al); |
|
475 |
} // if |
|
433 |
/** |
|
434 |
* Adds to mapcontrol all the file based layers selected by user in |
|
435 |
* fileOpenDialog instance. |
|
436 |
* |
|
437 |
* @param mapControl |
|
438 |
* MapControl where we want to add the selected layers |
|
439 |
* @param file |
|
440 |
* FileOpenDialog where user selected file based layers |
|
441 |
* |
|
442 |
* @return boolean flag to report sucess of the operation |
|
443 |
*/ |
|
444 |
private boolean loadFileAnnotationLayer(MapControl mapControl, File file) { |
|
445 |
if (file == null) { |
|
446 |
return false; |
|
447 |
} |
|
476 | 448 |
|
477 |
mapControl.getMapContext().endAtomicEvent(); |
|
449 |
FLayer lyr = null; |
|
450 |
IProjection proj = FOpenDialog.getLastProjection(); |
|
451 |
String driverName = "gvSIG shp driver"; |
|
452 |
Driver driver = null; // Driver[driverNames.length]; |
|
453 |
ArrayList errors = new ArrayList(); |
|
478 | 454 |
|
479 |
return true; |
|
480 |
} |
|
455 |
try { |
|
456 |
driver = LayerFactory.getDM().getDriver(driverName); |
|
457 |
} catch (DriverLoadException e) { |
|
458 |
DriverNotLoadedExceptionType type = new DriverNotLoadedExceptionType(); |
|
459 |
type.setDriverName(driverName); |
|
481 | 460 |
|
482 |
//TODO Este m?todo est? igual en AddLayer pero es privado y |
|
483 |
//no est?tico y he tenido que replicar c?digo |
|
484 |
//Comentar a Joaqu?n para la 1.0.3 |
|
485 |
private static void checkProjection(FLayer lyr, ViewPort viewPort) { |
|
486 |
if (lyr instanceof FLayers) { |
|
487 |
FLayers layers = (FLayers) lyr; |
|
461 |
DriverException exception = new DriverException(e, type); |
|
462 |
errors.add(exception); |
|
463 |
} |
|
488 | 464 |
|
489 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
490 |
checkProjection(layers.getLayer(i), viewPort); |
|
491 |
} |
|
492 |
} |
|
465 |
// A?adir capas al mapControl se trata como una transaccion |
|
466 |
mapControl.getMapContext().beginAtomicEvent(); |
|
493 | 467 |
|
494 |
if (lyr instanceof FLyrVect) {
|
|
495 |
FLyrVect lyrVect = (FLyrVect) lyr;
|
|
496 |
IProjection proj = lyr.getProjection();
|
|
468 |
String layerName = file.getName();
|
|
469 |
lyr = LayerFactory.createLayer(layerName, (VectorialFileDriver) driver,
|
|
470 |
file, proj);
|
|
497 | 471 |
|
498 |
// Comprobar que la projecci?n es la misma que la vista |
|
499 |
if (proj == null) { |
|
500 |
// SUPONEMOS que la capa est? en la proyecci?n que |
|
501 |
// estamos pidiendo (que ya es mucho suponer, ya). |
|
502 |
lyrVect.setProjection(viewPort.getProjection()); |
|
472 |
Annotation_Layer al = new Annotation_Layer(); |
|
473 |
LayerListener[] layerListeners = lyr.getLayerListeners(); |
|
503 | 474 |
|
504 |
return; |
|
505 |
} |
|
475 |
for (int i = 0; i < layerListeners.length; i++) { |
|
476 |
al.addLayerListener(layerListeners[i]); |
|
477 |
} |
|
506 | 478 |
|
507 |
if (proj != viewPort.getProjection()) { |
|
508 |
int option = JOptionPane.YES_OPTION; |
|
479 |
al.setSource(((FLyrVect) lyr).getSource()); |
|
480 |
al.setProjection(lyr.getProjection()); |
|
481 |
al.setName(layerName); |
|
509 | 482 |
|
510 |
if (!CRSFactory.doesRigurousTransformations()) { |
|
511 |
option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
|
512 |
PluginServices.getText(Annotation_Layer.class, |
|
513 |
"reproyectar_aviso") + "\n" + |
|
514 |
PluginServices.getText(Annotation_Layer.class, |
|
515 |
"Capa") + ": " + lyrVect.getName(), |
|
516 |
PluginServices.getText(Annotation_Layer.class, |
|
517 |
"reproyectar_pregunta"), |
|
518 |
JOptionPane.YES_NO_OPTION); |
|
519 |
} |
|
483 |
try { |
|
484 |
Annotation_Mapping.addAnnotationMapping(al); |
|
485 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
486 |
DriverIOExceptionType type = new DriverIOExceptionType(); |
|
487 |
type.setFile(file); |
|
520 | 488 |
|
521 |
if (option != JOptionPane.OK_OPTION) { |
|
522 |
return; |
|
523 |
} |
|
489 |
DriverException newException = new DriverException(e, type); |
|
490 |
lyr.addError(newException); |
|
491 |
lyr.setAvailable(false); |
|
492 |
errors.add(newException); |
|
493 |
} |
|
494 |
al.setInPixels(getCmbInPixels().getSelectedItem().equals( |
|
495 |
PluginServices.getText(this, "pixels"))); |
|
524 | 496 |
|
525 |
ICoordTrans ct = proj.getCT(viewPort.getProjection()); |
|
526 |
lyrVect.setCoordTrans(ct); |
|
527 |
System.err.println("coordTrans = " + proj.getAbrev() + " " + |
|
528 |
viewPort.getProjection().getAbrev()); |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
497 |
if (lyr != null) { |
|
498 |
lyr.setVisible(true); |
|
499 |
checkProjection(lyr, mapControl.getViewPort()); |
|
500 |
mapControl.getMapContext().getLayers().addLayer(al); |
|
501 |
} // if |
|
502 |
|
|
503 |
mapControl.getMapContext().endAtomicEvent(); |
|
504 |
|
|
505 |
return true; |
|
506 |
} |
|
507 |
|
|
508 |
// TODO Este m?todo est? igual en AddLayer pero es privado y |
|
509 |
// no est?tico y he tenido que replicar c?digo |
|
510 |
// Comentar a Joaqu?n para la 1.0.3 |
|
511 |
private static void checkProjection(FLayer lyr, ViewPort viewPort) { |
|
512 |
if (lyr instanceof FLayers) { |
|
513 |
FLayers layers = (FLayers) lyr; |
|
514 |
|
|
515 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
516 |
checkProjection(layers.getLayer(i), viewPort); |
|
517 |
} |
|
518 |
} |
|
519 |
|
|
520 |
if (lyr instanceof FLyrVect) { |
|
521 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
522 |
IProjection proj = lyr.getProjection(); |
|
523 |
|
|
524 |
// Comprobar que la projecci?n es la misma que la vista |
|
525 |
if (proj == null) { |
|
526 |
// SUPONEMOS que la capa est? en la proyecci?n que |
|
527 |
// estamos pidiendo (que ya es mucho suponer, ya). |
|
528 |
lyrVect.setProjection(viewPort.getProjection()); |
|
529 |
|
|
530 |
return; |
|
531 |
} |
|
532 |
|
|
533 |
if (proj != viewPort.getProjection()) { |
|
534 |
int option = JOptionPane.YES_OPTION; |
|
535 |
|
|
536 |
if (!CRSFactory.doesRigurousTransformations()) { |
|
537 |
option = JOptionPane.showConfirmDialog( |
|
538 |
(Component) PluginServices.getMainFrame(), |
|
539 |
PluginServices.getText(Annotation_Layer.class, |
|
540 |
"reproyectar_aviso") |
|
541 |
+ "\n" |
|
542 |
+ PluginServices.getText( |
|
543 |
Annotation_Layer.class, "Capa") |
|
544 |
+ ": " + lyrVect.getName(), PluginServices |
|
545 |
.getText(Annotation_Layer.class, |
|
546 |
"reproyectar_pregunta"), |
|
547 |
JOptionPane.YES_NO_OPTION); |
|
548 |
} |
|
549 |
|
|
550 |
if (option != JOptionPane.OK_OPTION) { |
|
551 |
return; |
|
552 |
} |
|
553 |
|
|
554 |
ICoordTrans ct = proj.getCT(viewPort.getProjection()); |
|
555 |
lyrVect.setCoordTrans(ct); |
|
556 |
System.err.println("coordTrans = " + proj.getAbrev() + " " |
|
557 |
+ viewPort.getProjection().getAbrev()); |
|
558 |
} |
|
559 |
} |
|
560 |
} |
|
532 | 561 |
} |
Also available in: Unified diff