root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiLayerSymbol.java @ 9919
History | View | Annotate | Download (7.56 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: MultiLayerSymbol.java 9919 2007-01-25 16:25:23Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.7 2007-01-25 16:25:23 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.6 2007/01/24 17:58:22 jaume
|
50 |
* new features and architecture error fixes
|
51 |
*
|
52 |
* Revision 1.5 2007/01/16 11:50:44 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.4 2007/01/12 10:08:26 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.3 2007/01/11 12:17:34 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
62 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
63 |
*
|
64 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
package com.iver.cit.gvsig.fmap.core.symbols; |
70 |
|
71 |
import java.awt.Graphics2D; |
72 |
import java.awt.Rectangle; |
73 |
import java.awt.Shape; |
74 |
import java.awt.geom.AffineTransform; |
75 |
import java.util.ArrayList; |
76 |
|
77 |
import javax.print.attribute.PrintRequestAttributeSet; |
78 |
|
79 |
import com.iver.cit.gvsig.fmap.core.FShape; |
80 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
81 |
import com.iver.cit.gvsig.fmap.core.SymbolFactory; |
82 |
import com.iver.utiles.XMLEntity; |
83 |
|
84 |
/**
|
85 |
* <p>Symbol that allows to combine many symbols into one and treat it
|
86 |
* as a single one. Within MultiLayerSymbol, each symbol is defined as a
|
87 |
* layer inside the MultiLayerSymbol.<br></p>
|
88 |
*
|
89 |
* <p>This symbol does not perform anything by itself. Rather than that it
|
90 |
* keeps a list of symbols and iterates over each element performing the
|
91 |
* operation over each one.<br></p>
|
92 |
*
|
93 |
* <p>The elements of the list can be any symbol, even other MultiLayerSymbol
|
94 |
* so, it is also possible to define symbols as a tree of symbols</p>
|
95 |
*
|
96 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
97 |
*
|
98 |
*/
|
99 |
public class MultiLayerSymbol extends AbstractSymbol { |
100 |
private ISymbol[] layers = new ISymbol[0]; |
101 |
private MultiLayerSymbol selectionSymbol;
|
102 |
private int symbolType; |
103 |
|
104 |
|
105 |
/**
|
106 |
* Gets the symbol in the layerIndex position of the symbol list.
|
107 |
* @param int layerIndex
|
108 |
* @return
|
109 |
*/
|
110 |
public ISymbol getLayer(int layerIndex) { |
111 |
try{
|
112 |
return layers[layerIndex];
|
113 |
} catch (Exception e) { |
114 |
return null; |
115 |
} |
116 |
} |
117 |
|
118 |
public int getLayerCount() { |
119 |
return layers.length;
|
120 |
} |
121 |
|
122 |
public ISymbol getSymbolForSelection() {
|
123 |
if (selectionSymbol == null) { |
124 |
selectionSymbol = new MultiLayerSymbol();
|
125 |
selectionSymbol.setDescription(getDescription()); |
126 |
selectionSymbol.symbolType = symbolType; |
127 |
for (int i = 0; i < layers.length; i++) { |
128 |
selectionSymbol.addLayer(layers[i].getSymbolForSelection()); |
129 |
} |
130 |
} |
131 |
return selectionSymbol;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Stacks a new symbol to the symbol list. The symbol is appended to the
|
136 |
* list and, in terms of use, it will be the last symbol to be processed.
|
137 |
* @param ISymbol newLayer
|
138 |
*/
|
139 |
public void addLayer(ISymbol newLayer) { |
140 |
if (newLayer == null) return; |
141 |
|
142 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
143 |
* next time it is required
|
144 |
*/
|
145 |
int size = layers.length+1; |
146 |
ISymbol[] newLayers = new ISymbol[size]; |
147 |
for (int i = 0; i < newLayers.length-1; i++) { |
148 |
newLayers[i] = layers[i]; |
149 |
} |
150 |
newLayers[size-1] = newLayer;
|
151 |
layers = newLayers; |
152 |
} |
153 |
|
154 |
public void addLayer(ISymbol newLayer, int layerIndex) throws IndexOutOfBoundsException { |
155 |
if (newLayer == null) return; |
156 |
|
157 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
158 |
* next time it is required
|
159 |
*/
|
160 |
if (layerIndex < 0 || layers.length < layerIndex) |
161 |
throw new IndexOutOfBoundsException(layerIndex+" < 0 or "+layerIndex+" > "+layers.length); |
162 |
int size = layers.length+1; |
163 |
ArrayList newLayers = new ArrayList(); |
164 |
for (int i = 0; i < layers.length; i++) { |
165 |
newLayers.add(layers[i]); |
166 |
} |
167 |
newLayers.add(layerIndex, newLayer); |
168 |
layers = (ISymbol[]) newLayers.toArray(new ISymbol[0]); |
169 |
} |
170 |
/**
|
171 |
* TODO maybe push it up to ISymbol
|
172 |
* @param layer
|
173 |
* @return true if this symbol contains the removed one
|
174 |
*/
|
175 |
public boolean removeLayer(ISymbol layer) { |
176 |
|
177 |
int capacity = 0; |
178 |
capacity = layers.length; |
179 |
ArrayList lst = new ArrayList(capacity); |
180 |
for (int i = 0; i < capacity; i++) { |
181 |
lst.add(layers[i]); |
182 |
} |
183 |
boolean contains = lst.remove(layer);
|
184 |
layers = (ISymbol[])lst.toArray(new ISymbol[0]); |
185 |
return contains;
|
186 |
} |
187 |
|
188 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
189 |
for (int i = 0; i < layers.length; i++) { |
190 |
layers[i].draw(g, affineTransform, shp); |
191 |
} |
192 |
} |
193 |
|
194 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
195 |
// TODO Auto-generated method stub
|
196 |
throw new Error("Not yet implemented!"); |
197 |
|
198 |
} |
199 |
|
200 |
public int getOnePointRgb() { |
201 |
// will paint only the last layer pixel
|
202 |
return layers[layers.length-1].getOnePointRgb(); |
203 |
} |
204 |
|
205 |
public XMLEntity getXMLEntity() {
|
206 |
XMLEntity xml = new XMLEntity();
|
207 |
|
208 |
xml.putProperty("className", getClass().getName());
|
209 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
210 |
xml.putProperty("symbolType", symbolType);
|
211 |
xml.putProperty("desc", getDescription());
|
212 |
for (int i = 0; i < layers.length; i++) { |
213 |
xml.addChild(layers[i].getXMLEntity()); |
214 |
} |
215 |
return xml;
|
216 |
} |
217 |
|
218 |
public int getSymbolType() { |
219 |
return symbolType;
|
220 |
} |
221 |
|
222 |
public boolean isSuitableFor(IGeometry geom) { |
223 |
return (geom.getGeometryType() & symbolType) > 0; |
224 |
} |
225 |
|
226 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
227 |
for (int i = 0; i < layers.length; i++) { |
228 |
layers[i].drawInsideRectangle(g, scaleInstance, r); |
229 |
} |
230 |
} |
231 |
|
232 |
public String getClassName() { |
233 |
return getClass().getName();
|
234 |
} |
235 |
|
236 |
public void setXMLEntity(XMLEntity xml) { |
237 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
238 |
setDescription(xml.getStringProperty("desc"));
|
239 |
symbolType = xml.getIntProperty("symbolType");
|
240 |
layers = new ISymbol[xml.getChildrenCount()];
|
241 |
for (int i = 0; i < layers.length; i++) { |
242 |
layers[i] = SymbolFactory.createFromXML(xml.getChild(i), "layer" + i);
|
243 |
} |
244 |
} |
245 |
|
246 |
public void setPrintingProperties(PrintRequestAttributeSet properties) { |
247 |
for (int i = 0; i < layers.length; i++) { |
248 |
layers[i].setPrintingProperties(properties); |
249 |
} |
250 |
} |
251 |
|
252 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws com.iver.cit.gvsig.fmap.DriverException { |
253 |
// TODO Implement it
|
254 |
throw new Error("Not yet implemented!"); |
255 |
|
256 |
} |
257 |
|
258 |
public void setLayer(int index, ISymbol layer) throws IndexOutOfBoundsException { |
259 |
layers[index] = layer; |
260 |
} |
261 |
|
262 |
public void setMultiLayerSymbolType(int type) { |
263 |
symbolType = type; |
264 |
} |
265 |
|
266 |
public void swapLayers(int index1, int index2) { |
267 |
ISymbol aux1 = getLayer(index1), aux2 = getLayer(index2); |
268 |
layers[index2] = aux1; |
269 |
layers[index1] = aux2; |
270 |
} |
271 |
} |