Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / style / DefaultMask.java @ 31544

History | View | Annotate | Download (4.72 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
23

    
24
import java.awt.BasicStroke;
25
import java.awt.Graphics2D;
26
import java.awt.Rectangle;
27
import java.awt.Shape;
28

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

    
44
/**
45
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
46
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
47
 */
48
public class DefaultMask extends AbstractStyle implements IMask {
49

    
50
        public static final String DEFAULT_MASK_DYNCLASS_NAME = "DefaultMask";
51

    
52
        private static final String FIELD_SIZE = "size";
53
        private static final String FIELD_FILL_SYMBOL = "fillSymbol";
54

    
55
        private static final GeometryManager geomManager = GeometryLocator
56
                        .getGeometryManager();
57
        private static final Logger logger = LoggerFactory
58
                        .getLogger(DefaultMask.class);
59
        private double size;
60
        private IFillSymbol fill;
61

    
62
        public double getSize() {
63
                return size;
64
        }
65

    
66
        public void setSize(double size) {
67
                this.size = size;
68
        }
69

    
70
        public IFillSymbol getFillSymbol() {
71
                return fill;
72

    
73
        }
74

    
75
        public void setFillSymbol(IFillSymbol fill) {
76
                this.fill = fill;
77
        }
78

    
79
        public void drawInsideRectangle(Graphics2D g, Rectangle r) {
80
                // TODO Implement it
81
                throw new Error("Not yet implemented!");
82

    
83
        }
84

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

    
98
                return haloShape;
99
        }
100

    
101
        public boolean isSuitableFor(ISymbol symbol) {
102
                // TODO Implement it
103
                throw new Error("Not yet implemented!");
104

    
105
        }
106

    
107
        public void drawOutline(Graphics2D g, Rectangle r) {
108
                // TODO Implement it
109
                throw new Error("Not yet implemented!");
110

    
111
        }
112

    
113
        public String getClassName() {
114
                return this.getClass().getName();
115
        }
116

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

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

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

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

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

    
146
        public static void registerPersistence() {
147
                // Add the DynClass definition.
148
                DynClass dynClass = ToolsLocator.getDynObjectManager().add(
149
                                DEFAULT_MASK_DYNCLASS_NAME);
150

    
151
                // Extend the Style base definition
152
                dynClass.extend(STYLE_DYNCLASS_NAME);
153

    
154
                // Fill symbol
155
                dynClass.addDynFieldObject(FIELD_FILL_SYMBOL);
156
                // size
157
                dynClass.addDynFieldDouble(FIELD_SIZE).setMandatory(true);
158

    
159
                // Register in persistence
160
                ToolsLocator.getPersistenceManager().registerClass(DefaultMask.class,
161
                                dynClass);
162
        }
163
}