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