svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / operations / ComposedLayer.java @ 40559
History | View | Annotate | Download (5.44 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.mapcontext.layers.operations; |
25 |
|
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.image.BufferedImage; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import org.gvsig.compat.print.PrintAttributes; |
32 |
import org.gvsig.fmap.dal.exception.ReadException; |
33 |
import org.gvsig.fmap.mapcontext.MapContext; |
34 |
import org.gvsig.fmap.mapcontext.ViewPort; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
36 |
import org.gvsig.fmap.mapcontext.layers.LayerDrawEvent; |
37 |
import org.gvsig.tools.task.Cancellable; |
38 |
|
39 |
/**
|
40 |
* Abstract class for the classes that make able
|
41 |
* a single draw for a layers group
|
42 |
*
|
43 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#newComposedLayer()
|
44 |
*/
|
45 |
public abstract class ComposedLayer { |
46 |
|
47 |
ArrayList pendingLayersEvents= new ArrayList(); |
48 |
MapContext mapContext = null;
|
49 |
|
50 |
public ComposedLayer(){
|
51 |
|
52 |
} |
53 |
|
54 |
public void setMapContext(MapContext mapContext) { |
55 |
this.mapContext = mapContext;
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* Checks if the layer can be added to this group
|
60 |
*
|
61 |
* @param layer
|
62 |
* @return layer can be added or not
|
63 |
*/
|
64 |
public abstract boolean canAdd(FLayer layer); |
65 |
|
66 |
/**
|
67 |
* Adds the layer to the draw group.
|
68 |
* You have to implements the doAdd(FLayer) method.
|
69 |
*
|
70 |
*
|
71 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#canAdd(FLayer)
|
72 |
*
|
73 |
* @param layer
|
74 |
* @throws Exception
|
75 |
*/
|
76 |
public final void add(FLayer layer) throws Exception { |
77 |
if (this.mapContext == null){ |
78 |
this.mapContext =layer.getMapContext();
|
79 |
} |
80 |
doAdd(layer); |
81 |
pendingLayersEvents.add(layer); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Draws all the group in one pass
|
86 |
* You have to implements the doDraw method.
|
87 |
*
|
88 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
89 |
*/
|
90 |
public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
91 |
Cancellable cancel,double scale) throws ReadException { |
92 |
fireLayerDrawingEvents(g,viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW); |
93 |
doDraw(image, g, viewPort, cancel, scale); |
94 |
fireLayerDrawingEvents(g,viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
95 |
pendingLayersEvents.clear(); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Prints all the group in one pass
|
100 |
* You have to implements the doDraw method.
|
101 |
*
|
102 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
103 |
*/
|
104 |
public final void print(Graphics2D g, ViewPort viewPort, |
105 |
Cancellable cancel,double scale,PrintAttributes properties) throws ReadException { |
106 |
doPrint(g, viewPort, cancel, scale,properties); |
107 |
pendingLayersEvents.clear(); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every
|
112 |
* layers of the group.
|
113 |
*
|
114 |
*
|
115 |
* @see org.gvsig.fmap.mapcontext.layers.LayerDrawEvent
|
116 |
*
|
117 |
*/
|
118 |
private void fireLayerDrawingEvents(Graphics2D g, ViewPort viewPort, int eventType) { |
119 |
Iterator iter = pendingLayersEvents.iterator();
|
120 |
LayerDrawEvent afterEvent; |
121 |
FLayer layer = null ;
|
122 |
while (iter.hasNext()) {
|
123 |
layer =(FLayer)iter.next(); |
124 |
afterEvent = new LayerDrawEvent(layer, g, viewPort, eventType);
|
125 |
// System.out.println("+++ evento " + afterEvent.getLayer().getName());
|
126 |
mapContext.fireLayerDrawingEvent(afterEvent); |
127 |
} |
128 |
} |
129 |
|
130 |
|
131 |
/**
|
132 |
* Adds the layer to the draw group.
|
133 |
* Specific implementation.
|
134 |
*
|
135 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#add(FLayer)
|
136 |
*
|
137 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#canAdd(FLayer)
|
138 |
*
|
139 |
* @param layer
|
140 |
* @throws Exception
|
141 |
*/
|
142 |
protected abstract void doAdd(FLayer layer) throws Exception ; |
143 |
|
144 |
/**
|
145 |
* Draws all the group in one pass.
|
146 |
* Specific implementation.
|
147 |
*
|
148 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
149 |
*
|
150 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
151 |
*/
|
152 |
protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
153 |
Cancellable cancel,double scale) throws ReadException ; |
154 |
|
155 |
/**
|
156 |
* Prints all the group in one pass.
|
157 |
* Specific implementation.
|
158 |
*
|
159 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
160 |
*
|
161 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#print(Graphics2D, ViewPort, Cancellable, double)
|
162 |
*/
|
163 |
protected abstract void doPrint(Graphics2D g, ViewPort viewPort, |
164 |
Cancellable cancel,double scale,PrintAttributes properties) throws ReadException ; |
165 |
|
166 |
} |