Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleFillSymbol.java @ 13881

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

    
122
import java.awt.Color;
123
import java.awt.Graphics2D;
124
import java.awt.Rectangle;
125
import java.awt.Shape;
126
import java.awt.geom.AffineTransform;
127

    
128
import javax.print.attribute.PrintRequestAttributeSet;
129

    
130
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
131
import com.iver.cit.gvsig.fmap.MapContext;
132
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
133
import com.iver.cit.gvsig.fmap.core.FShape;
134
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
135
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
136
import com.iver.utiles.StringUtilities;
137
import com.iver.utiles.XMLEntity;
138

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

    
146

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

    
157
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
158
                Color c = getFillColor();
159
                if (c!=null) {
160
                        g.setColor(c);
161
                        g.fill(shp);
162
                }
163
                if (getOutline() != null)
164
                        getOutline().draw(g, affineTransform, shp);
165
        }
166

    
167
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
168
                        Shape shp) {
169
                // TODO Auto-generated method stub
170
                throw new Error("Not yet implemented!");
171
        }
172

    
173
        public XMLEntity getXMLEntity() {
174
                XMLEntity xml = new XMLEntity();
175

    
176
                // the class name
177
                xml.putProperty("className", getClassName());
178

    
179
                // color
180
                Color c = getFillColor();
181
                if (c!=null)
182
                        xml.putProperty("color", StringUtilities.color2String(getFillColor()));
183

    
184
                // description
185
                xml.putProperty("desc", getDescription());
186

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

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

    
196
        public int getSymbolType() {
197
                return FShape.POLYGON;
198
        }
199

    
200
        public void drawInsideRectangle(Graphics2D g,
201
                        AffineTransform scaleInstance, Rectangle r) {
202
                Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height);
203
                rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2);
204
                FShape shp = new FPolygon2D(new GeneralPathX(rect));
205

    
206
                Color c = getFillColor();
207
                if (c != null) {
208
                        g.setColor(c);
209
                        g.fillRect(rect.x, rect.y, rect.width, rect.height);
210
                }
211

    
212
                if (getOutline() != null)
213
                        getOutline().draw(g, scaleInstance, shp);
214
        }
215

    
216
        public String getClassName() {
217
                return getClass().getName();
218
        }
219

    
220
        public void setXMLEntity(XMLEntity xml) {
221
                // color
222
                if (xml.contains("color"))
223
                        setFillColor(StringUtilities.string2Color(xml.getStringProperty("color")));
224

    
225
                // description
226
                setDescription(xml.getStringProperty("desc"));
227

    
228
                // is shape visible
229
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
230

    
231
                // outline
232
                if (xml.getChildrenCount() > 0)
233
                        setOutline((ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
234

    
235
        }
236

    
237
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) throws ReadDriverException {
238
                // TODO Implement it
239
                throw new Error("Not yet implemented!");
240

    
241
        }
242
}