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