svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dgn / legend / DGNLegendBuilder.java @ 34978
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 |
defaultLegend.useDefaultSymbol(true);
|
83 |
|
84 |
labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy(); |
85 |
labelingStragegy.setTextField(DGNStoreProvider.NAME_FIELD_TEXT); |
86 |
labelingStragegy |
87 |
.setRotationField(DGNStoreProvider.NAME_FIELD_ROTATIONTEXT); |
88 |
labelingStragegy.setHeightField(DGNStoreProvider.NAME_FIELD_HEIGHTTEXT); |
89 |
labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters) |
90 |
return this; |
91 |
} |
92 |
|
93 |
public void process(FeatureProvider feature, DGNReader dgnReader) { |
94 |
Integer clave = (Integer) feature.get("Color"); |
95 |
if (clave == null) { |
96 |
return;
|
97 |
} |
98 |
|
99 |
defaultLegend.useDefaultSymbol(false);
|
100 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
101 |
ISymbol theSymbol; |
102 |
Color color = dgnReader.DGNLookupColor(clave.intValue());
|
103 |
theSymbol = |
104 |
mapContextManager.getSymbolManager().createSymbol( |
105 |
Geometry.TYPES.GEOMETRY, color); |
106 |
|
107 |
theSymbol.setDescription(clave.toString()); |
108 |
|
109 |
if (theSymbol instanceof IMarkerSymbol) { |
110 |
((IMarkerSymbol) theSymbol).setSize(1);
|
111 |
} |
112 |
|
113 |
if (theSymbol instanceof ILineSymbol) { |
114 |
ILineSymbol lineSymbol = (ILineSymbol) theSymbol; |
115 |
lineSymbol.setLineWidth(1);
|
116 |
lineSymbol.setLineColor(color); |
117 |
} |
118 |
|
119 |
if (theSymbol instanceof IFillSymbol) { |
120 |
IFillSymbol fillSymbol = (IFillSymbol) theSymbol; |
121 |
fillSymbol.getOutline().setLineColor(color); |
122 |
fillSymbol.getOutline().setLineWidth(1);
|
123 |
fillSymbol.setFillColor(null);
|
124 |
} |
125 |
if (theSymbol != null) { |
126 |
defaultLegend.addSymbol(clave, theSymbol); |
127 |
} |
128 |
} |
129 |
} |
130 |
|
131 |
public Object getLabeling() { |
132 |
return labelingStragegy;
|
133 |
} |
134 |
|
135 |
|
136 |
} |