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