All pastes #432425 Raw Edit

ProteinGUI_Monmouth

public java v1 · immutable
·published 2007-04-10 07:12 UTC
rendered paste body
/* 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 handlersimport objectdraw.*;import java.awt.*;import java.io.*;import java.lang.*;import java.util.*;import java.applet.*;// Extend WindowsController to allow drawing to a canvaspublic 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()))<Math.abs((lastMouse.getY()-p.getY())) )  		{ 	 		FilledRect Stick = new FilledRect((canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10))-1.5,(canvas.getWidth()/10)*Math.round(p.getY()/(canvas.getWidth()/10)),3,(canvas.getWidth()/10),canvas); 	 		Stick.setColor(Color.BLACK); 	 		Stick.sendToBack(); 		}	 		else 		{ 		 	 		FilledRect Stick = new FilledRect((canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10)),(canvas.getWidth()/10)*Math.round(p.getY()/(canvas.getWidth()/10))-1.5,(canvas.getWidth()/10),3,canvas); 	 		Stick.setColor(Color.BLACK); 	 		Stick.sendToBack(); 		} 		}	}//END CLASS//Begin a new input output class. Should try to dump to the Text Document/* public class ReadfromFile    {	public void main(String args[]) 		{		FileOutputStream fileout;		try 			{			fileout = new FileOutputStream ("dump.txt");			new PrintStream (fileout).print("Hello World!");			fileout.close();			} 		catch (IOException e)			{			System.err.println("You have an error, revise your code please");			System.exit(-1);			}		}}*/