Revision 35778 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/DefaultMapContextDrawer.java
DefaultMapContextDrawer.java | ||
---|---|---|
40 | 40 |
protected boolean isLayerCacheable(FLayer layer){ |
41 | 41 |
return layer.isActive(); |
42 | 42 |
} |
43 |
|
|
43 |
|
|
44 | 44 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel, |
45 | 45 |
double scale) throws ReadDriverException { |
46 | 46 |
|
... | ... | |
119 | 119 |
//si tenemos una composicion de capas, necesitamos pintarlas |
120 | 120 |
//antes de guardarnos la imagen |
121 | 121 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (antes de cache)============"); |
122 |
this.draw(composed, image, g, cancel, scale); |
|
122 |
this.draw(composed, image, g, cancel, scale, MapContext.getScreenDPI());
|
|
123 | 123 |
// composed.draw(image, g, viewPort, cancel, scale); |
124 | 124 |
composed = null; |
125 | 125 |
|
... | ... | |
158 | 158 |
} |
159 | 159 |
} else { |
160 | 160 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (cambio composicion)============"); |
161 |
this.draw(composed, image, g, cancel, scale); |
|
161 |
this.draw(composed, image, g, cancel, scale, MapContext.getScreenDPI());
|
|
162 | 162 |
// composed.draw(image, g, viewPort, cancel, scale); |
163 | 163 |
composed = layer.newComposedLayer(); |
164 | 164 |
if (composed != null){ |
... | ... | |
172 | 172 |
} |
173 | 173 |
} |
174 | 174 |
// System.out.println("=== pintando "+ layerPos+ " "+layer.getName()); |
175 |
this.draw(layer, image, g, cancel, scale); |
|
175 |
this.draw(layer, image, g, cancel, scale, MapContext.getScreenDPI());
|
|
176 | 176 |
// layer.draw(image, g, viewPort, cancel, scale); |
177 | 177 |
|
178 | 178 |
} |
179 | 179 |
if (composed != null){ |
180 | 180 |
// si la composicion no se ha pintado la pintamos |
181 | 181 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (ultimo)============"); |
182 |
this.draw(composed, image, g, cancel, scale); |
|
182 |
this.draw(composed, image, g, cancel, scale, MapContext.getScreenDPI());
|
|
183 | 183 |
// composed.draw(image, g, viewPort, cancel, scale); |
184 | 184 |
} |
185 | 185 |
if (cancel.isCanceled()){ |
... | ... | |
189 | 189 |
this.previousDrawList = drawList; |
190 | 190 |
|
191 | 191 |
} |
192 |
|
|
193 |
|
|
192 | 194 |
|
195 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel, |
|
196 |
double scale, double _dpi) throws ReadDriverException { |
|
197 |
|
|
198 |
this.checkIntilalized(); |
|
199 |
|
|
200 |
boolean needToPaintAll = false; |
|
201 |
|
|
202 |
DrawList drawList = this.createDrawList(root, cancel,scale); |
|
203 |
if (cancel.isCanceled()){ |
|
204 |
return; |
|
205 |
} |
|
206 |
|
|
207 |
if (cachedImage == null){ |
|
208 |
needToPaintAll=true; |
|
209 |
} else if (!cachedImage.isValid(mapContext, viewPort, drawList.getFirstLayerToDraw())){ |
|
210 |
needToPaintAll=true; |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
int firstLayer= 0; |
|
215 |
if (!needToPaintAll){ |
|
216 |
firstLayer = cachedImage.getListPosition()+1; |
|
217 |
// System.out.println("=======Pintando a partir de la pos "+ firstLayer+"============"); |
|
218 |
g.drawImage(cachedImage.getImage(), 0, 0, null); |
|
219 |
// System.out.println("=======Pintando imagen ============"); |
|
220 |
|
|
221 |
} else{ |
|
222 |
this.cachedImage = null; |
|
223 |
// System.out.println("=======Pintando todo============"); |
|
224 |
} |
|
225 |
|
|
226 |
|
|
227 |
boolean cached=false; |
|
228 |
ComposedLayer composed = null; |
|
229 |
int pos; |
|
230 |
int layerPos= -1; |
|
231 |
FLayer layer; |
|
232 |
Object obj; |
|
233 |
LayersGroupEvent event; |
|
234 |
for (pos=0; pos < drawList.size(); pos++){ |
|
235 |
if (cancel.isCanceled()){ |
|
236 |
return; |
|
237 |
} |
|
238 |
|
|
239 |
obj = drawList.get(pos); |
|
240 |
|
|
241 |
// *** Gestion de eventos de pintado de grupos *** |
|
242 |
if (obj instanceof LayersGroupEvent){ |
|
243 |
event = (LayersGroupEvent) obj; |
|
244 |
if (event.type == LayersGroupEvent.IN_Event){ |
|
245 |
// System.out.println("=======Empiza a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
246 |
event.group.beginDraw(g, viewPort); |
|
247 |
} else{ |
|
248 |
event.group.endDraw(g, viewPort); |
|
249 |
// System.out.println("=======Fin a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
250 |
|
|
251 |
} |
|
252 |
continue; |
|
253 |
} |
|
254 |
layerPos++; |
|
255 |
if (layerPos < firstLayer){ |
|
256 |
continue; |
|
257 |
} |
|
258 |
|
|
259 |
layer = (FLayer) obj; |
|
260 |
if (cancel.isCanceled()){ |
|
261 |
return; |
|
262 |
} |
|
263 |
|
|
264 |
// *** Gestion de cache *** |
|
265 |
if ((!cached) && this.isLayerCacheable(layer)){ |
|
266 |
if (layerPos > 0){ //La primera capa es la activa, no cacheamos |
|
267 |
if (cachedImage==null || cachedImage.getListPosition() < layerPos-1){ |
|
268 |
|
|
269 |
if (composed != null){ |
|
270 |
//si tenemos una composicion de capas, necesitamos pintarlas |
|
271 |
//antes de guardarnos la imagen |
|
272 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (antes de cache)============"); |
|
273 |
this.draw(composed, image, g, cancel, scale, _dpi); |
|
274 |
// composed.draw(image, g, viewPort, cancel, scale); |
|
275 |
composed = null; |
|
276 |
|
|
277 |
} |
|
278 |
CachedImage newCached = new CachedImage(); |
|
279 |
newCached.setImage(image, mapContext, viewPort, layerPos-1); |
|
280 |
this.cachedImage = newCached; |
|
281 |
// System.out.println("=======Guardando imagen de la pos "+ (layerPos-1)+" ("+ newCached.getListPosition() +")============"); |
|
282 |
} |
|
283 |
} |
|
284 |
cached = true; |
|
285 |
} |
|
286 |
if (cancel.isCanceled()){ |
|
287 |
return; |
|
288 |
} |
|
289 |
|
|
290 |
if (composed == null){ |
|
291 |
composed = layer.newComposedLayer(); |
|
292 |
if (composed != null){ |
|
293 |
try { |
|
294 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
295 |
composed.add(layer); |
|
296 |
continue; |
|
297 |
} catch (Exception e) { |
|
298 |
throw new ReadDriverException("DefaultMapContexDrawer exception",e); |
|
299 |
} |
|
300 |
} |
|
301 |
}else{ |
|
302 |
if (composed.canAdd(layer)){ |
|
303 |
try { |
|
304 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
305 |
composed.add(layer); |
|
306 |
continue; |
|
307 |
} catch (Exception e) { |
|
308 |
throw new ReadDriverException("DefaultMapContexDrawer exception",e); |
|
309 |
} |
|
310 |
} else { |
|
311 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (cambio composicion)============"); |
|
312 |
this.draw(composed, image, g, cancel, scale, _dpi); |
|
313 |
// composed.draw(image, g, viewPort, cancel, scale); |
|
314 |
composed = layer.newComposedLayer(); |
|
315 |
if (composed != null){ |
|
316 |
try { |
|
317 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
318 |
composed.add(layer); |
|
319 |
continue; |
|
320 |
} catch (Exception e) { |
|
321 |
throw new ReadDriverException("DefaultMapContexDrawer exception",e); |
|
322 |
} } |
|
323 |
} |
|
324 |
} |
|
325 |
// System.out.println("=== pintando "+ layerPos+ " "+layer.getName()); |
|
326 |
this.draw(layer, image, g, cancel, scale, _dpi); |
|
327 |
// layer.draw(image, g, viewPort, cancel, scale); |
|
328 |
|
|
329 |
} |
|
330 |
if (composed != null){ |
|
331 |
// si la composicion no se ha pintado la pintamos |
|
332 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (ultimo)============"); |
|
333 |
this.draw(composed, image, g, cancel, scale, _dpi); |
|
334 |
// composed.draw(image, g, viewPort, cancel, scale); |
|
335 |
} |
|
336 |
if (cancel.isCanceled()){ |
|
337 |
return; |
|
338 |
} |
|
339 |
|
|
340 |
this.previousDrawList = drawList; |
|
341 |
|
|
342 |
} |
|
343 |
|
|
193 | 344 |
private void draw(Object layerOrComposed,BufferedImage image, Graphics2D g, Cancellable cancel, |
194 |
double scale) throws ReadDriverException{ |
|
345 |
double scale, double _dpi) throws ReadDriverException{
|
|
195 | 346 |
ILabelable labelable= null; |
196 | 347 |
ILabelable tmp= null; |
197 | 348 |
if (layerOrComposed instanceof ILabelable){ |
... | ... | |
212 | 363 |
composed.draw(image, g, viewPort, cancel, scale); |
213 | 364 |
} |
214 | 365 |
if (labelable != null){ |
215 |
labelable.drawLabels(image, g, viewPort, cancel, scale, MapContext.getScreenDPI());
|
|
366 |
labelable.drawLabels(image, g, viewPort, cancel, scale, _dpi);
|
|
216 | 367 |
} |
217 | 368 |
|
218 | 369 |
} |
Also available in: Unified diff