svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SmartTextSymbol.java @ 19509
History | View | Annotate | Download (7.42 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: SmartTextSymbol.java 13953 2007-09-21 12:26:04Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.6 2007-09-21 12:25:32 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.5 2007/08/16 06:55:19 jvidal
|
50 |
* javadoc updated
|
51 |
*
|
52 |
* Revision 1.4 2007/08/13 11:36:50 jvidal
|
53 |
* javadoc
|
54 |
*
|
55 |
* Revision 1.3 2007/03/28 16:48:14 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.2 2007/03/21 17:36:22 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.1 2007/03/09 11:20:56 jaume
|
62 |
* Advanced symbology (start committing)
|
63 |
*
|
64 |
* Revision 1.1.2.8 2007/02/21 07:34:09 jaume
|
65 |
* labeling starts working
|
66 |
*
|
67 |
* Revision 1.1.2.7 2007/02/16 10:54:12 jaume
|
68 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
69 |
*
|
70 |
* Revision 1.1.2.6 2007/02/15 16:23:44 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1.2.5 2007/02/09 07:47:05 jaume
|
74 |
* Isymbol moved
|
75 |
*
|
76 |
* Revision 1.1.2.4 2007/02/08 07:36:38 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.1.2.3 2007/02/06 16:54:36 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.1.2.2 2007/02/06 16:47:35 jaume
|
83 |
* first steps, follows a line
|
84 |
*
|
85 |
* Revision 1.1.2.1 2007/02/02 16:21:24 jaume
|
86 |
* start commiting labeling stuff
|
87 |
*
|
88 |
* Revision 1.1 2007/01/24 17:58:22 jaume
|
89 |
* new features and architecture error fixes
|
90 |
*
|
91 |
*
|
92 |
*/
|
93 |
package com.iver.cit.gvsig.fmap.core.symbols; |
94 |
|
95 |
import java.awt.Color; |
96 |
import java.awt.Font; |
97 |
import java.awt.Graphics2D; |
98 |
import java.awt.Rectangle; |
99 |
import java.awt.Shape; |
100 |
import java.awt.geom.AffineTransform; |
101 |
|
102 |
import javax.print.attribute.PrintRequestAttributeSet; |
103 |
|
104 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
105 |
import com.iver.cit.gvsig.fmap.core.FShape; |
106 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
107 |
import com.iver.cit.gvsig.fmap.core.TextPath; |
108 |
import com.iver.cit.gvsig.fmap.rendering.styling.ITextParser; |
109 |
import com.iver.utiles.XMLEntity; |
110 |
import com.iver.utiles.swing.threads.Cancellable; |
111 |
|
112 |
/**
|
113 |
* Class used to create symbols composed using a text defined by
|
114 |
* the user.This text can be edited (changing the color, the font of the characters, and
|
115 |
* the rotation of the text)and has the property that can follow a path.If this path
|
116 |
* does not exist, the text is treated as a simpletextsymbol (when is drawn).
|
117 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
118 |
*/
|
119 |
public class SmartTextSymbol extends SimpleTextSymbol implements ITextSymbol { |
120 |
private static ITextParser parse = new ITextParser() { |
121 |
public boolean hasTags() { |
122 |
// TODO Implement it
|
123 |
throw new Error("Not yet implemented!"); |
124 |
|
125 |
} |
126 |
public String next() { |
127 |
// TODO Implement it
|
128 |
throw new Error("Not yet implemented!"); |
129 |
|
130 |
} |
131 |
}; |
132 |
|
133 |
private char[] text; |
134 |
// Background: ITextBackground
|
135 |
// Case
|
136 |
private double CharacterSpacing; |
137 |
private double CharacterWidth; |
138 |
// Direction
|
139 |
private IFillSymbol fillSymbol;
|
140 |
private double flipAngle; |
141 |
// boolean kerning;
|
142 |
private double leading; |
143 |
// Position: textPosition
|
144 |
private Color ShadowColor; |
145 |
private double ShadowXOffset; |
146 |
private double ShadowYOffset; |
147 |
// TypeSetting: Boolean
|
148 |
private double WordSpacing; |
149 |
// ISimpleTextSymbol : ITextSymbol
|
150 |
// BreakCharacter: Long
|
151 |
// Clip: Boolean
|
152 |
private TextPath textPath;
|
153 |
private double xOffset; |
154 |
private double yOffset; |
155 |
private double angle; |
156 |
// Color: IColor
|
157 |
|
158 |
// HorizontalAlignment:
|
159 |
// esriTextHorizontalAlignment
|
160 |
private boolean rightToLeft; |
161 |
// VerticalAlignment
|
162 |
private double maskSize; |
163 |
// MaskStyle
|
164 |
private IFillSymbol maskSymbol;
|
165 |
private double margin; |
166 |
|
167 |
public ISymbol getSymbolForSelection() {
|
168 |
return this; // a text is not selectable |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Draws the text according. If this symbol has the text path set, then
|
173 |
* it is used as the text line, otherwise shp <b>must be an FPoint2D</b>
|
174 |
* indicating the starting point of the text and then the text will
|
175 |
* be rendered from there and following the rotation previously set.
|
176 |
*/
|
177 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
178 |
if (!isShapeVisible()) return; |
179 |
g.setFont(getFont()); |
180 |
|
181 |
g.setColor(Color.BLACK);
|
182 |
if (textPath != null) { |
183 |
//AffineTransform at = (AffineTransform) g.getTransform().clone();
|
184 |
for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < text.length; i++) { |
185 |
double[] pos = textPath.nextPosForGlyph(i); |
186 |
g.translate((int) pos[0], (int) pos[1]); |
187 |
g.rotate(pos[2]);
|
188 |
g.drawChars(new char[] {text[i]}, 0, 1, 0, 0); |
189 |
g.rotate(-pos[2]);
|
190 |
g.translate(-(int) pos[0], -(int) pos[1]); |
191 |
} |
192 |
} else {
|
193 |
super.draw(g, affineTransform, shp, cancel);
|
194 |
} |
195 |
} |
196 |
|
197 |
public void setTextPath(TextPath textPath) { |
198 |
this.textPath = textPath;
|
199 |
} |
200 |
|
201 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
202 |
// TODO Implement it
|
203 |
throw new Error("Not yet implemented!"); |
204 |
|
205 |
} |
206 |
|
207 |
public int getOnePointRgb() { |
208 |
return getTextColor().getRGB();
|
209 |
} |
210 |
|
211 |
public XMLEntity getXMLEntity() {
|
212 |
XMLEntity xml = new XMLEntity();
|
213 |
xml.putProperty("className", getClassName());
|
214 |
xml.putProperty("desc", getDescription());
|
215 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
216 |
return xml;
|
217 |
} |
218 |
|
219 |
public int getSymbolType() { |
220 |
return FShape.TEXT;
|
221 |
} |
222 |
|
223 |
public boolean isSuitableFor(IGeometry geom) { |
224 |
return true; |
225 |
} |
226 |
|
227 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
228 |
g.drawString("Not yet implemented", 0, r.height); |
229 |
} |
230 |
|
231 |
public void setPrintingProperties(PrintRequestAttributeSet printProperties) { |
232 |
// TODO Implement it
|
233 |
throw new Error("Not yet implemented!"); |
234 |
|
235 |
} |
236 |
|
237 |
public String getClassName() { |
238 |
return getClass().getName();
|
239 |
} |
240 |
|
241 |
public void setXMLEntity(XMLEntity xml) { |
242 |
setFont(new Font("Arial", Font.PLAIN, 18)); |
243 |
setText("this is my TEST text that follows a line");
|
244 |
setDescription(xml.getStringProperty("desc"));
|
245 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
246 |
|
247 |
} |
248 |
|
249 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException { |
250 |
// TODO Implement it
|
251 |
throw new Error("Not yet implemented!"); |
252 |
|
253 |
} |
254 |
|
255 |
public void setText(String text) { |
256 |
this.text = text.toCharArray();
|
257 |
} |
258 |
|
259 |
public String getText() { |
260 |
return new String(text); |
261 |
} |
262 |
} |