Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dgn / legend / DGNLegendBuilder.java @ 31631

History | View | Annotate | Download (4.26 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

    
28
package org.gvsig.fmap.dal.store.dgn.legend;
29

    
30
import java.awt.Color;
31

    
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
34
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
35
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
36
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
37
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.MapContextManager;
41
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
47

    
48
public class DGNLegendBuilder implements LegendBuilder {
49

    
50
        private MapContextManager mapContextManager = MapContextLocator
51
                        .getMapContextManager();
52

    
53
        private IVectorialUniqueValueLegend defaultLegend = null;
54
        private AttrInTableLabelingStrategy labelingStragegy = null;
55

    
56
        public void begin() {
57
                // Nothing to do
58
        }
59

    
60
        public void end() {
61
                // Nothing to do
62
        }
63

    
64
        public Object getLegend() {
65
                return defaultLegend;
66
        }
67

    
68
        public LegendBuilder initialize(FeatureStoreProvider store) {
69
                defaultLegend = (IVectorialUniqueValueLegend) mapContextManager.createLegend(
70
                                                IVectorialUniqueValueLegend.LEGEND_NAME);
71
                defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY);
72
                defaultLegend
73
                                .setClassifyingFieldNames(new String[] { DGNStoreProvider.NAME_FIELD_COLOR });
74
                defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT });
75

    
76
                ISymbol myDefaultSymbol =
77
                                mapContextManager.getSymbolManager()
78
                                .createSymbol(Geometry.TYPES.GEOMETRY); 
79

    
80
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
81

    
82
                labelingStragegy = new AttrInTableLabelingStrategy();
83
                labelingStragegy.setTextField(DGNStoreProvider.NAME_FIELD_TEXT);
84
                labelingStragegy
85
                                .setRotationField(DGNStoreProvider.NAME_FIELD_ROTATIONTEXT);
86
                labelingStragegy.setHeightField(DGNStoreProvider.NAME_FIELD_HEIGHTTEXT);
87
                labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters)
88
                return this;
89
        }
90

    
91
        public void process(FeatureProvider feature, DGNReader dgnReader) {
92
                Integer clave = (Integer) feature.get("Color");
93
                if (clave == null) {
94
                        return;
95
                }
96
                if (defaultLegend.getSymbolByValue(clave) == null) {
97
                        ISymbol theSymbol;
98
                        Color color = dgnReader.DGNLookupColor(clave.intValue());
99
                        theSymbol =
100
                                        mapContextManager.getSymbolManager().createSymbol(
101
                                        Geometry.TYPES.GEOMETRY, color); 
102

    
103
                        theSymbol.setDescription(clave.toString());
104

    
105
                        if (theSymbol instanceof IMarkerSymbol) {
106
                                ((IMarkerSymbol) theSymbol).setSize(1);
107
                        }
108

    
109
                        if (theSymbol instanceof ILineSymbol) {
110
                                ((ILineSymbol) theSymbol).setLineWidth(1);
111
                        }
112

    
113
                        if (theSymbol instanceof IFillSymbol) {
114
                                ((IFillSymbol) theSymbol).getOutline().setLineColor(color);
115
                                ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
116
                                ((IFillSymbol) theSymbol).setFillColor(null);
117
                        }
118
                        if (theSymbol != null) {
119
                                defaultLegend.addSymbol(clave, theSymbol);
120
                        }
121
                }
122
        }
123

    
124
        public Object getLabeling() {
125
                return labelingStragegy;
126
        }
127

    
128

    
129
}