Revision 8289

View differences:

org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <artifactId>org.gvsig.legend.picturemarkersymboltable.lib.impl</artifactId>
4
    <name>org.gvsig.legend.picturemarkersymboltable.lib.impl</name>
5
    <parent>
6
        <groupId>org.gvsig</groupId>
7
        <artifactId>org.gvsig.legend.picturemarkersymboltable.lib</artifactId>
8
        <version>1.0.17</version>
9
    </parent>
10
    <groupId>org.gvsig</groupId>
11
    <dependencies>
12
        <dependency>
13
            <groupId>org.gvsig</groupId>
14
            <artifactId>org.gvsig.legend.picturemarkersymboltable.lib.api</artifactId>
15
            <scope>compile</scope>
16
        </dependency>
17
        <dependency>
18
            <groupId>org.gvsig</groupId>
19
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
20
            <scope>compile</scope>
21
        </dependency>
22
        <dependency>
23
            <groupId>org.gvsig</groupId>
24
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
25
            <scope>compile</scope>
26
        </dependency>
27
        <dependency>
28
            <groupId>org.gvsig</groupId>
29
            <artifactId>org.gvsig.ui</artifactId>
30
            <scope>compile</scope>
31
        </dependency>
32
    
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
36
            <scope>test</scope>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
<!--
41
            <artifactId>${org.gvsig.h2spatial.provider}</artifactId>
42
-->
43
            <artifactId>org.gvsig.h2spatial.h2gis132.provider</artifactId>
44
            
45
            <scope>test</scope>
46
        </dependency>
47
        <dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
50
            <scope>test</scope>
51
        </dependency>    
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId>
55
            <scope>test</scope>
56
        </dependency>    
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
60
            <scope>test</scope>
61
        </dependency>    
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
65
            <scope>test</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.compat.se</artifactId>
70
            <scope>test</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
75
            <scope>test</scope>
76
        </dependency>      
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
80
            <scope>test</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
85
            <scope>test</scope>
86
        </dependency>
87
        <dependency>
88
            <groupId>org.gvsig</groupId>
89
            <artifactId>org.gvsig.tools.util.impl</artifactId>
90
            <scope>test</scope>
91
        </dependency>
92
        <dependency>
93
            <groupId>org.gvsig</groupId>
94
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
95
            <scope>test</scope>
96
        </dependency>
97
        <dependency>
98
            <groupId>org.gvsig</groupId>
99
            <artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId>
100
            <scope>compile</scope>
101
        </dependency>
102
    </dependencies>
103
</project>
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/impl/DefaultPictureMarkerSymbolTableLegend.java
1
package org.gvsig.legend.picturemarkersymboltable.lib.impl;
2

  
3
import java.awt.Color;
4
import java.awt.geom.Point2D;
5
import java.awt.image.BufferedImage;
6
import java.net.URL;
7
import java.util.ArrayList;
8
import java.util.List;
9
import javax.annotation.processing.SupportedSourceVersion;
10
import javax.lang.model.SourceVersion;
11
import org.apache.commons.collections4.map.LRUMap;
12
import org.apache.commons.lang3.StringUtils;
13
import org.gvsig.expressionevaluator.ExpressionBuilder;
14
import org.gvsig.expressionevaluator.ExpressionUtils;
15
import org.gvsig.fmap.dal.DALLocator;
16
import org.gvsig.fmap.dal.DataTypes;
17
import org.gvsig.fmap.dal.StoresRepository;
18
import org.gvsig.fmap.dal.exception.DataException;
19
import org.gvsig.fmap.dal.feature.Feature;
20
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
21
import org.gvsig.fmap.dal.feature.FeatureStore;
22
import org.gvsig.fmap.dal.feature.FeatureType;
23
import org.gvsig.fmap.geom.Geometry;
24
import org.gvsig.fmap.geom.GeometryUtils;
25
import org.gvsig.fmap.mapcontext.MapContextException;
26
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
27
import org.gvsig.fmap.mapcontext.rendering.legend.events.IntervalLegendEvent;
28
import org.gvsig.fmap.mapcontext.rendering.legend.events.LabelLegendEvent;
29
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
30
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
31
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
32
import org.gvsig.fmap.mapcontext.rendering.legend.events.ValueLegendEvent;
33
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
34
import org.gvsig.legend.picturemarkersymboltable.lib.api.PictureMarkerSymbolTableLegend;
35
import org.gvsig.symbology.SymbologyLocator;
36
import org.gvsig.symbology.SymbologyManager;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.dataTypes.Coercion;
41
import org.gvsig.tools.persistence.PersistentState;
42
import org.gvsig.tools.persistence.exception.PersistenceException;
43
import org.gvsig.tools.swing.api.SimpleImage;
44
import org.gvsig.tools.swing.api.ToolsSwingLocator;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
@SupportedSourceVersion(SourceVersion.RELEASE_8)
49
@SuppressWarnings("UseSpecificCatch")
50
public class DefaultPictureMarkerSymbolTableLegend 
51
        extends AbstractVectorialLegend 
52
        implements PictureMarkerSymbolTableLegend 
53
{
54
    
55
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPictureMarkerSymbolTableLegend.class);
56

  
57
    private static final int IMAGESCACHE_SIZE = 100;
58
    
59
    /** 
60
     * defaultSimbol no se usa para nada. 
61
     * Lo inicializamos en el constructor a SimpleMarkerSymbol por si a caso 
62
     * alguien lo consulta, por ejemplo al persistir el ImageMarkerSimbol.
63
     */
64
    transient private final ISimpleMarkerSymbol defaultSymbol;
65
    
66
    transient private final Coercion toColor;
67
    transient private FeatureStore imagesStore;
68
    transient private ExpressionBuilder expressionBuilder;
69
    transient private final LRUMap<Object, BufferedImage[]> imagesCache;
