svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dxf / legend / DXFLegendBuilder.java @ 34300
History | View | Annotate | Download (4.1 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.dxf.legend; |
29 |
|
30 |
import java.awt.Color; |
31 |
|
32 |
import org.gvsig.dxf.px.dxf.AcadColor; |
33 |
import org.gvsig.fmap.dal.DataTypes; |
34 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
35 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
36 |
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider; |
37 |
import org.gvsig.fmap.dal.store.dxf.LegendBuilder; |
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.SymbologyLocator; |
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
46 |
|
47 |
public class DXFLegendBuilder implements LegendBuilder { |
48 |
|
49 |
private MapContextManager mapContextManager = MapContextLocator
|
50 |
.getMapContextManager(); |
51 |
|
52 |
private IVectorialUniqueValueLegend defaultLegend = null; |
53 |
private IAttrInTableLabelingStrategy labelingStragegy = null; |
54 |
|
55 |
public void begin() { |
56 |
// Nothing to do
|
57 |
} |
58 |
|
59 |
public void end() { |
60 |
// Nothing to do
|
61 |
} |
62 |
|
63 |
public Object getLegend() { |
64 |
return defaultLegend;
|
65 |
} |
66 |
|
67 |
public LegendBuilder initialize(FeatureStoreProvider store) {
|
68 |
defaultLegend = (IVectorialUniqueValueLegend) mapContextManager |
69 |
.createLegend(IVectorialUniqueValueLegend.LEGEND_NAME); |
70 |
defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY); |
71 |
defaultLegend |
72 |
.setClassifyingFieldNames(new String[] { DXFStoreProvider.NAME_FIELD_COLOR }); |
73 |
defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT }); |
74 |
|
75 |
ISymbol myDefaultSymbol = |
76 |
mapContextManager.getSymbolManager().createSymbol( |
77 |
Geometry.TYPES.GEOMETRY, Color.BLACK);
|
78 |
|
79 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
80 |
|
81 |
labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy(); |
82 |
labelingStragegy.setTextField(DXFStoreProvider.NAME_FIELD_TEXT); |
83 |
labelingStragegy |
84 |
.setRotationField(DXFStoreProvider.NAME_FIELD_ROTATIONTEXT); |
85 |
labelingStragegy.setHeightField(DXFStoreProvider.NAME_FIELD_HEIGHTTEXT); |
86 |
labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters) |
87 |
return this; |
88 |
} |
89 |
|
90 |
public void process(FeatureProvider feature) { |
91 |
Integer clave = (Integer) feature.get("Color"); |
92 |
if (clave == null) { |
93 |
return;
|
94 |
} |
95 |
|
96 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
97 |
ISymbol theSymbol; |
98 |
Color color = null; |
99 |
try {
|
100 |
color = AcadColor.getColor(clave.intValue()); |
101 |
} catch (ArrayIndexOutOfBoundsException e) { |
102 |
color = AcadColor.getColor(255);
|
103 |
} |
104 |
// jaume, moved to ISymbol
|
105 |
theSymbol = |
106 |
mapContextManager.getSymbolManager().createSymbol( |
107 |
Geometry.TYPES.GEOMETRY, |
108 |
color); |
109 |
theSymbol.setDescription(clave.toString()); |
110 |
// Asigna los colores de Autocad a los
|
111 |
// bordes
|
112 |
// de los pol?gonos.
|
113 |
if (theSymbol instanceof IFillSymbol) { |
114 |
((IFillSymbol) theSymbol).getOutline().setLineColor(color); |
115 |
|
116 |
} |
117 |
if (theSymbol != null) { |
118 |
defaultLegend.addSymbol(clave, theSymbol); |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
public Object getLabeling() { |
124 |
return labelingStragegy;
|
125 |
} |
126 |
|
127 |
|
128 |
} |