root / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayer.java @ 13201
History | View | Annotate | Download (18 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.Image; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.util.List; |
48 |
import java.util.Map; |
49 |
|
50 |
import javax.print.attribute.PrintRequestAttributeSet; |
51 |
import javax.swing.ImageIcon; |
52 |
|
53 |
import org.cresques.cts.ICoordTrans; |
54 |
import org.cresques.cts.IProjection; |
55 |
import org.cresques.geo.Projected; |
56 |
|
57 |
import com.iver.cit.gvsig.fmap.DriverException; |
58 |
import com.iver.cit.gvsig.fmap.MapContext; |
59 |
import com.iver.cit.gvsig.fmap.MapControl; |
60 |
import com.iver.cit.gvsig.fmap.ViewPort; |
61 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
62 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer; |
64 |
import com.iver.utiles.XMLEntity; |
65 |
import com.iver.utiles.swing.threads.Cancellable; |
66 |
|
67 |
|
68 |
/**
|
69 |
* <p>Definition of the basic methods that all kind of <a href="http://www.gvsig.gva.es/">gvSIG</a> 's layers must implement.</p>
|
70 |
*
|
71 |
* <p>This kind of layers store their data by theirself, are drawable, projectable (with a projection), can be a node of a tree of layers, and
|
72 |
* could be editable and have a cache with previous draws. They also can be visible or not, and active or not.</p>
|
73 |
*
|
74 |
* <p>A layer can also store information about errors produced working with it, and have a name (kind of layer) and
|
75 |
* a brief summary explaining what's for.</p>
|
76 |
*
|
77 |
* <p>Each particular implementation can add new properties, and limit or expand the functionality.</p>
|
78 |
*
|
79 |
* @see Projected
|
80 |
*/
|
81 |
public interface FLayer extends Projected { |
82 |
/**
|
83 |
* <p>Returns an entity that represents this layer.</p>
|
84 |
*
|
85 |
* <p>This xml entity has elements that represent and store information about this layer.</p>
|
86 |
*
|
87 |
* @return an xml entity with information to the current layer
|
88 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
|
89 |
*/
|
90 |
XMLEntity getXMLEntity() throws XMLException;
|
91 |
|
92 |
/**
|
93 |
* <p>Inserts information to this layer from an xml entity.</p>
|
94 |
*
|
95 |
* <p>This xml entity has elements that represent and store information about this layer.</p>
|
96 |
*
|
97 |
* @param xml an <code>XMLEntity</code> with the information
|
98 |
*
|
99 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
|
100 |
*/
|
101 |
void setXMLEntity(XMLEntity xml) throws XMLException; |
102 |
|
103 |
/**
|
104 |
* Inserts some properties to this layer.
|
105 |
*
|
106 |
* @param xml an <code>XMLEntity</code> with the information
|
107 |
*
|
108 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
|
109 |
*/
|
110 |
void setXMLEntity03(XMLEntity xml) throws XMLException; |
111 |
|
112 |
/**
|
113 |
* Changes the status of the current layer to active or inactive.
|
114 |
*
|
115 |
* @param selected the boolean to be set
|
116 |
*/
|
117 |
void setActive(boolean selected); |
118 |
|
119 |
/**
|
120 |
* Returns <code>true</code> or <code>false</code> if this layer is in black or not in the <i>TOC</i>.
|
121 |
*
|
122 |
* @return <code>true</code> if this layer is active, otherwise <code>false</code>
|
123 |
*/
|
124 |
boolean isActive();
|
125 |
|
126 |
/**
|
127 |
* Sets a name to this layer.
|
128 |
*
|
129 |
* @param name the string that is to be this layer's name
|
130 |
*/
|
131 |
void setName(String name); |
132 |
|
133 |
/**
|
134 |
* Returns the name of this layer.
|
135 |
*
|
136 |
* @return an string with this layer's name
|
137 |
*/
|
138 |
String getName();
|
139 |
|
140 |
/**
|
141 |
* <p>Executes the initialization operations of this layer. This method is invoked
|
142 |
* only one time during the life of this layer and just before visualize it.</p>
|
143 |
*
|
144 |
* @throws com.iver.cit.gvsig.fmap.drivers.DriverIOException if fails loading the layer.
|
145 |
*/
|
146 |
void load() throws DriverIOException; |
147 |
|
148 |
/**
|
149 |
* Changes the status of the current layer to visible or invisible.
|
150 |
*
|
151 |
* @param visibility the boolean to be set
|
152 |
*/
|
153 |
void setVisible(boolean visibility); |
154 |
|
155 |
/**
|
156 |
* <p>Returns <code>true</code> if this layer is visible and available.</p>
|
157 |
*
|
158 |
* @see #isAvailable()
|
159 |
* @see #setAvailable(boolean)
|
160 |
* @see #visibleRequired()
|
161 |
*
|
162 |
* @return <code>true</code> if this layer is visible and available, otherwise <code>false</code>
|
163 |
*/
|
164 |
boolean isVisible();
|
165 |
|
166 |
/**
|
167 |
* Returns the parent <code>FLayers</code> of this layer.
|
168 |
*
|
169 |
* @return the parent of this layer, or <code>null</code> if hasn't parent
|
170 |
*/
|
171 |
public FLayers getParentLayer();
|
172 |
|
173 |
/**
|
174 |
* <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
|
175 |
*
|
176 |
* @return the model of this layer
|
177 |
*/
|
178 |
public MapContext getMapContext();
|
179 |
|
180 |
/**
|
181 |
* Inserts the parent <code>FLayers</code> of the layer.
|
182 |
*
|
183 |
* @param root a <code>FLayers</code> object
|
184 |
*/
|
185 |
public void setParentLayer(FLayers root); |
186 |
|
187 |
/**
|
188 |
* Returns the full extension of the layer.
|
189 |
*
|
190 |
* @return location and dimension of this layer
|
191 |
*
|
192 |
* @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
|
193 |
*/
|
194 |
Rectangle2D getFullExtent() throws DriverException; |
195 |
|
196 |
/**
|
197 |
* Draws the layer using a buffer.
|
198 |
*
|
199 |
* @param image an image used to accelerate the screen draw
|
200 |
* @param g a <code>Graphics2D</code> object that will allow the 2D draw
|
201 |
* @param viewPort the view port where the layer will be drawn
|
202 |
* @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
|
203 |
* @param scale a double value that represents the scale
|
204 |
*
|
205 |
* @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
|
206 |
*/
|
207 |
void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
208 |
Cancellable cancel, double scale) throws DriverException; |
209 |
|
210 |
/**
|
211 |
* Prints this layer according to some properties requested.
|
212 |
*
|
213 |
* @param g a <code>Graphics2D</code> object that will allow the 2D draw
|
214 |
* @param viewPort the view port where the layer will be drawn
|
215 |
* @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
|
216 |
* @param scale a double value that represents the scale
|
217 |
* @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
|
218 |
*
|
219 |
* @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
|
220 |
*/
|
221 |
void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
222 |
throws DriverException;
|
223 |
|
224 |
/**
|
225 |
* Inserts the transformation coordinates.
|
226 |
*
|
227 |
* @param ct transformation coordinates
|
228 |
*/
|
229 |
void setCoordTrans(ICoordTrans ct);
|
230 |
|
231 |
/**
|
232 |
* Returns the transformation coordinates.
|
233 |
*
|
234 |
* @return transformation coordinates
|
235 |
*/
|
236 |
ICoordTrans getCoordTrans(); |
237 |
|
238 |
/**
|
239 |
* Adds a LayerListener to the listener list.
|
240 |
*
|
241 |
* @param o a layer listener
|
242 |
*
|
243 |
* @return <code>true</code> if hasn't been any problem during the insertion of the listener
|
244 |
*/
|
245 |
public boolean addLayerListener(LayerListener o); |
246 |
|
247 |
/**
|
248 |
* Returns all LayerListener listeners of this layer as an array.
|
249 |
*
|
250 |
* @return an array with all layer listeners associated to this layer
|
251 |
*/
|
252 |
public LayerListener[] getLayerListeners(); |
253 |
|
254 |
/**
|
255 |
* Removes the LayerListener parameter from this layer.
|
256 |
*
|
257 |
* @param o a layer listener
|
258 |
*
|
259 |
* @return <code>true</code> if hasn't been any problem doing this process
|
260 |
*/
|
261 |
public boolean removeLayerListener(LayerListener o); |
262 |
|
263 |
/**
|
264 |
* <p>Returns <code>true</code> or <code>false</code> if the value of scale as parameter
|
265 |
* is within the maximum and minimum scale of this layer.</p>
|
266 |
*
|
267 |
* @param scale the scale > 0
|
268 |
*
|
269 |
* @return <code>true</code> if the scale is within the range of scales of this layer, otherwise <code>false</code>
|
270 |
*/
|
271 |
public boolean isWithinScale(double scale); |
272 |
|
273 |
/**
|
274 |
* Returns the minimum scale visible. Lower scales won't be drawn.
|
275 |
*
|
276 |
* @return the minimum scale > 0, -1 if not defined
|
277 |
*/
|
278 |
public double getMinScale(); |
279 |
|
280 |
/**
|
281 |
* Returns the maximum scale visible. Higher scales won't be drawn.
|
282 |
*
|
283 |
* @return the maximum scale > 0, -1 if not defined
|
284 |
*/
|
285 |
public double getMaxScale(); |
286 |
|
287 |
/**
|
288 |
* Sets the minimum scale visible. Lower scales won't be drawn.
|
289 |
*
|
290 |
* @param minScale the scale > 0, -1 if not defined
|
291 |
*/
|
292 |
public void setMinScale(double minScale); |
293 |
|
294 |
/**
|
295 |
* Sets the maximum scale visible. Higher scales won't be drawn.
|
296 |
*
|
297 |
* @param maxScale the scale > 0, -1 if not defined
|
298 |
*/
|
299 |
public void setMaxScale(double maxScale); |
300 |
|
301 |
/**
|
302 |
* Changes the status of the current layer to editable or not.
|
303 |
*
|
304 |
* @param b the boolean to be set
|
305 |
*
|
306 |
* @throws com.iver.cit.gvsig.fmap.edition.EditionException if fails enabling for edition this kind of layer.
|
307 |
*/
|
308 |
public void setEditing(boolean b) throws EditionException; |
309 |
|
310 |
/**
|
311 |
* <p>Returns <code>true</code> if this layer is editable.</p>
|
312 |
*
|
313 |
* @return <code>true</code> if this layer is editable, otherwise <code>false</code>
|
314 |
*/
|
315 |
public boolean isEditing(); |
316 |
|
317 |
/**
|
318 |
* <p>Uses or not a <code>BufferedImage</code> object that represents this image.</p>
|
319 |
*
|
320 |
* @return <code>true</code> if uses that kind of image, otherwise <code>false</code>
|
321 |
*/
|
322 |
public boolean isCachingDrawnLayers(); |
323 |
|
324 |
/**
|
325 |
* <p>Set <code>true</code> if you want this layer to store an image of previous layers.
|
326 |
* Then, if you perform a <code>FLayers#invalidateLayer()</code>, the system will
|
327 |
* redraw only this layers you are requesting.</p>
|
328 |
*
|
329 |
* @param bCacheDrawnLayers the boolean to be set
|
330 |
*/
|
331 |
// * <p>Another option could be store an image of each layer drawn, and call each one using something
|
332 |
// * like "invalidate()". On having rendered, it's possible to see if it's invalidated, and if itsn't,
|
333 |
// * paste the cached image.</p>
|
334 |
// *
|
335 |
// * <p> ERROR!: You can't cache that image, because if the background has changed, the antialiasing
|
336 |
// * will affect the draw of that layer. However, it would be useful draw the cached image of each layer
|
337 |
// * that aren't invalidated, and from that appears one of them invalidated, the rest already have to draw.
|
338 |
// * The problem is that continues spending more memory</p>
|
339 |
// *
|
340 |
// * @param bCacheDrawnLayers
|
341 |
// */
|
342 |
public void setCachingDrawnLayers(boolean bCacheDrawnLayers); |
343 |
|
344 |
/**
|
345 |
* Returns the image icon that will be shown in the TOC next to this layer.
|
346 |
*
|
347 |
* @return a reference to the image icon, or <code>null</code> if there isn't any
|
348 |
*/
|
349 |
public ImageIcon getTocImageIcon(); |
350 |
|
351 |
/**
|
352 |
* <p>Returns <code>true</code> or <code>false</code> if this layer appears or not in the TOC.</p>
|
353 |
* <p>If doesn't appears, remains in the view and in the project.</p>
|
354 |
*
|
355 |
* @return
|
356 |
*/
|
357 |
boolean isInTOC();
|
358 |
|
359 |
/**
|
360 |
* <p>Returns <code>true</code> or <code>false</code> if this layer needs or doesn't need a repaint.
|
361 |
*
|
362 |
* @return true if this layer need a repaint.
|
363 |
*/
|
364 |
public boolean isDirty(); |
365 |
|
366 |
/**
|
367 |
* <p>Changes the status of this layer to dirty if needs a repaint.</p>
|
368 |
*
|
369 |
* <p>By default, all layers will be set to dirty when the extent changes. But for events like changing
|
370 |
* its legend, or editing a layer, we could perform some optimization using the private method <code>MapContext#prepareDrawing</code> from <code>MapContext</code>.</p>
|
371 |
*
|
372 |
* @param dirty <code>true</code> if this layer needs a repaint
|
373 |
*/
|
374 |
public void setDirty(boolean dirty); |
375 |
|
376 |
/**
|
377 |
* Returns the image with bands, of the drawn layers.
|
378 |
*
|
379 |
* @return an image with bands
|
380 |
*/
|
381 |
public BufferedImage getCacheImageDrawnLayers(); |
382 |
|
383 |
/**
|
384 |
* Sets the image with bands, for the drawn layers.
|
385 |
*
|
386 |
* @param cacheImageDrawnLayers an image with bands
|
387 |
*/
|
388 |
public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers); |
389 |
|
390 |
/**
|
391 |
* Returns the status of this layer.
|
392 |
*
|
393 |
* @return the status stored in a <code>FLayerStatus</code> object
|
394 |
*/
|
395 |
public FLayerStatus getFLayerStatus();
|
396 |
|
397 |
/**
|
398 |
* Sets the status of this layer.
|
399 |
*
|
400 |
* @param status information of the status for this layer
|
401 |
*/
|
402 |
public void setFLayerStatus(FLayerStatus status); |
403 |
|
404 |
/*
|
405 |
* This stuff is to save error's info that causes
|
406 |
* unavailable status.
|
407 |
* */
|
408 |
/**
|
409 |
* Returns <code>true</code> if this layer is in OK status (it hasn't got errors).
|
410 |
*
|
411 |
* @return <code>true</code> if is in OK status, otherwise <code>false</code>
|
412 |
*/
|
413 |
public boolean isOk(); |
414 |
|
415 |
/**
|
416 |
* Returns the number of errors which causes this layer to be in unavailable status.
|
417 |
*
|
418 |
* @return number of errors >= 0
|
419 |
*/
|
420 |
public int getNumErrors(); |
421 |
|
422 |
/**
|
423 |
* Returns the specified error.
|
424 |
*
|
425 |
* @param i index of the error >= 0 && < <code>getNumErrors</code>
|
426 |
*
|
427 |
* @return a singular error
|
428 |
*/
|
429 |
public DriverException getError(int i); |
430 |
|
431 |
/**
|
432 |
* Adds an error reason that describes this layer's wrong status.
|
433 |
*
|
434 |
* @param error a <code>DriverException</code> with the information of the error
|
435 |
*/
|
436 |
public void addError(DriverException error); |
437 |
|
438 |
/**
|
439 |
* Returns a list with all layer errors.
|
440 |
*
|
441 |
* @return an <code>ArrayList</code> with the errors
|
442 |
*/
|
443 |
public List getErrors(); |
444 |
|
445 |
/**
|
446 |
* Changes the status of the current layer to available or not. By default it's <code>true</code>.
|
447 |
*
|
448 |
* @param the boolean to be set
|
449 |
*/
|
450 |
public void setAvailable(boolean available); |
451 |
|
452 |
/**
|
453 |
* Returns the status of availability of the current layer.
|
454 |
*
|
455 |
* @return <code>true</code> if the source of data is on-line, otherwise <code>false</code>
|
456 |
*/
|
457 |
public boolean isAvailable(); |
458 |
|
459 |
/**
|
460 |
* <p>Tries recover a layer of a possible error.</p>
|
461 |
* <p>If it has any problem during the load, marks the availability
|
462 |
* to false and throws an exception.</p>
|
463 |
*
|
464 |
* @throws DriverIOException if it's thrown a <code>DriverException</code> or an <code>IOException</code> during the load of this layer.
|
465 |
*/
|
466 |
public void reload() throws DriverIOException; |
467 |
|
468 |
/**
|
469 |
* Returns <code>true</code> if this layer has the visible status enabled.
|
470 |
*
|
471 |
* @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
|
472 |
*/
|
473 |
boolean visibleRequired();
|
474 |
|
475 |
/**
|
476 |
* Returns an string with the information of this layer.
|
477 |
*
|
478 |
* @return the string that is to be this component's information
|
479 |
*/
|
480 |
public String getInfoString(); |
481 |
|
482 |
/**
|
483 |
* Returns the writing status of this layer.
|
484 |
*
|
485 |
* @return <code>true</code> if there is a writing driver for this layer, otherwise <code>false</code>
|
486 |
*/
|
487 |
public boolean isWritable(); |
488 |
|
489 |
/**
|
490 |
* <p>Returns a reference to an object (property) associated to this layer.</p>
|
491 |
*
|
492 |
* <p>For example, you can attach a network definition to key "network" and check
|
493 |
* if a layer has a network loaded using <i>getAssociatedObject("network")</i> and
|
494 |
* that it's not null.</p>
|
495 |
*
|
496 |
* @param key the key associated to the property
|
497 |
*
|
498 |
* @return <code>null</code> if key is not found
|
499 |
*/
|
500 |
public Object getProperty(Object key); |
501 |
|
502 |
/**
|
503 |
* Insets an object as a property to this layer.
|
504 |
*
|
505 |
* @param key the key associated to the property
|
506 |
* @param obj the property
|
507 |
*/
|
508 |
public void setProperty(Object key, Object obj); |
509 |
|
510 |
/**
|
511 |
* <p>This method can be used to have a fast cloned layer.</p>
|
512 |
* <p>The implementations should take care of not recreate this layer. Instead of this,
|
513 |
* is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
|
514 |
* the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
|
515 |
* <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
|
516 |
*
|
517 |
* @return a layer that is a clonation of this layer
|
518 |
*
|
519 |
* @throws java.lang.Exception any exception produced during the cloning of this layer, will be thrown.
|
520 |
*/
|
521 |
public FLayer cloneLayer() throws Exception; |
522 |
|
523 |
/**
|
524 |
* Returns a hash map with all new properties associated to this layer.
|
525 |
*
|
526 |
* @return hash table with the added properties
|
527 |
*/
|
528 |
public Map getExtendedProperties(); |
529 |
|
530 |
/**
|
531 |
* <p>Returns a new instance of ComposedLayer.</p>
|
532 |
*
|
533 |
* <p>This allows make a single draw for a group
|
534 |
* of layers with the same source.</p>
|
535 |
*
|
536 |
* <p>If this operation isn't applicable for this
|
537 |
* kind of layer, this method returns null.</p>
|
538 |
*
|
539 |
* <p>By default this operation is not supported.</p>
|
540 |
*
|
541 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer
|
542 |
*
|
543 |
* @return a new composed layer or <code>null</code> if not supported
|
544 |
*/
|
545 |
public ComposedLayer newComposedLayer();
|
546 |
|
547 |
/**
|
548 |
* Returns the image icon that will be shown in the TOC next to this layer, according its status.
|
549 |
*
|
550 |
* @return the image
|
551 |
*/
|
552 |
Image getTocStatusImage();
|
553 |
|
554 |
/**
|
555 |
* Returns <code>true</code> if the projection of the layer can be changed.
|
556 |
*
|
557 |
* @return <code>true</code> if can be changed its projection, otherwise <code>false</code>
|
558 |
*/
|
559 |
public boolean isReprojectable(); |
560 |
|
561 |
/**
|
562 |
* <p>Changes the projection of this layer.</p>
|
563 |
* <p>This method will be overload in each kind of layer, according its specific operations</p>
|
564 |
*
|
565 |
* @param mapC object that will allow work with the image (draw, reproject, transform, store information, ...)
|
566 |
*
|
567 |
* @return <true> if the layer is created with the method {@link FLayers#addLayer(FLayer)}, but returns <code>false</code>
|
568 |
* if the layer load control is passed to the reprojection method
|
569 |
*/
|
570 |
public boolean reProject(MapControl mapC); |
571 |
|
572 |
/**
|
573 |
* Inserts the projection to this layer.
|
574 |
*
|
575 |
* @param proj information about the new projection
|
576 |
*/
|
577 |
public void setProjection(IProjection proj); |
578 |
} |