Statistics
| Revision:

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

History | View | Annotate | Download (5.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: SimpleLineStyle.java 10436 2007-02-21 07:34:09Z jaume $
45
* $Log$
46
* Revision 1.1.2.4  2007-02-21 07:34:09  jaume
47
* labeling starts working
48
*
49
* Revision 1.1.2.3  2007/02/15 16:23:44  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1.2.2  2007/02/12 15:15:20  jaume
53
* refactored interval legend and added graduated symbol legend
54
*
55
* Revision 1.1.2.1  2007/02/09 07:47:04  jaume
56
* Isymbol moved
57
*
58
*
59
*/
60
package com.iver.cit.gvsig.fmap.core.styles;
61

    
62
import java.awt.BasicStroke;
63
import java.awt.Color;
64
import java.awt.Graphics2D;
65
import java.awt.Rectangle;
66
import java.awt.Stroke;
67

    
68
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
69
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
70
import com.iver.utiles.XMLEntity;
71

    
72
/**
73
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
74
 */
75
public class SimpleLineStyle extends AbstractStyle implements ILineStyle {
76
        private final static Color PREVIEW_COLOR_1= new Color(150, 255, 200); //light blue
77
        private final static Color PREVIEW_COLOR_2 = new Color(255, 200, 100); //orange
78
        private final static int COLOR1_STROKE = 1;
79
        private final static int COLOR2_STROKE = 3;
80
        private float[] dashArray;
81
        private float dashPhase;
82
        private int endCap;
83
        private int lineJoin;
84
        private float miterlimit;
85
        /**
86
         * @uml.property  name="lineWidth"
87
         */
88
        private float lineWidth;
89

    
90

    
91

    
92
        public SimpleLineStyle() {
93
                BasicStroke dummy = new BasicStroke();
94
                dashArray = dummy.getDashArray();
95
                dashPhase = dummy.getDashPhase();
96
                endCap = dummy.getEndCap();
97
                lineJoin = dummy.getLineJoin();
98
                miterlimit = dummy.getMiterLimit();
99
        }
100

    
101

    
102
        public SimpleLineStyle(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) {
103
                this.lineWidth = width;
104
                this.endCap = cap;
105
                this.lineJoin = join;
106
                this.miterlimit = miterlimit;
107
                this.dashArray = dash;
108
                this.dashPhase = dash_phase;
109
        }
110

    
111
        public void drawInsideRectangle(Graphics2D g, Rectangle r) {
112
                Stroke oldStroke = g.getStroke();
113
                int h = (int) (r.getHeight() / 2);
114
                int margins = 2;
115

    
116
                BasicStroke stroke;
117
                stroke = new BasicStroke(COLOR1_STROKE, endCap, lineJoin, miterlimit, dashArray, dashPhase);
118
                g.setStroke(stroke);
119
                g.setColor(PREVIEW_COLOR_1);
120
                g.drawLine(margins, h, r.width-margins-margins, h);
121

    
122
                stroke = new BasicStroke(COLOR2_STROKE, endCap, lineJoin, miterlimit, dashArray, dashPhase);                g.setStroke(stroke);
123
                g.setColor(PREVIEW_COLOR_2);
124
                g.drawLine(margins, h, r.width-margins-margins, h);
125
                g.setStroke(oldStroke);
126
        }
127

    
128
        public String getClassName() {
129
                return getClass().getName();
130
        }
131

    
132
        public XMLEntity getXMLEntity() {
133
                XMLEntity xml = new XMLEntity();
134
                xml.putProperty("className", getClassName());
135
                xml.putProperty("desc", getDescription());
136

    
137
                if (dashArray != null) {
138
                        StringBuffer sb = new StringBuffer();
139
                        for (int i = 0; i < dashArray.length; i++) {
140
                                sb.append(dashArray[i]);
141
                                if (i< dashArray.length)
142
                                        sb.append(",");
143
                        }
144
                        xml.putProperty("dashArray", sb.toString());
145

    
146
                }
147
                xml.putProperty("lineWidth", lineWidth);
148
                xml.putProperty("dashPhase", dashPhase);
149
                xml.putProperty("endCap", endCap);
150
                xml.putProperty("lineJoin", lineJoin);
151
                xml.putProperty("miterLimit", miterlimit);
152
                return xml;
153
        }
154

    
155
        public void setXMLEntity(XMLEntity xml) {
156

    
157
                setDescription(xml.getStringProperty("desc"));
158
                if (xml.contains("dashArray")) {
159
                        String[] dashProp = xml.getStringProperty("dashArray").split(",");
160
                        dashArray = new float[dashProp.length];
161
                        for (int i = 0; i < dashProp.length; i++) {
162
                                dashArray[i] = Float.parseFloat(dashProp[i]);
163
                        }
164
                }
165
                lineWidth = xml.getFloatProperty("lineWidth");
166
                dashPhase = xml.getFloatProperty("dashPhase");
167
                endCap = xml.getIntProperty("endCap");
168
                lineJoin = xml.getIntProperty("lineJoin");
169
                miterlimit = xml.getFloatProperty("miterLimit");
170
        }
171

    
172
        public Stroke getStroke() {
173
                return new BasicStroke(lineWidth, endCap, lineJoin, miterlimit, dashArray, dashPhase);
174
        }
175

    
176
        /**
177
         * @return
178
         * @uml.property  name="lineWidth"
179
         */
180
        public float getLineWidth() {
181
                return lineWidth;
182
        }
183

    
184
        /**
185
         * @param width
186
         * @uml.property  name="lineWidth"
187
         */
188
        public void setLineWidth(float width) {
189
                this.lineWidth = width;
190
        }
191

    
192
        public boolean isSuitableFor(ISymbol symbol) {
193
                return symbol instanceof ILineSymbol;
194
        }
195

    
196
        public void setStroke(Stroke stroke) {
197
                if (stroke != null) {
198
                        BasicStroke dummy = (BasicStroke) stroke;
199
                        dashArray = dummy.getDashArray();
200
                        dashPhase = dummy.getDashPhase();
201
                        endCap = dummy.getEndCap();
202
                        lineJoin = dummy.getLineJoin();
203
                        miterlimit = dummy.getMiterLimit();
204
                }
205
        }
206

    
207

    
208
}