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 9745 jaume
/* 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$
45
* $Log$
46 10809 jaume
* 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 10679 jaume
* Advanced symbology (start committing)
51 10627 caballero
*
52 10679 jaume
* 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 10627 caballero
* Revision 1.3  2007/01/25 16:25:23  jaume
68 9919 jaume
* *** empty log message ***
69
*
70
* Revision 1.2  2007/01/24 17:58:22  jaume
71 9893 jaume
* new features and architecture error fixes
72
*
73
* Revision 1.1  2007/01/16 11:50:44  jaume
74 9745 jaume
* *** empty log message ***
75
*
76
*
77
*/
78
package com.iver.cit.gvsig.fmap.core.symbols;
79
80 10679 jaume
import java.awt.Color;
81 9745 jaume
import java.awt.Graphics2D;
82
import java.awt.Rectangle;
83
import java.awt.Shape;
84
import java.awt.geom.AffineTransform;
85
86 10627 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
87 9745 jaume
import com.iver.cit.gvsig.fmap.core.FShape;
88 10679 jaume
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
89
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
90 9893 jaume
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
91
import com.iver.utiles.StringUtilities;
92 9745 jaume
import com.iver.utiles.XMLEntity;
93
94 10679 jaume
/**
95
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
96
 */
97 9745 jaume
public class SimpleLineSymbol extends AbstractLineSymbol {
98 10679 jaume
        SimpleLineSymbol symbolForSelection;
99 9745 jaume
100
        public ISymbol getSymbolForSelection() {
101 10679 jaume
                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 9893 jaume
                }
107 10679 jaume
                return symbolForSelection;
108 9745 jaume
        }
109
110
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
111 10679 jaume
                g.setStroke(getLineStyle().getStroke());
112 9893 jaume
                g.setColor(getColor());
113 9745 jaume
                g.draw(shp);
114
        }
115
116
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
117
                        Shape shp) {
118 9893 jaume
                return 0;
119 9745 jaume
        }
120
121
        public int getOnePointRgb() {
122 9893 jaume
                return getColor().getRGB();
123 9745 jaume
        }
124
125
        public XMLEntity getXMLEntity() {
126 9893 jaume
                XMLEntity xml = new XMLEntity();
127
                xml.putProperty("className", getClassName());
128
                xml.putProperty("isShapeVisible", isShapeVisible());
129 10679 jaume
                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 9893 jaume
                return xml;
136 9745 jaume
        }
137
138
        public void drawInsideRectangle(Graphics2D g,
139
                        AffineTransform scaleInstance, Rectangle r) {
140 9893 jaume
                g.setColor(getColor());
141 10679 jaume
                g.setStroke(getLineStyle().getStroke());
142 9919 jaume
                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 9893 jaume
                final int splitHSize = (r.width - hGap - hGap) / splitCount;
146
                int hPos = hGap;
147 9919 jaume
                boolean swap = false;
148 9893 jaume
                for (int i = 0; i < splitCount; i++) {
149 9919 jaume
                        swap = !swap;
150
                        g.drawLine(hPos, swap ? vPos : r.height-vPos, hPos + splitHSize, swap ? r.height-vPos : vPos);
151 9893 jaume
                        hPos += splitHSize;
152
                }
153 9745 jaume
        }
154
155
        public String getClassName() {
156
                return getClass().getName();
157
        }
158
159
        public void setXMLEntity(XMLEntity xml) {
160 9893 jaume
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
161 10679 jaume
                setDescription(xml.getStringProperty("desc"));
162
                if (xml.contains("color"))
163 10809 jaume
                        setLineColor(StringUtilities.
164 9919 jaume
                                string2Color(xml.getStringProperty("color")));
165 10679 jaume
                setLineStyle((ILineStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null));
166 9745 jaume
        }
167
168
        public void print(Graphics2D g, AffineTransform at, FShape shape)
169 10627 caballero
                        throws ReadDriverException {
170 9745 jaume
                // TODO Implement it
171
                throw new Error("Not yet implemented!");
172
173
        }
174
175 10809 jaume
        public void setLineWidth(double width) {
176 10679 jaume
                getLineStyle().setLineWidth((float) width);
177
        }
178
179 10809 jaume
        public double getLineWidth() {
180 10679 jaume
                return getLineStyle().getLineWidth();
181
        }
182
183 9745 jaume
}