JSci.swing.JContourPlot Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsci Show documentation
Show all versions of jsci Show documentation
JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software.
It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ...
Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).
The newest version!
package JSci.swing;
import java.awt.*;
import javax.swing.*;
import JSci.awt.*;
/**
* A contour plot Swing component.
* @author Daniel Lemire
*/
public final class JContourPlot extends JDoubleBufferedComponent implements ColorScheme {
private float data[][];
private double min, max;
private int deltay;
private ColorScheme CS;
//modifi?
private double[] deltax;
//modifi?
private float c1=1;
private float c2=1;
private float c3=1;
private int Contourx=2;
private int Contoury=2;
private int largeurMax;
private int hauteurMax;
//modifi?
private int ColorScaleWidth=40;
private String MaxString, MinString, MiddleString;
/**
* Constructs a contour plot.
* @param z an array of the form z[i][j] = f(xi, yj)
.
*/
public JContourPlot(double z[][]) {
super();
CS=this;
setBackground(Color.white);
setData(z);
setContourX(1);
setContourY(1);
}
/**
* Sets the data plotted by this JContourPlot to the specified data.
*/
public void setData(double feed[][]) {
//invert the rows
double[][] array=new double[feed.length][];
for(int k=0;kmax)
max=array[k][l];
if(array[k][l]d){
compare/=10;
ans--;
}
return(ans);
}
while(comparewidthMax)
widthMax=data[k].length;
}
return new Dimension(widthMax+3*Contourx+ColorScaleWidth+5,(int)Math.max(data.length*2+2*Contoury,100));
}
/**
* There is a box around the graph, this
* sets how wide it will be in the horizontal direction.
* @param k width (in pixel)
* @exception IllegalArgumentException if the width is not at least one.
*/
public void setContourX(int k) {
if(k<1)
throw new IllegalArgumentException("This parameter must be greater than 1 : "+k+" < 1");
Contourx=k;
}
/**
* There is a box around the graph, this
* sets how wide it will be in the vertical direction.
* @param k width (in pixel).
* @exception IllegalArgumentException if the width is not at least one.
*/
public void setContourY(int k) {
if(k<1)
throw new IllegalArgumentException("This parameter must be greater than 1 : "+k+" < 1");
Contoury=k;
}
public void setBounds(int x,int y,int width,int height) {
super.setBounds(x,y,width,height);
rescale();
}
private void rescale() {
int thiswidth=getWidth();
int thisheight=getHeight();
Dimension s=getMinimumSize();
thiswidth=Math.max(thiswidth,s.width);
thisheight=Math.max(thisheight,s.height);
int largeur=thiswidth-3*Contourx;
int hauteur=thisheight-2*Contoury-ColorScaleWidth;
deltay=(int) Math.floor(hauteur/data.length);
hauteurMax=deltay*data.length;
//modifi?
deltax=new double[data.length];
//modifi?
largeurMax=0;
int MaxNumberOfElements=data[0].length;
for(int k=1;k1)||(x2<0)||(x2>1)||(x3<0)||(x3>1)) {
throw new IllegalArgumentException("Incorrect parameters : "+x1+", "+x2+", "+x3);
}
if(x1+x2+x3==0) {
throw new IllegalArgumentException("You have chosen black at the specified color. This would generate a completly black graph. Please choose another color.");
}
c1=x1;c2=x2;c3=x3;
}
public Color getColor(float f) {
if((f<0)||(f>1))
throw new IllegalArgumentException("Color are given for values between 0 and 1 : "+f);
return(Color.getHSBColor(f,1f,1f));
}
public void setColorScheme (ColorScheme cs) {
CS=cs;
}
/**
* Paint the graph.
*/
protected void offscreenPaint(Graphics g) {
int FontHeight=g.getFontMetrics(g.getFont()).getHeight();
g.setColor(new Color(1f-c1,1f-c2,1f-c3));
g.drawRect(Contourx+ColorScaleWidth,Contoury-1,largeurMax,hauteurMax);
g.drawRect(Contourx-1,Contoury-1,ColorScaleWidth,hauteurMax);
g.setClip(Contourx,Contoury,ColorScaleWidth-1,hauteurMax-1);
//double step255=hauteurMax/255;
for(float y=0;y