Revision 34978

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/SpatialManager.java
225 225
			while (iterator.hasNext()) {
226 226
				Feature feature = (Feature) iterator.next();
227 227
				Envelope envelope = feature.getDefaultEnvelope();
228
				fullEnvelope.add(envelope);
228
				if(envelope!=null){
229
					fullEnvelope.add(envelope);
230
				}
229 231
			}
230 232
		} finally {
231 233
			if (iterator != null) {
......
262 264
				}
263 265
			}
264 266
		}
265
    	fullEnvelope = originalEnvelope.getGeometry().getEnvelope();
267
    	if (originalEnvelope!=null){
268
    		fullEnvelope = originalEnvelope.getGeometry().getEnvelope();
269
    	} else {
270
    		fullEnvelope = null;
271
    	}
266 272
		isFullExtentDirty = false;
267 273
	}
268 274

  
branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/styling/AttrInTableLabelingStrategy.java
187 187
					} else if (heightFieldName != null) {
188 188
						// text size is defined in the table
189 189
						try {
190
							size = feature.getDouble(heightPos);
190
							size = feature.getDouble(fields.get(heightPos));
191 191
						} catch (Exception e) {
192 192
							logger.
193 193
								warn("Null text height value for text '{}'", feature.getString(fields.get(textPos)));
......
217 217
					} else if (colorFieldName != null) {
218 218
						// text size is defined in the table
219 219
						try {
220
							color = new Color(feature.getInt(colorPos));
220
							color = new Color(feature.getInt(fields.get(colorPos)));
221 221
						} catch (ClassCastException ccEx) {
222
							if (feature.get(colorPos) != null) {
222
							if (feature.get(fields.get(colorPos)) != null) {
223 223
								throw new ReadException("Unknown", ccEx);
224 224
							}
225 225
							logger.warn(
......
237 237
					double rotation = 0D;
238 238
					if (rotationFieldName != null) {
239 239
						// text rotation is defined in the table
240
						rotation = -Math.toRadians(((Number) feature.get(rotationPos)).doubleValue());
240
						rotation = -Math.toRadians(((Number) feature.get(fields.get(rotationPos))).doubleValue());
241 241
					}
242 242

  
243 243
					Geometry geom = feature.getDefaultGeometry();
branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/AbstractVectorialLegend.java
94 94
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
95 95
 */
96 96
public abstract class AbstractVectorialLegend extends AbstractLegend implements
97
    IVectorLegend {
97
		IVectorLegend {
98 98

  
99
    public static final String VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME =
100
        "VectorialLegend";
99
	public static final String VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME = "VectorialLegend";
101 100

  
102
    private static final String FIELD_HAS_ZSORT = "hasZSort";
103
    private static final String FIELD_SHAPETYPE = "shapeType";
104
    private static final String FIELD_DEFAULT_SYMBOL = "defaultSymbol";
101
	private static final String FIELD_HAS_ZSORT = "hasZSort";
102
	private static final String FIELD_SHAPETYPE = "shapeType";
103
	private static final String FIELD_DEFAULT_SYMBOL = "defaultSymbol";
105 104

  
106
    private static final GeometryManager geomManager = GeometryLocator
107
        .getGeometryManager();
105
	private static final GeometryManager geomManager = GeometryLocator
106
			.getGeometryManager();
108 107

  
109
    protected ZSort zSort;
108
	protected ZSort zSort;
110 109

  
111
    public ZSort getZSort() {
112
        return zSort;
113
    }
110
	public ZSort getZSort() {
111
		return zSort;
112
	}
114 113

  
115
    public void setZSort(ZSort zSort) {
116
        if (zSort == null) {
117
            removeLegendListener(this.zSort);
118
        }
119
        this.zSort = zSort;
120
        addLegendListener(zSort);
121
    }
114
	public void setZSort(ZSort zSort) {
115
		if (zSort == null) {
116
			removeLegendListener(this.zSort);
117
		}
118
		this.zSort = zSort;
119
		addLegendListener(zSort);
120
	}
122 121

  
123
    @SuppressWarnings("unchecked")
124
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
125
        Cancellable cancel, double scale, Map queryParameters,
126
        ICoordTrans coordTrans, FeatureStore featureStore)
127
        throws LegendException {
128
        double dpi = MapContext.getScreenDPI();
129
        draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
130
            featureStore, dpi);
131
    }
122
	@SuppressWarnings("unchecked")
123
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
124
			Cancellable cancel, double scale, Map queryParameters,
125
			ICoordTrans coordTrans, FeatureStore featureStore)
126
			throws LegendException {
127
		double dpi = MapContext.getScreenDPI();
128
		draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
129
				featureStore, dpi);
130
	}
132 131

  
133
    @SuppressWarnings("unchecked")
134
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
135
        double scale, Map queryParameters, ICoordTrans coordTrans,
136
        FeatureStore featureStore, PrintAttributes properties)
137
        throws LegendException {
138
        double dpi = 72;
132
	@SuppressWarnings("unchecked")
133
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
134
			double scale, Map queryParameters, ICoordTrans coordTrans,
135
			FeatureStore featureStore, PrintAttributes properties)
136
			throws LegendException {
137
		double dpi = 72;
139 138

  
140
        int resolution = properties.getPrintQuality();
139
		int resolution = properties.getPrintQuality();
141 140

  
142
        if (resolution == PrintAttributes.PRINT_QUALITY_NORMAL) {
143
            dpi = 300;
144
        } else
145
            if (resolution == PrintAttributes.PRINT_QUALITY_HIGH) {
146
                dpi = 600;
147
            } else
148
                if (resolution == PrintAttributes.PRINT_QUALITY_DRAFT) {
149
                    dpi = 72;
150
                }
141
		if (resolution == PrintAttributes.PRINT_QUALITY_NORMAL) {
142
			dpi = 300;
143
		} else if (resolution == PrintAttributes.PRINT_QUALITY_HIGH) {
144
			dpi = 600;
145
		} else if (resolution == PrintAttributes.PRINT_QUALITY_DRAFT) {
146
			dpi = 72;
147
		}
151 148

  
152
        FeatureSet featureSet = null;
153
        DisposableIterator it = null;
154
        try {
155
            ZSort zSort = getZSort();
149
		FeatureSet featureSet = null;
150
		DisposableIterator it = null;
151
		try {
152
			ZSort zSort = getZSort();
156 153

  
157
            // if layer has map levels it will use a ZSort
158
            boolean useZSort = zSort != null && zSort.isUsingZSort();
154
			// if layer has map levels it will use a ZSort
155
			boolean useZSort = zSort != null && zSort.isUsingZSort();
159 156

  
160
            int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
161
            for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
162
                // Get the iterator over the visible features
163
                String[] fieldNames =
164
                    getRequiredFeatureAttributeNames(featureStore);
157
			int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
158
			for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
159
				// Get the iterator over the visible features
160
				String[] fieldNames = getRequiredFeatureAttributeNames(featureStore);
165 161

  
166
                FeatureQuery featureQuery = featureStore.createFeatureQuery();
167
                featureQuery.setAttributeNames(fieldNames);
168
                featureQuery.setScale(scale);
162
				FeatureQuery featureQuery = featureStore.createFeatureQuery();
163
				featureQuery.setAttributeNames(fieldNames);
164
				featureQuery.setScale(scale);
169 165

  
170
                ContainsEnvelopeEvaluator iee =
171
                    new ContainsEnvelopeEvaluator(
172
                        viewPort.getAdjustedEnvelope(),
173
                        viewPort.getProjection(),
174
                        featureStore.getDefaultFeatureType(), featureStore
175
                            .getDefaultFeatureType()
176
                            .getDefaultGeometryAttributeName());
177
                featureQuery.setFilter(iee);
178
                featureSet = featureStore.getFeatureSet(featureQuery);
179
                it = featureSet.fastIterator();
166
				ContainsEnvelopeEvaluator iee = new ContainsEnvelopeEvaluator(
167
						viewPort.getAdjustedEnvelope(),
168
						viewPort.getProjection(),
169
						featureStore.getDefaultFeatureType(), featureStore
170
								.getDefaultFeatureType()
171
								.getDefaultGeometryAttributeName());
172
				featureQuery.setFilter(iee);
173
				featureSet = featureStore.getFeatureSet(featureQuery);
174
				it = featureSet.fastIterator();
180 175

  
181
                // Iteration over each feature
182
                while (!cancel.isCanceled() && it.hasNext()) {
183
                    Feature feat = (Feature) it.next();
184
                    Geometry geom = feat.getDefaultGeometry();
176
				// Iteration over each feature
177
				while (!cancel.isCanceled() && it.hasNext()) {
178
					Feature feat = (Feature) it.next();
179
					Geometry geom = feat.getDefaultGeometry();
185 180

  
186
                    // retrieve the symbol associated to such feature
187
                    ISymbol sym = getSymbolByFeature(feat);
188
                    if (sym == null) {
189
                        continue;
190
                    }
191
                    if (useZSort) {
192
                        int[] symLevels = zSort.getLevels(sym);
193
                        if (symLevels != null) {
181
					// retrieve the symbol associated to such feature
182
					ISymbol sym = getSymbolByFeature(feat);
183
					if (sym == null) {
184
						continue;
185
					}
186
					if (useZSort) {
187
						int[] symLevels = zSort.getLevels(sym);
188
						if (symLevels != null) {
194 189

  
195
                            // Check if this symbol is a multilayer
196
                            if (sym instanceof IMultiLayerSymbol) {
197
                                // if so, get the layer corresponding to the
198
                                // current level. If none, continue to next
199
                                // iteration
200
                                IMultiLayerSymbol mlSym =
201
                                    (IMultiLayerSymbol) sym;
202
                                for (int i = 0; i < mlSym.getLayerCount(); i++) {
203
                                    ISymbol mySym = mlSym.getLayer(i);
204
                                    if (symLevels[i] == mapPass) {
205
                                        sym = mySym;
206
                                        break;
207
                                    }
208
                                }
190
							// Check if this symbol is a multilayer
191
							if (sym instanceof IMultiLayerSymbol) {
192
								// if so, get the layer corresponding to the
193
								// current level. If none, continue to next
194
								// iteration
195
								IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
196
								for (int i = 0; i < mlSym.getLayerCount(); i++) {
197
									ISymbol mySym = mlSym.getLayer(i);
198
									if (symLevels[i] == mapPass) {
199
										sym = mySym;
200
										break;
201
									}
202
								}
209 203

  
210
                            } else {
211
                                // else, just draw the symbol in its level
212
                                if (symLevels[0] != mapPass) {
213
                                    continue;
214
                                }
215
                            }
216
                        }
217
                    }
204
							} else {
205
								// else, just draw the symbol in its level
206
								if (symLevels[0] != mapPass) {
207
									continue;
208
								}
209
							}
210
						}
211
					}
218 212

  
219
                    // Check if this symbol is sized with CartographicSupport
220
                    CartographicSupport csSym = null;
221
                    int symbolType = sym.getSymbolType();
213
					// Check if this symbol is sized with CartographicSupport
214
					CartographicSupport csSym = null;
215
					int symbolType = sym.getSymbolType();
222 216

  
223
                    if (symbolType == Geometry.TYPES.POINT
224
                        || symbolType == Geometry.TYPES.CURVE
225
                        || sym instanceof CartographicSupport) {
217
					if (symbolType == Geometry.TYPES.POINT
218
							|| symbolType == Geometry.TYPES.CURVE
219
							|| sym instanceof CartographicSupport) {
226 220

  
227
                        csSym = (CartographicSupport) sym;
228
                    }
221
						csSym = (CartographicSupport) sym;
222
					}
229 223

  
230
                    DrawOperationContext doc = new DrawOperationContext();
231
                    doc.setGraphics(g);
232
                    doc.setViewPort(viewPort);
233
                    if (csSym == null) {
234
                        doc.setSymbol(sym);
235
                    } else {
236
                        doc.setDPI(dpi);
237
                        doc.setCancellable(cancel);
238
                        doc.setSymbol((ISymbol) csSym);
239
                    }
240
                    geom.invokeOperation(DrawInts.CODE, doc);
241
                }
242
            }
243
        } catch (ReadException e) {
244
            throw new LegendDrawingException(e);
245
        } catch (GeometryOperationNotSupportedException e) {
246
            throw new LegendDrawingException(e);
247
        } catch (GeometryOperationException e) {
248
            throw new LegendDrawingException(e);
249
        } catch (DataException e) {
250
            throw new LegendDrawingException(e);
251
        } catch (MapContextException e) {
252
            throw new LegendDrawingException(e);
253
        } finally {
254
            if (it != null) {
255
                it.dispose();
256
            }
257
            if (featureSet != null) {
258
                featureSet.dispose();
259
            }
260
        }
261
    }
224
					DrawOperationContext doc = new DrawOperationContext();
225
					doc.setGraphics(g);
226
					doc.setViewPort(viewPort);
227
					if (csSym == null) {
228
						doc.setSymbol(sym);
229
					} else {
230
						doc.setDPI(dpi);
231
						doc.setCancellable(cancel);
232
						doc.setSymbol((ISymbol) csSym);
233
					}
234
					geom.invokeOperation(DrawInts.CODE, doc);
235
				}
236
			}
237
		} catch (ReadException e) {
238
			throw new LegendDrawingException(e);
239
		} catch (GeometryOperationNotSupportedException e) {
240
			throw new LegendDrawingException(e);
241
		} catch (GeometryOperationException e) {
242
			throw new LegendDrawingException(e);
243
		} catch (DataException e) {
244
			throw new LegendDrawingException(e);
245
		} catch (MapContextException e) {
246
			throw new LegendDrawingException(e);
247
		} finally {
248
			if (it != null) {
249
				it.dispose();
250
			}
251
			if (featureSet != null) {
252
				featureSet.dispose();
253
			}
254
		}