70
    
71
    private double size;
72
    private int units;
73
    private Color lineToOffsetColor;
74
    private boolean drawLineToOffset;
75

  
76
    private String classifyingFieldName;
77
    private String offsetXFieldName;
78
    private String offsetYFieldName;
79
    private String rotationFieldName;
80
    private String lineToOffsetColorFieldlName;
81

  
82
    private String imagesTableName;
83
    private String imagesTableClassifyingFieldName;
84
    private String imageFieldName;
85
    private String imageSelectedFieldName;
86
    private SimpleImage imageNotFound;
87
    
88
    private double scale;
89
    
90
    private class MyZSort extends ZSort {
91
        
92
	public MyZSort() {
93
		super();
94
	}
95

  
96
        @Override
97
	public void legendChanged(LegendChangedEvent e) throws MapContextException {
98
//		symbols.clear();
99
//		usingZSort = false;
100
//		initialize(e.getNewLegend());
101

  
102
	}
103

  
104
        @Override
105
	public String getClassName() {
106
		return getClass().getName();
107
	}
108

  
109
        @Override
110
	public int getLevelCount() {
111
		return 2;
112
	}
113

  
114
        @Override
115
	public void setUsingZSort(boolean usingZSort) {
116
	}
117

  
118
        @Override
119
	public void setLevels(ISymbol sym, int[] values) {
120
	}
121

  
122
        @Override
123
	public void setLevels(int row, int[] values) {
124
	}
125

  
126
        @Override
127
	public int[] getLevels(ISymbol sym) {
128
		return new int[]{0,1};
129
	}
130

  
131
        @Override
132
	public int[] getLevels(int row) {
133
		return null;
134
	}
135

  
136
        @Override
137
	public boolean isUsingZSort() {
138
		return true;
139
	}
140

  
141
        @Override
142
	public ISymbol[] getSymbols() {
143
		return null;
144
	}
145

  
146
        @Override
147
	public String[] getDescriptions() {
148
            return new String[] {"line", "Image"};
149
	}
150

  
151
        @Override
152
	public int getTopLevelIndexAllowed() {
153
		return 0;
154
	}
155

  
156
        @Override
157
	public String toString() {
158
            return "Line, Image";
159
	}
160

  
161
        @Override
162
	public boolean symbolChanged(SymbolLegendEvent e) {
163
		return true;
164
	}
165

  
166
        @Override
167
	public boolean classifiedSymbolChange(SymbolLegendEvent e) {
168
		return true;
169
	}
170

  
171
        @Override
172
	public boolean intervalChange(IntervalLegendEvent e) {
173
		return false;
174
	}
175

  
176
        @Override
177
	public boolean valueChange(ValueLegendEvent e) {
178
		return false;
179
	}
180

  
181
	// TODO should not exist here
182
        @Override
183
	public boolean labelFieldChange(LabelLegendEvent e) {
184
		return false;
185
	}
186

  
187
        @Override
188
	public void legendCleared(LegendClearEvent event) {
189
	}
190
        
191
    }
192
    
193
    public DefaultPictureMarkerSymbolTableLegend() {
194
        
195
        SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager();
196
        this.scale = 1;
197
        this.defaultSymbol = symbologyManager.createSimpleMarkerSymbol();
198
        this.toColor = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.COLOR);
199
        this.size = DEFAULT_IMAGE_SIZE;
200
        this.drawLineToOffset = true;
201
        this.lineToOffsetColor = Color.DARK_GRAY;
202
        this.imagesCache = new LRUMap<>(IMAGESCACHE_SIZE);
203
        this.setZSort(new MyZSort());
204
    }
205

  
206
    @Override
207
    public ISymbol getDefaultSymbol() {
208
        return this.defaultSymbol;
209
    }
210

  
211
    @Override
212
    public void setDefaultSymbol(ISymbol is) {
213
        //DO NOTHING
214
    }
215

  
216
    private Color getColor(Feature feature, String attrname, Color defaultValue) {
217
        if( StringUtils.isBlank(attrname) ) {
218
            return defaultValue;
219
        }
220
        try {
221
            return (Color) toColor.coerce(feature.get(attrname));
222
        } catch(Exception ex) {
223
            return defaultValue;
224
        }
225
    }
226
    
227
    @Override
228
    public ISymbol getSymbolByFeature(Feature feature) throws MapContextException {
229
        ImageMarkerSymbol symbol = new ImageMarkerSymbol();
230
        
231
        Point2D.Double offset = new Point2D.Double(0,0);
232
        if( StringUtils.isNotBlank(this.offsetXFieldName)) {
233
            offset.x = feature.getDouble(this.offsetXFieldName)*this.scale;
234
        }
235
        if( StringUtils.isNotBlank(this.offsetYFieldName)) {
236
            offset.y = feature.getDouble(this.offsetYFieldName)*this.scale;
237
        }
238
        symbol.setOffset(offset);
239
        
240
        if( StringUtils.isNotBlank(this.rotationFieldName)) {
241
            symbol.setRotation(feature.getDouble(this.rotationFieldName));
242
        } else {
243
            symbol.setRotation(0);
244
        }
245
        
246
        if( drawLineToOffset && (offset.x!=0 || offset.y!=0))    {
247
            symbol.setDrawLineToOffset(true);
248
            symbol.setLineToOffsetColor(
249
                    getColor(
250
                            feature, 
251
                            this.lineToOffsetColorFieldlName, 
252
                            this.lineToOffsetColor
253
                    )
254
            );
255
        } else {
256
            symbol.setDrawLineToOffset(false);
257
            symbol.setLineToOffsetColor(Color.DARK_GRAY);
258
        }
259
        symbol.setSize(this.size*this.scale);
260
        symbol.setUnit(this.units);
261
        
262
        Object classifyingValue = feature.get(this.classifyingFieldName);
263
        BufferedImage[] images = this.getImages(classifyingValue);
264
        symbol.setImage(images[0]);
265
        symbol.setImageSel(images[1]);
266
        return symbol;
267
    }
