Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / dgn / operation / DGNLegendLabelingManager.java @ 23303

History | View | Annotate | Download (3.21 KB)

1
package org.gvsig.fmap.data.feature.file.dgn.operation;
2

    
3
import java.awt.Color;
4
import java.util.ArrayList;
5
import java.util.Map;
6

    
7
import org.gvsig.fmap.data.DataException;
8
import org.gvsig.fmap.data.feature.Feature;
9
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
10
import org.gvsig.fmap.data.feature.file.dgn.DGNResource;
11
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNReader;
12
import org.gvsig.fmap.data.feature.operation.LegendLabelingManager;
13
import org.gvsig.fmap.geom.Geometry;
14
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
15
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
16
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
17
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol;
18
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol;
19
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol;
20
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
21
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
22

    
23
public class DGNLegendLabelingManager implements LegendLabelingManager {
24
        private AttrInTableLabelingStrategy labeling;
25
        private VectorialUniqueValueLegend defaultLegend;
26
        private ArrayList colors;
27
        private DGNReader m_DgnReader;
28

    
29
        protected DGNLegendLabelingManager(){
30
                // Legend
31
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(Geometry.TYPES.GEOMETRY);
32
                defaultLegend.setClassifyingFieldNames(new String[] {"Color"});
33

    
34
                defaultLegend.setClassifyingFieldTypes(new String[]{FeatureAttributeDescriptor.TYPE_INT});
35
                ISymbol myDefaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, Color.BLACK);
36
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
37
                colors = new ArrayList();
38

    
39
                labeling = new AttrInTableLabelingStrategy();
40
                labeling.setTextFieldId(DGNResource.ID_FIELD_TEXT);
41
                labeling.setRotationFieldId(DGNResource.ID_FIELD_ROTATIONTEXT);
42
                labeling.setHeightFieldId(DGNResource.ID_FIELD_HEIGHTTEXT);
43
                labeling.setUnit(1); //MapContext.NAMES[1] (meters)
44
        }
45

    
46
        public void add(Feature feature, Map params) throws DataException {
47
                // Legend
48
                Integer curColor = (Integer) feature.get(DGNResource.ID_FIELD_COLOR);
49
                if (!colors.contains(curColor)){
50

    
51
                        Color curColorObj = m_DgnReader.DGNLookupColor(
52
                                        curColor.intValue());
53
                        ISymbol sym =SymbologyFactory.createDefaultSymbolByShapeType(
54
                                        Geometry.TYPES.GEOMETRY,
55
                                        curColorObj);
56
                        sym.setDescription(curColor.toString());
57

    
58

    
59
                        if (sym instanceof IMarkerSymbol) {
60
                                ((IMarkerSymbol) sym).setSize(1);
61
                        }
62

    
63
                        if (sym instanceof ILineSymbol) {
64
                                ((ILineSymbol) sym).setLineWidth(1);
65
                        }
66

    
67
                        if (sym instanceof IFillSymbol) {
68
                                ((IFillSymbol) sym).getOutline().setLineColor(
69
                                                curColorObj);
70
                                ((IFillSymbol) sym).getOutline().setLineWidth(1);
71
                                ((IFillSymbol) sym).setFillColor(null);
72
                        }
73

    
74
                        defaultLegend.addSymbol(curColor, sym);
75
                        colors.add(curColor);
76
                }
77

    
78
        }
79

    
80
        public Object getDefaultLegend() {
81
                return this.defaultLegend;
82
        }
83

    
84
        public Object getLabeling() {
85
                return this.labeling;
86
        }
87

    
88
        public void endLoading() {
89
                this.colors.clear();
90
                this.colors = null;
91
                this.m_DgnReader = null;
92
        }
93

    
94
        public void startLoading(Map params) {
95
                this.m_DgnReader = (DGNReader) params.get("reader");
96
        }
97

    
98

    
99
}