255
	}
262 256

  
263
    /**
264
     * Draws the features from the {@link FeatureStore}, filtered with the scale
265
     * and the query parameters, with the symbols of the legend.
266
     */
267
    @SuppressWarnings("unchecked")
268
    protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
269
        Cancellable cancel, double scale, Map queryParameters,
270
        ICoordTrans coordTrans, FeatureStore featureStore, double dpi)
271
        throws LegendException {
257
	/**
258
	 * Draws the features from the {@link FeatureStore}, filtered with the scale
259
	 * and the query parameters, with the symbols of the legend.
260
	 */
261
	@SuppressWarnings("unchecked")
262
	protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
263
			Cancellable cancel, double scale, Map queryParameters,
264
			ICoordTrans coordTrans, FeatureStore featureStore, double dpi)
265
			throws LegendException {
272 266

  
273
        SimpleTaskStatus taskStatus = null;
274
        try {
275
            taskStatus = ToolsLocator.getTaskStatusManager().creteDefaultSimpleTaskStatus(featureStore.getName());
276
            taskStatus.add();
277
            if (!getDefaultSymbol().isShapeVisible()) {
278
                return;
279
            }
267
		SimpleTaskStatus taskStatus = null;
268
		try {
269
			taskStatus = ToolsLocator.getTaskStatusManager()
270
					.creteDefaultSimpleTaskStatus(featureStore.getName());
271
			taskStatus.add();
272
			if (!getDefaultSymbol().isShapeVisible()) {
273
				return;
274
			}
280 275

  
281
            if (cancel.isCanceled()) {
282
                return;
283
            }
276
			if (cancel.isCanceled()) {
277
				return;
278
			}
284 279

  
285
            IProjection dataProjection;
286
            Envelope reprojectedDataEnvelop;
280
			IProjection dataProjection;
281
			Envelope reprojectedDataEnvelop;
287 282

  
288
            try {
289
                if (coordTrans == null) {
290
                    dataProjection =
291
                        featureStore.getDefaultFeatureType().getDefaultSRS();
283
			try {
284
				if (coordTrans == null) {
285
					dataProjection = featureStore.getDefaultFeatureType()
286
							.getDefaultSRS();
292 287

  
293
                    // If the data does not provide a projection, use the
294
                    // current
295
                    // view one
296
                    if (dataProjection == null) {
297
                        dataProjection = viewPort.getProjection();
298
                    }
288
					// If the data does not provide a projection, use the
289
					// current
290
					// view one
291
					if (dataProjection == null) {
292
						dataProjection = viewPort.getProjection();
293
					}
299 294

  
300
                    reprojectedDataEnvelop = featureStore.getEnvelope();
301
                } else {
302
                    dataProjection = coordTrans.getPOrig();
295
					reprojectedDataEnvelop = featureStore.getEnvelope();
296
				} else {
297
					dataProjection = coordTrans.getPOrig();
303 298

  
304
                    reprojectedDataEnvelop =
305
                        featureStore.getEnvelope().convert(coordTrans);
306
                }
307
            } catch (DataException e) {
308
                throw new LegendDrawingException(e);
309
            }
299
					reprojectedDataEnvelop = featureStore.getEnvelope()
300
							.convert(coordTrans);
301
				}
302
			} catch (DataException e) {
303
				throw new LegendDrawingException(e);
304
			}
310 305

  
311
            // Gets the view envelope
312
            Envelope viewPortEnvelope = viewPort.getAdjustedEnvelope();
306
			// Gets the view envelope
307
			Envelope viewPortEnvelope = viewPort.getAdjustedEnvelope();
313 308

  
314
            // Gets the data envelope with the viewport SRS
315
            Envelope myEnvelope = reprojectedDataEnvelop;
309
			// Gets the data envelope with the viewport SRS
310
			Envelope myEnvelope = reprojectedDataEnvelop;
316 311

  
317
            // TODO: in some cases, the legend may need a different check to
318
            // decide if the data must be drawn or not
319
            // Checks if the viewport envelope intersects with the data envelope
320
            if (!viewPortEnvelope.intersects(myEnvelope)) {
321
                // The data is not visible in the current viewport, do nothing.
322
                return;
323
            }
312
			// TODO: in some cases, the legend may need a different check to
313
			// decide if the data must be drawn or not
314
			// Checks if the viewport envelope intersects with the data envelope
315
			if (!viewPortEnvelope.intersects(myEnvelope)) {
316
				// The data is not visible in the current viewport, do nothing.
317
				return;
318
			}
324 319

  
325
            // Check if all the data is contained into the viewport envelope
326
            boolean containsAll = viewPortEnvelope.contains(myEnvelope);
320
			// Check if all the data is contained into the viewport envelope
321
			boolean containsAll = viewPortEnvelope.contains(myEnvelope);
327 322

  
328
            // Create the drawing notification to be reused on each iteration
329
            DefaultFeatureDrawnNotification drawnNotification =
330
                new DefaultFeatureDrawnNotification();
323
			// Create the drawing notification to be reused on each iteration
324
			DefaultFeatureDrawnNotification drawnNotification = new DefaultFeatureDrawnNotification();
331 325

  
332
            if (cancel.isCanceled()) {
333
                return;
334
            }
326
			if (cancel.isCanceled()) {
327
				return;
328
			}
335 329

  
336
            
337
            FeatureSet featureSet = null;
338
            try {
339
                taskStatus.message("Retrieve selection");
340
                FeatureSelection selection = featureStore.getFeatureSelection();
330
			FeatureSet featureSet = null;
331
			try {
332
				taskStatus.message("Retrieve selection");
333
				FeatureSelection selection = featureStore.getFeatureSelection();
341 334

  
342
                FeatureQuery featureQuery =
343
                    createQuery(featureStore, scale, queryParameters,
344
                        coordTrans, dataProjection, viewPortEnvelope,
345
                        containsAll);
335
				FeatureQuery featureQuery = createQuery(featureStore, scale,
336
						queryParameters, coordTrans, dataProjection,
337
						viewPortEnvelope, containsAll);
346 338

  
347
                taskStatus.message("Retrieve data");
348
                featureSet = featureStore.getFeatureSet(featureQuery);
339
				taskStatus.message("Retrieve data");
340
				featureSet = featureStore.getFeatureSet(featureQuery);
349 341

  
350
                if (cancel.isCanceled()) {
351
                    return;
352
                }
342
				if (cancel.isCanceled()) {
343
					return;
344
				}
353 345

  
354
                taskStatus.message("Drawing");
355
                drawFeatures(image, g, viewPort, cancel, coordTrans, dpi,
356
                    drawnNotification, featureSet, selection);
346
				taskStatus.message("Drawing");
347
				drawFeatures(image, g, viewPort, cancel, coordTrans, dpi,
348
						drawnNotification, featureSet, selection);
357 349

  
358
            } catch (BaseException e) {
359
                throw new LegendDrawingException(e);
360
            } finally {
361
                if (featureSet != null) {
362
                    featureSet.dispose();
363
                }
364
            }
365
        } finally {
366
            if( taskStatus!=null ) {
367
                taskStatus.terminate();
368
                taskStatus.remove();
369
                taskStatus = null;
370
            }
371
        }
350
			} catch (BaseException e) {
351
				throw new LegendDrawingException(e);
352
			} finally {
353
				if (featureSet != null) {
354
					featureSet.dispose();
355
				}
356
			}
357
		} finally {
358
			if (taskStatus != null) {
359
				taskStatus.terminate();
360
				taskStatus.remove();
361
				taskStatus = null;
362
			}
363
		}
372 364

  
373
    }
