svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / stretch / StretchData.java @ 22827
History | View | Annotate | Download (5.06 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.rastertools.vectorizacion.stretch; |
20 |
|
21 |
import java.util.Observable; |
22 |
|
23 |
import org.gvsig.raster.beans.canvas.layers.StretchLayerDataModel; |
24 |
import org.gvsig.raster.beans.stretchselector.StretchSelectorData; |
25 |
import org.gvsig.raster.util.RasterToolsUtil; |
26 |
|
27 |
/**
|
28 |
* Modelo de datos para el panel de gesti?n de tramos.
|
29 |
*
|
30 |
* 19/08/2008
|
31 |
* @author Nacho Brodin nachobrodin@gmail.com
|
32 |
*/
|
33 |
public class StretchData extends Observable { |
34 |
|
35 |
private StretchSelectorData selectorData = null; |
36 |
private StretchLayerDataModel layerDataModel = null; |
37 |
private double[] histogram = new double[]{0, 0, 3, 4, 5, 8, 7, 18, 45, 36, 21, 36, 12, 23, 23, 40, 17, 10, 5, 1, 0, 0, 0}; |
38 |
|
39 |
/**
|
40 |
* Constructor
|
41 |
* @param selectorData
|
42 |
*/
|
43 |
public StretchData() {
|
44 |
this.selectorData = new StretchSelectorData(); |
45 |
} |
46 |
|
47 |
/**
|
48 |
* Actualiza datos y llama al update de los observadores
|
49 |
*/
|
50 |
public void updateObservers() { |
51 |
setChanged(); |
52 |
notifyObservers(); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* Asigna el modelo de datos de la capa gr?fica. Este es el que contiene la lista
|
57 |
* de valores de los tramos.
|
58 |
*/
|
59 |
public void setStretchLayerDataModel(StretchLayerDataModel layerDataModel) { |
60 |
this.layerDataModel = layerDataModel;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Obtiene el modelo de datos de la capa gr?fica
|
65 |
* @return
|
66 |
*/
|
67 |
public StretchLayerDataModel getStretchDataModel() {
|
68 |
return this.layerDataModel; |
69 |
} |
70 |
|
71 |
/**
|
72 |
* Obtiene los tramos a partir del modelo de datos de la gr?fica.
|
73 |
* @return double[]
|
74 |
*/
|
75 |
public double[] getStretchs() { |
76 |
if(layerDataModel == null) |
77 |
return new double[]{getMin(), getMax()}; |
78 |
return layerDataModel.getValues();
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Obtiene el el modelo de datos del selector de intervalos
|
83 |
* @return StretchSelectorData
|
84 |
*/
|
85 |
public StretchSelectorData getStretchSelectorData() {
|
86 |
return selectorData;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Obtiene el histograma para asignarlo a la capa del canvas
|
91 |
* gr?fico.
|
92 |
* @return double[]
|
93 |
*/
|
94 |
public double[] getHistogram() { |
95 |
return histogram;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Asigna el histograma en el formato tabla obtenido desde
|
100 |
* el objeto Histogram. Es almacenado en formato double[] que es
|
101 |
* el necesario para la capa del canvas.
|
102 |
* @param hist
|
103 |
*/
|
104 |
public void setHistogram(long[][] hist) { |
105 |
if(hist != null && hist.length > 0) { |
106 |
this.histogram = new double[hist[0].length]; |
107 |
for (int i = 0; i < hist[0].length; i++) |
108 |
this.histogram[i] = hist[0][i]; |
109 |
} |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Obtiene el valor m?ximo
|
114 |
* @return
|
115 |
*/
|
116 |
public double getMax() { |
117 |
try {
|
118 |
return new Double(selectorData.getMax()).doubleValue(); |
119 |
} catch(NumberFormatException e) { |
120 |
RasterToolsUtil.debug("El valor de max de StretchSelectorData no es convertible a double", this, e); |
121 |
} |
122 |
return 0; |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Asigna el valor m?ximo
|
127 |
* @param max
|
128 |
*/
|
129 |
public void setMax(double max) { |
130 |
selectorData.setMax(new Double(max).toString()); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Obtiene el valor m?nimo
|
135 |
* @return
|
136 |
*/
|
137 |
public double getMin() { |
138 |
try {
|
139 |
return new Double(selectorData.getMin()).doubleValue(); |
140 |
} catch(NumberFormatException e) { |
141 |
RasterToolsUtil.debug("El valor de max de StretchSelectorData no es convertible a double", this, e); |
142 |
} |
143 |
return 0; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* Asigna el valor m?nimo
|
148 |
* @param min
|
149 |
*/
|
150 |
public void setMin(double min) { |
151 |
selectorData.setMin(new Double(min).toString()); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Obtiene el n?mero de intervalos
|
156 |
* @return
|
157 |
*/
|
158 |
public double getNInterval() { |
159 |
try {
|
160 |
return new Double(selectorData.getNumber()).doubleValue(); |
161 |
} catch(NumberFormatException e) { |
162 |
RasterToolsUtil.debug("El valor de n?mero de intervalos de StretchSelectorData no es convertible a double", this, e); |
163 |
} |
164 |
return 0; |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Asigna el n?mero de intervalos
|
169 |
* @param interval
|
170 |
*/
|
171 |
public void setNInterval(double interval) { |
172 |
selectorData.setNumber(new Double(interval).toString()); |
173 |
} |
174 |
|
175 |
/**
|
176 |
* Obtiene el tama?o de intervalo
|
177 |
* @return
|
178 |
*/
|
179 |
public double getSizeInterval() { |
180 |
try {
|
181 |
return new Double(selectorData.getIntervalSize()).doubleValue(); |
182 |
} catch(NumberFormatException e) { |
183 |
RasterToolsUtil.debug("El valor de tama?o de intervalo de StretchSelectorData no es convertible a double", this, e); |
184 |
} |
185 |
return 0; |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Asigna el tama?o de intervalo
|
190 |
* @param sizeInterval
|
191 |
*/
|
192 |
public void setSizeInterval(double sizeInterval) { |
193 |
selectorData.setIntervalSize(new Double(sizeInterval).toString()); |
194 |
} |
195 |
} |