Statistics
| Revision:

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

History | View | Annotate | Download (7.9 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.dal.exception.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.XMLException;
141
import com.iver.utiles.swing.threads.Cancellable;
142

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

    
150

    
151
        public ISymbol getSymbolForSelection() {
152
                if (symbolForSelection == null) {
153
                        XMLEntity xml=null;
154
                        try {
155
                                xml = getXMLEntity();
156
                        } catch (XMLException e) {
157
                                // TODO Auto-generated catch block
158
                                e.printStackTrace();
159
                        }
160
                        xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
161
                        symbolForSelection = (SimpleFillSymbol) SymbologyFactory.
162
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
163
                }
164
                return symbolForSelection;
165
        }
166

    
167
        public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Cancellable cancel) {
168
                Color c = getFillColor();
169
                if (c!=null && hasFill()) {
170
                        g.setColor(c);
171
                        g.fill(geom);
172
                }
173
                if (getOutline() != null && hasOutline())
174
                        getOutline().draw(g, affineTransform, geom, cancel);
175
        }
176

    
177
        public XMLEntity getXMLEntity() throws XMLException {
178
                XMLEntity xml = new XMLEntity();
179

    
180
                // the class name
181
                xml.putProperty("className", getClassName());
182

    
183
                // color
184
                Color c = getFillColor();
185
                if (c!=null)
186
                        xml.putProperty("color", StringUtilities.color2String(getFillColor()));
187

    
188
                //has Fill
189
                xml.putProperty("hasFill", hasFill());
190
                // description
191
                xml.putProperty("desc", getDescription());
192

    
193
                // is shape visible
194
                xml.putProperty("isShapeVisible", isShapeVisible());
195

    
196
                xml.putProperty("referenceSystem", getReferenceSystem());
197
                xml.putProperty("unit", getUnit());
198

    
199
                // outline
200
                if (getOutline() != null)
201
                        xml.addChild(getOutline().getXMLEntity());
202

    
203
                //has Outline
204
                xml.putProperty("hasOutline", hasOutline());
205

    
206
                return xml;
207
        }
208

    
209
        public int getSymbolType() {
210
                return Geometry.TYPES.SURFACE;
211
        }
212

    
213
        public void drawInsideRectangle(Graphics2D g,
214
                        AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
215
                Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height);
216
                rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2);
217
                Geometry geom = new Surface2D(new GeneralPathX(rect));
218

    
219
                Color c = getFillColor();
220
                if (c != null && hasFill()) {
221
                        g.setColor(c);
222
                        g.fillRect(rect.x, rect.y, rect.width, rect.height);
223
                }
224

    
225
                if (getOutline() != null && hasOutline())
226
                        getOutline().draw(g, scaleInstance, geom, null);
227
        }
228

    
229
        public String getClassName() {
230
                return getClass().getName();
231
        }
232

    
233
        public void setXMLEntity(XMLEntity xml) {
234
                // color
235
                if (xml.contains("color"))
236
                        setFillColor(StringUtilities.string2Color(xml.getStringProperty("color")));
237

    
238
                //has Fill
239
                if(xml.contains("hasFill"))
240
                        setHasFill(xml.getBooleanProperty("hasFill"));
241

    
242
                // description
243
                setDescription(xml.getStringProperty("desc"));
244

    
245
                // is shape visible
246
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
247

    
248

    
249
                // outline
250
                if (xml.getChildrenCount() > 0)
251
                        setOutline((ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
252

    
253
                if (xml.contains("unit")) { // remove this line when done
254
                // measure unit (for outline)
255
                setUnit(xml.getIntProperty("unit"));
256

    
257
                // reference system (for outline)
258
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
259
                }
260

    
261
                //has Outline
262
                if(xml.contains("hasOutline"))
263
                        setHasOutline(xml.getBooleanProperty("hasOutline"));
264
        }
265

    
266
        public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet properties) throws ReadException {
267
                Color c = getFillColor();
268
                if (c!=null && hasFill()) {
269
                        g.setColor(c);
270
                        g.fill(geom);
271
                }
272
                if (getOutline() != null && hasOutline())
273
                        getOutline().print(g, at, geom, properties);
274
        }
275
}