import java.awt.*; import java.util.*; import ThirdParty.BarChart.*; public class G_Detector extends Panel implements Runnable{ Thread analyzeThread; DataChart chart = null; Histogram hist = null; int ySensorTop,ySensorBot,shootWidth; boolean passedTop,passedBot; int tClock=0; int topTime=0; int botTime=0; double TimeResolution = 10.0; Random ran = new Random(); //---------------------------------------------------------------- public G_Detector(int detHeight,int detWidth){ // Add sub-panels with readouts, histograms and controls setBackground(Color.cyan); int _width= 175; int _height = 200; Panel p1 = new Panel(); p1.setLayout(new BorderLayout()); hist = new Histogram(40,120.0,320.0,_width,_height-50); p1.add("North",new Label("Drop Delta-T times")); p1.add("Center",hist.chart._barChart); p1.add("South",new Label("Bin Range: 120-320ms",Label.CENTER)); add(p1); ySensorTop = (int)(0.40 * detHeight); ySensorBot = (int)(0.90 * detHeight); shootWidth = detWidth; } //---------------------------------------------------------------- public void init(){ passedTop = false; passedBot = false; hist.reset(); repaint(); } //---------------------------------------------------------------- public void start() { analyzeThread = new Thread(this); analyzeThread.start(); } //---------------------------------------------------------------- public void stop() { analyzeThread = null; } //---------------------------------------------------------------- // public void eventStart(){ passedTop = false; passedBot = false; tClock = 0; } //---------------------------------------------------------------- // public void eventDone(){ repaint(); } //---------------------------------------------------------------- // public void sensor(double y, int t){ tClock += t; if(!passedTop){ if( y >= ySensorTop){ topTime = tClock; passedTop=true; } return; } if(!passedBot){ if( y >= ySensorBot){ botTime = tClock; passedBot=true; // Data is ready so start detector thread start(); } return; } } //---------------------------------------------------------------- // public void analyze(){ double dt = botTime - topTime; dt += (int)(TimeResolution * ran.nextGaussian()); recordData(dt); stop(); } //---------------------------------------------------------------- public void run() { // Set at lower priority so that the animation will // be at top priority. analyzeThread.setPriority(Thread.NORM_PRIORITY - 1); // Do analysis when animation no busy. while (analyzeThread != null) { analyze(); } } //---------------------------------------------------------------- // Display the message, data, data event and histogram displays public void paint(Graphics g){ hist.graphIt(); } //---------------------------------------------------------------- // Draw the sensors on the drop shoot public void draw(Graphics g){ Color c = g.getColor(); g.setColor(Color.green); g.drawLine(0,ySensorTop,shootWidth,ySensorTop); g.drawLine(0,ySensorBot,shootWidth,ySensorBot); g.setColor(c); } //---------------------------------------------------------------- public void recordData(double dataPt){ hist.setData(dataPt); } }