// Parses a tagged file into a Kinematic Virtual Machine
import java.awt.*;
import java.net.*;
import java.util.*;
//The abstract keyword means that you can NOT declare an object of
//this type. Instead, a class must be made which extends this class,
//which the class GraphicFigure does
public abstract class KVMFile extends KVM
{
TagsVector tags;
//This is a function that returns a String from position i in tags
String tag(int i) { return (String)tags.elementAt(i); }
double x, y, z;
KVMFile(URL context, String URLName) {
//Creating a new TagsVector automatically parses the URL passed to it
tags = new TagsVector(context, URLName);
for (int i = 0 ; i < tags.size() ; i++) {
//These functions are defined in class KVM
if (tag(i).equals("local"))
push();
else if (tag(i).equals("/local"))
pop();
else if (tag(i).equals("joint")) {
++i;
joint(tag(++i));
}
else if (tag(i).equals("moveTo")) {
++i;
//Get coordinates and move (moveTo is defined in GraphicFigure)
parseXYZ(tag(++i));
moveTo(x, y, z);
}
else if (tag(i).equals("lineTo")) {
++i;
//Get coordinates and draw a line (lineTo is defined in GraphicFigure)
parseXYZ(tag(++i));
lineTo(x, y, z);
}
}
}
//Extracts the x, y and z values to draw the figure using substring()
void parseXYZ(String xyzS) {
//indexOf() returns the position of a character in a string
int c1 = xyzS.indexOf(',');
String yzS = xyzS.substring(c1+1);
int c2 = yzS.indexOf(',');
//Creates a new Double object and converts the substring given into a Double
x = (new Double(xyzS.substring(0, c1))).doubleValue();
y = (new Double( yzS.substring(0, c2))).doubleValue();
z = (new Double( yzS.substring(c2+1 ))).doubleValue();
}
}