root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / ProjectExtent.java @ 32880
History | View | Annotate | Download (4.29 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2009 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 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 |
package org.gvsig.app.project; |
29 |
|
30 |
import java.awt.geom.Rectangle2D; |
31 |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.GeometryManager; |
35 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
36 |
import org.gvsig.fmap.geom.primitive.Envelope; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.tools.persistence.Persistent; |
39 |
import org.gvsig.tools.persistence.PersistentState; |
40 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
|
45 |
/**
|
46 |
*
|
47 |
* @author 2006-2009 Jose Manuel Vivo
|
48 |
* @author 2005- Vicente Caballero
|
49 |
* @author 2009- Joaquin del Cerro
|
50 |
*
|
51 |
*/
|
52 |
|
53 |
public class ProjectExtent implements Persistent { |
54 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
55 |
private static final Logger logger = LoggerFactory.getLogger(ProjectExtent.class); |
56 |
|
57 |
private Envelope extent;
|
58 |
private String description; |
59 |
|
60 |
public ProjectExtent() {
|
61 |
this.extent = null; |
62 |
this.description = null; |
63 |
} |
64 |
|
65 |
public String getDescription() { |
66 |
return description;
|
67 |
} |
68 |
|
69 |
public void setDescription(String string) { |
70 |
description = string; |
71 |
} |
72 |
|
73 |
public Envelope getExtent() {
|
74 |
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 |
} |
83 |
|
84 |
public void setExtent(Envelope envelope) { |
85 |
this.extent = envelope;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* @deprecated use {link {@link #setExtent(Envelope)}
|
90 |
*/
|
91 |
public void setExtent(Rectangle2D rectangle2D) { |
92 |
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 |
} |
104 |
|
105 |
public String getEncuadre() { |
106 |
Point lower = extent.getLowerCorner();
|
107 |
Point upper = extent.getUpperCorner();
|
108 |
return lower.getX() + "," + lower.getY() + "," + upper.getX() + "," + upper.getY(); |
109 |
} |
110 |
|
111 |
public void setEncuadre(String encuadre) { |
112 |
String[] coords = encuadre.split(","); |
113 |
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 |
} |
128 |
|
129 |
/**
|
130 |
* @see java.lang.Object#toString()
|
131 |
*/
|
132 |
public String toString() { |
133 |
return description;
|
134 |
} |
135 |
|
136 |
public void loadFromState(PersistentState state) |
137 |
throws PersistenceException {
|
138 |
this.extent = (Envelope) state.get("envelope"); |
139 |
this.description = state.getString("description"); |
140 |
} |
141 |
|
142 |
public void saveToState(PersistentState state) throws PersistenceException { |
143 |
state.set("description", description);
|
144 |
state.set("envelope", extent);
|
145 |
} |
146 |
|
147 |
} |