Revision 26225 branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/FLayers.java

View differences:

FLayers.java
43 43
import java.awt.Graphics2D;
44 44
import java.awt.Point;
45 45
import java.awt.image.BufferedImage;
46
import java.awt.image.WritableRaster;
47 46
import java.util.ArrayList;
48 47
import java.util.Collections;
49 48
import java.util.Iterator;
......
93 92
 * @see FLyrDefault
94 93
 */
95 94
public class FLayers extends FLyrDefault implements LayerCollection,
96
		InfoByPoint {
95
InfoByPoint {
97 96
	/**
98 97
	 * List with all listeners registered for this kind of node.
99 98
	 *
......
184 183
		layers.add(pos,layer);
185 184
		layer.setParentLayer(this);
186 185
		if(layer.getProjection() != null && fmap != null) {
187
			if (layer.getProjection().getAbrev() != fmap.getProjection()
188
					.getAbrev()) { //FIXME
189
				layer.setCoordTrans(layer.getProjection().getCT(
190
						fmap.getProjection()));
191
			}
192
		}
186
			layer.setCoordTrans(layer.getProjection().getCT(fmap.getProjection()));
187
		}
188
		this.updateDrawVersion();
193 189
	}
194 190

  
195 191
	/*
......
243 239
		callLayerMoving(LayerPositionEvent.createLayerMovingEvent(aux, newfrom, newto));
244 240
		layers.remove(newfrom);
245 241
		layers.add(newto, aux);
242
		this.updateDrawVersion();
246 243
		callLayerMoved(LayerPositionEvent.createLayerMovedEvent(aux, newfrom, newto));
247 244
	}
248 245

  
......
253 250
	 */
254 251
	private void doRemoveLayer(FLayer lyr) {
255 252
		layers.remove(lyr);
253
		this.updateDrawVersion();
256 254
	}
257 255

  
258 256
	/*
......
273 271
		FLayer lyr = (FLayer) layers.get(idLayer);
274 272
		callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr));
275 273
		layers.remove(idLayer);
274
		this.updateDrawVersion();
276 275
		callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr));
277 276
	}
278 277

  
......
429 428
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double)
430 429
	 */
431 430
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
432
			Cancellable cancel,double scale) throws ReadException {
433
		draw(image,g,viewPort,cancel, scale, null);
431
			Cancellable cancel, double scale) throws ReadException {
432
		// FIXME Arreglar este error
433
		throw new RuntimeException("Esto no deberia de llamarse");
434 434
	}
435 435

  
436
	/**
437
	 * <p>Checks all layers (each one as a sub-node of this node <i>collection of layers</i>) of this collection and draws which are visible, and dirty (in cache) or aren't in cache. If a node is
438
	 *  a group of layers (<code>ComposedLayer</code>), executes it's drawn.</p>
439
	 *
440
	 * <p>All nodes which could group with the composed layer <code>group</code>, will be drawn together. And once the <code>
441
	 * group</code> is drawn, will be set to <code>null</code>.</p>
442
	 *
443
	 * <p>The particular behavior depends on the kind of each layer and composed layer. And this process can be cancelled at any
444
	 *  time by the shared object <code>cancel</code>.</p>
445
	 *
446
	 * @param image buffer used sometimes instead <code>g</code> to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one.
447
	 * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
448
	 * @param viewPort the information for drawing the layers
449
	 * @param cancel shared object that determines if this layer can continue being drawn
450
	 * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
451
	 * @param group a composed layer pending to paint; if this parameter is <code>null</code>, the composed layer
452
	 *  will also be drawn
453
	 *
454
	 * @return <code>null</code> if the layers in <code>group</code> had been drawn or were <code>null</code>; otherwise, the <code>group</code>
455
	 *
456
	 * @throws ReadDriverException if fails the driver reading the data.
457
	 *
458
	 * @see ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
459
	 */
460
	public ComposedLayer draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
461
			Cancellable cancel,double scale, ComposedLayer group) throws ReadException {
462
		boolean bNeedRecalculateCache = false;
463
		double dpi = MapContext.getScreenDPI();
464
		///// CHEMA ComposedLayer
465
		long tg1 = System.currentTimeMillis();
466
		///// CHEMA ComposedLayer
467

  
468

  
469
		for (int i=0; i < layers.size(); i++) {
470
			if (cancel.isCanceled()) {
471
				break; // M?s que nada porque las capas raster no son interrumpibles por ahora.
472
			}
473
			FLayer lyr = (FLayer) layers.get(i);
474

  
475
			if (!lyr.isVisible() || !lyr.isWithinScale(scale)) {
476
				continue;
477
			}
478

  
479
			LayerDrawEvent beforeEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW);
480
			fmap.fireLayerDrawingEvent(beforeEvent);
481
			if ((lyr.isDirty()) || (lyr.isCachingDrawnLayers() == false)) {
482
				bNeedRecalculateCache = true;
483
			}
484

  
485
			if (lyr.isVisible()) {
486

  
487
				long t1 = System.currentTimeMillis();
488
				// synchronized (this) {
489
				//Sincronizaci?n del m?todo dibujar de cada Layer, esto es posible hacerlo de otra forma,
490
				//pero de momento se queda as?, para solucionar el refresco de una misma vista que est? a?adida en el Layout.
491
				try{
492
					/* if (lyr instanceof IComposedDrawing)
493
    					 {
494
    					 // Acumulamos las peticiones hasta que sea
495
    					  // otro servidor o otro tipo de capa o la ?ltima
496
    					   // Si hay que dibujar:
497
    					    lyr.draw(image, g, viewPort, cancel,scale);
498
    					    // Si hay que acumlar:
499
    					     lyr.acumulateDrawing(antLayer);
500

  
501
    					     }
502
    					     else */
503

  
504
					if (lyr.isCachingDrawnLayers())
505
					{
506
						if ((bNeedRecalculateCache) || (lyr.getCacheImageDrawnLayers()==null))
507
						{
508
							//if (bNeedRecalculateCache)
509
							// {
510

  
511
							///// CHEMA ComposedLayer
512
							if (group != null) {
513
								//si tenemos un grupo pendiente de pintar, pintamos
514
								// para que la cache sea fiable
515
								group.draw(image, g, viewPort, cancel,scale);
516
								group = null;
517
							}
518
							///// CHEMA ComposedLayer
519

  
520

  
521

  
522

  
523

  
524
							// Copiamos la imagen actual
525
							BufferedImage buff = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
526
							WritableRaster w = buff.getRaster();
527
							image.copyData(w);
528
							lyr.setCacheImageDrawnLayers(buff);
529
						}
530
//						}
531
//						else
532
//						{
533
						if (lyr.getCacheImageDrawnLayers() != null)
534
						{
535
							// Previo a esto hemos tenido que fijar
536
							// la imagen que queremos usar, en el
537
							// prepareDrawing de FMap.
538
							if (lyr.isDirty())
539
							{
540

  
541

  
542
								///// CHEMA ComposedLayer
543
								// Checks for draw group (ComposedLayer)
544
								if (group != null) {
545
									// it's going to load a cache image,
546
									// the current draw isn't needed
547
									group = null;
548
								}
549
								///// CHEMA ComposedLayer
550

  
551
								g.drawImage(lyr.getCacheImageDrawnLayers(), 0, 0, null);
552
							}
553
						}
554
//						}
555
					}
556
					// Si la capa est? "sucia" o alguna de las de abajo est? sucia
557
					// hay que volver a dibujar.
558
					if (lyr.isDirty() || bNeedRecalculateCache)
559
					{
560
						if (!lyr.getFLayerStatus().isDriverLoaded()){
561
							continue;
562
		        		}
563
						///// CHEMA ComposedLayer
564
						//lyr.draw(image, g, viewPort, cancel,scale);
565
						///// CHEMA ComposedLayer
566

  
567
						// Checks for draw group (ComposedLayer)
568
						if (group != null) {
569
							if (lyr instanceof FLayers){
570
								group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group);
571
								LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
572
								fmap.fireLayerDrawingEvent(afterEvent);
573
							} else {
574
								//If layer can be added to the group, does it
575
								if (group.canAdd(lyr)) {
576
									group.add(lyr);
577
								} else {
578
									// draw the 'pending to draw' layer group
579
									group.draw(image, g, viewPort, cancel,scale);
580

  
581
									// gets a new group instance
582
									group = lyr.newComposedLayer();
583
									// if layer hasn't group, draws it inmediately
584
									if (group == null) {
585
										if (lyr instanceof FLayers){
586
											group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group);
587
										} else {
588
											lyr.draw(image, g, viewPort, cancel,scale);
589
										}
590
										LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
591
										fmap.fireLayerDrawingEvent(afterEvent);
592
									} else {
593
										// add the layer to the group
594
										group.setMapContext(fmap);
595
										group.add(lyr);
596

  
597
									}
598
								}
599
							}
600
						} else {
601
							// gets a new group instance
602
							group = lyr.newComposedLayer();
603
							// if layer hasn't group, draws it inmediately
604
							if (group == null) {
605
								if (lyr instanceof FLayers){
606
									group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group);
607
								} else {
608
									lyr.draw(image, g, viewPort, cancel,scale);
609
								}
610
								LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
611
								fmap.fireLayerDrawingEvent(afterEvent);
612
							} else {
613
								// adds the layer to the group
614
								group.setMapContext(fmap);
615
								group.add(lyr);
616
							}
617
						}
618
						///// CHEMA ComposedLayer
619

  
620
						/*
621
						 * (Jaume)
622
						 * If the layer is instance of ILabelable then it may have labels.
623
						 */
624
						if (lyr instanceof ILabelable
625
							&& ((ILabelable) lyr).isLabeled()
626
							&& ((ILabelable) lyr).getLabelingStrategy() != null
627
							&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) {
628

  
629
							///// CHEMA ComposedLayer
630
							if (group != null) {
631
								//si tenemos un grupo pendiente de pintar, pintamos
632
								// para que se pinten correctamente las etiquetas
633
								group.draw(image, g, viewPort, cancel,scale);
634
								group = null;
635
							}
636
							///// CHEMA ComposedLayer
637

  
638

  
639
							((ILabelable) lyr).drawLabels(image, g, viewPort, cancel, scale, dpi);
640
						}
641
						bNeedRecalculateCache = true;
642
					}