268

  
269
    @Override
270
    public int getShapeType() {
271
        return Geometry.TYPES.POINT;
272
    }
273

  
274
    private BufferedImage[] getImages(Object classifyingValue) {
275
        
276
        BufferedImage[] images;
277
        images = this.imagesCache.get(classifyingValue);
278
        if( images!=null ) {
279
            return images;
280
        }
281
        
282
        images = new BufferedImage[] { null, null };        
283
        try {
284
            FeatureStore store = this.getImagesStore();
285
            FeatureType featureType = store.getDefaultFeatureTypeQuietly();
286
            FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(this.imagesTableClassifyingFieldName);
287
            Object value = attr.coerce(classifyingValue);
288
            ExpressionBuilder builder = this.getExpressionBuilder();
289
            String filter = builder.eq(
290
                    builder.column(this.imagesTableClassifyingFieldName),
291
                    builder.constant(value)
292
            ).toString();
293
            Feature f = store.findFirst(filter);
294
            if( f==null ) {
295
                SimpleImage image = getImageNotFound();
296
                images[0] = image.getBufferedImage();
297
                images[1] = images[0];
298
            } else {
299
                SimpleImage image = (SimpleImage) f.getFromProfile(this.imageFieldName);
300
                if( image != null ) {
301
                    images[0] = image.getBufferedImage();
302
                    images[1] = images[0];
303
                }
304
                image = (SimpleImage) f.getFromProfile(this.imageSelectedFieldName);
305
                if( image != null && !image.isEmpty() ) {
306
                    images[1] = image.getBufferedImage();
307
                }
308
            }
309
        } catch(Exception ex) {
310
            LOGGER.debug("Can't retrieve images from table '"+this.imagesTableName+"'", ex);
311
        }
312
        this.imagesCache.put(classifyingValue, images);
313
        return images;
314
    }
315
    
316
    private SimpleImage getImageNotFound() {
317
        if(this.imageNotFound == null){
318
            URL url = this.getClass().getResource("/images/picturemarkersymboltablelegend/image-not-found.png");
319
            this.imageNotFound = ToolsSwingLocator.getToolsSwingManager().createSimpleImage(url);
320
        }
321
        return this.imageNotFound;
322
    }
323
    
324
    private ExpressionBuilder getExpressionBuilder() {
325
        if( this.expressionBuilder == null ) {
326
            this.expressionBuilder = ExpressionUtils.createExpressionBuilder();
327
        }
328
        return this.expressionBuilder;
329
    }
330
    
331
    private FeatureStore getImagesStore() {
332
        if( this.imagesStore == null ) {
333
            StoresRepository repository = DALLocator.getDataManager().getStoresRepository();
334
            this.imagesStore = (FeatureStore) repository.getStore(this.imagesTableName);
335
        }
336
        return this.imagesStore;
337
    }
338
    
339
    @Override
340
    public void setShapeType(int i) {
341
    }
342

  
343
    @Override
344
    public boolean isUseDefaultSymbol() {
345
        return true;
346
    }
347

  
348
    @Override
349
    public void useDefaultSymbol(boolean bln) {
350
    }
351

  
352
    @Override
353
    public boolean isSuitableForShapeType(int shapeType) {
354
        return GeometryUtils.isSubtype(Geometry.TYPES.POINT, shapeType);
355
    }
356

  
357
    @Override
358
    public void loadFromState(PersistentState state) throws PersistenceException {
359
        super.loadFromState(state);
360
        
361
        this.scale = state.getDouble("scale",1.0);
362
        this.size = state.getDouble("size",DEFAULT_IMAGE_SIZE);
363
        this.units = state.getInt("units",-1);
364
        this.lineToOffsetColor = (Color) state.get("lineToOffsetColor");
365
        this.drawLineToOffset = state.getBoolean("drawLineToOffset",true);
366
        this.classifyingFieldName = state.getString("classifyingFieldName");
367
        
368
        this.offsetXFieldName = state.getString("offsetXFieldName");
369
        this.offsetYFieldName = state.getString("offsetYFieldName");
370
        this.rotationFieldName = state.getString("rotationFieldName");
371
        this.lineToOffsetColorFieldlName = state.getString("lineToOffsetColorFieldlName");
372

  
373
        this.imagesTableName = state.getString("imagesTableName");
374
        this.imagesTableClassifyingFieldName = state.getString("imagesTableClassifyingFieldName");
375
        this.imageFieldName = state.getString("imageFieldName");
376
        this.imageSelectedFieldName = state.getString("imageSelectedFieldName");
377
        
378
        setZSort(new MyZSort());
379

  
380
        
381
    }
382

  
383
    @Override
384
    public void saveToState(PersistentState state) throws PersistenceException {
385
        super.saveToState(state);
386
        
387
        state.set("scale", this.scale);
388
        state.set("size", this.size);
389
        state.set("units", this.units);
390
        state.set("lineToOffsetColor", this.lineToOffsetColor);
391
        state.set("drawLineToOffset", this.drawLineToOffset);
392
        state.set("classifyingFieldName", this.classifyingFieldName);
393

  
394
        state.set("offsetXFieldName", this.offsetXFieldName);
395
        state.set("offsetYFieldName", this.offsetYFieldName);
396
        state.set("rotationFieldName", this.rotationFieldName);
397
        state.set("lineToOffsetColorFieldlName", this.lineToOffsetColorFieldlName);
398

  
399
        state.set("imagesTableName", this.imagesTableName);
400
        state.set("imagesTableClassifyingFieldName", this.imagesTableClassifyingFieldName);
401
        state.set("imageFieldName", this.imageFieldName);
402
        state.set("imageSelectedFieldName", this.imageSelectedFieldName);
403
        
404
    }
