Revision 41130
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/label/SmartTextSymbolLabelClass.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 |
package org.gvsig.labeling.label; |
|
42 |
|
|
43 |
import java.awt.Graphics2D; |
|
44 |
import java.awt.Rectangle; |
|
45 |
|
|
46 |
import org.slf4j.Logger; |
|
47 |
import org.slf4j.LoggerFactory; |
|
48 |
|
|
49 |
import org.gvsig.fmap.geom.Geometry; |
|
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelLocationMetrics; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
|
53 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
|
54 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
|
55 |
import org.gvsig.labeling.symbol.SmartTextSymbol; |
|
56 |
import org.gvsig.symbology.SymbologyLocator; |
|
57 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelClass; |
|
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelLocationMetrics; |
|
59 |
import org.gvsig.tools.ToolsLocator; |
|
60 |
import org.gvsig.tools.dynobject.DynStruct; |
|
61 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
62 |
import org.gvsig.tools.persistence.PersistentState; |
|
63 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
64 |
import org.gvsig.tools.util.Callable; |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* <p> |
|
69 |
* SmartTextSymbolLabelClass.java<br> |
|
70 |
* </p> |
|
71 |
* |
|
72 |
* <p> |
|
73 |
* |
|
74 |
* This is a <b>wrapper</b> to be able to use a SmartTextSymbol as a |
|
75 |
* LabelClass. A SmartTextSymbol uses a line instead of a point. |
|
76 |
* Being in fact a Line and not a Marker, it does not make any sense |
|
77 |
* to have label styles since the label styles are well-defined rectangle |
|
78 |
* areas where texts are placed in fields backgrounded by an image. In this |
|
79 |
* contexts, the area is defined dinamically for each line, and there is no |
|
80 |
* sense to have texts fields. They will be rendered as a single string |
|
81 |
* along a line.<br> |
|
82 |
* </p> |
|
83 |
* <p> The label itself is the SmartTextSymbol, |
|
84 |
* the geometry (the line), the label expression, |
|
85 |
* and the text applied to the symbol.<br> |
|
86 |
* </p> |
|
87 |
* <p> |
|
88 |
* Most of the operations performed by this LabelClass are in fact |
|
89 |
* delegated to the symbol.<br> |
|
90 |
* </p> |
|
91 |
* |
|
92 |
* |
|
93 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Mar 6, 2008 |
|
94 |
* |
|
95 |
*/ |
|
96 |
public class SmartTextSymbolLabelClass extends LabelClass { |
|
97 |
|
|
98 |
private static Logger logger = LoggerFactory.getLogger( |
|
99 |
SmartTextSymbolLabelClass.class); |
|
100 |
|
|
101 |
public static final String SMART_LABEL_CLASS_PERSISTENCE_DEFINITION_NAME = |
|
102 |
"Smart LabelClass"; |
|
103 |
|
|
104 |
private ILabelClass defLabelClass = null; |
|
105 |
private SmartTextSymbol smartTextSymbol; |
|
106 |
|
|
107 |
public SmartTextSymbolLabelClass() { |
|
108 |
defLabelClass = SymbologyLocator.getSymbologyManager().createDefaultLabel(); |
|
109 |
} |
|
110 |
|
|
111 |
public void draw(Graphics2D graphics, ILabelLocationMetrics llm, Geometry geo) { |
|
112 |
getTextSymbol().draw(graphics, null, geo, null, null); |
|
113 |
} |
|
114 |
|
|
115 |
public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) |
|
116 |
throws SymbolDrawingException { |
|
117 |
|
|
118 |
getTextSymbol().drawInsideRectangle(graphics, null, bounds, null); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
public String getClassName() { |
|
123 |
return getClass().getName(); |
|
124 |
} |
|
125 |
|
|
126 |
public ILabelStyle getLabelStyle() { |
|
127 |
// label style not allowed in this context |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
public ITextSymbol getTextSymbol() { |
|
133 |
if (smartTextSymbol == null) { |
|
134 |
smartTextSymbol = new SmartTextSymbol(); |
|
135 |
} |
|
136 |
return smartTextSymbol; |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
public void setLabelStyle(ILabelStyle labelStyle) { |
|
141 |
// operation not supported in this context |
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
public void setTextSymbol(ITextSymbol textSymbol) { |
|
146 |
if (textSymbol instanceof SmartTextSymbol) { |
|
147 |
this.smartTextSymbol = (SmartTextSymbol) textSymbol; |
|
148 |
} else { |
|
149 |
logger.error("While setting text symbol in label class", |
|
150 |
new Exception("Text symbol must be a SmartTextSymbol here")); |
|
151 |
} |
|
152 |
|
|
153 |
defLabelClass.setTextSymbol(textSymbol); |
|
154 |
} |
|
155 |
|
|
156 |
public void loadFromState(PersistentState state) |
|
157 |
throws PersistenceException { |
|
158 |
defLabelClass.loadFromState(state); |
|
159 |
} |
|
160 |
|
|
161 |
public void saveToState(PersistentState state) |
|
162 |
throws PersistenceException { |
|
163 |
defLabelClass.saveToState(state); |
|
164 |
} |
|
165 |
|
|
166 |
public static void registerPersistent() { |
|
167 |
|
|
168 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
169 |
if (manager.getDefinition(SMART_LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)==null) { |
|
170 |
|
|
171 |
DynStruct definition = manager.addDefinition( |
|
172 |
SmartTextSymbolLabelClass.class, |
|
173 |
SMART_LABEL_CLASS_PERSISTENCE_DEFINITION_NAME, |
|
174 |
SMART_LABEL_CLASS_PERSISTENCE_DEFINITION_NAME |
|
175 |
+ " Persistence definition", |
|
176 |
null, |
|
177 |
null |
|
178 |
); |
|
179 |
|
|
180 |
definition.extend(manager.getDefinition( |
|
181 |
LABEL_CLASS_PERSISTENCE_DEFINITION_NAME)); |
|
182 |
} |
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
} |
Also available in: Unified diff