643
				} catch (ReadException e){
644
					// fmap.callNewErrorEvent(new ErrorEvent(lyr.getName(), e));
645
					fmap.addLayerError("La capa " + lyr.getName() + " es err?nea.");
646
					lyr.addError(e);
647
					e.printStackTrace();
648
					lyr.setAvailable(false);
649
					// this.removeLayer(lyr);
650
				} catch (Exception e) {
651
					fmap.addLayerError("La capa " + lyr.getName() + " es err?nea.");
652
					e.printStackTrace();
653
					lyr.setAvailable(false);
654
				}
655
				// }
656
				long t2 = System.currentTimeMillis();
657
				logger.info("Layer " + lyr.getName() + " "
658
						+ (t2-t1) + " milisecs.");
659
				lyr.setDirty(false);
660
			}
661

  
662
		}
663
		///// CHEMA ComposedLayer
664
		if (group != null && this.getParentLayer() == null) {
665
			//si tenemos un grupo pendiente de pintar, pintamos
666
			group.draw(image, g, viewPort, cancel,scale);
667
			group = null;
668

  
669
		}
670
		///// CHEMA ComposedLayer
671
//		if (getVirtualLayers() != null) {
672
//			getVirtualLayers().draw(image, g, viewPort, cancel,scale);
673
//		}
674

  
675
		long tg2 = System.currentTimeMillis();
