Revision 11125
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLayers.java | ||
---|---|---|
421 | 421 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort) |
422 | 422 |
*/ |
423 | 423 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
424 |
Cancellable cancel,double scale) throws DriverException { |
|
424 |
Cancellable cancel,double scale) throws DriverException { |
|
425 |
draw(image,g,viewPort,cancel, scale, null); |
|
426 |
} |
|
427 |
|
|
428 |
|
|
429 |
public ComposedLayer draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
430 |
Cancellable cancel,double scale, ComposedLayer group) throws DriverException { |
|
425 | 431 |
//double scale = getFMap().getScaleView(); |
426 | 432 |
// Iterator iter = layers.iterator(); |
427 | 433 |
// try |
... | ... | |
430 | 436 |
|
431 | 437 |
///// CHEMA ComposedLayer |
432 | 438 |
long tg1 = System.currentTimeMillis(); |
433 |
ComposedLayer group = null; |
|
434 |
ArrayList pendingEvents= new ArrayList(); |
|
435 |
boolean fireAfterDrawEvent = true; |
|
436 | 439 |
///// CHEMA ComposedLayer |
437 | 440 |
|
438 |
|
|
439 |
|
|
441 |
|
|
442 |
|
|
440 | 443 |
// while (iter.hasNext()) |
441 | 444 |
// { |
442 | 445 |
for (int i=0; i < layers.size(); i++) { |
... | ... | |
445 | 448 |
// FLayer lyr = (FLayer) iter.next(); |
446 | 449 |
FLayer lyr = (FLayer) layers.get(i); |
447 | 450 |
|
448 |
|
|
449 |
///// CHEMA ComposedLayer |
|
450 |
fireAfterDrawEvent = true; |
|
451 |
///// CHEMA ComposedLayer |
|
452 |
|
|
453 |
|
|
451 |
|
|
452 |
|
|
454 | 453 |
/* if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken()){ |
455 | 454 |
continue; |
456 | 455 |
} |
... | ... | |
492 | 491 |
//si tenemos un grupo pendiente de pintar, pintamos |
493 | 492 |
// para que la cache sea fiable |
494 | 493 |
group.draw(image, g, viewPort, cancel,scale); |
495 |
fireLayerDrawingEvents(pendingEvents); |
|
496 |
pendingEvents.clear(); |
|
497 | 494 |
group = null; |
498 | 495 |
} |
499 | 496 |
///// CHEMA ComposedLayer |
497 |
|
|
500 | 498 |
|
501 |
|
|
502 | 499 |
// Copiamos la imagen actual |
503 | 500 |
BufferedImage buff = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
504 | 501 |
WritableRaster w = buff.getRaster(); |
... | ... | |
516 | 513 |
// prepareDrawing de FMap. |
517 | 514 |
if (lyr.isDirty()) |
518 | 515 |
{ |
519 |
|
|
520 |
|
|
516 |
|
|
517 |
|
|
521 | 518 |
///// CHEMA ComposedLayer |
522 | 519 |
// Checks for draw group (ComposedLayer) |
523 | 520 |
if (group != null) { |
524 | 521 |
// it's going to load a cache image, |
525 | 522 |
// the current draw isn't needed |
526 |
fireLayerDrawingEvents(pendingEvents); |
|
527 |
pendingEvents.clear(); |
|
528 | 523 |
group = null; |
529 | 524 |
} |
530 | 525 |
///// CHEMA ComposedLayer |
526 |
|
|
531 | 527 |
|
532 |
|
|
533 | 528 |
g.drawImage(lyr.getCacheImageDrawnLayers(), 0, 0, null); |
534 | 529 |
System.err.println("Pinto con acelerado lo que hab?a antes de " + lyr.getName()); |
535 | 530 |
} |
... | ... | |
539 | 534 |
// Si la capa est? "sucia" o alguna de las de abajo est? sucia |
540 | 535 |
// hay que volver a dibujar. |
541 | 536 |
if (lyr.isDirty() || bNeedRecalculateCache) |
542 |
{ |
|
537 |
{
|
|
543 | 538 |
if (!lyr.getFLayerStatus().isDriverLoaded()) |
544 | 539 |
{ |
545 | 540 |
continue; |
546 | 541 |
} |
547 |
|
|
542 |
|
|
548 | 543 |
///// CHEMA ComposedLayer |
549 | 544 |
//lyr.draw(image, g, viewPort, cancel,scale); |
550 | 545 |
//bNeedRecalculateCache = true; |
551 | 546 |
//System.err.println("Pinto sin acelerado " + lyr.getName()); |
552 | 547 |
///// CHEMA ComposedLayer |
553 |
|
|
548 |
|
|
554 | 549 |
///// CHEMA ComposedLayer |
555 | 550 |
// Checks for draw group (ComposedLayer) |
556 |
if (group != null) { |
|
557 |
//If layer can be added to the group, does it |
|
558 |
if (group.canAdd(lyr)) { |
|
559 |
group.add(lyr); |
|
560 |
pendingEvents.add(new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW)); |
|
561 |
fireAfterDrawEvent=false; |
|
551 |
if (group != null) { |
|
552 |
if (lyr instanceof FLayers){ |
|
553 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
|
554 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
|
555 |
fmap.fireLayerDrawingEvent(afterEvent); |
|
562 | 556 |
} else { |
563 |
// draw the 'pending to draw' layer group |
|
564 |
group.draw(image, g, viewPort, cancel,scale); |
|
565 |
fireLayerDrawingEvents(pendingEvents); |
|
566 |
pendingEvents.clear(); |
|
567 |
|
|
568 |
// gets a new group instance |
|
569 |
group = lyr.newComposedLayer(); |
|
570 |
// if layer hasn't group, draws it inmediately |
|
571 |
if (group == null) { |
|
572 |
lyr.draw(image, g, viewPort, cancel,scale); |
|
573 |
} else { |
|
574 |
// add the layer to the group |
|
575 |
group.add(lyr); |
|
576 |
pendingEvents.add(new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW)); |
|
577 |
fireAfterDrawEvent=false; |
|
578 |
} |
|
557 |
// If layer can be added to the group, does it |
|
558 |
if (group.canAdd(lyr)) { |
|
559 |
group.add(lyr); |
|
560 |
} else { |
|
561 |
// draw the 'pending to draw' layer group |
|
562 |
group.draw(image, g, viewPort, cancel,scale); |
|
563 |
|
|
564 |
// gets a new group instance |
|
565 |
group = lyr.newComposedLayer(); |
|
566 |
// if layer hasn't group, draws it inmediately |
|
567 |
if (group == null) { |
|
568 |
if (lyr instanceof FLayers){ |
|
569 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
|
570 |
} else { |
|
571 |
lyr.draw(image, g, viewPort, cancel,scale); |
|
572 |
} |
|
573 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
|
574 |
fmap.fireLayerDrawingEvent(afterEvent); |
|
575 |
} else { |
|
576 |
// add the layer to the group |
|
577 |
group.setMapContext(fmap); |
|
578 |
group.add(lyr); |
|
579 |
|
|
580 |
} |
|
581 |
} |
|
579 | 582 |
} |
580 | 583 |
} else { |
581 | 584 |
// gets a new group instance |
582 | 585 |
group = lyr.newComposedLayer(); |
583 |
// if layer hasn't group, draws it inmediately |
|
586 |
// if layer hasn't group, draws it inmediately
|
|
584 | 587 |
if (group == null) { |
585 |
lyr.draw(image, g, viewPort, cancel,scale); |
|
588 |
if (lyr instanceof FLayers){ |
|
589 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
|
590 |
} else { |
|
591 |
lyr.draw(image, g, viewPort, cancel,scale); |
|
592 |
} |
|
593 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
|
594 |
fmap.fireLayerDrawingEvent(afterEvent); |
|
586 | 595 |
} else { |
587 | 596 |
// adds the layer to the group |
597 |
group.setMapContext(fmap); |
|
588 | 598 |
group.add(lyr); |
589 |
pendingEvents.add(new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW)); |
|
590 |
fireAfterDrawEvent=false; |
|
591 | 599 |
} |
592 | 600 |
} |
593 | 601 |
///// CHEMA ComposedLayer |
... | ... | |
611 | 619 |
if (!cancel.isCanceled()) |
612 | 620 |
lyr.setDirty(false); |
613 | 621 |
} |
614 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
|
615 |
fmap.fireLayerDrawingEvent(afterEvent); |
|
616 | 622 |
|
617 | 623 |
} |
618 |
///// CHEMA ComposedLayer |
|
619 |
if (group != null) { |
|
620 |
//si tenemos un grupo pendiente de pintar, pintamos |
|
624 |
///// CHEMA ComposedLayer
|
|
625 |
if (group != null && this.getParentLayer() == null) {
|
|
626 |
//si tenemos un grupo pendiente de pintar, pintamos
|
|
621 | 627 |
group.draw(image, g, viewPort, cancel,scale); |
622 |
fireLayerDrawingEvents(pendingEvents);
|
|
628 |
group = null;
|
|
623 | 629 |
|
624 | 630 |
} |
625 |
///// CHEMA ComposedLayer |
|
631 |
///// CHEMA ComposedLayer
|
|
626 | 632 |
if (getVirtualLayers() != null) { |
627 | 633 |
getVirtualLayers().draw(image, g, viewPort, cancel,scale); |
628 | 634 |
} |
635 |
|
|
636 |
///// CHEMA ComposedLayer |
|
637 |
return group; |
|
638 |
///// CHEMA ComposedLayer |
|
639 |
|
|
629 | 640 |
// } |
630 | 641 |
// catch (ConcurrentModificationException e) |
631 | 642 |
// { |
632 | 643 |
// System.err.println(e.getMessage()); |
633 | 644 |
// } |
634 | 645 |
} |
635 |
|
|
636 |
private void fireLayerDrawingEvents(Collection events) { |
|
637 |
Iterator iter = events.iterator(); |
|
638 |
LayerDrawEvent afterEvent; |
|
639 |
while (iter.hasNext()) { |
|
640 |
afterEvent =(LayerDrawEvent)iter.next(); |
|
641 |
System.out.println("+++ evento " + afterEvent.getLayer().getName()); |
|
642 |
fmap.fireLayerDrawingEvent(afterEvent); |
|
643 |
} |
|
644 |
} |
|
645 |
|
|
646 |
|
|
646 | 647 |
/** |
647 | 648 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, |
648 | 649 |
* com.iver.cit.gvsig.fmap.ViewPort, |
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/layerOperations/ComposedLayer.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.Graphics2D; |
4 | 4 |
import java.awt.image.BufferedImage; |
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Collection; |
|
7 |
import java.util.Iterator; |
|
5 | 8 |
|
6 | 9 |
import com.iver.cit.gvsig.fmap.DriverException; |
10 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
7 | 11 |
import com.iver.cit.gvsig.fmap.ViewPort; |
8 | 12 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
13 |
import com.iver.cit.gvsig.fmap.layers.LayerDrawEvent; |
|
9 | 14 |
import com.iver.utiles.swing.threads.Cancellable; |
10 | 15 |
|
11 | 16 |
/** |
12 |
* Interface for the classes that make able
|
|
17 |
* Abstract class for the classes that make able
|
|
13 | 18 |
* a single draw for a layers group |
14 | 19 |
* |
15 | 20 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer() |
16 | 21 |
*/ |
17 |
public interface ComposedLayer {
|
|
22 |
public abstract class ComposedLayer {
|
|
18 | 23 |
|
24 |
ArrayList pendingLayersEvents= new ArrayList(); |
|
25 |
MapContext mapContext = null; |
|
26 |
|
|
27 |
public ComposedLayer(){ |
|
28 |
|
|
29 |
} |
|
30 |
|
|
31 |
public void setMapContext(MapContext mapContext) { |
|
32 |
this.mapContext = mapContext; |
|
33 |
} |
|
34 |
|
|
19 | 35 |
/** |
20 | 36 |
* Checks if the layer can be added to this group |
21 | 37 |
* |
22 | 38 |
* @param layer |
23 | 39 |
* @return layer can be added or not |
24 | 40 |
*/ |
25 |
public boolean canAdd(FLayer layer); |
|
41 |
public abstract boolean canAdd(FLayer layer);
|
|
26 | 42 |
|
27 | 43 |
/** |
28 |
* Adds the layer to the draw group |
|
44 |
* Adds the layer to the draw group. |
|
45 |
* You have to implements the doAdd(FLayer) method. |
|
46 |
* |
|
47 |
* |
|
29 | 48 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer) |
30 | 49 |
* |
31 | 50 |
* @param layer |
32 | 51 |
* @throws Exception |
33 | 52 |
*/ |
34 |
public void add(FLayer layer) throws Exception; |
|
53 |
public final void add(FLayer layer) throws Exception { |
|
54 |
if (this.mapContext == null){ |
|
55 |
this.mapContext =layer.getMapContext(); |
|
56 |
} |
|
57 |
doAdd(layer); |
|
58 |
pendingLayersEvents.add(layer); |
|
59 |
} |
|
35 | 60 |
|
36 | 61 |
/** |
37 | 62 |
* Draws all the group in one pass |
38 |
* |
|
63 |
* You have to implements the doDraw method.
|
|
39 | 64 |
* |
40 | 65 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double) |
41 | 66 |
*/ |
42 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
43 |
Cancellable cancel,double scale) throws DriverException; |
|
67 |
public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
68 |
Cancellable cancel,double scale) throws DriverException { |
|
69 |
doDraw(image, g, viewPort, cancel, scale); |
|
70 |
fireLayerDrawingEvents(g,viewPort); |
|
71 |
pendingLayersEvents.clear(); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every |
|
76 |
* layers of the group. |
|
77 |
* |
|
78 |
* |
|
79 |
* @see com.iver.cit.gvsig.fmap.layers.LayerDrawEvent |
|
80 |
* |
|
81 |
*/ |
|
82 |
private void fireLayerDrawingEvents(Graphics2D g, ViewPort viewPort) { |
|
83 |
Iterator iter = pendingLayersEvents.iterator(); |
|
84 |
LayerDrawEvent afterEvent; |
|
85 |
FLayer layer = null ; |
|
86 |
while (iter.hasNext()) { |
|
87 |
layer =(FLayer)iter.next(); |
|
88 |
afterEvent = new LayerDrawEvent(layer, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
|
89 |
System.out.println("+++ evento " + afterEvent.getLayer().getName()); |
|
90 |
mapContext.fireLayerDrawingEvent(afterEvent); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
44 | 94 |
|
95 |
/** |
|
96 |
* Adds the layer to the draw group. |
|
97 |
* Specific implementation. |
|
98 |
* |
|
99 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#add(FLayer) |
|
100 |
* |
|
101 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer) |
|
102 |
* |
|
103 |
* @param layer |
|
104 |
* @throws Exception |
|
105 |
*/ |
|
106 |
protected abstract void doAdd(FLayer layer) throws Exception ; |
|
45 | 107 |
|
108 |
/** |
|
109 |
* Draws all the group in one pass. |
|
110 |
* Specific implementation. |
|
111 |
* |
|
112 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double) |
|
113 |
* |
|
114 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double) |
|
115 |
*/ |
|
116 |
protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
117 |
Cancellable cancel,double scale) throws DriverException ; |
|
118 |
|
|
119 |
|
|
46 | 120 |
} |
branches/v10/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/ComposedLayerWMS.java | ||
---|---|---|
24 | 24 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer |
25 | 25 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrWMS |
26 | 26 |
*/ |
27 |
public class ComposedLayerWMS implements ComposedLayer {
|
|
27 |
public class ComposedLayerWMS extends ComposedLayer {
|
|
28 | 28 |
private FLyrWMS layer=null; |
29 | 29 |
|
30 | 30 |
/* (non-Javadoc) |
... | ... | |
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
/* (non-Javadoc) |
41 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#add(com.iver.cit.gvsig.fmap.layers.FLayer)
|
|
41 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#doAdd(com.iver.cit.gvsig.fmap.layers.FLayer)
|
|
42 | 42 |
*/ |
43 |
public void add(FLayer layer) throws Exception {
|
|
43 |
protected void doAdd(FLayer layer) throws Exception {
|
|
44 | 44 |
FLyrWMS aLayer =(FLyrWMS)layer; |
45 | 45 |
if (this.layer == null) { |
46 | 46 |
this.layer = new FLyrWMS(); |
... | ... | |
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
/* (non-Javadoc) |
69 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double) |
|
69 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#doDraw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double)
|
|
70 | 70 |
*/ |
71 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
|
71 |
protected void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
|
72 | 72 |
Cancellable cancel, double scale) throws DriverException { |
73 | 73 |
this.layer.draw(image,g,viewPort,cancel,scale); |
74 | 74 |
} |
Also available in: Unified diff