root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiLayerMarkerSymbol.java @ 10679
History | View | Annotate | Download (7.45 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: MultiLayerMarkerSymbol.java 10679 2007-03-09 11:25:01Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-03-09 11:20:57 jaume
|
47 |
* Advanced symbology (start committing)
|
48 |
*
|
49 |
* Revision 1.1.2.2 2007/02/21 07:34:08 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.awt.geom.Point2D; |
65 |
import java.util.ArrayList; |
66 |
|
67 |
import javax.print.attribute.PrintRequestAttributeSet; |
68 |
|
69 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
70 |
import com.iver.cit.gvsig.fmap.core.FShape; |
71 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
72 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
73 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
74 |
import com.iver.utiles.XMLEntity; |
75 |
|
76 |
public class MultiLayerMarkerSymbol extends AbstractSymbol implements IMarkerSymbol, IMultiLayerSymbol { |
77 |
private IMarkerSymbol[] layers = new IMarkerSymbol[0]; |
78 |
private MultiLayerMarkerSymbol selectionSymbol;
|
79 |
private Point2D offset = new Point2D.Double(); |
80 |
private double rotation; |
81 |
private double size; |
82 |
|
83 |
public Color getColor() { |
84 |
/*
|
85 |
* a multilayer symbol does not define any color, the color
|
86 |
* of each layer is defined by the layer itself
|
87 |
*/
|
88 |
return null; |
89 |
} |
90 |
|
91 |
public Point2D getOffset() { |
92 |
return offset;
|
93 |
} |
94 |
|
95 |
public double getRotation() { |
96 |
return rotation;
|
97 |
} |
98 |
|
99 |
public double getSize() { |
100 |
/*
|
101 |
* will return the widest symbol's width
|
102 |
*/
|
103 |
double size = Double.MIN_VALUE; |
104 |
for (int i = 0; i < layers.length; i++) { |
105 |
size = Math.max(size, layers[i].getSize());
|
106 |
} |
107 |
return size;
|
108 |
} |
109 |
|
110 |
public void setColor(Color color) { |
111 |
/*
|
112 |
* will apply the color to each layer
|
113 |
*/
|
114 |
for (int i = 0; i < layers.length; i++) { |
115 |
layers[i].setColor(color); |
116 |
} |
117 |
} |
118 |
|
119 |
public void setOffset(Point2D offset) { |
120 |
this.offset = offset;
|
121 |
} |
122 |
|
123 |
public void setRotation(double rotation) { |
124 |
this.rotation = rotation;
|
125 |
} |
126 |
|
127 |
public void setSize(double size) { |
128 |
this.size = size;
|
129 |
} |
130 |
|
131 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
132 |
for (int i = 0; i < layers.length; i++) { |
133 |
layers[i].draw(g, affineTransform, shp); |
134 |
} |
135 |
} |
136 |
|
137 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
138 |
for (int i = 0; i < layers.length; i++) { |
139 |
layers[i].drawInsideRectangle(g, scaleInstance, r); |
140 |
} |
141 |
} |
142 |
|
143 |
public int getOnePointRgb() { |
144 |
// will paint only the last layer pixel
|
145 |
return layers[layers.length-1].getOnePointRgb(); |
146 |
} |
147 |
|
148 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
149 |
Shape shp) {
|
150 |
// TODO Implement it
|
151 |
throw new Error("Not yet implemented!"); |
152 |
|
153 |
} |
154 |
|
155 |
public ISymbol getSymbolForSelection() {
|
156 |
if (selectionSymbol == null) { |
157 |
selectionSymbol = new MultiLayerMarkerSymbol();
|
158 |
selectionSymbol.setDescription(getDescription()); |
159 |
// selectionSymbol.symbolType = symbolType;
|
160 |
for (int i = 0; i < layers.length; i++) { |
161 |
selectionSymbol.addLayer(layers[i].getSymbolForSelection()); |
162 |
} |
163 |
} |
164 |
return selectionSymbol;
|
165 |
|
166 |
} |
167 |
|
168 |
|
169 |
public int getSymbolType() { |
170 |
return FShape.POINT;
|
171 |
} |
172 |
|
173 |
public XMLEntity getXMLEntity() {
|
174 |
XMLEntity xml = new XMLEntity();
|
175 |
|
176 |
xml.putProperty("className", getClass().getName());
|
177 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
178 |
xml.putProperty("desc", getDescription());
|
179 |
for (int i = 0; i < layers.length; i++) { |
180 |
xml.addChild(layers[i].getXMLEntity()); |
181 |
} |
182 |
return xml;
|
183 |
} |
184 |
|
185 |
public boolean isSuitableFor(IGeometry geom) { |
186 |
return geom.getGeometryType() == FShape.POINT;
|
187 |
} |
188 |
|
189 |
public void setPrintingProperties(PrintRequestAttributeSet properties) { |
190 |
for (int i = 0; i < layers.length; i++) { |
191 |
layers[i].setPrintingProperties(properties); |
192 |
} |
193 |
} |
194 |
|
195 |
public String getClassName() { |
196 |
return getClass().getName();
|
197 |
} |
198 |
|
199 |
public void setXMLEntity(XMLEntity xml) { |
200 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
201 |
setDescription(xml.getStringProperty("desc"));
|
202 |
layers = new IMarkerSymbol[xml.getChildrenCount()];
|
203 |
for (int i = 0; i < layers.length; i++) { |
204 |
layers[i] = (IMarkerSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(i), "layer" + i);
|
205 |
} |
206 |
} |
207 |
|
208 |
|
209 |
public void print(Graphics2D g, AffineTransform at, FShape shape) |
210 |
throws ReadDriverException {
|
211 |
// TODO Implement it
|
212 |
throw new Error("Not yet implemented!"); |
213 |
|
214 |
} |
215 |
|
216 |
public void setLayer(int index, ISymbol layer) throws IndexOutOfBoundsException { |
217 |
layers[index] = (IMarkerSymbol) layer; |
218 |
} |
219 |
|
220 |
public void swapLayers(int index1, int index2) { |
221 |
ISymbol aux1 = getLayer(index1), aux2 = getLayer(index2); |
222 |
layers[index2] = (IMarkerSymbol) aux1; |
223 |
layers[index1] = (IMarkerSymbol) aux2; |
224 |
} |
225 |
|
226 |
public ISymbol getLayer(int layerIndex) { |
227 |
try{
|
228 |
return layers[layerIndex];
|
229 |
} catch (Exception e) { |
230 |
return null; |
231 |
} |
232 |
} |
233 |
|
234 |
public int getLayerCount() { |
235 |
return layers.length;
|
236 |
} |
237 |
|
238 |
public void addLayer(ISymbol newLayer) { |
239 |
if (newLayer == null) return; |
240 |
|
241 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
242 |
* next time it is required
|
243 |
*/
|
244 |
int size = layers.length+1; |
245 |
IMarkerSymbol[] newLayers = new IMarkerSymbol[size]; |
246 |
for (int i = 0; i < newLayers.length-1; i++) { |
247 |
newLayers[i] = layers[i]; |
248 |
} |
249 |
newLayers[size-1] = (IMarkerSymbol) newLayer;
|
250 |
layers = newLayers; |
251 |
} |
252 |
|
253 |
public void addLayer(ISymbol newLayer, int layerIndex) throws IndexOutOfBoundsException { |
254 |
if (newLayer == null || newLayer instanceof ILabelStyle) return; // null or symbols that are styles are not allowed |
255 |
|
256 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
257 |
* next time it is required
|
258 |
*/
|
259 |
if (layerIndex < 0 || layers.length < layerIndex) |
260 |
throw new IndexOutOfBoundsException(layerIndex+" < 0 or "+layerIndex+" > "+layers.length); |
261 |
ArrayList newLayers = new ArrayList(); |
262 |
for (int i = 0; i < layers.length; i++) { |
263 |
newLayers.add(layers[i]); |
264 |
} |
265 |
newLayers.add(layerIndex, newLayer); |
266 |
layers = (IMarkerSymbol[]) newLayers.toArray(new IMarkerSymbol[0]); |
267 |
} |
268 |
|
269 |
public boolean removeLayer(ISymbol layer) { |
270 |
|
271 |
int capacity = 0; |
272 |
capacity = layers.length; |
273 |
ArrayList lst = new ArrayList(capacity); |
274 |
for (int i = 0; i < capacity; i++) { |
275 |
lst.add(layers[i]); |
276 |
} |
277 |
boolean contains = lst.remove(layer);
|
278 |
layers = (IMarkerSymbol[])lst.toArray(new IMarkerSymbol[0]); |
279 |
return contains;
|
280 |
} |
281 |
|
282 |
} |