Revision 20098 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/GraphicLayer.java
GraphicLayer.java | ||
---|---|---|
63 | 63 |
import com.vividsolutions.jts.index.ItemVisitor; |
64 | 64 |
import com.vividsolutions.jts.index.SpatialIndex; |
65 | 65 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
66 |
|
|
66 | 67 |
/** |
67 |
* <p>The class <code>GraphicLayer</code> represents a layer with graphical items, that are geometries with
|
|
68 |
* <p><code>GraphicLayer</code> represents a layer with graphical items, that are geometries with |
|
68 | 69 |
* a symbol and handlers associated.</p> |
69 |
* |
|
70 |
* <p>The internal graphical items are independent to each other and can be selected separately. There is a bit set to
|
|
71 |
* define which item are selected. And they which are selected, will be drawn with handlers, that according to the particular
|
|
72 |
* implementation of each one, can allow to move, center, ... the graphic item.</p>
|
|
73 |
* |
|
70 |
*
|
|
71 |
* <p>The internal graphical items are independent to each other and can be selected separately. There is a <i>bit set</i> to
|
|
72 |
* define which item are selected. They, will be drawn with handlers, that according to the particular
|
|
73 |
* implementation of each one, can allow user to move, center, deform, ... each graphical item.</p>
|
|
74 |
*
|
|
74 | 75 |
* @see FLyrDefault |
75 | 76 |
*/ |
76 | 77 |
public class GraphicLayer extends FLyrDefault { |
77 | 78 |
/** |
78 | 79 |
* Internal list with all graphic items of this layer. |
79 |
* |
|
80 |
*
|
|
80 | 81 |
* @see #addGraphic(FGraphic) |
81 | 82 |
* @see #clearAllGraphics() |
82 | 83 |
* @see #getGraphic(int) |
... | ... | |
91 | 92 |
|
92 | 93 |
/** |
93 | 94 |
* Internal list with all symbols of this layer. |
94 |
* |
|
95 |
*
|
|
95 | 96 |
* @see #addSymbol(ISymbol) |
96 | 97 |
* @see #clearSymbolsGraphics() |
97 | 98 |
*/ |
98 | 99 |
private ArrayList symbols = new ArrayList(); |
99 |
/** |
|
100 |
|
|
101 |
/** |
|
100 | 102 |
* Describes a rectangle defined by a location (x, y) and dimension, that represents this layer position |
101 | 103 |
* and dimension. |
102 |
* |
|
104 |
*
|
|
103 | 105 |
* @see #getFullExtent() |
104 | 106 |
* @see #reCalculateFullExtent() |
105 | 107 |
*/ |
... | ... | |
109 | 111 |
* An optimal index according a quadtree for fast access to spatial data. |
110 | 112 |
*/ |
111 | 113 |
private SpatialIndex spatialIndex = new Quadtree(); |
112 |
/** |
|
114 |
|
|
115 |
/** |
|
113 | 116 |
* A set of boolean items that specifies which graphic items of this layer are selected. |
114 |
* |
|
117 |
*
|
|
115 | 118 |
* @see #getSelection() |
116 | 119 |
* @see #setSelection(FBitSet) |
117 | 120 |
*/ |
118 | 121 |
private FBitSet selection = new FBitSet(); |
119 |
/** |
|
120 |
* Creates a default <i>FMap</i> layer. |
|
121 |
* |
|
122 |
|
|
123 |
/** |
|
124 |
* <p>Creates a new <code>GraphicLayer</code> instance.</p> |
|
125 |
* |
|
122 | 126 |
* @see FLyrDefault#FLyrDefault() |
123 | 127 |
*/ |
124 | 128 |
public GraphicLayer() { |
... | ... | |
132 | 136 |
return fullExtent; |
133 | 137 |
} |
134 | 138 |
|
135 |
|
|
136 | 139 |
/* |
137 | 140 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double) |
138 | 141 |
*/ |
... | ... | |
144 | 147 |
|
145 | 148 |
/** |
146 | 149 |
* <p>Processes all graphic items of this layer according to the <i>visitor pattern</i>. This |
147 |
* operation can be cancelled at any time.</p>
|
|
148 |
* |
|
150 |
* operation can be canceled at any time.</p>
|
|
151 |
*
|
|
149 | 152 |
* @param visitor object that allows visit each graphic item |
150 |
* @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and allows |
|
151 |
* cancel the visit |
|
153 |
* @param cancel shared object that determines if this layer can continue being drawn |
|
152 | 154 |
*/ |
153 | 155 |
public void process(ItemVisitor visitor, Cancellable cancel) |
154 | 156 |
{ |
... | ... | |
166 | 168 |
|
167 | 169 |
} |
168 | 170 |
|
169 |
|
|
170 | 171 |
/* |
171 | 172 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double, javax.print.attribute.PrintRequestAttributeSet) |
172 | 173 |
*/ |
... | ... | |
175 | 176 |
drawGraphics(null, g, viewPort, cancel); |
176 | 177 |
} |
177 | 178 |
} |
179 |
|
|
178 | 180 |
/** |
179 | 181 |
* <p>Draws each graphic item of this layer that it's associated symbol is also in this layer, and its |
180 | 182 |
* geometry intersects with the extent currently covered by the view (of the {@link ViewPort ViewPort}). If |
181 |
* the graphic item is selected, will also draw its selection handlers.</p> |
|
182 |
* |
|
183 |
* the graphic item is selected, will also draw its selection handlers.</p>
|
|
184 |
*
|
|
183 | 185 |
* @param image buffer used sometimes instead <code>g</code> to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one. |
184 | 186 |
* @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform |
185 | 187 |
* @param viewPort the information for drawing the layers |
186 | 188 |
* @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw |
187 |
* |
|
189 |
*
|
|
188 | 190 |
* @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double) |
189 | 191 |
* @see #print(Graphics2D, ViewPort, Cancellable, double, PrintRequestAttributeSet) |
190 | 192 |
*/ |
... | ... | |
235 | 237 |
} |
236 | 238 |
} |
237 | 239 |
} |
240 |
|
|
238 | 241 |
/** |
239 |
* <p>Adds a new symbol to the graphic layer, and if success, returns the last index of the internal |
|
242 |
* <p>Adds a new symbol to the graphic layer, and, if success, returns the last index of the internal
|
|
240 | 243 |
* list of symbols.</p> |
241 |
* |
|
244 |
*
|
|
242 | 245 |
* @param newSymbol the new symbol |
243 | 246 |
* @return last index of the internal list of symbols if success, -1 otherwise |
244 |
* |
|
247 |
*
|
|
245 | 248 |
* @see #clearSymbolsGraphics() |
246 | 249 |
*/ |
247 | 250 |
public int addSymbol(ISymbol newSymbol) |
... | ... | |
251 | 254 |
return -1; |
252 | 255 |
|
253 | 256 |
} |
257 |
|
|
254 | 258 |
/** |
255 |
* <p>Adds a new graphic item to the graphic layer, and if success, sets as new extent the graphic's |
|
259 |
* <p>Adds a new graphic item to the graphic layer, and, if success, sets as new extent the graphic's
|
|
256 | 260 |
* one if this layer hadn't, otherwise sets as new extent the union of both.</p> |
257 |
* |
|
261 |
*
|
|
258 | 262 |
* @param g the new graphic item |
259 |
* |
|
263 |
*
|
|
260 | 264 |
* @see #insertGraphic(int, FGraphic) |
261 | 265 |
* @see #inserGraphics(int, Collection) |
262 | 266 |
*/ |
... | ... | |
277 | 281 |
// return -1; |
278 | 282 |
|
279 | 283 |
} |
284 |
|
|
280 | 285 |
/** |
281 |
* <p>Adds a new graphic item to the graphic layer at the position specified of the internal list, and if success, |
|
286 |
* <p>Adds a new graphic item to the graphic layer at the position specified of the internal list, and, if success,
|
|
282 | 287 |
* sets as new extent the graphic's one if this layer hadn't, otherwise sets as new extent the union of both.</p> |
283 |
* |
|
284 |
* @param position the index of the element to insert |
|
288 |
*
|
|
289 |
* @param position the index of the element to insert
|
|
285 | 290 |
* @param g the new graphic item |
286 |
* |
|
291 |
*
|
|
287 | 292 |
* @see #inserGraphics(int, Collection) |
288 | 293 |
* @see #addGraphic(FGraphic) |
289 | 294 |
*/ |
... | ... | |
295 | 300 |
fullExtent.add(g.getGeom().getBounds2D()); |
296 | 301 |
} |
297 | 302 |
} |
303 |
|
|
298 | 304 |
/** |
299 | 305 |
* Removes all graphic items from this layer. The internal list of graphic items will be empty |
300 | 306 |
* after this call returns, and layer won't have extent. |
301 |
* |
|
307 |
*
|
|
302 | 308 |
* @see #removeGraphic(FGraphic) |
303 | 309 |
* @see #removeGraphic(int) |
304 | 310 |
*/ |
... | ... | |
307 | 313 |
graphics.clear(); |
308 | 314 |
fullExtent = null; |
309 | 315 |
} |
316 |
|
|
310 | 317 |
/** |
311 | 318 |
* Removes all symbols from this layer. The internal list of symbols will be empty |
312 | 319 |
* after this call returns. |
313 |
* |
|
320 |
*
|
|
314 | 321 |
* @see #addSymbol(ISymbol) |
315 | 322 |
*/ |
316 | 323 |
public void clearSymbolsGraphics() |
317 | 324 |
{ |
318 | 325 |
symbols.clear(); |
319 | 326 |
} |
327 |
|
|
320 | 328 |
/** |
321 | 329 |
* <p>Gets a set of boolean values that specifies which graphic items of this layer are selected.</p> |
322 |
* |
|
323 |
* @return a set of boolean values. Each value is equal to <code>true</code> if is selected the graphic item |
|
330 |
*
|
|
331 |
* @return a set of boolean values. Each value is equal to <code>true</code> if is selected the graphic item
|
|
324 | 332 |
* that has the same position in the internal list of graphic items of this layer, and to <code>false</code> if isn't selected |
325 |
* |
|
333 |
*
|
|
326 | 334 |
* @see #setSelection(FBitSet) |
327 | 335 |
*/ |
328 | 336 |
public FBitSet getSelection() { |
... | ... | |
331 | 339 |
|
332 | 340 |
/** |
333 | 341 |
* <p>Sets a set of boolean values that specifies which graphic items of this layer are selected.</p> |
334 |
* |
|
335 |
* @param selection a set of boolean values. Each value is equal to <code>true</code> if is selected the graphic item |
|
342 |
*
|
|
343 |
* @param selection a set of boolean values. Each value is equal to <code>true</code> if is selected the graphic item
|
|
336 | 344 |
* that has the same position in the internal list of graphic items of this layer, and to <code>false</code> if isn't selected |
337 |
* |
|
345 |
*
|
|
338 | 346 |
* @see #getSelection() |
339 | 347 |
*/ |
340 | 348 |
public void setSelection(FBitSet selection) { |
341 | 349 |
this.selection = selection; |
342 | 350 |
} |
351 |
|
|
343 | 352 |
/** |
344 |
* Returns a bit set that reports which graphic items that are geometries, intersect with
|
|
353 |
* Returns a bit set that reports which graphic items <i>(geometries)</i>, intersect with
|
|
345 | 354 |
* the rectangle <code>r</code>. |
346 |
* |
|
347 |
* @param r the <code>Rectangle2D</code> to be intersected with all geometries of this layer
|
|
355 |
*
|
|
356 |
* @param r the <code>Rectangle2D</code> to be intersected with some geometries of this layer
|
|
348 | 357 |
* @return a <code>FBitSet</code> which <code>true</code> bits represent the geometries of this layer |
349 | 358 |
* that intersect with the rectangle |
350 |
* |
|
359 |
*
|
|
351 | 360 |
* @see IGeometry#intersects(Rectangle2D) |
352 | 361 |
*/ |
353 | 362 |
public FBitSet queryByRect(Rectangle2D r) { |
... | ... | |
363 | 372 |
} |
364 | 373 |
return newSel; |
365 | 374 |
} |
375 |
|
|
366 | 376 |
/** |
367 | 377 |
* Removes a graphic item and recalculates the extent of this layer. |
368 |
* |
|
378 |
*
|
|
369 | 379 |
* @param graphic the graphic item to be removed |
370 |
* |
|
380 |
*
|
|
371 | 381 |
* @see #removeGraphic(int) |
372 | 382 |
* @see #clearAllGraphics() |
373 | 383 |
*/ |
... | ... | |
376 | 386 |
reCalculateFullExtent(); |
377 | 387 |
|
378 | 388 |
} |
389 |
|
|
379 | 390 |
/** |
380 | 391 |
* Returns the item at the specified position in the internal list of graphics. |
381 |
* |
|
392 |
*
|
|
382 | 393 |
* @param idGraphic index of item to return |
383 | 394 |
* @return the item at the specified position in the internal list of graphics |
384 |
* |
|
395 |
*
|
|
385 | 396 |
* @see #getGraphicByObjectTag(Object) |
386 | 397 |
* @see #getNumGraphics() |
387 | 398 |
*/ |
388 | 399 |
public FGraphic getGraphic(int idGraphic) { |
389 | 400 |
return (FGraphic) graphics.get(idGraphic); |
390 | 401 |
} |
402 |
|
|
391 | 403 |
/** |
392 | 404 |
* Returns the graphic item of this layer, that has the specified object tag. |
393 |
* |
|
394 |
* @param objectTag the object tag of the item to return
|
|
405 |
*
|
|
406 |
* @param objectTag the tag of the item to return
|
|
395 | 407 |
* @return the item that has the specified object tag, or <code>null</code> if there was no item that had it |
396 |
* |
|
408 |
*
|
|
397 | 409 |
* @see #getGraphic(int) |
398 | 410 |
* @see #getNumGraphics() |
399 | 411 |
*/ |
... | ... | |
410 | 422 |
* Returns the number of graphic items in this layer. |
411 | 423 |
* |
412 | 424 |
* @return the number of graphic items in this list |
413 |
* |
|
425 |
*
|
|
414 | 426 |
* @see #addGraphic(FGraphic) |
415 | 427 |
* @see #inserGraphics(int, Collection) |
416 | 428 |
* @see #insertGraphic(int, FGraphic) |
... | ... | |
422 | 434 |
public int getNumGraphics() { |
423 | 435 |
return graphics.size(); |
424 | 436 |
} |
437 |
|
|
425 | 438 |
/** |
426 | 439 |
* Recalculates the full extent of this layer as the union of the bounds 2D |
427 | 440 |
* of all internal graphic items. |
... | ... | |
438 | 451 |
} |
439 | 452 |
} |
440 | 453 |
} |
454 |
|
|
441 | 455 |
/** |
442 | 456 |
* <p>Inserts all of the elements in the specified {@link Collection Collection} into the internal list of graphic items, |
443 |
* starting at the specified position. Shifts the element currently at that position (if any) and any |
|
444 |
* subsequent elements to the right (increases their indices). The new elements will appear in the list
|
|
457 |
* starting at the specified position. Shifts the element currently at that position (if there was any) and any
|
|
458 |
* subsequent elements to the right (increasing their indices). The new elements will appear in the list
|
|
445 | 459 |
* in the order that they are returned by the specified collection's iterator.</p> |
446 |
* |
|
447 |
* @param index index at which to insert first element from the specified collection
|
|
460 |
*
|
|
461 |
* @param index index where starting to insert the elements from the specified collection
|
|
448 | 462 |
* @param c elements to be inserted into this list |
449 |
* |
|
463 |
*
|
|
450 | 464 |
* @see #insertGraphic(int, FGraphic) |
451 | 465 |
* @see #addGraphic(FGraphic) |
452 | 466 |
*/ |
... | ... | |
458 | 472 |
/** |
459 | 473 |
* <p>Fast remove: removes only a graphic item of this layer.</p> |
460 | 474 |
* <p>Remember to call {@linkplain #reCalculateFullExtent()} when you finish removing graphics.</p> |
461 |
* |
|
475 |
*
|
|
462 | 476 |
* @param graphicIndex the graphic item to be removed |
463 |
* |
|
477 |
*
|
|
464 | 478 |
* @see #removeGraphic(FGraphic) |
465 | 479 |
* @see #clearAllGraphics() |
466 | 480 |
*/ |
467 | 481 |
public void removeGraphic(int graphicIndex) { |
468 | 482 |
graphics.remove(graphicIndex); |
469 | 483 |
} |
484 |
|
|
470 | 485 |
/** |
471 |
* Return index of symbol, if it exists. |
|
472 |
* @param sym |
|
473 |
* @return -1 if it is not inside the symbols list. |
|
486 |
* <p>Searches for the first symbol <code>sym</code>, testing for equality using the equals method.</p> |
|
487 |
* |
|
488 |
* @param sym a symbol |
|
489 |
* @return the index of the first occurrence of <code>sym</code>; returns -1 if the object is not found. |
|
474 | 490 |
*/ |
475 | 491 |
public int getSymbol(ISymbol sym) { |
476 | 492 |
if (symbols.contains(sym)) { |
Also available in: Unified diff