root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / GraphicLayer.java @ 2970
History | View | Annotate | Download (4.94 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.v02.FSymbol; |
54 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
55 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
56 |
|
57 |
public class GraphicLayer extends FLyrDefault { |
58 |
private ArrayList graphics = new ArrayList(); |
59 |
private ArrayList symbols = new ArrayList(); |
60 |
private Rectangle2D fullExtent; |
61 |
|
62 |
public GraphicLayer() {
|
63 |
super();
|
64 |
// TODO Auto-generated constructor stub
|
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
69 |
*/
|
70 |
public Rectangle2D getFullExtent() throws DriverException { |
71 |
return fullExtent;
|
72 |
} |
73 |
|
74 |
/* (non-Javadoc)
|
75 |
* @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)
|
76 |
*/
|
77 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
78 |
if (isVisible() && isWithinScale(scale)){
|
79 |
drawGraphics(image, g, viewPort, cancel); |
80 |
} |
81 |
} |
82 |
|
83 |
/* (non-Javadoc)
|
84 |
* @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)
|
85 |
*/
|
86 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
87 |
if (isVisible() && isWithinScale(scale)){
|
88 |
drawGraphics(null, g, viewPort, cancel);
|
89 |
} |
90 |
} |
91 |
|
92 |
private void drawGraphics(BufferedImage image, Graphics2D g, |
93 |
ViewPort viewPort, Cancellable cancel) |
94 |
{ |
95 |
int numReg;
|
96 |
Rectangle2D elExtent = viewPort.getExtent();
|
97 |
if (elExtent == null) return; |
98 |
|
99 |
//int anchoMapa;
|
100 |
//int altoMapa;
|
101 |
//double anchoReal;
|
102 |
//double altoReal;
|
103 |
//double escala;
|
104 |
FSymbol theSymbol = null;
|
105 |
System.out.println("Dibujando gr?ficos..."); |
106 |
|
107 |
for (numReg = 0; numReg < graphics.size(); numReg++) { |
108 |
if (cancel.isCanceled()) {
|
109 |
break;
|
110 |
} |
111 |
|
112 |
FGraphic theGraphic = (FGraphic) graphics.get(numReg); |
113 |
|
114 |
if (theGraphic.getGeom().fastIntersects(elExtent.getMinX(),
|
115 |
elExtent.getMinY(), elExtent.getWidth(), elExtent.getHeight())) |
116 |
{ |
117 |
theSymbol = (FSymbol) symbols.get(theGraphic.getIdSymbol()); |
118 |
theGraphic.getGeom().draw(g,viewPort,theSymbol); |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
public int addSymbol(FSymbol newSymbol) |
124 |
{ |
125 |
if (symbols.add(newSymbol))
|
126 |
return symbols.size()-1; |
127 |
return -1; |
128 |
|
129 |
} |
130 |
/**
|
131 |
* Add a graphic to the graphic layer.
|
132 |
* @param g
|
133 |
* @return index of graphic created.
|
134 |
*/
|
135 |
public int addGraphic(FGraphic g) |
136 |
{ |
137 |
if (graphics.add(g))
|
138 |
{ |
139 |
if (fullExtent == null) { |
140 |
fullExtent = g.getGeom().getBounds2D(); |
141 |
} else {
|
142 |
fullExtent.add(g.getGeom().getBounds2D()); |
143 |
} |
144 |
|
145 |
return graphics.size()-1; |
146 |
} |
147 |
return -1; |
148 |
|
149 |
} |
150 |
|
151 |
/**
|
152 |
*
|
153 |
*/
|
154 |
public void clearAllGraphics() |
155 |
{ |
156 |
System.err.println("Clear all graphics. Antes hab?a " + graphics.size()); |
157 |
graphics.clear(); |
158 |
} |
159 |
/**
|
160 |
*
|
161 |
*/
|
162 |
public void clearSymbolsGraphics() |
163 |
{ |
164 |
symbols.clear(); |
165 |
} |
166 |
|
167 |
} |