Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SmartTextSymbol.java @ 13100

History | View | Annotate | Download (6.88 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 13100 2007-08-16 06:55:30Z jvidal $
45
* $Log$
46
* Revision 1.5  2007-08-16 06:55:19  jvidal
47
* javadoc updated
48
*
49
* Revision 1.4  2007/08/13 11:36:50  jvidal
50
* javadoc
51
*
52
* Revision 1.3  2007/03/28 16:48:14  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.2  2007/03/21 17:36:22  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1  2007/03/09 11:20:56  jaume
59
* Advanced symbology (start committing)
60
*
61
* Revision 1.1.2.8  2007/02/21 07:34:09  jaume
62
* labeling starts working
63
*
64
* Revision 1.1.2.7  2007/02/16 10:54:12  jaume
65
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
66
*
67
* Revision 1.1.2.6  2007/02/15 16:23:44  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.1.2.5  2007/02/09 07:47:05  jaume
71
* Isymbol moved
72
*
73
* Revision 1.1.2.4  2007/02/08 07:36:38  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1.2.3  2007/02/06 16:54:36  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1.2.2  2007/02/06 16:47:35  jaume
80
* first steps, follows a line
81
*
82
* Revision 1.1.2.1  2007/02/02 16:21:24  jaume
83
* start commiting labeling stuff
84
*
85
* Revision 1.1  2007/01/24 17:58:22  jaume
86
* new features and architecture error fixes
87
*
88
*
89
*/
90
package com.iver.cit.gvsig.fmap.core.symbols;
91

    
92
import java.awt.Color;
93
import java.awt.Font;
94
import java.awt.Graphics2D;
95
import java.awt.Rectangle;
96
import java.awt.Shape;
97
import java.awt.geom.AffineTransform;
98

    
99
import javax.print.attribute.PrintRequestAttributeSet;
100

    
101
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
102
import com.iver.cit.gvsig.fmap.core.FShape;
103
import com.iver.cit.gvsig.fmap.core.IGeometry;
104
import com.iver.cit.gvsig.fmap.core.TextPath;
105
import com.iver.cit.gvsig.fmap.rendering.styling.ITextParser;
106
import com.iver.utiles.XMLEntity;
107

    
108
/**
109
 * Class used to create symbols composed using a text defined by
110
 * the user.This text can be edited (changing the color, the font of the characters, and
111
 * the rotation of the text)and has the property that can follow a path.If this path
112
 * does not exist, the text is treated as a simpletextsymbol (when is drawn).
113
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
114
 */
115
public class SmartTextSymbol extends SimpleTextSymbol implements ITextSymbol {
116
        private static ITextParser parse = new ITextParser() {
117
                public boolean hasTags() {
118
                        // TODO Implement it
119
                        throw new Error("Not yet implemented!");
120

    
121
                }
122
                public String next() {
123
                        // TODO Implement it
124
                        throw new Error("Not yet implemented!");
125

    
126
                }
127
        };
128

    
129
        private char[] text;
130
//        Background: ITextBackground
131
//        Case
132
        private double CharacterSpacing;
133
        private double CharacterWidth;
134
//        Direction
135
        private IFillSymbol fillSymbol;
136
        private double flipAngle;
137
//        boolean kerning;
138
        private double leading;
139
//        Position: textPosition
140
        private Color ShadowColor;
141
        private double ShadowXOffset;
142
        private double ShadowYOffset;
143
//        TypeSetting: Boolean
144
        private double WordSpacing;
145
//        ISimpleTextSymbol : ITextSymbol
146
//        BreakCharacter: Long
147
//        Clip: Boolean
148
        private TextPath textPath;
149
        private double xOffset;
150
        private double yOffset;
151
        private double angle;
152
//        Color: IColor
153

    
154
//        HorizontalAlignment:
155
//        esriTextHorizontalAlignment
156
        private boolean rightToLeft;
157
        //        VerticalAlignment
158
        private double maskSize;
159
//        MaskStyle
160
        private  IFillSymbol maskSymbol;
161
        private double margin;
162

    
163
        public ISymbol getSymbolForSelection() {
164
                return this; // a text is not selectable
165
        }
166

    
167
        /**
168
         * Draws the text according. If this symbol has the text path set, then
169
         * it is used as the text line, otherwise shp <b>must be an FPoint2D</b>
170
         * indicating the starting point of the text and then the text will
171
         * be rendered from there and following the rotation previously set.
172
         */
173
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
174
                if (!isShapeVisible()) return;
175
                g.setFont(getFont());
176

    
177
                g.setColor(Color.BLACK);
178
                if (textPath != null) {
179
                        //AffineTransform at = (AffineTransform) g.getTransform().clone();
180
                        for (int i = 0; i < text.length; i++) {
181
                                double[] pos = textPath.nextPosForGlyph(i);
182
                                g.translate((int) pos[0], (int) pos[1]);
183
                                g.rotate(pos[2]);
184
                                g.drawChars(new char[] {text[i]}, 0, 1, 0, 0);
185
                                g.rotate(-pos[2]);
186
                                g.translate(-(int) pos[0], -(int) pos[1]);
187
                        }
188
                } else {
189
                        super.draw(g, affineTransform, shp);
190
                }
191
        }
192

    
193
        public void setTextPath(TextPath textPath) {
194
                this.textPath = textPath;
195
        }
196

    
197
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
198
                // TODO Implement it
199
                throw new Error("Not yet implemented!");
200

    
201
        }
202

    
203
        public int getOnePointRgb() {
204
                return getTextColor().getRGB();
205
        }
206

    
207
        public XMLEntity getXMLEntity() {
208
                XMLEntity xml = new XMLEntity();
209
                xml.putProperty("className", getClassName());
210
                xml.putProperty("desc", getDescription());
211
                xml.putProperty("isShapeVisible", isShapeVisible());
212
                return xml;
213
        }
214

    
215
        public int getSymbolType() {
216
                return FShape.TEXT;
217
        }
218

    
219
        public boolean isSuitableFor(IGeometry geom) {
220
                return true;
221
        }
222

    
223
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
224
                g.drawString("Not yet implemented", 0, r.height);
225
        }
226

    
227
        public void setPrintingProperties(PrintRequestAttributeSet printProperties) {
228
                // TODO Implement it
229
                throw new Error("Not yet implemented!");
230

    
231
        }
232

    
233
        public String getClassName() {
234
                return getClass().getName();
235
        }
236

    
237
        public void setXMLEntity(XMLEntity xml) {
238
                setFont(new Font("Arial", Font.PLAIN, 18));
239
                setText("this is my TEST text that follows a line");
240
                setDescription(xml.getStringProperty("desc"));
241
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
242

    
243
        }
244

    
245
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException {
246
                // TODO Implement it
247
                throw new Error("Not yet implemented!");
248

    
249
        }
250

    
251
        public void setText(String text) {
252
                this.text = text.toCharArray();
253
        }
254

    
255
        public String getText() {
256
                return new String(text);
257
        }
258
}