svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiLayerFillSymbol.java @ 10436
History | View | Annotate | Download (7.23 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 10436 2007-02-21 07:34:09Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.2 2007-02-21 07:34:09 jaume
|
47 |
* labeling starts working
|
48 |
*
|
49 |
* Revision 1.1.2.1 2007/02/16 10:54:12 jaume
|
50 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.cit.gvsig.fmap.core.symbols; |
55 |
|
56 |
import java.awt.Color; |
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.Rectangle; |
59 |
import java.awt.Shape; |
60 |
import java.awt.geom.AffineTransform; |
61 |
import java.util.ArrayList; |
62 |
|
63 |
import javax.print.attribute.PrintRequestAttributeSet; |
64 |
|
65 |
import com.iver.cit.gvsig.fmap.DriverException; |
66 |
import com.iver.cit.gvsig.fmap.core.FShape; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
69 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
70 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
71 |
import com.iver.utiles.XMLEntity; |
72 |
|
73 |
public class MultiLayerFillSymbol extends AbstractSymbol implements IFillSymbol, IMultiLayerSymbol{ |
74 |
private IFillSymbol[] layers = new IFillSymbol[0]; |
75 |
private MultiLayerFillSymbol selectionSymbol;
|
76 |
private Object symbolType; |
77 |
|
78 |
public Color getFillColor() { |
79 |
/*
|
80 |
* a multilayer symbol does not define any color, the color
|
81 |
* of each layer is defined by the layer itself
|
82 |
*/
|
83 |
return null; |
84 |
} |
85 |
|
86 |
public int getOnePointRgb() { |
87 |
// will paint only the last layer pixel
|
88 |
return layers[layers.length-1].getOnePointRgb(); |
89 |
} |
90 |
|
91 |
public ILineSymbol getOutline() {
|
92 |
/*
|
93 |
* a multilayer symbol does not define any outline, the outline
|
94 |
* of each layer is defined by the layer it self
|
95 |
*/
|
96 |
return null; |
97 |
} |
98 |
|
99 |
public boolean isSuitableFor(IGeometry geom) { |
100 |
return geom.getGeometryType() == FShape.POLYGON;
|
101 |
} |
102 |
|
103 |
public void setFillColor(Color color) { |
104 |
/*
|
105 |
* Will apply the color to each layer
|
106 |
*/
|
107 |
for (int i = 0; i < layers.length; i++) { |
108 |
layers[i].setFillColor(color); |
109 |
} |
110 |
} |
111 |
|
112 |
public void setOutline(ILineSymbol outline) { |
113 |
for (int i = 0; i < layers.length; i++) { |
114 |
layers[i].setOutline(outline); |
115 |
} |
116 |
} |
117 |
|
118 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
119 |
for (int i = 0; i < layers.length; i++) { |
120 |
layers[i].draw(g, affineTransform, shp); |
121 |
} |
122 |
} |
123 |
|
124 |
public void drawInsideRectangle(Graphics2D g, |
125 |
AffineTransform scaleInstance, Rectangle r) { |
126 |
for (int i = 0; i < layers.length; i++) { |
127 |
layers[i].drawInsideRectangle(g, scaleInstance, r); |
128 |
} |
129 |
} |
130 |
|
131 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
132 |
Shape shp) {
|
133 |
// TODO Implement it
|
134 |
throw new Error("Not yet implemented!"); |
135 |
|
136 |
} |
137 |
|
138 |
public ISymbol getSymbolForSelection() {
|
139 |
if (selectionSymbol == null) { |
140 |
selectionSymbol = new MultiLayerFillSymbol();
|
141 |
selectionSymbol.setDescription(getDescription()); |
142 |
selectionSymbol.symbolType = symbolType; |
143 |
for (int i = 0; i < layers.length; i++) { |
144 |
selectionSymbol.addLayer(layers[i].getSymbolForSelection()); |
145 |
} |
146 |
SimpleFillSymbol selLayer = new SimpleFillSymbol();
|
147 |
selLayer.setFillColor(FSymbol.getSelectionColor()); |
148 |
selLayer.setOutline(getOutline()); |
149 |
selectionSymbol.addLayer(selLayer); |
150 |
} |
151 |
return selectionSymbol;
|
152 |
|
153 |
} |
154 |
|
155 |
|
156 |
public int getSymbolType() { |
157 |
return FShape.POLYGON;
|
158 |
} |
159 |
|
160 |
public XMLEntity getXMLEntity() {
|
161 |
XMLEntity xml = new XMLEntity();
|
162 |
xml.putProperty("className", getClassName());
|
163 |
xml.putProperty("desc", getDescription());
|
164 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
165 |
for (int i = 0; i < layers.length; i++) { |
166 |
xml.addChild(layers[i].getXMLEntity()); |
167 |
} |
168 |
return xml;
|
169 |
} |
170 |
|
171 |
public void setPrintingProperties(PrintRequestAttributeSet printProperties) { |
172 |
// TODO Implement it
|
173 |
throw new Error("Not yet implemented!"); |
174 |
|
175 |
} |
176 |
|
177 |
public String getClassName() { |
178 |
return getClass().getName();
|
179 |
} |
180 |
|
181 |
public void setXMLEntity(XMLEntity xml) { |
182 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
183 |
setDescription(xml.getStringProperty("desc"));
|
184 |
layers = new IFillSymbol[xml.getChildrenCount()];
|
185 |
for (int i = 0; i < layers.length; i++) { |
186 |
layers[i] = (IFillSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(i), "layer" + i);
|
187 |
} |
188 |
} |
189 |
|
190 |
public void print(Graphics2D g, AffineTransform at, FShape shape) |
191 |
throws DriverException {
|
192 |
// TODO Implement it
|
193 |
throw new Error("Not yet implemented!"); |
194 |
|
195 |
} |
196 |
|
197 |
public void setLayer(int index, ISymbol layer) throws IndexOutOfBoundsException { |
198 |
layers[index] = (IFillSymbol) layer; |
199 |
} |
200 |
|
201 |
public void swapLayers(int index1, int index2) { |
202 |
ISymbol aux1 = getLayer(index1), aux2 = getLayer(index2); |
203 |
layers[index2] = (IFillSymbol) aux1; |
204 |
layers[index1] = (IFillSymbol) aux2; |
205 |
} |
206 |
|
207 |
public ISymbol getLayer(int layerIndex) { |
208 |
try{
|
209 |
return layers[layerIndex];
|
210 |
} catch (Exception e) { |
211 |
return null; |
212 |
} |
213 |
} |
214 |
|
215 |
public int getLayerCount() { |
216 |
return layers.length;
|
217 |
} |
218 |
|
219 |
public void addLayer(ISymbol newLayer) { |
220 |
if (newLayer == null) return; |
221 |
|
222 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
223 |
* next time it is required
|
224 |
*/
|
225 |
int size = layers.length+1; |
226 |
IFillSymbol[] newLayers = new IFillSymbol[size]; |
227 |
for (int i = 0; i < newLayers.length-1; i++) { |
228 |
newLayers[i] = layers[i]; |
229 |
} |
230 |
newLayers[size-1] = (IFillSymbol) newLayer;
|
231 |
layers = newLayers; |
232 |
} |
233 |
|
234 |
public void addLayer(ISymbol newLayer, int layerIndex) throws IndexOutOfBoundsException { |
235 |
if (newLayer == null || newLayer instanceof ILabelStyle) return; // null or symbols that are styles are not allowed |
236 |
|
237 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
238 |
* next time it is required
|
239 |
*/
|
240 |
if (layerIndex < 0 || layers.length < layerIndex) |
241 |
throw new IndexOutOfBoundsException(layerIndex+" < 0 or "+layerIndex+" > "+layers.length); |
242 |
ArrayList newLayers = new ArrayList(); |
243 |
for (int i = 0; i < layers.length; i++) { |
244 |
newLayers.add(layers[i]); |
245 |
} |
246 |
newLayers.add(layerIndex, newLayer); |
247 |
layers = (IFillSymbol[]) newLayers.toArray(new IFillSymbol[0]); |
248 |
} |
249 |
|
250 |
public boolean removeLayer(ISymbol layer) { |
251 |
|
252 |
int capacity = 0; |
253 |
capacity = layers.length; |
254 |
ArrayList lst = new ArrayList(capacity); |
255 |
for (int i = 0; i < capacity; i++) { |
256 |
lst.add(layers[i]); |
257 |
} |
258 |
boolean contains = lst.remove(layer);
|
259 |
layers = (IFillSymbol[])lst.toArray(new IFillSymbol[0]); |
260 |
return contains;
|
261 |
} |
262 |
|
263 |
} |