Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / impl / DefaultSymbologyManager.java @ 44534

History | View | Annotate | Download (11.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 3
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45

    
46
package org.gvsig.symbology.impl;
47

    
48
import java.awt.Shape;
49
import java.io.IOException;
50
import java.net.URL;
51
import java.util.Collection;
52
import java.util.Collections;
53
import java.util.HashMap;
54
import java.util.Map;
55

    
56
import org.apache.batik.ext.awt.geom.DefaultPathLength;
57

    
58
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
59
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
60
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass;
61
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClassFactory;
62
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod;
63
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
64
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints;
65
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IBackgroundFileStyle;
66
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
67
import org.gvsig.symbology.PathLength;
68
import org.gvsig.symbology.SymbologyLocator;
69
import org.gvsig.symbology.SymbologyManager;
70
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicSymbol;
71
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicLabelingStrategy;
72
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicVectorLegend;
73
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicLabelingStrategy;
74
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicSymbol;
75
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicVectorLegend;
76
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendWriter;
77
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval;
78
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
79
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.DefaultLabelingMethod;
80
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy;
81
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.ZoomConstraintsImpl;
82
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.IMultiShapeSymbol;
83
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMarkerFillSymbol;
84
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IPictureFillSymbol;
85
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol;
86
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol;
87
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
88
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
89
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
90
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol;
91
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ISimpleLineSymbol;
92
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.PictureLineSymbol;
93
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
94
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
95
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol;
96
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol;
97
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
98
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
99
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.BackgroundFileStyle;
100
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.DefaultMask;
101
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IArrowDecoratorStyle;
102
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
103
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask;
104
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ISimpleLineStyle;
105
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLabelStyle;
106
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLineStyle;
107
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle;
108
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol;
109
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
110
import org.gvsig.tools.util.Callable;
111
import org.gvsig.tools.util.Factory;
112

    
113
/**
114
 * Default {@link SymbologyManager} implementation.
115
 *
116
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
117
 */
118
public class DefaultSymbologyManager implements SymbologyManager {
119

    
120
        private Map labelClassFactories = new HashMap();
121
        private Map<String, Factory> labelStrategyFactories = new HashMap<>();
122
    private ILabelClassFactory defaultLabelClassFactory;
123

    
124
        public IInterval createInterval(double min, double max) {
125
                return new FInterval(min, max);
126
        }
127

    
128
        
129
    @Override
130
    public void registerLabelingStrategy(Factory factory) {
131
        labelStrategyFactories.put(factory.getName(), factory);
132
    }
133

    
134
    @Override
135
    public ILabelingStrategy createLabelingStrategy(String nameFactory, Object... parameters) {
136
        Factory factory = labelStrategyFactories.get(nameFactory);
137
        return (ILabelingStrategy) factory.create(parameters);
138
    }
139

    
140
        public static class RegisterSymbologyManager implements Callable {
141

    
142
                public Object call() throws Exception {
143

    
144
                        SymbologyLocator.registerSymbologyManager(DefaultSymbologyManager.class);
145

    
146
                        return Boolean.TRUE;
147
                }
148

    
149
        }
150
        
151
        public DynamicLabelingStrategy createDynamicLabelingStrategy() {
152
            return new DefaultDynamicLabelingStrategy();
153
        }
154
        
155
        public IArrowDecoratorStyle createArrowDecoratorStyle() {
156
                return new ArrowDecoratorStyle();
157
        }
158

    
159
//        public IMarkerSymbol createMarkerSymbol(){
160
//                return new SimpleMarkerSymbol();
161
//        }
162

    
163
        public ISimpleMarkerSymbol createSimpleMarkerSymbol() {
164
                return new SimpleMarkerSymbol();
165
        }
166

    
167
        public IMask createMask() {
168
                return new DefaultMask();
169
        }
170

    
171
        public IMultiShapeSymbol createMultiShapeSymbol() {
172
                return new MultiShapeSymbol();
173
        }
174

    
175
        public ISimpleFillSymbol createSimpleFillSymbol() {
176
                return new SimpleFillSymbol();
177
        }
178

    
179
        public ISimpleLineSymbol createSimpleLineSymbol() {
180
                return new SimpleLineSymbol();
181
        }
182

    
183
        public ISimpleLineStyle createSimpleLineStyle() {
184
                return new SimpleLineStyle();
185
        }
186

    
187
        public IBackgroundFileStyle createBackgroundFileStyle(URL imgURL)
188
                        throws IOException {
189
                return BackgroundFileStyle.createStyleByURL(imgURL);
190
        }
191

    
192
        public ISimpleTextSymbol createSimpleTextSymbol() {
193
                return new SimpleTextSymbol();
194
        }
195

    
196
        public IMarkerFillPropertiesStyle createSimpleMarkerFillPropertiesStyle() {
197
                return new SimpleMarkerFillPropertiesStyle();
198
        }
199

    
200
        public IPictureFillSymbol createPictureFillSymbol(URL imageURL,
201
                        URL selImageURL) throws IOException {
202
                return new PictureFillSymbol(imageURL, selImageURL);
203
        }
204

    
205
        public IPictureLineSymbol createPictureLineSymbol(URL imageURL,
206
                        URL selImageURL) throws IOException {
207
                return new PictureLineSymbol(imageURL, selImageURL);
208
        }
209

    
210
        public IPictureMarkerSymbol createPictureMarkerSymbol(URL imageURL,
211
                        URL selImageURL) throws IOException {
212
                return new PictureMarkerSymbol(imageURL, selImageURL);
213

    
214
        }
215

    
216
        public IMarkerFillSymbol createMarkerFillSymbol() {
217
                return new MarkerFillSymbol();
218
        }
219

    
220
        public IAttrInTableLabelingStrategy createAttrInTableLabelingStrategy() {
221
                return new AttrInTableLabelingStrategy();
222
        }
223

    
224
        public ILabelingStrategy createDefaultLabelingStrategy() {
225
                return new AttrInTableLabelingStrategy();
226
        }
227

    
228
        public ILabelingMethod createDefaultLabelingMethod() {
229
                return new DefaultLabelingMethod();
230
        }
231

    
232
        public IZoomConstraints createDefaultZoomConstraints() {
233
                return new ZoomConstraintsImpl();
234
        }
235

    
236
        public ILabelStyle createDefaultLabelStyle() {
237
                return new SimpleLabelStyle();
238
        }
239

    
240
        public void registerLabelClass(ILabelClassFactory factory) {
241
            this.labelClassFactories.put(factory.getID().toLowerCase(), factory);
242
            if( this.defaultLabelClassFactory==null ) {
243
                this.defaultLabelClassFactory = factory;
244
            }
245
        }
246

    
247
        public Collection<ILabelClassFactory> getLabelClassFactories() {
248
            return Collections.unmodifiableCollection(this.labelClassFactories.values());
249
        }
250

    
251
        public ILabelClassFactory getLabelClassFactory(String id) {
252
            if( id==null ) {
253
                return null;
254
            }
255
            return (ILabelClassFactory) this.labelClassFactories.get(id.toLowerCase());
256
        }
257

    
258
        public ILabelClass createDefaultLabel() {
259
            ILabelClassFactory f = this.getDefaultLabelFactory();
260
            if( f==null ) {
261
                return null;
262
            }
263
            return f.create();
264
        }
265

    
266
        public ILabelClassFactory getDefaultLabelFactory() {
267
            return this.defaultLabelClassFactory;
268
        }
269

    
270
        public void setDefaultLabelFactory(String id) {
271
            ILabelClassFactory f = this.getLabelClassFactory(id);
272
            if( f==null ) {
273
                throw new IllegalArgumentException("factory id is null");
274
            }
275
            this.setDefaultLabelFactory(f);
276
        }
277

    
278
        public void setDefaultLabelFactory(ILabelClassFactory factory) {
279
            if( !this.labelClassFactories.containsValue(factory) ) {
280
                this.labelClassFactories.put(factory.getID().toLowerCase(), factory);
281
            }
282
            this.defaultLabelClassFactory = factory;
283
        }
284

    
285
    @Override
286
    public PathLength createPathLength(Shape path) {
287
        return new DefaultPathLength(path);
288
    }
289

    
290
    public ILegendWriter getDefaultLegendWriter() {
291
        return new PersistenceBasedLegendWriter();
292
    }
293

    
294
}