root / org.gvsig.legend.urbanhorizontalsignage / trunk / org.gvsig.legend.urbanhorizontalsignage.lib / org.gvsig.legend.urbanhorizontalsignage.lib.impl / src / main / java / org / gvsig / legend / urbanhorizontalsignage / lib / impl / DefaultUrbanHorizontalSignageLegend.java @ 5087
History | View | Annotate | Download (17.4 KB)
1 |
package org.gvsig.legend.urbanhorizontalsignage.lib.impl; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Image; |
5 |
import org.gvsig.fmap.dal.exception.DataException; |
6 |
import org.gvsig.fmap.dal.feature.Feature; |
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
8 |
import org.gvsig.fmap.dal.feature.FeatureType; |
9 |
import org.gvsig.fmap.geom.Geometry; |
10 |
import org.gvsig.fmap.mapcontext.MapContextException; |
11 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
12 |
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData; |
13 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE; |
14 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_GAP_WIDTH_VALUE; |
15 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_HOLES_COLOR_VALUE; |
16 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_HOLES_LENGTH_VALUE; |
17 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_PAINT_HOLES_VALUE; |
18 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_ROUND_VERTEX_VALUE; |
19 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_SEGMENT_COLOR_VALUE; |
20 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_SEGMENT_LENGTH_VALUE; |
21 |
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageData.DEFAULT_WIDTH_VALUE; |
22 |
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLegend; |
23 |
import org.gvsig.symbology.SymbologyLocator; |
24 |
import org.gvsig.symbology.SymbologyManager; |
25 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
26 |
import org.gvsig.tools.ToolsLocator; |
27 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
28 |
import org.gvsig.tools.persistence.PersistentState; |
29 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
30 |
import org.gvsig.tools.swing.api.DataTypes; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
public class DefaultUrbanHorizontalSignageLegend |
35 |
extends AbstractVectorialLegend
|
36 |
implements UrbanHorizontalSignageLegend //, IHasImageLegend |
37 |
{ |
38 |
|
39 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageLegend.class); |
40 |
|
41 |
private UrbanHorizontalSignageSymbol defaultSymbol;
|
42 |
private Image imageLegend; |
43 |
private String widthFieldName; |
44 |
private String continuityFieldName; |
45 |
private String holesLengthFieldName; |
46 |
private String holesColorFieldName; |
47 |
private String paintHolesFieldName; |
48 |
private String segmentsLengthFieldName; |
49 |
private String segmentsColorFieldName; |
50 |
private String roundVertexFieldName; |
51 |
private int gapWidth; |
52 |
|
53 |
public DefaultUrbanHorizontalSignageLegend() {
|
54 |
|
55 |
SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager(); |
56 |
this.defaultSymbol = new UrbanHorizontalSignageSymbol(); |
57 |
DefaultUrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
|
58 |
data.setContinuity(UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT); |
59 |
this.defaultSymbol.setData(new DefaultUrbanHorizontalSignageData()); |
60 |
|
61 |
this.gapWidth = DEFAULT_GAP_WIDTH_VALUE;
|
62 |
} |
63 |
|
64 |
// @Override
|
65 |
// protected String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
|
66 |
// FeatureType ftype = featureStore.getDefaultFeatureType();
|
67 |
// if( StringUtils.isEmpty(this.fieldName) ) {
|
68 |
// return new String[]{
|
69 |
// ftype.getDefaultGeometryAttributeName()
|
70 |
// };
|
71 |
// }
|
72 |
// return new String[]{
|
73 |
// ftype.getDefaultGeometryAttributeName(),
|
74 |
// this.fieldName
|
75 |
// };
|
76 |
// }
|
77 |
|
78 |
@Override
|
79 |
public ISymbol getDefaultSymbol() {
|
80 |
return this.defaultSymbol; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void setDefaultSymbol(ISymbol is) { |
85 |
//DO NOTHING
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException { |
90 |
|
91 |
UrbanHorizontalSignageData values = getValues(ftr); |
92 |
|
93 |
UrbanHorizontalSignageSymbol symbol = new UrbanHorizontalSignageSymbol();
|
94 |
symbol.setData(values); |
95 |
return symbol;
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public int getShapeType() { |
100 |
return Geometry.TYPES.CURVE;
|
101 |
} |
102 |
|
103 |
@Override
|
104 |
public void setShapeType(int i) { |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public boolean isUseDefaultSymbol() { |
109 |
return true; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void useDefaultSymbol(boolean bln) { |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public boolean isSuitableForShapeType(int shapeType) { |
118 |
return true; |
119 |
} |
120 |
|
121 |
// @Override
|
122 |
// protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, Map queryParameters, ICoordTrans coordTrans, FeatureStore featureStore, FeatureQuery featureQuery, double dpi) throws LegendException {
|
123 |
// int saved_distance = this.algorithm.getDistance();
|
124 |
// try {
|
125 |
// int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
|
126 |
// Geometry theROI = null;
|
127 |
// if (this.roi!=null) {
|
128 |
// theROI = this.roi.cloneGeometry();
|
129 |
// theROI.transform(viewPort.getAffineTransform());
|
130 |
// }
|
131 |
// this.algorithm.setDistance(distance);
|
132 |
// this.algorithm.init(image.getWidth(), image.getHeight());
|
133 |
// super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
|
134 |
// if( !cancel.isCanceled() ) {
|
135 |
// this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI);
|
136 |
// }
|
137 |
// } finally {
|
138 |
// this.algorithm.setDistance(saved_distance);
|
139 |
//
|
140 |
// }
|
141 |
// }
|
142 |
|
143 |
// @Override
|
144 |
// public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
145 |
// double scale, Map queryParameters, ICoordTrans coordTrans,
|
146 |
// FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
|
147 |
// throws LegendException {
|
148 |
// int saved_distance = this.algorithm.getDistance();
|
149 |
// try {
|
150 |
// double dpi = viewPort.getDPI();
|
151 |
// // Ver CartographicSupportToolkit.getCartographicLength
|
152 |
// int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
|
153 |
// Geometry theROI = null;
|
154 |
// if (this.roi!=null) {
|
155 |
// theROI = this.roi.cloneGeometry();
|
156 |
// theROI.transform(viewPort.getAffineTransform());
|
157 |
// }
|
158 |
// this.algorithm.setDistance(distance);
|
159 |
// this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight());
|
160 |
// BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
161 |
// super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
|
162 |
// if (!cancel.isCanceled()) {
|
163 |
// this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI);
|
164 |
// g.drawImage(image, 0, 0, null);
|
165 |
// }
|
166 |
// } finally {
|
167 |
// this.algorithm.setDistance(saved_distance);
|
168 |
//
|
169 |
// }
|
170 |
// }
|
171 |
|
172 |
// @Override
|
173 |
// protected void drawFeatures(
|
174 |
// BufferedImage image,
|
175 |
// Graphics2D g,
|
176 |
// final ViewPort viewPort,
|
177 |
// final Cancellable cancel,
|
178 |
// final ICoordTrans coordTrans,
|
179 |
// double dpi,
|
180 |
// DefaultFeatureDrawnNotification drawnNotification,
|
181 |
// FeatureSet featureSet,
|
182 |
// FeatureSelection selection
|
183 |
// ) throws BaseException {
|
184 |
//
|
185 |
// SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager();
|
186 |
//
|
187 |
// UrbanHorizontalSignageManager uhsManager = UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
|
188 |
//
|
189 |
// try {
|
190 |
// featureSet.accept(new Visitor() {
|
191 |
// @Override
|
192 |
// public void visit(Object obj) throws VisitCanceledException,
|
193 |
// BaseException {
|
194 |
// if (cancel.isCanceled()) {
|
195 |
// throw new VisitCanceledException();
|
196 |
// }
|
197 |
// Feature feature = (Feature) obj;
|
198 |
// UrbanHorizontalSignageData values = getValues(feature);
|
199 |
// Geometry originalGeometry = feature.getDefaultGeometry();
|
200 |
//
|
201 |
// ISimpleLineSymbol lineSymbol = symbologyManager.createSimpleLineSymbol();
|
202 |
// lineSymbol.setColor(Color.YELLOW);
|
203 |
//
|
204 |
// uhsManager.calculateGeometries(originalGeometry, values);
|
205 |
// MultiPolygon geom;
|
206 |
//
|
207 |
// ISimpleFillSymbol segmentsSymbol = symbologyManager.createSimpleFillSymbol();;
|
208 |
// segmentsSymbol.setFillColor(values.getSegmentsColor());
|
209 |
//
|
210 |
// ISimpleFillSymbol holesSymbol = symbologyManager.createSimpleFillSymbol();
|
211 |
// holesSymbol.setFillColor(values.getHolesColor());
|
212 |
//
|
213 |
// geom = values.getSegmentsGeometry();
|
214 |
// if (geom != null && geom.getPrimitivesNumber() > 0) {
|
215 |
// segmentsSymbol.draw(g, viewPort.getAffineTransform(), geom,
|
216 |
// feature, cancel);
|
217 |
// }
|
218 |
//
|
219 |
// switch (values.getContinuity()) {
|
220 |
//// case CONTINUITY_MODE_CONT:
|
221 |
//// case CONTINUITY_MODE_CONT_CONT:
|
222 |
//// geom = values.getSegmentsGeometry();
|
223 |
//// if(geom != null && geom.getPrimitivesNumber()>0){
|
224 |
//// segmentsSymbol.draw(g, viewPort.getAffineTransform(), geom,
|
225 |
//// feature, cancel);
|
226 |
//// }
|
227 |
//// break;
|
228 |
// case CONTINUITY_MODE_CONT_DISC:
|
229 |
// case CONTINUITY_MODE_DISC_CONT:
|
230 |
// case CONTINUITY_MODE_DISC:
|
231 |
// case CONTINUITY_MODE_DISC_DISC:
|
232 |
// if(values.isPaintHoles()){
|
233 |
// geom = values.getHolesGeometry();
|
234 |
// if(geom != null && geom.getPrimitivesNumber()>0){
|
235 |
// holesSymbol.draw(g, viewPort.getAffineTransform(), geom,
|
236 |
// feature, cancel);
|
237 |
// }
|
238 |
// }
|
239 |
// }
|
240 |
//
|
241 |
// //For debug purposse only
|
242 |
// lineSymbol.draw(g, viewPort.getAffineTransform(), originalGeometry,
|
243 |
// feature, cancel);
|
244 |
// }
|
245 |
// });
|
246 |
//
|
247 |
// } catch (ConcurrentDataModificationException e) {
|
248 |
// cancel.setCanceled(true);
|
249 |
// }
|
250 |
// }
|
251 |
|
252 |
// @Override
|
253 |
// public Image getImageLegend() {
|
254 |
// if( this.imageLegend==null ) {
|
255 |
//// BufferedImage img = new BufferedImage(80, 20, BufferedImage.TYPE_INT_RGB);
|
256 |
//// ColorTablePainter painter = new DefaultColorTablePainter(this.getTargetColorTable(),"");
|
257 |
//// Graphics2D g = img.createGraphics();
|
258 |
//// g.setClip(0, 0, 80, 20);
|
259 |
//// g.setBackground(Color.WHITE);
|
260 |
//// g.fillRect(0, 0, 80, 20);
|
261 |
//// painter.paint(g, false);
|
262 |
//// this.imageLegend = img;
|
263 |
// }
|
264 |
// return this.imageLegend;
|
265 |
// }
|
266 |
//
|
267 |
// @Override
|
268 |
// public String getPathImage() {
|
269 |
// return null;
|
270 |
// }
|
271 |
|
272 |
@Override
|
273 |
public void loadFromState(PersistentState state) throws PersistenceException { |
274 |
// this.defaultSymbol = new SimpleTextSymbol();
|
275 |
this.imageLegend = null; |
276 |
|
277 |
super.loadFromState(state);
|
278 |
this.widthFieldName = state.getString("widthFieldName"); |
279 |
this.continuityFieldName = state.getString("continuityFieldName"); |
280 |
this.holesLengthFieldName = state.getString("holesLengthFieldName"); |
281 |
this.holesColorFieldName = state.getString("holesColorFieldName"); |
282 |
this.paintHolesFieldName = state.getString("paintHolesFieldName"); |
283 |
this.segmentsLengthFieldName = state.getString("segmentsLengthFieldName"); |
284 |
this.segmentsColorFieldName = state.getString("segmentsColorFieldName"); |
285 |
this.roundVertexFieldName = state.getString("roundVertexFieldName"); |
286 |
this.gapWidth = state.getInt("gapWidth", DEFAULT_GAP_WIDTH_VALUE); |
287 |
} |
288 |
|
289 |
@Override
|
290 |
public void saveToState(PersistentState state) throws PersistenceException { |
291 |
super.saveToState(state);
|
292 |
state.set("widthFieldName", this.widthFieldName); |
293 |
state.set("continuityFieldName", this.continuityFieldName); |
294 |
state.set("holesLengthFieldName", this.holesLengthFieldName); |
295 |
state.set("holesColorFieldName", this.holesColorFieldName); |
296 |
state.set("paintHolesFieldName", this.paintHolesFieldName); |
297 |
state.set("segmentsLengthFieldName", this.segmentsLengthFieldName); |
298 |
state.set("segmentsColorFieldName", this.segmentsColorFieldName); |
299 |
state.set("roundVertexFieldName", this.roundVertexFieldName); |
300 |
state.set("gapWidth", this.gapWidth); |
301 |
} |
302 |
|
303 |
@Override
|
304 |
protected String[] getRequiredFeatureAttributeNames(FeatureStore fs) throws DataException { |
305 |
return new String[]{ |
306 |
this.widthFieldName,
|
307 |
this.continuityFieldName,
|
308 |
this.holesLengthFieldName,
|
309 |
this.holesColorFieldName,
|
310 |
this.paintHolesFieldName,
|
311 |
this.segmentsLengthFieldName,
|
312 |
this.segmentsColorFieldName,
|
313 |
this.roundVertexFieldName,
|
314 |
fs.getDefaultFeatureType().getDefaultGeometryAttributeName()}; |
315 |
} |
316 |
|
317 |
@Override
|
318 |
public String getWidthFieldName() { |
319 |
return this.widthFieldName; |
320 |
} |
321 |
|
322 |
@Override
|
323 |
public void setWidthFieldName(String fieldName) { |
324 |
this.widthFieldName = fieldName;
|
325 |
} |
326 |
|
327 |
@Override
|
328 |
public String getContinuityFieldName() { |
329 |
return this.continuityFieldName; |
330 |
} |
331 |
|
332 |
@Override
|
333 |
public void setContinuityFieldName(String fieldName) { |
334 |
this.continuityFieldName = fieldName;
|
335 |
} |
336 |
|
337 |
@Override
|
338 |
public String getSegmentsColorFieldName() { |
339 |
return this.segmentsColorFieldName; |
340 |
} |
341 |
|
342 |
@Override
|
343 |
public void setSegmentsColorFieldName(String fieldName) { |
344 |
this.segmentsColorFieldName = fieldName;
|
345 |
} |
346 |
|
347 |
@Override
|
348 |
public String getSegmentsLengthFieldName() { |
349 |
return this.segmentsLengthFieldName; |
350 |
} |
351 |
|
352 |
@Override
|
353 |
public void setSegmentsLengthFieldName(String fieldName) { |
354 |
this.segmentsLengthFieldName = fieldName;
|
355 |
} |
356 |
|
357 |
@Override
|
358 |
public String getPaintHolesFieldName() { |
359 |
return this.paintHolesFieldName; |
360 |
} |
361 |
|
362 |
@Override
|
363 |
public void setPaintHolesFieldName(String fieldName) { |
364 |
this.paintHolesFieldName = fieldName;
|
365 |
} |
366 |
|
367 |
@Override
|
368 |
public String getHolesColorFieldName() { |
369 |
return this.holesColorFieldName; |
370 |
} |
371 |
|
372 |
@Override
|
373 |
public void setHolesColorFieldName(String fieldName) { |
374 |
this.holesColorFieldName = fieldName;
|
375 |
} |
376 |
|
377 |
@Override
|
378 |
public String getHolesLengthFieldName() { |
379 |
return this.holesLengthFieldName; |
380 |
} |
381 |
|
382 |
@Override
|
383 |
public void setHolesLengthFieldName(String fieldName) { |
384 |
this.holesLengthFieldName = fieldName;
|
385 |
} |
386 |
|
387 |
@Override
|
388 |
public String getRoundVertexFieldName() { |
389 |
return this.roundVertexFieldName; |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public void setRoundVertexFieldName(String fieldName) { |
394 |
this.roundVertexFieldName = fieldName;
|
395 |
} |
396 |
|
397 |
@Override
|
398 |
public int getGapWidth() { |
399 |
return this.gapWidth; |
400 |
} |
401 |
|
402 |
@Override
|
403 |
public void setGapWith(int value) { |
404 |
this.gapWidth = value;
|
405 |
} |
406 |
|
407 |
@Override
|
408 |
public UrbanHorizontalSignageData getValues(Feature feature) {
|
409 |
UrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
|
410 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
411 |
FeatureType ftype = feature.getType(); |
412 |
double valueDouble = feature.getIntOrDefault( this.widthFieldName, (int)DEFAULT_WIDTH_VALUE*100 )/100.0; |
413 |
data.setWidth(valueDouble); |
414 |
int valueInt = feature.getIntOrDefault( this.continuityFieldName, DEFAULT_CONTINUITY_VALUE ); |
415 |
data.setContinuity(valueInt); |
416 |
Color valueColor = (Color)feature.getOrDefault( this.segmentsColorFieldName, DataTypes.COLOR, DEFAULT_SEGMENT_COLOR_VALUE ); |
417 |
data.setSegmentsColor(valueColor); |
418 |
valueDouble = feature.getIntOrDefault( this.segmentsLengthFieldName, (int)DEFAULT_SEGMENT_LENGTH_VALUE*100 )/100.0; |
419 |
data.setSegmentsLength(valueDouble); |
420 |
valueDouble = feature.getIntOrDefault( this.holesLengthFieldName, (int)DEFAULT_HOLES_LENGTH_VALUE*100 )/100.0; |
421 |
data.setHolesLength(valueDouble); |
422 |
boolean valueBoolean = feature.getBooleanOrDefault( this.paintHolesFieldName, DEFAULT_PAINT_HOLES_VALUE ); |
423 |
data.setPaintHoles(valueBoolean); |
424 |
valueColor = (Color) feature.getOrDefault( this.holesColorFieldName, DataTypes.COLOR, DEFAULT_HOLES_COLOR_VALUE ); |
425 |
data.setHolesColor(valueColor); |
426 |
valueBoolean = feature.getBooleanOrDefault( this.roundVertexFieldName, DEFAULT_ROUND_VERTEX_VALUE );
|
427 |
data.setRoundVertex(valueBoolean); |
428 |
|
429 |
data.setGapWidth(this.getGapWidth()/100.0); |
430 |
|
431 |
return data;
|
432 |
} |
433 |
|
434 |
} |