svn-gvsig-desktop / tags / Root_v061 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / GraphicLayer.java @ 4812
History | View | Annotate | Download (5.04 KB)
1 |
/*
|
---|---|
2 |
* Created on 19-sep-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.fmap.layers; |
45 |
|
46 |
import java.awt.Graphics2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.util.ArrayList; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.DriverException; |
52 |
import com.iver.cit.gvsig.fmap.ViewPort; |
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
55 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
56 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
57 |
|
58 |
public class GraphicLayer extends FLyrDefault { |
59 |
private ArrayList graphics = new ArrayList(); |
60 |
private ArrayList symbols = new ArrayList(); |
61 |
private Rectangle2D fullExtent; |
62 |
|
63 |
public GraphicLayer() {
|
64 |
super();
|
65 |
System.err.println("GraphicLayer: Constructor"); |
66 |
} |
67 |
|
68 |
/* (non-Javadoc)
|
69 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
70 |
*/
|
71 |
public Rectangle2D getFullExtent() throws DriverException { |
72 |
return fullExtent;
|
73 |
} |
74 |
|
75 |
/* (non-Javadoc)
|
76 |
* @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)
|
77 |
*/
|
78 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
79 |
if (isVisible() && isWithinScale(scale)){
|
80 |
drawGraphics(image, g, viewPort, cancel); |
81 |
} |
82 |
} |
83 |
|
84 |
/* (non-Javadoc)
|
85 |
* @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)
|
86 |
*/
|
87 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
88 |
if (isVisible() && isWithinScale(scale)){
|
89 |
drawGraphics(null, g, viewPort, cancel);
|
90 |
} |
91 |
} |
92 |
|
93 |
private void drawGraphics(BufferedImage image, Graphics2D g, |
94 |
ViewPort viewPort, Cancellable cancel) |
95 |
{ |
96 |
int numReg;
|
97 |
Rectangle2D elExtent = viewPort.getAdjustedExtent();
|
98 |
if (elExtent == null) return; |
99 |
|
100 |
//int anchoMapa;
|
101 |
//int altoMapa;
|
102 |
//double anchoReal;
|
103 |
//double altoReal;
|
104 |
//double escala;
|
105 |
FSymbol theSymbol = null;
|
106 |
System.out.println("Dibujando gr?ficos...(" + graphics.size() + ")"); |
107 |
|
108 |
for (numReg = 0; numReg < graphics.size(); numReg++) { |
109 |
if (cancel.isCanceled()) {
|
110 |
break;
|
111 |
} |
112 |
|
113 |
FGraphic theGraphic = (FGraphic) graphics.get(numReg); |
114 |
IGeometry geom = theGraphic.getGeom(); |
115 |
if (geom.fastIntersects(elExtent.getMinX(),
|
116 |
elExtent.getMinY(), elExtent.getWidth(), elExtent.getHeight())) |
117 |
{ |
118 |
theSymbol = (FSymbol) symbols.get(theGraphic.getIdSymbol()); |
119 |
theGraphic.draw(g, viewPort, theSymbol); |
120 |
} |
121 |
} |
122 |
} |
123 |
|
124 |
public int addSymbol(FSymbol newSymbol) |
125 |
{ |
126 |
if (symbols.add(newSymbol))
|
127 |
return symbols.size()-1; |
128 |
return -1; |
129 |
|
130 |
} |
131 |
/**
|
132 |
* Add a graphic to the graphic layer.
|
133 |
* @param g
|
134 |
* @return index of graphic created.
|
135 |
*/
|
136 |
public int addGraphic(FGraphic g) |
137 |
{ |
138 |
if (graphics.add(g))
|
139 |
{ |
140 |
if (fullExtent == null) { |
141 |
fullExtent = g.getGeom().getBounds2D(); |
142 |
} else {
|
143 |
fullExtent.add(g.getGeom().getBounds2D()); |
144 |
} |
145 |
|
146 |
return graphics.size()-1; |
147 |
} |
148 |
return -1; |
149 |
|
150 |
} |
151 |
|
152 |
/**
|
153 |
*
|
154 |
*/
|
155 |
public void clearAllGraphics() |
156 |
{ |
157 |
System.err.println("Clear all graphics. Antes hab?a " + graphics.size()); |
158 |
graphics.clear(); |
159 |
} |
160 |
/**
|
161 |
*
|
162 |
*/
|
163 |
public void clearSymbolsGraphics() |
164 |
{ |
165 |
symbols.clear(); |
166 |
} |
167 |
|
168 |
} |