Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / styles / SimpleLineStyle.java @ 10679

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

    
65
import java.awt.BasicStroke;
66
import java.awt.Color;
67
import java.awt.Graphics2D;
68
import java.awt.Rectangle;
69
import java.awt.Stroke;
70

    
71
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
72
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
73
import com.iver.utiles.XMLEntity;
74

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

    
93

    
94

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

    
104

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

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

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

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

    
131
        public String getClassName() {
132
                return getClass().getName();
133
        }
134

    
135
        public XMLEntity getXMLEntity() {
136
                XMLEntity xml = new XMLEntity();
137
                xml.putProperty("className", getClassName());
138
                xml.putProperty("desc", getDescription());
139

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

    
149
                }
150
                xml.putProperty("lineWidth", lineWidth);
151
                xml.putProperty("dashPhase", dashPhase);
152
                xml.putProperty("endCap", endCap);
153
                xml.putProperty("lineJoin", lineJoin);
154
                xml.putProperty("miterLimit", miterlimit);
155
                return xml;
156
        }
157

    
158
        public void setXMLEntity(XMLEntity xml) {
159

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

    
175
        public Stroke getStroke() {
176
                return new BasicStroke(lineWidth, endCap, lineJoin, miterlimit, dashArray, dashPhase);
177
        }
178

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

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

    
195
        public boolean isSuitableFor(ISymbol symbol) {
196
                return symbol instanceof ILineSymbol;
197
        }
198

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

    
210

    
211
}