Revision 42543 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/FLayers.java

View differences:

FLayers.java
90 90

  
91 91
    /**
92 92
     * List with all listeners registered for this kind of node.
93
     *
94
     * @see #addLayerCollectionListener(LayerCollectionListener)
95
     * @see #removeLayerCollectionListener(LayerCollectionListener)
96
     * @see #callLayerAdded(LayerCollectionEvent)
97
     * @see #callLayerAdding(LayerCollectionEvent)
98
     * @see #callLayerMoved(LayerPositionEvent)
99
     * @see #callLayerMoving(LayerPositionEvent)
100
     * @see #callLayerRemoved(LayerCollectionEvent)
101
     * @see #callLayerRemoving(LayerCollectionEvent)
102 93
     */
103 94
    protected ArrayList layerCollectionListeners = null;
104 95

  
105 96
    /**
106 97
     * A synchronized list with the layers.
107
     *
108
     * @see #setAllVisibles(boolean)
109
     * @see #addLayer(FLayer)
110
     * @see #addLayer(int, FLayer)
111
     * @see #moveTo(int, int)
112
     * @see #removeLayer(FLayer)
113
     * @see #removeLayer(int)
114
     * @see #removeLayer(String)
115
     * @see #replaceLayer(String, FLayer)
116
     * @see #getVisibles()
117
     * @see #getLayer(int)
118
     * @see #getLayer(String)
119
     * @see #getLayersCount()
120
     * @see #getFullEnvelope()
121 98
     */
122 99
    protected List<FLayer> layers = null;
123 100

  
124
    /**
125
     * The model of the layer.
126
     *
127
     * @see #getMapContext()
128
     */
129 101
    protected MapContext fmap;
130 102

  
131 103
    /**
132 104
     * Useful for debug the problems during the implementation.
133 105
     */
134
    private static Logger logger = LoggerFactory.getLogger(FLayers.class);
106
    private static final Logger logger = LoggerFactory.getLogger(FLayers.class);
135 107

  
136 108
    public FLayers() {
137 109
        super();
138 110
        layerCollectionListeners = new ArrayList();
139 111
        layers = Collections.synchronizedList(new ArrayList());
140

  
141
        logger = LoggerFactory.getLogger(FLayers.class);
142 112
    }
143 113
    /*
144 114
     * (non-Javadoc)
145 115
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
146 116
     */
147 117

  
118
    @Override