405

  
406
    @Override
407
    protected String[] getRequiredFeatureAttributeNames(FeatureStore fs) throws DataException {
408
        List<String> attributes = new ArrayList<>();
409
        if( StringUtils.isNotBlank(this.classifyingFieldName)) {
410
            attributes.add(this.classifyingFieldName);
411
        }
412
        if( StringUtils.isNotBlank(this.offsetXFieldName)) {
413
            attributes.add(this.offsetXFieldName);
414
        }
415
        if( StringUtils.isNotBlank(this.offsetYFieldName)) {
416
            attributes.add(this.offsetYFieldName);
417
        }
418
        if( StringUtils.isNotBlank(this.rotationFieldName)) {
419
            attributes.add(this.rotationFieldName);
420
        }
421
        if( StringUtils.isNotBlank(this.lineToOffsetColorFieldlName)) {
422
            attributes.add(this.lineToOffsetColorFieldlName);
423
        }
424
        attributes.add( fs.getDefaultFeatureType().getDefaultGeometryAttributeName() );
425
        return attributes.toArray(new String[attributes.size()]);
426
    }
427

  
428
    @Override
429
    public Color getDefaultLineToOffsetColor() {
430
        return this.lineToOffsetColor;
431
    }
432

  
433
    @Override
434
    public void setDefaultLineToOffsetColor(Color color) {
435
        this.lineToOffsetColor = color;
436
    }
437

  
438
    @Override
439
    public boolean isDrawLineToOffset() {
440
        return this.drawLineToOffset;
441
    }
442

  
443
    @Override
444
    public void setDrawLineToOffset(boolean drawLineToOffset) {
445
        this.drawLineToOffset = drawLineToOffset;
446
    }
447

  
448
    @Override
449
    public double getImageSize() {
450
        return this.size;
451
    }
452

  
453
    @Override
454
    public void setImageSize(double size) {
455
        this.size = size;
456
    }
457

  
458
    @Override
459
    public String getLineToOffsetColorFieldName() {
460
        return this.lineToOffsetColorFieldlName;
461
    }
462

  
463
    @Override
464
    public void setLineToOffsetColorFieldName(String fieldName) {
465
        this.lineToOffsetColorFieldlName = fieldName;
466
    }
467

  
468
    @Override
469
    public String getOffsetXFieldName() {
470
        return this.offsetXFieldName;
471
    }
472

  
473
    @Override
474
    public void setOffsetXFieldName(String fieldName) {
475
        this.offsetXFieldName = fieldName;
476
    }
477

  
478
    @Override
479
    public String getOffsetYFieldName() {
480
        return this.offsetYFieldName;
481
    }
482

  
483
    @Override
484
    public void setOffsetYFieldName(String fieldName) {
485
        this.offsetYFieldName = fieldName;
486
    }
487

  
488
    @Override
489
    public String getRotationFieldName() {
490
        return this.rotationFieldName;
491
    }
492

  
493
    @Override
494
    public void setRotationFieldName(String fieldName) {
495
        this.rotationFieldName = fieldName;
496
    }
497

  
498
    @Override
499
    public String getImagesTableName() {
500
        return imagesTableName;
501
    }
502

  
503
    @Override
504
    public void setImagesTableName(String imagesTableName) {
505
        this.imagesTableName = imagesTableName;
506
        this.imagesCache.clear();
507
    }
508

  
509
    @Override
510
    public String getImageFieldName() {
511
        return imageFieldName;
512
    }
513

  
514
    @Override
515
    public void setImageFieldName(String imageFieldName) {
516
        this.imageFieldName = imageFieldName;
517
        this.imagesCache.clear();
518
    }
519

  
520
    @Override
521
    public String getClassifyingFieldName() {
522
        return classifyingFieldName;
523
    }
524

  
525
    @Override
526
    public void setClassifyingFieldName(String classifyingFieldName) {
527
        this.classifyingFieldName = classifyingFieldName;
528
        this.imagesCache.clear();
529
    }
530

  
531
    @Override
532
    public String getImageSelectedFieldName() {
533
        return imageSelectedFieldName;
534
    }
535

  
536
    @Override
537
    public void setImageSelectedFieldName(String imageSelectedFieldName) {
538
        this.imageSelectedFieldName = imageSelectedFieldName;
539
        this.imagesCache.clear();
540
    }
541

  
542
    @Override
543
    public String getImagesTableClassifyingFieldName() {
544
        return imagesTableClassifyingFieldName;
545
    }
546

  
547
    @Override
548
    public void setImagesTableClassifyingFieldName(String imagesTableClassifyingFieldName) {
549
        this.imagesTableClassifyingFieldName = imagesTableClassifyingFieldName;
550
        this.imagesCache.clear();
551
    }
552

  
553
    @Override
554
    public String[] getDescriptions() {
555
        return new String[] { this.classifyingFieldName + "->" + this.imagesTableName};
556
    }
557

  
558
    @Override
559
    public ISymbol[] getSymbols() {
560
        return new ISymbol[] { this.defaultSymbol };
561
    }
562

  
563
    @Override
564
    public Object[] getValues() {
565
        return new Object[] { "" } ;
566
    }
567

  
568
    @Override
569
    public int getUnits() {
570
        return units;
571
    }
572

  
573
    @Override
574
    public void setUnits(int units) {
575
        this.units = units;
576
    }
577

  
578
    @Override
579
    public double getScale() {
580
        return scale;
581
    }
582

  
583
    @Override
584
    public void setScale(double scale) {
585
        this.scale = scale;
586
    }
587

  
588
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/impl/PictureMarkerSymbolTableLibraryImpl.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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 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
 * 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

  
