Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / Paleta.java @ 28

History | View | Annotate | Download (2.21 KB)

1
/*
2
 * Created on 04-may-2004
3
 */
4
package org.cresques.px;
5

    
6
import java.awt.Color;
7
import java.io.BufferedReader;
8
import java.io.FileReader;
9
import java.io.IOException;
10

    
11
import org.cresques.io.GeoFile;
12

    
13
/**
14
 * Paleta de color (en principio para MDT
15
 * 
16
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
17
 */
18

    
19
public class Paleta {
20
        public String fName = null;
21
        String name = null;
22
        public Color [] color = null;
23
        boolean enPaleta = false;
24
        
25
        /**
26
         * Lee una paleta desde un .lut de ArcView
27
         * 
28
         * @param fName
29
         */
30

    
31
        public void loadLut(String fName) throws IOException {
32
                BufferedReader fi;
33
                String buf;
34
                int l = 0;
35
                if (fName == null)
36
                        fName = "C:/ESRI/AV_GIS30/ARCVIEW/averm/LUT/elevation.lut";
37
                this.fName = fName;
38
                fi = new BufferedReader(new FileReader(fName));
39
                while ((buf = fi.readLine()) != null) {
40
                        //System.out.println(buf);
41
                        l++;
42
                        parseLine(buf);
43
                }
44
                fi.close();
45

    
46
                //setColorFromLut("          0     0 19200 65280");
47
        }
48
        
49
        private void parseLine(String buf) {
50
                //LookUpTable Begin
51
                //        Version         = "1.0"
52
                //        Name            = "elevation"
53
                //        Description     = "one of several std color schemes for color coding elevation data"
54
                //        NrEntries       = 256
55
                //        LUT             = {
56
                //          0     0 19200 65280
57
                // ...
58
                //        }
59
                //LookUpTable End
60
                buf = GeoFile.filterWS(buf);
61
                String [] datos = buf.split(" ");
62
                System.out.println(buf);
63
                if (enPaleta) {
64
                        if (buf.length()>4) {
65
                                int nr = Integer.parseInt(datos[0].trim());
66
                                int r = Integer.parseInt(datos[1].trim());
67
                                int g = Integer.parseInt(datos[2].trim());
68
                                int b = Integer.parseInt(datos[3].trim());
69
                                setColorFromLut(nr, r, g, b);
70
                        } else
71
                                enPaleta = false;
72
                } else if (buf.length() > 4) {
73
                        if (buf.substring(0,3).compareTo("LUT") == 0) {
74
                                enPaleta = true;
75
                        } else if (buf.substring(0,3).compareTo("NrE") == 0) {
76
                                int numC = Integer.parseInt(datos[2].trim());
77
                                color = new Color[numC];
78
                                System.out.println("hay "+ numC + " colores.");         
79
                        }
80
                }
81
        }
82
        
83
        private void setColorFromLut(int nr, int r, int g, int b) {
84
                //"          0     0 19200 65280"
85
                color[nr] = new Color(r/256, g/256, b/256);
86
                //System.out.println(nr+":["+l.substring(5,10)+","+l.substring(11,16)+","+l.substring(17)+"]");         
87
                System.out.println(nr+":"+color[nr]);         
88
        }
89
}