Revision 38200 branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/impl/DefaultMapContextDrawer.java
DefaultMapContextDrawer.java | ||
---|---|---|
21 | 21 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelable; |
22 | 22 |
import org.gvsig.tools.task.Cancellable; |
23 | 23 |
|
24 |
|
|
25 |
|
|
26 | 24 |
public class DefaultMapContextDrawer implements MapContextDrawer { |
27 |
private MapContext mapContext=null;
|
|
28 |
private ViewPort viewPort=null;
|
|
29 |
private CachedImage cachedImage=null;
|
|
25 |
private MapContext mapContext = null;
|
|
26 |
private ViewPort viewPort = null;
|
|
27 |
private CachedImage cachedImage = null;
|
|
30 | 28 |
private DrawList previousDrawList = null; |
31 | 29 |
|
32 |
public DefaultMapContextDrawer(){ |
|
30 |
public DefaultMapContextDrawer() {
|
|
33 | 31 |
|
34 | 32 |
} |
35 | 33 |
|
36 |
protected void checkIntilalized(){ |
|
37 |
if (mapContext == null || viewPort == null){ |
|
38 |
throw new IllegalStateException("MapContext and ViewPort must be set"); |
|
34 |
protected void checkIntilalized() { |
|
35 |
if (mapContext == null || viewPort == null) { |
|
36 |
throw new IllegalStateException( |
|
37 |
"MapContext and ViewPort must be set"); |
|
39 | 38 |
} |
40 | 39 |
} |
41 | 40 |
|
42 |
protected boolean isLayerCacheable(FLayer layer){ |
|
41 |
protected boolean isLayerCacheable(FLayer layer) {
|
|
43 | 42 |
return layer.isActive(); |
44 | 43 |
} |
45 | 44 |
|
46 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel,
|
|
47 |
double scale) throws ReadException { |
|
45 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, |
|
46 |
Cancellable cancel, double scale) throws ReadException {
|
|
48 | 47 |
|
49 | 48 |
this.checkIntilalized(); |
50 | 49 |
|
51 | 50 |
boolean needToPaintAll = false; |
52 | 51 |
|
53 |
DrawList drawList = this.createDrawList(root, cancel,scale); |
|
54 |
if (cancel.isCanceled()){ |
|
52 |
DrawList drawList = this.createDrawList(root, cancel, scale);
|
|
53 |
if (cancel.isCanceled()) {
|
|
55 | 54 |
return; |
56 | 55 |
} |
57 | 56 |
|
58 |
if (cachedImage == null){ |
|
59 |
needToPaintAll=true; |
|
60 |
} else if (!cachedImage.isValid(mapContext, viewPort, drawList.getFirstLayerToDraw())){ |
|
61 |
needToPaintAll=true; |
|
57 |
if (cachedImage == null) { |
|
58 |
needToPaintAll = true; |
|
59 |
} else if (!cachedImage.isValid(mapContext, viewPort, |
|
60 |
drawList.getFirstLayerToDraw())) { |
|
61 |
needToPaintAll = true; |
|
62 | 62 |
} |
63 | 63 |
|
64 |
|
|
65 |
int firstLayer= 0;
|
|
66 |
if (!needToPaintAll){
|
|
67 |
firstLayer = cachedImage.getListPosition()+1;
|
|
68 |
// System.out.println("=======Pintando a partir de la pos "+ firstLayer+"============");
|
|
64 |
int firstLayer = 0; |
|
65 |
if (!needToPaintAll) {
|
|
66 |
firstLayer = cachedImage.getListPosition() + 1;
|
|
67 |
// System.out.println("=======Pintando a partir de la pos "+
|
|
68 |
// firstLayer+"============");
|
|
69 | 69 |
g.drawImage(cachedImage.getImage(), 0, 0, null); |
70 |
// System.out.println("=======Pintando imagen ============");
|
|
70 |
// System.out.println("=======Pintando imagen ============");
|
|
71 | 71 |
|
72 |
} else{ |
|
72 |
} else {
|
|
73 | 73 |
this.cachedImage = null; |
74 |
// System.out.println("=======Pintando todo============");
|
|
74 |
// System.out.println("=======Pintando todo============");
|
|
75 | 75 |
} |
76 | 76 |
|
77 |
|
|
78 |
boolean cached=false; |
|
77 |
boolean cached = false; |
|
79 | 78 |
ComposedLayer composed = null; |
80 | 79 |
int pos; |
81 |
int layerPos= -1; |
|
80 |
int layerPos = -1;
|
|
82 | 81 |
FLayer layer; |
83 | 82 |
Object obj; |
84 | 83 |
LayersGroupEvent event; |
85 |
for (pos=0; pos < drawList.size(); pos++){
|
|
86 |
if (cancel.isCanceled()){ |
|
84 |
for (pos = 0; pos < drawList.size(); pos++) {
|
|
85 |
if (cancel.isCanceled()) {
|
|
87 | 86 |
return; |
88 | 87 |
} |
89 | 88 |
|
90 | 89 |
obj = drawList.get(pos); |
91 | 90 |
|
92 | 91 |
// *** Gestion de eventos de pintado de grupos *** |
93 |
if (obj instanceof LayersGroupEvent){ |
|
92 |
if (obj instanceof LayersGroupEvent) {
|
|
94 | 93 |
event = (LayersGroupEvent) obj; |
95 |
if (event.type == LayersGroupEvent.IN_Event){ |
|
96 |
// System.out.println("=======Empiza a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
94 |
if (event.type == LayersGroupEvent.IN_Event) { |
|
95 |
// System.out.println("=======Empiza a pintar grupo de capas "+ |
|
96 |
// ((FLayers)event.group).getName() +"============"); |
|
97 | 97 |
event.group.beginDraw(g, viewPort); |
98 |
} else{ |
|
98 |
} else {
|
|
99 | 99 |
event.group.endDraw(g, viewPort); |
100 |
// System.out.println("=======Fin a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
100 |
// System.out.println("=======Fin a pintar grupo de capas "+ |
|
101 |
// ((FLayers)event.group).getName() +"============"); |
|
101 | 102 |
|
102 | 103 |
} |
103 | 104 |
continue; |
104 | 105 |
} |
105 | 106 |
layerPos++; |
106 |
if (layerPos < firstLayer){ |
|
107 |
if (layerPos < firstLayer) {
|
|
107 | 108 |
continue; |
108 | 109 |
} |
109 | 110 |
|
110 | 111 |
layer = (FLayer) obj; |
111 |
if (cancel.isCanceled()){ |
|
112 |
if (cancel.isCanceled()) {
|
|
112 | 113 |
return; |
113 | 114 |
} |
114 | 115 |
|
115 | 116 |
// *** Gestion de cache *** |
116 |
if ((!cached) && this.isLayerCacheable(layer)){ |
|
117 |
if (layerPos > 0){ //La primera capa es la activa, no cacheamos |
|
118 |
if (cachedImage==null || cachedImage.getListPosition() < layerPos-1){ |
|
117 |
if ((!cached) && this.isLayerCacheable(layer)) { |
|
118 |
if (layerPos > 0) { // La primera capa es la activa, no |
|
119 |
// cacheamos |
|
120 |
if (cachedImage == null |
|
121 |
|| cachedImage.getListPosition() < layerPos - 1) { |
|
119 | 122 |
|
120 |
if (composed != null){ |
|
121 |
//si tenemos una composicion de capas, necesitamos pintarlas |
|
122 |
//antes de guardarnos la imagen |
|
123 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (antes de cache)============"); |
|
123 |
if (composed != null) { |
|
124 |
// si tenemos una composicion de capas, necesitamos |
|
125 |
// pintarlas |
|
126 |
// antes de guardarnos la imagen |
|
127 |
// System.out.println("=======Pintando composicion de pintado "+ |
|
128 |
// (layerPos-1)+" (antes de cache)============"); |
|
124 | 129 |
this.draw(composed, image, g, cancel, scale); |
125 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
130 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
126 | 131 |
composed = null; |
127 | 132 |
|
128 | 133 |
} |
129 |
CachedImage newCached = new CachedImage(); |
|
130 |
newCached.setImage(image, mapContext, viewPort, layerPos-1); |
|
134 |
CachedImage newCached = new CachedImage(); |
|
135 |
newCached.setImage(image, mapContext, viewPort, |
|
136 |
layerPos - 1); |
|
131 | 137 |
this.cachedImage = newCached; |
132 |
// System.out.println("=======Guardando imagen de la pos "+ (layerPos-1)+" ("+ newCached.getListPosition() +")============"); |
|
138 |
// System.out.println("=======Guardando imagen de la pos "+ |
|
139 |
// (layerPos-1)+" ("+ newCached.getListPosition() |
|
140 |
// +")============"); |
|
133 | 141 |
} |
134 | 142 |
} |
135 | 143 |
cached = true; |
136 | 144 |
} |
137 |
if (cancel.isCanceled()){ |
|
145 |
if (cancel.isCanceled()) {
|
|
138 | 146 |
return; |
139 | 147 |
} |
140 | 148 |
|
141 |
if (composed == null){ |
|
149 |
if (composed == null) {
|
|
142 | 150 |
composed = layer.newComposedLayer(); |
143 |
if (composed != null){ |
|
151 |
if (composed != null) {
|
|
144 | 152 |
try { |
145 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
153 |
// System.out.println("=== a?adiendo a composicion de pintado "+ |
|
154 |
// layerPos+ " "+layer.getName()); |
|
146 | 155 |
composed.add(layer); |
147 | 156 |
continue; |
148 | 157 |
} catch (Exception e) { |
149 |
throw new ReadException("DefalutMapContexDrawer exception",e); |
|
158 |
throw new ReadException( |
|
159 |
"DefalutMapContexDrawer exception", e); |
|
150 | 160 |
} |
151 | 161 |
} |
152 |
}else{
|
|
153 |
if (composed.canAdd(layer)){ |
|
162 |
} else {
|
|
163 |
if (composed.canAdd(layer)) {
|
|
154 | 164 |
try { |
155 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
165 |
// System.out.println("=== a?adiendo a composicion de pintado "+ |
|
166 |
// layerPos+ " "+layer.getName()); |
|
156 | 167 |
composed.add(layer); |
157 | 168 |
continue; |
158 | 169 |
} catch (Exception e) { |
159 |
throw new ReadException("DefalutMapContexDrawer exception",e); |
|
170 |
throw new ReadException( |
|
171 |
"DefalutMapContexDrawer exception", e); |
|
160 | 172 |
} |
161 | 173 |
} else { |
162 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (cambio composicion)============"); |
|
174 |
// System.out.println("=======Pintando composicion de pintado "+ |
|
175 |
// (layerPos-1)+" (cambio composicion)============"); |
|
163 | 176 |
this.draw(composed, image, g, cancel, scale); |
164 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
177 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
165 | 178 |
composed = layer.newComposedLayer(); |
166 |
if (composed != null){ |
|
179 |
if (composed != null) {
|
|
167 | 180 |
try { |
168 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
181 |
// System.out.println("=== a?adiendo a composicion de pintado "+ |
|
182 |
// layerPos+ " "+layer.getName()); |
|
169 | 183 |
composed.add(layer); |
170 | 184 |
continue; |
171 | 185 |
} catch (Exception e) { |
172 |
throw new ReadException("DefalutMapContexDrawer exception",e); |
|
173 |
} } |
|
186 |
throw new ReadException( |
|
187 |
"DefalutMapContexDrawer exception", e); |
|
188 |
} |
|
189 |
} |
|
174 | 190 |
} |
175 | 191 |
} |
176 |
// System.out.println("=== pintando "+ layerPos+ " "+layer.getName()); |
|
192 |
// System.out.println("=== pintando "+ layerPos+ |
|
193 |
// " "+layer.getName()); |
|
177 | 194 |
this.draw(layer, image, g, cancel, scale); |
178 |
// layer.draw(image, g, viewPort, cancel, scale);
|
|
195 |
// layer.draw(image, g, viewPort, cancel, scale);
|
|
179 | 196 |
|
180 | 197 |
} |
181 |
if (composed != null){ |
|
198 |
if (composed != null) {
|
|
182 | 199 |
// si la composicion no se ha pintado la pintamos |
183 |
// System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (ultimo)============"); |
|
200 |
// System.out.println("=======Pintando composicion de pintado "+ |
|
201 |
// (layerPos-1)+" (ultimo)============"); |
|
184 | 202 |
this.draw(composed, image, g, cancel, scale); |
185 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
203 |
// composed.draw(image, g, viewPort, cancel, scale);
|
|
186 | 204 |
} |
187 |
if (cancel.isCanceled()){ |
|
205 |
if (cancel.isCanceled()) {
|
|
188 | 206 |
return; |
189 | 207 |
} |
190 | 208 |
|
... | ... | |
192 | 210 |
|
193 | 211 |
} |
194 | 212 |
|
195 |
private void draw(Object layerOrComposed,BufferedImage image, Graphics2D g, Cancellable cancel, |
|
196 |
double scale) throws ReadException{ |
|
197 |
ILabelable labelable= null; |
|
198 |
ILabelable tmp= null; |
|
199 |
if (layerOrComposed instanceof ILabelable){ |
|
213 |
private void draw(Object layerOrComposed, BufferedImage image, |
|
214 |
Graphics2D g, Cancellable cancel, double scale) |
|
215 |
throws ReadException { |
|
216 |
ILabelable labelable = null; |
|
217 |
ILabelable tmp = null; |
|
218 |
if (layerOrComposed instanceof ILabelable) { |
|
200 | 219 |
|
201 |
tmp =(ILabelable) layerOrComposed; |
|
220 |
tmp = (ILabelable) layerOrComposed;
|
|
202 | 221 |
|
203 |
if (tmp.isLabeled() |
|
204 |
&& tmp.getLabelingStrategy() != null |
|
205 |
&& tmp.getLabelingStrategy().shouldDrawLabels(scale)) { |
|
206 |
labelable =tmp; |
|
222 |
if (tmp.isLabeled() && tmp.getLabelingStrategy() != null |
|
223 |
&& tmp.getLabelingStrategy().shouldDrawLabels(scale)) { |
|
224 |
labelable = tmp; |
|
207 | 225 |
} |
208 | 226 |
} |
209 |
if (layerOrComposed instanceof FLayer){ |
|
227 |
if (layerOrComposed instanceof FLayer) {
|
|
210 | 228 |
FLayer layer = (FLayer) layerOrComposed; |
211 | 229 |
layer.draw(image, g, viewPort, cancel, scale); |
212 |
} else{ |
|
230 |
} else {
|
|
213 | 231 |
ComposedLayer composed = (ComposedLayer) layerOrComposed; |
214 | 232 |
composed.draw(image, g, viewPort, cancel, scale); |
215 | 233 |
} |
216 |
if (labelable != null){ |
|
217 |
labelable.drawLabels(image, g, viewPort, cancel, scale, MapContext.getScreenDPI()); |
|
234 |
if (labelable != null) { |
|
235 |
labelable.drawLabels(image, g, viewPort, cancel, scale, |
|
236 |
MapContext.getScreenDPI()); |
|
218 | 237 |
} |
219 | 238 |
|
220 | 239 |
} |
221 | 240 |
|
222 |
private void print(Object layerOrComposed,Graphics2D g, Cancellable cancel, |
|
223 |
double scale, PrintAttributes properties) throws ReadException{ |
|
224 |
ILabelable labelable= null; |
|
225 |
ILabelable tmp= null; |
|
226 |
if (layerOrComposed instanceof ILabelable){ |
|
241 |
private void print(Object layerOrComposed, Graphics2D g, |
|
242 |
Cancellable cancel, double scale, PrintAttributes properties) |
|
243 |
throws ReadException { |
|
244 |
ILabelable labelable = null; |
|
245 |
ILabelable tmp = null; |
|
246 |
if (layerOrComposed instanceof ILabelable) { |
|
227 | 247 |
|
228 |
tmp =(ILabelable) layerOrComposed; |
|
248 |
tmp = (ILabelable) layerOrComposed;
|
|
229 | 249 |
|
230 |
if (tmp.isLabeled() |
|
231 |
&& tmp.getLabelingStrategy() != null |
|
232 |
&& tmp.getLabelingStrategy().shouldDrawLabels(scale)) { |
|
233 |
labelable =tmp; |
|
250 |
if (tmp.isLabeled() && tmp.getLabelingStrategy() != null |
|
251 |
&& tmp.getLabelingStrategy().shouldDrawLabels(scale)) { |
|
252 |
labelable = tmp; |
|
234 | 253 |
} |
235 | 254 |
} |
236 | 255 |
|
237 |
if (layerOrComposed instanceof FLayer){ |
|
256 |
if (layerOrComposed instanceof FLayer) {
|
|
238 | 257 |
FLayer layer = (FLayer) layerOrComposed; |
239 | 258 |
layer.print(g, viewPort, cancel, scale, properties); |
240 |
} else{ |
|
259 |
} else {
|
|
241 | 260 |
ComposedLayer composed = (ComposedLayer) layerOrComposed; |
242 | 261 |
composed.print(g, viewPort, cancel, scale, properties); |
243 | 262 |
} |
244 |
if (labelable != null){ |
|
263 |
if (labelable != null) {
|
|
245 | 264 |
labelable.printLabels(g, viewPort, cancel, scale, properties); |
246 | 265 |
} |
247 | 266 |
|
248 | 267 |
} |
249 | 268 |
|
250 | 269 |
public void setMapContext(MapContext mapContext) { |
251 |
if (this.mapContext == mapContext){ |
|
270 |
if (this.mapContext == mapContext) {
|
|
252 | 271 |
return; |
253 | 272 |
} |
254 | 273 |
this.clean(); |
... | ... | |
257 | 276 |
} |
258 | 277 |
|
259 | 278 |
public void setViewPort(ViewPort viewPort) { |
260 |
if (this.viewPort == viewPort){ |
|
279 |
if (this.viewPort == viewPort) {
|
|
261 | 280 |
return; |
262 | 281 |
} |
263 | 282 |
this.clean(); |
... | ... | |
265 | 284 |
|
266 | 285 |
} |
267 | 286 |
|
268 |
protected void clean(){ |
|
287 |
protected void clean() {
|
|
269 | 288 |
this.cachedImage = null; |
270 | 289 |
} |
271 | 290 |
|
272 |
public class CachedImage{ |
|
291 |
public class CachedImage {
|
|
273 | 292 |
private BufferedImage image; |
274 | 293 |
private long mapContextVersion; |
275 | 294 |
private long viewPortVersion; |
276 | 295 |
private int listPosition; |
277 | 296 |
|
278 |
public void setImage(BufferedImage img,MapContext mapContext, ViewPort viewPort,int pos) { |
|
297 |
public void setImage(BufferedImage img, MapContext mapContext, |
|
298 |
ViewPort viewPort, int pos) { |
|
279 | 299 |
|
280 | 300 |
image = CompatLocator.getGraphicsUtils().copyBufferedImage(img); |
281 | 301 |
this.mapContextVersion = mapContext.getDrawVersion(); |
... | ... | |
295 | 315 |
return viewPortVersion; |
296 | 316 |
} |
297 | 317 |
|
298 |
public int getListPosition(){ |
|
318 |
public int getListPosition() {
|
|
299 | 319 |
return this.listPosition; |
300 | 320 |
} |
301 | 321 |
|
302 |
public boolean isValid(MapContext context,ViewPort viewPort,int firstLayerToDraw){ |
|
303 |
if (viewPort.getDrawVersion() > this.viewPortVersion){ |
|
322 |
public boolean isValid(MapContext context, ViewPort viewPort, |
|
323 |
int firstLayerToDraw) { |
|
324 |
if (viewPort.getDrawVersion() > this.viewPortVersion) { |
|
304 | 325 |
return false; |
305 | 326 |
} |
306 |
if (firstLayerToDraw <= this.listPosition){ |
|
327 |
if (firstLayerToDraw <= this.listPosition) {
|
|
307 | 328 |
return false; |
308 | 329 |
} |
309 | 330 |
return true; |
310 | 331 |
} |
311 | 332 |
} |
312 | 333 |
|
313 |
public class DrawList{ |
|
334 |
public class DrawList {
|
|
314 | 335 |
private List layers = new ArrayList(); |
315 | 336 |
private List all = new ArrayList(); |
316 | 337 |
private List versions = new ArrayList(); |
317 | 338 |
private DrawList previosList = null; |
318 |
private int firstLayerToDraw =-1; |
|
339 |
private int firstLayerToDraw = -1;
|
|
319 | 340 |
|
320 |
public DrawList(){ |
|
341 |
public DrawList() {
|
|
321 | 342 |
} |
322 | 343 |
|
323 |
public DrawList(DrawList previousList){ |
|
324 |
if (previousList != null){ |
|
325 |
this.firstLayerToDraw =previousList.getLayerCount(); |
|
326 |
this.previosList=previousList;
|
|
344 |
public DrawList(DrawList previousList) {
|
|
345 |
if (previousList != null) {
|
|
346 |
this.firstLayerToDraw = previousList.getLayerCount();
|
|
347 |
this.previosList = previousList;
|
|
327 | 348 |
} |
328 | 349 |
} |
329 | 350 |
|
330 |
public int getLayerCount(){ |
|
351 |
public int getLayerCount() {
|
|
331 | 352 |
return this.layers.size(); |
332 | 353 |
} |
333 | 354 |
|
334 |
private boolean hasChanged(FLayer layer, int pos){ |
|
335 |
FLayer previous =(FLayer) this.previosList.layers.get(pos); |
|
336 |
// String previousName = previous.getName();
|
|
337 |
// String layerName = layer.getName();
|
|
338 |
if (previous != layer){ |
|
355 |
private boolean hasChanged(FLayer layer, int pos) {
|
|
356 |
FLayer previous = (FLayer) this.previosList.layers.get(pos);
|
|
357 |
// String previousName = previous.getName();
|
|
358 |
// String layerName = layer.getName();
|
|
359 |
if (previous != layer) {
|
|
339 | 360 |
return true; |
340 | 361 |
} |
341 |
long previousVersion = ((Long) this.previosList.versions.get(pos)).longValue(); |
|
362 |
long previousVersion = ((Long) this.previosList.versions.get(pos)) |
|
363 |
.longValue(); |
|
342 | 364 |
long layerVersion = layer.getDrawVersion(); |
343 | 365 |
|
344 | 366 |
return previousVersion != layerVersion; |
345 | 367 |
} |
346 | 368 |
|
347 |
public void add(Object obj){ |
|
348 |
if (obj instanceof FLayer){ |
|
369 |
public void add(Object obj) {
|
|
370 |
if (obj instanceof FLayer) {
|
|
349 | 371 |
FLayer layer = (FLayer) obj; |
350 | 372 |
int curIndex = this.layers.size(); |
351 |
if (this.firstLayerToDraw >= curIndex){ |
|
352 |
if (this.previosList.getLayerCount() > curIndex){ |
|
353 |
if (this.hasChanged(layer, curIndex)){ |
|
373 |
if (this.firstLayerToDraw >= curIndex) {
|
|
374 |
if (this.previosList.getLayerCount() > curIndex) {
|
|
375 |
if (this.hasChanged(layer, curIndex)) {
|
|
354 | 376 |
this.firstLayerToDraw = curIndex; |
355 | 377 |
} |
356 |
} else if (this.previosList.getLayerCount() == curIndex){ |
|
378 |
} else if (this.previosList.getLayerCount() == curIndex) {
|
|
357 | 379 |
this.firstLayerToDraw = curIndex; |
358 | 380 |
} |
359 | 381 |
} |
360 | 382 |
this.layers.add(layer); |
361 | 383 |
this.versions.add(new Long(layer.getDrawVersion())); |
362 |
} else if (!(obj instanceof LayersGroupEvent)){ |
|
384 |
} else if (!(obj instanceof LayersGroupEvent)) {
|
|
363 | 385 |
throw new UnsupportedOperationException(); |
364 | 386 |
} |
365 | 387 |
|
366 | 388 |
this.all.add(obj); |
367 | 389 |
} |
368 | 390 |
|
369 |
public int size(){ |
|
391 |
public int size() {
|
|
370 | 392 |
return this.all.size(); |
371 | 393 |
} |
372 | 394 |
|
373 |
public int getFirstLayerToDraw(){ |
|
374 |
if (this.firstLayerToDraw > this.layers.size()){ |
|
395 |
public int getFirstLayerToDraw() {
|
|
396 |
if (this.firstLayerToDraw > this.layers.size()) {
|
|
375 | 397 |
this.firstLayerToDraw = this.layers.size(); |
376 | 398 |
} |
377 | 399 |
return this.firstLayerToDraw; |
378 | 400 |
} |
379 | 401 |
|
380 |
public FLayer getLayer(int pos){ |
|
402 |
public FLayer getLayer(int pos) {
|
|
381 | 403 |
return (FLayer) this.layers.get(pos); |
382 | 404 |
} |
383 | 405 |
|
384 |
public Object get(int pos){ |
|
406 |
public Object get(int pos) {
|
|
385 | 407 |
return this.all.get(pos); |
386 | 408 |
} |
387 | 409 |
|
388 | 410 |
} |
389 | 411 |
|
390 |
private class SimpleLayerIterator extends LayersIterator{ |
|
412 |
private class SimpleLayerIterator extends LayersIterator {
|
|
391 | 413 |
|
392 | 414 |
public SimpleLayerIterator(FLayer layer) { |
393 | 415 |
this.appendLayer(layer); |
... | ... | |
403 | 425 |
} |
404 | 426 |
|
405 | 427 |
public void dispose() { |
406 |
this.mapContext=null;
|
|
407 |
this.viewPort=null;
|
|
408 |
this.cachedImage=null;
|
|
428 |
this.mapContext = null;
|
|
429 |
this.viewPort = null;
|
|
430 |
this.cachedImage = null;
|
|
409 | 431 |
this.previousDrawList = null; |
410 | 432 |
} |
411 | 433 |
|
412 |
|
|
413 | 434 |
public void print(FLayers root, Graphics2D g, Cancellable cancel, |
414 |
double scale, PrintAttributes properties) |
|
415 |
throws ReadException { |
|
435 |
double scale, PrintAttributes properties) throws ReadException { |
|
416 | 436 |
this.checkIntilalized(); |
417 | 437 |
|
418 | 438 |
List printList = this.createPrintList(root, cancel); |
419 |
if (cancel.isCanceled()){ |
|
439 |
if (cancel.isCanceled()) {
|
|
420 | 440 |
return; |
421 | 441 |
} |
422 | 442 |
|
423 |
|
|
424 | 443 |
ComposedLayer composed = null; |
425 | 444 |
int pos; |
426 | 445 |
FLayer layer; |
427 |
int layerPos= -1; |
|
446 |
int layerPos = -1;
|
|
428 | 447 |
Object obj; |
429 | 448 |
LayersGroupEvent event; |
430 |
for (pos=0; pos < printList.size(); pos++){
|
|
431 |
if (cancel.isCanceled()){ |
|
449 |
for (pos = 0; pos < printList.size(); pos++) {
|
|
450 |
if (cancel.isCanceled()) {
|
|
432 | 451 |
return; |
433 | 452 |
} |
434 | 453 |
|
435 | 454 |
obj = printList.get(pos); |
436 |
if (obj instanceof LayersGroupEvent){ |
|
455 |
if (obj instanceof LayersGroupEvent) {
|
|
437 | 456 |
event = (LayersGroupEvent) obj; |
438 |
if (event.type == LayersGroupEvent.IN_Event){ |
|
439 |
// System.out.println("=======Empiza a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
457 |
if (event.type == LayersGroupEvent.IN_Event) { |
|
458 |
// System.out.println("=======Empiza a pintar grupo de capas "+ |
|
459 |
// ((FLayers)event.group).getName() +"============"); |
|
440 | 460 |
event.group.beginDraw(g, viewPort); |
441 |
} else{ |
|
461 |
} else {
|
|
442 | 462 |
event.group.endDraw(g, viewPort); |
443 |
// System.out.println("=======Fin a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============"); |
|
463 |
// System.out.println("=======Fin a pintar grupo de capas "+ |
|
464 |
// ((FLayers)event.group).getName() +"============"); |
|
444 | 465 |
|
445 | 466 |
} |
446 | 467 |
continue; |
... | ... | |
449 | 470 |
|
450 | 471 |
layer = (FLayer) obj; |
451 | 472 |
|
452 |
|
|
453 | 473 |
// *** Pintado de capa/composicion de capa *** |
454 |
if (composed == null){ |
|
474 |
if (composed == null) {
|
|
455 | 475 |
composed = layer.newComposedLayer(); |
456 |
if (composed != null){ |
|
476 |
if (composed != null) {
|
|
457 | 477 |
try { |
458 | 478 |
composed.add(layer); |
459 |
// System.out.println("=======Imprimiendo composicion de pintado "+ (layerPos-1)+" ============"); |
|
479 |
// System.out.println("=======Imprimiendo composicion de pintado "+ |
|
480 |
// (layerPos-1)+" ============"); |
|
460 | 481 |
continue; |
461 | 482 |
} catch (Exception e) { |
462 |
throw new ReadException("DefaultMapContexDrawer exception",e); |
|
483 |
throw new ReadException( |
|
484 |
"DefaultMapContexDrawer exception", e); |
|
463 | 485 |
} |
464 | 486 |
} |
465 |
}else{
|
|
466 |
if (composed.canAdd(layer)){ |
|
487 |
} else {
|
|
488 |
if (composed.canAdd(layer)) {
|
|
467 | 489 |
try { |
468 | 490 |
composed.add(layer); |
469 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
491 |
// System.out.println("=== a?adiendo a composicion de pintado "+ |
|
492 |
// layerPos+ " "+layer.getName()); |
|
470 | 493 |
continue; |
471 | 494 |
} catch (Exception e) { |
472 |
throw new ReadException("DefaultMapContexDrawer exception",e); |
|
495 |
throw new ReadException( |
|
496 |
"DefaultMapContexDrawer exception", e); |
|
473 | 497 |
} |
474 | 498 |
} else { |
475 |
// System.out.println("=======Imprimiendo composicion de pintado "+ (layerPos-1)+" ============"); |
|
499 |
// System.out.println("=======Imprimiendo composicion de pintado "+ |
|
500 |
// (layerPos-1)+" ============"); |
|
476 | 501 |
this.print(composed, g, cancel, scale, properties); |
477 |
// composed.print( g, viewPort, cancel, scale,properties);
|
|
502 |
// composed.print( g, viewPort, cancel, scale,properties);
|
|
478 | 503 |
composed = layer.newComposedLayer(); |
479 |
if (composed != null){ |
|
504 |
if (composed != null) {
|
|
480 | 505 |
try { |
481 | 506 |
composed.add(layer); |
482 |
// System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName()); |
|
507 |
// System.out.println("=== a?adiendo a composicion de pintado "+ |
|
508 |
// layerPos+ " "+layer.getName()); |
|
483 | 509 |
continue; |
484 | 510 |
} catch (Exception e) { |
485 |
throw new ReadException("DefaultMapContexDrawer exception",e); |
|
511 |
throw new ReadException( |
|
512 |
"DefaultMapContexDrawer exception", e); |
|
486 | 513 |
} |
487 | 514 |
} |
488 | 515 |
} |
489 | 516 |
} |
490 |
// System.out.println("=== imprimiendo "+ layerPos+ " "+layer.getName()); |
|
517 |
// System.out.println("=== imprimiendo "+ layerPos+ |
|
518 |
// " "+layer.getName()); |
|
491 | 519 |
this.print(layer, g, cancel, scale, properties); |
492 |
// layer.print(g, viewPort, cancel, scale,properties);
|
|
520 |
// layer.print(g, viewPort, cancel, scale,properties);
|
|
493 | 521 |
// *** Pintado de capa/composicion de capa *** |
494 |
if (composed != null){ |
|
522 |
if (composed != null) {
|
|
495 | 523 |
// si la composicion no se ha pintado la pintamos |
496 |
// System.out.println("=======Imprimiendo composicion de pintado "+ (layerPos-1)+" (ultimo) ============"); |
|
524 |
// System.out.println("=======Imprimiendo composicion de pintado "+ |
|
525 |
// (layerPos-1)+" (ultimo) ============"); |
|
497 | 526 |
this.print(composed, g, cancel, scale, properties); |
498 |
// composed.print(g, viewPort, cancel, scale, properties);
|
|
527 |
// composed.print(g, viewPort, cancel, scale, properties);
|
|
499 | 528 |
composed = null; |
500 | 529 |
} |
501 | 530 |
} |
502 | 531 |
|
503 |
|
|
504 | 532 |
} |
505 | 533 |
|
506 |
private DrawList createDrawList(FLayers root,Cancellable cancel,double scale){ |
|
534 |
private DrawList createDrawList(FLayers root, Cancellable cancel, |
|
535 |
double scale) { |
|
507 | 536 |
DrawList result = new DrawList(this.previousDrawList); |
508 |
Iterator iter = new MyLayerIterator((FLayer)root,scale);
|
|
509 |
while (iter.hasNext()){ |
|
510 |
if (cancel.isCanceled()){ |
|
537 |
Iterator iter = new MyLayerIterator((FLayer) root, scale);
|
|
538 |
while (iter.hasNext()) {
|
|
539 |
if (cancel.isCanceled()) {
|
|
511 | 540 |
return null; |
512 | 541 |
} |
513 | 542 |
result.add(iter.next()); |
... | ... | |
517 | 546 |
return result; |
518 | 547 |
} |
519 | 548 |
|
520 |
private List createPrintList(FLayers root,Cancellable cancel){
|
|
549 |
private List createPrintList(FLayers root, Cancellable cancel) {
|
|
521 | 550 |
List result = new ArrayList(); |
522 |
Iterator iter = new SimpleLayerIterator((FLayer)root); |
|
523 |
while (iter.hasNext()){ |
|
524 |
if (cancel.isCanceled()){ |
|
551 |
Iterator iter = new SimpleLayerIterator((FLayer) root);
|
|
552 |
while (iter.hasNext()) {
|
|
553 |
if (cancel.isCanceled()) {
|
|
525 | 554 |
return null; |
526 | 555 |
} |
527 | 556 |
result.add(iter.next()); |
... | ... | |
529 | 558 |
return result; |
530 | 559 |
} |
531 | 560 |
|
532 |
private class MyLayerIterator implements Iterator{ |
|
533 |
ArrayList layersList =new ArrayList();
|
|
561 |
private class MyLayerIterator implements Iterator {
|
|
562 |
ArrayList layersList = new ArrayList();
|
|
534 | 563 |
int index = 0; |
535 |
double scale=0;
|
|
564 |
double scale = 0;
|
|
536 | 565 |
|
537 |
|
|
538 | 566 |
public MyLayerIterator(FLayer layer, double scale) { |
539 |
this.scale=scale;
|
|
567 |
this.scale = scale;
|
|
540 | 568 |
this.appendLayer(layer); |
541 | 569 |
} |
542 | 570 |
|
... | ... | |
545 | 573 |
layersList.add(layer); |
546 | 574 |
} |
547 | 575 |
if (layer instanceof LayerCollection) { |
548 |
appendLayers((LayerCollection)layer); |
|
576 |
appendLayers((LayerCollection) layer);
|
|
549 | 577 |
} |
550 | 578 |
} |
551 | 579 |
|
552 | 580 |
private void appendLayers(LayerCollection layers) { |
553 | 581 |
int i; |
554 |
layersList.add(new LayersGroupEvent(layers,LayersGroupEvent.IN_Event)); |
|
555 |
for (i=0;i< layers.getLayersCount();i++) { |
|
582 |
layersList.add(new LayersGroupEvent(layers, |
|
583 |
LayersGroupEvent.IN_Event)); |
|
584 |
for (i = 0; i < layers.getLayersCount(); i++) { |
|
556 | 585 |
appendLayer(layers.getLayer(i)); |
557 | 586 |
} |
558 |
layersList.add(new LayersGroupEvent(layers,LayersGroupEvent.OUT_Event)); |
|
587 |
layersList.add(new LayersGroupEvent(layers, |
|
588 |
LayersGroupEvent.OUT_Event)); |
|
559 | 589 |
} |
560 | 590 |
|
561 | 591 |
public void remove() { |
... | ... | |
563 | 593 |
} |
564 | 594 |
|
565 | 595 |
public boolean hasNext() { |
566 |
return index < layersList.size();
|
|
596 |
return index < layersList.size(); |
|
567 | 597 |
} |
568 | 598 |
|
569 | 599 |
public Object next() { |
... | ... | |
579 | 609 |
if (layer instanceof FLayers) { |
580 | 610 |
return false; |
581 | 611 |
} |
582 |
return layer.isAvailable() && layer.isVisible() && layer.isWithinScale(this.scale); |
|
612 |
return layer.isAvailable() && layer.isVisible() |
|
613 |
&& layer.isWithinScale(this.scale); |
|
583 | 614 |
} |
584 | 615 |
|
585 | 616 |
} |
... | ... | |
588 | 619 |
public static final String IN_Event = "in"; |
589 | 620 |
public static final String OUT_Event = "Out"; |
590 | 621 |
|
591 |
private LayerCollection group=null;
|
|
622 |
private LayerCollection group = null;
|
|
592 | 623 |
private String type = IN_Event; |
593 | 624 |
|
594 |
public LayersGroupEvent(LayerCollection group,String type){
|
|
595 |
this.group =group; |
|
596 |
this.type =type; |
|
625 |
public LayersGroupEvent(LayerCollection group, String type) {
|
|
626 |
this.group = group;
|
|
627 |
this.type = type;
|
|
597 | 628 |
} |
598 | 629 |
|
599 |
|
|
600 | 630 |
public String getType() { |
601 | 631 |
return type; |
602 | 632 |
} |
Also available in: Unified diff