root / trunk / org.gvsig.dwg / org.gvsig.dwg.provider.legend / src / main / java / org / gvsig / dwg / fmap / dal / store / dwg / legend / DWGLegendBuilder.java @ 152
History | View | Annotate | Download (4.5 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.dwg.lib.util.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.SymbologyLocator; |
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
46 |
|
47 |
public class DWGLegendBuilder implements LegendBuilder { |
48 |
|
49 |
|
50 |
private IVectorialUniqueValueLegend defaultLegend = null; |
51 |
private IAttrInTableLabelingStrategy labelingStragegy = null; |
52 |
|
53 |
public void begin() { |
54 |
// Nothing to do
|
55 |
} |
56 |
|
57 |
public void end() { |
58 |
// Nothing to do
|
59 |
} |
60 |
|
61 |
public Object getLegend() { |
62 |
return defaultLegend;
|
63 |
} |
64 |
|
65 |
public LegendBuilder initialize(FeatureStoreProvider store) {
|
66 |
defaultLegend = (IVectorialUniqueValueLegend) MapContextLocator |
67 |
.getMapContextManager().createLegend( |
68 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
69 |
defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY); |
70 |
defaultLegend |
71 |
.setClassifyingFieldNames(new String[] { DWGStoreProvider.NAME_FIELD_COLOR }); |
72 |
defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT }); |
73 |
|
74 |
ISymbol myDefaultSymbol = |
75 |
MapContextLocator.getSymbolManager() |
76 |
.createSymbol(Geometry.TYPES.GEOMETRY, Color.BLACK);
|
77 |
|
78 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
79 |
|
80 |
labelingStragegy = |
81 |
SymbologyLocator.getSymbologyManager() |
82 |
.createAttrInTableLabelingStrategy(); |
83 |
labelingStragegy.setTextField(DWGStoreProvider.NAME_FIELD_TEXT); |
84 |
labelingStragegy |
85 |
.setRotationField(DWGStoreProvider.NAME_FIELD_ROTATIONTEXT); |
86 |
labelingStragegy.setHeightField(DWGStoreProvider.NAME_FIELD_HEIGHTTEXT); |
87 |
labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters) |
88 |
return this; |
89 |
} |
90 |
|
91 |
public void process(FeatureProvider feature) { |
92 |
Integer clave = (Integer) feature.get("Color"); |
93 |
if (clave == null) { |
94 |
return;
|
95 |
} |
96 |
|
97 |
defaultLegend.useDefaultSymbol(false);
|
98 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
99 |
ISymbol theSymbol; |
100 |
Color color = null; |
101 |
try {
|
102 |
color = AcadColor.getColor(clave.intValue()); |
103 |
} catch (ArrayIndexOutOfBoundsException e) { |
104 |
color = AcadColor.getColor(255);
|
105 |
} |
106 |
// jaume, moved to ISymbol
|
107 |
theSymbol = |
108 |
MapContextLocator.getSymbolManager().createSymbol( |
109 |
Geometry.TYPES.GEOMETRY, color); |
110 |
|
111 |
theSymbol.setDescription(clave.toString()); |
112 |
// Asigna los colores de Autocad a los
|
113 |
// bordes de los pol?gonos y pone el relleno transparente.
|
114 |
if (theSymbol instanceof IFillSymbol) { |
115 |
((IFillSymbol) theSymbol).getOutline().setLineColor(color); |
116 |
Color fillColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 0); |
117 |
((IFillSymbol) theSymbol).setFillColor(fillColor); |
118 |
} |
119 |
// Asigna los colores de Autocad a las l?neas
|
120 |
if (theSymbol instanceof ILineSymbol) { |
121 |
((ILineSymbol) theSymbol).setLineColor(color); |
122 |
} |
123 |
if (theSymbol != null) { |
124 |
defaultLegend.addSymbol(clave, theSymbol); |
125 |
} |
126 |
} |
127 |
defaultLegend.useDefaultSymbol(true);
|
128 |
|
129 |
} |
130 |
|
131 |
public Object getLabeling() { |
132 |
return labelingStragegy;
|
133 |
} |
134 |
|
135 |
|
136 |
} |