root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / ColorRamp.java @ 1100
History | View | Annotate | Download (4.58 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.cit.gvsig.fmap.rendering; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
44 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
45 |
|
46 |
import com.iver.utiles.StringUtilities; |
47 |
import com.iver.utiles.XMLEntity; |
48 |
|
49 |
import java.awt.Color; |
50 |
|
51 |
|
52 |
/**
|
53 |
* Rampa de colores para el dibujado de Raster.
|
54 |
*
|
55 |
* @author Vicente Caballero Navarro
|
56 |
*/
|
57 |
public class ColorRamp implements RasterLegend { |
58 |
private Color firstColor; |
59 |
private Color lastColor; |
60 |
private double first; |
61 |
private double last; |
62 |
|
63 |
/**
|
64 |
* Inserta el n?mero inicial y el color inicial.
|
65 |
*
|
66 |
* @param d N?mero inicial.
|
67 |
* @param c Color inicial.
|
68 |
*/
|
69 |
public void setFirstPoint(double d, Color c) { |
70 |
firstColor = c; |
71 |
first = d; |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Inserta el N?mero fianl y el color final.
|
76 |
*
|
77 |
* @param d N?mero final.
|
78 |
* @param c Color final.
|
79 |
*/
|
80 |
public void setLastPoint(double d, Color c) { |
81 |
lastColor = c; |
82 |
last = d; |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Devuelve el color a partir del n?mero.
|
87 |
*
|
88 |
* @param d N?mero.
|
89 |
*
|
90 |
* @return Color.
|
91 |
*/
|
92 |
public Color getColor(double d) { |
93 |
int fr = firstColor.getRed();
|
94 |
int fg = firstColor.getGreen();
|
95 |
int fb = firstColor.getBlue();
|
96 |
|
97 |
int lr = lastColor.getRed();
|
98 |
int lg = lastColor.getGreen();
|
99 |
int lb = lastColor.getBlue();
|
100 |
|
101 |
double total = last - first;
|
102 |
double tr = lr - fr;
|
103 |
double tg = lg - fg;
|
104 |
double tb = lb - fb;
|
105 |
|
106 |
double por = (d - first) / total;
|
107 |
int r = (int) ((por * tr) + fr); |
108 |
int g = (int) ((por * tg) + fg); |
109 |
int b = (int) ((por * tb) + fb); |
110 |
|
111 |
return new Color(r, g, b); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
116 |
*/
|
117 |
public String[] getDescriptions() { |
118 |
return null; |
119 |
} |
120 |
|
121 |
/**
|
122 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getSymbols()
|
123 |
*/
|
124 |
public FSymbol[] getSymbols() { |
125 |
return null; |
126 |
} |
127 |
|
128 |
/**
|
129 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
|
130 |
*/
|
131 |
public Object[] getValues() { |
132 |
return null; |
133 |
} |
134 |
|
135 |
/**
|
136 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
137 |
*/
|
138 |
public FSymbol getDefaultSymbol() {
|
139 |
return null; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#getSymbol(double)
|
144 |
*/
|
145 |
public FStyle2D getSymbol(double d) { |
146 |
return null; |
147 |
} |
148 |
|
149 |
/**
|
150 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#setDefaultSymbol(com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
|
151 |
*/
|
152 |
public void setDefaultSymbol(FStyle2D s) { |
153 |
} |
154 |
|
155 |
/**
|
156 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
157 |
*/
|
158 |
public XMLEntity getXMLEntity() {
|
159 |
XMLEntity xml = new XMLEntity();
|
160 |
xml.putProperty("className",this.getClass().getName()); |
161 |
xml.putProperty("first", first);
|
162 |
xml.putProperty("firstColor", StringUtilities.color2String(firstColor));
|
163 |
xml.putProperty("last", last);
|
164 |
xml.putProperty("lastColor", StringUtilities.color2String(lastColor));
|
165 |
|
166 |
return xml;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Crea un ColorRamp a partir del XMLEntity.
|
171 |
*
|
172 |
* @param xml XMLEntity.
|
173 |
*
|
174 |
* @return Nuevo ColorRamp.
|
175 |
*/
|
176 |
public static ColorRamp createFromXML(XMLEntity xml) { |
177 |
ColorRamp cr = new ColorRamp();
|
178 |
cr.first = xml.getDoubleProperty("first");
|
179 |
cr.firstColor = StringUtilities.string2Color(xml.getStringProperty( |
180 |
"fistColor"));
|
181 |
cr.last = xml.getDoubleProperty("last");
|
182 |
cr.lastColor = StringUtilities.string2Color(xml.getStringProperty( |
183 |
"lastColor"));
|
184 |
|
185 |
return cr;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
190 |
*/
|
191 |
public Legend cloneLegend() {
|
192 |
return createFromXML(getXMLEntity());
|
193 |
} |
194 |
} |