/** * Created by IntelliJ IDEA. * User: siddhartha * Date: Jan 29, 2006 * Time: 9:55:16 PM * To change this template use File | Settings | File Templates. /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////*\ This class is an extention of Canvas. Runs its own thread. paint methods cannot be called directly by browser (good) \*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////*/ import java.awt.*; import java.awt.event.MouseMotionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import java.text.DecimalFormat; //! @brief This class measures various quantities of interest and displays or plots them on screen. /// Not fully functional yet. Currently only measures average Delta-F or simply F. Can be used to measure other quantities, /// Energy, for example. Maybe Friction? class Measure extends Canvas implements Runnable { private Thread myThread; private AFMSimulator afmSim; private BufferedImage image; private Color backgroundColor; private Color textColor; private int ind; private final int W = 500, H = 300; private int delay = 100; private char what; // measuring what? F = Force, R = Friction, L = Liapunov, etc. private boolean plot = true; // plot or numerics? private final int X_AXIS = H/2; private final int Y_AXIS = W/2; private int zoom = 5000000; private DataQueue dataQueue, avgQueue; private String lastInfo = ""; private int prevY = 0; private char delta; public Measure() { setSize(W, H); afmSim = new AFMSimulator(); afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], AFMApplet.params[2], AFMApplet.params[3], AFMApplet.params[4], AFMApplet.params[5], AFMApplet.params[6], AFMApplet.params[7], AFMApplet.params[8]); afmSim.resetSim(); image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); backgroundColor = AFMConstants.BG_color; textColor= AFMConstants.text_color; Graphics back = image.getGraphics(); back.setColor(backgroundColor); back.fillRect(0, 0, W, H); back.setColor(textColor); what = 'F'; // defaults to Force delta = (char)(0*4096 + 3*256 + 9*16 + 4); // Unicode for delta is Ɗ (hexadecimal) back.drawString(measuring(what), 400, 20); addMouseMotionListener(new MouseCoordListener()); addMouseListener(new MouseCoordListener()); ind = 0; dataQueue = new DataQueue(); avgQueue = new DataQueue(); } public Measure(int _delay) { this(); delay = _delay; } public void start() { if (myThread != null) stop(); myThread = new Thread(this); myThread.start(); drawAxes(true); }//end start public void reset() { image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); Graphics back = image.getGraphics(); back.setColor(backgroundColor); back.fillRect(0, 0, W, H); back.setColor(textColor); back.drawString(measuring(what), 400, 20); ind = 0; dataQueue.empty(); avgQueue.empty(); afmSim.setParams(AFMApplet.params[0], AFMApplet.params[1], AFMApplet.params[2], AFMApplet.params[3], AFMApplet.params[4], AFMApplet.params[5], AFMApplet.params[6], AFMApplet.params[7], AFMApplet.params[8]); afmSim.resetSim(); } public void resume() { start(); } public void run() { while (myThread != null) { repaint(); try { Thread.sleep(delay); } catch (InterruptedException e) { this.stop(); } } }//end run public void stop() { myThread = null; } public void cleanup() { myThread = null; afmSim = null; image = null; backgroundColor = null; textColor = null; } public AFMSimulator getState() { return afmSim; } public void clear() { Graphics back = image.getGraphics(); back.setColor(backgroundColor); back.fillRect(0, 0, W, H); back.setColor(textColor); } public void switchDisplay() { clear(); if(plot) plot = false; else plot = true; } public void drawAxes(boolean show) { double x_max = (double) (W - W / 2) * Surface.L / W; // x_center holds *actual* x center value (in the system, not on the display) double y_max = (double) (X_AXIS - 0) / zoom; Color axes_color; if(show) axes_color = AFMConstants.axes_color; else axes_color = backgroundColor; AFMApplet.drawAxes(image, X_AXIS, Y_AXIS, "x", "F", x_max, y_max, zoom, axes_color); } public String measuring(char what) { if(what == 'F') return "Avg. " + delta + "F"; if(what == 'R') return "Friction"; if(what == 'E') return "Energy"; else return "Patience"; } public void measure(char what) { this.what = what; } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { Graphics back = image.getGraphics(); back.setColor(AFMConstants.terminal_color); double[][] roots = afmSim.getRoots(); for(int i=0; i