676

  
677
		logger.debug("Draw all layer " +this.getName() + " " +
678
				+ (tg2-tg1) + " milisecs.");
679
		///// CHEMA ComposedLayer
680
		return group;
681
		///// CHEMA ComposedLayer
682
	}
683

  
684 436
	/*
685 437
	 * (non-Javadoc)
686
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double, javax.print.attribute.PrintRequestAttributeSet)
438
	 * 
439
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
440
	 * com.iver.cit.gvsig.fmap.ViewPort,
441
	 * com.iver.utiles.swing.threads.Cancellable, double,
442
	 * javax.print.attribute.PrintRequestAttributeSet)
687 443
	 */
688
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties)
444
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
445
			double scale, PrintRequestAttributeSet properties)
689 446
	throws ReadException {
690
		this.print(g, viewPort, cancel, scale, properties, null);
447
		throw new RuntimeException("No deberia pasar por aqui");
691 448
	}
692 449

  
450
	public void print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel,
451
			double scale, PrintRequestAttributeSet properties)
452
	throws ReadException {
453
		this.print_old(g, viewPort, cancel, scale, properties, null);
454
	}
455

  
693 456
	/**
694 457
	 * <p>Checks all layers (each one as a sub-node of this node <i>collection of layers</i>) of this collection and draws their requested properties. If a node is
695 458
	 *  a group of layers (<code>ComposedLayer</code>), executes it's drawn.</p>
......
721 484
	 *
722 485
	 * @throws ReadDriverException if fails the driver reading the data.
723 486
	 */
724
	public ComposedLayer print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties, ComposedLayer group)

725
	throws ReadException {

726
        double dpi = 72;
487
	public ComposedLayer print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties, ComposedLayer group)
