root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / styles / SimpleLineStyle.java @ 11051
History | View | Annotate | Download (5.8 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: SimpleLineStyle.java 11051 2007-04-04 15:41:05Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3 2007-04-04 15:41:05 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.2 2007/03/09 11:20:56 jaume
|
50 |
* Advanced symbology (start committing)
|
51 |
*
|
52 |
* Revision 1.1.2.4 2007/02/21 07:34:09 jaume
|
53 |
* labeling starts working
|
54 |
*
|
55 |
* Revision 1.1.2.3 2007/02/15 16:23:44 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1.2.2 2007/02/12 15:15:20 jaume
|
59 |
* refactored interval legend and added graduated symbol legend
|
60 |
*
|
61 |
* Revision 1.1.2.1 2007/02/09 07:47:04 jaume
|
62 |
* Isymbol moved
|
63 |
*
|
64 |
*
|
65 |
*/
|
66 |
package com.iver.cit.gvsig.fmap.core.styles; |
67 |
|
68 |
import java.awt.BasicStroke; |
69 |
import java.awt.Color; |
70 |
import java.awt.Graphics2D; |
71 |
import java.awt.Rectangle; |
72 |
import java.awt.Stroke; |
73 |
|
74 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
75 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
76 |
import com.iver.utiles.XMLEntity; |
77 |
|
78 |
/**
|
79 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
80 |
*/
|
81 |
public class SimpleLineStyle extends AbstractStyle implements ILineStyle { |
82 |
private final static Color PREVIEW_COLOR_1= new Color(150, 255, 200); //light blue |
83 |
private final static Color PREVIEW_COLOR_2 = new Color(255, 200, 100); //orange |
84 |
private final static int COLOR1_STROKE = 1; |
85 |
private final static int COLOR2_STROKE = 3; |
86 |
private float[] dashArray; |
87 |
private float dashPhase; |
88 |
private int endCap; |
89 |
private int lineJoin; |
90 |
private float miterlimit; |
91 |
/**
|
92 |
* @uml.property name="lineWidth"
|
93 |
*/
|
94 |
private float lineWidth; |
95 |
|
96 |
|
97 |
|
98 |
public SimpleLineStyle() {
|
99 |
BasicStroke dummy = new BasicStroke(); |
100 |
dashArray = dummy.getDashArray(); |
101 |
dashPhase = dummy.getDashPhase(); |
102 |
endCap = dummy.getEndCap(); |
103 |
lineJoin = dummy.getLineJoin(); |
104 |
miterlimit = dummy.getMiterLimit(); |
105 |
} |
106 |
|
107 |
|
108 |
public SimpleLineStyle(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) { |
109 |
this.lineWidth = width;
|
110 |
this.endCap = cap;
|
111 |
this.lineJoin = join;
|
112 |
this.miterlimit = miterlimit;
|
113 |
this.dashArray = dash;
|
114 |
this.dashPhase = dash_phase;
|
115 |
} |
116 |
|
117 |
public void drawInsideRectangle(Graphics2D g, Rectangle r) { |
118 |
Stroke oldStroke = g.getStroke();
|
119 |
int h = (int) (r.getHeight() / 2); |
120 |
int margins = 2; |
121 |
|
122 |
BasicStroke stroke;
|
123 |
stroke = new BasicStroke(COLOR1_STROKE, endCap, lineJoin, miterlimit, dashArray, dashPhase); |
124 |
g.setStroke(stroke); |
125 |
g.setColor(PREVIEW_COLOR_1); |
126 |
g.drawLine(margins, h, r.width-margins-margins, h); |
127 |
|
128 |
stroke = new BasicStroke(COLOR2_STROKE, endCap, lineJoin, miterlimit, dashArray, dashPhase); g.setStroke(stroke); |
129 |
g.setColor(PREVIEW_COLOR_2); |
130 |
g.drawLine(margins, h, r.width-margins-margins, h); |
131 |
g.setStroke(oldStroke); |
132 |
} |
133 |
|
134 |
public String getClassName() { |
135 |
return getClass().getName();
|
136 |
} |
137 |
|
138 |
public XMLEntity getXMLEntity() {
|
139 |
XMLEntity xml = new XMLEntity();
|
140 |
xml.putProperty("className", getClassName());
|
141 |
xml.putProperty("desc", getDescription());
|
142 |
|
143 |
if (dashArray != null) { |
144 |
StringBuffer sb = new StringBuffer(); |
145 |
for (int i = 0; i < dashArray.length; i++) { |
146 |
sb.append(dashArray[i]); |
147 |
if (i< dashArray.length)
|
148 |
sb.append(",");
|
149 |
} |
150 |
xml.putProperty("dashArray", sb.toString());
|
151 |
|
152 |
} |
153 |
xml.putProperty("lineWidth", lineWidth);
|
154 |
xml.putProperty("dashPhase", dashPhase);
|
155 |
xml.putProperty("endCap", endCap);
|
156 |
xml.putProperty("lineJoin", lineJoin);
|
157 |
xml.putProperty("miterLimit", miterlimit);
|
158 |
return xml;
|
159 |
} |
160 |
|
161 |
public void setXMLEntity(XMLEntity xml) { |
162 |
|
163 |
setDescription(xml.getStringProperty("desc"));
|
164 |
if (xml.contains("dashArray")) { |
165 |
String[] dashProp = xml.getStringProperty("dashArray").split(","); |
166 |
dashArray = new float[dashProp.length]; |
167 |
for (int i = 0; i < dashProp.length; i++) { |
168 |
dashArray[i] = Float.parseFloat(dashProp[i]);
|
169 |
} |
170 |
} |
171 |
lineWidth = xml.getFloatProperty("lineWidth");
|
172 |
dashPhase = xml.getFloatProperty("dashPhase");
|
173 |
endCap = xml.getIntProperty("endCap");
|
174 |
lineJoin = xml.getIntProperty("lineJoin");
|
175 |
miterlimit = xml.getFloatProperty("miterLimit");
|
176 |
} |
177 |
|
178 |
public Stroke getStroke() { |
179 |
return new BasicStroke(lineWidth, endCap, lineJoin, miterlimit, dashArray, dashPhase); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* @return
|
184 |
* @uml.property name="lineWidth"
|
185 |
*/
|
186 |
public float getLineWidth() { |
187 |
return lineWidth;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* @param width
|
192 |
* @uml.property name="lineWidth"
|
193 |
*/
|
194 |
public void setLineWidth(float width) { |
195 |
this.lineWidth = width;
|
196 |
} |
197 |
|
198 |
public boolean isSuitableFor(ISymbol symbol) { |
199 |
return symbol instanceof ILineSymbol; |
200 |
} |
201 |
|
202 |
public void setStroke(Stroke stroke) { |
203 |
if (stroke != null) { |
204 |
BasicStroke dummy = (BasicStroke) stroke; |
205 |
dashArray = dummy.getDashArray(); |
206 |
dashPhase = dummy.getDashPhase(); |
207 |
endCap = dummy.getEndCap(); |
208 |
lineJoin = dummy.getLineJoin(); |
209 |
miterlimit = dummy.getMiterLimit(); |
210 |
} |
211 |
} |
212 |
|
213 |
public void drawOutline(Graphics2D g, Rectangle r) { |
214 |
drawInsideRectangle(g, r); |
215 |
} |
216 |
|
217 |
} |