365
	}
374 366

  
375
    /**
376
     * Creates a {@link FeatureQuery} to load the {@link Feature}s to draw.
377
     */
378
    @SuppressWarnings("unchecked")
379
    private FeatureQuery createQuery(FeatureStore featureStore, double scale,
380
        Map queryParameters, ICoordTrans coordTrans,
381
        IProjection dataProjection, Envelope viewPortEnvelope,
382
        boolean containsAll) throws DataException {
367
	/**
368
	 * Creates a {@link FeatureQuery} to load the {@link Feature}s to draw.
369
	 */
370
	@SuppressWarnings("unchecked")
371
	private FeatureQuery createQuery(FeatureStore featureStore, double scale,
372
			Map queryParameters, ICoordTrans coordTrans,
373
			IProjection dataProjection, Envelope viewPortEnvelope,
374
			boolean containsAll) throws DataException {
383 375

  
384
        FeatureQuery featureQuery = featureStore.createFeatureQuery();
385
        featureQuery.setScale(scale);
386
        String[] fieldNames = getRequiredFeatureAttributeNames(featureStore);
387
        featureQuery.setAttributeNames(fieldNames);
388
        // TODO: Mobile has it's own IntersectsEnvelopeEvaluator
389
        if (!containsAll) {
390
            // Gets the viewport envelope with the data SRS
391
            Envelope viewPortEnvelopeInMyProj = viewPortEnvelope;
392
            // FIXME
393
            if (coordTrans != null) {
394
                viewPortEnvelopeInMyProj =
395
                    viewPortEnvelope.convert(coordTrans.getInverted());
396
            }
376
		FeatureQuery featureQuery = featureStore.createFeatureQuery();
377
		featureQuery.setScale(scale);
378
		String[] fieldNames = getRequiredFeatureAttributeNames(featureStore);
379
		featureQuery.setAttributeNames(fieldNames);
380
		// TODO: Mobile has it's own IntersectsEnvelopeEvaluator
381
		if (!containsAll) {
382
			// Gets the viewport envelope with the data SRS
383
			Envelope viewPortEnvelopeInMyProj = viewPortEnvelope;
384
			// FIXME
385
			if (coordTrans != null) {
386
				viewPortEnvelopeInMyProj = viewPortEnvelope.convert(coordTrans
387
						.getInverted());
388
			}
397 389

  
398
            if (dataProjection == null) {
399
                throw new IllegalArgumentException(
400
                    "Error, the projection parameter value is null");
401
            }
390
			if (dataProjection == null) {
391
				throw new IllegalArgumentException(
392
						"Error, the projection parameter value is null");
393
			}
402 394

  
403
            IntersectsEnvelopeEvaluator iee =
404
                new IntersectsEnvelopeEvaluator(viewPortEnvelopeInMyProj,
405
                    dataProjection, featureStore.getDefaultFeatureType(),
406
                    featureStore.getDefaultFeatureType()
407
                        .getDefaultGeometryAttributeName());
408
            featureQuery.setFilter(iee);
409
        }
410
        if (queryParameters != null) {
411
            Iterator iterEntry = queryParameters.entrySet().iterator();
412
            Entry entry;
413
            while (iterEntry.hasNext()) {
414
                entry = (Entry) iterEntry.next();
415
                featureQuery.setQueryParameter((String) entry.getKey(),
416
                    entry.getValue());
417
            }
418
        }
419
        return featureQuery;
420
    }
395
			IntersectsEnvelopeEvaluator iee = new IntersectsEnvelopeEvaluator(
396
					viewPortEnvelopeInMyProj, dataProjection,
397
					featureStore.getDefaultFeatureType(), featureStore
398
							.getDefaultFeatureType()
399
							.getDefaultGeometryAttributeName());
400
			featureQuery.setFilter(iee);
401
		}
402
		if (queryParameters != null) {
403
			Iterator iterEntry = queryParameters.entrySet().iterator();
404
			Entry entry;
405
			while (iterEntry.hasNext()) {
406
				entry = (Entry) iterEntry.next();
407
				featureQuery.setQueryParameter((String) entry.getKey(),
408
						entry.getValue());
409
			}
410
		}
411
		return featureQuery;
412
	}
