root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / FThemeManagerWindow.java @ 6117
History | View | Annotate | Download (21.6 KB)
1 | 1671 | jmorell | /*
|
---|---|---|---|
2 | * Created on 24-ene-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.cit.gvsig.gui.thememanager; |
||
45 | |||
46 | import java.awt.BorderLayout; |
||
47 | import java.awt.Component; |
||
48 | import java.awt.event.ActionEvent; |
||
49 | import java.awt.event.ActionListener; |
||
50 | import java.io.File; |
||
51 | import java.io.FileNotFoundException; |
||
52 | import java.io.FileReader; |
||
53 | import java.io.FileWriter; |
||
54 | import java.text.NumberFormat; |
||
55 | import java.text.ParseException; |
||
56 | |||
57 | import javax.swing.JButton; |
||
58 | import javax.swing.JDialog; |
||
59 | import javax.swing.JFileChooser; |
||
60 | import javax.swing.JPanel; |
||
61 | import javax.swing.JTabbedPane; |
||
62 | |||
63 | import org.exolab.castor.xml.MarshalException; |
||
64 | import org.exolab.castor.xml.Marshaller; |
||
65 | import org.exolab.castor.xml.ValidationException; |
||
66 | |||
67 | import com.hardcode.gdbms.engine.data.DataSource; |
||
68 | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
||
69 | import com.iver.andami.PluginServices; |
||
70 | import com.iver.andami.messages.NotificationManager; |
||
71 | import com.iver.andami.ui.mdiManager.View; |
||
72 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
73 | import com.iver.cit.gvsig.fmap.DriverException; |
||
74 | import com.iver.cit.gvsig.fmap.FMap; |
||
75 | 4981 | azabala | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
76 | 1671 | jmorell | import com.iver.cit.gvsig.fmap.layers.FLayer; |
77 | 2383 | vcaballero | import com.iver.cit.gvsig.fmap.layers.FLayers; |
78 | 3563 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
79 | 1671 | jmorell | import com.iver.cit.gvsig.fmap.layers.XMLException; |
80 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
81 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
82 | import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend; |
||
83 | import com.iver.cit.gvsig.fmap.rendering.Legend; |
||
84 | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
||
85 | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
||
86 | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
||
87 | 2600 | caballero | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
88 | 6117 | jaume | import com.iver.cit.gvsig.gui.panels.LinkPanel; |
89 | 1671 | jmorell | import com.iver.cit.gvsig.gui.thememanager.legendmanager.FPanelLegendManager; |
90 | 2383 | vcaballero | import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.AbstractPanel; |
91 | 1830 | fernando | import com.iver.cit.gvsig.gui.thememanager.scalemanager.FPanelScaleManager; |
92 | 2395 | jmorell | import com.iver.cit.gvsig.project.ProjectView; |
93 | 1671 | jmorell | import com.iver.utiles.GenericFileFilter; |
94 | import com.iver.utiles.XMLEntity; |
||
95 | 4981 | azabala | import com.iver.utiles.swing.threads.IMonitorableTask; |
96 | 1671 | jmorell | import com.iver.utiles.xmlEntity.generate.XmlTag; |
97 | |||
98 | /**
|
||
99 | * @author jmorell (jose.morell@gmail.com)
|
||
100 | * @version 24-ene-2005
|
||
101 | */
|
||
102 | 2383 | vcaballero | public final class FThemeManagerWindow extends AbstractPanel implements View { |
103 | 1671 | jmorell | private FMap mapContext;
|
104 | private FLayer layer;
|
||
105 | private Legend renderer; // Le asignaremos la leyenda del primer tema activo. |
||
106 | private FPanelScaleManager fPanelScaleManager;
|
||
107 | private FPanelLegendManager fPanelLegendManager;
|
||
108 | 2395 | jmorell | private LinkPanel linkPanel;
|
109 | 1671 | jmorell | private JTabbedPane organizador = new JTabbedPane(); // @jve:decl-index=0: |
110 | private ComandosListener m_actionListener = new ComandosListener(this); |
||
111 | //private ProjectView view;
|
||
112 | private NumberFormat nf = NumberFormat.getInstance(); |
||
113 | |||
114 | /**
|
||
115 | * Creates new form JPanel
|
||
116 | */
|
||
117 | public FThemeManagerWindow() {
|
||
118 | initialize(); |
||
119 | this.setSize(650, 420); |
||
120 | } |
||
121 | |||
122 | /**
|
||
123 | * Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
||
124 | * di?logo desde la barra de comandos.
|
||
125 | *
|
||
126 | */
|
||
127 | public FThemeManagerWindow(FLayer l, FMap fMap) {
|
||
128 | initialize(); |
||
129 | layer = l; |
||
130 | mapContext = fMap; |
||
131 | try {
|
||
132 | ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
||
133 | renderer = (Legend) aux.getLegend().cloneLegend(); |
||
134 | fPanelScaleManager.setMapContext(mapContext); |
||
135 | fPanelLegendManager.setMapContext(mapContext); |
||
136 | } catch (XMLException e) {
|
||
137 | // TODO Auto-generated catch block
|
||
138 | e.printStackTrace(); |
||
139 | } catch (DriverException e1) {
|
||
140 | // TODO Auto-generated catch block
|
||
141 | e1.printStackTrace(); |
||
142 | } |
||
143 | |||
144 | fPanelScaleManager.setLayer(layer, renderer); |
||
145 | fPanelLegendManager.setLayer(layer, renderer); |
||
146 | |||
147 | organizador.setSelectedIndex(0);
|
||
148 | |||
149 | this.setSize(650, 420); |
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * This method initializes this
|
||
154 | *
|
||
155 | * @return void
|
||
156 | */
|
||
157 | private void initialize() { |
||
158 | |||
159 | fPanelScaleManager = new FPanelScaleManager();
|
||
160 | fPanelLegendManager = new FPanelLegendManager();
|
||
161 | |||
162 | organizador.addTab(PluginServices.getText(this,"General"), fPanelScaleManager); |
||
163 | organizador.addTab(PluginServices.getText(this,"Simbologia"), fPanelLegendManager); |
||
164 | |||
165 | JPanel panelButtons = new JPanel(); |
||
166 | |||
167 | JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
||
168 | btnAceptar.setActionCommand("OK");
|
||
169 | btnAceptar.addActionListener(m_actionListener); |
||
170 | |||
171 | JButton btnApply = new JButton(PluginServices.getText(this,"Aplicar")); |
||
172 | btnApply.setActionCommand("APPLY");
|
||
173 | btnApply.addActionListener(m_actionListener); |
||
174 | |||
175 | JButton btnSaveLegend = new JButton(PluginServices.getText(this,"Guardar_leyenda")+"..."); |
||
176 | btnSaveLegend.setActionCommand("SAVE_LEGEND");
|
||
177 | btnSaveLegend.addActionListener(m_actionListener); |
||
178 | |||
179 | JButton btnLoadLegend = new JButton(PluginServices.getText(this,"Recuperar_leyenda")+"..."); |
||
180 | btnLoadLegend.setActionCommand("LOAD_LEGEND");
|
||
181 | btnLoadLegend.addActionListener(m_actionListener); |
||
182 | |||
183 | JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
||
184 | btnCancelar.setActionCommand("CANCEL");
|
||
185 | btnCancelar.addActionListener(m_actionListener); |
||
186 | |||
187 | panelButtons.add(btnApply, null);
|
||
188 | |||
189 | setLayout(new BorderLayout()); |
||
190 | panelButtons.setLayout(null);
|
||
191 | organizador.setPreferredSize(new java.awt.Dimension(640,390)); |
||
192 | 2379 | jmorell | btnAceptar.setBounds(9, 5, 89, 23); |
193 | btnApply.setBounds(107, 5, 89, 23); |
||
194 | btnSaveLegend.setBounds(205, 5, 159, 23); |
||
195 | btnLoadLegend.setBounds(373, 5, 159, 23); |
||
196 | btnCancelar.setBounds(541, 5, 89, 23); |
||
197 | 1671 | jmorell | panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
198 | add(organizador, java.awt.BorderLayout.NORTH); |
||
199 | panelButtons.add(btnAceptar, null);
|
||
200 | add(panelButtons, java.awt.BorderLayout.SOUTH); |
||
201 | panelButtons.add(btnSaveLegend, null);
|
||
202 | panelButtons.add(btnLoadLegend, null);
|
||
203 | panelButtons.add(btnCancelar, null);
|
||
204 | } |
||
205 | |||
206 | 2383 | vcaballero | |
207 | 1671 | jmorell | |
208 | /**
|
||
209 | * En esta funci?n se coge el primer tema activo del TOC y se usa su
|
||
210 | * renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
|
||
211 | * cuadro de di?logo, en el openLegendManager() de la vista.
|
||
212 | *
|
||
213 | * @param mapContext TOC que abre este cuadro de di?logo.
|
||
214 | * @throws DriverException
|
||
215 | */
|
||
216 | public void setMapContext(FMap mapContext) throws DriverException { |
||
217 | this.mapContext = mapContext;
|
||
218 | 2383 | vcaballero | layer = getFirstActiveLayerVect(mapContext.getLayers()); |
219 | 1671 | jmorell | try {
|
220 | ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
||
221 | renderer = (Legend) aux.getLegend().cloneLegend(); |
||
222 | } catch (XMLException e) {
|
||
223 | // TODO Auto-generated catch block
|
||
224 | e.printStackTrace(); |
||
225 | } |
||
226 | fPanelScaleManager.setMapContext(mapContext); |
||
227 | fPanelLegendManager.setMapContext(mapContext); |
||
228 | actualizar(); |
||
229 | } |
||
230 | |||
231 | /**
|
||
232 | * DOCUMENT ME!
|
||
233 | */
|
||
234 | private void actualizar() { |
||
235 | 2383 | vcaballero | FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers()); |
236 | 1671 | jmorell | |
237 | fPanelScaleManager.setLayer(lyrSelected, renderer); |
||
238 | fPanelLegendManager.setLayer(lyrSelected, renderer); |
||
239 | |||
240 | organizador.setSelectedIndex(0);
|
||
241 | } |
||
242 | |||
243 | private void btnApply_actionPerformed(ActionEvent evt) { |
||
244 | 2437 | caballero | // ClassifiableVectorial aux = (ClassifiableVectorial) layer;
|
245 | 2583 | caballero | |
246 | switch (fPanelLegendManager.getVisibleCard()) {
|
||
247 | 1671 | jmorell | case 0: // default symbol |
248 | renderer = fPanelLegendManager.getM_defaultLegendPanel().getLegend(); |
||
249 | 2209 | vcaballero | fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + PluginServices.getText(this,"_(Simbolo_unico)")); |
250 | 1671 | jmorell | break;
|
251 | case 1: // Unique Values |
||
252 | renderer = fPanelLegendManager.getM_valuesLegendPanel().getLegend(); |
||
253 | 2209 | vcaballero | fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Valores_unicos)");
|
254 | 1671 | jmorell | break;
|
255 | case 2:// break values |
||
256 | renderer = fPanelLegendManager.getM_breaksLegendPanel().getLegend(); |
||
257 | 2209 | vcaballero | fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Intervalos)");
|
258 | 1671 | jmorell | break;
|
259 | case 3://text |
||
260 | 2583 | caballero | fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Etiquetas_estandar)");
|
261 | 1671 | jmorell | } |
262 | 2741 | fjp | // System.out.println("Color punto 1 " + renderer.getDefaultSymbol().getColor().toString());
|
263 | 5152 | fjp | // fPanelLegendManager.getM_labelsLegendPanel().setFSymbol(renderer.getDefaultSymbol());
|
264 | // boolean bShapesVisibles = renderer.getDefaultSymbol().isShapeVisible();
|
||
265 | 2583 | caballero | fPanelLegendManager.getM_labelsLegendPanel().updateValuesFromControls((VectorialLegend)renderer); |
266 | 5152 | fjp | // renderer.getDefaultSymbol().setShapeVisible(bShapesVisibles);
|
267 | 2741 | fjp | // System.out.println("Color punto 2 " + renderer.getDefaultSymbol().getColor().toString());
|
268 | 1671 | jmorell | try {
|
269 | // Intentamos aplicar la leyenda a todas
|
||
270 | // las capas activas a las que se les pueda aplicar
|
||
271 | FLayer[] activeLyrs = mapContext.getLayers().getActives();
|
||
272 | for (int i=0; i < activeLyrs.length; i++) |
||
273 | { |
||
274 | 2383 | vcaballero | FLayer laux=activeLyrs[i]; |
275 | if (activeLyrs[i] instanceof FLayers){ |
||
276 | laux=getFirstActiveLayerVect((FLayers)activeLyrs[i]); |
||
277 | } |
||
278 | if (laux instanceof ClassifiableVectorial) |
||
279 | 1671 | jmorell | { |
280 | 2383 | vcaballero | ClassifiableVectorial aux2 = (ClassifiableVectorial) laux; |
281 | 1671 | jmorell | if (renderer instanceof ClassifiedLegend) |
282 | { |
||
283 | // Es una leyenda que necesita un recordset con un
|
||
284 | // nombre de campo. Comprobamos que ese recordset
|
||
285 | // tiene ese nombre de campo y es del tipo esperado
|
||
286 | ClassifiedLegend cl = (ClassifiedLegend) renderer; |
||
287 | if (aux2 instanceof AlphanumericData) |
||
288 | { |
||
289 | DataSource rs = ((AlphanumericData) aux2).getRecordset();
|
||
290 | int idField = rs.getFieldIndexByName(cl.getFieldName());
|
||
291 | if (idField != -1) |
||
292 | { |
||
293 | //TODO: Aqu? deber?amos comprobar si el tipo de campo
|
||
294 | // es el tipo de campo esperado.
|
||
295 | 2600 | caballero | if (renderer instanceof VectorialUniqueValueLegend){ |
296 | ((VectorialUniqueValueLegend)renderer).setLabelHeightField(null);
|
||
297 | ((VectorialUniqueValueLegend)renderer).setLabelRotationField(null);
|
||
298 | } |
||
299 | 2437 | caballero | |
300 | 1671 | jmorell | aux2.setLegend((VectorialLegend) renderer); |
301 | } |
||
302 | |||
303 | } |
||
304 | } |
||
305 | else if (renderer instanceof SingleSymbolLegend) |
||
306 | aux2.setLegend((VectorialLegend) renderer); |
||
307 | } |
||
308 | |||
309 | } |
||
310 | // aux.setLegend((VectorialLegend) m_Renderer);
|
||
311 | |||
312 | } catch (FieldNotFoundException e) {
|
||
313 | // TODO Auto-generated catch block
|
||
314 | e.printStackTrace(); |
||
315 | } catch (DriverException e) {
|
||
316 | // TODO Auto-generated catch block
|
||
317 | e.printStackTrace(); |
||
318 | 1830 | fernando | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
319 | 1671 | jmorell | // TODO Auto-generated catch block
|
320 | e.printStackTrace(); |
||
321 | } |
||
322 | |||
323 | if (fPanelScaleManager.getJRadioButton1().isSelected()) {
|
||
324 | try
|
||
325 | { |
||
326 | layer.setMinScale((nf.parse(fPanelScaleManager.getJTextField1().getText())).doubleValue()); |
||
327 | } |
||
328 | catch (ParseException ex) |
||
329 | { |
||
330 | if (fPanelScaleManager.getJTextField1().getText().compareTo("") == 0) |
||
331 | layer.setMinScale(-1);
|
||
332 | else
|
||
333 | System.err.print(ex.getLocalizedMessage());
|
||
334 | } |
||
335 | try
|
||
336 | { |
||
337 | layer.setMaxScale((nf.parse(fPanelScaleManager.getJTextField2().getText())).doubleValue()); |
||
338 | } |
||
339 | catch (ParseException ex) |
||
340 | { |
||
341 | if (fPanelScaleManager.getJTextField2().getText().compareTo("") == 0) |
||
342 | layer.setMaxScale(-1);
|
||
343 | else
|
||
344 | System.err.print(ex.getLocalizedMessage());
|
||
345 | } |
||
346 | 2381 | vcaballero | |
347 | 1671 | jmorell | } else {
|
348 | layer.setMinScale(-1);
|
||
349 | layer.setMaxScale(-1);
|
||
350 | } |
||
351 | 2570 | caballero | if (!fPanelScaleManager.getLayerName().equals(layer.getName())){
|
352 | layer.setName(fPanelScaleManager.getLayerName()); |
||
353 | } |
||
354 | 3563 | fjp | if (layer instanceof FLyrVect) |
355 | { |
||
356 | FLyrVect lyrVect = (FLyrVect) layer; |
||
357 | if (fPanelScaleManager.isSpatialIndexSelected())
|
||
358 | { |
||
359 | 4981 | azabala | // if (lyrVect.getSpatialIndex() == null)
|
360 | if(lyrVect.getISpatialIndex() == null) |
||
361 | 3563 | fjp | { |
362 | 4981 | azabala | //AZABALA
|
363 | try {
|
||
364 | PluginServices. |
||
365 | cancelableBackgroundExecution(getCreateSpatialIndexTask()); |
||
366 | } catch (DriverIOException e) {
|
||
367 | // TODO Auto-generated catch block
|
||
368 | e.printStackTrace(); |
||
369 | } catch (DriverException e) {
|
||
370 | // TODO Auto-generated catch block
|
||
371 | e.printStackTrace(); |
||
372 | } |
||
373 | // lyrVect.createSpatialIndex();
|
||
374 | 3563 | fjp | } |
375 | } |
||
376 | 4981 | azabala | //AZABALA
|
377 | /*
|
||
378 | * If we unselect the spatial index checkbox...Must we delete
|
||
379 | * spatial index file, or we only have to put Spatial Index
|
||
380 | * reference to null?. I have followed the second choice
|
||
381 | */
|
||
382 | else{
|
||
383 | 3563 | fjp | lyrVect.deleteSpatialIndex(); |
384 | 4981 | azabala | } |
385 | 3563 | fjp | |
386 | |||
387 | } |
||
388 | 2437 | caballero | //layer.getFMap().invalidate();
|
389 | layer.getFMap().callLegendChanged(); |
||
390 | 1671 | jmorell | } |
391 | 4981 | azabala | |
392 | 5096 | azabala | |
393 | 4981 | azabala | /**
|
394 | * Instanciates a ITask (@see com.iver.utiles.swing.threads.ITask)
|
||
395 | * to create a spatial index for the selected layer in background.
|
||
396 | * This task also allow to monitor process evolution, and to cancel
|
||
397 | * this process.
|
||
398 | * @throws DriverException
|
||
399 | * @throws DriverIOException
|
||
400 | */
|
||
401 | public IMonitorableTask getCreateSpatialIndexTask() throws DriverIOException, |
||
402 | DriverException{ |
||
403 | |||
404 | // FIXME REVISAR ESTO (Quizas lanzar TaskException)
|
||
405 | 5096 | azabala | return new CreateSpatialIndexMonitorableTask((FLyrVect)layer); |
406 | 4981 | azabala | } |
407 | |||
408 | /**
|
||
409 | 1671 | jmorell | * DOCUMENT ME!
|
410 | *
|
||
411 | * @author Fernando Gonz?lez Cort?s
|
||
412 | */
|
||
413 | private class ComandosListener implements ActionListener { |
||
414 | private FThemeManagerWindow fLayerPropertiesWindow;
|
||
415 | |||
416 | /**
|
||
417 | * Creates a new ComandosListener object.
|
||
418 | *
|
||
419 | * @param lg DOCUMENT ME!
|
||
420 | */
|
||
421 | public ComandosListener(FThemeManagerWindow fLayerPropertiesWindow) {
|
||
422 | this.fLayerPropertiesWindow = fLayerPropertiesWindow;
|
||
423 | } |
||
424 | |||
425 | /* (non-Javadoc)
|
||
426 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
427 | */
|
||
428 | public void actionPerformed(ActionEvent e) { |
||
429 | if (e.getActionCommand() == "OK") { |
||
430 | 2395 | jmorell | // Implementaci?n para hacer funcionar el hyperlink ...
|
431 | //com.iver.cit.gvsig.gui.View theView = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView();
|
||
432 | //ProjectView view = theView.getModel();
|
||
433 | 4874 | fjp | if (PluginServices.getMainFrame() != null) |
434 | { |
||
435 | ProjectView view = fPanelScaleManager.getView(); |
||
436 | view.setTypeLink(fPanelScaleManager.getLinkType()); |
||
437 | if (fPanelScaleManager.getSelectedLinkField()!=null) |
||
438 | { |
||
439 | view.setSelectedField(fPanelScaleManager.getSelectedLinkField().toString().trim()); |
||
440 | view.setExtLink(fPanelScaleManager.getExtensionLink()); |
||
441 | } |
||
442 | } |
||
443 | 2395 | jmorell | //
|
444 | 1671 | jmorell | fLayerPropertiesWindow.btnApply_actionPerformed(e); |
445 | if (PluginServices.getMainFrame() == null) |
||
446 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
447 | else
|
||
448 | PluginServices.getMDIManager().closeView(FThemeManagerWindow.this); |
||
449 | System.out.println("Ok"); |
||
450 | } else if (e.getActionCommand() == "CANCEL") { |
||
451 | if (PluginServices.getMainFrame() == null) |
||
452 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
453 | else
|
||
454 | PluginServices.getMDIManager().closeView(FThemeManagerWindow.this); |
||
455 | System.out.println("CANCEL"); |
||
456 | } else if (e.getActionCommand() == "APPLY") { |
||
457 | fLayerPropertiesWindow.btnApply_actionPerformed(e); |
||
458 | System.out.println("APPLY"); |
||
459 | } else if (e.getActionCommand() == "LOAD_LEGEND") { |
||
460 | JFileChooser jfc = new JFileChooser(); |
||
461 | jfc.addChoosableFileFilter(new GenericFileFilter("gvl", |
||
462 | 2209 | vcaballero | PluginServices.getText(this, "tipo_de_leyenda"))); |
463 | 5325 | ldiaz | //jfc.addChoosableFileFilter(new GenericFileFilter("sld","sld"));
|
464 | 1671 | jmorell | |
465 | if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
466 | 5325 | ldiaz | File file=jfc.getSelectedFile();
|
467 | 3624 | ldiaz | if (!(file.getPath().endsWith(".gvl") || file.getPath().endsWith(".GVL"))) |
468 | { |
||
469 | 1671 | jmorell | file=new File(file.getPath()+".gvl"); |
470 | } |
||
471 | readLegend(file); |
||
472 | 2437 | caballero | fPanelLegendManager.setRenderer(renderer); |
473 | 1671 | jmorell | fPanelLegendManager.actualizar(); |
474 | } |
||
475 | } else if (e.getActionCommand() == "SAVE_LEGEND") { |
||
476 | fLayerPropertiesWindow.btnApply_actionPerformed(e); |
||
477 | JFileChooser jfc = new JFileChooser(); |
||
478 | 5488 | jmvivo | jfc.addChoosableFileFilter(new GenericFileFilter("sld","*.sld")); |
479 | 1671 | jmorell | jfc.addChoosableFileFilter(new GenericFileFilter("gvl", |
480 | 2209 | vcaballero | PluginServices.getText(this, "tipo_de_leyenda"))); |
481 | 5488 | jmvivo | |
482 | 1671 | jmorell | |
483 | 3624 | ldiaz | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
484 | { |
||
485 | 1671 | jmorell | File file=jfc.getSelectedFile();
|
486 | 3624 | ldiaz | if (jfc.getFileFilter().accept(new File("dummy.sld"))) |
487 | { |
||
488 | if (!(file.getPath().toLowerCase().endsWith(".sld"))){ |
||
489 | file=new File(file.getPath()+".sld"); |
||
490 | } |
||
491 | export2SLD(file); |
||
492 | 1671 | jmorell | } |
493 | 3624 | ldiaz | else{
|
494 | if (!(file.getPath().toLowerCase().endsWith(".gvl"))){ |
||
495 | file=new File(file.getPath()+".gvl"); |
||
496 | } |
||
497 | writeLegend(file); |
||
498 | } |
||
499 | 1671 | jmorell | } |
500 | } else {}
|
||
501 | } |
||
502 | } |
||
503 | 3624 | ldiaz | |
504 | private void export2SLD(File file) { |
||
505 | try {
|
||
506 | FileWriter writer = new FileWriter(file.getAbsolutePath()); |
||
507 | 4566 | ldiaz | writer.write( renderer.getSLDString(layer.getName())); |
508 | writer.close(); |
||
509 | |||
510 | // Marshaller m = new Marshaller(writer);
|
||
511 | // m.setEncoding("ISO-8859-1");
|
||
512 | // m.marshal(renderer.getSLDString());
|
||
513 | 3624 | ldiaz | } catch (Exception e) { |
514 | NotificationManager.addError(PluginServices.getText(this, "Error_exportando_SLD"), e); |
||
515 | } |
||
516 | } |
||
517 | |||
518 | 1671 | jmorell | private void writeLegend(File file) { |
519 | try {
|
||
520 | FileWriter writer = new FileWriter(file.getAbsolutePath()); |
||
521 | Marshaller m = new Marshaller(writer);
|
||
522 | m.setEncoding("ISO-8859-1");
|
||
523 | 3657 | ldiaz | m.marshal(renderer.getXMLEntity().getXmlTag()); |
524 | 1671 | jmorell | } catch (Exception e) { |
525 | 2209 | vcaballero | NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_leyenda"), e); |
526 | 1671 | jmorell | } |
527 | } |
||
528 | |||
529 | public void readLegend(File file) { |
||
530 | try {
|
||
531 | File xmlFile = new File(file.getAbsolutePath()); |
||
532 | FileReader reader;
|
||
533 | reader = new FileReader(xmlFile); |
||
534 | |||
535 | XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
||
536 | renderer = LegendFactory.createFromXML(new XMLEntity(tag));
|
||
537 | //fPanelLegendManager.setRenderer(LegendFactory.createFromXML(new XMLEntity(tag)));
|
||
538 | } catch (FileNotFoundException e) { |
||
539 | 2209 | vcaballero | NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e); |
540 | 1671 | jmorell | } catch (MarshalException e) { |
541 | 5503 | cesar | NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e); |
542 | 1671 | jmorell | } catch (ValidationException e) {
|
543 | 5503 | cesar | NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e); |
544 | 1671 | jmorell | } catch (XMLException e) {
|
545 | 5503 | cesar | NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e); |
546 | 1671 | jmorell | } |
547 | } |
||
548 | |||
549 | /* (non-Javadoc)
|
||
550 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
551 | */
|
||
552 | public ViewInfo getViewInfo() {
|
||
553 | // Solo se llama una vez
|
||
554 | ViewInfo viewInfo = new ViewInfo(ViewInfo.MODELESSDIALOG);
|
||
555 | viewInfo.setWidth(650);
|
||
556 | viewInfo.setHeight(420);
|
||
557 | 5258 | jmvivo | viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
558 | 1671 | jmorell | return viewInfo;
|
559 | } |
||
560 | |||
561 | /**
|
||
562 | * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
||
563 | */
|
||
564 | /*public void viewActivated() {
|
||
565 | }
|
||
566 | |||
567 | public FMap getMapContext() {
|
||
568 | return mapContext;
|
||
569 | }
|
||
570 | public FLayer getLayer() {
|
||
571 | return layer;
|
||
572 | }
|
||
573 | public Legend getRenderer() {
|
||
574 | return renderer;
|
||
575 | }*/
|
||
576 | |||
577 | /**
|
||
578 | * @return Returns the organizador.
|
||
579 | */
|
||
580 | public JTabbedPane getOrganizador() { |
||
581 | return organizador;
|
||
582 | } |
||
583 | /**
|
||
584 | * @param organizador The organizador to set.
|
||
585 | */
|
||
586 | public void setOrganizador(JTabbedPane organizador) { |
||
587 | this.organizador = organizador;
|
||
588 | } |
||
589 | } |