Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extDwg / src / org / gvsig / dwg / fmap / dal / store / dwg / legend / DWGLegendBuilder.java @ 31631

History | View | Annotate | Download (3.91 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.dwg.fmap.dal.store.dwg.legend;
29

    
30
import java.awt.Color;
31

    
32
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider;
33
import org.gvsig.dwg.fmap.dal.store.dwg.LegendBuilder;
34
import org.gvsig.dxf.px.dxf.AcadColor;
35
import org.gvsig.fmap.dal.DataTypes;
36
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
37
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
42
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
44

    
45
public class DWGLegendBuilder implements LegendBuilder {
46

    
47

    
48
        private IVectorialUniqueValueLegend defaultLegend = null;
49
        private AttrInTableLabelingStrategy labelingStragegy = null;
50

    
51
        public void begin() {
52
                // Nothing to do
53
        }
54

    
55
        public void end() {
56
                // Nothing to do
57
        }
58

    
59
        public Object getLegend() {
60
                return defaultLegend;
61
        }
62

    
63
        public LegendBuilder initialize(FeatureStoreProvider store) {
64
                defaultLegend = (IVectorialUniqueValueLegend) MapContextLocator
65
                                .getMapContextManager().createLegend(
66
                                                IVectorialUniqueValueLegend.LEGEND_NAME);
67
                defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY);
68
                defaultLegend
69
                                .setClassifyingFieldNames(new String[] { DWGStoreProvider.NAME_FIELD_COLOR });
70
                defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT });
71

    
72
                ISymbol myDefaultSymbol =
73
                                MapContextLocator.getSymbolManager()
74
                                .createSymbol(Geometry.TYPES.GEOMETRY, Color.BLACK);
75

    
76
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
77

    
78

    
79
                labelingStragegy = new AttrInTableLabelingStrategy();
80
                labelingStragegy.setTextField(DWGStoreProvider.NAME_FIELD_TEXT);
81
                labelingStragegy
82
                                .setRotationField(DWGStoreProvider.NAME_FIELD_ROTATIONTEXT);
83
                labelingStragegy.setHeightField(DWGStoreProvider.NAME_FIELD_HEIGHTTEXT);
84
                labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters)
85
                return this;
86
        }
87

    
88
        public void process(FeatureProvider feature) {
89
                Integer clave = (Integer) feature.get("Color");
90
                if (clave == null) {
91
                        return;
92
                }
93
                if (defaultLegend.getSymbolByValue(clave) == null) {
94
                        ISymbol theSymbol;
95
                        Color color = null;
96
                        try {
97
                                color = AcadColor.getColor(clave.intValue());
98
                        } catch (ArrayIndexOutOfBoundsException e) {
99
                                color = AcadColor.getColor(255);
100
                        }
101
                        // jaume, moved to ISymbol
102
                        theSymbol =
103
                                        MapContextLocator.getSymbolManager().createSymbol(
104
                                        Geometry.TYPES.GEOMETRY, color);
105
                        
106
                        theSymbol.setDescription(clave.toString());
107
                        // Asigna los colores de Autocad a los
108
                        // bordes
109
                        // de los pol?gonos.
110
                        if (theSymbol instanceof IFillSymbol) {
111
                                ((IFillSymbol) theSymbol).getOutline().setLineColor(color);
112

    
113
                        }
114
                        if (theSymbol != null) {
115
                                defaultLegend.addSymbol(clave, theSymbol);
116
                        }
117
                }
118

    
119
        }
120

    
121
        public Object getLabeling() {
122
                return labelingStragegy;
123
        }
124

    
125

    
126
}