All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JSci.awt.DefaultCategoryGraph2DModel Maven / Gradle / Ivy

Go to download

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 DefaultCategoryGraph2DModel class provides a default implementation
* of the CategoryGraph2DModel interface.
* @version 1.2
* @author Mark Hale
*/
public final class DefaultCategoryGraph2DModel extends AbstractGraphModel implements CategoryGraph2DModel, TableModelListener {
        private static final int X_AXIS_COLUMN = 0;
        private static final int SERIES_COLUMN = 1;

        private Object defaultCategories[] = new Object[0];
        private final List series=new ArrayList();
        private int pos=0;
        private DataSeries curSeries=null;

        public DefaultCategoryGraph2DModel() {}
        /**
        * Sets the default x-axis values.
        * A copy of the values is made.
        * This method does not change the x-axis values of any data series
        * and so does not fire any events.
        */
        public void setCategories(Object cat[]) {
                if(defaultCategories.length!=cat.length)
                        defaultCategories=new Object[cat.length];
                System.arraycopy(cat,0,defaultCategories,0,cat.length);
        }
        /**
        * Adds a data series using the default values for the x-axis.
	* Be sure to call {@link #setCategories(Object[]) setCategories} first.
        */
        public void addSeries(float newSeries[]) {
                addSeries(new DataSeries(defaultCategories, newSeries));
        }
        /**
        * Adds a data series using the default values for the x-axis.
	* Be sure to call {@link #setCategories(Object[]) setCategories} first.
        */
        public void addSeries(double newSeries[]) {
                addSeries(new DataSeries(defaultCategories, newSeries));
        }
        /**
        * 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(Object newXAxis[], float newSeries[]) {
                addSeries(new DataSeries(newXAxis, newSeries));
        }
        /**
        * Adds a data series.
        * Convenience method.
        */
        public void addSeries(Object newXAxis[], double newSeries[]) {
                addSeries(new DataSeries(newXAxis, 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);
        }
        /**
        * Changes a data series.
        * Convenience method.
        */
        public void changeSeries(int i,double newSeries[]) {
                getSeries(i).setValues(newSeries);
        }
        /**
        * Remove 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()));
        }

// CategoryGraph2DModel interface

        public String getCategory(int i) {
                return curSeries.getCategory(i).toString();
        }
        public float getValue(int i) {
                return curSeries.getValue(i);
        }
        public int seriesLength() {
                return curSeries.length();
        }
        public void firstSeries() {
                curSeries=getSeries(0);
                for(pos=0;!curSeries.isVisible() && pos




© 2015 - 2024 Weber Informatics LLC | Privacy Policy