svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.impl / src / test / java / org / gvsig / raster / lib / legend / impl / io / GimpGradientColorTableIOTest.java @ 43803
History | View | Annotate | Download (4.58 KB)
1 |
package org.gvsig.raster.lib.legend.impl.io; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.io.File; |
5 |
import java.io.IOException; |
6 |
import java.util.ArrayList; |
7 |
import java.util.List; |
8 |
|
9 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
10 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
11 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
12 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTableIO; |
13 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTableIOFactory; |
14 |
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
15 |
import org.gvsig.raster.lib.legend.api.exceptions.ColorTableIOException; |
16 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
17 |
|
18 |
/**
|
19 |
*
|
20 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
21 |
*
|
22 |
*/
|
23 |
public class GimpGradientColorTableIOTest extends AbstractLibraryAutoInitTestCase { |
24 |
|
25 |
private ColorTableIO colorTableIO;
|
26 |
|
27 |
@Override
|
28 |
protected void doSetUp() throws Exception { |
29 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
30 |
ColorTableIOFactory colorTableIOFactory = |
31 |
rasterLegendManager.getColorTableIOFactory(GimpGradientColorTableIO.NAME); |
32 |
colorTableIO = colorTableIOFactory.create(); |
33 |
} |
34 |
|
35 |
public void testReadFile() { |
36 |
|
37 |
File file =
|
38 |
new File(this.getClass().getClassLoader().getResource("colorTables/gimpGradient.ggr") |
39 |
.getFile()); |
40 |
|
41 |
ColorTable colorTable = null;
|
42 |
try {
|
43 |
colorTable = colorTableIO.read(file); |
44 |
} catch (ColorTableIOException e) {
|
45 |
fail("Can not read file to get Color table");
|
46 |
} |
47 |
|
48 |
assertEquals(100, colorTable.getClasses().size());
|
49 |
assertEquals(new Color(10, 5, 153), colorTable.getClasses().get(0).getColor()); |
50 |
assertEquals(new Color(8, 196, 244), colorTable.getClasses().get(50).getColor()); |
51 |
assertEquals(new Color(5, 154, 63), colorTable.getClasses().get(99).getColor()); |
52 |
} |
53 |
|
54 |
public void testReadColorTableFile() { |
55 |
|
56 |
File file =
|
57 |
new File(this.getClass().getClassLoader().getResource("colorTables/gimpGradient.ggr") |
58 |
.getFile()); |
59 |
|
60 |
ColorTable colorTable = RasterLegendLocator.getRasterLegendManager().createColorTable(); |
61 |
try {
|
62 |
colorTableIO.read(colorTable, file); |
63 |
} catch (ColorTableIOException e) {
|
64 |
fail("Can not read file to get Color table");
|
65 |
} |
66 |
|
67 |
assertEquals(100, colorTable.getClasses().size());
|
68 |
assertEquals(new Color(10, 5, 153), colorTable.getClasses().get(0).getColor()); |
69 |
assertEquals(new Color(8, 196, 244), colorTable.getClasses().get(50).getColor()); |
70 |
assertEquals(new Color(5, 154, 63), colorTable.getClasses().get(99).getColor()); |
71 |
} |
72 |
|
73 |
public void testWrite() { |
74 |
|
75 |
File file = null; |
76 |
try {
|
77 |
file = File.createTempFile("testGimpGradient", ".ggr"); |
78 |
} catch (IOException e) { |
79 |
fail("Can not create temp file");
|
80 |
} |
81 |
|
82 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
83 |
List<ColorTableClass> colorTableClasses = new ArrayList<ColorTableClass>(); |
84 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("0", 0, 50, Color.BLACK)); |
85 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("1", 20, 50, Color.CYAN)); |
86 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("2", 40, 50, Color.RED)); |
87 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("3", 60, 50, Color.BLUE)); |
88 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("4", 80, 50, Color.WHITE)); |
89 |
colorTableClasses.add(rasterLegendManager.createColorTableClass("5", 100, 50, Color.GRAY)); |
90 |
|
91 |
ColorTable colorTable = |
92 |
rasterLegendManager.createColorTable("testColorTable", colorTableClasses, false); |
93 |
|
94 |
try {
|
95 |
colorTableIO.write(colorTable, file); |
96 |
colorTableIO.read(colorTable, file); |
97 |
} catch (ColorTableIOException e) {
|
98 |
fail("Can not read file to get Color table");
|
99 |
} |
100 |
|
101 |
assertEquals(6, colorTable.getClasses().size());
|
102 |
assertEquals(Color.BLACK, colorTable.getClasses().get(0).getColor()); |
103 |
assertEquals(Color.CYAN, colorTable.getClasses().get(1).getColor()); |
104 |
assertEquals(Color.RED, colorTable.getClasses().get(2).getColor()); |
105 |
assertEquals(Color.BLUE, colorTable.getClasses().get(3).getColor()); |
106 |
assertEquals(Color.WHITE, colorTable.getClasses().get(4).getColor()); |
107 |
assertEquals(Color.GRAY, colorTable.getClasses().get(5).getColor()); |
108 |
} |
109 |
|
110 |
} |