Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/px/Paleta.java

View differences:

Paleta.java
1 1
/*
2 2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5 3
 *
4
 * Copyright (C) 2004-5.
5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 2
......
18 18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19 19
 *
20 20
 * For more information, contact:
21
 * 
21
 *
22 22
 * cresques@gmail.com
23 23
 */
24 24
package org.cresques.px;
25 25

  
26
import org.cresques.io.GeoFile;
27

  
26 28
import java.awt.Color;
29

  
27 30
import java.io.BufferedReader;
28 31
import java.io.FileReader;
29 32
import java.io.IOException;
30 33

  
31
import org.cresques.io.GeoFile;
32 34

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

  
39 40
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
	 */
41
    public String fName = null;
42
    String name = null;
43
    public Color[] color = null;
44
    boolean enPaleta = false;
50 45

  
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();
46
    /**
47
     * Lee una paleta desde un .lut de ArcView
48
     *
49
     * @param fName
50
     */
51
    public void loadLut(String fName) throws IOException {
52
        BufferedReader fi;
53
        String buf;
54
        int l = 0;
65 55

  
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
	}
56
        if (fName == null) {
57
            fName = "C:/ESRI/AV_GIS30/ARCVIEW/averm/LUT/elevation.lut";
58
        }
59

  
60
        this.fName = fName;
61
        fi = new BufferedReader(new FileReader(fName));
62

  
63
        while ((buf = fi.readLine()) != null) {
64
            //System.out.println(buf);
65
            l++;
66
            parseLine(buf);
67
        }
68

  
69
        fi.close();
70

  
71
        //setColorFromLut("	  0     0 19200 65280");
72
    }
73

  
74
    private void parseLine(String buf) {
75
        //LookUpTable Begin
76
        //	Version         = "1.0"
77
        //	Name            = "elevation"
78
        //	Description     = "one of several std color schemes for color coding elevation data"
79
        //	NrEntries       = 256
80
        //	LUT             = {
81
        //	  0     0 19200 65280
82
        // ...
83
        //	}
84
        //LookUpTable End
85
        buf = GeoFile.filterWS(buf);
86

  
87
        String[] datos = buf.split(" ");
88
        System.out.println(buf);
89

  
90
        if (enPaleta) {
91
            if (buf.length() > 4) {
92
                int nr = Integer.parseInt(datos[0].trim());
93
                int r = Integer.parseInt(datos[1].trim());
94
                int g = Integer.parseInt(datos[2].trim());
95
                int b = Integer.parseInt(datos[3].trim());
96
                setColorFromLut(nr, r, g, b);
97
            } else {
98
                enPaleta = false;
99
            }
100
        } else if (buf.length() > 4) {
101
            if (buf.substring(0, 3).compareTo("LUT") == 0) {
102
                enPaleta = true;
103
            } else if (buf.substring(0, 3).compareTo("NrE") == 0) {
104
                int numC = Integer.parseInt(datos[2].trim());
105
                color = new Color[numC];
106
                System.out.println("hay " + numC + " colores.");
107
            }
108
        }
109
    }
110

  
111
    private void setColorFromLut(int nr, int r, int g, int b) {
112
        //"	  0     0 19200 65280"
113
        color[nr] = new Color(r / 256, g / 256, b / 256);
114

  
115
        //System.out.println(nr+":["+l.substring(5,10)+","+l.substring(11,16)+","+l.substring(17)+"]");	 
116
        System.out.println(nr + ":" + color[nr]);
117
    }
109 118
}

Also available in: Unified diff