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 @ 44256

History | View | Annotate | Download (11.3 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

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

    
119
        private Map labelClassFactories = new HashMap();
120
    private ILabelClassFactory defaultLabelClassFactory;
121

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

    
126
        public static class RegisterSymbologyManager implements Callable {
127

    
128
                public Object call() throws Exception {
129

    
130
                        SymbologyLocator.registerSymbologyManager(DefaultSymbologyManager.class);
131

    
132
                        return Boolean.TRUE;
133
                }
134

    
135
        }
136

    
137
        public DynamicVectorLegend createDynamicVectorLegend() {
138
            return new DefaultDynamicVectorLegend();
139
        }
140
        
141
        public DynamicLabelingStrategy createDynamicLabelingStrategy() {
142
            return new DefaultDynamicLabelingStrategy();
143
        }
144
        
145
        public DynamicSymbol createDynamicSymbol() {
146
            return new DefaultDynamicSymbol();
147
        }
148
        
149
        public IArrowDecoratorStyle createArrowDecoratorStyle() {
150
                return new ArrowDecoratorStyle();
151
        }
152

    
153
//        public IMarkerSymbol createMarkerSymbol(){
154
//                return new SimpleMarkerSymbol();
155
//        }
156

    
157
        public ISimpleMarkerSymbol createSimpleMarkerSymbol() {
158
                return new SimpleMarkerSymbol();
159
        }
160

    
161
        public IMask createMask() {
162
                return new DefaultMask();
163
        }
164

    
165
        public IMultiShapeSymbol createMultiShapeSymbol() {
166
                return new MultiShapeSymbol();
167
        }
168

    
169
        public ISimpleFillSymbol createSimpleFillSymbol() {
170
                return new SimpleFillSymbol();
171
        }
172

    
173
        public ISimpleLineSymbol createSimpleLineSymbol() {
174
                return new SimpleLineSymbol();
175
        }
176

    
177
        public ISimpleLineStyle createSimpleLineStyle() {
178
                return new SimpleLineStyle();
179
        }
180

    
181
        public IBackgroundFileStyle createBackgroundFileStyle(URL imgURL)
182
                        throws IOException {
183
                return BackgroundFileStyle.createStyleByURL(imgURL);
184
        }
185

    
186
        public ISimpleTextSymbol createSimpleTextSymbol() {
187
                return new SimpleTextSymbol();
188
        }
189

    
190
        public IMarkerFillPropertiesStyle createSimpleMarkerFillPropertiesStyle() {
191
                return new SimpleMarkerFillPropertiesStyle();
192
        }
193

    
194
        public IPictureFillSymbol createPictureFillSymbol(URL imageURL,
195
                        URL selImageURL) throws IOException {
196
                return new PictureFillSymbol(imageURL, selImageURL);
197
        }
198

    
199
        public IPictureLineSymbol createPictureLineSymbol(URL imageURL,
200
                        URL selImageURL) throws IOException {
201
                return new PictureLineSymbol(imageURL, selImageURL);
202
        }
203

    
204
        public IPictureMarkerSymbol createPictureMarkerSymbol(URL imageURL,
205
                        URL selImageURL) throws IOException {
206
                return new PictureMarkerSymbol(imageURL, selImageURL);
207

    
208
        }
209

    
210
        public IMarkerFillSymbol createMarkerFillSymbol() {
211
                return new MarkerFillSymbol();
212
        }
213

    
214
        public IAttrInTableLabelingStrategy createAttrInTableLabelingStrategy() {
215
                return new AttrInTableLabelingStrategy();
216
        }
217

    
218
        public ILabelingStrategy createDefaultLabelingStrategy() {
219
                return new AttrInTableLabelingStrategy();
220
        }
221

    
222
        public ILabelingMethod createDefaultLabelingMethod() {
223
                return new DefaultLabelingMethod();
224
        }
225

    
226
        public IZoomConstraints createDefaultZoomConstraints() {
227
                return new ZoomConstraintsImpl();
228
        }
229

    
230
        public ILabelStyle createDefaultLabelStyle() {
231
                return new SimpleLabelStyle();
232
        }
233

    
234
        public void registerLabelClass(ILabelClassFactory factory) {
235
            this.labelClassFactories.put(factory.getID().toLowerCase(), factory);
236
            if( this.defaultLabelClassFactory==null ) {
237
                this.defaultLabelClassFactory = factory;
238
            }
239
        }
240

    
241
        public Collection<ILabelClassFactory> getLabelClassFactories() {
242
            return Collections.unmodifiableCollection(this.labelClassFactories.values());
243
        }
244

    
245
        public ILabelClassFactory getLabelClassFactory(String id) {
246
            if( id==null ) {
247
                return null;
248
            }
249
            return (ILabelClassFactory) this.labelClassFactories.get(id.toLowerCase());
250
        }
251

    
252
        public ILabelClass createDefaultLabel() {
253
            ILabelClassFactory f = this.getDefaultLabelFactory();
254
            if( f==null ) {
255
                return null;
256
            }
257
            return f.create();
258
        }
259

    
260
        public ILabelClassFactory getDefaultLabelFactory() {
261
            return this.defaultLabelClassFactory;
262
        }
263

    
264
        public void setDefaultLabelFactory(String id) {
265
            ILabelClassFactory f = this.getLabelClassFactory(id);
266
            if( f==null ) {
267
                throw new IllegalArgumentException("factory id is null");
268
            }
269
            this.setDefaultLabelFactory(f);
270
        }
271

    
272
        public void setDefaultLabelFactory(ILabelClassFactory factory) {
273
            if( !this.labelClassFactories.containsValue(factory) ) {
274
                this.labelClassFactories.put(factory.getID().toLowerCase(), factory);
275
            }
276
            this.defaultLabelClassFactory = factory;
277
        }
278

    
279
    @Override
280
    public PathLength createPathLength(Shape path) {
281
        return new DefaultPathLength(path);
282
    }
283

    
284
    public ILegendWriter getDefaultLegendWriter() {
285
        return new PersistenceBasedLegendWriter();
286
    }
287

    
288
}