svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MarkerLineSymbol.java @ 19509
History | View | Annotate | Download (6.51 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 |
package com.iver.cit.gvsig.fmap.core.symbols; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Shape; |
46 |
import java.awt.geom.AffineTransform; |
47 |
|
48 |
import javax.print.attribute.PrintRequestAttributeSet; |
49 |
|
50 |
import org.apache.batik.ext.awt.geom.PathLength; |
51 |
|
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
54 |
import com.iver.cit.gvsig.fmap.core.FShape; |
55 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
56 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
import com.iver.utiles.swing.threads.Cancellable; |
59 |
|
60 |
/**
|
61 |
* MarkerLineSymbol allows to use any symbol defined as an image to draw a lineal object.
|
62 |
* The line will be painted as a run of symbols through the path defined by the line.
|
63 |
*
|
64 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
65 |
*/
|
66 |
public class MarkerLineSymbol extends AbstractLineSymbol { |
67 |
private IMarkerSymbol marker;
|
68 |
private MarkerLineSymbol symSelect;
|
69 |
private double separation = 5; |
70 |
private double cartographicSeparation; |
71 |
|
72 |
{ |
73 |
marker = SymbologyFactory.createDefaultMarkerSymbol(); |
74 |
marker.setSize(5);
|
75 |
} |
76 |
|
77 |
public void setLineWidth(double width) { |
78 |
getLineStyle().setLineWidth((float) width);
|
79 |
} |
80 |
|
81 |
public double getLineWidth() { |
82 |
return getLineStyle().getLineWidth();
|
83 |
} |
84 |
|
85 |
|
86 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
87 |
PathLength pl = new PathLength(shp);
|
88 |
float myLineLength = pl.lengthOfPath(); // length without the first and last arrow |
89 |
float separation = (float) cartographicSeparation; |
90 |
|
91 |
FPoint2D p = new FPoint2D(pl.pointAtLength(0)); |
92 |
double lineWidth = getLineWidth();
|
93 |
double halfLineWidth = lineWidth * 0.5; |
94 |
marker.setSize(lineWidth); |
95 |
marker.draw(g, affineTransform, p, null);
|
96 |
|
97 |
if (separation == 0) separation = 1; |
98 |
float length = separation;
|
99 |
while ((cancel==null || !cancel.isCanceled()) && length < myLineLength) { |
100 |
p = new FPoint2D(pl.pointAtLength(length));
|
101 |
marker.draw(g, affineTransform, p, null);
|
102 |
length += separation + halfLineWidth; |
103 |
} |
104 |
} |
105 |
|
106 |
|
107 |
/**
|
108 |
* Gets the separation between the marker symbols that are used to draw the line.
|
109 |
*
|
110 |
* @return separation
|
111 |
*/
|
112 |
public double getSeparation() { |
113 |
return separation;
|
114 |
} |
115 |
|
116 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
117 |
Shape shp) {
|
118 |
// TODO Auto-generated method stub
|
119 |
throw new Error("Not yet implemented!"); |
120 |
} |
121 |
|
122 |
public ISymbol getSymbolForSelection() {
|
123 |
if (symSelect == null) { |
124 |
symSelect = (MarkerLineSymbol) SymbologyFactory. |
125 |
createSymbolFromXML(getXMLEntity(), "selection derived symbol");
|
126 |
symSelect.setMarker((IMarkerSymbol) symSelect.getMarker() |
127 |
.getSymbolForSelection()); |
128 |
|
129 |
} |
130 |
|
131 |
return symSelect;
|
132 |
} |
133 |
|
134 |
public Color getColor() { |
135 |
return marker.getColor();
|
136 |
} |
137 |
|
138 |
public void setLineColor(Color color) { |
139 |
marker.setColor(color); |
140 |
} |
141 |
|
142 |
public XMLEntity getXMLEntity() {
|
143 |
XMLEntity xml = new XMLEntity();
|
144 |
xml.putProperty("className", getClassName());
|
145 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
146 |
xml.putProperty("desc", getDescription());
|
147 |
xml.putProperty("unit", getUnit());
|
148 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
149 |
xml.putProperty("separation", getSeparation());
|
150 |
XMLEntity xmlMarker = marker.getXMLEntity(); |
151 |
xmlMarker.putProperty("id", "marker"); |
152 |
xml.addChild(xmlMarker); |
153 |
XMLEntity xmlLineStyle = getLineStyle().getXMLEntity(); |
154 |
xmlLineStyle.putProperty("id", "lineStyle"); |
155 |
xml.addChild(xmlLineStyle); |
156 |
return xml;
|
157 |
} |
158 |
|
159 |
public void setXMLEntity(XMLEntity xml) { |
160 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
161 |
setDescription(xml.getStringProperty("desc"));
|
162 |
setSeparation(xml.getDoubleProperty("separation"));
|
163 |
setUnit(xml.getIntProperty("unit"));
|
164 |
setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
165 |
marker = (IMarkerSymbol) SymbologyFactory. |
166 |
createSymbolFromXML(xml.firstChild("id", "marker"), "theMarker"); |
167 |
setLineStyle((ILineStyle) SymbologyFactory. |
168 |
createStyleFromXML(xml.firstChild("id", "lineStyle"), "theLineStyle")); |
169 |
} |
170 |
/**
|
171 |
* Sets the separation between the marker symbols that compose the line
|
172 |
*
|
173 |
* @param separation
|
174 |
*/
|
175 |
public void setSeparation(double separation) { |
176 |
this.separation = separation;
|
177 |
this.cartographicSeparation = separation;
|
178 |
} |
179 |
|
180 |
public String getClassName() { |
181 |
return getClass().getName();
|
182 |
} |
183 |
|
184 |
public void print(Graphics2D g, AffineTransform at, FShape shape, |
185 |
PrintRequestAttributeSet properties) throws ReadDriverException { |
186 |
// TODO Auto-generated method stub
|
187 |
throw new Error("Not yet implemented!"); |
188 |
} |
189 |
/**
|
190 |
* Returns the marker symbol that compose the line
|
191 |
*
|
192 |
* @return marker IMarkerSymbol
|
193 |
*/
|
194 |
public IMarkerSymbol getMarker() {
|
195 |
return marker;
|
196 |
} |
197 |
/**
|
198 |
* Sets the marker symbol that compose the line
|
199 |
*
|
200 |
* @param marker IMarkerSymbol
|
201 |
*/
|
202 |
public void setMarker(IMarkerSymbol marker) { |
203 |
this.marker = marker;
|
204 |
} |
205 |
|
206 |
//@Override
|
207 |
public void setCartographicSize(double cartographicSize, FShape shp) { |
208 |
double oldLineWidth = getLineWidth();
|
209 |
super.setCartographicSize(cartographicSize, shp);
|
210 |
double newLineWidth = getLineWidth();
|
211 |
double scale = newLineWidth/oldLineWidth;
|
212 |
cartographicSeparation = separation * scale; |
213 |
} |
214 |
|
215 |
|
216 |
|
217 |
} |