488
	throws ReadException {
489
		double dpi = 72;
727 490

  
728 491
		PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
729 492
		if (resolution.equals(PrintQuality.NORMAL)){
......
751 514
				// Checks for draw group (ComposedLayer)
752 515
				if (group != null) {
753 516
					if (lyr instanceof FLayers){
754
						group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group);

517
						group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group);
755 518
					} else {
756 519
						// If layer can be added to the group, does it
757 520
						if (lyr instanceof ILabelable
......
775 538
							// if layer hasn't group, draws it inmediately
776 539
							if (group == null) {
777 540
								if (lyr instanceof FLayers){
778
									group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group);

541
									group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group);
779 542
								} else {
780 543
									lyr.print(g, viewPort, cancel,scale,properties);
781 544
									if (lyr instanceof ILabelable
......
801 564
					// if layer hasn't group, draws it inmediately
802 565
					if (group == null) {
803 566
						if (lyr instanceof FLayers){
804
							group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group);

567
							group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group);
805 568
						} else {
806 569
							lyr.print(g, viewPort, cancel,scale,properties);
807 570
							if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) {
......
836 599
		}
837 600
		///// CHEMA ComposedLayer
838 601

  
839
//		if (getVirtualLayers() != null) {
840
//			getVirtualLayers().print( g, viewPort, cancel, scale, properties);
841
//		}
602
		//		if (getVirtualLayers() != null) {
603
		//			getVirtualLayers().print( g, viewPort, cancel, scale, properties);
604
		//		}
842 605

  
843 606
		///// CHEMA ComposedLayer
844 607
		return group;
......
1185 948
	public ImageIcon getTocImageIcon() {
1186 949
		return new ImageIcon(MapContext.class.getResource("images/layerGroup.png"));
1187 950
	}
1188
	/*
1189
	 * (non-Javadoc)
1190
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#isDirty()
1191
	 */
1192
	public boolean isDirty() {
1193
		for (Iterator iter = layers.iterator(); iter.hasNext();) {
1194
			FLayer lyr = (FLayer) iter.next();
1195
			if (lyr.isDirty()) {
1196
				return true;
1197
			}
1198
		}
1199
		return false;
1200
	}
1201
	/*
1202
	 * (non-Javadoc)
1203
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setDirty(boolean)
1204
	 */
1205
	public void setDirty(boolean dirty) {
1206
		for (Iterator iter = layers.iterator(); iter.hasNext();) {
1207
			FLayer lyr = (FLayer) iter.next();
1208
			lyr.setDirty(dirty);
1209
		}
1210 951

  
1211
	}
1212

  
1213 952
	/**
1214 953
	 * <p>Adds the layer with the information in an XML entity and the specified name, to this collection of layers. And
1215 954
	 *  returns <code>true</code> if there hasn't been errors.</p>
......
1222 961
	 *
1223 962
	 * @throws LoadLayerException if fails loading this layer.
1224 963
	 */
1225
//	public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
1226
//		fmap.clearErrors();
1227
//		this.addLayerFromXML(xml,name);
1228
//
1229
//		return (fmap.getLayersError().size() == 0);
1230
//
1231
//	}
964
	//	public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
965
	//		fmap.clearErrors();
966
	//		this.addLayerFromXML(xml,name);
967
	//
968
	//		return (fmap.getLayersError().size() == 0);
969
	//
970
	//	}
1232 971

  
1233 972
	/**
1234 973
	 * <p>Adds the layer with the information in an XML entity and the specified name, to this collection of layers.</p>
......
1243 982
	 * @throws LoadLayerException if fails loading this layer.
1244 983
	 */
1245 984
	private void addLayerFromXML(XMLEntity xml, String name) throws LoadLayerException {
1246
	FLayer layer = null;
985
		FLayer layer = null;
1247 986

  
1248
	try {
1249
		if (name == null) {
1250
			name = xml.getName();
1251
		}
987
		try {
988
			if (name == null) {
989
				name = xml.getName();
990
			}
1252 991

  
1253 992

  
1254
		String className = xml.getStringProperty("className");
1255
		Class clase = Class.forName(className);
1256
		layer = (FLayer) clase.newInstance();
1257
		if (FLayers.class.isAssignableFrom(clase)) {
1258
			((FLayers)layer).setMapContext(getMapContext());
1259
			((FLayers)layer).setParentLayer(this);
1260
//			layer = new FLayers(getMapContext(),this);
1261
			layer.setXMLEntity(xml);
1262
		} else {
1263
			// Capas Nuevas (externas)
1264
			layer.setName(name);
1265
			layer.setXMLEntity(xml);
1266
			layer.load();
1267
		}
993
			String className = xml.getStringProperty("className");
994
			Class clase = Class.forName(className);
995
			layer = (FLayer) clase.newInstance();
996
			if (FLayers.class.isAssignableFrom(clase)) {
997
				((FLayers)layer).setMapContext(getMapContext());
998
				((FLayers)layer).setParentLayer(this);
999
				//			layer = new FLayers(getMapContext(),this);
1000
				layer.setXMLEntity(xml);
1001
			} else {
1002
				// Capas Nuevas (externas)
1003
				layer.setName(name);
1004
				layer.setXMLEntity(xml);
1005
				layer.load();
1006
			}
1268 1007

  
1269
//		//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
1270
//		//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1271
//		if (className.equals(FLyrVect.class.getName())){// || className.equals(FLyrAnnotation.class.getName())) {
1272
//			String type = xml.getStringProperty("type");
1273
//			if ("vectorial".equals(type)){
1274
//				//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
1275
//				IProjection proj = null;
1276
//				if (xml.contains("proj")) {
1277
//					proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
1278
//				}
1279
//				else
1280
//				{
1281
//					proj = this.getMapContext().getViewPort().getProjection();
1282
//				}
1283
//				if (xml.contains("file")) {
1284
//					Driver d;
1285
//					try {
1286
//						d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
1287
//					} catch (DriverLoadException e1) {
1288
//						throw new DriverLayerException(name,e1);
1289
//					}
1290
//					layer = LayerFactory.createLayer(name, (VectorialFileDriver) d,
1291
//							new File(xml.getStringProperty("file")),
1292
//							proj);
1293
//
1294
//
1295
//				}
1296
//				if (xml.contains("db")) {
1297
//
1298
//					String driverName = xml.getStringProperty("db");
1299
//					IVectorialDatabaseDriver driver;
1300
//					try {
1301
//						driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
1302
//						//Hay que separar la carga de los datos del XMLEntity del load.
1303
//						driver.setXMLEntity(xml.getChild(2));
1304
//
1305
//						boolean loadOk = false;
1306
//						((DefaultJDBCDriver)driver).load();
1307
//						if (((DefaultJDBCDriver)driver).getConnection() != null) {
1308
//							loadOk = true;
1309
//						}
1310
//						layer = LayerFactory.createDBLayer(driver, name, proj);
1311
//						if (!loadOk) {
1312
//							layer.setAvailable(false);
1313
//						}
1314
//
1315
//					} catch (DriverLoadException e) {
1316
//						throw new DriverLayerException(name,e);
1317
//					} catch (XMLException e) {
1318
//						throw new DriverLayerException(name,e);
1319
//					} catch (ReadException e) {
1320
//						throw new DriverLayerException(name,e);
1321
//					}
1322
//
1323
//				}
1324
//				// Clases con algun driver gen?rico creado por otro
1325
//				// programador
1326
//				if (xml.contains("other")) {
1327
//
1328
//					String driverName = xml.getStringProperty("other");
1329
//					VectorialDriver driver = null;
1330
//					try {
1331
//						driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
1332
//					} catch (DriverLoadException e) {
1333
//						// Si no existe ese driver, no pasa nada.
1334
//						// Puede que el desarrollador no quiera que
1335
//						// aparezca en el cuadro de di?logo y ha metido
1336
//						// el jar con sus clases en nuestro directorio lib.
1337
//						// Intentamos cargar esa clase "a pelo".
1338
//						if (xml.getChild(2).contains("className"))
1339
//						{
1340
//							String className2 = xml.getChild(2).getStringProperty("className");
1341
//							try {
1342
//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1343
//							} catch (Exception e1) {
1344
//								throw new DriverLayerException(name,e);
1345
//							}
1346
//						}
1347
//					} catch (NullPointerException npe) {
1348
//						// Si no existe ese driver, no pasa nada.
1349
//						// Puede que el desarrollador no quiera que
1350
//						// aparezca en el cuadro de di?logo y ha metido
1351
//						// el jar con sus clases en nuestro directorio lib.
1352
//						// Intentamos cargar esa clase "a pelo".
1353
//						if (xml.getChild(2).contains("className"))
1354
//						{
1355
//							String className2 = xml.getChild(2).getStringProperty("className");
1356
//							try {
1357
//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1358
//							} catch (Exception e1) {
1359
//								throw new DriverLayerException(name,e1);
1360
//							}
1361
//						}
1362
//					}
1363
//					if (driver instanceof IPersistence)
1364
//					{
1365
//						IPersistence persist = (IPersistence) driver;
1366
//						persist.setXMLEntity(xml.getChild(2));
1367
//					}
1368
//					layer = LayerFactory.createLayer(name, driver, proj);
1369
//				}
1370
//
1371
//			}
1372
//
1373
//			//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
1374
//			//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1375
//			if (className.equals(FLyrAnnotation.class.getName())){
1376
//				layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer);
1377
//			}
1378
//
1379
//
1380
//			layer.setXMLEntity(xml);
1381
//
1382
//		} else {
1383
//			Class clase = LayerFactory.getLayerClassForLayerClassName(className);
1384
//			layer = (FLayer) clase.newInstance();
1385
//			if (clase.isAssignableFrom(FLayers.class)) {
1386
//				((FLayers)layer).setMapContext(getMapContext());
1387
//				((FLayers)layer).setParentLayer(this);
1388
////				layer = new FLayers(getMapContext(),this);
1389
//				layer.setXMLEntity(xml);
1390
//			} else {
1391
//				// Capas Nuevas (externas)
1392
//				layer.setName(name);
1393
//				layer.setXMLEntity(xml);
1394
//				layer.load();
1395
//			}
1396
//		}
1397
		this.addLayer(layer);
1398
		logger.debug("layer: "+ layer.getName() +" loaded");
1399
		// Comprobar que la proyecci?n es la misma que la de FMap
1400
		// Si no lo es, es una capa que est? reproyectada al vuelo
1401
		IProjection proj = layer.getProjection();
1402
		if ((proj != null)) {
1403
			if (!proj.getFullCode().equals(getMapContext().getProjection().getFullCode()))
1404
			{
1405
				ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1406
				// TODO: REVISAR CON LUIS
1407
				// Se lo fijamos a todas, luego cada una que se reproyecte
1408
				// si puede, o que no haga nada
1008
			//		//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
1009
			//		//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1010
			//		if (className.equals(FLyrVect.class.getName())){// || className.equals(FLyrAnnotation.class.getName())) {
1011
			//			String type = xml.getStringProperty("type");
1012
			//			if ("vectorial".equals(type)){
1013
			//				//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
1014
			//				IProjection proj = null;
1015
			//				if (xml.contains("proj")) {
1016
			//					proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
1017
			//				}
1018
			//				else
1019
			//				{
1020
			//					proj = this.getMapContext().getViewPort().getProjection();
1021
			//				}
1022
			//				if (xml.contains("file")) {
1023
			//					Driver d;
1024
			//					try {
1025
			//						d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
1026
			//					} catch (DriverLoadException e1) {
1027
			//						throw new DriverLayerException(name,e1);
1028
			//					}
1029
			//					layer = LayerFactory.createLayer(name, (VectorialFileDriver) d,
1030
			//							new File(xml.getStringProperty("file")),
1031
			//							proj);
1032
			//
1033
			//
1034
			//				}
1035
			//				if (xml.contains("db")) {
1036
			//
1037
			//					String driverName = xml.getStringProperty("db");
1038
			//					IVectorialDatabaseDriver driver;
1039
			//					try {
1040
			//						driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
1041
			//						//Hay que separar la carga de los datos del XMLEntity del load.
1042
			//						driver.setXMLEntity(xml.getChild(2));
1043
			//
1044
			//						boolean loadOk = false;
1045
			//						((DefaultJDBCDriver)driver).load();
1046
			//						if (((DefaultJDBCDriver)driver).getConnection() != null) {
1047
			//							loadOk = true;
1048
			//						}
1049
			//						layer = LayerFactory.createDBLayer(driver, name, proj);
1050
			//						if (!loadOk) {
1051
			//							layer.setAvailable(false);
1052
			//						}
1053
			//
1054
			//					} catch (DriverLoadException e) {
1055
			//						throw new DriverLayerException(name,e);
1056
			//					} catch (XMLException e) {
1057
			//						throw new DriverLayerException(name,e);
1058
			//					} catch (ReadException e) {
1059
			//						throw new DriverLayerException(name,e);
1060
			//					}
1061
			//
1062
			//				}
1063
			//				// Clases con algun driver gen?rico creado por otro
1064
			//				// programador
1065
			//				if (xml.contains("other")) {
1066
			//
1067
			//					String driverName = xml.getStringProperty("other");
1068
			//					VectorialDriver driver = null;
1069
			//					try {
1070
			//						driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
1071
			//					} catch (DriverLoadException e) {
1072
			//						// Si no existe ese driver, no pasa nada.
1073
			//						// Puede que el desarrollador no quiera que
1074
			//						// aparezca en el cuadro de di?logo y ha metido
1075
			//						// el jar con sus clases en nuestro directorio lib.
1076
			//						// Intentamos cargar esa clase "a pelo".
1077
			//						if (xml.getChild(2).contains("className"))
1078
			//						{
1079
			//							String className2 = xml.getChild(2).getStringProperty("className");
1080
			//							try {
1081
			//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1082
			//							} catch (Exception e1) {
1083
			//								throw new DriverLayerException(name,e);
1084
			//							}
1085
			//						}
1086
			//					} catch (NullPointerException npe) {
1087
			//						// Si no existe ese driver, no pasa nada.
1088
			//						// Puede que el desarrollador no quiera que
1089
			//						// aparezca en el cuadro de di?logo y ha metido
1090
			//						// el jar con sus clases en nuestro directorio lib.
1091
			//						// Intentamos cargar esa clase "a pelo".
1092
			//						if (xml.getChild(2).contains("className"))
1093
			//						{
1094
			//							String className2 = xml.getChild(2).getStringProperty("className");
1095
			//							try {
1096
			//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1097
			//							} catch (Exception e1) {
1098
			//								throw new DriverLayerException(name,e1);
1099
			//							}
1100
			//						}
1101
			//					}
1102
			//					if (driver instanceof IPersistence)
1103
			//					{
1104
			//						IPersistence persist = (IPersistence) driver;
1105
			//						persist.setXMLEntity(xml.getChild(2));
1106
			//					}
1107
			//					layer = LayerFactory.createLayer(name, driver, proj);
1108
			//				}
1109
			//
1110
			//			}
1111
			//
1112
			//			//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
1113
			//			//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1114
			//			if (className.equals(FLyrAnnotation.class.getName())){
1115
			//				layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer);
1116
			//			}
1117
			//
1118
			//
1119
			//			layer.setXMLEntity(xml);
1120
			//
1121
			//		} else {
1122
			//			Class clase = LayerFactory.getLayerClassForLayerClassName(className);
1123
			//			layer = (FLayer) clase.newInstance();
1124
			//			if (clase.isAssignableFrom(FLayers.class)) {
1125
			//				((FLayers)layer).setMapContext(getMapContext());
1126
			//				((FLayers)layer).setParentLayer(this);
1127
			////				layer = new FLayers(getMapContext(),this);
1128
			//				layer.setXMLEntity(xml);
1129
			//			} else {
1130
			//				// Capas Nuevas (externas)
1131
			//				layer.setName(name);
1132
			//				layer.setXMLEntity(xml);
1133
			//				layer.load();
1134
			//			}
1135
			//		}
1136
			this.addLayer(layer);
1137
			logger.debug("layer: "+ layer.getName() +" loaded");
1138
			// Comprobar que la proyecci?n es la misma que la de FMap
1139
			// Si no lo es, es una capa que est? reproyectada al vuelo
1140
			IProjection proj = layer.getProjection();
1141
			if ((proj != null)) {
1142
				if (!proj.getFullCode().equals(getMapContext().getProjection().getFullCode()))
1143
				{
1144
					ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1145
					// TODO: REVISAR CON LUIS
1146
					// Se lo fijamos a todas, luego cada una que se reproyecte
1147
					// si puede, o que no haga nada
1409 1148

  
1410
				layer.setCoordTrans(ct);
1149
					layer.setCoordTrans(ct);
1150
				}
1411 1151
			}
1152
		} catch (XMLException e) {
1153
			fmap.addLayerError(xml.getStringProperty("name"));
1154
			throw new LoadLayerException(name,e);
1155
		} catch (ClassNotFoundException e) {
1156
			fmap.addLayerError(xml.getStringProperty("name"));
1157
			throw new LoadLayerException(name,e);
1158
		} catch (InstantiationException e) {
1159
			fmap.addLayerError(xml.getStringProperty("name"));
1160
			throw new LoadLayerException(name,e);
1161
		} catch (IllegalAccessException e) {
1162
			fmap.addLayerError(xml.getStringProperty("name"));
1163
			throw new LoadLayerException(name,e);
1164
		} catch (LoadLayerException e){
1165
			fmap.addLayerError(xml.getStringProperty("name"));
1166
			throw e;
1412 1167
		}
1413
	} catch (XMLException e) {
1414
		fmap.addLayerError(xml.getStringProperty("name"));
1415
		throw new LoadLayerException(name,e);
1416
	} catch (ClassNotFoundException e) {
1417
		fmap.addLayerError(xml.getStringProperty("name"));
1418
		throw new LoadLayerException(name,e);
1419
	} catch (InstantiationException e) {
1420
		fmap.addLayerError(xml.getStringProperty("name"));
1421
		throw new LoadLayerException(name,e);
1422
	} catch (IllegalAccessException e) {
1423
		fmap.addLayerError(xml.getStringProperty("name"));
1424
		throw new LoadLayerException(name,e);
1425
	} catch (LoadLayerException e){
1426
		fmap.addLayerError(xml.getStringProperty("name"));
1427
		throw e;
1428 1168
	}
1429
	}
1430 1169

  
1431 1170
	/**
1432 1171
	 * <p>Sets the <code>MapContext</code> that contains this layer node.</p>
......
1448 1187
	 * @param name name of the layer to add
1449 1188
	 */
1450 1189
	private void addLayerFromXMLNew(XMLEntity xml, String name) {
1451
//		FLayer layer = null;
1452
//
1453
//
1454
//		try {
1455
//			String className = xml.getStringProperty("className");
1456
//			Class clazz = Class.forName(className);
1457
//			if (clazz.isAssignableFrom(FLayers.class)) {
1458
//				layer = (FLayer) clazz.newInstance();
1459
//				((FLayers)layer).setMapContext(getMapContext());
1460
//				((FLayers)layer).setParentLayer(this);
1461
//	//		if (className.equals((FLayers.class.getName()))){
1462
//	//			layer = new FLayers(getMapContext(),this);
1463
//			} else {
1464
//	//			Por compatibilidad
1465
//				if (className.equals(FLyrVect.class.getName())) {
1466
//					if (xml.contains("file")) {
1467
//						layer = new FLayerFileVectorial();
1468
//					} else if (xml.contains("db")) {
1469
//						try {
1470
//							layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial");
1471
//						} catch (Exception e) {
1472
//							throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC"));
1473
//						}
1474
//						//className = FLayerJDBCVectorial.class.getName();
1475
//					} else if (xml.contains("other")){
1476
//						layer = new FLayerGenericVectorial();
1477
//					} else {
1478
//						throw new XMLException(new Exception("Capa vectorial de tipo no reconocido"));
1479
//					}
1480
//	//				Fin por compatibilidad
1481
//				} else {
1482
//					try {
1483
//						layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
1484
//					} catch (Exception e) {
1485
//						//puende que no este registrada como punto de extension
1486
//						Class clase = Class.forName(className);
1487
//						layer = (FLayer) clase.newInstance();
1488
//						// FIXME: Hacemos algo aqui o dejamos que suba el error?
1489
//					}
1490
//				}
1491
//
1492
//			}
1493
//			layer.setXMLEntity(xml);
1494
//			if (name != null) layer.setName(name);
1495
//			layer.load();
1496
//
1497
//			this.addLayer(layer);
1498
//			logger.debug("layer: "+ layer.getName() +" loaded");
1499
//			// Comprobar que la proyecci?n es la misma que la de FMap
1500
//			// Si no lo es, es una capa que est? reproyectada al vuelo
1501
//			IProjection proj = layer.getProjection();
1502
//			if ((proj != null))
1503
//				if (proj != getMapContext().getProjection())
1504
//				{
1505
//					ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1506
//					// TODO: REVISAR CON LUIS
1507
//					// Se lo fijamos a todas, luego cada una que se reproyecte
1508
//					// si puede, o que no haga nada
1509
//					layer.setCoordTrans(ct);
1510
//
1511
//				}
1512
//		}catch (Exception e) {
1513
//			fmap.addLayerError(xml.getStringProperty("name"));
1514
//			logger.debug(Messages.getString("could_not_load_layer")+": "+xml.getStringProperty("name") + ".\n"
1515
//					+Messages.getString("reason")+":", e);
1516
//		}
1190
		//		FLayer layer = null;
1191
		//
1192
		//
1193
		//		try {
1194
		//			String className = xml.getStringProperty("className");
1195
		//			Class clazz = Class.forName(className);
1196
		//			if (clazz.isAssignableFrom(FLayers.class)) {
1197
		//				layer = (FLayer) clazz.newInstance();
1198
		//				((FLayers)layer).setMapContext(getMapContext());
1199
		//				((FLayers)layer).setParentLayer(this);
1200
		//	//		if (className.equals((FLayers.class.getName()))){
1201
		//	//			layer = new FLayers(getMapContext(),this);
1202
		//			} else {
1203
		//	//			Por compatibilidad
1204
		//				if (className.equals(FLyrVect.class.getName())) {
1205
		//					if (xml.contains("file")) {
1206
		//						layer = new FLayerFileVectorial();
1207
		//					} else if (xml.contains("db")) {
1208
		//						try {
1209
		//							layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial");
1210
		//						} catch (Exception e) {
1211
		//							throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC"));
1212
		//						}
1213
		//						//className = FLayerJDBCVectorial.class.getName();
1214
		//					} else if (xml.contains("other")){
1215
		//						layer = new FLayerGenericVectorial();
1216
		//					} else {
1217
		//						throw new XMLException(new Exception("Capa vectorial de tipo no reconocido"));
1218
		//					}
1219
		//	//				Fin por compatibilidad
1220
		//				} else {
1221
		//					try {
1222
		//						layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
1223
		//					} catch (Exception e) {
1224
		//						//puende que no este registrada como punto de extension
1225
		//						Class clase = Class.forName(className);
1226
		//						layer = (FLayer) clase.newInstance();
1227
		//						// FIXME: Hacemos algo aqui o dejamos que suba el error?
1228
		//					}
1229
		//				}
1230
		//
1231
		//			}
1232
		//			layer.setXMLEntity(xml);
1233
		//			if (name != null) layer.setName(name);
1234
		//			layer.load();
1235
		//
1236
		//			this.addLayer(layer);
1237
		//			logger.debug("layer: "+ layer.getName() +" loaded");
1238
		//			// Comprobar que la proyecci?n es la misma que la de FMap
1239
		//			// Si no lo es, es una capa que est? reproyectada al vuelo
1240
		//			IProjection proj = layer.getProjection();
1241
		//			if ((proj != null))
1242
		//				if (proj != getMapContext().getProjection())
1243
		//				{
1244
		//					ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1245
		//					// TODO: REVISAR CON LUIS
1246
		//					// Se lo fijamos a todas, luego cada una que se reproyecte
1247
		//					// si puede, o que no haga nada
1248
		//					layer.setCoordTrans(ct);
1249
		//
1250
		//				}
1251
		//		}catch (Exception e) {
1252
		//			fmap.addLayerError(xml.getStringProperty("name"));
1253
		//			logger.debug(Messages.getString("could_not_load_layer")+": "+xml.getStringProperty("name") + ".\n"
1254
		//					+Messages.getString("reason")+":", e);
1255
		//		}
1517 1256
	}
1518 1257

  
1519 1258
	public void accept(Visitor visitor) throws BaseException {
......
1585 1324
	}
1586 1325

  
1587 1326

  
1327
	public void beginDraw(Graphics2D g, ViewPort viewPort) {
1328
		LayerDrawEvent beforeEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW);
1329
		fmap.fireLayerDrawingEvent(beforeEvent);
1330
	}
1331

  
1332
	public void endDraw(Graphics2D g, ViewPort viewPort) {
1333
		LayerDrawEvent afterEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
1334
		fmap.fireLayerDrawingEvent(afterEvent);
1335
	}
1336

  
1588 1337
}

Also available in: Unified diff