package jasext.hist.function;

import jas2.hist.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import jas2.util.*;
import javax.swing.Icon;

public class SumFunctionFactory implements FunctionFactory
{
	public Basic1DFunction createFunction(JASHist h) throws FunctionFactoryError
	{
		SumOfFunctions sum = new SumOfFunctions();
		int n=0;

		// By default add all the other functions!

		Enumeration e = h.get1DFunctions();
		while (e.hasMoreElements()) 
		{
			JASHistData data = (JASHistData) e.nextElement();
			Basic1DFunction func = (Basic1DFunction) data.getDataSource();
			sum.addFunction(func);
			n++;
		}	

		if (n<2) throw new FunctionFactoryError("Need at least two functions to sum!");

		sum.setIncluded(n);
		/* sets up a boolean array that holds whether a particular
		 * function is included in the sum */
		return sum;
	}
	public String getFunctionName()
	{
		return "Sum of existing functions";
	}
	public Icon getFunctionIcon()
	{
		return icon; 
	}
	private Icon icon = JASIcon.create(this,"sum.gif");

	/*
	private class SumFunctionDialog 
		extends JASDialog implements ItemListener, ActionListener
	{
		SumFunctionDialog(JASHist h, Frame f)
		{
			super(f,"Choose Functions to Sum...");
			setLayout(new FlowLayout());

			Enumeration e = h.get1DFunctions();
			while (e.hasMoreElements()) 
			{
				JASHist1DData data = (JASHist1DData) e.nextElement();
				Basic1DFunction func = (Basic1DFunction) data.getDataSource();
				Checkbox c = new Checkbox(func.getTitle());
				add(c);
			}
			pack();
		}
		public void itemStateChanged(ItemEvent evt)
		{
			callEnable();
		}
		public void actionPerformed(ActionEvent evt)
		{
			onOK();
		}
		public void enableOK(JASState state)
		{
			//state.setEnabled(m_list.getSelectedValue()!=null);
		}
		public void onOK()
		{
			super.onOK();
		}
	}*/
}

 

Ads help maintain this website.