Revision 37204

View differences:

branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/FLayers.java
323 323
	 *
324 324
	 * @param layerName the name of the layer to be replaced
325 325
	 * @param layer the new layer
326
	 * @deprecated use {@link FLayers#replaceLayer(FLayer, FLayer)}
326 327
	 */
327 328
	public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException
328 329
	{
329
		FLayer lyr;
330
		FLayer parent;
331
		for (int i = 0; i < layers.size(); i++) {
332
			lyr = ((FLayer) layers.get(i));
333

  
334
			if (lyr.getName().compareToIgnoreCase(layerName) == 0) {
335
				parent = lyr.getParentLayer();
336
				removeLayer(i);
337
				if (parent != null) {
338
					//Notificamos a la capa que va a ser a?adida
339
					if (layer instanceof FLyrDefault) {
340
						((FLyrDefault)layer).wakeUp();
341
					}
342
				}
343

  
344
				if (layer instanceof FLayers){
345
					FLayers layers=(FLayers)layer;
346
					fmap.addAsCollectionListener(layers);
347
				}
348
				callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer));
349

  
350
//				layers.add(i,layer);
351
//				layer.setParentLayer(this);
352
				this.doAddLayer(i, layer);
353
				
354
				callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer));
355
				break;
356
			}
357
		}
330
		replaceLayer(getLayer(layerName), layer);
358 331
	}
332
	
333
	/**
334
     * Replace a layer by another layer.  It search recursively by all the 
335
     * ILayerCollection nodes
336
     *
337
     * @param layer
338
     *          the layer to be replaced
339
     * @param newLayer
340
     *          the new layer
341
     */
342
    public void replaceLayer(FLayer layer, FLayer newLayer) throws LoadLayerException
343
    {        
344
        replaceLayer(this, layer, newLayer);
345
    }
346
    
347
    /**
348
     * Replace a layer by other layer. It search recursively by all the 
349
     * ILayerCollection nodes
350
     * @param parentLayer
351
     *          the parent layer
352
     * @param layer
353
     *          the layer to be replaced
354
     * @param newLayer
355
     *          the new layer
356
     * @throws LoadLayerException
357
     */
358
    private void replaceLayer(FLayers parentLayer, FLayer layer, FLayer newLayer) throws LoadLayerException
359
    {        
360
        FLayer lyr;       
361
        for (int i = 0; i < parentLayer.getLayersCount(); i++) {
362
            lyr = ((FLayer) parentLayer.getLayer(i));
363
            if (lyr.equals(layer)) {              
364
                parentLayer.removeLayer(i);             
365
                parentLayer.addLayer(i, newLayer);                
366
                break;
367
            }
368
            if (lyr instanceof LayerCollection){
369
                replaceLayer((FLayers)lyr, layer, newLayer);
370
            }
371
        }
372
    }
359 373

  
360 374
	/*
361 375
	 * (non-Javadoc)
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/GraphicLayer.java
21 21
 */
22 22
package org.gvsig.fmap.mapcontext.layers.vectorial;
23 23

  
24
import java.util.Iterator;
25

  
24 26
import org.gvsig.fmap.geom.Geometry;
25 27
import org.gvsig.fmap.mapcontext.MapContext;
26 28
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
......
78 80
	public int getSymbolId(ISymbol symbol);
79 81

  
80 82
	/**
81
	 * Adds a new {@link Geometry} to be rendered into the layer.
82
	 * 
83
	 * @param groupId
84
	 *            group identifier. Allows to identify a group of
85
	 *            {@link Geometry} added to the layer
86
	 * @param geom
87
	 *            the {@link Geometry} to add
88
	 * @param idsym
89
	 *            the {@link ISymbol} identifier to apply to render the
90
	 *            {@link Geometry}
91
	 */
92
	public void addGraphic(String groupId, Geometry geom, int idsym);
93

  
94
	/**
95 83
	 * @deprecated @see
96 84
	 *             {@link #addGraphic(String, Geometry, int, String, Object, int)
97 85

  
......
105 93
	 */
106 94
	public void addGraphic(Geometry geom, int idsym, String label);
