root / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiLayerFillSymbol.java @ 10450
History | View | Annotate | Download (7.62 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: MultiLayerFillSymbol.java 10450 2007-02-21 16:09:35Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.3 2007-02-21 16:09:02 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.2 2007/02/21 07:34:09 jaume
|
50 |
* labeling starts working
|
51 |
*
|
52 |
* Revision 1.1.2.1 2007/02/16 10:54:12 jaume
|
53 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.cit.gvsig.fmap.core.symbols; |
58 |
|
59 |
import java.awt.Color; |
60 |
import java.awt.Graphics2D; |
61 |
import java.awt.Rectangle; |
62 |
import java.awt.Shape; |
63 |
import java.awt.geom.AffineTransform; |
64 |
import java.util.ArrayList; |
65 |
|
66 |
import javax.print.attribute.PrintRequestAttributeSet; |
67 |
|
68 |
import com.iver.cit.gvsig.fmap.DriverException; |
69 |
import com.iver.cit.gvsig.fmap.core.FShape; |
70 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
71 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
72 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
73 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
74 |
import com.iver.utiles.XMLEntity; |
75 |
|
76 |
public class MultiLayerFillSymbol extends AbstractSymbol implements IFillSymbol, IMultiLayerSymbol{ |
77 |
private IFillSymbol[] layers = new IFillSymbol[0]; |
78 |
private MultiLayerFillSymbol selectionSymbol;
|
79 |
private Object symbolType; |
80 |
|
81 |
public Color getFillColor() { |
82 |
/*
|
83 |
* a multilayer symbol does not define any color, the color
|
84 |
* of each layer is defined by the layer itself
|
85 |
*/
|
86 |
return null; |
87 |
} |
88 |
|
89 |
public int getOnePointRgb() { |
90 |
// will paint only the last layer pixel
|
91 |
return layers[layers.length-1].getOnePointRgb(); |
92 |
} |
93 |
|
94 |
public ILineSymbol getOutline() {
|
95 |
/*
|
96 |
* a multilayer symbol does not define any outline, the outline
|
97 |
* of each layer is defined by the layer it self
|
98 |
*/
|
99 |
return null; |
100 |
} |
101 |
|
102 |
public boolean isSuitableFor(IGeometry geom) { |
103 |
return geom.getGeometryType() == FShape.POLYGON;
|
104 |
} |
105 |
|
106 |
public void setFillColor(Color color) { |
107 |
/*
|
108 |
* Will apply the color to each layer
|
109 |
*/
|
110 |
for (int i = 0; i < layers.length; i++) { |
111 |
layers[i].setFillColor(color); |
112 |
} |
113 |
} |
114 |
|
115 |
public void setOutline(ILineSymbol outline) { |
116 |
for (int i = 0; i < layers.length; i++) { |
117 |
layers[i].setOutline(outline); |
118 |
} |
119 |
} |
120 |
|
121 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
122 |
for (int i = 0; i < layers.length; i++) { |
123 |
layers[i].draw(g, affineTransform, shp); |
124 |
} |
125 |
} |
126 |
|
127 |
public void drawInsideRectangle(Graphics2D g, |
128 |
AffineTransform scaleInstance, Rectangle r) { |
129 |
for (int i = 0; i < layers.length; i++) { |
130 |
layers[i].drawInsideRectangle(g, scaleInstance, r); |
131 |
} |
132 |
} |
133 |
|
134 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
135 |
Shape shp) {
|
136 |
// TODO Implement it
|
137 |
throw new Error("Not yet implemented!"); |
138 |
|
139 |
} |
140 |
|
141 |
public ISymbol getSymbolForSelection() {
|
142 |
if (selectionSymbol == null) { |
143 |
selectionSymbol = new MultiLayerFillSymbol();
|
144 |
selectionSymbol.setDescription(getDescription()); |
145 |
selectionSymbol.symbolType = symbolType; |
146 |
for (int i = 0; i < layers.length; i++) { |
147 |
selectionSymbol.addLayer(layers[i].getSymbolForSelection()); |
148 |
} |
149 |
SimpleFillSymbol selLayer = new SimpleFillSymbol();
|
150 |
selLayer.setFillColor(FSymbol.getSelectionColor()); |
151 |
selLayer.setOutline(getOutline()); |
152 |
selectionSymbol.addLayer(selLayer); |
153 |
} |
154 |
return selectionSymbol;
|
155 |
|
156 |
} |
157 |
|
158 |
|
159 |
public int getSymbolType() { |
160 |
return FShape.POLYGON;
|
161 |
} |
162 |
|
163 |
public XMLEntity getXMLEntity() {
|
164 |
XMLEntity xml = new XMLEntity();
|
165 |
xml.putProperty("className", getClassName());
|
166 |
xml.putProperty("desc", getDescription());
|
167 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
168 |
for (int i = 0; i < layers.length; i++) { |
169 |
xml.addChild(layers[i].getXMLEntity()); |
170 |
} |
171 |
return xml;
|
172 |
} |
173 |
|
174 |
public void setPrintingProperties(PrintRequestAttributeSet printProperties) { |
175 |
// TODO Implement it
|
176 |
throw new Error("Not yet implemented!"); |
177 |
|
178 |
} |
179 |
|
180 |
public String getClassName() { |
181 |
return getClass().getName();
|
182 |
} |
183 |
|
184 |
public void setXMLEntity(XMLEntity xml) { |
185 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
186 |
setDescription(xml.getStringProperty("desc"));
|
187 |
layers = new IFillSymbol[xml.getChildrenCount()];
|
188 |
for (int i = 0; i < layers.length; i++) { |
189 |
layers[i] = (IFillSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(i), "layer" + i);
|
190 |
} |
191 |
} |
192 |
|
193 |
public void print(Graphics2D g, AffineTransform at, FShape shape) |
194 |
throws DriverException {
|
195 |
// TODO Implement it
|
196 |
throw new Error("Not yet implemented!"); |
197 |
|
198 |
} |
199 |
|
200 |
public void setLayer(int index, ISymbol layer) throws IndexOutOfBoundsException { |
201 |
layers[index] = (IFillSymbol) layer; |
202 |
} |
203 |
|
204 |
public void swapLayers(int index1, int index2) { |
205 |
ISymbol aux1 = getLayer(index1), aux2 = getLayer(index2); |
206 |
layers[index2] = (IFillSymbol) aux1; |
207 |
layers[index1] = (IFillSymbol) aux2; |
208 |
} |
209 |
|
210 |
public ISymbol getLayer(int layerIndex) { |
211 |
try{
|
212 |
return layers[layerIndex];
|
213 |
} catch (Exception e) { |
214 |
return null; |
215 |
} |
216 |
} |
217 |
|
218 |
public int getLayerCount() { |
219 |
return layers.length;
|
220 |
} |
221 |
|
222 |
public void addLayer(ISymbol newLayer) { |
223 |
if (newLayer == null) return; |
224 |
|
225 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
226 |
* next time it is required
|
227 |
*/
|
228 |
int size = layers.length+1; |
229 |
IFillSymbol[] newLayers = new IFillSymbol[size]; |
230 |
for (int i = 0; i < newLayers.length-1; i++) { |
231 |
newLayers[i] = layers[i]; |
232 |
} |
233 |
newLayers[size-1] = (IFillSymbol) newLayer;
|
234 |
layers = newLayers; |
235 |
} |
236 |
|
237 |
public void addLayer(ISymbol newLayer, int layerIndex) throws IndexOutOfBoundsException { |
238 |
if (newLayer == null || newLayer instanceof ILabelStyle) return; // null or symbols that are styles are not allowed |
239 |
|
240 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
241 |
* next time it is required
|
242 |
*/
|
243 |
if (layerIndex < 0 || layers.length < layerIndex) |
244 |
throw new IndexOutOfBoundsException(layerIndex+" < 0 or "+layerIndex+" > "+layers.length); |
245 |
ArrayList newLayers = new ArrayList(); |
246 |
for (int i = 0; i < layers.length; i++) { |
247 |
newLayers.add(layers[i]); |
248 |
} |
249 |
newLayers.add(layerIndex, newLayer); |
250 |
layers = (IFillSymbol[]) newLayers.toArray(new IFillSymbol[0]); |
251 |
} |
252 |
|
253 |
public boolean removeLayer(ISymbol layer) { |
254 |
|
255 |
int capacity = 0; |
256 |
capacity = layers.length; |
257 |
ArrayList lst = new ArrayList(capacity); |
258 |
for (int i = 0; i < capacity; i++) { |
259 |
lst.add(layers[i]); |
260 |
} |
261 |
boolean contains = lst.remove(layer);
|
262 |
layers = (IFillSymbol[])lst.toArray(new IFillSymbol[0]); |
263 |
return contains;
|
264 |
} |
265 |
|
266 |
public int getFillAlpha() { |
267 |
// will compute the acumulated opacity
|
268 |
double myAlpha = 0; |
269 |
for (int i = 0; i < layers.length; i++) { |
270 |
double layerAlpha = layers[i].getFillAlpha()/255D; |
271 |
myAlpha += (1-myAlpha)*layerAlpha;
|
272 |
} |
273 |
int result = (int) Math.round(myAlpha * 255); |
274 |
return (result>255) ? 255 : result; |
275 |
} |
276 |
|
277 |
} |