Statistics
| Revision:

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

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

    
80
import java.awt.Color;
81
import java.awt.Font;
82
import java.awt.Graphics2D;
83
import java.awt.Rectangle;
84
import java.awt.Shape;
85
import java.awt.geom.AffineTransform;
86

    
87
import javax.print.attribute.PrintRequestAttributeSet;
88

    
89
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
90
import com.iver.cit.gvsig.fmap.core.FShape;
91
import com.iver.cit.gvsig.fmap.core.IGeometry;
92
import com.iver.cit.gvsig.fmap.core.TextPath;
93
import com.iver.cit.gvsig.fmap.rendering.styling.ITextParser;
94
import com.iver.utiles.XMLEntity;
95

    
96
/**
97
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
98
 */
99
public class SmartTextSymbol extends SimpleTextSymbol implements ITextSymbol {
100
        private static ITextParser parse = new ITextParser() {
101
                public boolean hasTags() {
102
                        // TODO Implement it
103
                        throw new Error("Not yet implemented!");
104

    
105
                }
106
                public String next() {
107
                        // TODO Implement it
108
                        throw new Error("Not yet implemented!");
109

    
110
                }
111
        };
112

    
113
        private char[] text;
114
//        Background: ITextBackground
115
//        Case
116
        private double CharacterSpacing;
117
        private double CharacterWidth;
118
//        Direction
119
        private IFillSymbol fillSymbol;
120
        private double flipAngle;
121
//        boolean kerning;
122
        private double leading;
123
//        Position: textPosition
124
        private Color ShadowColor;
125
        private double ShadowXOffset;
126
        private double ShadowYOffset;
127
//        TypeSetting: Boolean
128
        private double WordSpacing;
129
//        ISimpleTextSymbol : ITextSymbol
130
//        BreakCharacter: Long
131
//        Clip: Boolean
132
        private TextPath textPath;
133
        private double xOffset;
134
        private double yOffset;
135
        private double angle;
136
//        Color: IColor
137

    
138
//        HorizontalAlignment:
139
//        esriTextHorizontalAlignment
140
        private boolean rightToLeft;
141
        //        VerticalAlignment
142
        private double maskSize;
143
//        MaskStyle
144
        private  IFillSymbol maskSymbol;
145
        private double margin;
146

    
147
        public ISymbol getSymbolForSelection() {
148
                return this; // a text is not selectable
149
        }
150

    
151
        /**
152
         * Draws the text according. If this symbol has the text path set, then
153
         * it is used as the text line, otherwise shp <b>must be an FPoint2D</b>
154
         * indicating the starting point of the text and then the text will
155
         * be rendered from there and following the rotation previously set.
156
         */
157
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
158
                g.setFont(getFont());
159

    
160
                g.setColor(Color.BLACK);
161
                if (textPath != null) {
162
                        //AffineTransform at = (AffineTransform) g.getTransform().clone();
163
                        for (int i = 0; i < text.length; i++) {
164
                                double[] pos = textPath.nextPosForGlyph(i);
165
                                g.translate((int) pos[0], (int) pos[1]);
166
                                g.rotate(pos[2]);
167
                                g.drawChars(new char[] {text[i]}, 0, 1, 0, 0);
168
                                g.rotate(-pos[2]);
169
                                g.translate(-(int) pos[0], -(int) pos[1]);
170
                        }
171
                } else {
172
                        super.draw(g, affineTransform, shp);
173
                }
174
        }
175

    
176
        public void setTextPath(TextPath textPath) {
177
                this.textPath = textPath;
178
        }
179

    
180
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
181
                // TODO Implement it
182
                throw new Error("Not yet implemented!");
183

    
184
        }
185

    
186
        public int getOnePointRgb() {
187
                return getTextColor().getRGB();
188
        }
189

    
190
        public XMLEntity getXMLEntity() {
191
                XMLEntity xml = new XMLEntity();
192
                xml.putProperty("className", getClassName());
193
                xml.putProperty("desc", getDescription());
194

    
195
                return xml;
196
        }
197

    
198
        public int getSymbolType() {
199
                return FShape.TEXT;
200
        }
201

    
202
        public boolean isSuitableFor(IGeometry geom) {
203
                return true;
204
        }
205

    
206
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
207
                g.drawString("Not yet implemented", 0, r.height);
208
        }
209

    
210
        public void setPrintingProperties(PrintRequestAttributeSet printProperties) {
211
                // TODO Implement it
212
                throw new Error("Not yet implemented!");
213

    
214
        }
215

    
216
        public String getClassName() {
217
                return getClass().getName();
218
        }
219

    
220
        public void setXMLEntity(XMLEntity xml) {
221
                setFont(new Font("Arial", Font.PLAIN, 18));
222
                setText("this is my TEST text that follows a line");
223
                setTextColor(Color.BLACK);
224
                setIsShapeVisible(true);
225
        }
226

    
227
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException {
228
                // TODO Implement it
229
                throw new Error("Not yet implemented!");
230

    
231
        }
232

    
233
        public void setText(String text) {
234
                this.text = text.toCharArray();
235
        }
236

    
237
        public String getText() {
238
                return new String(text);
239
        }
240
}