25
package org.gvsig.legend.picturemarkersymboltable.lib.impl;
26

  
27
import java.io.InputStream;
28
import java.util.Map;
29
import org.gvsig.fmap.mapcontext.MapContextLibrary;
30
import org.gvsig.fmap.mapcontext.MapContextLocator;
31
import org.gvsig.fmap.mapcontext.MapContextManager;
32
import org.gvsig.legend.picturemarkersymboltable.lib.api.PictureMarkerSymbolTableLibrary;
33
import org.gvsig.legend.picturemarkersymboltable.lib.api.PictureMarkerSymbolTableLocator;
34
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.library.AbstractLibrary;
38
import org.gvsig.tools.library.LibraryException;
39
import org.gvsig.tools.persistence.PersistenceManager;
40

  
41
public class PictureMarkerSymbolTableLibraryImpl extends AbstractLibrary {
42

  
43
    @Override
44
    public void doRegistration() {
45
        registerAsImplementationOf(PictureMarkerSymbolTableLibrary.class);
46
        this.require(MapContextLibrary.class);
47
        this.require(SymbologyDefaultImplLibrary.class);
48
    }
49

  
50
    @Override
51
    protected void doInitialize() throws LibraryException {
52
        PictureMarkerSymbolTableLocator.registerPictureMarkerSymbolTableManager(DefaultPictureMarkerSymbolTableManager.class);
53
        MapContextManager mapContextManager = MapContextLocator.getMapContextManager();
54
        mapContextManager.registerLegend("PictureMarkerSymbolTableLegend", DefaultPictureMarkerSymbolTableLegend.class);
55
    }
56

  
57
    @Override
58
    protected void doPostInitialize() throws LibraryException {
59
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
60
        InputStream is = this.getClass().getResourceAsStream("PictureMarkerSymbolTablePersistence.xml");
61
        Map<String,DynStruct> definitions;
62
        try {
63
            definitions = ToolsLocator.getDynObjectManager().importDynClassDefinitions(is, this.getClass().getClassLoader());
64
        } catch (Exception ex) {
65
            throw new LibraryException(this.getClass(), ex);
66
        }
67
        
68
        persistenceManager.addDefinition(
69
                DefaultPictureMarkerSymbolTableLegend.class,
70
                "DefaultPictureMarkerSymbolTableLegend",
71
                definitions,
72
                null,
73
                null
74
        );
75
    }
76

  
77
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/impl/ImageMarkerSymbol.java
1
package org.gvsig.legend.picturemarkersymboltable.lib.impl;
2

  
3
import java.awt.Graphics2D;
4
import java.awt.Rectangle;
5
import java.awt.geom.AffineTransform;
6
import java.awt.geom.Point2D;
7
import java.awt.image.BufferedImage;
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.geom.Geometry;
10
import org.gvsig.fmap.geom.primitive.Point;
11
import org.gvsig.fmap.mapcontext.MapContext;
12
import org.gvsig.fmap.mapcontext.ViewPort;
13
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
14
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
15
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
16
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.AbstractLineSymbol;
17
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
18
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
19
import org.gvsig.tools.swing.api.TransparencySupport;
20
import org.gvsig.tools.task.Cancellable;
21

  
22
/**
23
 *
24
 * @author gvSIG Team
25
 */
26
@SuppressWarnings("UseSpecificCatch")
27
public class ImageMarkerSymbol extends AbstractMarkerSymbol implements  IMarkerSymbol, IMultiLayerSymbol, TransparencySupport {
28

  
29
    private ImageMarkerSymbol selectionSym;
30
    private boolean selected;
31
    private BufferedImage image;
32
    private BufferedImage imagesel;
33
    private ISymbol[] layers;
34
    
35
    private static class ImageSymbol extends AbstractMarkerSymbol implements IMarkerSymbol {
36

  
37
        private final ImageMarkerSymbol parent;
38

  
39
        public ImageSymbol(ImageMarkerSymbol parent) {
40
            this.parent = parent;
41
        }
42
        
43
        @Override
44
        public ISymbol getSymbolForSelection() {
45
            return ((ImageMarkerSymbol)(this.parent.getSymbolForSelection())).getLayer(1);
46
        }
47

  
48
        @Override
49
        public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl) {
50
            Point p;
51
            try {
52
                p = geom.centroid();
53
            } catch (Exception ex) {
54
                return;
55
            }
56
            if (affineTransform != null) {
57
                p.transform(affineTransform);
58
            }
59
            double x, y;
60
            int size = (int) Math.round(this.parent.getEfectiveSize(f));
61
            double halfSize = this.parent.getEfectiveSize(f) / 2;
62
            x = p.getX() - halfSize;
63
            y = p.getY() - halfSize;
64
            Point2D theOffset = this.parent.getEfectiveOffset(f);
65
            int xOffset = (int) theOffset.getX();
66
            int yOffset = (int) theOffset.getY();
67

  
68
            if (size > 0) {
69
                Rectangle rect = new Rectangle(size, size);
70
                g.translate(x + xOffset, y + yOffset);
71
                double auxRotation = this.parent.getEfectiveRotationInRadians(f);
72
                g.rotate(auxRotation, halfSize, halfSize);
73

  
74
                this.parent.drawInsideRectangle(g, rect, true);
75

  
76
                g.rotate(-auxRotation, halfSize, halfSize);
77
                g.translate(-(x + xOffset), -(y + yOffset));
78

  
79
            }
80
        }
81

  
82
        @Override
83
        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
84
            return this.parent.toCartographicSize(viewPort, dpi, geom); //To change body of generated methods, choose Tools | Templates.
85
        }
86

  
87
        @Override
88
        public void setCartographicSize(double cartographicSize, Geometry geom) {
89
            this.parent.setCartographicSize(cartographicSize, geom); //To change body of generated methods, choose Tools | Templates.
90
        }
91

  
92
        @Override
93
        public int getUnit() {
94
            return this.parent.getUnit();
95
        }
96

  
97
    }
