root / trunk / libraries / libRaster / src / org / gvsig / raster / datastruct / ColorItem.java @ 13022
History | View | Annotate | Download (4.05 KB)
1 | 12504 | bsanchez | /* 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 | 12567 | bsanchez | public class ColorItem implements Cloneable { |
30 | 12504 | bsanchez | private double value = 0.0f; |
31 | private String nameClass = null; |
||
32 | private Color color = Color.black; |
||
33 | 13022 | bsanchez | private double interpolated = 50; |
34 | 12504 | bsanchez | |
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 | 13022 | bsanchez | public double getInterpolated() { |
57 | 12504 | bsanchez | 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 | 13022 | bsanchez | public void setInterpolated(double interpolated) { |
66 | 12504 | bsanchez | this.interpolated = interpolated;
|
67 | if (this.interpolated > 100) |
||
68 | this.interpolated = 100; |
||
69 | if (this.interpolated < 0) |
||
70 | this.interpolated = 0; |
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * Obtener en que valor estar? dicho color
|
||
75 | * @return
|
||
76 | */
|
||
77 | public double getValue() { |
||
78 | return value;
|
||
79 | } |
||
80 | |||
81 | /**
|
||
82 | * Definir el valor del ColorItem.
|
||
83 | * @param value
|
||
84 | */
|
||
85 | public void setValue(double value) { |
||
86 | this.value = value;
|
||
87 | } |
||
88 | |||
89 | /**
|
||
90 | * Devuelve el nombre de la clase
|
||
91 | * @return
|
||
92 | */
|
||
93 | public String getNameClass() { |
||
94 | return nameClass;
|
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * Define el nombre de la clase
|
||
99 | * @param nameClass
|
||
100 | */
|
||
101 | public void setNameClass(String nameClass) { |
||
102 | this.nameClass = nameClass;
|
||
103 | } |
||
104 | 12567 | bsanchez | |
105 | /*
|
||
106 | * (non-Javadoc)
|
||
107 | * @see java.lang.Object#clone()
|
||
108 | */
|
||
109 | public Object clone() { |
||
110 | ColorItem clone = null;
|
||
111 | try {
|
||
112 | clone = (ColorItem) super.clone();
|
||
113 | } catch (CloneNotSupportedException e) { |
||
114 | } |
||
115 | |||
116 | if (color != null) |
||
117 | clone.color = new Color(color.getRGB(), (color.getAlpha() != 255)); |
||
118 | |||
119 | if (nameClass != null) |
||
120 | clone.nameClass = new String(nameClass); |
||
121 | |||
122 | return clone;
|
||
123 | } |
||
124 | 12707 | bsanchez | |
125 | /*
|
||
126 | * (non-Javadoc)
|
||
127 | * @see java.lang.Object#hashCode()
|
||
128 | */
|
||
129 | public int hashCode() { |
||
130 | final int PRIME = 31; |
||
131 | int result = 1; |
||
132 | result = PRIME * result + ((color == null) ? 0 : color.hashCode()); |
||
133 | 13022 | bsanchez | result = PRIME * result + (int) interpolated;
|
134 | 12707 | bsanchez | result = PRIME * result + ((nameClass == null) ? 0 : nameClass.hashCode()); |
135 | long temp;
|
||
136 | temp = Double.doubleToLongBits(value);
|
||
137 | result = PRIME * result + (int) (temp ^ (temp >>> 32)); |
||
138 | return result;
|
||
139 | } |
||
140 | |||
141 | /*
|
||
142 | * (non-Javadoc)
|
||
143 | * @see java.lang.Object#equals(java.lang.Object)
|
||
144 | */
|
||
145 | public boolean equals(Object obj) { |
||
146 | if (this == obj) |
||
147 | return true; |
||
148 | if (obj == null) |
||
149 | return false; |
||
150 | if (getClass() != obj.getClass())
|
||
151 | return false; |
||
152 | final ColorItem other = (ColorItem) obj;
|
||
153 | if (color == null) { |
||
154 | if (other.color != null) |
||
155 | return false; |
||
156 | } else if (!color.equals(other.color)) |
||
157 | return false; |
||
158 | if (interpolated != other.interpolated)
|
||
159 | return false; |
||
160 | if (nameClass == null) { |
||
161 | if (other.nameClass != null) |
||
162 | return false; |
||
163 | } else if (!nameClass.equals(other.nameClass)) |
||
164 | return false; |
||
165 | if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value)) |
||
166 | return false; |
||
167 | return true; |
||
168 | } |
||
169 | 12504 | bsanchez | } |