107 95

  
96
    /**
97
     * Adds a new {@link Geometry} to be rendered into the layer.
98
     * 
99
     * @param groupId
100
     *            group identifier. Allows to identify a group of
101
     *            {@link Geometry} added to the layer
102
     * @param geom
103
     *            the {@link Geometry} to add
104
     * @param idsym
105
     *            the {@link ISymbol} identifier to apply to render the
106
     *            {@link Geometry}
107
     */
108
    public void addGraphic(String groupId, Geometry geom, int idsym);
109

  
108 110
	/**
109 111
	 * Adds a new {@link Geometry} to be rendered into the layer.
110 112
	 * 
......
147 149
	public void addGraphic(String groupId, Geometry geom, int idsym,
148 150
			String label, Object tag, int priority);
149 151

  
152
    /**
153
     * Adds a new {@link Geometry} to be rendered into the layer.
154
     * 
155
     * @param groupId
156
     *            group identifier. Allows to identify a group of
157
     *            {@link Geometry} added to the layer
158
     * @param geoms
159
     *            the {@link Geometry}s to add
160
     * @param idsym
161
     *            the {@link ISymbol} identifier to apply to render the
162
     *            {@link Geometry}
163
     */
164
    public void addGraphics(String groupId, Iterator geoms, int idsym);
165

  
166
    /**
167
     * Adds a new {@link Geometry} to be rendered into the layer.
168
     * 
169
     * @param groupId
170
     *            group identifier. Allows to identify a group of
171
     *            {@link Geometry} added to the layer
172
     * @param geoms
173
     *            the {@link Geometry}s to add
174
     * @param idsym
175
     *            the {@link ISymbol} identifier to apply to render the
176
     *            {@link Geometry}
177
     * @param label
178
     *            the text to show if the {@link ISymbol} is a
179
     *            {@link ITextSymbol}. Set null otherwise.
180
     */
181
    public void addGraphics(String groupId, Iterator geoms, int idsym,
182
        String label);
183

  
184
    /**
185
     * Adds a new {@link Geometry} to be rendered into the layer.
186
     * 
187
     * @param groupId
188
     *            group identifier. Allows to identify a group of
189
     *            {@link Geometry} added to the layer
190
     * @param geoms
191
     *            the {@link Geometry}s to add
192
     * @param idsym
193
     *            the {@link ISymbol} identifier to apply to render the
194
     *            {@link Geometry}
195
     * @param label
196
     *            the text to show if the {@link ISymbol} is a
197
     *            {@link ITextSymbol}. Set null otherwise.
198
     * @param tag
199
     *            an object to classify, identify or add related information to
200
     *            the {@link Geometry}
201
     * @param priority
202
     *            to apply while rendering the {@link Geometry}. Values with
203
     *            lower priority will be rendered first.
204
     */
205
    public void addGraphics(String groupId, Iterator geoms, int idsym,
206
        String label, Object tag, int priority);
