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