Statistics
| Revision:

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

History | View | Annotate | Download (5.16 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 10809 2007-03-20 16:02:24Z jaume $
45
* $Log$
46
* Revision 1.6  2007-03-20 16:02:24  jaume
47
* rename method
48
*
49
* Revision 1.5  2007/03/09 11:20:56  jaume
50
* Advanced symbology (start committing)
51
*
52
* Revision 1.3.2.5  2007/02/21 07:34:09  jaume
53
* labeling starts working
54
*
55
* Revision 1.3.2.4  2007/02/15 16:23:44  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.3.2.3  2007/02/13 16:19:19  jaume
59
* graduated symbol legends (start commiting)
60
*
61
* Revision 1.3.2.2  2007/02/12 15:15:20  jaume
62
* refactored interval legend and added graduated symbol legend
63
*
64
* Revision 1.3.2.1  2007/02/09 07:47:05  jaume
65
* Isymbol moved
66
*
67
* Revision 1.3  2007/01/25 16:25:23  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.2  2007/01/24 17:58:22  jaume
71
* new features and architecture error fixes
72
*
73
* Revision 1.1  2007/01/16 11:50:44  jaume
74
* *** empty log message ***
75
*
76
*
77
*/
78
package com.iver.cit.gvsig.fmap.core.symbols;
79

    
80
import java.awt.Color;
81
import java.awt.Graphics2D;
82
import java.awt.Rectangle;
83
import java.awt.Shape;
84
import java.awt.geom.AffineTransform;
85

    
86
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
87
import com.iver.cit.gvsig.fmap.core.FShape;
88
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
89
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
90
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
91
import com.iver.utiles.StringUtilities;
92
import com.iver.utiles.XMLEntity;
93

    
94
/**
95
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
96
 */
97
public class SimpleLineSymbol extends AbstractLineSymbol {
98
        SimpleLineSymbol symbolForSelection;
99

    
100
        public ISymbol getSymbolForSelection() {
101
                if (symbolForSelection == null) {
102
                        XMLEntity xml = getXMLEntity();
103
                        xml.putProperty("color", StringUtilities.color2String(FSymbol.getSelectionColor()));
104
                        symbolForSelection = (SimpleLineSymbol) SymbologyFactory.
105
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
106
                }
107
                return symbolForSelection;
108
        }
109

    
110
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
111
                g.setStroke(getLineStyle().getStroke());
112
                g.setColor(getColor());
113
                g.draw(shp);
114
        }
115

    
116
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
117
                        Shape shp) {
118
                return 0;
119
        }
120

    
121
        public int getOnePointRgb() {
122
                return getColor().getRGB();
123
        }
124

    
125
        public XMLEntity getXMLEntity() {
126
                XMLEntity xml = new XMLEntity();
127
                xml.putProperty("className", getClassName());
128
                xml.putProperty("isShapeVisible", isShapeVisible());
129
                xml.putProperty("desc", getDescription());
130
                Color c = getColor();
131
                if (c!= null)
132
                        xml.putProperty("color", StringUtilities.color2String(getColor()));
133

    
134
                xml.addChild(getLineStyle().getXMLEntity());
135
                return xml;
136
        }
137

    
138
        public void drawInsideRectangle(Graphics2D g,
139
                        AffineTransform scaleInstance, Rectangle r) {
140
                g.setColor(getColor());
141
                g.setStroke(getLineStyle().getStroke());
142
                final int hGap = (int) (r.getWidth() * 0.1); // the left and right margins
143
                final int vPos = 1;                                                  // the top and bottom margins
144
                final int splitCount = 3;                                          // number of lines
145
                final int splitHSize = (r.width - hGap - hGap) / splitCount;
146
                int hPos = hGap;
147
                boolean swap = false;
148
                for (int i = 0; i < splitCount; i++) {
149
                        swap = !swap;
150
                        g.drawLine(hPos, swap ? vPos : r.height-vPos, hPos + splitHSize, swap ? r.height-vPos : vPos);
151
                        hPos += splitHSize;
152
                }
153
        }
154

    
155
        public String getClassName() {
156
                return getClass().getName();
157
        }
158

    
159
        public void setXMLEntity(XMLEntity xml) {
160
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
161
                setDescription(xml.getStringProperty("desc"));
162
                if (xml.contains("color"))
163
                        setLineColor(StringUtilities.
164
                                string2Color(xml.getStringProperty("color")));
165
                setLineStyle((ILineStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null));
166
        }
167

    
168
        public void print(Graphics2D g, AffineTransform at, FShape shape)
169
                        throws ReadDriverException {
170
                // TODO Implement it
171
                throw new Error("Not yet implemented!");
172

    
173
        }
174

    
175
        public void setLineWidth(double width) {
176
                getLineStyle().setLineWidth((float) width);
177
        }
178

    
179
        public double getLineWidth() {
180
                return getLineStyle().getLineWidth();
181
        }
182

    
183
}