98

  
99
    private static class LineSymbol extends AbstractLineSymbol implements ILineSymbol {
100
        
101
        private final ImageMarkerSymbol parent;
102

  
103
        public LineSymbol(ImageMarkerSymbol parent) {
104
            this.parent = parent;
105
        }
106

  
107
        @Override
108
        public ISymbol getSymbolForSelection() {
109
            return ((ImageMarkerSymbol)(this.parent.getSymbolForSelection())).getLayer(0);
110
        }
111

  
112
        @Override
113
        public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl) {
114
            Point p;
115
            try {
116
                p = geom.centroid();
117
            } catch (Exception ex) {
118
                return;
119
            }
120
            if (affineTransform != null) {
121
                p.transform(affineTransform);
122
            }
123
            int size = (int) Math.round(this.parent.getEfectiveSize(f));
124
            Point2D theOffset = this.parent.getEfectiveOffset(f);
125
            int xOffset = (int) theOffset.getX();
126
            int yOffset = (int) theOffset.getY();
127

  
128
            if (size > 0) {
129
                if (this.parent.isDrawLineToOffset()) {
130
                    g.setColor(this.parent.getEfectiveLineToOffsetColor(f));
131
                    g.drawLine((int) p.getX(), (int) p.getY(), (int) p.getX() + xOffset, (int) p.getY() + yOffset);
132
                }
133
            }
134
        }
135

  
136
        @Override
137
        public void setLineWidth(double d) {
138
        }
139

  
140
        @Override
141
        public double getLineWidth() {
142
            return 1;
143
        }
144

  
145
        @Override
146
        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
147
            return this.parent.toCartographicSize(viewPort, dpi, geom); //To change body of generated methods, choose Tools | Templates.
148
        }
149

  
150
        @Override
151
        public void setCartographicSize(double cartographicSize, Geometry geom) {
152
            this.parent.setCartographicSize(cartographicSize, geom); //To change body of generated methods, choose Tools | Templates.
153
        }
154

  
155
        @Override
156
        public int getUnit() {
157
            return this.parent.getUnit();
158
        }
159
        
160
    }
161

  
162
    public ImageMarkerSymbol() {
163
        this.layers = new ISymbol[] {new LineSymbol(this), new ImageSymbol(this)};
164
    }
165
    
166
    void setImage(BufferedImage img) {
167
        this.image = img;
168
    }
169
    
170
    void setImageSel(BufferedImage img) {
171
        this.imagesel = img;
172
    }
173
    
174
    @Override
175
    public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
176
        Point p;
177
        try {
178
            p = geom.centroid();
179
        } catch (Exception ex) {
180
            return;
181
        }
182
        if (affineTransform != null) {
183
            p.transform(affineTransform);
184
        }
185
        double x, y;
186
        int size = (int) Math.round(getEfectiveSize(f));
187
        double halfSize = getEfectiveSize(f) / 2;
188
        x = p.getX() - halfSize;
189
        y = p.getY() - halfSize;
190
        Point2D theOffset = this.getEfectiveOffset(f);
191
        int xOffset = (int) theOffset.getX();
192
        int yOffset = (int) theOffset.getY();
193

  
194
        if (size > 0) {
195
            if( isDrawLineToOffset() ) {
196
                g.setColor(this.getEfectiveLineToOffsetColor(f));
197
                g.drawLine((int)p.getX(), (int)p.getY(), (int)p.getX() + xOffset, (int)p.getY() + yOffset);
198
            }
199
            Rectangle rect = new Rectangle(size, size);
200
            g.translate(x + xOffset, y + yOffset);
201
            double auxRotation = getEfectiveRotationInRadians(f);
202
            g.rotate(auxRotation, halfSize, halfSize);
203
            
204
            this.drawInsideRectangle(g, rect, true);
205
            
206
            g.rotate(-auxRotation, halfSize, halfSize);
207
            g.translate(-(x + xOffset), -(y + yOffset));
208
            
209
        }
210
    }
211

  
212
    private void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) {
213
        BufferedImage theImage = (!selected) ? this.image : this.imagesel;
214
        if (theImage != null) {
215

  
216
            double xOffset = 0;
217
            double yOffset = 0;
218
            @SuppressWarnings("UnusedAssignment")
219
            double xScale = 1;
220
            @SuppressWarnings("UnusedAssignment")
221
            double yScale = 1;
222
            if (keepAspectRatio) {
223
                double scale;
224
                if (theImage.getWidth() > theImage.getHeight()) {
225
                    scale = r.getWidth() / theImage.getWidth();
226
                    yOffset = 0.5 * (r.getHeight() - theImage.getHeight() * scale);
227
                } else {
228
                    scale = r.getHeight() / theImage.getHeight();
229
                    xOffset = 0.5 * (r.getWidth() - theImage.getWidth() * scale);
230
                }
231
                xScale = yScale = scale;
232

  
233
            } else {
234
                xScale = r.getWidth() / theImage.getWidth();
235
                yScale = r.getHeight() / theImage.getHeight();
236
                yOffset = theImage.getHeight() * 0.5 * yScale;
237

  
238
            }
239

  
240
            AffineTransform at = AffineTransform.getTranslateInstance(xOffset, yOffset);
241
            at.concatenate(AffineTransform.getScaleInstance(xScale, yScale));
242
            g.drawRenderedImage(theImage, at);
243
        }
244
        
245
    }
246
    
247
    
248
    @Override
