Revision 6897 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/main/java/org/gvsig/raster/lib/legend/impl/DefaultRasterLegendManager.java
DefaultRasterLegendManager.java | ||
---|---|---|
19 | 19 |
import org.gvsig.raster.lib.legend.api.Transparency; |
20 | 20 |
import org.gvsig.raster.lib.legend.api.TransparencyRange; |
21 | 21 |
import org.gvsig.raster.lib.legend.impl.io.gvSIGColorTableIO; |
22 |
|
|
23 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
|
24 |
import org.apache.commons.lang3.tuple.Pair; |
|
22 | 25 |
import org.slf4j.Logger; |
23 | 26 |
import org.slf4j.LoggerFactory; |
24 | 27 |
|
... | ... | |
52 | 55 |
} |
53 | 56 |
|
54 | 57 |
@Override |
55 |
public List<ColorTable> getColorTables(File folder) {
|
|
58 |
public List<Pair<File, ColorTable>> getColorTables(File folder) {
|
|
56 | 59 |
|
57 | 60 |
if (folder.isFile()) { |
58 | 61 |
throw new IllegalArgumentException("File object has to be a directory"); |
... | ... | |
63 | 66 |
"It is necessary read permissions to get files and load color tables"); |
64 | 67 |
} |
65 | 68 |
|
66 |
List<ColorTable> colorTables = new ArrayList<ColorTable>();
|
|
69 |
List<Pair<File, ColorTable>> colorTables = new ArrayList<Pair<File, ColorTable>>();
|
|
67 | 70 |
for (File file : listFilesForFolder(folder)) { |
68 | 71 |
|
69 | 72 |
Collection<ColorTableIOFactory> factories = this.colorTableIOFactories.values(); |
... | ... | |
73 | 76 |
ColorTableIO colorTableIO = colorTableIOFactory.create(); |
74 | 77 |
try{ |
75 | 78 |
ColorTable colorTable = colorTableIO.read(file); |
76 |
colorTables.add(colorTable);
|
|
79 |
colorTables.add(new ImmutablePair<File, ColorTable>(file,colorTable));
|
|
77 | 80 |
break; |
78 | 81 |
} catch (Exception e){ |
79 | 82 |
// Log warn but continue reading files. |
... | ... | |
112 | 115 |
} |
113 | 116 |
|
114 | 117 |
@Override |
118 |
public List<ColorTableClass> createListColorTableClasses(double minimum, double maximum, int intervals, Color fromColor, Color toColor){ |
|
119 |
double intervalSize = (maximum-minimum)/intervals; |
|
120 |
return createListColorTableClasses(minimum, maximum, intervalSize, fromColor, toColor); |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public List<ColorTableClass> createListColorTableClasses(double minimum, double maximum, double intervalSize, Color fromColor, Color toColor){ |
|
126 |
List<ColorTableClass> colorTableClasses = new ArrayList<ColorTableClass>(); |
|
127 |
|
|
128 |
int counter = 0; |
|
129 |
double value = minimum; |
|
130 |
|
|
131 |
Color color = fromColor; |
|
132 |
while(value<maximum){ |
|
133 |
double proportion = (value-minimum)/(maximum-minimum); |
|
134 |
color = getInterpolatedColor(fromColor, toColor, proportion); |
|
135 |
ColorTableClass colorTableClass = this.createColorTableClass(new Integer(counter).toString(), value, 50.0, color); |
|
136 |
colorTableClasses.add(colorTableClass); |
|
137 |
value = value + intervalSize; |
|
138 |
counter++; |
|
139 |
} |
|
140 |
value = maximum; |
|
141 |
ColorTableClass colorTableClass = this.createColorTableClass(new Integer(counter).toString(), value, 50.0, toColor); |
|
142 |
colorTableClasses.add(colorTableClass); |
|
143 |
|
|
144 |
return colorTableClasses; |
|
145 |
} |
|
146 |
|
|
147 |
private Color getInterpolatedColor(Color fromColor, Color toColor, double proportion){ |
|
148 |
int red = fromColor.getRed(); |
|
149 |
int green = fromColor.getGreen(); |
|
150 |
int blue = fromColor.getBlue(); |
|
151 |
int alpha = fromColor.getAlpha(); |
|
152 |
|
|
153 |
int rangeRed = toColor.getRed()-fromColor.getRed(); |
|
154 |
red = (int)Math.round(fromColor.getRed()+(rangeRed*proportion)); |
|
155 |
|
|
156 |
int rangeGreen = toColor.getGreen()-fromColor.getGreen(); |
|
157 |
green = (int)Math.round(fromColor.getGreen()+(rangeGreen*proportion)); |
|
158 |
|
|
159 |
int rangeBlue = toColor.getBlue()-fromColor.getBlue(); |
|
160 |
blue = (int)Math.round(fromColor.getBlue()+(rangeBlue*proportion)); |
|
161 |
|
|
162 |
int rangeAlpha = toColor.getAlpha()-fromColor.getAlpha(); |
|
163 |
alpha = (int)Math.round(fromColor.getAlpha()+(rangeAlpha*proportion)); |
|
164 |
|
|
165 |
return new Color(red, green, blue, alpha); |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
115 | 169 |
public ColorTableIO getColorTableIO() { |
116 | 170 |
ColorTableIOFactory defaultFactory = this.colorTableIOFactories.get(gvSIGColorTableIO.NAME); |
117 | 171 |
if (defaultFactory == null) { |
Also available in: Unified diff