Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / Paleta.java @ 2312

History | View | Annotate | Download (3.05 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.px;
25

    
26
import java.awt.Color;
27
import java.io.BufferedReader;
28
import java.io.FileReader;
29
import java.io.IOException;
30

    
31
import org.cresques.io.GeoFile;
32

    
33
/**
34
 * Paleta de color (en principio para MDT
35
 * 
36
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
37
 */
38

    
39
public class Paleta {
40
        public String fName = null;
41
        String name = null;
42
        public Color [] color = null;
43
        boolean enPaleta = false;
44
        
45
        /**
46
         * Lee una paleta desde un .lut de ArcView
47
         * 
48
         * @param fName
49
         */
50

    
51
        public void loadLut(String fName) throws IOException {
52
                BufferedReader fi;
53
                String buf;
54
                int l = 0;
55
                if (fName == null)
56
                        fName = "C:/ESRI/AV_GIS30/ARCVIEW/averm/LUT/elevation.lut";
57
                this.fName = fName;
58
                fi = new BufferedReader(new FileReader(fName));
59
                while ((buf = fi.readLine()) != null) {
60
                        //System.out.println(buf);
61
                        l++;
62
                        parseLine(buf);
63
                }
64
                fi.close();
65

    
66
                //setColorFromLut("          0     0 19200 65280");
67
        }
68
        
69
        private void parseLine(String buf) {
70
                //LookUpTable Begin
71
                //        Version         = "1.0"
72
                //        Name            = "elevation"
73
                //        Description     = "one of several std color schemes for color coding elevation data"
74
                //        NrEntries       = 256
75
                //        LUT             = {
76
                //          0     0 19200 65280
77
                // ...
78
                //        }
79
                //LookUpTable End
80
                buf = GeoFile.filterWS(buf);
81
                String [] datos = buf.split(" ");
82
                System.out.println(buf);
83
                if (enPaleta) {
84
                        if (buf.length()>4) {
85
                                int nr = Integer.parseInt(datos[0].trim());
86
                                int r = Integer.parseInt(datos[1].trim());
87
                                int g = Integer.parseInt(datos[2].trim());
88
                                int b = Integer.parseInt(datos[3].trim());
89
                                setColorFromLut(nr, r, g, b);
90
                        } else
91
                                enPaleta = false;
92
                } else if (buf.length() > 4) {
93
                        if (buf.substring(0,3).compareTo("LUT") == 0) {
94
                                enPaleta = true;
95
                        } else if (buf.substring(0,3).compareTo("NrE") == 0) {
96
                                int numC = Integer.parseInt(datos[2].trim());
97
                                color = new Color[numC];
98
                                System.out.println("hay "+ numC + " colores.");         
99
                        }
100
                }
101
        }
102
        
103
        private void setColorFromLut(int nr, int r, int g, int b) {
104
                //"          0     0 19200 65280"
105
                color[nr] = new Color(r/256, g/256, b/256);
106
                //System.out.println(nr+":["+l.substring(5,10)+","+l.substring(11,16)+","+l.substring(17)+"]");         
107
                System.out.println(nr+":"+color[nr]);         
108
        }
109
}