207

  
150 208
	/**
151 209
	 * Removes all previously registered {@link Geometry} objects from the layer
152 210
	 * with the given groupId.
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/impl/DefaultGraphicLayer.java
26 26
*/
27 27
package org.gvsig.fmap.mapcontext.layers.vectorial.impl;
28 28

  
29
import java.util.Iterator;
30

  
29 31
import org.cresques.cts.IProjection;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
30 35
import org.gvsig.fmap.dal.DALLocator;
31 36
import org.gvsig.fmap.dal.DataManager;
32 37
import org.gvsig.fmap.dal.DataTypes;
33 38
import org.gvsig.fmap.dal.exception.DataException;
34 39
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
35
import org.gvsig.tools.dispose.DisposableIterator;
36 40
import org.gvsig.fmap.dal.feature.EditableFeature;
37 41
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
38 42
import org.gvsig.fmap.dal.feature.EditableFeatureType;
......
49 53
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
50 54
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
51 55
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
56
import org.gvsig.tools.dispose.DisposableIterator;
52 57
import org.gvsig.tools.exception.BaseException;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55 58

  
56 59
/**
57 60
 * Default {@link GraphicLayer} implementation. 
......
129 132
			if (!store.isEditing()){
130 133
				store.edit(FeatureStore.MODE_APPEND);
131 134
			}
132
			EditableFeature feature = store.createNewFeature().getEditable();
133
			feature.setString(GraphicLayer.FEATURE_ATTR_GROUPID, groupId);
134
			feature.setGeometry(GraphicLayer.FEATURE_ATTR_GEOMETRY, geom);
135
			feature.setInt(GraphicLayer.FEATURE_ATTR_IDSYMBOL, idsym);	
136
			feature.setString(GraphicLayer.FEATURE_ATTR_LABEL, label);	
137
			feature.setLong(GraphicLayer.FEATURE_ATTR_FEATUREID, ids);
138
			feature.set(GraphicLayer.FEATURE_ATTR_TAG, tag);
139
			feature.setInt(GraphicLayer.FEATURE_ATTR_PRIORITY, priority);
140

  
141
			ids++;
142

  
143
			store.insert(feature);
135
			insertGeometry(groupId, geom, idsym, label, tag, priority);
144 136
			store.finishEditing();
145 137
		} catch (DataException e) {
146 138
			logger.error("Error adding a geometry to the graphic layer", e);
147 139
		}
148
	}	
140
	}
149 141

  
142
    private void insertGeometry(String groupId, Geometry geom, int idsym,
143
        String label, Object tag, int priority) throws DataException {
144
        EditableFeature feature = store.createNewFeature().getEditable();
145
        feature.setString(GraphicLayer.FEATURE_ATTR_GROUPID, groupId);
146
        feature.setGeometry(GraphicLayer.FEATURE_ATTR_GEOMETRY, geom);
147
        feature.setInt(GraphicLayer.FEATURE_ATTR_IDSYMBOL, idsym);	
148
        feature.setString(GraphicLayer.FEATURE_ATTR_LABEL, label);	
149
        feature.setLong(GraphicLayer.FEATURE_ATTR_FEATUREID, ids);
150
        feature.set(GraphicLayer.FEATURE_ATTR_TAG, tag);
151
        feature.setInt(GraphicLayer.FEATURE_ATTR_PRIORITY, priority);
152

  
153
        ids++;
154

  
155
        store.insert(feature);
156
    }	
157

  
158
    public void addGraphics(String groupId, Iterator geoms, int idsym) {
159
        addGraphics(groupId, geoms, idsym, null, null, DEFAULT_PRIORITY);
160
    }
161

  
162
    public void addGraphics(String groupId, Iterator geoms, int idsym,
163
        String label) {
164
        addGraphics(groupId, geoms, idsym, label, null, DEFAULT_PRIORITY);
165
    }
166

  
167
    public void addGraphics(String groupId, Iterator geoms, int idsym,
168
        String label, Object tag, int priority) {
169
        try {
170
            if (!store.isEditing()) {
171
                store.edit(FeatureStore.MODE_APPEND);
172
            }
173
            for (; geoms.hasNext();) {
174
                Geometry geom = (Geometry) geoms.next();
175
                insertGeometry(groupId, geom, idsym, label, tag, priority);
176
            }
177
            store.finishEditing();
178
        } catch (DataException e) {
179
            logger.error("Error adding a geometry to the graphic layer", e);
180
        }
181
    }
182

  
150 183
	public int addSymbol(ISymbol newSymbol) {
151 184
		symbolId++;
152 185
		legend.addSymbol(new Integer(symbolId), newSymbol);
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/FLyrDefault.java
960 960
		this.parentLayer = (FLayers) state.get("parentLayer");
961 961
		this.status = (FLayerStatus) state.get("status");
962 962
		this.minScale = state.getDouble("minScale");
963
		this.minScale = state.getDouble("maxScale");
963
		this.maxScale = state.getDouble("maxScale");
964 964
		this.transparency = state.getInt("transparency");
965 965
		this.ct = (ICoordTrans) state.get("coordTrans");
966 966

  
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
35 35
import java.util.Collections;
36 36
import java.util.HashMap;
37 37
import java.util.Map;
38
import java.util.Random;
39 38

  
40 39
import org.cresques.cts.IProjection;
41 40
import org.slf4j.Logger;
......
279 278
	public IVectorLegend createDefaultVectorLegend(int shapeType)
280 279
	throws MapContextRuntimeException {
281 280
		try {
282
			Random rand = new Random();
283

  
284
			int numreg = rand.nextInt(255 / 2);
285
			double div = (1 - rand.nextDouble() * 0.66) * 0.9;
286
			Color randomColor = new Color(((int) (255 * div + (numreg * rand
287
					.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand
288
							.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand
289
									.nextDouble()))) % 255);
290
			IVectorLegend legend = (IVectorLegend) createLegend(getDefaultVectorLegend());
291
			if( legend == null ) {
292
				return null;
293
			}
294
			ISymbol defaultSymbol =
295
				getSymbolManager().createSymbol(shapeType, randomColor);
296
			legend.setDefaultSymbol(defaultSymbol);
281
            // Create legend
282
            IVectorLegend legend =
283
                (IVectorLegend) createLegend(getDefaultVectorLegend());
284
            if (legend == null) {
285
                return null;
286
            }
287
            // Set legend values
288
            legend.setDefaultSymbol(getSymbolManager().createSymbol(shapeType));
297 289
			legend.setShapeType(shapeType);
298 290
			return legend;
299 291
		} catch(Exception e) {
......
470 462
		ILegend legend = null;
471 463

  
472 464
		//Loading the legend from a store based on file
465
        DataServerExplorer dataServerExplorer = null;
473 466
		try {
474 467
//			This access by reflection is done because the libFMap_dalfile project
475 468
//			has to be divided in several projects. The commented code is the fine
......
483 476
//					legend = (ILegend)persistenceManager.create(persistentState);
484 477
//				}
485 478
//			}
486
			DataServerExplorer dataServerExplorer = dataStore.getExplorer();
479
            dataServerExplorer = dataStore.getExplorer();
487 480
			Class[] args = new Class[2];
488 481
			args[0] = DataStore.class;
489 482
			args[1] = String.class;
......
501 494
			}	
502 495

  
503 496
		} catch (Exception e) {
504
			LOG.info("Can't load the specific legend provided by the explorer.", e);
497
            LOG.debug(
498
                "Can't load the specific legend provided by the explorer "
499
                    + dataServerExplorer, e);
505 500
		} 
506 501

  
507 502
		//If the legend is null, next option is to check if the store has the getLegend method
......
510 505
				legend = (IVectorLegend) dataStore.invokeDynMethod(
511 506
						"getLegend", null);
512 507
			} catch (DynMethodNotSupportedException e) {
513
	            LOG.info("This store {} can not provide a legend.", dataStore.getName(), e);
508
                LOG.debug("This store {} does not provide a legend.",
509
                    dataStore.getName());
514 510
			} catch (DynMethodException e) {
515
				LOG.error("Can't load the specific legend provided for the store {}.", dataStore.getName(), e);
511
                LOG.error(
512
                    "Can't load the specific legend provided for the store {}.",
513
                    dataStore.getName(), e);
516 514
			}
517 515
		}
518 516

  
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContext.java
1289 1289

  
1290 1290
			// Registramos al FMap como listener del legend de las capas
1291 1291
			FLayer lyr = e.getAffectedLayer();
1292
			selectionListener(lyr);
1293
			if (lyr instanceof SingleLayer){
1294
				if (((SingleLayer) lyr).getDataStore() != null) {
1295
					((SingleLayer) lyr).getDataStore().addObserver(
1296
							MapContext.this);
1297
				}
1298
			}
1292
			addSelectionListener(lyr);
1299 1293
		}
1300 1294

  
1301
		/**
1302
		 * <p>Registers an event buffer as a listener for all layers as argument.</p>
1303
		 *
1304
		 * <p>Each {@link FLayer FLayer} of this map must have an event buffer for all kind
1305
		 * of specific listeners of that layer. This method distinguish between {@link Classifiable Classifiable},
1306
		 * {@link AlphanumericData AlphanumericData}, and {@link FLayers FLayers} layers, and for each one,
1307
		 * registers, for their specific listeners, the <code>eventBuffer</code> as a listener.</p>
1308
		 *
1309
		 * @param the layer or layers
1310
		 */
