svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / SmartTextSymbolLabelClass.java @ 40665
History | View | Annotate | Download (4.79 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 |
package org.gvsig.labeling; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.Shape; |
48 |
import java.awt.geom.PathIterator; |
49 |
|
50 |
import org.gvsig.symbology.fmap.symbols.SmartTextSymbol; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
53 |
import com.iver.cit.gvsig.fmap.core.FShape; |
54 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
55 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
56 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
58 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
59 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelLocationMetrics; |
60 |
import com.iver.utiles.XMLEntity; |
61 |
|
62 |
/**
|
63 |
* <p>
|
64 |
* SmartTextSymbolLabelClass.java<br>
|
65 |
* </p>
|
66 |
*
|
67 |
* <p>
|
68 |
*
|
69 |
* This is a <b>wrapper</b> to be able to use a SmartTextSymbol as a
|
70 |
* LabelClass. A SmartTextSymbol uses a line instead of a point.
|
71 |
* Being in fact a Line and not a Marker, it does not make any sense
|
72 |
* to have label styles since the label styles are well-defined rectangle
|
73 |
* areas where texts are placed in fields backgrounded by an image. In this
|
74 |
* contexts, the area is defined dinamically for each line, and there is no
|
75 |
* sense to have texts fields. They will be rendered as a single string
|
76 |
* along a line.<br>
|
77 |
* </p>
|
78 |
* <p> The label itself is the SmartTextSymbol,
|
79 |
* the geometry (the line), the label expression,
|
80 |
* and the text applied to the symbol.<br>
|
81 |
* </p>
|
82 |
* <p>
|
83 |
* Most of the operations performed by this LabelClass are in fact
|
84 |
* delegated to the symbol.<br>
|
85 |
* </p>
|
86 |
*
|
87 |
*
|
88 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Mar 6, 2008
|
89 |
*
|
90 |
*/
|
91 |
public class SmartTextSymbolLabelClass extends LabelClass { |
92 |
private SmartTextSymbol smartTextSymbol;
|
93 |
|
94 |
@Override
|
95 |
public void draw(Graphics2D graphics, LabelLocationMetrics llm, FShape shp) { |
96 |
|
97 |
getTextSymbol().draw(graphics, null, shp, null); |
98 |
|
99 |
|
100 |
} |
101 |
|
102 |
@Override
|
103 |
public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) |
104 |
throws SymbolDrawingException {
|
105 |
getTextSymbol().drawInsideRectangle(graphics, null, bounds, null); |
106 |
} |
107 |
|
108 |
|
109 |
@Override
|
110 |
public String getClassName() { |
111 |
return getClass().getName();
|
112 |
} |
113 |
|
114 |
@Override
|
115 |
public ILabelStyle getLabelStyle() {
|
116 |
// label style not allowed in this context
|
117 |
return null; |
118 |
} |
119 |
|
120 |
|
121 |
// @Override
|
122 |
// public FShape getShape(LabelLocationMetrics llm) {
|
123 |
// // TODO Auto-generated method stub
|
124 |
// throw new Error("Not yet implemented!");
|
125 |
// }
|
126 |
|
127 |
|
128 |
@Override
|
129 |
public ITextSymbol getTextSymbol() {
|
130 |
if (smartTextSymbol == null) { |
131 |
smartTextSymbol = new SmartTextSymbol();
|
132 |
} |
133 |
return smartTextSymbol;
|
134 |
} |
135 |
|
136 |
|
137 |
@Override
|
138 |
public XMLEntity getXMLEntity() {
|
139 |
XMLEntity xml = super.getXMLEntity();
|
140 |
xml.putProperty("className", getClassName());
|
141 |
return xml;
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
public void setLabelStyle(ILabelStyle labelStyle) { |
146 |
// operation don't supported in this context
|
147 |
} |
148 |
|
149 |
|
150 |
@Override
|
151 |
public void setTextSymbol(ITextSymbol textSymbol) { |
152 |
//// if (! (textSymbol instanceof SmartTextSymbol)) throw new IllegalArgumentException("Only SmartTextSymbol allowed in this context");
|
153 |
// if (! (textSymbol instanceof SmartTextSymbol)) {
|
154 |
// // transform it into a SmartTextSymbol
|
155 |
// SmartTextSymbol aux = new SmartTextSymbol();
|
156 |
// if (textSymbol != null) {
|
157 |
// aux.setDescription(textSymbol.getDescription());
|
158 |
// aux.setText(textSymbol.getText());
|
159 |
// aux.setFont(textSymbol.getFont());
|
160 |
// aux.setTextColor(textSymbol.getTextColor());
|
161 |
// aux.setFontSize(textSymbol.getFont().getSize());
|
162 |
//
|
163 |
// }
|
164 |
// textSymbol = aux;
|
165 |
// }
|
166 |
this.smartTextSymbol = (SmartTextSymbol) textSymbol;
|
167 |
super.setTextSymbol(textSymbol);
|
168 |
} |
169 |
|
170 |
|
171 |
} |