svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleLineSymbol.java @ 12043
History | View | Annotate | Download (5.78 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: SimpleLineSymbol.java 12043 2007-06-07 06:58:18Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.9 2007-06-07 06:50:40 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.8 2007/05/08 08:47:40 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.7 2007/03/26 15:02:49 jaume
|
53 |
* Refactored IPrintable
|
54 |
*
|
55 |
* Revision 1.6 2007/03/20 16:02:24 jaume
|
56 |
* rename method
|
57 |
*
|
58 |
* Revision 1.5 2007/03/09 11:20:56 jaume
|
59 |
* Advanced symbology (start committing)
|
60 |
*
|
61 |
* Revision 1.3.2.5 2007/02/21 07:34:09 jaume
|
62 |
* labeling starts working
|
63 |
*
|
64 |
* Revision 1.3.2.4 2007/02/15 16:23:44 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.3.2.3 2007/02/13 16:19:19 jaume
|
68 |
* graduated symbol legends (start commiting)
|
69 |
*
|
70 |
* Revision 1.3.2.2 2007/02/12 15:15:20 jaume
|
71 |
* refactored interval legend and added graduated symbol legend
|
72 |
*
|
73 |
* Revision 1.3.2.1 2007/02/09 07:47:05 jaume
|
74 |
* Isymbol moved
|
75 |
*
|
76 |
* Revision 1.3 2007/01/25 16:25:23 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.2 2007/01/24 17:58:22 jaume
|
80 |
* new features and architecture error fixes
|
81 |
*
|
82 |
* Revision 1.1 2007/01/16 11:50:44 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
*
|
86 |
*/
|
87 |
package com.iver.cit.gvsig.fmap.core.symbols; |
88 |
|
89 |
import java.awt.Color; |
90 |
import java.awt.Graphics2D; |
91 |
import java.awt.Rectangle; |
92 |
import java.awt.Shape; |
93 |
import java.awt.geom.AffineTransform; |
94 |
|
95 |
import javax.print.attribute.PrintRequestAttributeSet; |
96 |
|
97 |
import org.opengis.go.display.style.ArrowStyle; |
98 |
|
99 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
100 |
import com.iver.cit.gvsig.fmap.core.FShape; |
101 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
102 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
103 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
104 |
import com.iver.utiles.StringUtilities; |
105 |
import com.iver.utiles.XMLEntity; |
106 |
|
107 |
/**
|
108 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
109 |
*/
|
110 |
public class SimpleLineSymbol extends AbstractLineSymbol { |
111 |
SimpleLineSymbol symbolForSelection; |
112 |
|
113 |
public ISymbol getSymbolForSelection() {
|
114 |
if (symbolForSelection == null) { |
115 |
XMLEntity xml = getXMLEntity(); |
116 |
xml.putProperty("color", StringUtilities.color2String(FSymbol.getSelectionColor()));
|
117 |
symbolForSelection = (SimpleLineSymbol) SymbologyFactory. |
118 |
createSymbolFromXML(xml, getDescription()+" version for selection");
|
119 |
} |
120 |
return symbolForSelection;
|
121 |
} |
122 |
|
123 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
124 |
g.setStroke(getLineStyle().getStroke()); |
125 |
g.setColor(getColor()); |
126 |
g.draw(shp); |
127 |
ArrowMarkerSymbol sym = getLineStyle().getArrowDecorator(); |
128 |
if (sym != null) |
129 |
sym.draw(g, affineTransform, shp); |
130 |
} |
131 |
|
132 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
133 |
Shape shp) {
|
134 |
return 0; |
135 |
} |
136 |
|
137 |
public int getOnePointRgb() { |
138 |
return getColor().getRGB();
|
139 |
} |
140 |
|
141 |
public XMLEntity getXMLEntity() {
|
142 |
XMLEntity xml = new XMLEntity();
|
143 |
xml.putProperty("className", getClassName());
|
144 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
145 |
xml.putProperty("desc", getDescription());
|
146 |
xml.putProperty("unit", getUnit());
|
147 |
|
148 |
// reference system
|
149 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
150 |
|
151 |
Color c = getColor();
|
152 |
if (c!= null) |
153 |
xml.putProperty("color", StringUtilities.color2String(getColor()));
|
154 |
|
155 |
xml.addChild(getLineStyle().getXMLEntity()); |
156 |
return xml;
|
157 |
} |
158 |
|
159 |
public void drawInsideRectangle(Graphics2D g, |
160 |
AffineTransform scaleInstance, Rectangle r) { |
161 |
g.setColor(getColor()); |
162 |
g.setStroke(getLineStyle().getStroke()); |
163 |
final int hGap = (int) (r.getWidth() * 0.1); // the left and right margins |
164 |
final int vPos = 1; // the top and bottom margins |
165 |
final int splitCount = 3; // number of lines |
166 |
final int splitHSize = (r.width - hGap - hGap) / splitCount; |
167 |
int hPos = hGap;
|
168 |
boolean swap = false; |
169 |
for (int i = 0; i < splitCount; i++) { |
170 |
swap = !swap; |
171 |
g.drawLine(hPos, swap ? vPos : r.height-vPos, hPos + splitHSize, swap ? r.height-vPos : vPos); |
172 |
hPos += splitHSize; |
173 |
} |
174 |
} |
175 |
|
176 |
public String getClassName() { |
177 |
return getClass().getName();
|
178 |
} |
179 |
|
180 |
public void setXMLEntity(XMLEntity xml) { |
181 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
182 |
setDescription(xml.getStringProperty("desc"));
|
183 |
setUnit(xml.getIntProperty("unit"));
|
184 |
if (xml.contains("color")) |
185 |
setLineColor(StringUtilities. |
186 |
string2Color(xml.getStringProperty("color")));
|
187 |
setLineStyle((ILineStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null)); |
188 |
} |
189 |
|
190 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) |
191 |
throws ReadDriverException {
|
192 |
// TODO Implement it
|
193 |
throw new Error("Not yet implemented!"); |
194 |
|
195 |
} |
196 |
|
197 |
public void setLineWidth(double width) { |
198 |
getLineStyle().setLineWidth((float) width);
|
199 |
} |
200 |
|
201 |
public double getLineWidth() { |
202 |
return getLineStyle().getLineWidth();
|
203 |
} |
204 |
|
205 |
} |