Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / symbols / SimpleFillSymbol.java @ 23070

History | View | Annotate | Download (7.71 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: SimpleFillSymbol.java 21071 2008-06-02 10:55:35Z vcaballero $
45
* $Log$
46
* Revision 1.14  2007-09-21 12:25:32  jaume
47
* cancellation support extended down to the IGeometry and ISymbol level
48
*
49
* Revision 1.13  2007/09/19 16:22:04  jaume
50
* removed unnecessary imports
51
*
52
* Revision 1.12  2007/09/18 14:50:31  caballero
53
* Leyendas sobre el Layout
54
*
55
* Revision 1.11  2007/07/23 06:52:25  jaume
56
* default selection color refactored, moved to MapContext
57
*
58
* Revision 1.10  2007/03/26 15:02:49  jaume
59
* Refactored IPrintable
60
*
61
* Revision 1.9  2007/03/21 11:37:00  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.8  2007/03/21 11:02:17  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.7  2007/03/20 17:00:50  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.6  2007/03/20 16:02:09  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.5  2007/03/09 11:20:57  jaume
74
* Advanced symbology (start committing)
75
*
76
* Revision 1.3.2.5  2007/02/21 07:34:09  jaume
77
* labeling starts working
78
*
79
* Revision 1.3.2.4  2007/02/16 10:54:12  jaume
80
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
81
*
82
* Revision 1.3.2.3  2007/02/15 16:23:44  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.3.2.2  2007/02/12 15:15:20  jaume
86
* refactored interval legend and added graduated symbol legend
87
*
88
* Revision 1.3.2.1  2007/02/09 07:47:05  jaume
89
* Isymbol moved
90
*
91
* Revision 1.3  2007/01/24 17:58:22  jaume
92
* new features and architecture error fixes
93
*
94
* Revision 1.2  2007/01/10 16:39:41  jaume
95
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
96
*
97
* Revision 1.1  2007/01/10 16:31:36  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.7  2006/11/14 11:10:27  jaume
101
* *** empty log message ***
102
*
103
* Revision 1.6  2006/11/09 18:39:05  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.5  2006/11/09 10:22:50  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.4  2006/11/08 13:05:51  jaume
110
* *** empty log message ***
111
*
112
* Revision 1.3  2006/11/08 10:56:47  jaume
113
* *** empty log message ***
114
*
115
* Revision 1.2  2006/11/06 16:06:52  jaume
116
* *** empty log message ***
117
*
118
* Revision 1.1  2006/10/30 19:30:35  jaume
119
* *** empty log message ***
120
*
121
*
122
*/
123
package org.gvsig.fmap.mapcontext.rendering.symbols;
124

    
125
import java.awt.Color;
126
import java.awt.Graphics2D;
127
import java.awt.Rectangle;
128
import java.awt.geom.AffineTransform;
129

    
130
import javax.print.attribute.PrintRequestAttributeSet;
131

    
132
import org.gvsig.fmap.data.ReadException;
133
import org.gvsig.fmap.geom.Geometry;
134
import org.gvsig.fmap.geom.primitive.GeneralPathX;
135
import org.gvsig.fmap.geom.primitive.Surface2D;
136
import org.gvsig.fmap.mapcontext.MapContext;
137

    
138
import com.iver.utiles.StringUtilities;
139
import com.iver.utiles.XMLEntity;
140
import com.iver.utiles.swing.threads.Cancellable;
141

    
142
/**
143
 * Basic fill symbol. It will allow to paint a shape with its filling color (and transparency) and the outline.
144
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
145
 */
146
public class SimpleFillSymbol extends AbstractFillSymbol {
147
        private SimpleFillSymbol symbolForSelection;
148

    
149

    
150
        public ISymbol getSymbolForSelection() {
151
                if (symbolForSelection == null) {
152
                        XMLEntity xml = getXMLEntity();
153
                        xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
154
                        symbolForSelection = (SimpleFillSymbol) SymbologyFactory.
155
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
156
                }
157
                return symbolForSelection;
158
        }
159

    
160
        public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Cancellable cancel) {
161
                Color c = getFillColor();
162
                if (c!=null && hasFill()) {
163
                        g.setColor(c);
164
                        g.fill(geom);
165
                }
166
                if (getOutline() != null && hasOutline())
167
                        getOutline().draw(g, affineTransform, geom, cancel);
168
        }
169

    
170
        public XMLEntity getXMLEntity() {
171
                XMLEntity xml = new XMLEntity();
172

    
173
                // the class name
174
                xml.putProperty("className", getClassName());
175

    
176
                // color
177
                Color c = getFillColor();
178
                if (c!=null)
179
                        xml.putProperty("color", StringUtilities.color2String(getFillColor()));
180

    
181
                //has Fill
182
                xml.putProperty("hasFill", hasFill());
183
                // description
184
                xml.putProperty("desc", getDescription());
185

    
186
                // is shape visible
187
                xml.putProperty("isShapeVisible", isShapeVisible());
188

    
189
                xml.putProperty("referenceSystem", getReferenceSystem());
190
                xml.putProperty("unit", getUnit());
191

    
192
                // outline
193
                if (getOutline() != null)
194
                        xml.addChild(getOutline().getXMLEntity());
195

    
196
                //has Outline
197
                xml.putProperty("hasOutline", hasOutline());
198

    
199
                return xml;
200
        }
201

    
202
        public int getSymbolType() {
203
                return Geometry.TYPES.SURFACE;
204
        }
205

    
206
        public void drawInsideRectangle(Graphics2D g,
207
                        AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
208
                Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height);
209
                rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2);
210
                Geometry geom = new Surface2D(new GeneralPathX(rect));
211

    
212
                Color c = getFillColor();
213
                if (c != null && hasFill()) {
214
                        g.setColor(c);
215
                        g.fillRect(rect.x, rect.y, rect.width, rect.height);
216
                }
217

    
218
                if (getOutline() != null && hasOutline())
219
                        getOutline().draw(g, scaleInstance, geom, null);
220
        }
221

    
222
        public String getClassName() {
223
                return getClass().getName();
224
        }
225

    
226
        public void setXMLEntity(XMLEntity xml) {
227
                // color
228
                if (xml.contains("color"))
229
                        setFillColor(StringUtilities.string2Color(xml.getStringProperty("color")));
230

    
231
                //has Fill
232
                if(xml.contains("hasFill"))
233
                        setHasFill(xml.getBooleanProperty("hasFill"));
234

    
235
                // description
236
                setDescription(xml.getStringProperty("desc"));
237

    
238
                // is shape visible
239
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
240

    
241

    
242
                // outline
243
                if (xml.getChildrenCount() > 0)
244
                        setOutline((ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
245

    
246
                if (xml.contains("unit")) { // remove this line when done
247
                // measure unit (for outline)
248
                setUnit(xml.getIntProperty("unit"));
249

    
250
                // reference system (for outline)
251
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
252
                }
253

    
254
                //has Outline
255
                if(xml.contains("hasOutline"))
256
                        setHasOutline(xml.getBooleanProperty("hasOutline"));
257
        }
258

    
259
        public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet properties) throws ReadException {
260
                Color c = getFillColor();
261
                if (c!=null && hasFill()) {
262
                        g.setColor(c);
263
                        g.fill(geom);
264
                }
265
                if (getOutline() != null && hasOutline())
266
                        getOutline().print(g, at, geom, properties);
267
        }
268
}