148 119
    public void addLayerCollectionListener(LayerCollectionListener listener) {
149 120
        if (!layerCollectionListeners.contains(listener)) {
150 121
            layerCollectionListeners.add(listener);
......
155 126
     * (non-Javadoc)
156 127
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllVisibles(boolean)
157 128
     */
129
    @Override
158 130
    public void setAllVisibles(boolean visible) {
159 131
        FLayer lyr;
160 132

  
......
172 144
     * (non-Javadoc)
173 145
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
174 146
     */
147
    @Override
175 148
    public void removeLayerCollectionListener(LayerCollectionListener listener) {
176 149
        layerCollectionListeners.remove(listener);
177 150
    }
......
205 178
     * (non-Javadoc)
206 179
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
207 180
     */
181
    @Override
208 182
    public void addLayer(FLayer layer) {
209 183

  
210 184
        MapContext mco = this.getMapContext();
......
227 201
    /**
228 202
     * Adds a layer in an specified position in this node.
229 203
     *
204
     * @param pos
230 205
     * @param layer a layer
231 206
     */
232 207
    public void addLayer(int pos, FLayer layer) {
......
257 232
     * (non-Javadoc)
258 233
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#moveTo(int, int)
259 234
     */
235
    @Override
260 236
    public void moveTo(int from, int to) throws CancelationException {
261 237
        int newfrom = layers.size() - from - 1;
262 238
        int newto = layers.size() - to - 1;
......
286 262
     * (non-Javadoc)
287 263
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
288 264
     */
265
    @Override
289 266
    public void removeLayer(FLayer lyr) throws CancelationException {
290 267
        callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr));
291 268
        doRemoveLayer(lyr);
......
296 273
     * (non-Javadoc)
297 274
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(int)
298 275
     */
276
    @Override
299 277
    public void removeLayer(int idLayer) {
300 278
        FLayer lyr = (FLayer) layers.get(idLayer);
301 279
        callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr));
......
309 287
     * (non-Javadoc)
310 288
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(java.lang.String)
311 289
     */
290
    @Override
312 291
    public void removeLayer(String layerName) {
313 292
        FLayer lyr;
314 293

  
......
328 307
     *
329 308
     * @param layerName the name of the layer to be replaced
330 309
     * @param layer the new layer
310
     * @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
331 311
     * @deprecated use {@link FLayers#replaceLayer(FLayer, FLayer)}
332 312
     */
333 313
    public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException {
......
340 320
     *
341 321
     * @param layer the layer to be replaced
342 322
     * @param newLayer the new layer
323
     * @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
343 324
     */
344 325
    public void replaceLayer(FLayer layer, FLayer newLayer) throws LoadLayerException {
345 326
        replaceLayer(this, layer, newLayer);
......
373 354
     * (non-Javadoc)
374 355
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getVisibles()
375 356
     */
357
    @Override
376 358
    public FLayer[] getVisibles() {
377 359
        ArrayList array = new ArrayList();
378 360
        LayersIterator iter = new LayersIterator(this) {
361
            @Override
379 362
            public boolean evaluate(FLayer layer) {
380 363
                return layer.isVisible();
381 364
            }
......
393 376
     * (non-Javadoc)
394 377
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(int)
395 378
     */
379
    @Override
396 380
    public FLayer getLayer(int index) {
397 381
        return (FLayer) layers.get(index);
398 382
    }
......
401 385
     * (non-Javadoc)
402 386
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(java.lang.String)
403 387
     */
388
    @Override
404 389
    public FLayer getLayer(String layerName) {
405 390
        for (int i = 0; i < layers.size(); i++) {
406 391
            FLayer lyr = ((FLayer) layers.get(i));
......
440 425
     * (non-Javadoc)
441 426
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayersCount()
442 427
     */
428
    @Override
443 429
    public int getLayersCount() {
444 430
        return layers.size();
445 431
    }
......
448 434
     * (non-Javadoc)
449 435
     * @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)
450 436
     */
437
    @Override
451 438
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
452 439
            Cancellable cancel, double scale) throws ReadException {
453 440
        // FIXME Arreglar este error
......
462 449
     * com.iver.utiles.swing.threads.Cancellable, double,
463 450
     * javax.print.attribute.PrintAttributes)
464 451
     */
452
    @Override
465 453
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
466 454
            double scale, PrintAttributes properties)
467 455
            throws ReadException {
......
515 503
     *
516 504
     * @return <code>null</code> if the layers in <code>group</code> had been
517 505
     * drawn or were <code>null</code>; otherwise, the <code>group</code>
506
     * @throws org.gvsig.fmap.dal.exception.ReadException
518 507
     *
519 508
     * @see FLayer#print(Graphics2D, ViewPort, Cancellable, double,
520 509
     * PrintAttributes)
521
     *
522
     * @throws ReadDriverException if fails the driver reading the data.
523 510
     */
524 511
    public ComposedLayer print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties, ComposedLayer group)
525 512
            throws ReadException {
......
546 533

  
547 534
            try {
548 535

  
549
                ///// CHEMA ComposedLayer
550 536
                // Checks for draw group (ComposedLayer)
551 537
                if (group != null) {
552 538
                    if (lyr instanceof FLayers) {
......
616 602

  
617 603
                    }
618 604
                }
619
                ///// CHEMA ComposedLayer
620 605

  
621 606
            } catch (Exception e) {
622 607
                String mesg = Messages.getString("error_printing_layer") + " " + lyr.getName() + ": " + e.getMessage();
......
626 611

  
627 612
        }
628 613

  
629
        ///// CHEMA ComposedLayer
630 614
        if (group != null && this.getParentLayer() == null) {
631 615
            //si tenemos un grupo pendiente de pintar, pintamos
632 616
            group.print(g, viewPort, cancel, scale, properties);
633 617
            group = null;
634 618

  
635 619
        }
636
		///// CHEMA ComposedLayer
637

  
638
        //		if (getVirtualLayers() != null) {
639
        //			getVirtualLayers().print( g, viewPort, cancel, scale, properties);
640
        //		}
641
        ///// CHEMA ComposedLayer
642 620
        return group;
643
        ///// CHEMA ComposedLayer
644 621
    }
645 622

  
646 623
    /*
647 624
     * (non-Javadoc)
648 625
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
649 626
     */
627
    @Override
650 628
    public Envelope getFullEnvelope() {
651 629
        Envelope rAux = null;
652 630
        boolean first = true;
......
661 639
                    rAux.add(capa.getFullEnvelope());
662 640
                }
663 641
            } catch (Exception e) {
664
                e.printStackTrace();//TODO hay que revisar para determinar el comportamiento que espera el usuario.
642
                logger.warn("Can't calculate the envelope of the layer group '"+this.getName()+"'.",e);
665 643
            }
666 644
        }
667 645

  
......
673 651
     * another layer is going to be added or replaced in the internal list of
674 652
     * layers.
675 653
     *
676
     * @param e a layer collection event with the new layer
654
     * @param event a layer collection event with the new layer
677 655
     */
678 656
    protected void callLayerAdding(LayerCollectionEvent event)
679 657
            throws CancelationException {
......
722 700
     * Notifies all listeners associated to this collection of layers, that
723 701
     * another layer has been added or replaced in the internal list of layers.
724 702
     *
725
     * @param e a layer collection event with the new layer
703
     * @param event a layer collection event with the new layer
726 704
     */
727 705
    protected void callLayerAdded(LayerCollectionEvent event) {
728 706
        ArrayList aux = (ArrayList) layerCollectionListeners.clone();
......
735 713
     * Notifies all listeners associated to this collection of layers, that
736 714
     * another layer has been removed from the internal list of layers.
737 715
     *
738
     * @param e a layer collection event with the layer removed
716
     * @param event a layer collection event with the layer removed
739 717
     */
740 718
    protected void callLayerRemoved(LayerCollectionEvent event) {
741 719
        ArrayList aux = (ArrayList) layerCollectionListeners.clone();
......
748 726
     * Notifies all listeners associated to this collection of layers, that
749 727
     * another layer has been moved in the internal list of layers.
750 728
     *
751
     * @param e a layer collection event with the layer moved, and the initial
729
     * @param event a layer collection event with the layer moved, and the initial
752 730
     * and final positions
753 731
     */
754 732
    protected void callLayerMoved(LayerPositionEvent event) {
......
758 736
        }
759 737
    }
760 738

  
739
    @Override
761 740
    public void saveToState(PersistentState state) throws PersistenceException {
762 741

  
763 742
        super.saveToState(state);
......
775 754
        state.set("layers", layersToSave);
776 755
    }
777 756

  
757
    @Override
778 758
    public void loadFromState(PersistentState state) throws PersistenceException {
779 759

  
780 760
        super.loadFromState(state);
......
791 771
     * (non-Javadoc)
792 772
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMapContext()
793 773
     */
774
    @Override
794 775
    public MapContext getMapContext() {
795 776
        return fmap;
796 777
    }
797 778

  
798 779
    /*
799
     * I don't think this implementation makes any sense.
800
     * We can group layers with different transformations,
801
     * we cannot set the ICoordTrans for all (?)
802
     * 
803
     public void setCoordTrans(ICoordTrans ct) {
804
     super.setCoordTrans(ct);
805

  
806
     for (Iterator iter = layers.iterator(); iter.hasNext();) {
807
     FLayer layer = (FLayer) iter.next();
808
     layer.setCoordTrans(ct);
809
     }
810
     }
811
     */
812
    /*
813 780
     * (non-Javadoc)
814 781
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
815 782
     */
783
    @Override
816 784
    public void setAllActives(boolean active) {
817 785
        FLayer lyr;
818 786

  
......
830 798
     * (non-Javadoc)
831 799
     * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
832 800
     */
801
    @Override
833 802
    public FLayer[] getActives() {
834 803
        List ret = new ArrayList();
835 804
        LayersIterator it = new LayersIterator(this) {
836 805

  
806
            @Override
837 807
            public boolean evaluate(FLayer layer) {
838 808
                return layer.isActive();
839 809
            }
......
850 820
     * (non-Javadoc)
851 821
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMinScale()
852 822
     */
823
    @Override
853 824
    public double getMinScale() {
854 825
        return -1; // La visibilidad o no la controla cada capa
855 826
        // dentro de una colecci?n
......
859 830
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMaxScale()
860 831
     */
861 832

  
833
    @Override
862 834
    public double getMaxScale() {
863 835
        return -1;
864 836
    }
......
867 839
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMinScale(double)
868 840
     */
869 841

  
842
    @Override
870 843
    public void setMinScale(double minScale) {
871 844
        for (Iterator iter = layers.iterator(); iter.hasNext();) {
872 845
            FLayer lyr = (FLayer) iter.next();
......
878 851
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMaxScale(double)
879 852
     */
880 853

  
854
    @Override
881 855
    public void setMaxScale(double maxScale) {
882 856
        for (Iterator iter = layers.iterator(); iter.hasNext();) {
883 857
            FLayer lyr = (FLayer) iter.next();
......
889 863
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setActive(boolean)
890 864
     */
891 865

  
866
    @Override
892 867
    public void setActive(boolean b) {
893 868
        super.setActive(b);
894 869
        for (int i = 0; i < layers.size(); i++) {
......
899 874
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
900 875
     */
901 876

  
877
    @Override
902 878
    public boolean addLayerListener(LayerListener o) {
903 879
        for (int i = 0; i < layers.size(); i++) {
904 880
            ((FLayer) layers.get(i)).addLayerListener(o);
......
906 882
        return true;
907 883
    }
908 884

  
885
    @Override
909 886
    public DynObjectSet getInfo(Point p, double tolerance,
910 887
            Cancellable cancel) throws LoadLayerException, DataException {
911 888
        return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance);
912 889
    }
913 890

  
891
    @Override
914 892
    public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel,
915 893
            boolean fast) throws LoadLayerException, DataException {
916 894
        return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance);
917 895
    }
918 896

  
897
    @Override
919 898
    public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p,
920 899
            double tolerance) throws LoadLayerException, DataException {
921 900
        int i;
......
937 916
     * (non-Javadoc)
938 917
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
939 918
     */
919
    @Override
940 920
    public String getTocImageIcon() {
941 921
        return "layer-icon-group";
942 922
    }
943 923

  
944 924
    /**
945 925
     * <p>
946
     * Adds the layer with the information in an XML entity and the specified
947
     * name, to this collection of layers. And returns <code>true</code> if
948
     * there hasn't been errors.</p>
949
     *
950
     * @see CopyOfFLayers#addLayerFromXML(XMLEntity, String)
951
     *
952
     * @param xml tree-node structure with information about layers
953
     * @param name name of the layer to add
954
     * @return <code>true</code> if there were no errors adding the layer,
955
     * <code>false</code> otherwise
956
     *
957
     * @throws LoadLayerException if fails loading this layer.
958
     */
959
    //	public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
960
    //		fmap.clearErrors();
961
    //		this.addLayerFromXML(xml,name);
962
    //
963
    //		return (fmap.getLayersError().size() == 0);
964
    //
965
    //	}
966
//	/**
967
//	 * <p>Adds the layer with the information in an XML entity and the specified name, to this collection of layers.</p>
968
//	 *
969
//	 * <p>This method really executes the addition, considering the kind of layer (<code>FLyrVect</code>,
970
//	 *  <code>FLyrAnnotation</code>, <code>FLyrRaster</code>, a collection of layers (<code>FLayers</code>),
971
//	 *  or another kind of layer (<code>FLayer</code>)), and the driver in the layer.</p>
972
//	 *
973
//	 * @param xml tree-node structure with information about layers
974
//	 * @param name name of the layer to add
975
//	 *
976
//	 * @throws LoadLayerException if fails loading this layer.
977
//	 */
978
//	private void addLayerFromXML(XMLEntity xml, String name) throws LoadLayerException {
979
//		FLayer layer = null;
980
//
981
//		try {
982
//			if (name == null) {
983
//				name = xml.getName();
984
//			}
985
//
986
//
987
//			String className = xml.getStringProperty("className");
988
//			Class clase = Class.forName(className);
989
//			layer = (FLayer) clase.newInstance();
990
//			if (FLayers.class.isAssignableFrom(clase)) {
991
//				((FLayers)layer).setMapContext(getMapContext());
992
//				((FLayers)layer).setParentLayer(this);
993
//				//			layer = new FLayers(getMapContext(),this);
994
//				layer.setXMLEntity(xml);
995
//			} else {
996
//				// Capas Nuevas (externas)
997
//				layer.setName(name);
998
//				layer.setXMLEntity(xml);
999
//				layer.load();
1000
//			}
1001
//
1002
//			//		//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,
1003
//			//		//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1004
//			//		if (className.equals(FLyrVect.class.getName())){// || className.equals(FLyrAnnotation.class.getName())) {
1005
//			//			String type = xml.getStringProperty("type");
1006
//			//			if ("vectorial".equals(type)){
1007
//			//				//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
1008
//			//				IProjection proj = null;
1009
//			//				if (xml.contains("proj")) {
1010
//			//					proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
1011
//			//				}
1012
//			//				else
1013
//			//				{
1014
//			//					proj = this.getMapContext().getViewPort().getProjection();
1015
//			//				}
1016
//			//				if (xml.contains("file")) {
1017
//			//					Driver d;
1018
//			//					try {
1019
//			//						d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
1020
//			//					} catch (DriverLoadException e1) {
1021
//			//						throw new DriverLayerException(name,e1);
1022
//			//					}
1023
//			//					layer = LayerFactory.createLayer(name, (VectorialFileDriver) d,
1024
//			//							new File(xml.getStringProperty("file")),
1025
//			//							proj);
1026
//			//
1027
//			//
1028
//			//				}
1029
//			//				if (xml.contains("db")) {
1030
//			//
1031
//			//					String driverName = xml.getStringProperty("db");
1032
//			//					IVectorialDatabaseDriver driver;
1033
//			//					try {
1034
//			//						driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
1035
//			//						//Hay que separar la carga de los datos del XMLEntity del load.
1036
//			//						driver.setXMLEntity(xml.getChild(2));
1037
//			//
1038
//			//						boolean loadOk = false;
1039
//			//						((DefaultJDBCDriver)driver).load();
1040
//			//						if (((DefaultJDBCDriver)driver).getConnection() != null) {
1041
//			//							loadOk = true;
1042
//			//						}
1043
//			//						layer = LayerFactory.createDBLayer(driver, name, proj);
1044
//			//						if (!loadOk) {
1045
//			//							layer.setAvailable(false);
1046
//			//						}
1047
//			//
1048
//			//					} catch (DriverLoadException e) {
1049
//			//						throw new DriverLayerException(name,e);
1050
//			//					} catch (XMLException e) {
1051
//			//						throw new DriverLayerException(name,e);
1052
//			//					} catch (ReadException e) {
1053
//			//						throw new DriverLayerException(name,e);
1054
//			//					}
1055
//			//
1056
//			//				}
1057
//			//				// Clases con algun driver gen?rico creado por otro
1058
//			//				// programador
1059
//			//				if (xml.contains("other")) {
1060
//			//
1061
//			//					String driverName = xml.getStringProperty("other");
1062
//			//					VectorialDriver driver = null;
1063
//			//					try {
1064
//			//						driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
1065
//			//					} catch (DriverLoadException e) {
1066
//			//						// Si no existe ese driver, no pasa nada.
1067
//			//						// Puede que el desarrollador no quiera que
1068
//			//						// aparezca en el cuadro de di?logo y ha metido
1069
//			//						// el jar con sus clases en nuestro directorio lib.
1070
//			//						// Intentamos cargar esa clase "a pelo".
1071
//			//						if (xml.getChild(2).contains("className"))
1072
//			//						{
1073
//			//							String className2 = xml.getChild(2).getStringProperty("className");
1074
//			//							try {
1075
//			//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1076
//			//							} catch (Exception e1) {
1077
//			//								throw new DriverLayerException(name,e);
1078
//			//							}
1079
//			//						}
1080
//			//					} catch (NullPointerException npe) {
1081
//			//						// Si no existe ese driver, no pasa nada.
1082
//			//						// Puede que el desarrollador no quiera que
1083
//			//						// aparezca en el cuadro de di?logo y ha metido
1084
//			//						// el jar con sus clases en nuestro directorio lib.
1085
//			//						// Intentamos cargar esa clase "a pelo".
1086
//			//						if (xml.getChild(2).contains("className"))
1087
//			//						{
1088
//			//							String className2 = xml.getChild(2).getStringProperty("className");
1089
//			//							try {
1090
//			//								driver = (VectorialDriver) Class.forName(className2).newInstance();
1091
//			//							} catch (Exception e1) {
1092
//			//								throw new DriverLayerException(name,e1);
1093
//			//							}
1094
//			//						}
1095
//			//					}
1096
//			//					if (driver instanceof IPersistence)
1097
//			//					{
1098
//			//						IPersistence persist = (IPersistence) driver;
1099
//			//						persist.setXMLEntity(xml.getChild(2));
1100
//			//					}
1101
//			//					layer = LayerFactory.createLayer(name, driver, proj);
1102
//			//				}
1103
//			//
1104
//			//			}
1105
//			//
1106
//			//			//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,
1107
//			//			//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
1108
//			//			if (className.equals(FLyrAnnotation.class.getName())){
1109
//			//				layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer);
1110
//			//			}
1111
//			//
1112
//			//
1113
//			//			layer.setXMLEntity(xml);
1114
//			//
1115
//			//		} else {
1116
//			//			Class clase = LayerFactory.getLayerClassForLayerClassName(className);
1117
//			//			layer = (FLayer) clase.newInstance();
1118
//			//			if (clase.isAssignableFrom(FLayers.class)) {
1119
//			//				((FLayers)layer).setMapContext(getMapContext());
1120
//			//				((FLayers)layer).setParentLayer(this);
1121
//			////				layer = new FLayers(getMapContext(),this);
1122
//			//				layer.setXMLEntity(xml);
1123
//			//			} else {
1124
//			//				// Capas Nuevas (externas)
1125
//			//				layer.setName(name);
1126
//			//				layer.setXMLEntity(xml);
1127
//			//				layer.load();
1128
//			//			}
1129
//			//		}
1130
//			this.addLayer(layer);
1131
//			logger.debug("layer: "+ layer.getName() +" loaded");
1132
//			// Comprobar que la proyecci?n es la misma que la de FMap
1133
//			// Si no lo es, es una capa que est? reproyectada al vuelo
1134
//			IProjection proj = layer.getProjection();
1135
//			if ((proj != null)) {
1136
//				if (!proj.getFullCode().equals(getMapContext().getProjection().getFullCode()))
1137
//				{
1138
//					ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1139
//					// TODO: REVISAR CON LUIS
1140
//					// Se lo fijamos a todas, luego cada una que se reproyecte
1141
//					// si puede, o que no haga nada
1142
//
1143
//					layer.setCoordTrans(ct);
1144
//				}
1145
//			}
1146
//		} catch (XMLException e) {
1147
//			fmap.addLayerError(xml.getStringProperty("name"));
1148
//			throw new LoadLayerException(name,e);
1149
//		} catch (ClassNotFoundException e) {
1150
//			fmap.addLayerError(xml.getStringProperty("name"));
1151
//			throw new LoadLayerException(name,e);
1152
//		} catch (InstantiationException e) {
1153
//			fmap.addLayerError(xml.getStringProperty("name"));
1154
//			throw new LoadLayerException(name,e);
1155
//		} catch (IllegalAccessException e) {
1156
//			fmap.addLayerError(xml.getStringProperty("name"));
1157
//			throw new LoadLayerException(name,e);
1158
//		} catch (LoadLayerException e){
1159
//			fmap.addLayerError(xml.getStringProperty("name"));
1160
//			throw e;
1161
//		}
1162
//	}
1163
    /**
1164
     * <p>
1165 926
     * Sets the <code>MapContext</code> that contains this layer node.</p>
1166 927
     *
1167 928
     * @param mapContext the <code>MapContext</code> that contains this layer
......
1171 932
        this.fmap = mapContext;
1172 933
    }
1173 934

  
1174
//	/**
1175
//	 * <p>Creates a new layer of the same class as the property <i>className</i> of the XML, after, adds the XML entity to that layer
1176
//	 *  and loads the layer. Then, adds the layer to this collection of layers, and if there is a projection defined,
1177
//	 *  inserts the transformation coordinates to the layer.</p>
1178
//	 *
1179
//	 * <p>If the new layer is an instance of <code>FLyrVect</code>, and has a label field, creates a label layer on the layer.</p>
1180
//	 *
1181
//	 * @param xml tree-node structure with information about layers
1182
//	 * @param name name of the layer to add
1183
//	 */
1184
//	private void addLayerFromXMLNew(XMLEntity xml, String name) {
1185
//		//		FLayer layer = null;
1186
//		//
1187
//		//
1188
//		//		try {
1189
//		//			String className = xml.getStringProperty("className");
1190
//		//			Class clazz = Class.forName(className);
1191
//		//			if (clazz.isAssignableFrom(FLayers.class)) {
1192
//		//				layer = (FLayer) clazz.newInstance();
1193
//		//				((FLayers)layer).setMapContext(getMapContext());
1194
//		//				((FLayers)layer).setParentLayer(this);
1195
//		//	//		if (className.equals((FLayers.class.getName()))){
1196
//		//	//			layer = new FLayers(getMapContext(),this);
1197
//		//			} else {
1198
//		//	//			Por compatibilidad
1199
//		//				if (className.equals(FLyrVect.class.getName())) {
1200
//		//					if (xml.contains("file")) {
1201
//		//						layer = new FLayerFileVectorial();
1202
//		//					} else if (xml.contains("db")) {
1203
//		//						try {
1204
//		//							layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial");
1205
//		//						} catch (Exception e) {
1206
//		//							throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC"));
1207
//		//						}
1208
//		//						//className = FLayerJDBCVectorial.class.getName();
1209
//		//					} else if (xml.contains("other")){
1210
//		//						layer = new FLayerGenericVectorial();
1211
//		//					} else {
1212
//		//						throw new XMLException(new Exception("Capa vectorial de tipo no reconocido"));
1213
//		//					}
1214
//		//	//				Fin por compatibilidad
1215
//		//				} else {
1216
//		//					try {
1217
//		//						layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
1218
//		//					} catch (Exception e) {
1219
//		//						//puende que no este registrada como punto de extension
1220
//		//						Class clase = Class.forName(className);
1221
//		//						layer = (FLayer) clase.newInstance();
1222
//		//						// FIXME: Hacemos algo aqui o dejamos que suba el error?
1223
//		//					}
1224
//		//				}
1225
//		//
1226
//		//			}
1227
//		//			layer.setXMLEntity(xml);
1228
//		//			if (name != null) layer.setName(name);
1229
//		//			layer.load();
1230
//		//
1231
//		//			this.addLayer(layer);
1232
//		//			logger.debug("layer: "+ layer.getName() +" loaded");
1233
//		//			// Comprobar que la proyecci?n es la misma que la de FMap
1234
//		//			// Si no lo es, es una capa que est? reproyectada al vuelo
1235
//		//			IProjection proj = layer.getProjection();
1236
//		//			if ((proj != null))
1237
//		//				if (proj != getMapContext().getProjection())
1238
//		//				{
1239
//		//					ICoordTrans ct = proj.getCT(getMapContext().getProjection());
1240
//		//					// TODO: REVISAR CON LUIS
1241
//		//					// Se lo fijamos a todas, luego cada una que se reproyecte
1242
//		//					// si puede, o que no haga nada
1243
//		//					layer.setCoordTrans(ct);
1244
//		//
1245
//		//				}
1246
//		//		}catch (Exception e) {
1247
//		//			fmap.addLayerError(xml.getStringProperty("name"));
1248
//		//			logger.debug(Messages.getString("could_not_load_layer")+": "+xml.getStringProperty("name") + ".\n"
1249
//		//					+Messages.getString("reason")+":", e);
1250
//		//		}
1251
//	}
935
    @Override
1252 936
    public void accept(Visitor visitor) throws BaseException {
1253 937
        for (int i = 0; i < this.getLayersCount(); i++) {
1254 938
            FLayer layer = this.getLayer(i);
......
1264 948
        }
1265 949
    }
1266 950

  
951
    @Override
1267 952
    public void accept(LayersVisitor visitor) throws BaseException {
1268 953
        for (int i = 0; i < this.getLayersCount(); i++) {
1269 954
            FLayer layer = this.getLayer(i);
......
1280 965
     *
1281 966
     * @see org.gvsig.metadata.Metadata#getMetadataID()
1282 967
     */
968
    @Override
1283 969
    public Object getMetadataID() throws MetadataException {
1284
        StringBuffer strb = new StringBuffer();
970
        StringBuilder strb = new StringBuilder();
1285 971
        strb.append("Layers(");
1286 972
        strb.append(this.getName());
1287 973
        strb.append("):{");
......
1300 986
     *
1301 987
     * @see org.gvsig.metadata.Metadata#getMetadataChildren()
1302 988
     */
989
    @Override
1303 990
    public Set getMetadataChildren() {
1304 991
        Set ret = new TreeSet();
1305 992
        Iterator iter = this.layers.iterator();
......
1314 1001
     *
1315 1002
     * @see org.gvsig.metadata.Metadata#getMetadataName()
1316 1003
     */
1004
    @Override
1317 1005
    public String getMetadataName() throws MetadataException {
1318
        StringBuffer strb = new StringBuffer();
1006
        StringBuilder strb = new StringBuilder();
1319 1007
        strb.append("Layer Group '");
1320 1008
        strb.append(this.getName());
1321 1009
        strb.append("': {");
......
1328 1016
        return strb.toString();
1329 1017
    }
1330 1018

  
1019
    @Override
1331 1020
    public void beginDraw(Graphics2D g, ViewPort viewPort) {
1332 1021
        LayerDrawEvent beforeEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW);
1333 1022
        fmap.fireLayerDrawingEvent(beforeEvent);
1334 1023
    }
1335 1024

  
1025
    @Override
1336 1026
    public void endDraw(Graphics2D g, ViewPort viewPort) {
1337 1027
        LayerDrawEvent afterEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
1338 1028
        fmap.fireLayerDrawingEvent(afterEvent);
......
1340 1030

  
1341 1031
    public static class RegisterPersistence implements Callable {
1342 1032

  
1033
        @Override
1343 1034
        public Object call() {
1344 1035

  
1345 1036
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
......
1359 1050
        }
1360 1051
    }
1361 1052

  
1053
    @Override
1362 1054
    protected void doDispose() throws BaseException {
1363 1055
        if (layers != null) {
1364 1056
            for (int i = 0; i < layers.size(); i++) {
......
1367 1059
        }
1368 1060
    }
1369 1061

  
1062
    @Override
1370 1063
    public void move(FLayer layer, LayerCollection group, int where, FLayer adjoiningLayer) throws LayerNotFoundInCollectionException {
1371 1064

  
1372 1065
        callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(layer));
......
1387 1080
        }
1388 1081
    }
1389 1082

  
1083
    @Override
1390 1084
    public void move(FLayer layer, LayerCollection group) {
1391 1085
        try {
1392 1086
            move(layer, group, END, null);
......
1395 1089
        }
1396 1090
    }
1397 1091

  
1092
    @Override
1398 1093
    public void addLayer(FLayer layer, int where, FLayer adjoiningLayer)
1399 1094
            throws LayerNotFoundInCollectionException {
1400 1095

  
......
1443 1138

  
1444 1139
    public FLayer getFirstActiveLayer() {
1445 1140
        LayersIterator it = new LayersIterator(this) {
1141
            @Override
1446 1142
            public boolean evaluate(FLayer layer) {
1447 1143
                return layer.isActive();
1448 1144
            }
......
1455 1151

  
1456 1152
    public FLyrVect getFirstActiveVectorLayer() {
1457 1153
        LayersIterator it = new LayersIterator(this) {
1154
            @Override
1458 1155
            public boolean evaluate(FLayer layer) {
1459 1156
                return layer.isActive() && layer instanceof FLyrVect;
1460 1157
            }
......
1465 1162
        return null;
1466 1163
    }
1467 1164
    
1165
    @Override
1468 1166
    public Iterator iterator() {
1469 1167
        return this.layers.iterator();
1470 1168
    }
......
1474 1172
        return layers.iterator();
1475 1173
    }
1476 1174
    
1175
    @Override
1477 1176
    public int size() {
1478 1177
        return this.layers.size();
1479 1178
    }
1480 1179
    
1180
    @Override
1481 1181
    public FLayer get(int index) {
1482 1182
        return this.layers.get(index);
1483 1183
    }
1484 1184
    
1185
    @Override
1485 1186
    public boolean isEmpty() {
1486 1187
        return this.layers.isEmpty();
1487 1188
    }
1488 1189

  
1190
    @Override
1489 1191
    public boolean contains(Object o) {
1490 1192
        return this.layers.contains(o);
1491 1193
    }
1492 1194

  
1195
    @Override
1493 1196
    public Object[] toArray() {
1494 1197
        return this.layers.toArray();
1495 1198
    }
1496 1199

  
1200
    @Override
1497 1201
    public Object[] toArray(Object[] ts) {
1498 1202
        return this.layers.toArray(ts);
1499 1203
    }
1500 1204

  
1205
    @Override
1501 1206
    public boolean add(FLayer e) {
1502 1207
        this.addLayer(e);
1503 1208
        return true;
1504 1209
    }
1505 1210

  
1211
    @Override
1506 1212
    public boolean remove(Object o) {
1507 1213
        this.removeLayer((FLayer) o);
1508 1214
        return true;
1509 1215
    }
1510 1216

  
1217
    @Override
1511 1218
    public boolean containsAll(Collection clctn) {
1512 1219
        return this.layers.containsAll(clctn);
1513 1220
    }
1514 1221

  
1222
    @Override
1515 1223
    public void add(int i, FLayer e) {
1516 1224
        this.addLayer(i, (FLayer) e);
1517 1225
    }
1518 1226

  
1227
    @Override
1519 1228
    public FLayer remove(int i) {
1520 1229
        FLayer o = this.getLayer(i);
1521 1230
        this.removeLayer(i);
1522 1231
        return o;
1523 1232
    }
1524 1233

  
1234
    @Override
1525 1235
    public int indexOf(Object o) {
1526 1236
        return this.layers.indexOf(o);
1527 1237
    }
1528 1238

  
1239
    @Override
1529 1240
    public int lastIndexOf(Object o) {
1530 1241
        return this.layers.lastIndexOf(o);
1531 1242
    }
1532 1243

  
1244
    @Override
1533 1245
    public ListIterator listIterator() {
1534 1246
        return this.layers.listIterator();
1535 1247
    }
1536 1248

  
1249
    @Override
1537 1250
    public ListIterator listIterator(int i) {
1538 1251
        return this.layers.listIterator(i);
1539 1252
    }
1540 1253

  
1254
    @Override
1541 1255
    public List subList(int i, int i1) {
1542 1256
        return this.layers.subList(i, i1);
1543 1257
    }
1544 1258
    
1259
    @Override
1545 1260
    public boolean addAll(Collection clctn) {
1546 1261
        Iterator it = clctn.iterator();
1547 1262
        while( it.hasNext() ) {
......
1550 1265
        return true;
1551 1266
    }
1552 1267

  
1268
    @Override
1553 1269
    public boolean addAll(int i, Collection clctn) {
1554 1270
        Iterator it = clctn.iterator();
1555 1271
        while( it.hasNext() ) {
......
1558 1274
        return true;
1559 1275
    }
1560 1276

  
1277
    @Override
1561 1278
    public boolean removeAll(Collection clctn) {
1562 1279
        Iterator it = clctn.iterator();
1563 1280
        while( it.hasNext() ) {
......
1566 1283
        return true;
1567 1284
    }
1568 1285

  
1286
    @Override
1569 1287
    public boolean retainAll(Collection clctn) {
1570 1288
        Iterator it = this.layers.iterator();
1571 1289
        while( it.hasNext() ) {
......
1577 1295
        return true;
1578 1296
    }
1579 1297

  
1298
    @Override
1580 1299
    public FLayer set(int i, FLayer e) {
1581 1300
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1582 1301
    }

Also available in: Unified diff