svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / layerOperations / ComposedLayer.java @ 12271
History | View | Annotate | Download (3.39 KB)
1 |
package com.iver.cit.gvsig.fmap.layers.layerOperations; |
---|---|
2 |
|
3 |
import java.awt.Graphics2D; |
4 |
import java.awt.image.BufferedImage; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Collection; |
7 |
import java.util.Iterator; |
8 |
|
9 |
import com.iver.cit.gvsig.fmap.DriverException; |
10 |
import com.iver.cit.gvsig.fmap.MapContext; |
11 |
import com.iver.cit.gvsig.fmap.ViewPort; |
12 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
13 |
import com.iver.cit.gvsig.fmap.layers.LayerDrawEvent; |
14 |
import com.iver.utiles.swing.threads.Cancellable; |
15 |
|
16 |
/**
|
17 |
* Abstract class for the classes that make able
|
18 |
* a single draw for a layers group
|
19 |
*
|
20 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
|
21 |
*/
|
22 |
public abstract class ComposedLayer { |
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 |
|
35 |
/**
|
36 |
* Checks if the layer can be added to this group
|
37 |
*
|
38 |
* @param layer
|
39 |
* @return layer can be added or not
|
40 |
*/
|
41 |
public abstract boolean canAdd(FLayer layer); |
42 |
|
43 |
/**
|
44 |
* Adds the layer to the draw group.
|
45 |
* You have to implements the doAdd(FLayer) method.
|
46 |
*
|
47 |
*
|
48 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
|
49 |
*
|
50 |
* @param layer
|
51 |
* @throws Exception
|
52 |
*/
|
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 |
} |
60 |
|
61 |
/**
|
62 |
* Draws all the group in one pass
|
63 |
* You have to implements the doDraw method.
|
64 |
*
|
65 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
66 |
*/
|
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 |
|
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 ; |
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 |
|
120 |
} |