JSci.awt.DefaultGraph3DModel 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.awt;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
/**
* The DefaultGraph3DModel class provides a default implementation
* of the Graph3DModel interface.
* @version 1.2
* @author Mark Hale
*/
public final class DefaultGraph3DModel extends AbstractGraphModel implements Graph3DModel, TableModelListener {
private static final int X_AXIS_COLUMN = 0;
private static final int Y_AXIS_COLUMN = 1;
private static final int SERIES_COLUMN = 2;
private float xAxis[] = new float[0];
private float yAxis[] = new float[0];
private final List series=new ArrayList();
private int pos=0;
private DataSeries curSeries=null;
public DefaultGraph3DModel() {}
/**
* Sets the x-axis values.
* A copy of the values is made.
*/
public void setXAxis(float x[]) {
if(xAxis.length!=x.length)
xAxis=new float[x.length];
System.arraycopy(x,0,xAxis,0,x.length);
fireGraphDataChanged();
}
/**
* Sets the y-axis values.
* A copy of the values is made.
*/
public void setYAxis(float y[]) {
if(yAxis.length!=y.length)
yAxis=new float[y.length];
System.arraycopy(y,0,yAxis,0,y.length);
fireGraphDataChanged();
}
/**
* Adds a data series.
*/
public void addSeries(DataSeries newSeries) {
series.add(newSeries);
fireGraphDataChanged();
newSeries.addTableModelListener(this);
}
/**
* Adds a data series.
* Convenience method.
*/
public void addSeries(float newSeries[]) {
addSeries(new DataSeries(xAxis, yAxis, newSeries));
}
/**
* Changes a data series.
*/
public void changeSeries(int i,DataSeries newSeries) {
getSeries(i).removeTableModelListener(this);
series.set(i, newSeries);
fireGraphDataChanged();
newSeries.addTableModelListener(this);
}
/**
* Changes a data series.
* Convenience method.
*/
public void changeSeries(int i,float newSeries[]) {
getSeries(i).setValues(newSeries);
}
/**
* Removes a data series.
*/
public void removeSeries(int i) {
getSeries(i).removeTableModelListener(this);
series.remove(i);
fireGraphDataChanged();
}
public DataSeries getSeries(int i) {
return (DataSeries)series.get(i);
}
/**
* Convenience method.
*/
public void setSeriesVisible(int i,boolean flag) {
getSeries(i).setVisible(flag);
}
/**
* Implementation of TabelModelListener.
* Application code will not use this method explicitly, it is used internally.
*/
public void tableChanged(TableModelEvent evt) {
if(evt.getColumn() == SERIES_COLUMN)
fireGraphSeriesUpdated(series.indexOf(evt.getSource()));
}
// Graph3DModel interface
public float getXCoord(int i) {
return xAxis[i];
}
public float getYCoord(int i) {
return yAxis[i];
}
public float getZCoord(int i) {
return curSeries.getValue(i);
}
public int seriesLength() {
return curSeries.length();
}
public void firstSeries() {
curSeries=getSeries(0);
for(pos=0;!curSeries.isVisible() && pos