[ b a c k   t o   i n d e x ]

package robot_graph;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
/**
 * This is to test RobotGraph.  Will construct it and report it.
 * 
 * Creation date: (11/7/2000 9:32:30 PM)
 * @author: William Martin
 */
public class RobotGraphTester 	extends JFrame implements 
								ActionListener {
	private int p = 100;
	RobotGraph robotGraph;
	jpanel j;
	JButton btn = new JButton("  Make  Graph  ");
	JButton btn1 = new JButton("  Submitt  Text  Field  ");
	JButton btn2 = new JButton("  Draw  The  Vertices  ");
	JButton btn3 = new JButton("  Draw  The  Edges  ");
	JLabel label = new JLabel("Number of Vertices:");
	JLabel label1 = new JLabel("Text Field:");
	JLabel adjadicentLandmarksLabel = new JLabel("Adjadacent Landmarks:");
	JLabel onSameHeadingLabel = new JLabel("We have been on this heading:");
	JTextField tf1 = new JTextField(5);
	JTextField tf = new JTextField(20);
	JTextField onSameHeadingTextField = new JTextField(3);
	JTextField adjadicentLandmarksTextFeld = new JTextField(30);
/**
 * This app. is for visual testing of the Robot Graph Class.
 * Creation date: (11/28/2000 8:40:53 PM)
 */
public RobotGraphTester() {
	super();
	Container contentPane = getContentPane();
	j = new jpanel();
	contentPane.add(j);
	setSize(700, 550);
	setResizable(false);
	setTitle("Robot Graph Tester");
	btn.setHorizontalTextPosition(JButton.LEFT);
	btn.addActionListener(this);
	j.add(btn);
	btn1.setHorizontalTextPosition(JButton.LEFT);
	btn1.addActionListener(this);
	j.add(btn1);
	btn2.setHorizontalTextPosition(JButton.LEFT);
	btn2.addActionListener(this);
	j.add(btn2);
	btn3.setHorizontalTextPosition(JButton.LEFT);
	btn3.addActionListener(this);
	j.add(btn3);
	j.add(label);
	j.add(tf1);
	j.add(label1);
	j.add(tf);
	j.add(onSameHeadingLabel);
	j.add(onSameHeadingTextField);
	j.add(adjadicentLandmarksLabel);
	j.add(adjadicentLandmarksTextFeld);
	tf.setText("No Graph Exists");
}
/**
 * This method serves as a template for our core operations.
 * Creation date: (11/29/2000 4:36:41 PM)
 */
public void actionPerformed(ActionEvent e) {
	Graphics graphics = getGraphics();
	String s = "";
	String s2 = "";
	int scenero, x, y;
/* 	This is how we will make the graph when the robot is 
		started*/
	if ((JButton) e.getSource() == btn) { //Make a graph button
		robotGraph = new RobotGraph();
		tf.setText("New Graph Constructed: " + robotGraph.id());
		tf1.setText(String.valueOf(robotGraph.vertices.size()));
		/* This is how we add events (corners or vertices)*/
	} else
		if (e.getSource() == btn1) { //Submitt text field button
			s = String.valueOf(tf.getText());
			StringTokenizer st = new StringTokenizer(s, " ");
			p = 120;
			while (st.hasMoreTokens()) {
				scenero = Integer.parseInt(st.nextToken());
				x = Integer.parseInt(st.nextToken());
				y = Integer.parseInt(st.nextToken());
				robotGraph.construct(scenero, x, y);// Here is 
													// the call
				try {
					Thread.sleep(100);
				} //slow it down
				catch (Exception err) {
					err.printStackTrace();
				}
				s2 = ("Attempted to insert landmark: " + 
					  scenero + ", " + x + ", " + y);
				graphics.drawString(s2, 10, p);
				p = p + 20;
				tf1.setText(String.valueOf
					(robotGraph.vectorOfVertices().size()));
			}
			tf.setText("DONE");
			graphics.clearRect(0, 100, 600, 680);
			/* 	This is how we will send data to the client and 
			 *	how the client will display it*/
			/*VERTICES*/
		} else
			if (e.getSource() == btn2) {
				for (int i = 0; i < robotGraph.vertices.size(); 
														i++) {
					Vertex v = (Vertex) 
						robotGraph.vertices.elementAt(i);
					int landmark = v.landmark();
					int xi = v.xCoord;
					int yi = v.yCoord;
					DrawLandmark d = new 
						DrawLandmark(graphics, landmark, xi, yi);
				}
				/*EDGES*/
			} else
				if (e.getSource() == btn3) {
					for (int i = 0; i < robotGraph.edges.size();
														i++) {
						Edge edge = (Edge) 
							robotGraph.edges.elementAt(i);
						Vertex v1 = edge.v1;
						Vertex v2 = edge.v2;
						int v1x = v1.xCoord;
						int v1y = v1.yCoord;
						int v2x = v2.xCoord;
						int v2y = v2.yCoord;
						graphics.drawLine(v1x, v1y, v2x, v2y);
						graphics.drawString
								((edge.getLength(v1, v2) + "cm"), 
								((v1.xCoord() + v2.xCoord()) / 2), 
								((v1.yCoord() + v2.yCoord()) / 2)
								+ 20);
					}
					/*CALL TO GET DATA FOR CLIENT*/
				}
	onSameHeadingTextField.setText(String.valueOf
								  (robotGraph.checkHeading()));
	for(int a = 0; a < robotGraph.vertices.size(); a++){
		adjadicentLandmarksTextFeld.setText(" ");
		Vertex v = (Vertex)robotGraph.vertices.elementAt(a);
		adjadicentLandmarksTextFeld.setText
									(v.reportAdjacentPaths());
	}
}
/**
 * Main method. Handle window closing.
 * Creation date: (11/7/2000 9:34:18 PM)
 * @param args java.lang.String[]
 */
public static void main(String[] args) {
	final JFrame f = new RobotGraphTester();
	f.setVisible(true);
	f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	f.addWindowListener(new WindowAdapter(){
		public void windowClosed(WindowEvent e){
			System.exit(0);
		}
	});
}
}