root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / ColorRamp.java @ 1853
History | View | Annotate | Download (4.58 KB)
1 | 1100 | fjp | /* 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 | 230 | fernando | package com.iver.cit.gvsig.fmap.rendering; |
42 | |||
43 | 458 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
44 | 435 | vcaballero | import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
45 | 230 | fernando | |
46 | 435 | vcaballero | import com.iver.utiles.StringUtilities; |
47 | import com.iver.utiles.XMLEntity; |
||
48 | 298 | vcaballero | |
49 | 435 | vcaballero | import java.awt.Color; |
50 | 322 | fernando | |
51 | |||
52 | 298 | vcaballero | /**
|
53 | 1034 | vcaballero | * Rampa de colores para el dibujado de Raster.
|
54 | 298 | vcaballero | *
|
55 | * @author Vicente Caballero Navarro
|
||
56 | */
|
||
57 | 435 | vcaballero | public class ColorRamp implements RasterLegend { |
58 | 1034 | vcaballero | private Color firstColor; |
59 | private Color lastColor; |
||
60 | private double first; |
||
61 | private double last; |
||
62 | 298 | vcaballero | |
63 | 1034 | vcaballero | /**
|
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 | 230 | fernando | |
74 | 1034 | vcaballero | /**
|
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 | 233 | fernando | |
85 | 1034 | vcaballero | /**
|
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 | 298 | vcaballero | |
97 | 1034 | vcaballero | int lr = lastColor.getRed();
|
98 | int lg = lastColor.getGreen();
|
||
99 | int lb = lastColor.getBlue();
|
||
100 | 298 | vcaballero | |
101 | 1034 | vcaballero | double total = last - first;
|
102 | double tr = lr - fr;
|
||
103 | double tg = lg - fg;
|
||
104 | double tb = lb - fb;
|
||
105 | 298 | vcaballero | |
106 | 1034 | vcaballero | 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 | 298 | vcaballero | |
111 | 1034 | vcaballero | return new Color(r, g, b); |
112 | } |
||
113 | 322 | fernando | |
114 | 1034 | vcaballero | /**
|
115 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
||
116 | */
|
||
117 | public String[] getDescriptions() { |
||
118 | return null; |
||
119 | } |
||
120 | 322 | fernando | |
121 | 1034 | vcaballero | /**
|
122 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getSymbols()
|
||
123 | */
|
||
124 | public FSymbol[] getSymbols() { |
||
125 | return null; |
||
126 | } |
||
127 | 322 | fernando | |
128 | 1034 | vcaballero | /**
|
129 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
|
||
130 | */
|
||
131 | public Object[] getValues() { |
||
132 | return null; |
||
133 | } |
||
134 | 322 | fernando | |
135 | 1034 | vcaballero | /**
|
136 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
||
137 | */
|
||
138 | public FSymbol getDefaultSymbol() {
|
||
139 | return null; |
||
140 | } |
||
141 | 322 | fernando | |
142 | 1034 | vcaballero | /**
|
143 | * @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#getSymbol(double)
|
||
144 | */
|
||
145 | public FStyle2D getSymbol(double d) { |
||
146 | return null; |
||
147 | } |
||
148 | 322 | fernando | |
149 | 1034 | vcaballero | /**
|
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 | 435 | vcaballero | |
155 | 1034 | vcaballero | /**
|
156 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
||
157 | */
|
||
158 | public XMLEntity getXMLEntity() {
|
||
159 | XMLEntity xml = new XMLEntity();
|
||
160 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
161 | 1034 | vcaballero | xml.putProperty("first", first);
|
162 | xml.putProperty("firstColor", StringUtilities.color2String(firstColor));
|
||
163 | xml.putProperty("last", last);
|
||
164 | xml.putProperty("lastColor", StringUtilities.color2String(lastColor));
|
||
165 | 435 | vcaballero | |
166 | 1034 | vcaballero | return xml;
|
167 | } |
||
168 | 435 | vcaballero | |
169 | 1034 | vcaballero | /**
|
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 | 435 | vcaballero | |
185 | 1034 | vcaballero | return cr;
|
186 | } |
||
187 | 435 | vcaballero | |
188 | 1034 | vcaballero | /**
|
189 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
||
190 | */
|
||
191 | public Legend cloneLegend() {
|
||
192 | return createFromXML(getXMLEntity());
|
||
193 | } |
||
194 | 230 | fernando | } |