Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleLineSymbol.java @ 10436

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

    
74
import java.awt.Graphics2D;
75
import java.awt.Rectangle;
76
import java.awt.Shape;
77
import java.awt.geom.AffineTransform;
78

    
79
import com.iver.cit.gvsig.fmap.DriverException;
80
import com.iver.cit.gvsig.fmap.core.FShape;
81
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
82
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
83
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
84
import com.iver.utiles.StringUtilities;
85
import com.iver.utiles.XMLEntity;
86

    
87
/**
88
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
89
 */
90
public class SimpleLineSymbol extends AbstractLineSymbol {
91
        SimpleLineSymbol symbolForSelection;
92

    
93
        public ISymbol getSymbolForSelection() {
94
                if (symbolForSelection == null) {
95
                        XMLEntity xml = getXMLEntity();
96
                        xml.putProperty("color", StringUtilities.color2String(FSymbol.getSelectionColor()));
97
                        symbolForSelection = (SimpleLineSymbol) SymbologyFactory.
98
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
99
                }
100
                return symbolForSelection;
101
        }
102

    
103
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
104
                g.setStroke(getLineStyle().getStroke());
105
                g.setColor(getColor());
106
                g.draw(shp);
107
        }
108

    
109
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
110
                        Shape shp) {
111
                return 0;
112
        }
113

    
114
        public int getOnePointRgb() {
115
                return getColor().getRGB();
116
        }
117

    
118
        public XMLEntity getXMLEntity() {
119
                XMLEntity xml = new XMLEntity();
120
                xml.putProperty("className", getClassName());
121
                xml.putProperty("isShapeVisible", isShapeVisible());
122
                xml.putProperty("color", StringUtilities.color2String(getColor()));
123
                xml.addChild(getLineStyle().getXMLEntity());
124
                return xml;
125
        }
126

    
127
        public void drawInsideRectangle(Graphics2D g,
128
                        AffineTransform scaleInstance, Rectangle r) {
129
                g.setColor(getColor());
130
                g.setStroke(getLineStyle().getStroke());
131
                final int hGap = (int) (r.getWidth() * 0.1); // the left and right margins
132
                final int vPos = 1;                                                  // the top and bottom margins
133
                final int splitCount = 3;                                          // number of lines
134
                final int splitHSize = (r.width - hGap - hGap) / splitCount;
135
                int hPos = hGap;
136
                boolean swap = false;
137
                for (int i = 0; i < splitCount; i++) {
138
                        swap = !swap;
139
                        g.drawLine(hPos, swap ? vPos : r.height-vPos, hPos + splitHSize, swap ? r.height-vPos : vPos);
140
                        hPos += splitHSize;
141
                }
142
        }
143

    
144
        public String getClassName() {
145
                return getClass().getName();
146
        }
147

    
148
        public void setXMLEntity(XMLEntity xml) {
149
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
150
                setColor(StringUtilities.
151
                                string2Color(xml.getStringProperty("color")));
152
                setLineStyle((ILineStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null));
153
        }
154

    
155
        public void print(Graphics2D g, AffineTransform at, FShape shape)
156
                        throws DriverException {
157
                // TODO Implement it
158
                throw new Error("Not yet implemented!");
159

    
160
        }
161

    
162
        public void setWidth(double width) {
163
                getLineStyle().setLineWidth((float) width);
164
        }
165

    
166
        public double getWidth() {
167
                return getLineStyle().getLineWidth();
168
        }
169

    
170
}