/* TO DO: * Canvas resizing isn't handled by the grid(could be zoom, or complete redraw) * PALLETTE!! * Undo feature * Dump to file (Needs Review) * 3D!! */ //Global imports of external JRE libraries and event handlers import objectdraw.*; import java.awt.*; import java.io.*; import java.lang.*; import java.util.*; import java.applet.*; // Extend WindowsController to allow drawing to a canvas public class guicode extends WindowController { public FilledOval Ball; //the ball Location lastMouse; /* Draw the grid in gray for reference. Creates an array of lines * which span the canvas via one loop; makes a 10x10 grid. */ private FilledRect X_Grid; private FilledRect Y_Grid; public void onMouseEnter(Location p) { int i = 0; while (i <= canvas.getWidth()) { X_Grid = new FilledRect(i,0,1,canvas.getHeight(),canvas); X_Grid.setColor(Color.GRAY); X_Grid.sendToBack(); Y_Grid = new FilledRect(0,i,canvas.getWidth(),1,canvas); Y_Grid.setColor(Color.GRAY); Y_Grid.sendToBack(); i+=canvas.getWidth()/10; } } public void onMouseExit(Location p) { canvas.clear(); } /* Create a new ball everytime the mouse is clicked. The real cool part is that * the center of the ball is automagically moved to the nearest grid point. */ public void onMouseClick(Location p) { /* perhaps width# should be in an array, or even stored in a file to allow * for multiple "balls" in the future. We will need this for the * proteins(different atoms=>different sizes). */ int width1; width1 = 7; FilledOval Ball = new FilledOval(p.getX()-3.5,p.getY()-3.5,width1,width1,canvas); Ball.setColor(Color.RED); Ball.moveTo((canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10))-(width1/2),(canvas.getWidth()/10)*Math.round(p.getY()/(canvas.getWidth()/10))-(width1/2)); Ball.sendToFront(); } // Create an undo function here /* Make sticks to connect the balls we have. The most important * statement creates a way for the stick to be either going in * the X direction or the Y direction, but not both. */ public void onMousePress(Location point) { lastMouse = point; } public void onMouseDrag(Location p) { if ( (Math.abs(lastMouse.getX()-p.getX()))