root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dgn / legend / DGNLegendBuilder.java @ 38533
History | View | Annotate | Download (4.51 KB)
1 | 29106 | jmvivo | /* 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 | 29289 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
34 | 29106 | jmvivo | 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 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextLocator; |
40 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
41 | 31631 | jpiera | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
42 | 29106 | jmvivo | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
43 | 34300 | fdiaz | import org.gvsig.symbology.SymbologyLocator; |
44 | import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
||
45 | 30011 | cordinyana | 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 | 29106 | jmvivo | |
49 | public class DGNLegendBuilder implements LegendBuilder { |
||
50 | |||
51 | 30011 | cordinyana | private MapContextManager mapContextManager = MapContextLocator
|
52 | .getMapContextManager(); |
||
53 | 29106 | jmvivo | |
54 | 30011 | cordinyana | private IVectorialUniqueValueLegend defaultLegend = null; |
55 | 34300 | fdiaz | private IAttrInTableLabelingStrategy labelingStragegy = null; |
56 | 29106 | jmvivo | |
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 | 30011 | cordinyana | defaultLegend = (IVectorialUniqueValueLegend) mapContextManager.createLegend( |
71 | IVectorialUniqueValueLegend.LEGEND_NAME); |
||
72 | defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY); |
||
73 | 29106 | jmvivo | defaultLegend |
74 | .setClassifyingFieldNames(new String[] { DGNStoreProvider.NAME_FIELD_COLOR }); |
||
75 | defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT }); |
||
76 | |||
77 | 30892 | cordinyana | ISymbol myDefaultSymbol = |
78 | mapContextManager.getSymbolManager() |
||
79 | 30011 | cordinyana | .createSymbol(Geometry.TYPES.GEOMETRY); |
80 | 29106 | jmvivo | |
81 | defaultLegend.setDefaultSymbol(myDefaultSymbol); |
||
82 | 34978 | fdiaz | defaultLegend.useDefaultSymbol(true);
|
83 | 29106 | jmvivo | |
84 | 34300 | fdiaz | labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy(); |
85 | 29106 | jmvivo | 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 | 29289 | jmvivo | public void process(FeatureProvider feature, DGNReader dgnReader) { |
94 | 29106 | jmvivo | Integer clave = (Integer) feature.get("Color"); |
95 | if (clave == null) { |
||
96 | return;
|
||
97 | } |
||
98 | 34978 | fdiaz | |
99 | defaultLegend.useDefaultSymbol(false);
|
||
100 | 29106 | jmvivo | if (defaultLegend.getSymbolByValue(clave) == null) { |
101 | ISymbol theSymbol; |
||
102 | Color color = dgnReader.DGNLookupColor(clave.intValue());
|
||
103 | 30892 | cordinyana | theSymbol = |
104 | mapContextManager.getSymbolManager().createSymbol( |
||
105 | 30011 | cordinyana | Geometry.TYPES.GEOMETRY, color); |
106 | |||
107 | 29106 | jmvivo | theSymbol.setDescription(clave.toString()); |
108 | |||
109 | if (theSymbol instanceof IMarkerSymbol) { |
||
110 | ((IMarkerSymbol) theSymbol).setSize(1);
|
||
111 | } |
||
112 | |||
113 | if (theSymbol instanceof ILineSymbol) { |
||
114 | 34910 | fdiaz | ILineSymbol lineSymbol = (ILineSymbol) theSymbol; |
115 | lineSymbol.setLineWidth(1);
|
||
116 | lineSymbol.setLineColor(color); |
||
117 | 29106 | jmvivo | } |
118 | |||
119 | if (theSymbol instanceof IFillSymbol) { |
||
120 | 34910 | fdiaz | IFillSymbol fillSymbol = (IFillSymbol) theSymbol; |
121 | fillSymbol.getOutline().setLineColor(color); |
||
122 | fillSymbol.getOutline().setLineWidth(1);
|
||
123 | fillSymbol.setFillColor(null);
|
||
124 | 29106 | jmvivo | } |
125 | if (theSymbol != null) { |
||
126 | defaultLegend.addSymbol(clave, theSymbol); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | public Object getLabeling() { |
||
132 | return labelingStragegy;
|
||
133 | } |
||
134 | |||
135 | |||
136 | } |