/* * SpaceCanvas.java * * Created on October 29, 2005, 8:53 AM */ package Current.popups.WhereAmI; import Current.gui.*; import Current.basic.*; import Current.manage.*; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.util.*; /** * * @author pat */ public class WhereAmICanvas extends DBCanvas implements MouseListener { Manager M; // the view being highlighted Rectangle2D.Double view; // This Affine Transform takes the viewing area to the [0,1]x[0,1] unit square. AffineTransform square; // This controls user zooming of the canvas AffineTransform zoom; // The resulting transform used for drawing AffineTransform transform; // The inverse of transform AffineTransform inverse; ////////// OBJECTS ListenSquare Doc; // used for painting private Image offscreen; private int width; private int height; // used when a redraw is needed boolean forceRedraw=false; /** Creates a new instance of SpaceCanvas */ public WhereAmICanvas(Manager M) { this.M=M; M.addListener(this); setFont(new Font("sanserif", Font.PLAIN, 12)); // set width and height to dummy values: width=height=0; zoom=new AffineTransform(); ////////// COLORS setBackground(new Color(0,0,50)); ////////// OBJECTS Doc=new ListenSquare(0,0,12,12,Color.black); Doc.on=1; view=M.getViewingRectangle(); addMouseListener(this); setSize(200,200); } public void mcbCleanup() { M.remove(this); } /** Reset the main AffineTransform * This should be called after zooming in or out * and after resizing the canvas */ public void resetTransform(){ transform=new AffineTransform(square); transform.concatenate(zoom); try { inverse=transform.createInverse(); } catch (Exception e) { System.out.println("Non-invertible transform exception. This error should never happen"); } } /** Create the AffineTransform, square, * which sends the [0,1]x[0,1] square to the interior of canvas. * It adds a 5% border. */ public void resetSquare(){ int width=this.width-1, height=this.height-1; // set transform to be the identity affine transform square=new AffineTransform(); int size; if (width