package ij.plugin.frame;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.awt.datatransfer.*;
import ij.*;
import ij.plugin.PlugIn;
import ij.plugin.frame.*;
import ij.text.*;
import ij.gui.*;
import ij.util.*;
import ij.io.*;
import ij.process.*;
import ij.measure.*;
/** ImageJ plugin that does curve fitting using the modified CurveFitter class.
* Includes simplex settings dialog option.
*
* @author Kieran Holland (email: holki659@student.otago.ac.nz)
*
* 2013-10-01: fit not in EventQueue, setStatusAndEsc, error if nonnumeric data
*/
public class Fitter extends PlugInFrame implements PlugIn, ItemListener, ActionListener, KeyListener, ClipboardOwner {
Choice fit;
Button doIt, open, apply;
Checkbox settings;
String fitTypeStr = CurveFitter.fitList[0];
TextArea textArea;
double[] dx = {0,1,2,3,4,5};
double[] dy = {0,.9,4.5,8,18,24};
double[] x,y;
static CurveFitter cf;
static int fitType = -1;
static String equation = "y = a + b*x + c*x*x";
static final int USER_DEFINED = -1;
public Fitter() {
super("Curve Fitter");
WindowManager.addWindow(this);
addKeyListener(this);
Panel panel = new Panel();
fit = new Choice();
for (int i=0; i1000)
npoints = 1000;
double[] a = Tools.getMinMax(x);
double xmin=a[0], xmax=a[1];
if (eightBitCalibrationPlot) {
npoints = 256;
xmin = 0;
xmax = 255;
}
a = Tools.getMinMax(y);
double ymin=a[0], ymax=a[1]; //y range of data points
float[] px = new float[npoints];
float[] py = new float[npoints];
double inc = (xmax-xmin)/(npoints-1);
double tmp = xmin;
for (int i=0; i100))
break;
textArea.append(s+"\n");
}
r.close();
}
catch (Exception e) {
IJ.error(e.getMessage());
return;
}
}
public void itemStateChanged(ItemEvent e) {
fitTypeStr = fit.getSelectedItem();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof MenuItem) {
String cmd = e.getActionCommand();
if (cmd==null) return;
if (cmd.equals("Cut"))
cut();
else if (cmd.equals("Copy"))
copy();
else if (cmd.equals("Paste"))
paste();
return;
}
try {
if (e.getSource()==doIt) {
final int fitType = CurveFitter.getFitCode(fit.getSelectedItem());
Thread thread = new Thread(
new Runnable() {
final public void run() {
doFit(fitType);
}
}, "CurveFitting"
);
thread.setPriority(Thread.currentThread().getPriority());
thread.start();
} else if (e.getSource()==apply)
applyFunction();
else
open();
} catch (Exception ex) {IJ.log(""+ex);}
}
String zapGremlins(String text) {
char[] chars = new char[text.length()];
chars = text.toCharArray();
int count=0;
for (int i=0; i127)) {
count++;
chars[i] = ' ';
}
}
if (count>0)
return new String(chars);
else
return text;
}
public void keyTyped (KeyEvent e) {}
public void keyReleased (KeyEvent e) {}
public void keyPressed (KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
IJ.getInstance().keyPressed(e);
}
private boolean copy() {
String s = textArea.getSelectedText();
Clipboard clip = getToolkit().getSystemClipboard();
if (clip!=null) {
StringSelection cont = new StringSelection(s);
clip.setContents(cont,this);
return true;
} else
return false;
}
private void cut() {
if (copy()) {
int start = textArea.getSelectionStart();
int end = textArea.getSelectionEnd();
textArea.replaceRange("", start, end);
}
}
private void paste() {
String s;
s = textArea.getSelectedText();
Clipboard clipboard = getToolkit( ). getSystemClipboard();
Transferable clipData = clipboard.getContents(s);
try {
s = (String)(clipData.getTransferData(DataFlavor.stringFlavor));
} catch (Exception e) {
s = e.toString( );
}
int start = textArea.getSelectionStart( );
int end = textArea.getSelectionEnd( );
textArea.replaceRange(s, start, end);
if (IJ.isMacOSX())
textArea.setCaretPosition(start+s.length());
}
public void lostOwnership (Clipboard clip, Transferable cont) {}
}
Ads help maintain this website.