421 413

  
422
    /**
423
     * Draws the features from the {@link FeatureSet}, with the symbols of the
424
     * legend.
425
     */
426
    private void drawFeatures(BufferedImage image, Graphics2D g,
427
        ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
428
        double dpi, DefaultFeatureDrawnNotification drawnNotification,
429
        FeatureSet featureSet, FeatureSelection selection) throws BaseException {
430
        if (isUseZSort()) {
431
            drawFeaturesMultiLayer(image, g, viewPort, cancel, coordTrans, dpi,
432
                drawnNotification, featureSet, selection);
433
        } else {
434
            drawFeaturesSingleLayer(image, g, viewPort, cancel, coordTrans,
435
                dpi, drawnNotification, featureSet, selection);
436
        }
437
    }
414
	/**
415
	 * Draws the features from the {@link FeatureSet}, with the symbols of the
416
	 * legend.
417
	 */
418
	private void drawFeatures(BufferedImage image, Graphics2D g,
419
			ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
420
			double dpi, DefaultFeatureDrawnNotification drawnNotification,
421
			FeatureSet featureSet, FeatureSelection selection)
422
			throws BaseException {
423
		if (isUseZSort()) {
424
			drawFeaturesMultiLayer(image, g, viewPort, cancel, coordTrans, dpi,
425
					drawnNotification, featureSet, selection);
426
		} else {
427
			drawFeaturesSingleLayer(image, g, viewPort, cancel, coordTrans,
428
					dpi, drawnNotification, featureSet, selection);
429
		}
430
	}
438 431

  
439
    /**
440
     * Draws the features from the {@link FeatureSet}, with the symbols of the
441
     * legend, using a single drawing layer.
442
     */
443
    private void drawFeaturesSingleLayer(final BufferedImage image,
444
        final Graphics2D g, final ViewPort viewPort, final Cancellable cancel,
445
        final ICoordTrans coordTrans, final double dpi,
446
        final DefaultFeatureDrawnNotification drawnNotification,
447
        FeatureSet featureSet, final FeatureSelection selection)
448
        throws BaseException {
432
	/**
433
	 * Draws the features from the {@link FeatureSet}, with the symbols of the
434
	 * legend, using a single drawing layer.
435
	 */
436
	private void drawFeaturesSingleLayer(final BufferedImage image,
437
			final Graphics2D g, final ViewPort viewPort,
438
			final Cancellable cancel, final ICoordTrans coordTrans,
439
			final double dpi,
440
			final DefaultFeatureDrawnNotification drawnNotification,
441
			FeatureSet featureSet, final FeatureSelection selection)
442
			throws BaseException {
449 443

  
450
        try {
451
            featureSet.accept(new Visitor() {
444
		try {
445
			featureSet.accept(new Visitor() {
446
				public void visit(Object obj) throws VisitCanceledException,
447
						BaseException {
448
					Feature feat = (Feature) obj;
449
					drawFeatureSingleLayer(image, g, viewPort, cancel,
450
							coordTrans, dpi, drawnNotification, feat, selection);
451
				}
452
			});
452 453

  
453
                public void visit(Object obj) throws VisitCanceledException,
454
                    BaseException {
455
                    Feature feat = (Feature) obj;
456
                    drawFeatureSingleLayer(image, g, viewPort, cancel,
457
                        coordTrans, dpi, drawnNotification, feat, selection);
458
                }
459
            });
454
		} catch (ConcurrentDataModificationException e) {
455
			cancel.setCanceled(true);
456
			return;
457
		}
458
	}
460 459

  
461
        } catch (ConcurrentDataModificationException e) {
462
            cancel.setCanceled(true);
463
            return;
464
        }
465
    }
460
	/**
461
	 * Draws a Feature with the symbols of the legend, using a single drawing
462
	 * layer.
463
	 */
464
	private void drawFeatureSingleLayer(BufferedImage image, Graphics2D g,
465
			ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
466
			double dpi, DefaultFeatureDrawnNotification drawnNotification,
467
			Feature feat, FeatureSelection selection)