1311
		private void selectionListener(FLayer lyr){
1312
			lyr.addLayerListener(eventBuffer);
1313

  
1314
			if (lyr instanceof Classifiable) {
1315
				Classifiable c = (Classifiable) lyr;
1316
				c.addLegendListener(eventBuffer);
1317
			}
1318

  
1319
			if (lyr instanceof FLayers){
1320
				FLayers lyrs=(FLayers)lyr;
1321
				for(int i=0;i<lyrs.getLayersCount();i++){
1322
					selectionListener(lyrs.getLayer(i));
1323
				}
1324
			}
1325

  
1326
		}
1327 1295
		/*
1328 1296
		 * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
1329 1297
		 */
......
1605 1573
		layers.addLayerCollectionListener(eventBuffer);
1606 1574
		layers.setProjection(vp.getProjection());
1607 1575
		
1608
		
1576
		//Add the listener for the selection
1577
		addSelectionListener(layers);
1609 1578
	}
1610 1579

  
1611 1580
	private void loadLayers(FLayers lyrs) {
......
1647 1616
		dispose(layers);
1648 1617
		dispose(tracLayer);
1649 1618
	}
1619
	
1620
    /**
1621
     * <p>Registers an event buffer as a listener for all layers as argument.</p>
1622
     *
1623
     * <p>Each {@link FLayer FLayer} of this map must have an event buffer for all kind
1624
     * of specific listeners of that layer. This method distinguish between {@link Classifiable Classifiable},
1625
     * {@link AlphanumericData AlphanumericData}, and {@link FLayers FLayers} layers, and for each one,
1626
     * registers, for their specific listeners, the <code>eventBuffer</code> as a listener.</p>
1627
     *
1628
     * @param the layer or layers
1629
     */
