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 / FLayer.java @ 43215
History | View | Annotate | Download (17.5 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; |
25 |
|
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.Image; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.awt.image.BufferedImage; |
30 |
import java.net.URI; |
31 |
import java.util.List; |
32 |
import java.util.Map; |
33 |
|
34 |
import org.cresques.cts.ICoordTrans; |
35 |
import org.cresques.cts.IProjection; |
36 |
import org.cresques.geo.Projected; |
37 |
import org.gvsig.compat.print.PrintAttributes; |
38 |
import org.gvsig.fmap.dal.DataStore; |
39 |
import org.gvsig.fmap.dal.exception.ReadException; |
40 |
import org.gvsig.fmap.geom.primitive.Envelope; |
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.ViewPort; |
43 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
44 |
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
45 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
46 |
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer; |
47 |
import org.gvsig.metadata.Metadata; |
48 |
import org.gvsig.tools.dispose.Disposable; |
49 |
import org.gvsig.tools.exception.BaseException; |
50 |
import org.gvsig.tools.persistence.Persistent; |
51 |
import org.gvsig.tools.task.Cancellable; |
52 |
|
53 |
|
54 |
|
55 |
/**
|
56 |
* Definition of the basic functionality that all kind of layers should implement.
|
57 |
* <br>
|
58 |
* This kind of layers store their data, are drawable, projectable (with a projection), can be a node of a tree of layers, and
|
59 |
* could be editable and have a cache with previous draws. They also can be visible or not, and active or not.
|
60 |
* <br>
|
61 |
* A layer can also store information about errors produced working with it, and have a name (kind of layer) and
|
62 |
* a brief summary explaining what's for.
|
63 |
* <br>
|
64 |
* Each particular implementation can add new properties, and limit or expand the functionality.</p
|
65 |
* <br>
|
66 |
* @see Projected
|
67 |
*/
|
68 |
public interface FLayer extends Projected, Persistent, Metadata, Disposable, ExtendedPropertiesSupport |
69 |
{ |
70 |
public final String METADATA_DEFINITION_NAME = "Layer"; |
71 |
public final String METADATA_DEFINITION_DESCRIPTION = "Basic layer metadata definition"; |
72 |
|
73 |
public static final String METADATA_CRS = DataStore.METADATA_CRS; |
74 |
public static final String METADATA_NAME = "name"; |
75 |
|
76 |
/**
|
77 |
* <p>Changes the status of this layer to active or inactive.</p>
|
78 |
* <p>One layer is active if is selected in TOC.</p>
|
79 |
*
|
80 |
* @param selected the boolean to be set
|
81 |
*
|
82 |
* @see #isActive()
|
83 |
*/
|
84 |
void setActive(boolean selected); |
85 |
|
86 |
/**
|
87 |
* <p>Returns if this layer is active or not in TOC.</p>
|
88 |
* <p>One layer is active if is selected in TOC.</p>
|
89 |
*
|
90 |
* @return <code>true</code> if this layer is active; <code>false</code> otherwise
|
91 |
*
|
92 |
* @see #setActive(boolean)
|
93 |
*/
|
94 |
boolean isActive();
|
95 |
|
96 |
/**
|
97 |
* Sets a name to this layer.
|
98 |
*
|
99 |
* @param name the string that is to be this layer's name
|
100 |
*
|
101 |
* @see #getName()
|
102 |
*/
|
103 |
void setName(String name); |
104 |
|
105 |
/**
|
106 |
* Returns the name of this layer.
|
107 |
*
|
108 |
* @return an string with this layer's name
|
109 |
*
|
110 |
* @see #setName(String)
|
111 |
*/
|
112 |
String getName();
|
113 |
|
114 |
/**
|
115 |
* <p>Executes the initialization operations of this layer. This method is invoked
|
116 |
* only one time during the life of this layer and just before visualize it.</p>
|
117 |
*
|
118 |
* @throws LoadLayerException if fails loading the layer.
|
119 |
*
|
120 |
* @see #reload()
|
121 |
*/
|
122 |
void load() throws LoadLayerException; |
123 |
/**
|
124 |
* <p>Changes the status of this layer to visible or not.</p>
|
125 |
* <p>One layer is visible if it's check box associated is selected. This means
|
126 |
* that layer will tried to be painted. If the data associated isn't available,
|
127 |
* then this property will change to <code>false</code>.</p>
|
128 |
*
|
129 |
* @param visibility the boolean to be set
|
130 |
*
|
131 |
* @see #isVisible()
|
132 |
* @see #visibleRequired()
|
133 |
* @see #isAvailable()
|
134 |
*/
|
135 |
void setVisible(boolean visibility); |
136 |
|
137 |
/**
|
138 |
* <p>Returns if this layer is visible and available.</p>
|
139 |
* <p>One layer is visible if it's check box associated is selected. This means
|
140 |
* that layer will tried to be painted.</p>
|
141 |
* <p>One layer is available if the source of data is on-line.</p>
|
142 |
* <p>It's probably that one layer selected hadn't available it's data, for example
|
143 |
* in a remote service.</p>
|
144 |
*
|
145 |
* @return <code>true</code> if this layer is visible and available; <code>false</code> otherwise
|
146 |
*
|
147 |
* @see #isAvailable()
|
148 |
* @see #setAvailable(boolean)
|
149 |
* @see #visibleRequired()
|
150 |
*/
|
151 |
boolean isVisible();
|
152 |
|
153 |
/**
|
154 |
* Returns the parent {@link FLayers FLayers} node of this layer.
|
155 |
*
|
156 |
* @return the parent of this layer, or <code>null</code> if hasn't parent
|
157 |
*
|
158 |
* @see #setParentLayer(FLayers)
|
159 |
*/
|
160 |
public FLayers getParentLayer();
|
161 |
|
162 |
/**
|
163 |
* <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
|
164 |
*
|
165 |
* @return the model of this layer
|
166 |
*/
|
167 |
public MapContext getMapContext();
|
168 |
|
169 |
/**
|
170 |
* Inserts the parent {@link FLayers FLayers} node of the layer.
|
171 |
*
|
172 |
* @param root a <code>FLayers</code> object
|
173 |
*
|
174 |
* @see #getParentLayer()
|
175 |
*/
|
176 |
public void setParentLayer(FLayers root); |
177 |
/**
|
178 |
* Returns the full extension of the layer node.
|
179 |
*
|
180 |
* @return location and dimension of this layer node
|
181 |
*
|
182 |
* @throws ReadException if fails the driver used in this method.
|
183 |
*/
|
184 |
Envelope getFullEnvelope() throws ReadException;
|
185 |
|
186 |
/**
|
187 |
* Draws the layer using a buffer.
|
188 |
*
|
189 |
* @param image an image used to accelerate the screen draw
|
190 |
* @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
|
191 |
* @param viewPort information for drawing this layer
|
192 |
* @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
|
193 |
* @param scale value that represents the scale
|
194 |
*
|
195 |
* @throws ReadException if fails the driver used in this method.
|
196 |
*
|
197 |
* @see #print(Graphics2D, ViewPort, Cancellable, double, PrintAttributes)
|
198 |
*/
|
199 |
void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
200 |
Cancellable cancel,double scale) throws ReadException; |
201 |
|
202 |
/**
|
203 |
* Prints this layer according to some properties requested.
|
204 |
*
|
205 |
* @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
|
206 |
* @param viewPort the information for drawing the layers
|
207 |
* @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw
|
208 |
* @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
|
209 |
* @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
|
210 |
*
|
211 |
* @throws ReadException if fails the driver used in this method.
|
212 |
*
|
213 |
* @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
|
214 |
*/
|
215 |
void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties) |
216 |
throws ReadException;
|
217 |
|
218 |
/**
|
219 |
* Inserts the transformation coordinates.
|
220 |
*
|
221 |
* @param ct transformation coordinates
|
222 |
*
|
223 |
* @see #getCoordTrans()
|
224 |
*/
|
225 |
void setCoordTrans(ICoordTrans ct);
|
226 |
|
227 |
/**
|
228 |
* Returns the transformation coordinates.
|
229 |
*
|
230 |
* @return transformation coordinates
|
231 |
*
|
232 |
* @see #setCoordTrans(ICoordTrans)
|
233 |
*/
|
234 |
ICoordTrans getCoordTrans(); |
235 |
|
236 |
/**
|
237 |
* Adds a <code>LayerListener</code> to the listener list.
|
238 |
*
|
239 |
* @param o a layer listener
|
240 |
*
|
241 |
* @return <code>true</code> if hasn't been any problem during the insertion of the listener
|
242 |
*
|
243 |
* @see #getLayerListeners()
|
244 |
* @see #removeLayerListener(LayerListener)
|
245 |
*/
|
246 |
public boolean addLayerListener(LayerListener o); |
247 |
/**
|
248 |
* Returns all <code>LayerListener</code>s of this layer as an array.
|
249 |
*
|
250 |
* @return an array with all layer listeners associated to this layer
|
251 |
*
|
252 |
* @see #addLayerListener(LayerListener)
|
253 |
* @see #removeLayerListener(LayerListener)
|
254 |
*/
|
255 |
public LayerListener[] getLayerListeners(); |
256 |
/**
|
257 |
* Removes the <code>LayerListener</code> argument from this layer.
|
258 |
*
|
259 |
* @param o a layer listener
|
260 |
*
|
261 |
* @return <code>true</code> if hasn't been any problem doing this process
|
262 |
*
|
263 |
* @see #addLayerListener(LayerListener)
|
264 |
* @see #getLayerListeners()
|
265 |
*/
|
266 |
public boolean removeLayerListener(LayerListener o); |
267 |
/**
|
268 |
* <p>Returns if the value of <code>scale</code> argument
|
269 |
* is within the maximum and minimum scale of this layer.</p>
|
270 |
*
|
271 |
* @param scale the scale > 0
|
272 |
*
|
273 |
* @return <code>true</code> if the <code>scale</code> argument is within the range of scales of this layer; <code>false</code> otherwise
|
274 |
*
|
275 |
* @see #setMinScale(double)
|
276 |
* @see #setMaxScale(double)
|
277 |
*/
|
278 |
public boolean isWithinScale(double scale); |
279 |
|
280 |
|
281 |
/**
|
282 |
* Returns the minimum scale visible. Lower scales won't be drawn.
|
283 |
*
|
284 |
* @return the minimum scale > 0, -1 if not defined
|
285 |
*
|
286 |
* @see #setMinScale(double)
|
287 |
*/
|
288 |
public double getMinScale(); |
289 |
|
290 |
/**
|
291 |
* Returns the maximum scale visible. Higher scales won't be drawn.
|
292 |
*
|
293 |
* @return the maximum scale > 0, -1 if not defined
|
294 |
*
|
295 |
* @see #setMaxScale(double)
|
296 |
*/
|
297 |
public double getMaxScale(); |
298 |
/**
|
299 |
* Sets the minimum scale visible. Lower scales won't be drawn.
|
300 |
*
|
301 |
* @param minScale the scale > 0, -1 if not defined
|
302 |
*
|
303 |
* @see #getMinScale()
|
304 |
*/
|
305 |
public void setMinScale(double minScale); |
306 |
/**
|
307 |
* Sets the maximum scale visible. Higher scales won't be drawn.
|
308 |
*
|
309 |
* @param maxScale the scale > 0, -1 if not defined
|
310 |
*
|
311 |
* @see #getMaxScale()
|
312 |
*/
|
313 |
public void setMaxScale(double maxScale); |
314 |
|
315 |
/**
|
316 |
* <p>Returns if this layer is editable.</p>
|
317 |
* <p>One layer is editable if user can modify its information with graphical tools.</p>
|
318 |
*
|
319 |
* @return <code>true</code> if this layer is editable; <code>false</code> otherwise
|
320 |
*
|
321 |
* @see #setEditing(boolean)
|
322 |
*/
|
323 |
public boolean isEditing(); |
324 |
|
325 |
/**
|
326 |
* Returns the image icon that will be shown in the TOC next to this layer.
|
327 |
*
|
328 |
* @return a String reference to the image icon, or <code>null</code> if there isn't any
|
329 |
*/
|
330 |
public String getTocImageIcon(); |
331 |
|
332 |
/**
|
333 |
* <p>Returns if this layer appears in the TOC.</p>
|
334 |
* <p>If doesn't appears, remains in the view and in the project.</p>
|
335 |
*
|
336 |
* @return <code>true</code> if this layer appears in the TOC; <code>false</code> otherwise
|
337 |
*/
|
338 |
boolean isInTOC();
|
339 |
/**
|
340 |
* <p>Sets that this layer appears or not in the TOC.</p>
|
341 |
*
|
342 |
* @param b <code>true</code> if appears in the TOC; <code>false</code> otherwise
|
343 |
*/
|
344 |
void setInTOC(boolean b); |
345 |
/**
|
346 |
* Returns the status of this layer.
|
347 |
*
|
348 |
* @return the status stored in a <code>FLayerStatus</code> object
|
349 |
*
|
350 |
* @see #setFLayerStatus(FLayerStatus)
|
351 |
*/
|
352 |
public FLayerStatus getFLayerStatus();
|
353 |
/**
|
354 |
* Sets the status of this layer.
|
355 |
*
|
356 |
* @param status information of the status for this layer
|
357 |
*
|
358 |
* @see #getFLayerStatus()
|
359 |
*/
|
360 |
public void setFLayerStatus(FLayerStatus status); |
361 |
/*
|
362 |
* This stuff is to save error's info that causes
|
363 |
* unavailable status.
|
364 |
* */
|
365 |
/**
|
366 |
* <p>Returns if this layer hasn't got errors.</p>
|
367 |
*
|
368 |
* @return <code>true</code> if this layer hasn't got errors; <code>false</code> otherwise
|
369 |
*/
|
370 |
public boolean isOk(); |
371 |
/**
|
372 |
* Returns the number of errors which causes this layer to be in unavailable status.
|
373 |
*
|
374 |
* @return number of errors >= 0
|
375 |
*
|
376 |
* @see #getError(int)
|
377 |
* @see #getErrors()
|
378 |
*/
|
379 |
public int getNumErrors(); |
380 |
|
381 |
/**
|
382 |
* Returns the specified error.
|
383 |
*
|
384 |
* @param i index of the error >= 0 && < <code>getNumErrors</code>
|
385 |
*
|
386 |
* @return a singular error
|
387 |
*
|
388 |
* @see #getNumErrors()
|
389 |
* @see #getErrors()
|
390 |
*/
|
391 |
public Throwable getError(int i); |
392 |
|
393 |
/**
|
394 |
* Adds an error reason that describes this layer's wrong status.
|
395 |
*
|
396 |
* @param exception
|
397 |
* a <code>BaseException</code> with the information of the error
|
398 |
*
|
399 |
* @see #getNumErrors()
|
400 |
* @see #getError(int)
|
401 |
* @see #getErrors()
|
402 |
*/
|
403 |
public void addError(Throwable exception); |
404 |
|
405 |
public void setError(Throwable ex); |
406 |
|
407 |
/**
|
408 |
* Returns a list with all layer errors.
|
409 |
*
|
410 |
* @return an <code>ArrayList</code> with the errors
|
411 |
*
|
412 |
* @see #getError(int)
|
413 |
* @see #getNumErrors()
|
414 |
*/
|
415 |
public List<Throwable> getErrors(); |
416 |
/**
|
417 |
* <p>Changes the status of availability of this layer.</p>
|
418 |
* <p>One layer is available if the source of data is on-line.</p>
|
419 |
*
|
420 |
* @param available the boolean to be set
|
421 |
*
|
422 |
* @see #isAvailable()
|
423 |
*/
|
424 |
public void setAvailable(boolean available); |
425 |
/**
|
426 |
* <p>Returns the status of availability of this layer.</p>
|
427 |
* <p>One layer is available if the source of data is on-line.</p>
|
428 |
*
|
429 |
* @return <code>true</code> if the source of data is on-line; <code>false</code> otherwise
|
430 |
*
|
431 |
* @see #setAvailable(boolean)
|
432 |
* @see #isVisible()
|
433 |
*/
|
434 |
public boolean isAvailable(); |
435 |
|
436 |
/**
|
437 |
* <p>
|
438 |
* Tries recover a layer of a possible error.
|
439 |
* </p>
|
440 |
* <p>
|
441 |
* If it has any problem during the load, marks the availability to false
|
442 |
* and throws an exception.
|
443 |
* </p>
|
444 |
*
|
445 |
* @throws ReloadLayerException
|
446 |
* if it's thrown a <code>ReadException</code> or an
|
447 |
* <code>IOException</code> during the load of this layer.
|
448 |
*
|
449 |
* @see #load()
|
450 |
*/
|
451 |
public void reload() throws ReloadLayerException; |
452 |
|
453 |
/**
|
454 |
* Returns <code>true</code> if this layer has the visible status enabled.
|
455 |
*
|
456 |
* @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
|
457 |
*
|
458 |
* @see #isVisible()
|
459 |
* @see #setVisible(boolean)
|
460 |
*/
|
461 |
boolean visibleRequired();
|
462 |
/**
|
463 |
* Returns an string with the information of this layer.
|
464 |
*
|
465 |
* @return the string that is to be this component's information
|
466 |
*/
|
467 |
public String getInfoString(); |
468 |
/**
|
469 |
* <p>Returns the writing status of this layer.</p>
|
470 |
* <p>One layer is writable if there is a writing driver for this layer.</p>
|
471 |
*
|
472 |
* @return <code>true</code> if there is a writing driver for this layer; <code>false</code> otherwise
|
473 |
*/
|
474 |
public boolean isWritable(); |
475 |
|
476 |
/**
|
477 |
* <p>This method can be used to have a fast cloned layer.</p>
|
478 |
* <p>The implementations should take care of not recreate this layer. Instead of this,
|
479 |
* is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
|
480 |
* the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
|
481 |
* <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
|
482 |
*
|
483 |
* @return a layer that is a clonation of this layer
|
484 |
*
|
485 |
* @throws java.lang.Exception any exception produced during the cloning of this layer.
|
486 |
*/
|
487 |
public FLayer cloneLayer() throws Exception; |
488 |
|
489 |
/**
|
490 |
* <p>Returns a new instance of {@link ComposedLayer ComposedLayer}.</p>
|
491 |
*
|
492 |
* <p>This allows make a single draw for a group
|
493 |
* of layers with the same source.</p>
|
494 |
*
|
495 |
* <p>If this operation isn't applicable for this
|
496 |
* kind of layer, this method returns null.</p>
|
497 |
*
|
498 |
* <p>By default this operation is not supported.</p>
|
499 |
*
|
500 |
* @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer
|
501 |
*
|
502 |
* @return a new composed layer or <code>null</code> if not supported
|
503 |
*/
|
504 |
public ComposedLayer newComposedLayer();
|
505 |
|
506 |
/**
|
507 |
* Returns the image icon that will be shown in the TOC next to this layer, according its status.
|
508 |
*
|
509 |
* @return the image
|
510 |
*/
|
511 |
Image getTocStatusImage();
|
512 |
|
513 |
/**
|
514 |
* <p>Sets the projection to this layer.</p>
|
515 |
*
|
516 |
* @param proj information about the new projection
|
517 |
*
|
518 |
*/
|
519 |
public void setProjection(IProjection proj); |
520 |
|
521 |
public long getDrawVersion(); |
522 |
|
523 |
public boolean isTemporary(); |
524 |
|
525 |
public void setTemporary(boolean temporary); |
526 |
|
527 |
/**
|
528 |
* Do nothing.
|
529 |
*
|
530 |
* @param b
|
531 |
* @throws org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException
|
532 |
* @deprecated Editing status is managed internally by layer, cannot be assigned here.
|
533 |
*/
|
534 |
public void setEditing(boolean b) throws StartEditionLayerException; |
535 |
|
536 |
/**
|
537 |
* Alwais return false
|
538 |
* @return false
|
539 |
* @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
|
540 |
*/
|
541 |
public boolean allowLinks(); |
542 |
|
543 |
/**
|
544 |
* Alwais return null.
|
545 |
* @return null
|
546 |
* @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
|
547 |
*/
|
548 |
public AbstractLinkProperties getLinkProperties();
|
549 |
|
550 |
/**
|
551 |
* alwais return null
|
552 |
*
|
553 |
* @param point
|
554 |
* @param tolerance
|
555 |
* @return null
|
556 |
* @throws org.gvsig.fmap.dal.exception.ReadException
|
557 |
* @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
|
558 |
*/
|
559 |
public URI[] getLink(Point2D point, double tolerance) throws ReadException; |
560 |
|
561 |
|
562 |
|
563 |
} |