468
			throws MapContextException, CreateGeometryException {
466 469

  
467
    /**
468
     * Draws a Feature with the symbols of the legend, using a single drawing
469
     * layer.
470
     */
471
    private void drawFeatureSingleLayer(BufferedImage image, Graphics2D g,
472
        ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
473
        double dpi, DefaultFeatureDrawnNotification drawnNotification,
474
        Feature feat, FeatureSelection selection) throws MapContextException,
475
        CreateGeometryException {
470
		Geometry geom = feat.getDefaultGeometry();
471
		if (geom == null) {
472
			return;
473
		}
476 474

  
477
        Geometry geom = feat.getDefaultGeometry();
475
		if (geom.getType() == Geometry.TYPES.NULL) {
476
			return;
477
		}
478 478

  
479
        if (geom.getType() == Geometry.TYPES.NULL) {
480
            return;
481
        }
479
		ISymbol sym = getSymbol(feat, selection);
480
		if (sym == null) {
481
			return;
482
		}
482 483

  
483
        ISymbol sym = getSymbol(feat, selection);
484
        if (sym == null) {
485
            return;
486
        }
484
		if (coordTrans != null) {
485
			geom = geom.cloneGeometry();
486
			geom.reProject(coordTrans);
487
		}
487 488

  
488
        if (coordTrans != null) {
489
            geom = geom.cloneGeometry();
490
            geom.reProject(coordTrans);
491
        }
489
		if (cancel.isCanceled()) {
490
			return;
491
		}
492 492

  
493
        if (cancel.isCanceled()) {
494
            return;
495
        }
493
		drawGeometry(geom, image, feat, sym, viewPort, g, dpi, cancel);
496 494

  
497
        drawGeometry(geom, image, feat, sym, viewPort, g, dpi, cancel);
495
		// Notify the drawing observers
496
		drawnNotification.setFeature(feat);
497
		drawnNotification.setDrawnGeometry(geom);
498
		notifyObservers(drawnNotification);
499
	}
498 500

  
499
        // Notify the drawing observers
500
        drawnNotification.setFeature(feat);
501
        drawnNotification.setDrawnGeometry(geom);
502
        notifyObservers(drawnNotification);
503
    }
501
	/**
502
	 * Draws the features from the {@link FeatureSet}, with the symbols of the
503
	 * legend, using a multiple drawing layer.
504
	 */
505
	private void drawFeaturesMultiLayer(BufferedImage image, Graphics2D g,
506
			ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
507
			double dpi, DefaultFeatureDrawnNotification drawnNotification,
508
			FeatureSet featureSet, FeatureSelection selection)
509
			throws MapContextException, CreateGeometryException, DataException {
504 510

  
505
    /**
506
     * Draws the features from the {@link FeatureSet}, with the symbols of the
507
     * legend, using a multiple drawing layer.
508
     */
509
    private void drawFeaturesMultiLayer(BufferedImage image, Graphics2D g,
510
        ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
511
        double dpi, DefaultFeatureDrawnNotification drawnNotification,
512
        FeatureSet featureSet, FeatureSelection selection)
513
        throws MapContextException, CreateGeometryException, DataException {
511
		// -- visual FX stuff
512
		long time = System.currentTimeMillis();
514 513

  
515
        // -- visual FX stuff
516
        long time = System.currentTimeMillis();
514
		boolean bSymbolLevelError = false;
515
		// render temporary map each screenRefreshRate milliseconds;
516
		int screenRefreshDelay = (int) ((1D / MapContext.getDrawFrameRate()) * 3 * 1000);
517
		BufferedImage[] imageLevels = null;
518
		Graphics2D[] graphics = null;
517 519

  
518
        boolean bSymbolLevelError = false;
519
        // render temporary map each screenRefreshRate milliseconds;
520
        int screenRefreshDelay =
521
            (int) ((1D / MapContext.getDrawFrameRate()) * 3 * 1000);
522
        BufferedImage[] imageLevels = null;
523
        Graphics2D[] graphics = null;
520
		imageLevels = new BufferedImage[getZSort().getLevelCount()];
521
		graphics = new Graphics2D[imageLevels.length];
522
		for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
524 523

  
525
        imageLevels = new BufferedImage[getZSort().getLevelCount()];
526
        graphics = new Graphics2D[imageLevels.length];
527
        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
524
			imageLevels[i] = CompatLocator.getGraphicsUtils()
525
					.createBufferedImage(image.getWidth(), image.getHeight(),
526
							image.getType());
528 527

  
529
            imageLevels[i] =
530
                CompatLocator.getGraphicsUtils().createBufferedImage(
531
                    image.getWidth(), image.getHeight(), image.getType());
528
			graphics[i] = imageLevels[i].createGraphics();
529
			graphics[i].setTransform(g.getTransform());
530
			graphics[i].setRenderingHints(g.getRenderingHints());
531
		}
532
		// -- end visual FX stuff
532 533

  
533
            graphics[i] = imageLevels[i].createGraphics();
534
            graphics[i].setTransform(g.getTransform());
535
            graphics[i].setRenderingHints(g.getRenderingHints());
536
        }
537
        // -- end visual FX stuff
534
		DisposableIterator it = null;
535
		try {
536
			it = featureSet.fastIterator();
537
			// Iteration over each feature
538
			while (it.hasNext()) {
539
				if (cancel.isCanceled()) {
540
					return;
541
				}
542
				Feature feat = (Feature) it.next();
538 543

  
539
        DisposableIterator it = null;
540
        try {
541
            it = featureSet.fastIterator();
542
            // Iteration over each feature
543
            while (it.hasNext()) {
544
                if (cancel.isCanceled()) {
545
                    return;
546
                }
547
                Feature feat = (Feature) it.next();
544
				bSymbolLevelError |= drawFeatureMultiLayer(image, g, viewPort,
545
						cancel, coordTrans, dpi, drawnNotification, selection,
546
						time, screenRefreshDelay, imageLevels, graphics, feat);
548 547

  
549
                bSymbolLevelError |=
550
                    drawFeatureMultiLayer(image, g, viewPort, cancel,
551
                        coordTrans, dpi, drawnNotification, selection, time,
552
                        screenRefreshDelay, imageLevels, graphics, feat);
548
			}
549
		} catch (ConcurrentDataModificationException e) {
550
			cancel.setCanceled(true);
551
			return;
552
		} finally {
553
			if (it != null) {
554
				it.dispose();
555
			}
556
		}
553 557

  
554
            }
555
        } catch (ConcurrentDataModificationException e) {
556
            cancel.setCanceled(true);
557
            return;
558
        } finally {
559
            if (it != null) {
560
                it.dispose();
561
            }
562
        }
558
		g.drawImage(image, 0, 0, null);
563 559

  
564
        g.drawImage(image, 0, 0, null);
560
		Point2D offset = viewPort.getOffset();
561
		CompatLocator.getGraphicsUtils().translate(g, offset.getX(),
562
				offset.getY());
565 563

  
566
        Point2D offset = viewPort.getOffset();
567
        CompatLocator.getGraphicsUtils().translate(g, offset.getX(),
568
            offset.getY());
564
		for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
565
			g.drawImage(imageLevels[i], 0, 0, null);
566
			imageLevels[i] = null;
567
			graphics[i] = null;
568
		}
569 569

  
570
        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
571
            g.drawImage(imageLevels[i], 0, 0, null);
572
            imageLevels[i] = null;
573
            graphics[i] = null;