1630
    private void addSelectionListener(FLayer lyr){
1631
        lyr.addLayerListener(eventBuffer);
1632

  
1633
        if (lyr instanceof Classifiable) {
1634
            Classifiable c = (Classifiable) lyr;
1635
            c.addLegendListener(eventBuffer);
1636
        }
1637

  
1638
        if (lyr instanceof FLayers){
1639
            FLayers lyrs=(FLayers)lyr;
1640
            for(int i=0;i<lyrs.getLayersCount();i++){
1641
                addSelectionListener(lyrs.getLayer(i));
1642
            }
1643
        }
1644
        if (lyr instanceof SingleLayer){
1645
            if (((SingleLayer) lyr).getDataStore() != null) {
1646
                ((SingleLayer) lyr).getDataStore().addObserver(
1647
                        MapContext.this);
1648
            }
1649
        }
1650
    }
1650 1651
}
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/rendering/symbols/impl/DefaultSymbolManager.java
35 35
import java.util.Collections;
36 36
import java.util.HashMap;
37 37
import java.util.Map;
38
import java.util.Random;
38 39

  
39 40
import org.gvsig.fmap.mapcontext.MapContextRuntimeException;
40 41
import org.gvsig.fmap.mapcontext.impl.InvalidRegisteredClassException;
......
49 50
import org.gvsig.tools.persistence.PersistenceManager;
50 51
import org.gvsig.tools.persistence.PersistentState;
51 52
import org.gvsig.tools.persistence.exception.PersistenceException;
52
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
53 53

  
54 54
/**
55 55
 * Default {@link SymbolManager} implementation.
......
286 286
					symbolClass, symbolName, e);
287 287
		}
288 288

  
289
        Color symbolColor;
290
        if (getSymbolPreferences().isDefaultSymbolFillColorAleatory()) {
291
            Random rand = new Random();
292
            int numreg = rand.nextInt(255 / 2);
293
            double div = (1 - rand.nextDouble() * 0.66) * 0.9;
294
            symbolColor =
295
                new Color(
296
                    ((int) (255 * div + (numreg * rand.nextDouble()))) % 255,
297
                    ((int) (255 * div + (numreg * rand.nextDouble()))) % 255,
298
                    ((int) (255 * div + (numreg * rand.nextDouble()))) % 255);
299
        }
300
        else {
301
            symbolColor = getSymbolPreferences().getDefaultSymbolFillColor();
302
        }
303
        symbol.setColor(symbolColor);
289 304
		// Perform this initialization into the Symbol implementation
290 305
		// if (symbol instanceof CartographicSupport) {
291 306
		// CartographicSupport cs = (CartographicSupport) symbol;
branches/dal_time_support/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geom/operation/DrawInts.java
37 37
				toCartographicSize(viewPort, doc.getDPI(), geom);
38 38
				// draw it as normally
39 39
				Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform());
40
				symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,
41
						doc.getFeature(), cancel);
40
				
41
				//the AffineTransform has to be null because the transformToInts method
42
				//reprojects the geometry
43
				symbol.draw(g, null, decimatedShape, doc.getFeature(), cancel);
44
				
42 45
				// restore previous size
43 46
				((CartographicSupport)symbol).setCartographicSize(previousSize, geom);
44 47
			}else{

Also available in: Unified diff