package Cartesian; import netscape.application.*; /** The Cartesian class provides a way to use Cartesian coordinates for Java windows. * @author John H. Young * @version 1.0.0 * @see C_Point * @see C_Line * @see C_Rectangle */ public class Cartesian { Graphics Canvas; int Width; int Height; /** The constructor receives a Graphics to which the Cartesian class * will become attached, and the size of the window. * @param NewCanvas The Graphics class instance on which the Cartesian coordinates will be imposed. * @param NewExtent The size of the window. */ public Cartesian (Graphics NewCanvas, Rect NewExtent) { Canvas = NewCanvas; Width = NewExtent.width; Height = NewExtent.height; Canvas.setColor (Color.white); Canvas.fillRect (NewExtent); Canvas.setColor (Color.black); } /** This method draws a line from (X1, Y1) to (X2, Y2). * @param X1 Horizontal position of the start of the line. * @param Y1 Vertical position of the start of the line. * @param X2 Horizontal position of the end of the line. * @param Y2 Vertical position of the end of the line. */ public void LineCoord (int X1, int Y1, int X2, int Y2) { Canvas.drawLine (X1, Height - Y1, X2, Height - Y2); } /** This method draws a line from (X1, Y1) to (X2, Y2).  It is equivalent to LineCoord. * @param X1 Horizontal position of the start of the line. * @param Y1 Vertical position of the start of the line. * @param X2 Horizontal position of the end of the line. * @param Y2 Vertical position of the end of the line. */ public void Line (int X1, int Y1, int X2, int Y2) { Canvas.drawLine (X1, Height - Y1, X2, Height - Y2); } /** This method draws a line from C_Point A to C_Point B. * @param A Beginning point of the line. * @param B Ending point of the line. */ public void Line (C_Point A, C_Point B) { Canvas.drawLine (A.X(), Height - A.Y(), B.X(), Height - B.Y()); } /** This method draws a rectangle with lower left corner at (Left, Bottom), and upper right corner at (Right, Top).  * It is equivalent to RectangleCoord. * @param Left Horizontal position of the left side of the rectangle. * @param Bottom Vertical position of the bottom of the rectangle. * @param Right Horizontal position of the right side of the rectangle. * @param Top Vertical position of the top of the rectangle. */ public void Rectangle (int Left, int Bottom, int Right, int Top) { Line (Left, Bottom, Left, Top); Line (Left, Top, Right, Top); Line (Right, Top, Right, Bottom); Line (Right, Bottom, Left, Bottom); } /** This method draws a rectangle with lower left corner at (Left, Bottom), and upper right corner at (Right, Top).  * It is equivalent to Rectangle with integer parameters. * @param Left Horizontal position of the left side of the rectangle. * @param Bottom Vertical position of the bottom of the rectangle. * @param Right Horizontal position of the right side of the rectangle. * @param Top Vertical position of the top of the rectangle. */ public void RectangleCoord (int Left, int Bottom, int Right, int Top) { Line (Left, Bottom, Left, Top); Line (Left, Top, Right, Top); Line (Right, Top, Right, Bottom); Line (Right, Bottom, Left, Bottom); } /** This method draws a rectangle with lower left corner at C_Point BottomLeft, and upper right corner C_Point TopRight.  * It is equivalent to RectanglePt. * @param BottomLeft C_Point at the lower left corner of the rectangle. * @param TopRight C_Point at the upper right corner of the rectangle. */ public void Rectangle (C_Point BottomLeft, C_Point TopRight) { C_Point TopLeft; C_Point BottomRight; TopLeft = new C_Point (BottomLeft.X(), TopRight.Y()); BottomRight = new C_Point (TopRight.X(), BottomLeft.Y()); Line (BottomLeft, TopLeft); Line (TopLeft, TopRight); Line (TopRight, BottomRight); Line (BottomRight, BottomLeft); } /** This method draws a rectangle with lower left corner at C_Point BottomLeft, and upper right corner C_Point TopRight.  * It is equivalent to RectanglePt. * @param BottomLeft C_Point at the lower left corner of the rectangle. * @param TopRight C_Point at the upper right corner of the rectangle. */ public void RectanglePt (C_Point BottomLeft, C_Point TopRight) { C_Point TopLeft; C_Point BottomRight; TopLeft = new C_Point (BottomLeft.X(), TopRight.Y()); BottomRight = new C_Point (TopRight.X(), BottomLeft.Y()); Line (BottomLeft, TopLeft); Line (TopLeft, TopRight); Line (TopRight, BottomRight); Line (BottomRight, BottomLeft); } /** This method draws a closed polygon connecting the points of a VertexList, in order.  * @param VertexCount Number of points in the VertexList. * @param Vertices The list of points. */ public void PolyGon (int VertexCount, VertexList Vertices) { int Cursor; Cursor = 1; while (Cursor < VertexCount) { Line (Vertices.Point (Cursor - 1), Vertices.Point (Cursor)); Cursor = Cursor + 1; } Line (Vertices.Point (Cursor - 1), Vertices.Point (0)); } /** This method draws lines connecting the points of a VertexList, in order.  * @param VertexCount Number of points in the VertexList. * @param Vertices The list of points. */ public void PolyLine (int VertexCount, VertexList Vertices) { int Cursor; Cursor = 1; while (Cursor < VertexCount) { Line (Vertices.Point (Cursor - 1), Vertices.Point (Cursor)); Cursor = Cursor + 1; } } /** This method draws lines connecting the points of a VertexList, in order.  * @param VertexCount Number of points in the VertexList. * @param X The list of horizontal positions. * @param Y The list of vertical positions. */ public void PolyLine (int VertexCount, VertexCoordinateList X, VertexCoordinateList Y) { int Cursor; Cursor = 1; while (Cursor < VertexCount) { Line (X.Get (Cursor - 1), Y.Get (Cursor - 1), X.Get (Cursor), Y.Get (Cursor)); Cursor = Cursor + 1; } } /** This method draws lines connecting the points of a VertexList, in order.  * @param VertexCount Number of points in the VertexList. * @param X The list of horizontal positions. * @param Y The list of vertical positions. */ public void PolyLineCoord (int VertexCount, VertexCoordinateList X, VertexCoordinateList Y) { PolyLine (VertexCount, X, Y); } /** This method draws text from the string, with the lower left corner at point LL.  * @param LL Lower Left corner of the text * @param Words The text to be drawn */ public void Text (C_Point LL, String Words) { Canvas.drawString (Words, LL.X(), Height - LL.Y()); } public void String (int x, int y, String Text) { Canvas.drawString (Text, x, Height - y); } /** This method sets the drawing color for future calls.  * @param NewColor The new color. */ public void SetColor (Color NewColor) { Canvas.setColor (NewColor); } }