root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / beans / canvas / layers / functions / ExponentialLine.java @ 19555
History | View | Annotate | Download (2.77 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.raster.beans.canvas.layers.functions; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Graphics; |
23 |
|
24 |
import org.gvsig.raster.beans.canvas.GCanvas; |
25 |
|
26 |
|
27 |
/**
|
28 |
* Representa una linea con incremento exponencial.
|
29 |
*
|
30 |
* 14-oct-2007
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public class ExponentialLine extends BaseFunction { |
34 |
int[] xPoints = null; |
35 |
int[] yPoints = null; |
36 |
|
37 |
/**
|
38 |
* Constructor. Asigna el color
|
39 |
* @param c
|
40 |
*/
|
41 |
public ExponentialLine(Color c) { |
42 |
setColor(c); |
43 |
} |
44 |
|
45 |
/*
|
46 |
* (non-Javadoc)
|
47 |
* @see org.gvsig.gui.beans.canvas.DrawableElement#firstDraw()
|
48 |
*/
|
49 |
public void firstDrawActions() { |
50 |
xPoints = new int[canvas.getCanvasWidth()]; |
51 |
yPoints = new int[canvas.getCanvasHeight()]; |
52 |
double pos = Math.log(canvas.getCanvasMinY()); |
53 |
double max = Math.log(canvas.getCanvasMaxY()); |
54 |
double increase = (max - pos) / canvas.getCanvasHeight();
|
55 |
for (int i = canvas.getCanvasMinY(); i < canvas.getCanvasMaxY(); i++) { |
56 |
try {
|
57 |
//yPoints[i] = value - (int)(value * Math.exp((double)i / 64) / Math.exp(3));
|
58 |
yPoints[i - canvas.getCanvasMinY()] = canvas.getCanvasHeight() - (int)Math.round(Math.exp(pos)); |
59 |
xPoints[i - canvas.getCanvasMinX()] = i; |
60 |
//System.out.println(xPoints[i] + " " + yPoints[i]);
|
61 |
//System.out.println(Math.exp((double)i/85));
|
62 |
System.out.println(xPoints[i - canvas.getCanvasMinX()] + " : " + pos + " : " + yPoints[i - canvas.getCanvasMinY()]); |
63 |
pos += increase; |
64 |
} catch(ArrayIndexOutOfBoundsException e) {} |
65 |
} |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Dibujado de la l?nea de incremento exponencial sobre el canvas.
|
70 |
*/
|
71 |
protected void paint(Graphics g) { |
72 |
g.setColor(color); |
73 |
g.drawPolyline(xPoints, yPoints, xPoints.length); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Asigna el objeto JComponent donde se pintan los elementos. Inicializa los puntos
|
78 |
* de inicio y fin de l?nea y asigna los listener
|
79 |
* @param canvas
|
80 |
*/
|
81 |
public void setCanvas(GCanvas canvas) { |
82 |
super.setCanvas(canvas);
|
83 |
} |
84 |
|
85 |
public void firstActions() {} |
86 |
} |