Revision 8458
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/AbstractMarker.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.4 2006-10-30 19:30:35 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.3 2006/10/26 16:27:33 jaume |
|
50 |
* support for composite marker symbols (not tested) |
|
51 |
* |
|
52 |
* Revision 1.2 2006/10/26 07:46:58 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.1 2006/10/25 10:50:41 jaume |
|
56 |
* movement of classes and gui stuff |
|
57 |
* |
|
58 |
* Revision 1.1 2006/10/18 07:54:06 jaume |
|
59 |
* *** empty log message *** |
|
60 |
* |
|
61 |
* |
|
62 |
*/ |
|
63 |
package com.iver.cit.gvsig.fmap.core.symbols; |
|
64 |
|
|
65 |
import java.awt.Point; |
|
66 |
import java.awt.geom.Point2D; |
|
67 |
import java.util.ArrayList; |
|
68 |
|
|
69 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
70 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
71 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
72 |
|
|
73 |
public abstract class AbstractMarker implements ISymbol { |
|
74 |
|
|
75 |
protected boolean isShapeVisible = true; |
|
76 |
protected String desc; |
|
77 |
protected double rotation; |
|
78 |
protected Point2D offset; |
|
79 |
protected ISymbol[] subSymbols; // TODO maybe push it up to ISymbol |
|
80 |
public String getDescription() { |
|
81 |
return desc; |
|
82 |
} |
|
83 |
|
|
84 |
public boolean isShapeVisible() { |
|
85 |
return isShapeVisible; |
|
86 |
} |
|
87 |
public void setDescription(String desc) { |
|
88 |
this.desc = desc; |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
public double getRotation() { |
|
93 |
return rotation; |
|
94 |
} |
|
95 |
|
|
96 |
public void setRotation(double r) { |
|
97 |
this.rotation = r; |
|
98 |
} |
|
99 |
public Point2D getOffset() { |
|
100 |
if (offset == null) { |
|
101 |
offset = new Point(); |
|
102 |
} |
|
103 |
return offset; |
|
104 |
} |
|
105 |
|
|
106 |
public void setOffset(Point offset) { |
|
107 |
this.offset = offset; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* TODO maybe push it up to ISymbol |
|
112 |
* @param sym |
|
113 |
*/ |
|
114 |
public void addSymbol(ISymbol sym) { |
|
115 |
int capacity = 0; |
|
116 |
if (subSymbols != null) |
|
117 |
capacity = subSymbols.length; |
|
118 |
ArrayList lst = new ArrayList(capacity); |
|
119 |
for (int i = 0; i < capacity; i++) { |
|
120 |
lst.add(subSymbols[i]); |
|
121 |
} |
|
122 |
subSymbols = (ISymbol[])lst.toArray(new ISymbol[0]); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* TODO maybe push it up to ISymbol |
|
127 |
* @param sym |
|
128 |
* @return true if this symbol contains the removed one |
|
129 |
*/ |
|
130 |
public boolean removeSymbol(ISymbol sym) { |
|
131 |
|
|
132 |
int capacity = 0; |
|
133 |
if (subSymbols != null) |
|
134 |
capacity = subSymbols.length; |
|
135 |
ArrayList lst = new ArrayList(capacity); |
|
136 |
for (int i = 0; i < capacity; i++) { |
|
137 |
lst.add(subSymbols[i]); |
|
138 |
} |
|
139 |
boolean contains = lst.remove(sym); |
|
140 |
subSymbols = (ISymbol[])lst.toArray(new ISymbol[0]); |
|
141 |
return contains; |
|
142 |
} |
|
143 |
|
|
144 |
public boolean isSuitableFor(IGeometry geom) { |
|
145 |
return geom.getGeometryType() == FShape.POINT; |
|
146 |
} |
|
147 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/CharacterMarker.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.4 2006-10-30 19:30:35 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.3 2006/10/29 23:53:49 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2 2006/10/26 16:27:33 jaume |
|
53 |
* support for composite marker symbols (not tested) |
|
54 |
* |
|
55 |
* Revision 1.1 2006/10/25 10:50:41 jaume |
|
56 |
* movement of classes and gui stuff |
|
57 |
* |
|
58 |
* Revision 1.3 2006/10/24 19:54:16 jaume |
|
59 |
* added IPersistence |
|
60 |
* |
|
61 |
* Revision 1.2 2006/10/24 08:02:51 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* Revision 1.1 2006/10/18 07:54:06 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* |
|
68 |
*/ |
|
69 |
package com.iver.cit.gvsig.fmap.core.symbols; |
|
70 |
|
|
71 |
import java.awt.Color; |
|
72 |
import java.awt.Font; |
|
73 |
import java.awt.Graphics2D; |
|
74 |
import java.awt.Point; |
|
75 |
import java.awt.Rectangle; |
|
76 |
import java.awt.Shape; |
|
77 |
import java.awt.geom.AffineTransform; |
|
78 |
import java.awt.geom.Point2D; |
|
79 |
|
|
80 |
import org.apache.batik.ext.awt.geom.PathLength; |
|
81 |
|
|
82 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
83 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
84 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
85 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
|
86 |
import com.iver.utiles.StringUtilities; |
|
87 |
import com.iver.utiles.XMLEntity; |
|
88 |
|
|
89 |
|
|
90 |
// TODO quitar batik-util.jar del classpath de extGraph cuando movamos esto a FMap |
|
91 |
/** |
|
92 |
* Symbol that manages symbols from a TrueType font source |
|
93 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
94 |
*/ |
|
95 |
public class CharacterMarker extends AbstractMarker { |
|
96 |
private Font font; |
|
97 |
private Color color = Color.BLACK; |
|
98 |
private int symbol; |
|
99 |
|
|
100 |
/** |
|
101 |
* Creates a new instance of CharacterMarker with default values |
|
102 |
* |
|
103 |
*/ |
|
104 |
public CharacterMarker() { |
|
105 |
super(); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Creates a new instance of CharacterMarker specifying the marker source |
|
110 |
* font, the character code corresponding to the symbol, and the color that |
|
111 |
* will be used in rendering time. |
|
112 |
* |
|
113 |
* @param font - |
|
114 |
* src Font |
|
115 |
* @param charCode - |
|
116 |
* character code of the symbol for this font |
|
117 |
* @param color - |
|
118 |
* color to be used in when rendering. |
|
119 |
*/ |
|
120 |
public CharacterMarker(Font font, int charCode, Color color) { |
|
121 |
super(); |
|
122 |
this.font = font; |
|
123 |
symbol = charCode; |
|
124 |
this.color = color; |
|
125 |
} |
|
126 |
|
|
127 |
public Font getFont() { |
|
128 |
if (font == null) { |
|
129 |
font = new Font("Arial", Font.PLAIN, 20); |
|
130 |
} |
|
131 |
return font; |
|
132 |
} |
|
133 |
|
|
134 |
public void setFont(Font font) { |
|
135 |
this.font = font; |
|
136 |
} |
|
137 |
|
|
138 |
public ISymbol getSymbolForSelection() { |
|
139 |
// TODO Auto-generated method stub |
|
140 |
throw new Error("Not yet implemented!"); |
|
141 |
} |
|
142 |
|
|
143 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
|
144 |
g.setFont(getFont()); |
|
145 |
g.setColor(color); |
|
146 |
g.rotate(getRotation()); |
|
147 |
Point2D p = null; |
|
148 |
switch (shp.getShapeType()) { |
|
149 |
case FShape.POINT: |
|
150 |
p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp) |
|
151 |
.getY()); |
|
152 |
// p = affineTransform.transform(p, null); |
|
153 |
break; |
|
154 |
case FShape.LINE: |
|
155 |
PathLength pathLen = new PathLength(shp); |
|
156 |
float midDistance = pathLen.lengthOfPath() / 2; |
|
157 |
p = pathLen.pointAtLength(midDistance); |
|
158 |
// p = affineTransform.transform(p, null); |
|
159 |
break; |
|
160 |
case FShape.POLYGON: |
|
161 |
/*Geometry geom = FConverter.java2d_to_jts(shp); |
|
162 |
Point centroid = geom.getCentroid(); |
|
163 |
p = new Point2D.Double(centroid.getX(), centroid.getY()); |
|
164 |
*/ |
|
165 |
} |
|
166 |
|
|
167 |
char[] text = new char[] { (char) symbol }; |
|
168 |
g.drawChars(text, 0, text.length, (int) p.getX(), (int) p.getY()); |
|
169 |
} |
|
170 |
|
|
171 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
|
172 |
Shape shp) { |
|
173 |
// TODO Auto-generated method stub |
|
174 |
throw new Error("Not yet implemented!"); |
|
175 |
} |
|
176 |
|
|
177 |
public int getOnePointRgb() { |
|
178 |
return color.getRGB(); |
|
179 |
} |
|
180 |
|
|
181 |
public XMLEntity getXMLEntity() { |
|
182 |
XMLEntity xml = new XMLEntity(); |
|
183 |
|
|
184 |
// the class name |
|
185 |
xml.putProperty("className", getClassName()); |
|
186 |
|
|
187 |
// color |
|
188 |
xml.putProperty("color", StringUtilities.color2String(color)); |
|
189 |
|
|
190 |
// font |
|
191 |
xml.putProperty("font", font.getFontName()); |
|
192 |
|
|
193 |
// font style |
|
194 |
xml.putProperty("fontStyle", font.getStyle()); |
|
195 |
|
|
196 |
// symbol code |
|
197 |
xml.putProperty("symbolCode", symbol); |
|
198 |
|
|
199 |
// description |
|
200 |
xml.putProperty("desc", desc); |
|
201 |
|
|
202 |
// is shape visible |
|
203 |
xml.putProperty("isShapeVisible", isShapeVisible); |
|
204 |
|
|
205 |
// x offset |
|
206 |
xml.putProperty("xOffset", getOffset().getX()); |
|
207 |
|
|
208 |
// y offset |
|
209 |
xml.putProperty("yOffset", getOffset().getY()); |
|
210 |
|
|
211 |
// rotation |
|
212 |
xml.putProperty("rotation", rotation); |
|
213 |
return xml; |
|
214 |
} |
|
215 |
|
|
216 |
public int getSymbolType() { |
|
217 |
return CHARACTER_MARKER; |
|
218 |
} |
|
219 |
|
|
220 |
public void drawInsideRectangle(Graphics2D g, |
|
221 |
AffineTransform scaleInstance, Rectangle r) { |
|
222 |
g.rotate(getRotation()); |
|
223 |
// Sirve de algo el scaleInstance??? |
|
224 |
// g.setFont(font.deriveFont(scaleInstance)); |
|
225 |
double h = r.getHeight(); |
|
226 |
Font myFont = font.deriveFont( |
|
227 |
(float) (h * FConstant.FONT_HEIGHT_SCALE_FACTOR)).deriveFont( |
|
228 |
scaleInstance); |
|
229 |
g.setFont(myFont); |
|
230 |
g.setColor(color); |
|
231 |
r.y = (int) h; |
|
232 |
|
|
233 |
// center character in case the rectangle is not square |
|
234 |
int x = r.x; |
|
235 |
int y = r.y; |
|
236 |
int width = (int) r.getHeight(); |
|
237 |
int height = (int) r.getWidth(); |
|
238 |
int diff = (width-height); |
|
239 |
if (diff<0) { |
|
240 |
x -= diff /2; |
|
241 |
} else { |
|
242 |
y += diff /2; |
|
243 |
} |
|
244 |
|
|
245 |
// and apply the offset |
|
246 |
x = x + (int) offset.getX(); // TODO scale offset |
|
247 |
y = y + (int) offset.getY(); // TODO scale offset |
|
248 |
char[] text = new char[] { (char) symbol }; |
|
249 |
g.drawChars(text, 0, text.length, x, y); |
|
250 |
|
|
251 |
// finally, draw the subsymbols if any |
|
252 |
if (subSymbols!=null) { |
|
253 |
for (int i = 0; i < subSymbols.length; i++) { |
|
254 |
subSymbols[i].drawInsideRectangle(g, scaleInstance, r); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
public void setCharacter(int symbol) { |
|
260 |
this.symbol = symbol; |
|
261 |
} |
|
262 |
|
|
263 |
public String getClassName() { |
|
264 |
return this.getClass().getName(); |
|
265 |
} |
|
266 |
|
|
267 |
public void setXMLEntity(XMLEntity xml) { |
|
268 |
color = StringUtilities.string2Color(xml.getStringProperty("color")); |
|
269 |
Point p = new Point(); |
|
270 |
p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset")); |
|
271 |
|
|
272 |
desc = xml.getStringProperty("desc"); |
|
273 |
font = new Font(xml.getStringProperty("font"), |
|
274 |
xml.getIntProperty("fontStyle"), |
|
275 |
100 /* or whatever*/); |
|
276 |
isShapeVisible = xml.getBooleanProperty("isShapeVisible"); |
|
277 |
symbol = xml.getIntProperty("symbolCode"); |
|
278 |
offset = p; |
|
279 |
rotation = xml.getDoubleProperty("rotation"); |
|
280 |
|
|
281 |
} |
|
282 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/CharacterMarkerSymbol.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-10-31 16:16:34 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.4 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.3 2006/10/29 23:53:49 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.2 2006/10/26 16:27:33 jaume |
|
56 |
* support for composite marker symbols (not tested) |
|
57 |
* |
|
58 |
* Revision 1.1 2006/10/25 10:50:41 jaume |
|
59 |
* movement of classes and gui stuff |
|
60 |
* |
|
61 |
* Revision 1.3 2006/10/24 19:54:16 jaume |
|
62 |
* added IPersistence |
|
63 |
* |
|
64 |
* Revision 1.2 2006/10/24 08:02:51 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.1 2006/10/18 07:54:06 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* |
|
71 |
*/ |
|
72 |
package com.iver.cit.gvsig.fmap.core.symbols; |
|
73 |
|
|
74 |
import java.awt.Color; |
|
75 |
import java.awt.Font; |
|
76 |
import java.awt.Graphics2D; |
|
77 |
import java.awt.Point; |
|
78 |
import java.awt.Rectangle; |
|
79 |
import java.awt.Shape; |
|
80 |
import java.awt.geom.AffineTransform; |
|
81 |
import java.awt.geom.Point2D; |
|
82 |
|
|
83 |
import org.apache.batik.ext.awt.geom.PathLength; |
|
84 |
|
|
85 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
86 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
87 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
88 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
|
89 |
import com.iver.utiles.StringUtilities; |
|
90 |
import com.iver.utiles.XMLEntity; |
|
91 |
|
|
92 |
|
|
93 |
// TODO quitar batik-util.jar del classpath de extGraph cuando movamos esto a FMap |
|
94 |
/** |
|
95 |
* Symbol that manages symbols from a TrueType font source |
|
96 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
97 |
*/ |
|
98 |
public class CharacterMarkerSymbol extends AbstractMarkerSymbol { |
|
99 |
private Font font; |
|
100 |
private Color color = Color.BLACK; |
|
101 |
private int symbol; |
|
102 |
|
|
103 |
/** |
|
104 |
* Creates a new instance of CharacterMarker with default values |
|
105 |
* |
|
106 |
*/ |
|
107 |
public CharacterMarkerSymbol() { |
|
108 |
super(); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Creates a new instance of CharacterMarker specifying the marker source |
|
113 |
* font, the character code corresponding to the symbol, and the color that |
|
114 |
* will be used in rendering time. |
|
115 |
* |
|
116 |
* @param font - |
|
117 |
* src Font |
|
118 |
* @param charCode - |
|
119 |
* character code of the symbol for this font |
|
120 |
* @param color - |
|
121 |
* color to be used in when rendering. |
|
122 |
*/ |
|
123 |
public CharacterMarkerSymbol(Font font, int charCode, Color color) { |
|
124 |
super(); |
|
125 |
this.font = font; |
|
126 |
symbol = charCode; |
|
127 |
this.color = color; |
|
128 |
} |
|
129 |
|
|
130 |
public Font getFont() { |
|
131 |
if (font == null) { |
|
132 |
font = new Font("Arial", Font.PLAIN, 20); |
|
133 |
} |
|
134 |
return font; |
|
135 |
} |
|
136 |
|
|
137 |
public void setFont(Font font) { |
|
138 |
this.font = font; |
|
139 |
} |
|
140 |
|
|
141 |
public ISymbol getSymbolForSelection() { |
|
142 |
// TODO Auto-generated method stub |
|
143 |
throw new Error("Not yet implemented!"); |
|
144 |
} |
|
145 |
|
|
146 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
|
147 |
g.setFont(getFont()); |
|
148 |
g.setColor(color); |
|
149 |
g.rotate(getRotation()); |
|
150 |
Point2D p = null; |
|
151 |
switch (shp.getShapeType()) { |
|
152 |
case FShape.POINT: |
|
153 |
p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp) |
|
154 |
.getY()); |
|
155 |
// p = affineTransform.transform(p, null); |
|
156 |
break; |
|
157 |
case FShape.LINE: |
|
158 |
PathLength pathLen = new PathLength(shp); |
|
159 |
float midDistance = pathLen.lengthOfPath() / 2; |
|
160 |
p = pathLen.pointAtLength(midDistance); |
|
161 |
// p = affineTransform.transform(p, null); |
|
162 |
break; |
|
163 |
case FShape.POLYGON: |
|
164 |
/*Geometry geom = FConverter.java2d_to_jts(shp); |
|
165 |
Point centroid = geom.getCentroid(); |
|
166 |
p = new Point2D.Double(centroid.getX(), centroid.getY()); |
|
167 |
*/ |
|
168 |
} |
|
169 |
|
|
170 |
char[] text = new char[] { (char) symbol }; |
|
171 |
g.drawChars(text, 0, text.length, (int) p.getX(), (int) p.getY()); |
|
172 |
} |
|
173 |
|
|
174 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
|
175 |
Shape shp) { |
|
176 |
// TODO Auto-generated method stub |
|
177 |
throw new Error("Not yet implemented!"); |
|
178 |
} |
|
179 |
|
|
180 |
public int getOnePointRgb() { |
|
181 |
return color.getRGB(); |
|
182 |
} |
|
183 |
|
|
184 |
public XMLEntity getXMLEntity() { |
|
185 |
XMLEntity xml = new XMLEntity(); |
|
186 |
|
|
187 |
// the class name |
|
188 |
xml.putProperty("className", getClassName()); |
|
189 |
|
|
190 |
// color |
|
191 |
xml.putProperty("color", StringUtilities.color2String(color)); |
|
192 |
|
|
193 |
// font |
|
194 |
xml.putProperty("font", font.getFontName()); |
|
195 |
|
|
196 |
// font style |
|
197 |
xml.putProperty("fontStyle", font.getStyle()); |
|
198 |
|
|
199 |
// symbol code |
|
200 |
xml.putProperty("symbolCode", symbol); |
|
201 |
|
|
202 |
// description |
|
203 |
xml.putProperty("desc", desc); |
|
204 |
|
|
205 |
// is shape visible |
|
206 |
xml.putProperty("isShapeVisible", isShapeVisible); |
|
207 |
|
|
208 |
// x offset |
|
209 |
xml.putProperty("xOffset", getOffset().getX()); |
|
210 |
|
|
211 |
// y offset |
|
212 |
xml.putProperty("yOffset", getOffset().getY()); |
|
213 |
|
|
214 |
// rotation |
|
215 |
xml.putProperty("rotation", rotation); |
|
216 |
return xml; |
|
217 |
} |
|
218 |
|
|
219 |
public int getSymbolType() { |
|
220 |
return CHARACTER_MARKER; |
|
221 |
} |
|
222 |
|
|
223 |
public void drawInsideRectangle(Graphics2D g, |
|
224 |
AffineTransform scaleInstance, Rectangle r) { |
|
225 |
g.rotate(getRotation()); |
|
226 |
// Sirve de algo el scaleInstance??? |
|
227 |
// g.setFont(font.deriveFont(scaleInstance)); |
|
228 |
double h = r.getHeight(); |
|
229 |
Font myFont = font.deriveFont( |
|
230 |
(float) (h * FConstant.FONT_HEIGHT_SCALE_FACTOR)).deriveFont( |
|
231 |
scaleInstance); |
|
232 |
g.setFont(myFont); |
|
233 |
g.setColor(color); |
|
234 |
r.y = (int) h; |
|
235 |
|
|
236 |
// center character in case the rectangle is not square |
|
237 |
int x = r.x; |
|
238 |
int y = r.y; |
|
239 |
int width = (int) r.getHeight(); |
|
240 |
int height = (int) r.getWidth(); |
|
241 |
int diff = (width-height); |
|
242 |
if (diff<0) { |
|
243 |
x -= diff /2; |
|
244 |
} else { |
|
245 |
y += diff /2; |
|
246 |
} |
|
247 |
|
|
248 |
// and apply the offset |
|
249 |
x = x + (int) offset.getX(); // TODO scale offset |
|
250 |
y = y + (int) offset.getY(); // TODO scale offset |
|
251 |
char[] text = new char[] { (char) symbol }; |
|
252 |
g.drawChars(text, 0, text.length, x, y); |
|
253 |
|
|
254 |
// finally, draw the subsymbols if any |
|
255 |
if (subSymbols!=null) { |
|
256 |
for (int i = 0; i < subSymbols.length; i++) { |
|
257 |
subSymbols[i].drawInsideRectangle(g, scaleInstance, r); |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
public void setCharacter(int symbol) { |
|
263 |
this.symbol = symbol; |
|
264 |
} |
|
265 |
|
|
266 |
public String getClassName() { |
|
267 |
return this.getClass().getName(); |
|
268 |
} |
|
269 |
|
|
270 |
public void setXMLEntity(XMLEntity xml) { |
|
271 |
color = StringUtilities.string2Color(xml.getStringProperty("color")); |
|
272 |
Point p = new Point(); |
|
273 |
p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset")); |
|
274 |
|
|
275 |
desc = xml.getStringProperty("desc"); |
|
276 |
font = new Font(xml.getStringProperty("font"), |
|
277 |
xml.getIntProperty("fontStyle"), |
|
278 |
100 /* or whatever*/); |
|
279 |
isShapeVisible = xml.getBooleanProperty("isShapeVisible"); |
|
280 |
symbol = xml.getIntProperty("symbolCode"); |
|
281 |
offset = p; |
|
282 |
rotation = xml.getDoubleProperty("rotation"); |
|
283 |
|
|
284 |
} |
|
285 |
} |
|
0 | 286 |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/AbstractMarkerSymbol.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-10-31 16:16:34 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.4 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.3 2006/10/26 16:27:33 jaume |
|
53 |
* support for composite marker symbols (not tested) |
|
54 |
* |
|
55 |
* Revision 1.2 2006/10/26 07:46:58 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.1 2006/10/25 10:50:41 jaume |
|
59 |
* movement of classes and gui stuff |
|
60 |
* |
|
61 |
* Revision 1.1 2006/10/18 07:54:06 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* |
|
65 |
*/ |
|
66 |
package com.iver.cit.gvsig.fmap.core.symbols; |
|
67 |
|
|
68 |
import java.awt.Point; |
|
69 |
import java.awt.geom.Point2D; |
|
70 |
import java.util.ArrayList; |
|
71 |
|
|
72 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
73 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
74 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
75 |
|
|
76 |
public abstract class AbstractMarkerSymbol implements ISymbol { |
|
77 |
|
|
78 |
protected boolean isShapeVisible = true; |
|
79 |
protected String desc; |
|
80 |
protected double rotation; |
|
81 |
protected Point2D offset; |
|
82 |
protected ISymbol[] subSymbols; // TODO maybe push it up to ISymbol |
|
83 |
public String getDescription() { |
|
84 |
return desc; |
|
85 |
} |
|
86 |
|
|
87 |
public boolean isShapeVisible() { |
|
88 |
return isShapeVisible; |
|
89 |
} |
|
90 |
public void setDescription(String desc) { |
|
91 |
this.desc = desc; |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
public double getRotation() { |
|
96 |
return rotation; |
|
97 |
} |
|
98 |
|
|
99 |
public void setRotation(double r) { |
|
100 |
this.rotation = r; |
|
101 |
} |
|
102 |
public Point2D getOffset() { |
|
103 |
if (offset == null) { |
|
104 |
offset = new Point(); |
|
105 |
} |
|
106 |
return offset; |
|
107 |
} |
|
108 |
|
|
109 |
public void setOffset(Point offset) { |
|
110 |
this.offset = offset; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* TODO maybe push it up to ISymbol |
|
115 |
* @param sym |
|
116 |
*/ |
|
117 |
public void addSymbol(ISymbol sym) { |
|
118 |
int capacity = 0; |
|
119 |
if (subSymbols != null) |
|
120 |
capacity = subSymbols.length; |
|
121 |
ArrayList lst = new ArrayList(capacity); |
|
122 |
for (int i = 0; i < capacity; i++) { |
|
123 |
lst.add(subSymbols[i]); |
|
124 |
} |
|
125 |
subSymbols = (ISymbol[])lst.toArray(new ISymbol[0]); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* TODO maybe push it up to ISymbol |
|
130 |
* @param sym |
|
131 |
* @return true if this symbol contains the removed one |
|
132 |
*/ |
|
133 |
public boolean removeSymbol(ISymbol sym) { |
|
134 |
|
|
135 |
int capacity = 0; |
|
136 |
if (subSymbols != null) |
|
137 |
capacity = subSymbols.length; |
|
138 |
ArrayList lst = new ArrayList(capacity); |
|
139 |
for (int i = 0; i < capacity; i++) { |
|
140 |
lst.add(subSymbols[i]); |
|
141 |
} |
|
142 |
boolean contains = lst.remove(sym); |
|
143 |
subSymbols = (ISymbol[])lst.toArray(new ISymbol[0]); |
|
144 |
return contains; |
|
145 |
} |
|
146 |
|
|
147 |
public boolean isSuitableFor(IGeometry geom) { |
|
148 |
return geom.getGeometryType() == FShape.POINT; |
|
149 |
} |
|
150 |
} |
|
0 | 151 |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/MarkerFillSymbol.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1 2006-10-30 19:30:35 jaume
|
|
46 |
* Revision 1.2 2006-10-31 16:16:34 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.1 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
49 | 51 |
* |
52 |
* |
|
50 | 53 |
*/ |
51 | 54 |
package com.iver.cit.gvsig.fmap.core.symbols; |
52 | 55 |
|
... | ... | |
64 | 67 |
|
65 | 68 |
public class MarkerFillSymbol extends AbstractFillSymbol { |
66 | 69 |
private double rotation; |
67 |
private AbstractMarker markerSymbol; |
|
70 |
private AbstractMarkerSymbol markerSymbol;
|
|
68 | 71 |
private boolean grid; |
69 | 72 |
private double xOffset = 0; |
70 | 73 |
private double yOffset = 0; |
... | ... | |
88 | 91 |
this.markerSize = markerSize; |
89 | 92 |
} |
90 | 93 |
|
91 |
public AbstractMarker getMarkerSymbol() { |
|
94 |
public AbstractMarkerSymbol getMarkerSymbol() {
|
|
92 | 95 |
return markerSymbol; |
93 | 96 |
} |
94 | 97 |
|
95 |
public void setMarkerSymbol(AbstractMarker markerSymbol) { |
|
98 |
public void setMarkerSymbol(AbstractMarkerSymbol markerSymbol) {
|
|
96 | 99 |
this.markerSymbol = markerSymbol; |
97 | 100 |
} |
98 | 101 |
|
... | ... | |
157 | 160 |
|
158 | 161 |
public XMLEntity getXMLEntity() { |
159 | 162 |
XMLEntity xml = new XMLEntity(); |
163 |
xml.putProperty("className", getClassName()); |
|
160 | 164 |
xml.putProperty("rotation", rotation); |
161 | 165 |
xml.putProperty("grid", grid); |
162 | 166 |
xml.putProperty("xOffset", xOffset); |
... | ... | |
191 | 195 |
int colCount = (int) ((r.getWidth()-xOffset)/xSeparation); |
192 | 196 |
|
193 | 197 |
double x = xOffset; |
194 |
double y = yOffset; |
|
198 |
double y = r.getHeight()-yOffset;
|
|
195 | 199 |
for (int i = 0; i < rowCount; i++) { |
196 | 200 |
for (int j = 0; j < colCount; j++) { |
197 | 201 |
points.add(new Point2D.Double(x, y)); |
198 | 202 |
x += xSeparation; |
199 | 203 |
} |
200 | 204 |
x = xOffset; |
201 |
y += ySeparation;
|
|
205 |
y -= ySeparation;
|
|
202 | 206 |
} |
203 | 207 |
} else { |
204 | 208 |
throw new Error("Not yet implemented!"); |
... | ... | |
217 | 221 |
yOffset = xml.getDoubleProperty("yOffset"); |
218 | 222 |
xSeparation = xml.getDoubleProperty("xSeparation"); |
219 | 223 |
ySeparation = xml.getDoubleProperty("ySeparation"); |
220 |
markerSymbol = (AbstractMarker) SymbolFactory. |
|
224 |
markerSymbol = (AbstractMarkerSymbol) SymbolFactory.
|
|
221 | 225 |
createFromXML(xml.getChild(0)); |
222 | 226 |
} |
223 | 227 |
|
224 |
public void setMarker(AbstractMarker marker) { |
|
228 |
public void setMarker(AbstractMarkerSymbol marker) {
|
|
225 | 229 |
this.markerSymbol = marker; |
226 | 230 |
} |
227 | 231 |
|
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/AbstractFillSymbol.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1 2006-10-30 19:30:35 jaume
|
|
46 |
* Revision 1.2 2006-10-31 16:16:34 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.1 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
49 | 51 |
* |
52 |
* |
|
50 | 53 |
*/ |
51 | 54 |
package com.iver.cit.gvsig.fmap.core.symbols; |
52 | 55 |
|
... | ... | |
79 | 82 |
return geom.getGeometryType() == FShape.POLYGON; |
80 | 83 |
} |
81 | 84 |
|
82 |
public ISymbol[] getLayers() { |
|
83 |
if (layers == null) |
|
84 |
layers = new ISymbol[1]; |
|
85 |
return layers; |
|
85 |
public ISymbol getLayer(int layerIndex) { |
|
86 |
try{ |
|
87 |
return layers[layerIndex]; |
|
88 |
} catch (Exception e) { |
|
89 |
return null; |
|
90 |
} |
|
86 | 91 |
} |
87 | 92 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/CharacterMarker.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-10-31 16:16:34 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
package com.iver.cit.gvsig.gvsig.gui.styling; |
|
52 |
|
|
53 |
import java.util.ArrayList; |
|
54 |
|
|
55 |
import javax.swing.JPanel; |
|
56 |
|
|
57 |
import com.iver.andami.PluginServices; |
|
58 |
import com.iver.utiles.XMLEntity; |
|
59 |
|
|
60 |
public class CharacterMarker extends AbstractTypeSymbolEditorPanel{ |
|
61 |
|
|
62 |
private ArrayList tabs = new ArrayList(); |
|
63 |
|
|
64 |
public CharacterMarker(SymbolEditor owner) { |
|
65 |
super(owner); |
|
66 |
initialize(); |
|
67 |
} |
|
68 |
|
|
69 |
private void initialize() { |
|
70 |
JPanel myTab; |
|
71 |
{ |
|
72 |
myTab = new JPanel(); |
|
73 |
myTab.setName(PluginServices.getText(this, "character_marker")); |
|
74 |
tabs.add(myTab); |
|
75 |
} |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
public XMLEntity getXMLEntity() { |
|
80 |
// TODO Auto-generated method stub |
|
81 |
return null; |
|
82 |
} |
|
83 |
|
|
84 |
public String getName() { |
|
85 |
return PluginServices.getText(this, "character_marker_symbol"); |
|
86 |
} |
|
87 |
|
|
88 |
public JPanel[] getTabs() { |
|
89 |
// TODO Auto-generated method stub |
|
90 |
return (JPanel[]) tabs .toArray(new JPanel[0]); |
|
91 |
} |
|
92 |
|
|
93 |
public void refreshControls(int layerIndex) { |
|
94 |
// TODO Auto-generated method stub |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
} |
|
0 | 99 |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/AbstractTypeSymbolEditorPanel.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.3 2006-10-30 19:30:35 jaume
|
|
46 |
* Revision 1.4 2006-10-31 16:16:34 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.3 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
49 | 52 |
* Revision 1.2 2006/10/29 23:53:49 jaume |
50 | 53 |
* *** empty log message *** |
51 | 54 |
* |
... | ... | |
63 | 66 |
public abstract class AbstractTypeSymbolEditorPanel { |
64 | 67 |
|
65 | 68 |
protected SymbolEditor owner; |
69 |
protected int layerIndex = 0; |
|
66 | 70 |
|
67 | 71 |
public abstract XMLEntity getXMLEntity(); |
68 | 72 |
/** |
... | ... | |
76 | 80 |
} |
77 | 81 |
public abstract String getName(); |
78 | 82 |
public abstract JPanel[] getTabs(); |
83 |
|
|
79 | 84 |
/** |
80 | 85 |
* Invoked when the user selects or adds a new layer. This method fills up |
81 | 86 |
* the components on the right according on the layer properties |
... | ... | |
88 | 93 |
} |
89 | 94 |
|
90 | 95 |
protected final void fireSymbolChangedEvent() { |
96 |
owner.setLayerToSymbol(owner.getSelectedLayerIndex(), getXMLEntity()); |
|
91 | 97 |
owner.refresh(); |
92 | 98 |
} |
93 | 99 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/SymbolSelector.java | ||
---|---|---|
614 | 614 |
xml.putProperty("outline", StringUtilities.color2String(jcc2.getColor())); |
615 | 615 |
} |
616 | 616 |
|
617 |
if (selectedSymbol != null) { |
|
618 |
selectedSymbol.setXMLEntity(xml); |
|
619 |
} |
|
620 |
|
|
621 | 617 |
SymbolSelector.this.repaint(); |
622 | 618 |
} |
623 | 619 |
} |
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/MarkerFill.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.3 2006-10-30 19:30:35 jaume
|
|
46 |
* Revision 1.4 2006-10-31 16:16:34 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.3 2006/10/30 19:30:35 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
49 | 52 |
* Revision 1.2 2006/10/29 23:53:49 jaume |
50 | 53 |
* *** empty log message *** |
51 | 54 |
* |
... | ... | |
71 | 74 |
import javax.swing.JRadioButton; |
72 | 75 |
|
73 | 76 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
77 |
import org.gvsig.gui.beans.swing.JBlank; |
|
74 | 78 |
import org.gvsig.gui.beans.swing.JButton; |
75 | 79 |
|
76 | 80 |
import com.iver.andami.PluginServices; |
77 | 81 |
import com.iver.cit.gvsig.fmap.core.FShape; |
78 | 82 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractFillSymbol; |
79 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarker; |
|
83 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol;
|
|
80 | 84 |
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol; |
81 | 85 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
82 | 86 |
import com.iver.utiles.StringUtilities; |
... | ... | |
87 | 91 |
public class MarkerFill extends AbstractTypeSymbolEditorPanel implements ActionListener { |
88 | 92 |
private static final String NAME = PluginServices. |
89 | 93 |
getText(MarkerFill.class, "marker_fill"); |
90 |
private static final double DEFAULT_SEPARATION = 20;
|
|
91 |
private static final double DEFAULT_OFFSET = 0;
|
|
94 |
private static final double DEFAULT_SEPARATION = 20;
|
|
95 |
private static final double DEFAULT_OFFSET = 10;
|
|
92 | 96 |
private ArrayList tabs = new ArrayList(); |
93 | 97 |
private JDecimalField txtOffsetX; |
94 | 98 |
private JDecimalField txtOffsetY; |
95 | 99 |
private JDecimalField txtSeparationX; |
96 | 100 |
private JDecimalField txtSeparationY; |
97 |
private ColorChooserPanel markerCC; |
|
98 |
private JButton btnChooseMarker; |
|
99 |
private JButton btnOutline; |
|
100 |
private JRadioButton rdGrid; |
|
101 |
private JRadioButton rdRandom; |
|
102 |
private MarkerFillSymbol mfs = new MarkerFillSymbol(); |
|
103 |
|
|
101 |
private ColorChooserPanel markerCC; |
|
102 |
private JButton btnChooseMarker; |
|
103 |
private JButton btnOutline; |
|
104 |
private JRadioButton rdGrid; |
|
105 |
private JRadioButton rdRandom; |
|
106 |
private MarkerFillSymbol mfs = new MarkerFillSymbol(); |
|
104 | 107 |
public MarkerFill(SymbolEditor owner) { |
105 | 108 |
super(owner); |
106 | 109 |
initialize(); |
107 | 110 |
} |
108 | 111 |
|
109 | 112 |
private void initialize() { |
110 |
//XMLEntity xml = owner.getSymbol().getXMLEntity(); |
|
111 |
|
|
112 | 113 |
GridLayout layout; |
113 | 114 |
JPanel myTab; |
114 | 115 |
// Marker fill tab |
115 | 116 |
|
116 | 117 |
{ |
117 | 118 |
|
118 |
myTab = new GridBagLayoutPanel();
|
|
119 |
myTab.setName(PluginServices.getText(this, "marker_fill"));
|
|
119 |
myTab = new GridBagLayoutPanel();
|
|
120 |
myTab.setName(PluginServices.getText(this, "marker_fill"));
|
|
120 | 121 |
|
121 |
GridBagLayoutPanel p = (GridBagLayoutPanel) myTab; |
|
122 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
123 |
markerCC = new ColorChooserPanel(); |
|
124 |
markerCC.setAlpha(255); |
|
125 |
markerCC.addActionListener(this); |
|
126 |
aux.add(markerCC); |
|
127 | 122 |
|
128 |
p.addComponent(PluginServices.getText(this, "color"), aux);
|
|
129 |
btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker"));
|
|
130 |
btnChooseMarker.addActionListener(this);
|
|
131 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
|
|
132 |
aux.add(btnChooseMarker);
|
|
133 |
p.addComponent("", aux);
|
|
123 |
GridBagLayoutPanel p = (GridBagLayoutPanel) myTab;
|
|
124 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
|
|
125 |
markerCC = new ColorChooserPanel();
|
|
126 |
markerCC.setAlpha(255);
|
|
127 |
markerCC.addActionListener(this);
|
|
128 |
aux.add(markerCC);
|
|
134 | 129 |
|
135 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
136 |
btnOutline = new JButton(PluginServices.getText(this, "outline")); |
|
137 |
aux.add(btnOutline); |
|
138 |
btnOutline.setEnabled(false); |
|
139 |
p.addComponent("", aux); |
|
130 |
p.addComponent(PluginServices.getText(this, "color"), aux); |
|
131 |
btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker")); |
|
132 |
btnChooseMarker.addActionListener(this); |
|
133 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
134 |
aux.add(btnChooseMarker); |
|
135 |
p.addComponent("", aux); |
|
140 | 136 |
|
141 |
ButtonGroup group = new ButtonGroup(); |
|
142 |
rdGrid = new JRadioButton(PluginServices.getText(this, "grid")); |
|
143 |
rdGrid.addActionListener(this); |
|
144 |
rdRandom = new JRadioButton(PluginServices.getText(this, "random")); |
|
145 |
rdRandom.addActionListener(this); |
|
146 |
group.add(rdGrid); |
|
147 |
group.add(rdRandom); |
|
137 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
138 |
btnOutline = new JButton(PluginServices.getText(this, "outline")); |
|
139 |
aux.add(btnOutline); |
|
140 |
btnOutline.setEnabled(false); |
|
141 |
p.addComponent("", aux); |
|
148 | 142 |
|
143 |
ButtonGroup group = new ButtonGroup(); |
|
144 |
rdGrid = new JRadioButton(PluginServices.getText(this, "grid")); |
|
145 |
rdGrid.addActionListener(this); |
|
146 |
rdRandom = new JRadioButton(PluginServices.getText(this, "random")); |
|
147 |
rdRandom.addActionListener(this); |
|
148 |
group.add(rdGrid); |
|
149 |
group.add(rdRandom); |
|
149 | 150 |
|
150 | 151 |
|
151 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
152 |
aux.add(rdGrid); |
|
153 |
aux.add(rdRandom); |
|
154 | 152 |
|
155 |
p.addComponent("", aux); |
|
153 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
154 |
aux.add(rdGrid); |
|
155 |
aux.add(rdRandom); |
|
156 |
|
|
157 |
p.addComponent("", aux); |
|
158 |
|
|
159 |
p.addComponent(new JBlank(50,50), new JBlank(50,50)); |
|
156 | 160 |
} |
157 | 161 |
tabs.add(myTab); |
158 | 162 |
|
159 | 163 |
// Fill properties tab |
160 | 164 |
{ |
161 |
layout = new GridLayout();
|
|
165 |
layout = new GridLayout();
|
|
162 | 166 |
layout.setColumns(1); |
163 | 167 |
layout.setVgap(5); |
164 | 168 |
myTab = new JPanel(); |
... | ... | |
218 | 222 |
myTab.setLayout(layout); |
219 | 223 |
} |
220 | 224 |
tabs.add(myTab); |
225 |
// if (xml != null) { |
|
226 |
// // restore previous values |
|
227 |
// txtOffsetX.setText(xml.getStringProperty("xOffset")); |
|
228 |
// txtOffsetY.setText(xml.getStringProperty("yOffset")); |
|
229 |
// txtSeparationX.setText(xml.getStringProperty("xSeparation")); |
|
230 |
// txtSeparationY.setText(xml.getStringProperty("ySeparation")); |
|
231 |
// rdGrid.setSelected(xml.getBooleanProperty("grid")); |
|
232 |
// } else { |
|
233 |
// // set defaults |
|
234 |
// |
|
235 |
// } |
|
221 | 236 |
} |
222 | 237 |
|
223 | 238 |
public void refreshControls(int layerIndex) { |
224 | 239 |
|
225 | 240 |
|
226 |
AbstractFillSymbol sym = (AbstractFillSymbol) owner.getSymbol(); |
|
227 |
if (layerIndex > sym.getLayers().length) |
|
228 |
return; |
|
229 |
XMLEntity xml = sym.getLayers()[layerIndex].getXMLEntity(); |
|
230 |
Color c = null; |
|
231 |
if (xml.contains("color")) { |
|
232 |
c = StringUtilities.string2Color(xml.getStringProperty("color")); |
|
233 |
} else { |
|
234 |
c = Color.BLACK; |
|
235 |
} |
|
236 |
markerCC.setColor(c); |
|
241 |
AbstractFillSymbol sym = (AbstractFillSymbol) owner.getSymbol(); |
|
242 |
if (sym.getLayer(layerIndex) == null) { |
|
243 |
// set defaults |
|
244 |
markerCC.setColor(Color.BLACK); |
|
245 |
rdGrid.setSelected(true); |
|
246 |
rdRandom.setSelected(false); |
|
247 |
txtOffsetX.setText(String.valueOf(DEFAULT_OFFSET)); |
|
248 |
txtOffsetY.setText(String.valueOf(DEFAULT_OFFSET)); |
|
249 |
txtSeparationX.setText(String.valueOf(DEFAULT_SEPARATION)); |
|
250 |
txtSeparationY.setText(String.valueOf(DEFAULT_SEPARATION)); |
|
251 |
} else { |
|
252 |
XMLEntity xml = sym.getLayer(layerIndex).getXMLEntity(); |
|
253 |
markerCC.setColor(StringUtilities.string2Color(xml.getStringProperty("color"))); |
|
254 |
boolean b = xml.getBooleanProperty("grid"); |
|
255 |
rdGrid.setSelected(b); |
|
256 |
rdRandom.setSelected(!b); |
|
237 | 257 |
|
238 |
if (xml.contains("grid")) { |
|
239 |
boolean b = xml.getBooleanProperty("grid"); |
|
240 |
rdGrid.setSelected(b); |
|
241 |
rdRandom.setSelected(!b); |
|
242 |
} else { |
|
243 |
System.err.println("en un funcionament normal, per ac? no deuria de passar"); |
|
244 |
} |
|
258 |
txtOffsetX.setText(String.valueOf(xml.getDoubleProperty("xOffset"))); |
|
259 |
txtOffsetY.setText(String.valueOf(xml.getDoubleProperty("yOffset"))); |
|
245 | 260 |
|
246 |
if (xml.contains("xOffset")) { |
|
247 |
mfs.setXOffset(xml.getDoubleProperty("xOffset")); |
|
248 |
} else { |
|
249 |
mfs.setYOffset(DEFAULT_OFFSET); |
|
250 |
} |
|
251 |
|
|
252 |
if (xml.contains("yOffset")) { |
|
253 |
mfs.setYOffset(xml.getDoubleProperty("yOffset")); |
|
254 |
} else { |
|
255 |
mfs.setXOffset(DEFAULT_OFFSET); |
|
256 |
} |
|
257 |
|
|
258 |
if (xml.contains("xSeparation")) { |
|
259 |
mfs.setXSeparation(xml.getDoubleProperty("xSeparation")); |
|
260 |
} else { |
|
261 |
mfs.setXSeparation(DEFAULT_SEPARATION); |
|
262 |
} |
|
263 |
|
|
264 |
if (xml.contains("ySeparation")) { |
|
265 |
mfs.setYSeparation(xml.getDoubleProperty("ySeparation")); |
|
266 |
} else { |
|
267 |
mfs.setYSeparation(DEFAULT_SEPARATION); |
|
268 |
} |
|
261 |
txtSeparationX.setText(String.valueOf(xml.getDoubleProperty("xSeparation"))); |
|
262 |
txtSeparationY.setText(String.valueOf(xml.getDoubleProperty("ySeparation"))); |
|
263 |
} |
|
269 | 264 |
} |
270 | 265 |
|
271 | 266 |
public XMLEntity getXMLEntity() { |
272 |
XMLEntity xml = new XMLEntity(); |
|
273 |
xml.putProperty("xOffset", txtOffsetX.getText()); |
|
274 |
xml.putProperty("yOffset", txtOffsetY.getText()); |
|
275 |
xml.putProperty("xSeparation", txtSeparationX.getText()); |
|
276 |
xml.putProperty("ySeparation", txtSeparationY.getText()); |
|
277 |
xml.putProperty("isGrid", rdGrid.isSelected()); |
|
278 |
xml.putProperty("color", StringUtilities.color2String(markerCC.getColor())); |
|
279 |
return xml; |
|
267 |
return mfs.getXMLEntity(); |
|
280 | 268 |
} |
281 | 269 |
|
282 | 270 |
public String getName() { |
... | ... | |
287 | 275 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
288 | 276 |
} |
289 | 277 |
|
290 |
public void actionPerformed(ActionEvent e) {
|
|
291 |
JComponent comp = (JComponent) e.getSource();
|
|
292 |
if (comp.equals(btnChooseMarker)) {
|
|
293 |
AbstractFillSymbol ownersSymbol = (AbstractFillSymbol) owner.getSymbol();
|
|
278 |
public void actionPerformed(ActionEvent e) {
|
|
279 |
JComponent comp = (JComponent) e.getSource();
|
|
280 |
if (comp.equals(btnChooseMarker)) {
|
|
281 |
AbstractFillSymbol ownersSymbol = (AbstractFillSymbol) owner.getSymbol();
|
|
294 | 282 |
|
295 | 283 |
|
296 |
SymbolSelector symSelect = new SymbolSelector( |
|
297 |
ownersSymbol.getLayers().length >0 ? ownersSymbol.getLayers()[0] : null |
|
298 |
, FShape.POINT); |
|
299 |
PluginServices.getMDIManager().addWindow(symSelect); |
|
300 |
AbstractMarker marker = (AbstractMarker) symSelect.getSymbol(); |
|
301 |
/*XMLEntity xml = owner.getSymbol().getXMLEntity(); |
|
302 |
xml.removeAllChildren(); |
|
303 |
xml.addChild(marker.getXMLEntity()); |
|
304 |
owner.getSymbol().setXMLEntity(xml);*/ |
|
305 |
mfs.setMarker(marker); |
|
306 |
} |
|
307 |
try { |
|
308 |
mfs.setXOffset(Double.parseDouble(txtOffsetX.getText())); |
|
309 |
mfs.setYOffset(Double.parseDouble(txtOffsetY.getText())); |
|
310 |
mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText())); |
|
311 |
mfs.setYSeparation(Double.parseDouble(txtSeparationX.getText())); |
|
312 |
mfs.setGrid(rdGrid.isSelected()); |
|
313 |
} catch (Exception ex) {} |
|
314 |
//mfs.setRotation() TODO |
|
315 |
fireSymbolChangedEvent(); |
|
316 |
} |
|
284 |
SymbolSelector symSelect = new SymbolSelector( ownersSymbol.getLayer(layerIndex), FShape.POINT); |
|
285 |
PluginServices.getMDIManager().addWindow(symSelect); |
|
286 |
AbstractMarkerSymbol marker = (AbstractMarkerSymbol) symSelect.getSymbol(); |
|
287 |
/*XMLEntity xml = owner.getSymbol().getXMLEntity(); |
|
288 |
xml.removeAllChildren(); |
|
289 |
xml.addChild(marker.getXMLEntity()); |
|
290 |
owner.getSymbol().setXMLEntity(xml);*/ |
|
291 |
mfs.setMarker(marker); |
|
292 |
} |
|
293 |
try { |
|
294 |
mfs.setXOffset(Double.parseDouble(txtOffsetX.getText())); |
|
295 |
} catch (Exception ex) {} |
|
296 |
try { |
|
297 |
mfs.setYOffset(Double.parseDouble(txtOffsetY.getText())); |
|
298 |
} catch (Exception ex) {} |
|
299 |
try { |
|
300 |
mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText())); |
|
301 |
} catch (Exception ex) {} |
|
302 |
try { |
|
303 |
mfs.setYSeparation(Double.parseDouble(txtSeparationY.getText())); |
|
304 |
} catch (Exception ex) {} |
|
305 |
try { |
|
306 |
mfs.setGrid(rdGrid.isSelected()); |
|
307 |
} catch (Exception ex) {} |
|
317 | 308 |
|
309 |
fireSymbolChangedEvent(); |
|
310 |
} |
|
311 |
|
|
318 | 312 |
} |
Also available in: Unified diff