Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2011 / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / impl / SymbologyDefaultImplLibrary.java @ 33580

History | View | Annotate | Download (11.2 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
 * 2009 {gvSIG}  {{Task}}
26
 */
27
package org.gvsig.symbology.impl;
28

    
29
import java.util.ArrayList;
30
import java.util.List;
31

    
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.mapcontext.MapContextException;
34
import org.gvsig.fmap.mapcontext.MapContextLocator;
35
import org.gvsig.fmap.mapcontext.MapContextManager;
36
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
37
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend;
38
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
40
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
42
import org.gvsig.symbology.SymbologyLocator;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractIntervalLegend;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractLegend;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval;
48
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialIntervalLegend;
50
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
52
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.DefaultLabelingMethod;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelClass;
54
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.ZoomConstraintsImpl;
55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.AbstractLineSymbol;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.MultiLayerLineSymbol;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.ArrowMarkerSymbol;
68
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.MultiLayerMarkerSymbol;
69
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
70
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.AbstractStyle;
71
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
72
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.DefaultMask;
73
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLineStyle;
74
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
75
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.warning.impl.WarningSymbol;
76
import org.gvsig.tools.exception.ListBaseException;
77
import org.gvsig.tools.library.AbstractLibrary;
78
import org.gvsig.tools.library.LibraryException;
79
import org.slf4j.Logger;
80
import org.slf4j.LoggerFactory;
81

    
82
/**
83
 * Library for the Basic Symbology implementation.
84
 * 
85
 * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
86
 */
87
public class SymbologyDefaultImplLibrary extends AbstractLibrary {
88

    
89
    private Logger LOG =
90
        LoggerFactory.getLogger(SymbologyDefaultImplLibrary.class);
91

    
92
    protected void doInitialize() throws LibraryException {
93
        // Nothing to do
94
    }
95

    
96
    @SuppressWarnings({ "rawtypes", "unchecked" })
97
    protected void doPostInitialize() throws LibraryException {
98
        List exs = new ArrayList();
99

    
100
        MapContextManager manager = MapContextLocator.getMapContextManager();
101
        try {
102
            registerSymbols(manager);
103
        } catch (Exception e) {
104
            exs.add(e);
105
        }
106
        try {
107
            registerSymbolsPersistence();
108
        } catch (Exception e) {
109
            exs.add(e);
110
        }
111

    
112
        try {
113
            registerLegends(manager);
114
        } catch (Exception e) {
115
            exs.add(e);
116
        }
117

    
118
        try {
119
            registerLegendsPersistence();
120
        } catch (Exception e) {
121
            exs.add(e);
122
        }
123

    
124
        try {
125
            registerLabelingPersistence();
126
        } catch (Exception e) {
127
            exs.add(e);
128
        }
129

    
130
        try {
131
            SymbologyLocator.registerSymbologyManager(DefaultSymbologyManager.class);
132
        } catch (Exception e) {
133
            exs.add(e);
134
        }
135

    
136
        if (exs.size() > 0) {
137
            LibraryException ex = new LibraryException(this.getClass(), exs);
138
            LOG.warn(((ListBaseException) (ex.getCause())).getMessageStack());
139
            throw ex;
140
        }
141
    }
142

    
143
    /**
144
     * Registers symbol implementations in the {@link MapContextManager}.
145
     */
146
    private void registerSymbols(MapContextManager manager) throws MapContextException {
147

    
148
        SymbolManager symbolManager = manager.getSymbolManager();
149

    
150
        // Fill
151
        int[] shapeTypes =
152
            new int[] { Geometry.TYPES.SURFACE, Geometry.TYPES.CIRCLE,
153
                Geometry.TYPES.ELLIPSE, Geometry.TYPES.MULTISURFACE };
154
        symbolManager.registerSymbol(IFillSymbol.SYMBOL_NAME,
155
            shapeTypes,
156
            SimpleFillSymbol.class);
157
        symbolManager.registerMultiLayerSymbol(IFillSymbol.SYMBOL_NAME,
158
            shapeTypes,
159
            MultiLayerFillSymbol.class);
160

    
161
        // Line
162
        shapeTypes =
163
            new int[] { Geometry.TYPES.CURVE, Geometry.TYPES.ARC,
164
                Geometry.TYPES.ELLIPTICARC, Geometry.TYPES.MULTICURVE };
165
        symbolManager.registerSymbol(ILineSymbol.SYMBOL_NAME,
166
            shapeTypes,
167
            SimpleLineSymbol.class);
168
        symbolManager.registerMultiLayerSymbol(ILineSymbol.SYMBOL_NAME,
169
            shapeTypes,
170
            MultiLayerLineSymbol.class);
171

    
172
        // Marker
173
        shapeTypes =
174
            new int[] { Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT };
175
        symbolManager.registerSymbol(IMarkerSymbol.SYMBOL_NAME,
176
            shapeTypes,
177
            SimpleMarkerSymbol.class);
178
        symbolManager.registerMultiLayerSymbol(IMarkerSymbol.SYMBOL_NAME,
179
            shapeTypes,
180
            MultiLayerMarkerSymbol.class);
181

    
182
        // Text
183
        shapeTypes = new int[] { Geometry.TYPES.TEXT };
184
        symbolManager.registerSymbol(ITextSymbol.SYMBOL_NAME,
185
            shapeTypes,
186
            SimpleTextSymbol.class);
187

    
188
        // MultiShape
189
        shapeTypes = new int[] { Geometry.TYPES.GEOMETRY };
190
        symbolManager.registerSymbol(MultiShapeSymbol.SYMBOL_NAME,
191
            shapeTypes,
192
            MultiShapeSymbol.class);
193

    
194
        // Warning
195
        symbolManager.registerSymbol(IWarningSymbol.SYMBOL_NAME,
196
            WarningSymbol.class);
197
    }
198

    
199
    /**
200
     * Registers legend implementations in the {@link MapContextManager}.
201
     */
202
    private void registerLegends(MapContextManager manager) {
203
        List<Exception> exceptions = new ArrayList<Exception>();
204

    
205
        try {
206
            manager.registerLegend(IVectorialUniqueValueLegend.LEGEND_NAME,
207
                VectorialUniqueValueLegend.class);
208
        } catch (Exception ex) {
209
            exceptions.add(ex);
210
        }
211
        try {
212
            manager.registerLegend(IVectorialIntervalLegend.LEGEND_NAME,
213
                VectorialIntervalLegend.class);
214
        } catch (Exception ex) {
215
            exceptions.add(ex);
216
        }
217
        try {
218
            manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME,
219
                SingleSymbolLegend.class);
220

    
221
        } catch (Exception ex) {
222
            exceptions.add(ex);
223
        }
224
        if (exceptions.size() > 0) {
225
            throw new LibraryException(this.getClass(), exceptions);
226
        }
227

    
228
    }
229

    
230
    private void registerLabelingPersistence() {
231
        ZoomConstraintsImpl.registerPersistence();
232
        LabelClass.registerPersistence();
233
        DefaultLabelingMethod.registerPersistence();
234
        AttrInTableLabelingStrategy.registerPersistence();
235
    }
236

    
237
    /**
238
     * Register dynclass and persistence definitions for Legend classes.
239
     */
240
    private void registerLegendsPersistence() {
241
        AbstractLegend.registerPersistence();
242
        AbstractVectorialLegend.registerPersistence();
243
        AbstractClassifiedVectorLegend.registerPersistence();
244
        FInterval.registerPersistence();
245
        AbstractIntervalLegend.registerPersistence();
246
        VectorialIntervalLegend.registerPersistence();
247
        VectorialUniqueValueLegend.registerPersistence();
248
        SingleSymbolLegend.registerPersistence();
249
    }
250

    
251
    /**
252
     * Register dynclass and persistence definitions for Symbol classes.
253
     */
254
    private void registerSymbolsPersistence() {
255
        // Styles
256
        AbstractStyle.registerPersistence();
257
        ArrowDecoratorStyle.registerPersistence();
258
        DefaultMask.registerPersistence();
259
        SimpleLineStyle.registerPersistence();
260

    
261
        // Base symbol
262
        AbstractSymbol.registerPersistence();
263

    
264
        // Fill symbols
265
        AbstractFillSymbol.registerPersistence();
266
        SimpleFillSymbol.registerPersistence();
267
        MultiLayerFillSymbol.registerPersistence();
268

    
269
        // Line symbols
270
        AbstractLineSymbol.registerPersistence();
271
        SimpleLineSymbol.registerPersistence();
272
        MultiLayerLineSymbol.registerPersistence();
273

    
274
        // Marker symbols
275
        AbstractMarkerSymbol.registerPersistence();
276
        SimpleMarkerSymbol.registerPersistence();
277
        ArrowMarkerSymbol.registerPersistence();
278
        MultiLayerMarkerSymbol.registerPersistence();
279

    
280
        // Text symbols
281
        SimpleTextSymbol.registerPersistence();
282

    
283
        // MultiShape symbol
284
        MultiShapeSymbol.registerPersistence();
285

    
286
        // Warning symbol
287
        WarningSymbol.registerPersistence();
288
    }
289
}