Revision 9524 branches/piloto3d/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/GraphicLayer.java
GraphicLayer.java | ||
---|---|---|
2 | 2 |
* Created on 19-sep-2005 |
3 | 3 |
* |
4 | 4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
7 |
*
|
|
7 |
* |
|
8 | 8 |
* This program is free software; you can redistribute it and/or |
9 | 9 |
* modify it under the terms of the GNU General Public License |
10 | 10 |
* as published by the Free Software Foundation; either version 2 |
11 | 11 |
* of the License, or (at your option) any later version. |
12 |
*
|
|
12 |
* |
|
13 | 13 |
* This program is distributed in the hope that it will be useful, |
14 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 |
*
|
|
17 |
* |
|
18 | 18 |
* You should have received a copy of the GNU General Public License |
19 | 19 |
* along with this program; if not, write to the Free Software |
20 | 20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* For more information, contact: |
23 | 23 |
* |
24 | 24 |
* Generalitat Valenciana |
... | ... | |
30 | 30 |
* +34 963862235 |
31 | 31 |
* gvsig@gva.es |
32 | 32 |
* www.gvsig.gva.es |
33 |
*
|
|
33 |
* |
|
34 | 34 |
* or |
35 |
*
|
|
35 |
* |
|
36 | 36 |
* IVER T.I. S.A |
37 | 37 |
* Salamanca 50 |
38 | 38 |
* 46005 Valencia |
39 | 39 |
* Spain |
40 |
*
|
|
40 |
* |
|
41 | 41 |
* +34 963163400 |
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
... | ... | |
47 | 47 |
import java.awt.geom.Rectangle2D; |
48 | 48 |
import java.awt.image.BufferedImage; |
49 | 49 |
import java.util.ArrayList; |
50 |
import java.util.Collection; |
|
50 | 51 |
|
52 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
53 |
|
|
51 | 54 |
import org.cresques.cts.ICoordTrans; |
52 | 55 |
|
53 | 56 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 | 57 |
import com.iver.cit.gvsig.fmap.ViewPort; |
55 | 58 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
59 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
56 | 60 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
58 | 61 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
59 | 62 |
import com.iver.utiles.swing.threads.Cancellable; |
60 | 63 |
import com.vividsolutions.jts.index.ItemVisitor; |
... | ... | |
84 | 87 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double) |
85 | 88 |
*/ |
86 | 89 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
87 |
if (isVisible() && isWithinScale(scale)){
|
|
90 |
if (isVisible() && isWithinScale(scale)){ |
|
88 | 91 |
drawGraphics(image, g, viewPort, cancel); |
89 |
}
|
|
92 |
} |
|
90 | 93 |
} |
91 |
|
|
94 |
|
|
92 | 95 |
/** |
93 |
* Generic visitor pattern. It may be used for queryByRect, byPoint,
|
|
96 |
* Generic visitor pattern. It may be used for queryByRect, byPoint, |
|
94 | 97 |
* by polygon, etc. |
95 | 98 |
* @param visitor |
96 | 99 |
* @param cancel |
... | ... | |
98 | 101 |
public void process(ItemVisitor visitor, Cancellable cancel) |
99 | 102 |
{ |
100 | 103 |
int numReg; |
101 |
|
|
104 |
|
|
102 | 105 |
for (numReg = 0; numReg < graphics.size(); numReg++) { |
103 |
if (cancel.isCanceled()) { |
|
104 |
break; |
|
106 |
if(cancel != null){ |
|
107 |
if (cancel.isCanceled()) { |
|
108 |
break; |
|
109 |
} |
|
105 | 110 |
} |
106 |
|
|
107 | 111 |
FGraphic theGraphic = (FGraphic) graphics.get(numReg); |
108 | 112 |
visitor.visitItem(theGraphic); |
109 | 113 |
} |
110 |
|
|
114 |
|
|
111 | 115 |
} |
112 | 116 |
|
113 | 117 |
/* (non-Javadoc) |
114 | 118 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double) |
115 | 119 |
*/ |
116 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
|
117 |
if (isVisible() && isWithinScale(scale)){
|
|
120 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws DriverException {
|
|
121 |
if (isVisible() && isWithinScale(scale)){ |
|
118 | 122 |
drawGraphics(null, g, viewPort, cancel); |
119 |
}
|
|
123 |
} |
|
120 | 124 |
} |
121 |
|
|
125 |
|
|
122 | 126 |
private void drawGraphics(BufferedImage image, Graphics2D g, |
123 |
ViewPort viewPort, Cancellable cancel)
|
|
127 |
ViewPort viewPort, Cancellable cancel) |
|
124 | 128 |
{ |
125 | 129 |
int numReg; |
126 | 130 |
Rectangle2D elExtent = viewPort.getAdjustedExtent(); |
127 | 131 |
if (elExtent == null) return; |
128 |
|
|
132 |
|
|
129 | 133 |
//int anchoMapa; |
130 | 134 |
//int altoMapa; |
131 | 135 |
//double anchoReal; |
132 | 136 |
//double altoReal; |
133 | 137 |
//double escala; |
134 |
FSymbol theSymbol = null;
|
|
138 |
ISymbol theSymbol = null;
|
|
135 | 139 |
// System.out.println("Dibujando gr?ficos...(" + graphics.size() + ")"); |
136 |
|
|
140 |
|
|
137 | 141 |
ICoordTrans ct = getCoordTrans(); |
138 |
|
|
142 |
|
|
139 | 143 |
for (numReg = 0; numReg < graphics.size(); numReg++) { |
140 | 144 |
if (cancel.isCanceled()) { |
141 | 145 |
break; |
142 | 146 |
} |
143 |
|
|
147 |
|
|
144 | 148 |
FGraphic theGraphic = (FGraphic) graphics.get(numReg); |
145 | 149 |
IGeometry geom = theGraphic.getGeom(); |
146 |
|
|
150 |
|
|
147 | 151 |
// Modificaci?n para Jorge, para que le reproyecte los gr?ficos. |
148 | 152 |
if (ct != null) { |
149 | 153 |
geom = geom.cloneGeometry(); |
150 | 154 |
geom.reProject(ct); |
151 | 155 |
} |
152 |
|
|
153 |
if (geom.fastIntersects(elExtent.getMinX(),
|
|
156 |
|
|
157 |
if (geom.fastIntersects(elExtent.getMinX(), |
|
154 | 158 |
elExtent.getMinY(), elExtent.getWidth(), elExtent.getHeight())) |
155 | 159 |
{ |
156 |
theSymbol = (FSymbol) symbols.get(theGraphic.getIdSymbol()); |
|
160 |
theSymbol = (ISymbol) symbols.get(theGraphic.getIdSymbol()); |
|
161 |
if (theSymbol == null) |
|
162 |
continue; |
|
157 | 163 |
if (selection.get(numReg)) // Si est? seleccinado |
158 | 164 |
{ |
159 | 165 |
FGraphicUtilities.DrawHandlers(g, viewPort.getAffineTransform(), geom.getHandlers(IGeometry.SELECTHANDLER)); |
... | ... | |
164 | 170 |
} |
165 | 171 |
} |
166 | 172 |
} |
167 |
}
|
|
168 |
|
|
169 |
public int addSymbol(FSymbol newSymbol)
|
|
170 |
{
|
|
173 |
} |
|
174 |
|
|
175 |
public int addSymbol(ISymbol newSymbol)
|
|
176 |
{ |
|
171 | 177 |
if (symbols.add(newSymbol)) |
172 | 178 |
return symbols.size()-1; |
173 | 179 |
return -1; |
174 |
|
|
180 |
|
|
175 | 181 |
} |
176 | 182 |
/** |
177 | 183 |
* Add a graphic to the graphic layer. |
178 | 184 |
* @param g |
179 |
* @return index of graphic created. |
|
180 | 185 |
*/ |
181 |
public int addGraphic(FGraphic g)
|
|
186 |
public void addGraphic(FGraphic g)
|
|
182 | 187 |
{ |
183 | 188 |
if (graphics.add(g)) |
184 | 189 |
{ |
185 |
|
|
190 |
|
|
186 | 191 |
// spatialIndex.insert(g.getGeom().getBounds2D()) |
187 | 192 |
if (fullExtent == null) { |
188 | 193 |
fullExtent = g.getGeom().getBounds2D(); |
... | ... | |
190 | 195 |
fullExtent.add(g.getGeom().getBounds2D()); |
191 | 196 |
} |
192 | 197 |
|
193 |
return graphics.size()-1; |
|
198 |
// return graphics.size()-1;
|
|
194 | 199 |
} |
195 |
return -1; |
|
200 |
// return -1;
|
|
196 | 201 |
|
197 | 202 |
} |
203 |
|
|
204 |
public void insertGraphic(int position, FGraphic g) { |
|
205 |
graphics.add(position, g); |
|
206 |
if (fullExtent == null) { |
|
207 |
fullExtent = g.getGeom().getBounds2D(); |
|
208 |
} else { |
|
209 |
fullExtent.add(g.getGeom().getBounds2D()); |
|
210 |
} |
|
211 |
} |
|
198 | 212 |
|
199 | 213 |
/** |
200 |
*
|
|
214 |
* |
|
201 | 215 |
*/ |
202 | 216 |
public void clearAllGraphics() |
203 | 217 |
{ |
204 | 218 |
System.err.println("Clear all graphics. Antes hab?a " + graphics.size()); |
205 | 219 |
graphics.clear(); |
220 |
fullExtent = null; |
|
206 | 221 |
} |
207 | 222 |
/** |
208 |
*
|
|
223 |
* |
|
209 | 224 |
*/ |
210 | 225 |
public void clearSymbolsGraphics() |
211 | 226 |
{ |
... | ... | |
223 | 238 |
public FBitSet queryByRect(Rectangle2D r) { |
224 | 239 |
FBitSet newSel = new FBitSet(); |
225 | 240 |
for (int numReg = 0; numReg < graphics.size(); numReg++) { |
226 |
|
|
241 |
|
|
227 | 242 |
FGraphic theGraphic = (FGraphic) graphics.get(numReg); |
228 | 243 |
IGeometry geom = theGraphic.getGeom(); |
229 | 244 |
if (geom.intersects(r)) |
... | ... | |
233 | 248 |
} |
234 | 249 |
return newSel; |
235 | 250 |
} |
236 |
|
|
251 |
|
|
252 |
public void removeGraphic(FGraphic graphic) { |
|
253 |
graphics.remove(graphic); |
|
254 |
reCalculateFullExtent(); |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
public FGraphic getGraphic(int idGraphic) { |
|
259 |
return (FGraphic) graphics.get(idGraphic); |
|
260 |
} |
|
261 |
|
|
262 |
public FGraphic getGraphicByObjectTag(Object objectTag) { |
|
263 |
for (int i = 0; i < graphics.size(); i++) { |
|
264 |
FGraphic theGraphic = (FGraphic) graphics.get(i); |
|
265 |
if (theGraphic.getObjectTag() == objectTag) |
|
266 |
return theGraphic; |
|
267 |
} |
|
268 |
return null; |
|
269 |
} |
|
270 |
|
|
271 |
|
|
272 |
public int getNumGraphics() { |
|
273 |
return graphics.size(); |
|
274 |
} |
|
275 |
|
|
276 |
private void reCalculateFullExtent(){ |
|
277 |
if (graphics.size() > 0) { |
|
278 |
FGraphic g = (FGraphic) graphics.get(0); |
|
279 |
fullExtent = g.getGeom().getBounds2D(); |
|
280 |
for (int i = 1; i < graphics.size(); i++) { |
|
281 |
g = (FGraphic) graphics.get(i); |
|
282 |
Rectangle2D rAux = g.getGeom().getBounds2D(); |
|
283 |
|
|
284 |
fullExtent.add(rAux); |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
public void inserGraphics(int index, Collection c) { |
|
290 |
graphics.addAll(index, c); |
|
291 |
|
|
292 |
} |
|
293 |
|
|
294 |
public FLayer cloneLayer() throws Exception { |
|
295 |
GraphicLayer lyr = new GraphicLayer(); |
|
296 |
for (int i =0; i < symbols.size(); i++) |
|
297 |
{ |
|
298 |
lyr.addSymbol((ISymbol) symbols.get(i)); |
|
299 |
} |
|
300 |
for (int i =0; i < graphics.size(); i++) |
|
301 |
{ |
|
302 |
lyr.addGraphic((FGraphic) graphics.get(i)); |
|
303 |
} |
|
304 |
|
|
305 |
return lyr; |
|
306 |
} |
|
307 |
|
|
237 | 308 |
} |
Also available in: Unified diff