svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / enhanced / graphics / InputHistogram.java @ 19945
History | View | Annotate | Download (4.32 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.enhanced.graphics; |
20 |
|
21 |
import java.awt.Color; |
22 |
|
23 |
import org.gvsig.raster.beans.canvas.GCanvas; |
24 |
import org.gvsig.raster.beans.canvas.layers.Border; |
25 |
import org.gvsig.raster.beans.canvas.layers.GraphicHistogram; |
26 |
import org.gvsig.raster.beans.canvas.layers.InfoLayer; |
27 |
import org.gvsig.raster.beans.canvas.layers.MinMaxLines; |
28 |
import org.gvsig.raster.beans.canvas.layers.functions.BaseFunction; |
29 |
import org.gvsig.raster.beans.canvas.layers.functions.DensitySlicingLine; |
30 |
import org.gvsig.raster.beans.canvas.layers.functions.LogaritmicExponentialLine; |
31 |
import org.gvsig.raster.beans.canvas.layers.functions.StraightLine; |
32 |
import org.gvsig.raster.datastruct.Histogram; |
33 |
import org.gvsig.rastertools.enhanced.ui.EnhancedListener; |
34 |
/**
|
35 |
* Componente con el histograma de entrada.
|
36 |
*
|
37 |
* 20/02/2008
|
38 |
* @author Nacho Brodin nachobrodin@gmail.com
|
39 |
*/
|
40 |
public class InputHistogram extends HistogramGraphicBase { |
41 |
private static final long serialVersionUID = 681848373747974757L; |
42 |
|
43 |
/**
|
44 |
* Crea una nueva instancia de InputHistogram.
|
45 |
*/
|
46 |
public InputHistogram(Histogram hist, int[] renderBands, double[] minList, double[] maxList) { |
47 |
super(hist, renderBands, minList, maxList);
|
48 |
} |
49 |
|
50 |
/*
|
51 |
* (non-Javadoc)
|
52 |
* @see org.gvsig.rastertools.enhanced.graphics.HistogramGraphicBase#getCanvas()
|
53 |
*/
|
54 |
public GCanvas getCanvas() {
|
55 |
if(canvas == null) { |
56 |
canvas = new GCanvas(Color.BLACK); |
57 |
canvas.addDrawableElement(new GraphicHistogram(Color.white)); |
58 |
canvas.addDrawableElement(new MinMaxLines(minMaxLineColor));
|
59 |
canvas.addDrawableElement(new StraightLine(functionColor));
|
60 |
canvas.addDrawableElement(new Border(borderColor)); |
61 |
canvas.addDrawableElement(new InfoLayer(Color.WHITE)); |
62 |
} |
63 |
return canvas;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Asigna el listener para gestionar el evento de movimiento de gr?ficos
|
68 |
* @param listener
|
69 |
*/
|
70 |
public void setListener(EnhancedListener listener) { |
71 |
getCanvas().addValueChangedListener(listener); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Asigna el nivel de la funci?n si esta es density slicing.
|
76 |
* @param level
|
77 |
*/
|
78 |
public void setLevel(int level) { |
79 |
if (histogramDrawed != null) |
80 |
histogramDrawed.setLevel(level); |
81 |
getCanvas().repaint(); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Asigna el tipo de funci?n Lineal, Exponencial, logaritmica, density slicing, campana de gauss,
|
86 |
* raiz cuadrada o ecualizaci?n.
|
87 |
*
|
88 |
* @param type Tipo de histograma. El valor est? definido en las constantes de GraphicHistogram
|
89 |
*/
|
90 |
public void setFunction(int function) { |
91 |
if (histogramDrawed == null) |
92 |
return;
|
93 |
|
94 |
BaseFunction baseFunction = histogramDrawed.getBaseFunction(); |
95 |
switch (function) {
|
96 |
case GraphicHistogram.FUNCTION_DENSITY:
|
97 |
if (!baseFunction.getClass().equals(DensitySlicingLine.class))
|
98 |
baseFunction = new DensitySlicingLine(histogramDrawed.getBaseFunction().getColor());
|
99 |
break;
|
100 |
case GraphicHistogram.FUNCTION_LINEAL:
|
101 |
if (!baseFunction.getClass().equals(StraightLine.class))
|
102 |
baseFunction = new StraightLine(histogramDrawed.getBaseFunction().getColor());
|
103 |
break;
|
104 |
case GraphicHistogram.FUNCTION_LOGARIT:
|
105 |
baseFunction = new LogaritmicExponentialLine(histogramDrawed.getBaseFunction().getColor(), 1.0); |
106 |
break;
|
107 |
case GraphicHistogram.FUNCTION_EXPONENT:
|
108 |
baseFunction = new LogaritmicExponentialLine(histogramDrawed.getBaseFunction().getColor(), -1.0); |
109 |
break;
|
110 |
} |
111 |
|
112 |
histogramDrawed.setBaseFunction(baseFunction); |
113 |
getCanvas().replaceDrawableElement(histogramDrawed.getBaseFunction(), BaseFunction.class); |
114 |
|
115 |
// Fuerza un repintado inmediato para actualizar los valores
|
116 |
getCanvas().paint(getCanvas().getGraphics()); |
117 |
} |
118 |
} |