root / org.gvsig.dgn / trunk / org.gvsig.dgn / org.gvsig.dgn.provider.legend / src / main / java / org / gvsig / fmap / dal / store / dgn / legend / DGNLegendBuilder.java @ 229
History | View | Annotate | Download (4.51 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.SymbologyLocator; |
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
46 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
47 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
48 |
|
49 |
public class DGNLegendBuilder implements LegendBuilder { |
50 |
|
51 |
private MapContextManager mapContextManager = MapContextLocator
|
52 |
.getMapContextManager(); |
53 |
|
54 |
private IVectorialUniqueValueLegend defaultLegend = null; |
55 |
private IAttrInTableLabelingStrategy labelingStragegy = null; |
56 |
|
57 |
public void begin() { |
58 |
// Nothing to do
|
59 |
} |
60 |
|
61 |
public void end() { |
62 |
// Nothing to do
|
63 |
} |
64 |
|
65 |
public Object getLegend() { |
66 |
return defaultLegend;
|
67 |
} |
68 |
|
69 |
public LegendBuilder initialize(FeatureStoreProvider store) {
|
70 |
defaultLegend = (IVectorialUniqueValueLegend) mapContextManager.createLegend( |
71 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
72 |
defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY); |
73 |
defaultLegend |
74 |
.setClassifyingFieldNames(new String[] { DGNStoreProvider.NAME_FIELD_COLOR }); |
75 |
defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT }); |
76 |
|
77 |
ISymbol myDefaultSymbol = |
78 |
mapContextManager.getSymbolManager() |
79 |
.createSymbol(Geometry.TYPES.GEOMETRY); |
80 |
|
81 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
82 |
|
83 |
labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy(); |
84 |
labelingStragegy.setTextField(DGNStoreProvider.NAME_FIELD_TEXT); |
85 |
labelingStragegy |
86 |
.setRotationField(DGNStoreProvider.NAME_FIELD_ROTATIONTEXT); |
87 |
labelingStragegy.setHeightField(DGNStoreProvider.NAME_FIELD_HEIGHTTEXT); |
88 |
labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters) |
89 |
return this; |
90 |
} |
91 |
|
92 |
public void process(FeatureProvider feature, DGNReader dgnReader) { |
93 |
Integer clave = (Integer) feature.get("Color"); |
94 |
if (clave == null) { |
95 |
return;
|
96 |
} |
97 |
|
98 |
defaultLegend.useDefaultSymbol(false);
|
99 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
100 |
ISymbol theSymbol; |
101 |
Color color = dgnReader.DGNLookupColor(clave.intValue());
|
102 |
theSymbol = |
103 |
mapContextManager.getSymbolManager().createSymbol( |
104 |
Geometry.TYPES.GEOMETRY, color); |
105 |
|
106 |
theSymbol.setDescription(clave.toString()); |
107 |
|
108 |
if (theSymbol instanceof IMarkerSymbol) { |
109 |
((IMarkerSymbol) theSymbol).setSize(1);
|
110 |
} |
111 |
|
112 |
if (theSymbol instanceof ILineSymbol) { |
113 |
ILineSymbol lineSymbol = (ILineSymbol) theSymbol; |
114 |
lineSymbol.setLineWidth(1);
|
115 |
lineSymbol.setLineColor(color); |
116 |
} |
117 |
|
118 |
if (theSymbol instanceof IFillSymbol) { |
119 |
IFillSymbol fillSymbol = (IFillSymbol) theSymbol; |
120 |
fillSymbol.getOutline().setLineColor(color); |
121 |
fillSymbol.getOutline().setLineWidth(1);
|
122 |
fillSymbol.setFillColor(null);
|
123 |
} |
124 |
if (theSymbol != null) { |
125 |
defaultLegend.addSymbol(clave, theSymbol); |
126 |
} |
127 |
} |
128 |
defaultLegend.useDefaultSymbol(true);
|
129 |
} |
130 |
|
131 |
public Object getLabeling() { |
132 |
return labelingStragegy;
|
133 |
} |
134 |
|
135 |
|
136 |
} |