Revision 470 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/legendmanager/FLegendManagerWindow.java
FLegendManagerWindow.java | ||
---|---|---|
22 | 22 |
import javax.swing.JOptionPane; |
23 | 23 |
import javax.swing.JPanel; |
24 | 24 |
import javax.swing.JTabbedPane; |
25 |
import javax.xml.transform.TransformerFactory; |
|
26 |
import javax.xml.transform.sax.SAXTransformerFactory; |
|
27 | 25 |
|
28 |
import org.xml.sax.SAXNotSupportedException;
|
|
29 |
import org.xml.sax.XMLReader;
|
|
30 |
import org.xml.sax.helpers.XMLReaderFactory;
|
|
31 |
|
|
26 |
import com.hardcode.driverManager.DriverLoadException;
|
|
27 |
import com.hardcode.gdbms.engine.data.DriverException;
|
|
28 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
|
|
29 |
import com.iver.cit.gvsig.fmap.FMap; |
|
32 | 30 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
33 | 31 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
34 | 32 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
... | ... | |
36 | 34 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
37 | 35 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
38 | 36 |
import com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend; |
37 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
|
39 | 38 |
import com.iver.cit.gvsig.gui.TOC; |
40 | 39 |
import com.iver.cit.gvsig.gui.legendmanager.panels.FPanelLegendDefault; |
41 |
import com.iver.cit.gvsig.project.XMLEntityXMLHandler;
|
|
40 |
import com.iver.cit.gvsig.gui.legendmanager.panels.FPanelLegendValues;
|
|
42 | 41 |
import com.iver.mdiApp.App; |
43 | 42 |
import com.iver.mdiApp.Messages; |
44 | 43 |
import com.iver.mdiApp.Utilities; |
... | ... | |
62 | 61 |
public final static int LEGEND_TYPE_VALUE = 2; |
63 | 62 |
public final static int SYMBOL_TYPE_DEFAULT = 5; |
64 | 63 |
|
65 |
private NewMapControl m_MapControl;
|
|
64 |
private FMap mapContext;
|
|
66 | 65 |
private FLyrVect m_Lyr; |
67 |
private TOC m_Toc; |
|
68 | 66 |
private Legend m_Renderer; // Le asignaremos la leyenda del primer tema activo. |
69 | 67 |
private JTabbedPane organizador = new JTabbedPane(); |
70 | 68 |
private FPanelLegendDefault m_defaultLegendPanel; |
71 |
// private FPanelLegendValues m_valuesLegendPanel;
|
|
69 |
private FPanelLegendValues m_valuesLegendPanel; |
|
72 | 70 |
// private FPanelLegendBreaks m_breaksLegendPanel; |
73 | 71 |
// private FPanelLegendLabels m_labelsLegendPanel; |
74 | 72 |
private JButton btnApply; |
... | ... | |
107 | 105 |
*/ |
108 | 106 |
//Createmos los paneles. |
109 | 107 |
m_defaultLegendPanel = new FPanelLegendDefault(); |
110 |
/* m_valuesLegendPanel = new FPanelLegendValues();
|
|
111 |
m_breaksLegendPanel = new FPanelLegendBreaks(); |
|
108 |
m_valuesLegendPanel = new FPanelLegendValues(); |
|
109 |
/* m_breaksLegendPanel = new FPanelLegendBreaks();
|
|
112 | 110 |
m_labelsLegendPanel = new FPanelLegendLabels(this); */ |
113 | 111 |
// TODO: PONER LOS TABS |
114 | 112 |
//Add the scroll panes to a split pane. |
115 | 113 |
organizador.addTab(Utilities.getMessage(this,"Simbolo_unico"), m_defaultLegendPanel); |
116 |
/* organizador.addTab(Utilities.getMessage(this,"Valores_unicos"), m_valuesLegendPanel);
|
|
117 |
organizador.addTab(Utilities.getMessage(this,"Intervalos"), m_breaksLegendPanel); |
|
114 |
organizador.addTab(Utilities.getMessage(this,"Valores_unicos"), m_valuesLegendPanel); |
|
115 |
/* organizador.addTab(Utilities.getMessage(this,"Intervalos"), m_breaksLegendPanel);
|
|
118 | 116 |
organizador.addTab(Utilities.getMessage(this,"Etiquetado"), m_labelsLegendPanel);*/ |
119 | 117 |
|
120 | 118 |
java.awt.Dimension minimumSize = new java.awt.Dimension(100, 50); |
... | ... | |
157 | 155 |
private FLyrVect getFirstActiveLayerVect() |
158 | 156 |
{ |
159 | 157 |
// Comprobar en openLegendManager que hay alg?n tema activo! |
160 |
FLayer[] activeLyrs = m_MapControl.getMapContext().getLayers().getActives();
|
|
158 |
FLayer[] activeLyrs = mapContext.getLayers().getActives();
|
|
161 | 159 |
if (activeLyrs.length == 0) |
162 | 160 |
{ |
163 | 161 |
JOptionPane.showMessageDialog(null, |
... | ... | |
189 | 187 |
* renderer para inicializar. Hay que llamarla SIEMPRE que se abra el |
190 | 188 |
* cuadro de di?logo, en el openLegendManager() de la vista. |
191 | 189 |
* |
192 |
* @param associatedToc TOC que abre este cuadro de di?logo.
|
|
190 |
* @param mapContext TOC que abre este cuadro de di?logo.
|
|
193 | 191 |
*/ |
194 |
public void setToc(TOC associatedToc) { |
|
195 |
m_Toc = associatedToc; |
|
196 |
|
|
197 |
FLyrVect lyr = getFirstActiveLayerVect(); |
|
198 |
m_Renderer = (Legend) lyr.getLegendInfo(); //.cloneRenderer(); |
|
192 |
public void setMapContext(FMap mapContext) { |
|
193 |
this.mapContext = mapContext; |
|
194 |
m_Lyr = getFirstActiveLayerVect(); |
|
195 |
try { |
|
196 |
m_Renderer = (Legend) m_Lyr.getLegendInfo().cloneLegend(); |
|
197 |
} catch (ClassNotFoundException e) { |
|
198 |
// TODO Auto-generated catch block |
|
199 |
e.printStackTrace(); |
|
200 |
} catch (InstantiationException e) { |
|
201 |
// TODO Auto-generated catch block |
|
202 |
e.printStackTrace(); |
|
203 |
} catch (IllegalAccessException e) { |
|
204 |
// TODO Auto-generated catch block |
|
205 |
e.printStackTrace(); |
|
206 |
} |
|
199 | 207 |
actualizar(); |
200 | 208 |
} |
201 | 209 |
|
202 |
/** |
|
203 |
* Esto solo lo usa el localizador para las leyendas |
|
204 |
* |
|
205 |
* @param m |
|
206 |
* @param lyr |
|
207 |
*/ |
|
208 |
public void setMapControl(NewMapControl m, FLyrVect lyr) |
|
209 |
{ |
|
210 |
m_MapControl = m; |
|
211 |
m_Lyr = lyr; |
|
212 |
m_Renderer = lyr.getLegendInfo(); //.cloneRenderer(); |
|
213 |
m_Toc = null; |
|
214 |
|
|
215 |
actualizar(); |
|
216 |
} |
|
217 | 210 |
|
218 | 211 |
/** |
219 | 212 |
* DOCUMENT ME! |
220 | 213 |
*/ |
221 | 214 |
private void actualizar() { |
222 | 215 |
// Avisar si no es Vectorial |
223 |
FLyrVect lyrSelected = null; |
|
224 |
FLyrVect lyr = getFirstActiveLayerVect(); |
|
216 |
FLyrVect lyrSelected = getFirstActiveLayerVect(); |
|
225 | 217 |
|
226 | 218 |
m_defaultLegendPanel.setFSymbol(m_Renderer.getDefaultSymbol()); |
227 |
// m_valuesLegendPanel.setLayer(lyrSelected, m_Renderer);
|
|
219 |
m_valuesLegendPanel.setLayer(lyrSelected, m_Renderer); |
|
228 | 220 |
// m_breaksLegendPanel.setLayer(lyrSelected, m_Renderer); |
229 | 221 |
// m_labelsLegendPanel.setLayer(lyrSelected, m_Renderer); |
230 | 222 |
|
... | ... | |
263 | 255 |
|
264 | 256 |
// TODO: APLICAR LA LEYENDA A LAS CAPAS ACTIVAS |
265 | 257 |
|
266 |
/* switch (organizador.getSelectedIndex()) {
|
|
258 |
switch (organizador.getSelectedIndex()) { |
|
267 | 259 |
case 0: // default symbol |
268 |
|
|
269 |
if (m_defaultLegendPanel.getFSymbol().m_symbolType == FConstant.SYMBOL_TYPE_POINT) { |
|
270 |
m_defaultLegendPanel.updateControls(); // Para que lo que haya en |
|
271 |
} |
|
272 |
|
|
273 |
// ese momento en los controles pase al m_FSymbol |
|
274 |
m_Renderer.setLegendType(FConstant.LEGEND_TYPE_DEFAULT); |
|
275 |
m_Renderer.setDefaultSymbol(m_defaultLegendPanel.getFSymbol()); |
|
276 |
|
|
260 |
m_Renderer = m_defaultLegendPanel.getLegend(); |
|
277 | 261 |
break; |
278 |
|
|
279 | 262 |
case 1: // Unique Values |
280 |
m_Renderer.setLegendType(FConstant.LEGEND_TYPE_VALUE); |
|
281 |
m_valuesLegendPanel.fillSymbolListFromTable(); |
|
282 |
|
|
263 |
m_Renderer = m_valuesLegendPanel.getLegend(); |
|
283 | 264 |
break; |
284 | 265 |
|
285 |
case 2: // Breaks |
|
286 |
m_Renderer.setLegendType(FConstant.LEGEND_TYPE_BREAK); |
|
287 |
m_breaksLegendPanel.fillSymbolListFromTable(); |
|
288 |
|
|
289 |
break; |
|
290 |
|
|
291 |
case 3: // Etiquetado |
|
292 |
m_labelsLegendPanel.updateValuesFromControls(); |
|
293 |
if (m_Renderer.getLabelField() != null) |
|
294 |
{ |
|
295 |
for (int i = 0; i < listSelLayers.size(); i++) { |
|
296 |
lyr = (FLyrVect) listSelLayers.get(i); |
|
297 |
|
|
298 |
FRecordset rs = lyr.getRecordset(); |
|
299 |
int idFieldText = lyr.getFieldID(m_Renderer.getLabelField()); |
|
300 |
// int idFieldRotationText = lyr.getFieldID(m_Renderer.getLabelRotationField()); |
|
301 |
// int idFieldHeightText = lyr.getFieldID(m_Renderer.getLabelHeightField()); |
|
302 |
|
|
303 |
lyr.m_labels.clear(); |
|
304 |
for (int j = 0; j < lyr.m_NumShapes; j++) { |
|
305 |
rs.moveTo(j); |
|
306 |
FLabel theLabel = new FLabel(rs.getFieldValueAsString(idFieldText)); |
|
307 |
// Valor por defecto de las etiquetas |
|
308 |
theLabel.setHeight(m_Renderer.getDefaultSymbol().m_FontSize); |
|
309 |
|
|
310 |
// Si el campo de heightfield est? definido, rellenamos el height del label |
|
311 |
// con su valor |
|
312 |
// if (m_Renderer.getLabelHeightField() != null) |
|
313 |
// theLabel.setHeight(rs.getFieldValueAsNumber(idFieldRotationText).doubleValue()); |
|
314 |
// idem para el de rotaci?n |
|
315 |
// if (m_Renderer.getLabelRotationField() != null) |
|
316 |
// theLabel.setHeight(rs.getFieldValueAsNumber(idFieldHeightText).doubleValue()); |
|
317 |
|
|
318 |
lyr.m_labels.add(theLabel); |
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
break; |
|
324 | 266 |
} |
267 |
try { |
|
268 |
m_Lyr.setLegend((VectorialLegend) m_Renderer); |
|
269 |
} catch (DriverLoadException e) { |
|
270 |
// TODO Auto-generated catch block |
|
271 |
e.printStackTrace(); |
|
272 |
} catch (FieldNotFoundException e) { |
|
273 |
// TODO Auto-generated catch block |
|
274 |
e.printStackTrace(); |
|
275 |
} catch (DriverException e) { |
|
276 |
// TODO Auto-generated catch block |
|
277 |
e.printStackTrace(); |
|
278 |
} |
|
325 | 279 |
|
326 |
for (int i = 0; i < listSelLayers.size(); i++) { |
|
327 |
if (listSelLayers.get(i) instanceof FLyrVect) { |
|
328 |
lyr = (FLyrVect) listSelLayers.get(i); |
|
329 |
|
|
330 |
if ((m_Renderer.getLegendType() == FConstant.LEGEND_TYPE_VALUE) || |
|
331 |
(m_Renderer.getLegendType() == FConstant.LEGEND_TYPE_BREAK)) { |
|
332 |
int idField = lyr.getFieldID(m_Renderer.getFieldName()); |
|
333 |
|
|
334 |
if ((i == 0) && |
|
335 |
((!m_valuesLegendPanel.m_bCacheDirty) || |
|
336 |
(!m_breaksLegendPanel.m_bCacheDirty))) // la primera capa la cogemos del arrayCache |
|
337 |
{ |
|
338 |
if (m_Renderer.getLegendType() == FConstant.LEGEND_TYPE_VALUE) { |
|
339 |
for (int j = 0; j < lyr.m_NumShapes; j++) { |
|
340 |
lyr.m_legendValues[j] = m_valuesLegendPanel.m_keysCache[j]; |
|
341 |
} |
|
342 |
} else { |
|
343 |
for (int j = 0; j < lyr.m_NumShapes; j++) { |
|
344 |
lyr.m_legendValues[j] = m_breaksLegendPanel.m_valuesCache[j]; |
|
345 |
} |
|
346 |
} |
|
347 |
} else { |
|
348 |
FRecordset rs = lyr.getRecordset(); |
|
349 |
int fieldType = rs.getFieldType(idField); |
|
350 |
|
|
351 |
for (int j = 0; j < lyr.m_NumShapes; j++) { |
|
352 |
rs.moveTo(j); |
|
353 |
|
|
354 |
lyr.m_legendValues[j] = rs.getFieldValueAsString(idField); |
|
355 |
break; |
|
356 |
|
|
357 |
case FRecordset.DECIMAL: |
|
358 |
case FRecordset.INTEGER: |
|
359 |
lyr.m_legendValues[j] = rs.getFieldValueAsNumber(idField); |
|
360 |
|
|
361 |
break; |
|
362 |
} |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
lyr.setRenderer(m_Renderer); |
|
368 |
} |
|
369 |
// if es vectorial |
|
370 |
} */ |
|
371 |
|
|
372 | 280 |
// closeDialog(null); |
373 |
if (m_Toc != null) |
|
374 |
{ |
|
375 |
m_Toc.refresh(); |
|
376 |
} |
|
377 |
m_MapControl.drawMap(); |
|
281 |
|
|
282 |
// TODO: Aqu? hay que refrescar, si se puede |
|
378 | 283 |
} |
379 | 284 |
|
380 | 285 |
/* (non-Javadoc) |
... | ... | |
382 | 287 |
*/ |
383 | 288 |
public Object read(File file) { |
384 | 289 |
Legend ret = null; |
385 |
try { |
|
290 |
/* try {
|
|
386 | 291 |
TransformerFactory transFact = TransformerFactory.newInstance(); |
387 | 292 |
|
388 | 293 |
if (transFact.getFeature(SAXTransformerFactory.FEATURE)) { |
... | ... | |
403 | 308 |
} catch (Exception exc) { |
404 | 309 |
App.instance.getNm().addError("Error leyendo la leyenda", exc); |
405 | 310 |
} |
311 |
*/ |
|
312 |
return ret; |
|
406 | 313 |
|
407 |
return ret; |
|
408 | 314 |
} |
409 | 315 |
|
410 | 316 |
/* (non-Javadoc) |
Also available in: Unified diff