Statistics
| Revision:

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

History | View | Annotate | Download (6.56 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: SimpleLineSymbol.java 18621 2008-02-08 07:59:54Z jdominguez $
45
* $Log$
46
* Revision 1.16  2007-09-21 12:25:32  jaume
47
* cancellation support extended down to the IGeometry and ISymbol level
48
*
49
* Revision 1.15  2007/09/19 16:22:04  jaume
50
* removed unnecessary imports
51
*
52
* Revision 1.14  2007/09/17 09:33:47  jaume
53
* some multishapedsymbol bugs fixed
54
*
55
* Revision 1.13  2007/08/09 07:38:32  jvidal
56
* javadoc
57
*
58
* Revision 1.12  2007/07/23 06:52:55  jaume
59
* Added support for arrow line decorator (start commiting)
60
*
61
* Revision 1.11  2007/07/18 06:54:35  jaume
62
* continuing with cartographic support
63
*
64
* Revision 1.10  2007/06/29 13:07:01  jaume
65
* +PictureLineSymbol
66
*
67
* Revision 1.9  2007/06/07 06:50:40  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.8  2007/05/08 08:47:40  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.7  2007/03/26 15:02:49  jaume
74
* Refactored IPrintable
75
*
76
* Revision 1.6  2007/03/20 16:02:24  jaume
77
* rename method
78
*
79
* Revision 1.5  2007/03/09 11:20:56  jaume
80
* Advanced symbology (start committing)
81
*
82
* Revision 1.3.2.5  2007/02/21 07:34:09  jaume
83
* labeling starts working
84
*
85
* Revision 1.3.2.4  2007/02/15 16:23:44  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.3.2.3  2007/02/13 16:19:19  jaume
89
* graduated symbol legends (start commiting)
90
*
91
* Revision 1.3.2.2  2007/02/12 15:15:20  jaume
92
* refactored interval legend and added graduated symbol legend
93
*
94
* Revision 1.3.2.1  2007/02/09 07:47:05  jaume
95
* Isymbol moved
96
*
97
* Revision 1.3  2007/01/25 16:25:23  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.2  2007/01/24 17:58:22  jaume
101
* new features and architecture error fixes
102
*
103
* Revision 1.1  2007/01/16 11:50:44  jaume
104
* *** empty log message ***
105
*
106
*
107
*/
108
package com.iver.cit.gvsig.fmap.core.symbols;
109

    
110
import java.awt.Color;
111
import java.awt.Graphics2D;
112
import java.awt.Rectangle;
113
import java.awt.geom.AffineTransform;
114

    
115
import javax.print.attribute.PrintRequestAttributeSet;
116

    
117
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
118
import com.iver.cit.gvsig.fmap.MapContext;
119
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
120
import com.iver.cit.gvsig.fmap.core.FShape;
121
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
122
import com.iver.cit.gvsig.fmap.core.styles.ArrowDecoratorStyle;
123
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
124
import com.iver.cit.gvsig.fmap.core.styles.Line2DOffset;
125
import com.iver.utiles.StringUtilities;
126
import com.iver.utiles.XMLEntity;
127
import com.iver.utiles.swing.threads.Cancellable;
128

    
129
/**
130
 * SimpleLineSymbol is the most basic symbol for the representation of line objects.
131
 * Allows to define the width of the line, the color and the drawn pattern.
132
 *
133
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
134
 */
135
public class SimpleLineSymbol extends AbstractLineSymbol {
136
        SimpleLineSymbol symbolForSelection;
137
        private double width;
138

    
139
        
140
        public ISymbol getSymbolForSelection() {
141
                if (symbolForSelection == null) { 
142
                        XMLEntity xml = getXMLEntity();
143
                        xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
144
                        symbolForSelection = (SimpleLineSymbol) SymbologyFactory.
145
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
146
                }
147
                return symbolForSelection;
148
        }
149

    
150
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
151
                g.setStroke(getLineStyle().getStroke());
152
                
153
                if (getLineStyle().getOffset() != 0) {
154
                        double offset = getLineStyle().getOffset();
155
                        shp = new FPolygon2D(Line2DOffset.offsetLine(shp, offset));
156
                }
157
                g.setColor(getColor());
158
                g.draw(shp);
159
        
160
                ArrowDecoratorStyle arrowDecorator = getLineStyle().getArrowDecorator();
161

    
162
                if (arrowDecorator != null)
163
                        arrowDecorator.draw(g, affineTransform, shp);
164
        }
165

    
166
        public int getOnePointRgb() {
167
                return getColor().getRGB();
168
        }
169

    
170
        public XMLEntity getXMLEntity() {
171
                XMLEntity xml = new XMLEntity();
172
                xml.putProperty("className", getClassName());
173
                xml.putProperty("isShapeVisible", isShapeVisible());
174
                xml.putProperty("desc", getDescription());
175
                xml.putProperty("unit", getUnit());
176

    
177
                // reference system
178
                xml.putProperty("referenceSystem", getReferenceSystem());
179

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

    
184
                setLineWidth(getLineWidth()); // not a joke
185
                xml.addChild(getLineStyle().getXMLEntity());
186
                return xml;
187
        }
188

    
189
        public void drawInsideRectangle(Graphics2D g,
190
                        AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
191
                g.setColor(getColor());
192
                g.setStroke(getLineStyle().getStroke());
193
                super.drawInsideRectangle(g, scaleInstance, r);
194
        }
195

    
196
        public String getClassName() {
197
                return getClass().getName();
198
        }
199

    
200
        public void setXMLEntity(XMLEntity xml) {
201
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
202
                setDescription(xml.getStringProperty("desc"));
203
                if (xml.contains("color"))
204
                        setLineColor(StringUtilities.
205
                                string2Color(xml.getStringProperty("color")));
206
                setLineStyle((ILineStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null));
207
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
208
                setUnit(xml.getIntProperty("unit"));
209
                width = getLineStyle().getLineWidth(); // not a joke
210
        }
211

    
212
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties)
213
                        throws ReadDriverException {
214
                // TODO Implement it
215
                throw new Error("Not yet implemented!");
216

    
217
        }
218

    
219
        public void setLineWidth(double width) {
220
                this.width = width;
221
                getLineStyle().setLineWidth((float) width);
222
        }
223

    
224
        public double getLineWidth() {
225
                return width;
226
        }
227

    
228
}