Revision 1034 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/ColorRamp.java
ColorRamp.java | ||
---|---|---|
1 |
/* Generated by Together */ |
|
2 | 1 |
package com.iver.cit.gvsig.fmap.rendering; |
3 | 2 |
|
4 | 3 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
... | ... | |
11 | 10 |
|
12 | 11 |
|
13 | 12 |
/** |
14 |
* Rampa de colores para el dibujado de Raster's
|
|
13 |
* Rampa de colores para el dibujado de Raster.
|
|
15 | 14 |
* |
16 | 15 |
* @author Vicente Caballero Navarro |
17 | 16 |
*/ |
18 | 17 |
public class ColorRamp implements RasterLegend { |
19 |
private Color firstColor;
|
|
20 |
private Color lastColor;
|
|
21 |
private double first;
|
|
22 |
private double last;
|
|
18 |
private Color firstColor;
|
|
19 |
private Color lastColor;
|
|
20 |
private double first;
|
|
21 |
private double last;
|
|
23 | 22 |
|
24 |
/**
|
|
25 |
* DOCUMENT ME!
|
|
26 |
*
|
|
27 |
* @param d DOCUMENT ME!
|
|
28 |
* @param c DOCUMENT ME!
|
|
29 |
*/
|
|
30 |
public void setFirstPoint(double d, Color c) {
|
|
31 |
firstColor = c;
|
|
32 |
first = d;
|
|
33 |
}
|
|
23 |
/**
|
|
24 |
* Inserta el n?mero inicial y el color inicial.
|
|
25 |
*
|
|
26 |
* @param d N?mero inicial.
|
|
27 |
* @param c Color inicial.
|
|
28 |
*/
|
|
29 |
public void setFirstPoint(double d, Color c) {
|
|
30 |
firstColor = c;
|
|
31 |
first = d;
|
|
32 |
}
|
|
34 | 33 |
|
35 |
/**
|
|
36 |
* DOCUMENT ME!
|
|
37 |
*
|
|
38 |
* @param d DOCUMENT ME!
|
|
39 |
* @param c DOCUMENT ME!
|
|
40 |
*/
|
|
41 |
public void setLastPoint(double d, Color c) {
|
|
42 |
lastColor = c;
|
|
43 |
last = d;
|
|
44 |
}
|
|
34 |
/**
|
|
35 |
* Inserta el N?mero fianl y el color final.
|
|
36 |
*
|
|
37 |
* @param d N?mero final.
|
|
38 |
* @param c Color final.
|
|
39 |
*/
|
|
40 |
public void setLastPoint(double d, Color c) {
|
|
41 |
lastColor = c;
|
|
42 |
last = d;
|
|
43 |
}
|
|
45 | 44 |
|
46 |
/**
|
|
47 |
* DOCUMENT ME!
|
|
48 |
*
|
|
49 |
* @param d DOCUMENT ME!
|
|
50 |
*
|
|
51 |
* @return DOCUMENT ME!
|
|
52 |
*/
|
|
53 |
public Color getColor(double d) {
|
|
54 |
int fr = firstColor.getRed();
|
|
55 |
int fg = firstColor.getGreen();
|
|
56 |
int fb = firstColor.getBlue();
|
|
45 |
/**
|
|
46 |
* Devuelve el color a partir del n?mero.
|
|
47 |
*
|
|
48 |
* @param d N?mero.
|
|
49 |
*
|
|
50 |
* @return Color.
|
|
51 |
*/
|
|
52 |
public Color getColor(double d) {
|
|
53 |
int fr = firstColor.getRed();
|
|
54 |
int fg = firstColor.getGreen();
|
|
55 |
int fb = firstColor.getBlue();
|
|
57 | 56 |
|
58 |
int lr = lastColor.getRed();
|
|
59 |
int lg = lastColor.getGreen();
|
|
60 |
int lb = lastColor.getBlue();
|
|
57 |
int lr = lastColor.getRed();
|
|
58 |
int lg = lastColor.getGreen();
|
|
59 |
int lb = lastColor.getBlue();
|
|
61 | 60 |
|
62 |
double total = last - first;
|
|
63 |
double tr = lr - fr;
|
|
64 |
double tg = lg - fg;
|
|
65 |
double tb = lb - fb;
|
|
61 |
double total = last - first;
|
|
62 |
double tr = lr - fr;
|
|
63 |
double tg = lg - fg;
|
|
64 |
double tb = lb - fb;
|
|
66 | 65 |
|
67 |
double por = (d - first) / total;
|
|
68 |
int r = (int) ((por * tr) + fr);
|
|
69 |
int g = (int) ((por * tg) + fg);
|
|
70 |
int b = (int) ((por * tb) + fb);
|
|
66 |
double por = (d - first) / total;
|
|
67 |
int r = (int) ((por * tr) + fr);
|
|
68 |
int g = (int) ((por * tg) + fg);
|
|
69 |
int b = (int) ((por * tb) + fb);
|
|
71 | 70 |
|
72 |
return new Color(r, g, b);
|
|
73 |
}
|
|
71 |
return new Color(r, g, b);
|
|
72 |
}
|
|
74 | 73 |
|
75 |
/**
|
|
76 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
|
77 |
*/
|
|
78 |
public String[] getDescriptions() {
|
|
79 |
return null;
|
|
80 |
}
|
|
74 |
/**
|
|
75 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
|
76 |
*/
|
|
77 |
public String[] getDescriptions() {
|
|
78 |
return null;
|
|
79 |
}
|
|
81 | 80 |
|
82 |
/**
|
|
83 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getSymbols()
|
|
84 |
*/
|
|
85 |
public FSymbol[] getSymbols() {
|
|
86 |
return null;
|
|
87 |
}
|
|
81 |
/**
|
|
82 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getSymbols()
|
|
83 |
*/
|
|
84 |
public FSymbol[] getSymbols() {
|
|
85 |
return null;
|
|
86 |
}
|
|
88 | 87 |
|
89 |
/**
|
|
90 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
|
|
91 |
*/
|
|
92 |
public Object[] getValues() {
|
|
93 |
return null;
|
|
94 |
}
|
|
88 |
/**
|
|
89 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
|
|
90 |
*/
|
|
91 |
public Object[] getValues() {
|
|
92 |
return null;
|
|
93 |
}
|
|
95 | 94 |
|
96 |
/**
|
|
97 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
|
98 |
*/
|
|
99 |
public FSymbol getDefaultSymbol() {
|
|
100 |
return null;
|
|
101 |
}
|
|
95 |
/**
|
|
96 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
|
97 |
*/
|
|
98 |
public FSymbol getDefaultSymbol() {
|
|
99 |
return null;
|
|
100 |
}
|
|
102 | 101 |
|
103 |
/**
|
|
104 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#getSymbol(double)
|
|
105 |
*/
|
|
106 |
public FStyle2D getSymbol(double d) {
|
|
107 |
return null;
|
|
108 |
}
|
|
102 |
/**
|
|
103 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#getSymbol(double)
|
|
104 |
*/
|
|
105 |
public FStyle2D getSymbol(double d) {
|
|
106 |
return null;
|
|
107 |
}
|
|
109 | 108 |
|
110 |
/**
|
|
111 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#setDefaultSymbol(com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
|
|
112 |
*/
|
|
113 |
public void setDefaultSymbol(FStyle2D s) {
|
|
114 |
}
|
|
109 |
/**
|
|
110 |
* @see com.iver.cit.gvsig.fmap.rendering.RasterLegend#setDefaultSymbol(com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
|
|
111 |
*/
|
|
112 |
public void setDefaultSymbol(FStyle2D s) {
|
|
113 |
}
|
|
115 | 114 |
|
116 |
/**
|
|
117 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
|
118 |
*/
|
|
119 |
public XMLEntity getXMLEntity() {
|
|
120 |
XMLEntity xml = new XMLEntity();
|
|
121 |
xml.putProperty("first", first);
|
|
122 |
xml.putProperty("firstColor", StringUtilities.color2String(firstColor));
|
|
123 |
xml.putProperty("last", last);
|
|
124 |
xml.putProperty("lastColor", StringUtilities.color2String(lastColor));
|
|
115 |
/**
|
|
116 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
|
117 |
*/
|
|
118 |
public XMLEntity getXMLEntity() {
|
|
119 |
XMLEntity xml = new XMLEntity();
|
|
120 |
xml.putProperty("first", first);
|
|
121 |
xml.putProperty("firstColor", StringUtilities.color2String(firstColor));
|
|
122 |
xml.putProperty("last", last);
|
|
123 |
xml.putProperty("lastColor", StringUtilities.color2String(lastColor));
|
|
125 | 124 |
|
126 |
return xml;
|
|
127 |
}
|
|
125 |
return xml;
|
|
126 |
}
|
|
128 | 127 |
|
129 |
/**
|
|
130 |
* DOCUMENT ME!
|
|
131 |
*
|
|
132 |
* @param xml DOCUMENT ME!
|
|
133 |
*
|
|
134 |
* @return DOCUMENT ME!
|
|
135 |
*/
|
|
136 |
public static ColorRamp createFromXML(XMLEntity xml) {
|
|
137 |
ColorRamp cr = new ColorRamp();
|
|
138 |
cr.first = xml.getDoubleProperty("first");
|
|
139 |
cr.firstColor = StringUtilities.string2Color(xml.getStringProperty(
|
|
140 |
"fistColor"));
|
|
141 |
cr.last = xml.getDoubleProperty("last");
|
|
142 |
cr.lastColor = StringUtilities.string2Color(xml.getStringProperty(
|
|
143 |
"lastColor"));
|
|
128 |
/**
|
|
129 |
* Crea un ColorRamp a partir del XMLEntity.
|
|
130 |
*
|
|
131 |
* @param xml XMLEntity.
|
|
132 |
*
|
|
133 |
* @return Nuevo ColorRamp.
|
|
134 |
*/
|
|
135 |
public static ColorRamp createFromXML(XMLEntity xml) {
|
|
136 |
ColorRamp cr = new ColorRamp();
|
|
137 |
cr.first = xml.getDoubleProperty("first");
|
|
138 |
cr.firstColor = StringUtilities.string2Color(xml.getStringProperty(
|
|
139 |
"fistColor"));
|
|
140 |
cr.last = xml.getDoubleProperty("last");
|
|
141 |
cr.lastColor = StringUtilities.string2Color(xml.getStringProperty(
|
|
142 |
"lastColor"));
|
|
144 | 143 |
|
145 |
return cr;
|
|
146 |
}
|
|
144 |
return cr;
|
|
145 |
}
|
|
147 | 146 |
|
148 |
/**
|
|
149 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
|
150 |
*/
|
|
151 |
public Legend cloneLegend() {
|
|
152 |
return createFromXML(getXMLEntity());
|
|
153 |
}
|
|
147 |
/**
|
|
148 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
|
149 |
*/
|
|
150 |
public Legend cloneLegend() {
|
|
151 |
return createFromXML(getXMLEntity());
|
|
152 |
}
|
|
154 | 153 |
} |
Also available in: Unified diff