/* * Created on 8.2.2005 * */ package viewer; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; /** * @author Matti Paalanen * * DrawCanvas represents the drawable surface into which all the information is also * painted. * * There are two distinct DrawCanvases used in the Applet. The one the user can draw upon and trigger animations with the buttons * and the second one, that is used to visualize the function - the one into which the points are mapped via the defined function. * First one is set as drawable, second one not. * */ public class DrawCanvas extends Canvas implements MouseMotionListener, MouseListener { public boolean sweepMode; public boolean fillMode; public boolean gridMode; private int sweepLine; private int lineMode; public boolean connectLines = true; private ViewerApplet owner; private Image buffer; //for double-buffering (efficient paint-operations) private Graphics buf; //for double-buffering public ArrayList objects = new ArrayList(); public double prevX; public double prevY; public boolean drawable; public static AlphaComposite alpha = makeComposite(0.3f); public DrawCanvas(ViewerApplet owner, boolean drawable) { super(); this.owner = owner; this.drawable = drawable; addMouseMotionListener(this); addMouseListener(this); } private static AlphaComposite makeComposite(float alpha) { int type = AlphaComposite.SRC_OVER; return(AlphaComposite.getInstance(type, alpha)); } public void paint(Graphics g) { int h = getHeight(); int w = getWidth(); int[] areaSize = {w, h}; double[] limits = owner.getSourceLimits(this); //Initialize double-buffering. Inside paint operation for insurance. if(buffer==null||(buffer.getWidth(this) 0 && ((Drawable)objects.get(0)).getColor() != null) ((Graphics2D)buf).setComposite(alpha); for(int i=0;i