All pastes #433795 Raw Edit

ProteinGUI_Monmouth2

public javascript v1 · immutable
·published 2007-04-11 00:41 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 guicode2 extends WindowController {	public FilledOval Ball; //the ball	Location lastMouse;/* Draw the grid in gray for reference: The loop creates an array of lines * which span the canvas, makes a 10x10 grid. */	private FilledRect X_Grid;	private FilledRect Y_Grid;	public void onMouseEnter(Location p) {		int i = 0;		int j = 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,j,canvas.getWidth(),1,canvas);				Y_Grid.setColor(Color.GRAY);				Y_Grid.sendToBack();				i+=canvas.getWidth()/10;				j+=canvas.getHeight()/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) {		int width;		width = 7; /*	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). */			FilledOval Ball = new FilledOval(				p.getX()-width/2,				p.getY()-width/2,				width,				width,				canvas);		Ball.setColor(Color.RED);		Ball.moveTo(				(canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10))-(width/2),				(canvas.getHeight()/10)*Math.round(p.getY()/(canvas.getHeight()/10))-(width/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())) ) { 			if (p.getY() < lastMouse.getY()) { 				FilledRect Stick = new FilledRect( 						(canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10))-1.5, 						(canvas.getHeight()/10)*Math.round(p.getY()/(canvas.getHeight()/10))-(canvas.getHeight()/10), 						3, 						(canvas.getHeight()/10), 						canvas); 				Stick.setColor(Color.BLACK); 				Stick.sendToBack(); 			} 			else { 				FilledRect Stick = new FilledRect( 						(canvas.getWidth()/10)*Math.round(lastMouse.getX()/(canvas.getWidth()/10))-1.5, 						(canvas.getHeight()/10)*Math.round(lastMouse.getY()/(canvas.getHeight()/10)), 						3, 						(canvas.getHeight()/10), 						canvas); 				Stick.setColor(Color.BLACK); 				Stick.sendToBack(); 			} 		}	 		else if ( (Math.abs(lastMouse.getX()-p.getX()))>Math.abs((lastMouse.getY()-p.getY())) ) {	 			if (p.getX() < lastMouse.getX()) { 				FilledRect Stick = new FilledRect( 						(canvas.getWidth()/10)*Math.round(p.getX()/(canvas.getWidth()/10))-(canvas.getWidth()/10), 						(canvas.getHeight()/10)*Math.round(p.getY()/(canvas.getHeight()/10))-1.5, 						(canvas.getWidth()/10), 						3, 						canvas); 	 	 		Stick.setColor(Color.BLACK); 	 	 		Stick.sendToBack(); 			} 			else { 				FilledRect Stick = new FilledRect( 						(canvas.getWidth()/10)*Math.round(lastMouse.getX()/(canvas.getWidth()/10)), 						(canvas.getHeight()/10)*Math.round(lastMouse.getY()/(canvas.getHeight()/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);			}		}}*/