root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / ProjectExtent.java @ 38601
History | View | Annotate | Download (4.29 KB)
1 | 31496 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2009 Infrastructures and Transports Department
|
||
4 | 31544 | cordinyana | * of the Valencian Government (CIT)
|
5 | 31496 | jjdelcerro | *
|
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2004-2009 IVER TI
|
||
26 | *
|
||
27 | */
|
||
28 | 29598 | jpiera | package org.gvsig.app.project; |
29 | 1222 | fernando | |
30 | import java.awt.geom.Rectangle2D; |
||
31 | |||
32 | 31496 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
33 | 27419 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
34 | import org.gvsig.fmap.geom.GeometryManager; |
||
35 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
36 | 21530 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
37 | 31496 | jjdelcerro | import org.gvsig.fmap.geom.primitive.Point; |
38 | import org.gvsig.tools.persistence.Persistent; |
||
39 | import org.gvsig.tools.persistence.PersistentState; |
||
40 | 32880 | jjdelcerro | import org.gvsig.tools.persistence.exception.PersistenceException; |
41 | 27419 | jpiera | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; |
||
43 | 21530 | vcaballero | |
44 | 1222 | fernando | |
45 | /**
|
||
46 | *
|
||
47 | 31496 | jjdelcerro | * @author 2006-2009 Jose Manuel Vivo
|
48 | * @author 2005- Vicente Caballero
|
||
49 | * @author 2009- Joaquin del Cerro
|
||
50 | *
|
||
51 | 1222 | fernando | */
|
52 | 31496 | jjdelcerro | |
53 | public class ProjectExtent implements Persistent { |
||
54 | 27419 | jpiera | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
55 | private static final Logger logger = LoggerFactory.getLogger(ProjectExtent.class); |
||
56 | 31496 | jjdelcerro | |
57 | private Envelope extent;
|
||
58 | 1222 | fernando | private String description; |
59 | |||
60 | 31496 | jjdelcerro | public ProjectExtent() {
|
61 | this.extent = null; |
||
62 | this.description = null; |
||
63 | } |
||
64 | |||
65 | 1222 | fernando | public String getDescription() { |
66 | return description;
|
||
67 | } |
||
68 | |||
69 | 31496 | jjdelcerro | public void setDescription(String string) { |
70 | description = string; |
||
71 | } |
||
72 | |||
73 | 21530 | vcaballero | public Envelope getExtent() {
|
74 | 31496 | jjdelcerro | if( this.extent == null ) { |
75 | try {
|
||
76 | this.extent = geomManager.createEnvelope(Geometry.SUBTYPES.GEOM2D);
|
||
77 | } catch (CreateEnvelopeException e) {
|
||
78 | logger.warn("Can't create envelop.", e);
|
||
79 | } |
||
80 | } |
||
81 | return this.extent; |
||
82 | 1222 | fernando | } |
83 | |||
84 | 31496 | jjdelcerro | public void setExtent(Envelope envelope) { |
85 | this.extent = envelope;
|
||
86 | 1222 | fernando | } |
87 | |||
88 | /**
|
||
89 | 31496 | jjdelcerro | * @deprecated use {link {@link #setExtent(Envelope)}
|
90 | 1222 | fernando | */
|
91 | public void setExtent(Rectangle2D rectangle2D) { |
||
92 | 31496 | jjdelcerro | try {
|
93 | this.extent = geomManager.createEnvelope(
|
||
94 | rectangle2D.getMinX(), |
||
95 | rectangle2D.getMinY(), |
||
96 | rectangle2D.getMaxX(), |
||
97 | rectangle2D.getMaxY(), |
||
98 | Geometry.SUBTYPES.GEOM2D); |
||
99 | } catch (CreateEnvelopeException e) {
|
||
100 | logger.warn("Can't create envelope.", e);
|
||
101 | throw new RuntimeException("Can't create envelope.",e); |
||
102 | } |
||
103 | 1222 | fernando | } |
104 | |||
105 | public String getEncuadre() { |
||
106 | 31496 | jjdelcerro | Point lower = extent.getLowerCorner();
|
107 | Point upper = extent.getUpperCorner();
|
||
108 | return lower.getX() + "," + lower.getY() + "," + upper.getX() + "," + upper.getY(); |
||
109 | 1222 | fernando | } |
110 | |||
111 | public void setEncuadre(String encuadre) { |
||
112 | String[] coords = encuadre.split(","); |
||
113 | 31496 | jjdelcerro | try {
|
114 | this.extent = geomManager.createEnvelope(
|
||
115 | Double.parseDouble(coords[0]), |
||
116 | Double.parseDouble(coords[1]), |
||
117 | Double.parseDouble(coords[2]), |
||
118 | Double.parseDouble(coords[3]), |
||
119 | Geometry.SUBTYPES.GEOM2D); |
||
120 | } catch (NumberFormatException e) { |
||
121 | logger.warn("Incorrect format string.", e);
|
||
122 | throw new RuntimeException("Incorrect format string.",e); |
||
123 | } catch (CreateEnvelopeException e) {
|
||
124 | logger.warn("Can't create envelope.", e);
|
||
125 | throw new RuntimeException("Can't create envelope.",e); |
||
126 | } |
||
127 | 1222 | fernando | } |
128 | |||
129 | /**
|
||
130 | * @see java.lang.Object#toString()
|
||
131 | */
|
||
132 | public String toString() { |
||
133 | return description;
|
||
134 | } |
||
135 | |||
136 | 31496 | jjdelcerro | public void loadFromState(PersistentState state) |
137 | throws PersistenceException {
|
||
138 | this.extent = (Envelope) state.get("envelope"); |
||
139 | this.description = state.getString("description"); |
||
140 | } |
||
141 | 1222 | fernando | |
142 | 31496 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
143 | state.set("description", description);
|
||
144 | state.set("envelope", extent);
|
||
145 | } |
||
146 | 1222 | fernando | |
147 | } |