root / branches / v2_0_0_prep / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / operations / ComposedLayer.java @ 21200
History | View | Annotate | Download (4.4 KB)
1 |
package org.gvsig.fmap.mapcontext.layers.operations; |
---|---|
2 |
|
3 |
import java.awt.Graphics2D; |
4 |
import java.awt.image.BufferedImage; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Iterator; |
7 |
|
8 |
import javax.print.attribute.PrintRequestAttributeSet; |
9 |
|
10 |
import org.gvsig.data.ReadException; |
11 |
import org.gvsig.fmap.mapcontext.MapContext; |
12 |
import org.gvsig.fmap.mapcontext.ViewPort; |
13 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
14 |
import org.gvsig.fmap.mapcontext.layers.LayerDrawEvent; |
15 |
|
16 |
import com.iver.utiles.swing.threads.Cancellable; |
17 |
|
18 |
/**
|
19 |
* Abstract class for the classes that make able
|
20 |
* a single draw for a layers group
|
21 |
*
|
22 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#newComposedLayer()
|
23 |
*/
|
24 |
public abstract class ComposedLayer { |
25 |
|
26 |
ArrayList pendingLayersEvents= new ArrayList(); |
27 |
MapContext mapContext = null;
|
28 |
|
29 |
public ComposedLayer(){
|
30 |
|
31 |
} |
32 |
|
33 |
public void setMapContext(MapContext mapContext) { |
34 |
this.mapContext = mapContext;
|
35 |
} |
36 |
|
37 |
/**
|
38 |
* Checks if the layer can be added to this group
|
39 |
*
|
40 |
* @param layer
|
41 |
* @return layer can be added or not
|
42 |
*/
|
43 |
public abstract boolean canAdd(FLayer layer); |
44 |
|
45 |
/**
|
46 |
* Adds the layer to the draw group.
|
47 |
* You have to implements the doAdd(FLayer) method.
|
48 |
*
|
49 |
*
|
50 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#canAdd(FLayer)
|
51 |
*
|
52 |
* @param layer
|
53 |
* @throws Exception
|
54 |
*/
|
55 |
public final void add(FLayer layer) throws Exception { |
56 |
if (this.mapContext == null){ |
57 |
this.mapContext =layer.getMapContext();
|
58 |
} |
59 |
doAdd(layer); |
60 |
pendingLayersEvents.add(layer); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Draws all the group in one pass
|
65 |
* You have to implements the doDraw method.
|
66 |
*
|
67 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
68 |
*/
|
69 |
public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
70 |
Cancellable cancel,double scale) throws ReadException { |
71 |
doDraw(image, g, viewPort, cancel, scale); |
72 |
fireLayerDrawingEvents(g,viewPort); |
73 |
pendingLayersEvents.clear(); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Prints all the group in one pass
|
78 |
* You have to implements the doDraw method.
|
79 |
*
|
80 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
81 |
*/
|
82 |
public final void print(Graphics2D g, ViewPort viewPort, |
83 |
Cancellable cancel,double scale,PrintRequestAttributeSet properties) throws ReadException { |
84 |
doPrint(g, viewPort, cancel, scale,properties); |
85 |
pendingLayersEvents.clear(); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every
|
90 |
* layers of the group.
|
91 |
*
|
92 |
*
|
93 |
* @see org.gvsig.fmap.mapcontext.layers.LayerDrawEvent
|
94 |
*
|
95 |
*/
|
96 |
private void fireLayerDrawingEvents(Graphics2D g, ViewPort viewPort) { |
97 |
Iterator iter = pendingLayersEvents.iterator();
|
98 |
LayerDrawEvent afterEvent; |
99 |
FLayer layer = null ;
|
100 |
while (iter.hasNext()) {
|
101 |
layer =(FLayer)iter.next(); |
102 |
afterEvent = new LayerDrawEvent(layer, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
|
103 |
System.out.println("+++ evento " + afterEvent.getLayer().getName()); |
104 |
mapContext.fireLayerDrawingEvent(afterEvent); |
105 |
} |
106 |
} |
107 |
|
108 |
|
109 |
/**
|
110 |
* Adds the layer to the draw group.
|
111 |
* Specific implementation.
|
112 |
*
|
113 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#add(FLayer)
|
114 |
*
|
115 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#canAdd(FLayer)
|
116 |
*
|
117 |
* @param layer
|
118 |
* @throws Exception
|
119 |
*/
|
120 |
protected abstract void doAdd(FLayer layer) throws Exception ; |
121 |
|
122 |
/**
|
123 |
* Draws all the group in one pass.
|
124 |
* Specific implementation.
|
125 |
*
|
126 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
127 |
*
|
128 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
129 |
*/
|
130 |
protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
131 |
Cancellable cancel,double scale) throws ReadException ; |
132 |
|
133 |
/**
|
134 |
* Prints all the group in one pass.
|
135 |
* Specific implementation.
|
136 |
*
|
137 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
138 |
*
|
139 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
140 |
*/
|
141 |
protected abstract void doPrint(Graphics2D g, ViewPort viewPort, |
142 |
Cancellable cancel,double scale,PrintRequestAttributeSet properties) throws ReadException ; |
143 |
|
144 |
} |