574
        }
570
		CompatLocator.getGraphicsUtils().translate(g, -offset.getX(),
571
				-offset.getY());
575 572

  
576
        CompatLocator.getGraphicsUtils().translate(g, -offset.getX(),
577
            -offset.getY());
573
		imageLevels = null;
574
		graphics = null;
578 575

  
579
        imageLevels = null;
580
        graphics = null;
576
		if (bSymbolLevelError) {
577
			setZSort(null);
578
		}
579
	}
581 580

  
582
        if (bSymbolLevelError) {
583
            setZSort(null);
584
        }
585
    }
581
	/**
582
	 * Draws a Feature with the symbols of the legend, using a multiple drawing
583
	 * layer.
584
	 */
585
	private boolean drawFeatureMultiLayer(BufferedImage image, Graphics2D g,
586
			ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
587
			double dpi, DefaultFeatureDrawnNotification drawnNotification,
588
			FeatureSelection selection, long time, int screenRefreshDelay,
589
			BufferedImage[] imageLevels, Graphics2D[] graphics, Feature feat)
590
			throws MapContextException, CreateGeometryException {
586 591

  
587
    /**
588
     * Draws a Feature with the symbols of the legend, using a multiple drawing
589
     * layer.
590
     */
591
    private boolean drawFeatureMultiLayer(BufferedImage image, Graphics2D g,
592
        ViewPort viewPort, Cancellable cancel, ICoordTrans coordTrans,
593
        double dpi, DefaultFeatureDrawnNotification drawnNotification,
594
        FeatureSelection selection, long time, int screenRefreshDelay,
595
        BufferedImage[] imageLevels, Graphics2D[] graphics, Feature feat)
596
        throws MapContextException, CreateGeometryException {
592
		Geometry geom = feat.getDefaultGeometry();
593
		boolean bSymbolLevelError = false;
594
		long drawingTime = time;
597 595

  
598
        Geometry geom = feat.getDefaultGeometry();
599
        boolean bSymbolLevelError = false;
600
        long drawingTime = time;
596
		if (geom.getType() == Geometry.TYPES.NULL) {
597
			return false;
598
		}
601 599

  
602
        if (geom.getType() == Geometry.TYPES.NULL) {
603
            return false;
604
        }
600
		ISymbol sym = getSymbol(feat, selection);
605 601

  
606
        ISymbol sym = getSymbol(feat, selection);
602
		if (sym == null) {
603
			return false;
604
		}
607 605

  
608
        if (sym == null) {
609
            return false;
610
        }
606
		if (coordTrans != null) {
607
			geom = geom.cloneGeometry();
608
			geom.reProject(coordTrans);
609
		}
611 610

  
612
        if (coordTrans != null) {
613
            geom = geom.cloneGeometry();
614
            geom.reProject(coordTrans);
615
        }
611
		if (cancel.isCanceled()) {
612
			return false;
613
		}
616 614

  
617
        if (cancel.isCanceled()) {
618
            return false;
619
        }
615
		// Check if this symbol is a multilayer
616
		int[] symLevels = getZSort().getLevels(sym);
617
		if (sym instanceof IMultiLayerSymbol) {
618
			// if so, treat each of its layers as a single
619
			// symbol
620
			// in its corresponding map level
621
			IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
622
			for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) {
623
				ISymbol mySym = mlSym.getLayer(i);
624
				int symbolLevel = 0;
625
				if (symLevels != null) {
626
					symbolLevel = symLevels[i];
627
				} else {
628
					/*
629
					 * an error occured when managing symbol levels some of the
630
					 * legend changed events regarding the symbols did not
631
					 * finish satisfactory and the legend is now inconsistent.
632
					 * For this drawing, it will finish as it was at the bottom
633
					 * (level 0) but, when done, the ZSort will be reset to
634
					 * avoid app crashes. This is a bug that has to be fixed.
635
					 */
636
					bSymbolLevelError = true;
637
				}
638
				drawGeometry(geom, imageLevels[symbolLevel], feat, mySym,
639
						viewPort, graphics[symbolLevel], dpi, cancel);
640
			}
641
		} else {
642
			// else, just draw the symbol in its level
643
			int symbolLevel = 0;
644
			if (symLevels != null) {
645
				symbolLevel = symLevels[0];
646
			}
647
			drawGeometry(geom, imageLevels[symbolLevel], feat, sym, viewPort,
648
					graphics[symbolLevel], dpi, cancel);
649
		}
620 650

  
621
        // Check if this symbol is a multilayer
622
        int[] symLevels = getZSort().getLevels(sym);
623
        if (sym instanceof IMultiLayerSymbol) {
624
            // if so, treat each of its layers as a single
625
            // symbol
626
            // in its corresponding map level
627
            IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
628
            for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) {
629
                ISymbol mySym = mlSym.getLayer(i);
630
                int symbolLevel = 0;
631
                if (symLevels != null) {
632
                    symbolLevel = symLevels[i];
633
                } else {
634
                    /*
635
                     * an error occured when managing symbol levels some of the
636
                     * legend changed events regarding the symbols did not
637
                     * finish satisfactory and the legend is now inconsistent.
638
                     * For this drawing, it will finish as it was at the bottom
639
                     * (level 0) but, when done, the ZSort will be reset to
640
                     * avoid app crashes. This is a bug that has to be fixed.
641
                     */
642
                    bSymbolLevelError = true;
643
                }
644
                drawGeometry(geom, imageLevels[symbolLevel], feat, mySym,
645
                    viewPort, graphics[symbolLevel], dpi, cancel);
646
            }
647
        } else {
648
            // else, just draw the symbol in its level
649
            int symbolLevel = 0;
650
            if (symLevels != null) {
651
                symbolLevel = symLevels[0];
652
            }
653
            drawGeometry(geom, imageLevels[symbolLevel], feat, sym, viewPort,
654
                graphics[symbolLevel], dpi, cancel);
655
        }
651
		// -- visual FX stuff
652
		// Cuando el offset!=0 se est? dibujando sobre el
653
		// Layout y por tanto no tiene que ejecutar el
654
		// siguiente c?digo.
655
		Point2D offset = viewPort.getOffset();
656
		if (offset.getX() == 0 && offset.getY() == 0) {
657
			if ((System.currentTimeMillis() - drawingTime) > screenRefreshDelay) {
656 658

  
657
        // -- visual FX stuff
658
        // Cuando el offset!=0 se est? dibujando sobre el
659
        // Layout y por tanto no tiene que ejecutar el
660
        // siguiente c?digo.
661
        Point2D offset = viewPort.getOffset();
662
        if (offset.getX() == 0 && offset.getY() == 0) {
663
            if ((System.currentTimeMillis() - drawingTime) > screenRefreshDelay) {
659
				BufferedImage virtualBim = CompatLocator.getGraphicsUtils()
660
						.createBufferedImage(image.getWidth(),
661
								image.getHeight(), BufferedImage.TYPE_INT_ARGB);
664 662

  
665
                BufferedImage virtualBim =
666
                    CompatLocator.getGraphicsUtils().createBufferedImage(
667
                        image.getWidth(), image.getHeight(),
668
                        BufferedImage.TYPE_INT_ARGB);
663
				Graphics2D virtualGraphics = virtualBim.createGraphics();
664
				virtualGraphics.drawImage(image, 0, 0, null);
665
				for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
666
					virtualGraphics.drawImage(imageLevels[i], 0, 0, null);
667
				}
668
				g.clearRect(0, 0, image.getWidth(), image.getHeight());
669
				g.drawImage(virtualBim, 0, 0, null);
670
				drawingTime = System.currentTimeMillis();
671
			}
672
			// -- end visual FX stuff
669 673

  
670
                Graphics2D virtualGraphics = virtualBim.createGraphics();
671
                virtualGraphics.drawImage(image, 0, 0, null);
672
                for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
673
                    virtualGraphics.drawImage(imageLevels[i], 0, 0, null);
674
                }
675
                g.clearRect(0, 0, image.getWidth(), image.getHeight());
676
                g.drawImage(virtualBim, 0, 0, null);
677
                drawingTime = System.currentTimeMillis();
678
            }
