Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRaster / src / org / gvsig / raster / datastruct / ColorItem.java @ 31829

History | View | Annotate | Download (4.11 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.datastruct;
20

    
21
import java.awt.Color;
22
/**
23
 * Valor minimo para un item de una tabla de color. Este tendr? que pixel afecta,
24
 * nombre de esa clase, color y como estar? interpolado con el siguiente.
25
 *
26
 * @version 04/07/2007
27
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
28
 */
29
public class ColorItem implements Cloneable {
30
        private double value = 0.0f;
31
        private String nameClass = null;
32
        private Color color = Color.black;
33
        private double interpolated = 50;
34

    
35
        /**
36
         * Devuelve el color
37
         * @return
38
         */
39
        public Color getColor() {
40
                return color;
41
        }
42

    
43
        /**
44
         * Definir el color
45
         * @param color
46
         */
47
        public void setColor(Color color) {
48
                this.color = color;
49
        }
50

    
51
        /**
52
         * Devuelve el valor de interpolaci?n con el siguiente color.
53
         * L?mites: 0..100
54
         * @return
55
         */
56
        public double getInterpolated() {
57
                return interpolated;
58
        }
59

    
60
        /**
61
         * Definir el valor de interpolaci?n. Si es mayor a 100 o menor a 0 se pone
62
         * entre los valores correctos.
63
         * @param interpolated
64
         */
65
        public void setInterpolated(double interpolated) {
66
                if (interpolated > 100)
67
                        this.interpolated = 100;
68
                else
69
                        if (interpolated < 0)
70
                                this.interpolated = 0;
71
                        else
72
                                this.interpolated = interpolated;
73
        }
74

    
75
        /**
76
         * Obtener en que valor estar? dicho color
77
         * @return
78
         */
79
        public double getValue() {
80
                return value;
81
        }
82

    
83
        /**
84
         * Definir el valor del ColorItem.
85
         * @param value
86
         */
87
        public void setValue(double value) {
88
                if (Double.isNaN(value))
89
                        return;
90
                this.value = value;
91
        }
92

    
93
        /**
94
         * Devuelve el nombre de la clase
95
         * @return
96
         */
97
        public String getNameClass() {
98
                return nameClass;
99
        }
100

    
101
        /**
102
         * Define el nombre de la clase
103
         * @param nameClass
104
         */
105
        public void setNameClass(String nameClass) {
106
                this.nameClass = nameClass;
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see java.lang.Object#clone()
112
         */
113
        public Object clone() {
114
                ColorItem clone = null;
115
                try {
116
                        clone = (ColorItem) super.clone();
117
                } catch (CloneNotSupportedException e) {
118
                }
119

    
120
                if (color != null)
121
                        clone.color = new Color(color.getRGB(), (color.getAlpha() != 255));
122

    
123
                if (nameClass != null)
124
                        clone.nameClass = new String(nameClass);
125

    
126
                return clone;
127
        }
128

    
129
        /*
130
         * (non-Javadoc)
131
         * @see java.lang.Object#hashCode()
132
         */
133
        public int hashCode() {
134
                final int PRIME = 31;
135
                int result = 1;
136
                result = PRIME * result + ((color == null) ? 0 : color.hashCode());
137
                result = PRIME * result + (int) interpolated;
138
                result = PRIME * result + ((nameClass == null) ? 0 : nameClass.hashCode());
139
                long temp;
140
                temp = Double.doubleToLongBits(value);
141
                result = PRIME * result + (int) (temp ^ (temp >>> 32));
142
                return result;
143
        }
144

    
145
        /*
146
         * (non-Javadoc)
147
         * @see java.lang.Object#equals(java.lang.Object)
148
         */
149
        public boolean equals(Object obj) {
150
                if (this == obj)
151
                        return true;
152
                if (obj == null)
153
                        return false;
154
                if (getClass() != obj.getClass())
155
                        return false;
156
                final ColorItem other = (ColorItem) obj;
157
                if (color == null) {
158
                        if (other.color != null)
159
                                return false;
160
                } else
161
                        if (!color.equals(other.color))
162
                                return false;
163
                if (interpolated != other.interpolated)
164
                        return false;
165
                if (nameClass == null) {
166
                        if (other.nameClass != null)
167
                                return false;
168
                } else
169
                        if (!nameClass.equals(other.nameClass))
170
                                return false;
171
                if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value))
172
                        return false;
173
                return true;
174
        }
175
}