249
    public ISymbol getSymbolForSelection() {
250
        if (selectionSym == null) {
251
            try {
252
                selectionSym = (ImageMarkerSymbol) this.clone();
253
            } catch (CloneNotSupportedException e) {
254
//                LOG.warn("Error creating the selection symbol for the symbol "+ this, e);
255
            }
256
            selectionSym.selected = true;
257
            selectionSym.selectionSym = selectionSym; // avoid too much lazy creations
258
        } else {
259
            selectionSym.setColor(MapContext.getSelectionColor());
260
        }
261
        return selectionSym;
262
    }
263

  
264
    @Override
265
    public Object clone() throws CloneNotSupportedException {
266
        ImageMarkerSymbol copy = (ImageMarkerSymbol) super.clone();
267
        copy.layers = new ISymbol[] {new LineSymbol(copy), new ImageSymbol(copy)};
268

  
269
        return copy;
270
    }
271

  
272
    @Override
273
    public void setTransparency(double d) {
274
    }
275

  
276
    @Override
277
    public double getTransparency() {
278
        return 0;
279
    }
280

  
281
    @Override
282
    public void setLayer(int i, ISymbol is) throws IndexOutOfBoundsException {
283
    }
284

  
285
    @Override
286
    public void swapLayers(int i, int i1) {
287
    }
288

  
289
    @Override
290
    public ISymbol getLayer(int i) {
291
        return getLayers()[i];
292
    }
293

  
294
    @Override
295
    public int getLayerCount() {
296
        return 2;
297
    }
298

  
299
    @Override
300
    public void addLayer(ISymbol is) {
301
    }
302

  
303
    @Override
304
    public void addLayer(ISymbol is, int i) throws IndexOutOfBoundsException {
305
    }
306

  
307
    @Override
308
    public boolean removeLayer(ISymbol is) {
309
        return false;
310
    }
311

  
312
    public ISymbol[] getLayers() {
313
        return layers;
314
    }
315
    
316
    
317
    
318
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/impl/DefaultPictureMarkerSymbolTableManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.legend.picturemarkersymboltable.lib.impl;
24

  
25
import org.gvsig.legend.picturemarkersymboltable.lib.api.PictureMarkerSymbolTableLegend;
26
import org.gvsig.legend.picturemarkersymboltable.lib.api.PictureMarkerSymbolTableManager;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
@SuppressWarnings("UseSpecificCatch")
31
public class DefaultPictureMarkerSymbolTableManager implements PictureMarkerSymbolTableManager {
32

  
33
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPictureMarkerSymbolTableManager.class);
34

  
35
    @Override
36
    public PictureMarkerSymbolTableLegend createPictureMarkerSymbolTableLegend() {
37
        return new DefaultPictureMarkerSymbolTableLegend();
38
    }
39

  
40
    @Override
41
    public Class<? extends PictureMarkerSymbolTableLegend> getPictureMarkerSymbolTableLegendClass() {
42
        return DefaultPictureMarkerSymbolTableLegend.class;
43
    }
44

  
45
    
46
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.legend.picturemarkersymboltable.lib.impl.PictureMarkerSymbolTableLibraryImpl
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.impl/src/main/resources/org/gvsig/legend/picturemarkersymboltable/lib/impl/PictureMarkerSymbolTablePersistence.xml
1
<?xml version="1.0"?>
2
<definitions>
3
    <version>1.0.0</version>
4
    <classes>
5
        <class name="DefaultPictureMarkerSymbolTableLegend">
6
            <extends>
7
                <class name="VectorialLegend" namespace="persistence"/>
8
            </extends>
9
            <fields>
10
                <field name="scale" type="Double" defaultValue="1" mandatory="false">
11
                    <description></description>
12
                </field>
13
                <field name="size" type="Double" defaultValue="15" mandatory="false">
14
                    <description></description>
15
                </field>
16
                <field name="units" type="Integer" defaultValue="-1" mandatory="false">
17
                    <description></description>
18
                </field>
19
                <field name="lineToOffsetColor" type="Object" ClassOfValue="java.awt.Color" defaultValue="darkgrey" mandatory="false">
20
                    <description></description>
21
                </field>
22
                <field name="drawLineToOffset" type="Boolean" defaultValue="true" mandatory="false">
23
                    <description></description>
24
                </field>
25
                <field name="classifyingFieldName" type="String" defaultValue="" mandatory="true">
26
                    <description></description>
27
                </field>
28
                <field name="offsetXFieldName" type="String" defaultValue="" mandatory="false">
29
                    <description></description>
30
                </field>
31
                <field name="offsetYFieldName" type="String" defaultValue="" mandatory="false">
32
                    <description></description>
33
                </field>
34
                <field name="rotationFieldName" type="String" defaultValue="" mandatory="false">
35
                    <description></description>
36
                </field>
37
                <field name="lineToOffsetColorFieldlName" type="String" defaultValue="" mandatory="false">
38
                    <description></description>
39
                </field>
40
                <field name="imagesTableName" type="String" defaultValue="" mandatory="true">
41
                    <description></description>
42
                </field>
43
                <field name="imagesTableClassifyingFieldName" type="String" defaultValue="" mandatory="true">
44
                    <description></description>
45
                </field>
46
                <field name="imageFieldName" type="String" defaultValue="" mandatory="true">
47
                    <description></description>
48
                </field>
49
                <field name="imageSelectedFieldName" type="String" defaultValue="" mandatory="false">
50
                    <description></description>
51
                </field>
52
            </fields>
53
        </class>
54

  
55
    </classes>