679
            // -- end visual FX stuff
674
		}
675
		// Notify the drawing observers
676
		drawnNotification.setFeature(feat);
677
		drawnNotification.setDrawnGeometry(geom);
678
		notifyObservers(drawnNotification);
679
		return bSymbolLevelError;
680
	}
680 681

  
681
        }
682
        // Notify the drawing observers
683
        drawnNotification.setFeature(feat);
684
        drawnNotification.setDrawnGeometry(geom);
685
        notifyObservers(drawnNotification);
686
        return bSymbolLevelError;
687
    }
682
	/**
683
	 * Returns the symbol to use to draw a {@link Feature} taking into account
684
	 * if it is selected.
685
	 */
686
	private ISymbol getSymbol(Feature feat, FeatureSelection selection)
687
			throws MapContextException {
688
		// retrieve the symbol associated to such feature
689
		ISymbol sym = getSymbolByFeature(feat);
688 690

  
689
    /**
690
     * Returns the symbol to use to draw a {@link Feature} taking into account
691
     * if it is selected.
692
     */
693
    private ISymbol getSymbol(Feature feat, FeatureSelection selection)
694
        throws MapContextException {
695
        // retrieve the symbol associated to such feature
696
        ISymbol sym = getSymbolByFeature(feat);
691
		if (sym != null && selection.isSelected(feat)) {
692
			sym = sym.getSymbolForSelection();
693
		}
694
		return sym;
695
	}
697 696

  
698
        if (sym != null && selection.isSelected(feat)) {
699
            sym = sym.getSymbolForSelection();
700
        }
701
        return sym;
702
    }
697
	/**
698
	 * Returns if the legend is using a ZSort.
699
	 */
700
	private boolean isUseZSort() {
701
		return getZSort() != null && getZSort().isUsingZSort();
702
	}
703 703

  
704
    /**
705
     * Returns if the legend is using a ZSort.
706
     */
707
    private boolean isUseZSort() {
708
        return getZSort() != null && getZSort().isUsingZSort();
709
    }
704
	/**
705
	 * Draws a {@link Geometry} using the given {@link ISymbol}, over the
706
	 * {@link Graphics2D} object.
707
	 */
708
	private void drawGeometry(Geometry geom, BufferedImage image,
709
			Feature feature, ISymbol symbol, ViewPort viewPort,
710
			Graphics2D graphics, double dpi, Cancellable cancellable)
711
			throws CreateGeometryException {
710 712

  
711
    /**
712
     * Draws a {@link Geometry} using the given {@link ISymbol}, over the
713
     * {@link Graphics2D} object.
714
     */
715
    private void drawGeometry(Geometry geom, BufferedImage image,
716
        Feature feature, ISymbol symbol, ViewPort viewPort,
717
        Graphics2D graphics, double dpi, Cancellable cancellable)
718
        throws CreateGeometryException {
713
		if (geom instanceof Aggregate) {
714
			drawAggregate((Aggregate) geom, image, feature, symbol, viewPort,
715
					graphics, dpi, cancellable);
716
		} else {
717
			boolean bDrawCartographicSupport = false;
718
			if (symbol instanceof CartographicSupport) {
719
				bDrawCartographicSupport = ((CartographicSupport) symbol)
720
						.getUnit() != -1;
721
			}
719 722

  
720
        if (geom instanceof Aggregate) {
721
            drawAggregate((Aggregate) geom, image, feature, symbol, viewPort,
722
                graphics, dpi, cancellable);
723
        } else {
724
            boolean bDrawCartographicSupport = false;
725
            if (symbol instanceof CartographicSupport) {
726
                bDrawCartographicSupport =
727
                    ((CartographicSupport) symbol).getUnit() != -1;
728
            }
723
			double previousSize = 0.0d;
729 724

  
730
            double previousSize = 0.0d;
725
			if (bDrawCartographicSupport) {
726
				// make the symbol to resize itself with the current rendering
727
				// context
728
				previousSize = ((CartographicSupport) symbol)
729
						.toCartographicSize(viewPort, dpi, geom);
730
			}
731 731

  
732
            if (bDrawCartographicSupport) {
733
                // make the symbol to resize itself with the current rendering
734
                // context
735
                previousSize =
736
                    ((CartographicSupport) symbol).toCartographicSize(viewPort,
737
                        dpi, geom);
738
            }
732
			try {
733
				// draw it as normally
734
				double[] dot = new double[2];
735
				boolean onePoint = symbol.isOneDotOrPixel(geom, dot, viewPort,
736
						(int) dpi);
739 737

  
740
            try {
741
                // draw it as normally
742
                double[] dot = new double[2];
743
                boolean onePoint =
744
                    symbol.isOneDotOrPixel(geom, dot, viewPort, (int) dpi);
738
				if (onePoint) {
739
					if (dot[0] < 0 || dot[1] < 0 || dot[0] >= image.getWidth()
740
							|| dot[1] >= image.getHeight()) {
741
						return;
742
					}
743
					// FIXME: setRgb should change to draw
744
					image.setRGB((int) dot[0], (int) dot[1],
745
							symbol.getOnePointRgb());
746
				} else {
747
					Geometry decimatedShape = transformToInts(geom,
748
							viewPort.getAffineTransform());
749
					symbol.draw(graphics, viewPort.getAffineTransform(),
750
							decimatedShape, feature, cancellable);
751
				}
745 752

  
746
                if (onePoint) {
747
                    if (dot[0] < 0 || dot[1] < 0 || dot[0] >= image.getWidth()
748
                        || dot[1] >= image.getHeight()) {
749
                        return;
750
                    }
751
                    // FIXME: setRgb should change to draw
752
                    image.setRGB((int) dot[0], (int) dot[1],
753
                        symbol.getOnePointRgb());
754
                } else {
755
                    Geometry decimatedShape =
756
                        transformToInts(geom, viewPort.getAffineTransform());
757
                    symbol.draw(graphics, viewPort.getAffineTransform(),
758
                        decimatedShape, feature, cancellable);
759
                }
753
			} finally {
754
				if (bDrawCartographicSupport) {
755
					// restore previous size
756
					((CartographicSupport) symbol).setCartographicSize(
757
							previousSize, geom);
758
				}
759
			}
760
		}
761
	}
760 762

  
761
            } finally {
762
                if (bDrawCartographicSupport) {
763
                    // restore previous size
764
                    ((CartographicSupport) symbol).setCartographicSize(
765
                        previousSize, geom);
766
                }
767
            }
768
        }
769
    }
763
	/**
764
	 * Draws an {@link Aggregate} using the given {@link ISymbol}, over the
765
	 * {@link Graphics2D} object.
766
	 */
