svn-gvsig-desktop / tags / v1_1_Build_1008 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / layerOperations / ComposedLayer.java @ 12520
History | View | Annotate | Download (4.3 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 | 12348 | jmvivo | import javax.print.attribute.PrintRequestAttributeSet; |
10 | |||
11 | 11030 | jmvivo | import com.iver.cit.gvsig.fmap.DriverException; |
12 | 11125 | jmvivo | import com.iver.cit.gvsig.fmap.MapContext; |
13 | 10932 | jmvivo | import com.iver.cit.gvsig.fmap.ViewPort; |
14 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
15 | 11125 | jmvivo | import com.iver.cit.gvsig.fmap.layers.LayerDrawEvent; |
16 | 10932 | jmvivo | import com.iver.utiles.swing.threads.Cancellable; |
17 | |||
18 | /**
|
||
19 | 12348 | jmvivo | * Abstract class for the classes that make able
|
20 | 10932 | jmvivo | * a single draw for a layers group
|
21 | 12348 | jmvivo | *
|
22 | 10932 | jmvivo | * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
|
23 | */
|
||
24 | 11125 | jmvivo | public abstract class ComposedLayer { |
25 | 10932 | jmvivo | |
26 | 12348 | jmvivo | ArrayList pendingLayersEvents= new ArrayList(); |
27 | MapContext mapContext = null;
|
||
28 | |||
29 | 11125 | jmvivo | public ComposedLayer(){
|
30 | 12348 | jmvivo | |
31 | 11125 | jmvivo | } |
32 | |||
33 | public void setMapContext(MapContext mapContext) { |
||
34 | this.mapContext = mapContext;
|
||
35 | } |
||
36 | 12348 | jmvivo | |
37 | 10932 | jmvivo | /**
|
38 | * Checks if the layer can be added to this group
|
||
39 | 12348 | jmvivo | *
|
40 | 10932 | jmvivo | * @param layer
|
41 | * @return layer can be added or not
|
||
42 | */
|
||
43 | 11125 | jmvivo | public abstract boolean canAdd(FLayer layer); |
44 | 12348 | jmvivo | |
45 | 10932 | jmvivo | /**
|
46 | 12348 | jmvivo | * Adds the layer to the draw group.
|
47 | 11125 | jmvivo | * You have to implements the doAdd(FLayer) method.
|
48 | 12348 | jmvivo | *
|
49 | *
|
||
50 | 10932 | jmvivo | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
|
51 | 12348 | jmvivo | *
|
52 | 10932 | jmvivo | * @param layer
|
53 | 12348 | jmvivo | * @throws Exception
|
54 | 10932 | jmvivo | */
|
55 | 11125 | jmvivo | public final void add(FLayer layer) throws Exception { |
56 | if (this.mapContext == null){ |
||
57 | this.mapContext =layer.getMapContext();
|
||
58 | } |
||
59 | doAdd(layer); |
||
60 | 12348 | jmvivo | pendingLayersEvents.add(layer); |
61 | 11125 | jmvivo | } |
62 | 12348 | jmvivo | |
63 | 10932 | jmvivo | /**
|
64 | * Draws all the group in one pass
|
||
65 | 12348 | jmvivo | * You have to implements the doDraw method.
|
66 | 10932 | jmvivo | *
|
67 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
||
68 | */
|
||
69 | 11125 | jmvivo | public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
70 | Cancellable cancel,double scale) throws DriverException { |
||
71 | doDraw(image, g, viewPort, cancel, scale); |
||
72 | fireLayerDrawingEvents(g,viewPort); |
||
73 | 12348 | jmvivo | pendingLayersEvents.clear(); |
74 | 11125 | jmvivo | } |
75 | 12348 | jmvivo | |
76 | 11125 | jmvivo | /**
|
77 | 12348 | jmvivo | * Prints all the group in one pass
|
78 | * You have to implements the doDraw method.
|
||
79 | *
|
||
80 | * @see com.iver.cit.gvsig.fmap.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 DriverException { |
||
84 | doPrint(g, viewPort, cancel, scale,properties); |
||
85 | pendingLayersEvents.clear(); |
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | 11125 | jmvivo | * Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every
|
90 | * layers of the group.
|
||
91 | 12348 | jmvivo | *
|
92 | *
|
||
93 | 11125 | jmvivo | * @see com.iver.cit.gvsig.fmap.layers.LayerDrawEvent
|
94 | 12348 | jmvivo | *
|
95 | 11125 | jmvivo | */
|
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 | 10932 | jmvivo | |
108 | 12348 | jmvivo | |
109 | |||
110 | 11125 | jmvivo | /**
|
111 | * Adds the layer to the draw group.
|
||
112 | 12348 | jmvivo | * Specific implementation.
|
113 | *
|
||
114 | 11125 | jmvivo | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#add(FLayer)
|
115 | 12348 | jmvivo | *
|
116 | 11125 | jmvivo | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
|
117 | 12348 | jmvivo | *
|
118 | 11125 | jmvivo | * @param layer
|
119 | 12348 | jmvivo | * @throws Exception
|
120 | 11125 | jmvivo | */
|
121 | protected abstract void doAdd(FLayer layer) throws Exception ; |
||
122 | 12348 | jmvivo | |
123 | 11125 | jmvivo | /**
|
124 | * Draws all the group in one pass.
|
||
125 | 12348 | jmvivo | * Specific implementation.
|
126 | 11125 | jmvivo | *
|
127 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
||
128 | *
|
||
129 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
||
130 | 12348 | jmvivo | */
|
131 | 11125 | jmvivo | protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
132 | Cancellable cancel,double scale) throws DriverException ; |
||
133 | 12348 | jmvivo | |
134 | /**
|
||
135 | * Prints all the group in one pass.
|
||
136 | * Specific implementation.
|
||
137 | *
|
||
138 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
||
139 | *
|
||
140 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
||
141 | */
|
||
142 | protected abstract void doPrint(Graphics2D g, ViewPort viewPort, |
||
143 | Cancellable cancel,double scale,PrintRequestAttributeSet properties) throws DriverException ; |
||
144 | |||
145 | |||
146 | 10932 | jmvivo | } |