56
</definitions>
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.api/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/api/PictureMarkerSymbolTableManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 3
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.legend.picturemarkersymboltable.lib.api;
24

  
25

  
26
public interface PictureMarkerSymbolTableManager {
27

  
28
    public PictureMarkerSymbolTableLegend createPictureMarkerSymbolTableLegend();
29

  
30
    public Class<? extends PictureMarkerSymbolTableLegend> getPictureMarkerSymbolTableLegendClass();
31

  
32
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.api/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/api/PictureMarkerSymbolTableLegend.java
1
package org.gvsig.legend.picturemarkersymboltable.lib.api;
2

  
3
import java.awt.Color;
4
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
5
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
6
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
7

  
8
public interface PictureMarkerSymbolTableLegend 
9
        extends IVectorLegend, IClassifiedLegend, ISingleSymbolLegend 
10
    {
11
    
12
    public static final int DEFAULT_IMAGE_SIZE = 15;
13

  
14
    public double getImageSize();
15
    
16
    public int getUnits();
17

  
18
    public boolean isDrawLineToOffset();
19

  
20
    public Color getDefaultLineToOffsetColor();
21

  
22

  
23
    public String getClassifyingFieldName();
24

  
25
    public String getOffsetXFieldName();
26

  
27
    public String getOffsetYFieldName();
28

  
29
    public String getRotationFieldName();
30

  
31
    public String getLineToOffsetColorFieldName();
32

  
33

  
34

  
35
    public String getImagesTableName();
36

  
37
    public String getImageFieldName();
38

  
39
    public String getImageSelectedFieldName();
40

  
41
    public String getImagesTableClassifyingFieldName();
42

  
43
    public double getScale();
44

  
45

  
46
    public void setImageSize(double size);
47

  
48
    public void setUnits(int unit);
49
    
50
    public void setDefaultLineToOffsetColor(Color color);
51

  
52
    public void setDrawLineToOffset(boolean drawLineToOffset);
53

  
54
    
55

  
56
    public void setLineToOffsetColorFieldName(String fieldName);
57

  
58
    public void setOffsetXFieldName(String fieldName);
59

  
60
    public void setOffsetYFieldName(String fieldName);
61

  
62
    public void setRotationFieldName(String fieldName);
63

  
64
    public void setClassifyingFieldName(String classifyingFieldName);
65

  
66
    
67

  
68
    public void setImagesTableName(String imagesTableName);
69

  
70
    public void setImageFieldName(String imageFieldName);
71

  
72
    public void setImageSelectedFieldName(String imageSelectedFieldName);
73

  
74
    public void setImagesTableClassifyingFieldName(String imagesTableClassifyingFieldName);
75

  
76
    public void setScale(double scale);
77
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.api/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/api/PictureMarkerSymbolTableLocator.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.legend.picturemarkersymboltable.lib.api;
24

  
25
import org.gvsig.tools.locator.AbstractLocator;
26
import org.gvsig.tools.locator.Locator;
27
import org.gvsig.tools.locator.LocatorException;
28

  
29

  
30
public class PictureMarkerSymbolTableLocator extends AbstractLocator {
31

  
32
    /**
33
     * HeatmapLegend locator name
34
     */
35
    private static final String LOCATOR_NAME = "PictureMarkerSymbolTableLocator";
36

  
37
    /**
38
     * HeatmapLegend manager name
39
     */
40
    public static final String MANAGER_NAME = "PictureMarkerSymbolTableManager";
41

  
42
    /**
43
     * HeatmapLegend manager description
44
     */
45
    private static final String MANAGER_DESCRIPTION =
46
        "PictureMarkerSymbolTable Manager of gvSIG";
47

  
48

  
49
    /**
50
     * Unique instance
51
     */
52
    private static final PictureMarkerSymbolTableLocator instance = new PictureMarkerSymbolTableLocator();
53

  
54
    @Override
55
    public String getLocatorName() {
56
        return LOCATOR_NAME;
57
    }
58

  
59
    /**
60
     * Registers the Class implementing the UrbanHorizontalSignageManager interface.
61
     *
62
     * @param clazz
63
     *            implementing the UrbanHorizontalSignageManager interface
64
     */
65
    public static void registerPictureMarkerSymbolTableManager(Class clazz){
66
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
67
    }
68

  
69
    public static void registerDefaultPictureMarkerSymbolTableManager(Class clazz){
70
        getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
71
    }
72

  
73
    public static PictureMarkerSymbolTableManager getPictureMarkerSymbolTableManager() throws LocatorException {
74
        return (PictureMarkerSymbolTableManager) getInstance().get(MANAGER_NAME);
75
    }
76

  
77
    /**
78
     * @return
79
     */
80
    public static Locator getInstance() {
81
        return instance;
82
    }
83

  
84
}
org.gvsig.legend.picturemarkersymboltable/tags/org.gvsig.legend.picturemarkersymboltable-1.0.17/org.gvsig.legend.picturemarkersymboltable.lib/org.gvsig.legend.picturemarkersymboltable.lib.api/src/main/java/org/gvsig/legend/picturemarkersymboltable/lib/api/PictureMarkerSymbolTableLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.legend.picturemarkersymboltable.lib.api;
24

  
25
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
26
import org.gvsig.symbology.SymbologyLocator;
27
import org.gvsig.symbology.SymbologyManager;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
31

  
32

  
33
public class PictureMarkerSymbolTableLibrary extends AbstractLibrary {
34

  
35
    @Override
36
    protected void doInitialize() throws LibraryException {
37
        registerAsAPI(PictureMarkerSymbolTableLibrary.class);
38
    }
39

  
40
    @Override
41
    protected void doPostInitialize() throws LibraryException {
42
        // Validate there is any implementation registered.
43
        PictureMarkerSymbolTableManager manager = PictureMarkerSymbolTableLocator.getPictureMarkerSymbolTableManager();
44
        if (manager == null) {
45
            throw new ReferenceNotRegisteredException(
46
                PictureMarkerSymbolTableLocator.MANAGER_NAME, PictureMarkerSymbolTableLocator.getInstance());
47
        }
48

  
49
        SymbologyManager symbolManager = SymbologyLocator.getSymbologyManager();
50
        ILegendWriter legendWriter = symbolManager.getDefaultLegendWriter();
51
    }
52

  
53
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff