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 / fmap / mapcontext / rendering / symbol / style / DefaultMask.java @ 40560

History | View | Annotate | Download (5.25 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
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
25

    
26
import java.awt.BasicStroke;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29
import java.awt.Shape;
30

    
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.GeneralPathX;
37
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42
import org.gvsig.tools.persistence.PersistentState;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44
import org.gvsig.tools.util.Callable;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
50
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
51
 */
52
public class DefaultMask extends AbstractStyle implements IMask {
53
        private static final Logger LOG = LoggerFactory.getLogger(DefaultMask.class);
54

    
55
        public static final String DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME = "DefaultMask";
56

    
57
        private static final String FIELD_SIZE = "size";
58
        private static final String FIELD_FILL_SYMBOL = "fillSymbol";
59

    
60
        private static final GeometryManager geomManager = GeometryLocator
61
                        .getGeometryManager();
62
        private double size;
63
        private IFillSymbol fill;
64

    
65
        public double getSize() {
66
                return size;
67
        }
68

    
69
        public void setSize(double size) {
70
                this.size = size;
71
        }
72

    
73
        public IFillSymbol getFillSymbol() {
74
                return fill;
75

    
76
        }
77

    
78
        public void setFillSymbol(IFillSymbol fill) {
79
                this.fill = fill;
80
        }
81

    
82
        public void drawInsideRectangle(Graphics2D g, Rectangle r) {
83
                // TODO Implement it
84
                LOG.error("TODO: Not yet implemented");
85
                throw new Error("Not yet implemented!");
86

    
87
        }
88

    
89
        public Geometry getHaloShape(Shape shp) {
90
                BasicStroke stroke = new BasicStroke(
91
                                (int) /* falta CartographicSupport */getSize());
92
                Shape myShp = stroke.createStrokedShape(shp);
93
                Geometry haloShape = null;
94
                ;
95
                try {
96
                        haloShape = geomManager.createSurface(new GeneralPathX(myShp
97
                                        .getBounds2D().getPathIterator(null)), SUBTYPES.GEOM2D);
98
                } catch (CreateGeometryException e) {
99
                        LOG.error("Error creating a surface", e);
100
                }
101

    
102
                return haloShape;
103
        }
104

    
105
        public boolean isSuitableFor(ISymbol symbol) {
106
                // TODO Implement it
107
                LOG.error("TODO: Not yet implemented");
108
                throw new Error("Not yet implemented!");
109

    
110
        }
111

    
112
        public void drawOutline(Graphics2D g, Rectangle r) {
113
                // TODO Implement it
114
                LOG.error("TODO: Not yet implemented");
115
                throw new Error("Not yet implemented!");
116

    
117
        }
118

    
119
        public Object clone() throws CloneNotSupportedException {
120
                DefaultMask copy = (DefaultMask) super.clone();
121
                if (fill != null) {
122
                        copy.fill = (IFillSymbol) fill.clone();
123
                }
124
                return copy;
125
        }
126

    
127
        public void loadFromState(PersistentState state)
128
                        throws PersistenceException {
129
                // Set parent style properties
130
                super.loadFromState(state);
131

    
132
                // Set own properties
133
                setFillSymbol((IFillSymbol) state.get(FIELD_FILL_SYMBOL));
134
                setSize(state.getDouble(FIELD_SIZE));
135
        }
136

    
137
        public void saveToState(PersistentState state) throws PersistenceException {
138
                // Save parent fill symbol properties
139
                super.saveToState(state);
140

    
141
                // Save own properties
142
                if (getFillSymbol() != null) {
143
                        state.set(FIELD_FILL_SYMBOL, getFillSymbol());
144
                }
145
                state.set(FIELD_SIZE, getSize());
146
        }
147

    
148
        public static class RegisterPersistence implements Callable {
149

    
150
                public Object call() throws Exception {
151
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
152
                        if( manager.getDefinition(DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME)==null ) {
153
                                DynStruct definition = manager.addDefinition(
154
                                                DefaultMask.class,
155
                                                DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME,
156
                                                DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
157
                                                null, 
158
                                                null
159
                                );
160
                                
161
                                // Extend the Style base definition
162
                                definition.extend(manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME));
163

    
164
                                // Fill symbol
165
                                definition.addDynFieldObject(FIELD_FILL_SYMBOL)
166
                                        .setClassOfValue(IFillSymbol.class);
167
                                // size
168
                                definition.addDynFieldDouble(FIELD_SIZE).setMandatory(true);
169
                        }
170
                        return Boolean.TRUE;
171
                }
172
                
173
        }
174
}