767
	private void drawAggregate(Aggregate aggregate, BufferedImage image,
768
			Feature feature, ISymbol symbol, ViewPort viewPort,
769
			Graphics2D graphics, double dpi, Cancellable cancellable)
770
			throws CreateGeometryException {
771
		for (int i = 0; i < aggregate.getPrimitivesNumber(); i++) {
772
			Geometry prim = aggregate.getPrimitiveAt(i);
773
			drawGeometry(prim, image, feature, symbol, viewPort, graphics, dpi,
774
					cancellable);
775
		}
776
	}
770 777

  
771
    /**
772
     * Draws an {@link Aggregate} using the given {@link ISymbol}, over the
773
     * {@link Graphics2D} object.
774
     */
775
    private void drawAggregate(Aggregate aggregate, BufferedImage image,
776
        Feature feature, ISymbol symbol, ViewPort viewPort,
777
        Graphics2D graphics, double dpi, Cancellable cancellable)
778
        throws CreateGeometryException {
779
        for (int i = 0; i < aggregate.getPrimitivesNumber(); i++) {
780
            Geometry prim = aggregate.getPrimitiveAt(i);
781
            drawGeometry(prim, image, feature, symbol, viewPort, graphics, dpi,
782
                cancellable);
783
        }
784
    }
778
	/**
779
	 * Transforms a Geometry from map coordinates to the view coordinates.
780
	 */
781
	private Geometry transformToInts(Geometry gp, AffineTransform at)
782
			throws CreateGeometryException {
783
		GeneralPathX newGp = new GeneralPathX();
784
		double[] theData = new double[6];
785
		double[] aux = new double[6];
785 786

  
786
    /**
787
     * Transforms a Geometry from map coordinates to the view coordinates.
788
     */
789
    private Geometry transformToInts(Geometry gp, AffineTransform at)
790
        throws CreateGeometryException {
791
        GeneralPathX newGp = new GeneralPathX();
792
        double[] theData = new double[6];
793
        double[] aux = new double[6];
787
		// newGp.reset();
788
		PathIterator theIterator;
789
		int theType;
790
		int numParts = 0;
794 791

  
795
        // newGp.reset();
796
        PathIterator theIterator;
797
        int theType;
798
        int numParts = 0;
792
		java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double();
793
		java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double();
794
		boolean bFirst = true;
795
		int xInt, yInt, antX = -1, antY = -1;
799 796

  
800
        java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double();
801
        java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double();
802
        boolean bFirst = true;
803
        int xInt, yInt, antX = -1, antY = -1;
797
		theIterator = gp.getPathIterator(null); // , flatness);
798
		int numSegmentsAdded = 0;
799
		while (!theIterator.isDone()) {
800
			theType = theIterator.currentSegment(theData);
804 801

  
805
        theIterator = gp.getPathIterator(null); // , flatness);
806
        int numSegmentsAdded = 0;
807
        while (!theIterator.isDone()) {
808
            theType = theIterator.currentSegment(theData);
802
			switch (theType) {
803
			case PathIterator.SEG_MOVETO:
804
				numParts++;
805
				ptSrc.setLocation(theData[0], theData[1]);
806
				at.transform(ptSrc, ptDst);
807
				antX = (int) ptDst.getX();
808
				antY = (int) ptDst.getY();
809
				newGp.moveTo(antX, antY);
810
				numSegmentsAdded++;
811
				bFirst = true;
812
				break;
809 813

  
810
            switch (theType) {
811
            case PathIterator.SEG_MOVETO:
812
                numParts++;
813
                ptSrc.setLocation(theData[0], theData[1]);
814
                at.transform(ptSrc, ptDst);
815
                antX = (int) ptDst.getX();
816
                antY = (int) ptDst.getY();
817
                newGp.moveTo(antX, antY);
818
                numSegmentsAdded++;
819
                bFirst = true;
820
                break;
814
			case PathIterator.SEG_LINETO:
815
				ptSrc.setLocation(theData[0], theData[1]);
816
				at.transform(ptSrc, ptDst);
817
				xInt = (int) ptDst.getX();
818
				yInt = (int) ptDst.getY();
819
				if ((bFirst) || ((xInt != antX) || (yInt != antY))) {
820
					newGp.lineTo(xInt, yInt);
821
					antX = xInt;
822
					antY = yInt;
823
					bFirst = false;
824
					numSegmentsAdded++;
825
				}
826
				break;
821 827

  
822
            case PathIterator.SEG_LINETO:
823
                ptSrc.setLocation(theData[0], theData[1]);
824
                at.transform(ptSrc, ptDst);
825
                xInt = (int) ptDst.getX();
826
                yInt = (int) ptDst.getY();
827
                if ((bFirst) || ((xInt != antX) || (yInt != antY))) {
828
                    newGp.lineTo(xInt, yInt);
829
                    antX = xInt;
830
                    antY = yInt;
831
                    bFirst = false;
832
                    numSegmentsAdded++;
833
                }
834
                break;
828
			case PathIterator.SEG_QUADTO:
829
				at.transform(theData, 0, aux, 0, 2);
830
				newGp.quadTo(aux[0], aux[1], aux[2], aux[3]);
831
				numSegmentsAdded++;
832
				break;
835 833

  
836
            case PathIterator.SEG_QUADTO:
837
                at.transform(theData, 0, aux, 0, 2);
838
                newGp.quadTo(aux[0], aux[1], aux[2], aux[3]);
839
                numSegmentsAdded++;
840
                break;
834
			case PathIterator.SEG_CUBICTO:
835
				at.transform(theData, 0, aux, 0, 3);
836
				newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]);
837
				numSegmentsAdded++;
838
				break;
841 839

  
842
            case PathIterator.SEG_CUBICTO:
843
                at.transform(theData, 0, aux, 0, 3);
844
                newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]);
845
                numSegmentsAdded++;
846
                break;
840
			case PathIterator.SEG_CLOSE:
841
				if (numSegmentsAdded < 3) {
842
					newGp.lineTo(antX, antY);
843
				}
844
				newGp.closePath();
847 845

  
848
            case PathIterator.SEG_CLOSE:
849
                if (numSegmentsAdded < 3) {
850
                    newGp.lineTo(antX, antY);
851
                }
852
                newGp.closePath();
846
				break;
847
			} // end switch
853 848

  
854
                break;
855
            } // end switch
849
			theIterator.next();
850
		} // end while loop
856 851

  
857
            theIterator.next();
858
        } // end while loop
852
		Geometry geom = null;
853
		switch (gp.getType()) {
854
		case Geometry.TYPES.POINT:
855
			geom = geomManager.createPoint(ptDst.getX(), ptDst.getY(),
856
					SUBTYPES.GEOM2D);
857
			break;
858
		case Geometry.TYPES.CURVE:
859
		case Geometry.TYPES.ARC:
860
			geom = geomManager.createCurve(newGp, SUBTYPES.GEOM2D);
861
			break;
859 862

  
860
        Geometry geom = null;
861
        switch (gp.getType()) {
862
        case Geometry.TYPES.POINT:
863
            geom =
864
                geomManager.createPoint(ptDst.getX(), ptDst.getY(),
865
                    SUBTYPES.GEOM2D);
866
            break;
867
        case Geometry.TYPES.CURVE:
868
        case Geometry.TYPES.ARC:
869
            geom = geomManager.createCurve(newGp, SUBTYPES.GEOM2D);
870
            break;
863
		case Geometry.TYPES.SURFACE:
864
		case Geometry.TYPES.CIRCLE:
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff