Revision 44249 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/dynamiclegend/DefaultDynamicSymbol.java

View differences:

DefaultDynamicSymbol.java
9 9
import java.awt.Color;
10 10
import java.awt.Graphics2D;
11 11
import java.awt.Rectangle;
12
import java.awt.Stroke;
13 12
import java.awt.geom.AffineTransform;
14 13
import java.util.ArrayList;
15 14
import java.util.List;
......
18 17
import org.gvsig.compat.print.PrintAttributes;
19 18
import org.gvsig.expressionevaluator.Expression;
20 19
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
21
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
22 20
import org.gvsig.expressionevaluator.MutableSymbolTable;
23 21
import org.gvsig.expressionevaluator.SymbolTable;
24 22
import org.gvsig.fmap.dal.DALLocator;
25 23
import org.gvsig.fmap.dal.exception.DataException;
26
import org.gvsig.fmap.dal.exception.InitializeException;
27 24
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
28 25
import org.gvsig.fmap.dal.feature.Feature;
29 26
import org.gvsig.fmap.dal.feature.FeatureStore;
......
32 29
import org.gvsig.fmap.geom.GeometryManager;
33 30
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34 31
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.fmap.geom.primitive.GeneralPathX;
36 32
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.fmap.geom.type.GeometryType;
38 33
import org.gvsig.fmap.mapcontext.MapContext;
39 34
import org.gvsig.fmap.mapcontext.ViewPort;
40 35
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
......
42 37
import org.gvsig.symbology.SymbologyLocator;
43 38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol;
44 39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
46 40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ISimpleLineSymbol;
47 41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
48
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.CIRCLE_STYLE;
49
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.CROSS_STYLE;
50
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.DIAMOND_STYLE;
51
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.SQUARE_STYLE;
52
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.STAR_STYLE;
53
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.TRIANGLE_STYLE;
54
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.VERTICAL_LINE_STYLE;
55
import static org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol.X_STYLE;
56 42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ILineStyle;
59 43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ISimpleLineStyle;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.Line2DOffset;
61
import org.gvsig.tools.evaluator.Evaluator;
62 44
import org.gvsig.tools.persistence.PersistentState;
63 45
import org.gvsig.tools.persistence.exception.PersistenceException;
64 46
import org.gvsig.tools.task.Cancellable;
......
66 48

  
67 49
public class DefaultDynamicSymbol implements DynamicSymbol {
68 50

  
69
    private Feature feature;
51
    private Feature feature = null;
70 52
    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(SimpleFillSymbol.class);
71 53
    private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
72 54

  
73
    public static final String OUTLINECOLOR = "COUTLINE";
74
    public static final String FILLCOLOR = "CFILL";
75
    public static final String SIZE = "CSIZE";
76
    private MutableSymbolTable symbolTable;
55
    public static Expression eOutlineColor = null;
56
    public static Expression eFillColor = null;
57
    public static Expression eSize = null;
58
    public static Expression eRotation = null;
77 59

  
78 60
    private final boolean isShapeVisible = true;
79 61
    private ISimpleMarkerSymbol pointSymbol = null;
80 62
    private ISimpleLineSymbol lineSymbol = null;
81 63
    private ISimpleFillSymbol polygonSymbol = null;
64
    public FeatureSymbolTable featureSymbolTable = null;
65
    public SymbolTable symbolTable = null;
66
    private Expression eOffset;
67
    private List<String> listRequiredAttributeNames;
82 68

  
83 69
    public DefaultDynamicSymbol() {
84
        feature = null;
70
        symbolTable = ExpressionEvaluatorLocator.getManager().createSymbolTable();
71
        featureSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable();
72
        symbolTable.addSymbolTable(featureSymbolTable);
73

  
85 74
    }
86 75

  
87 76
    @Override
88 77
    public void setFeature(Feature feat) {
89 78
        feature = feat;
79
        featureSymbolTable.setFeature(feat);
90 80
    }
91 81

  
92 82
    @Override
......
94 84
        return null;
95 85
    }
96 86

  
97
    private DynamicSymbol symbolForSelection;
98

  
99 87
    @Override
100 88
    public ISymbol getSymbolForSelection() {
101
        if (symbolForSelection == null) {
102
            DynamicSymbol selectionSymbol;
103
            try {
104
                selectionSymbol = (DynamicSymbol) this.clone();
105
                if (selectionSymbol != null) {
106
//                    selectionSymbol.setHasFill(true);
107
//                    setSymbolForSelection(selectionSymbol);
108
                }
109
            } catch (CloneNotSupportedException ex) {
110
//                Logger.getLogger(DefaultDynamicSymbol.class.getName()).log(Level.SEVERE, null, ex);
111
            }
112

  
113
        } else {
114
            symbolForSelection.setColor(MapContext.getSelectionColor());
89
        int typeGeom = feature.getDefaultGeometry().getGeometryType().getType();
90
        switch (typeGeom) {
91
            case Geometry.TYPES.POINT:
92
            case Geometry.TYPES.MULTIPOINT:
93
                setPointSymbolValues();
94
                pointSymbol.setColor(MapContext.getSelectionColor());
95
                pointSymbol.setOutlineColor(MapContext.getSelectionColor());
96
                return pointSymbol;
97
            case Geometry.TYPES.LINE:
98
            case Geometry.TYPES.MULTILINE:
99
                setLineSymbolValues();
100
                lineSymbol.setColor(MapContext.getSelectionColor());
101
                return lineSymbol;
102
            case Geometry.TYPES.POLYGON:
103
            case Geometry.TYPES.ELLIPSE:
104
            case Geometry.TYPES.CIRCLE:
105
            case Geometry.TYPES.MULTIPOLYGON:
106
                setPolygonSymbolValues();
107
                polygonSymbol.setFillColor(MapContext.getSelectionColor());
108
                return polygonSymbol;
109
            default:
110
                break;
115 111
        }
116
        return symbolForSelection;
112
        return null;
117 113
    }
118 114

  
119 115
    @Override
120 116
    public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
121 117
        Color c = getColor(); //TODO
122 118
        int typeGeom = geom.getGeometryType().getType();
123
        if (typeGeom == Geometry.TYPES.POINT || typeGeom == Geometry.TYPES.MULTIPOINT) {
124
            drawPoint(g, affineTransform, geom, f, cancel);
125
        } else if (typeGeom == Geometry.TYPES.LINE || typeGeom == Geometry.TYPES.MULTILINE) {
126
            drawLine(g, affineTransform, geom, f, cancel);
127
        } else if (typeGeom == Geometry.TYPES.POLYGON || typeGeom == Geometry.TYPES.MULTIPOLYGON) {
128
            drawPolygon(g, affineTransform, geom, f, cancel);
129
        } else if (true) {
130
            // Optimiza el pintado de geometrias grandes.
131
            try {
132
                Geometry env = geom.getEnvelope().getGeometry();
133
                env.transform(affineTransform);
134
                Envelope env2 = env.getEnvelope();
135
                if (env2.getLength(0) < 1.5 && env2.getLength(1) < 1.5) {
136
                    geom = env2.getUpperCorner();
119
        switch (typeGeom) {
120
            case Geometry.TYPES.POINT:
121
            case Geometry.TYPES.MULTIPOINT:
122
                drawPoint(g, affineTransform, geom, f, cancel);
123
                break;
124
            case Geometry.TYPES.LINE:
125
            case Geometry.TYPES.MULTILINE:
126
                drawLine(g, affineTransform, geom, f, cancel);
127
                break;
128
            case Geometry.TYPES.POLYGON:
129
            case Geometry.TYPES.ELLIPSE:
130
            case Geometry.TYPES.CIRCLE:
131
            case Geometry.TYPES.MULTIPOLYGON:
132
                drawPolygon(g, affineTransform, geom, f, cancel);
133
                break;
134
            default:
135
                // Optimiza el pintado de geometrias grandes.
136
                try {
137
                    Geometry env = geom.getEnvelope().getGeometry();
138
                    env.transform(affineTransform);
139
                    Envelope env2 = env.getEnvelope();
140
                    if (env2.getLength(0) < 1.5 && env2.getLength(1) < 1.5) {
141
                        geom = env2.getUpperCorner();
142
                    }
143
                } catch (Exception ex) {
144
                    LOG.warn("Error optimizing the drawing of the geometry. Continues with normal drawing.", ex);
145
                    // Do nothing, continue with the draw of the original geometry
137 146
                }
138
            } catch (Exception ex) {
139
                LOG.warn("Error optimizing the drawing of the geometry. Continues with normal drawing.", ex);
140
                // Do nothing, continue with the draw of the original geometry
141
            }
142

  
143
            g.setColor(c);
144
            g.fill(geom.getShape(affineTransform));
145
            g.draw(geom.getShape(affineTransform));
146

  
147
                g.setColor(c);
148
                g.fill(geom.getShape(affineTransform));
149
                g.draw(geom.getShape(affineTransform));
150
                break;
147 151
        }
148 152
    }
149 153

  
150 154
    protected void drawPolygon(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
155
        setPolygonSymbolValues();
156
        polygonSymbol.draw(g, affineTransform, geom, f, cancel);
157
    }
158

  
159
    protected void setPolygonSymbolValues() {
151 160
        if (polygonSymbol == null) {
152 161
            polygonSymbol = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
153 162
        }
......
158 167
        polygonSymbol.setFillColor(getComputedFillColor());
159 168
        polygonSymbol.setHasOutline(true);
160 169
        polygonSymbol.setHasFill(true);
161

  
162
        polygonSymbol.draw(g, affineTransform, geom, f, cancel);
163 170
    }
164 171

  
165 172
    protected void setLineSymbolValues() {
......
183 190
        lineSymbol.draw(g, affineTransform, geom, f, cancel);
184 191
    }
185 192

  
186
    protected void drawPoint(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
193
    protected void setPointSymbolValues() {
187 194
        if (pointSymbol == null) {
188 195
            pointSymbol = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol();
189 196
        }
......
194 201
        pointSymbol.setOutlined(true);
195 202
        pointSymbol.setOutlineSize(2);
196 203
        pointSymbol.setOutlineColor(getComputedOutlineColor());
204
    }
205

  
206
    protected void drawPoint(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
207
        setPointSymbolValues();
197 208
        pointSymbol.draw(g, affineTransform, geom, f, cancel);
198 209
    }
199 210

  
......
264 275
    }
265 276

  
266 277
    public Expression getComputedColor() {
267
        String value = feature.get(FILLCOLOR).toString();
268
        Expression expression = getExpressionFromString(value);
269
        return expression;
278
        return eFillColor;
270 279
    }
271 280

  
272 281
    public Expression getOutlineColor() {
273
        String value = feature.get(OUTLINECOLOR).toString();
274
        Expression expression = getExpressionFromString(value);
275
        return expression;
282
        return eOutlineColor;
276 283
    }
277 284

  
278 285
    public Color getComputedOutlineColor() {
......
280 287
    }
281 288

  
282 289
    public void setOutlineColor(Expression exp) {
283

  
290
        eOutlineColor = exp;
284 291
    }
285 292

  
286 293
    public Expression getFillColor() {
287
        String value = feature.get(FILLCOLOR).toString();
288
        Expression expression = getExpressionFromString(value);
289
        return expression;
294
        return eFillColor;
290 295
    }
291 296

  
292 297
    public Color getComputedFillColor() {
......
294 299
    }
295 300

  
296 301
    public void setFillColor(Expression exp) {
297

  
302
        eFillColor = exp;
298 303
    }
299 304

  
300 305
    public Expression getSize() {
301
        String value = feature.get(SIZE).toString();
302
        Expression expression = getExpressionFromString(value);
303
        return expression;
306
        return eSize;
304 307
    }
305 308

  
306 309
    public int getComputedSize() {
......
310 313
    }
311 314

  
312 315
    public void setSize(Expression exp) {
313

  
316
        eSize = exp;
314 317
    }
315 318

  
316 319
    public Expression getOffset() {
317
        // TODO
318
        Point pointOffset = null;
319
        String value = "";
320
        try {
321
            pointOffset = GeometryLocator.getGeometryManager().createPoint(0, 0, Geometry.SUBTYPES.GEOM2D);
322
            value = pointOffset.convertToWKT();
323
        } catch (Exception ex) {
324
            Logger.getLogger(DefaultDynamicSymbol.class.getName()).log(Level.SEVERE, null, ex);
325
        }
326

  
327
        Expression expression = getExpressionFromString(value);
328
        return expression;
320
        return eOffset;
329 321
    }
322
    
323
    public void setOffset(Expression offset) {
324
        eOffset = offset;
325
    }
330 326

  
331 327
    public Point getComputedOffset() {
332 328
//        Expression exp = getSize();
......
340 336
        return pointOffset;
341 337
    }
342 338

  
343
    public void setOffset(Expression exp) {
344 339

  
345
    }
346

  
347 340
    public Expression getRotation() {
348
//        String value = feature.get(SIZE).toString();
349
        String value = "0";
350
        Expression expression = getExpressionFromString(value);
351
        return expression;
341
        return eRotation;
352 342
    }
353 343

  
354 344
    public int getComputedRotation() {
......
358 348
    }
359 349

  
360 350
    public void setRotation(Expression exp) {
361

  
351
        eRotation = exp;
362 352
    }
363 353

  
364
    private Expression getExpressionFromString(String value) {
365
        Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
366
        expression.setPhrase(value);
367
        return expression;
368
    }
369 354

  
355

  
370 356
    private Color getColorFromExpression(Expression exp) {
371 357
        Integer rgbcolor = (Integer) exp.execute(getFeatureSymbolTable());
372 358
        Color color = new Color(rgbcolor, true);
373 359
        return color;
374 360
    }
375 361

  
376
    public Object getComputedValue(String field) {
377
        Object value;
378
        value = feature.get(field);
379

  
380
        return value;
381
    }
382

  
362
//    public Object getComputedValue(String field) {
363
//        Object value;
364
//        value = feature.get(field);
365
//
366
//        return value;
367
//    }
383 368
    @Override
384 369
    public void setColor(Color color) {
385 370

  
......
387 372

  
388 373
    @Override
389 374
    public void setColor(Expression color) {
375
        eOutlineColor = color;
390 376

  
391 377
    }
392 378

  
......
438 424

  
439 425
    @Override
440 426
    public List<String> getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
441
        List<String> myList = new ArrayList<>();
442
        myList.add(OUTLINECOLOR);
443
        myList.add(FILLCOLOR);
444
        myList.add(SIZE);
445
        return myList;
427
        return this.listRequiredAttributeNames;
428

  
446 429
    }
430
    
431
    public void setRequiredFeatureAttributesNames(List<String> listRequiredAttributeNames) {
432
        this.listRequiredAttributeNames = listRequiredAttributeNames;
433
    
434
    }
435
    
447 436

  
448 437
}

Also available in: Unified diff