ann.gui.CartesianPanel

 

CartesianPanel.java is a widget for Cartesian systems. This class extend JPanel.

 

public CartesianPanel()

Default constructor

Postcondition: I have been initialized:

lower-left == (-4.0, -4.0);

upper-right == (4.0, 4.0).

 

public CartesianPanel(Point lowerLeft, Point upperRight)

Explicit Point constructor

Receive: lowerLeft, upperRight, two Point values.

Postcondition: I have been initialized:

lower-left == lowerLeft;

upper-right == upperRight.

 

public CartesianPanel(double minX, double minY, double maxX, double maxY)

Explicit coordinate constructor

Receive: minX, minY, maxX, maxY, four double values.

Postcondition: I have been initialized:

lower-left == (minX, minY);

upper-right == (maxX, maxY).

 

private void setSizeDependentAttributes()

Utility to initialize size-dependent attributes

Precondition: I have a height accessible via getHeight(), and a width accessible via getWidth().

Postcondition: My size-dependent attributes: myRows, myLastRow, myColumns, myColumnsPerX, myRowsPerY, xInterval, and yInterval have been initialized.

 

public int xToColumn(double x)

Map x-value to a grid column

Receive: x, a double

Return: the grid column corresponding to x.

 

public int yToRow(double y)

Map y-value to a grid row

Receive: y, a double

Return: the grid row corresponding to y.

 

public double deltaX()

Get x-value corresponding to 1 grid column

Return: the change in x per column.

 

public double deltaY()

Get y-value corresponding to 1 grid row

Return: the change in y per row.

 

public double minX()

Minimum x-value accessor

Return: my minimum x-value

 

public double minY()

Minimum y-value accessor

Return: my minimum y-value

 

public double maxX()

Maximum x-value accessor

Return: my maximum x-value

 

public double maxY()

Maximum y-value accessor

Return: my maximum y-value

 

public void setAxisVisible(boolean flag)

Mutator for axis visibility

Receive: flag, a boolean value

Postcondition: myAxisVisible == flag && my axis is visible iff myAxisVisible.

 

public boolean getAxisVisible()

Accessor for axis visibility

Return: myAxisVisible

 

public void resetAxis(double minX, double minY, double maxX, double maxY)

Mutator for axis values using coordinates

Receive: minX, minY, maxX, maxY, all double values.

Postcondition: my axes and size-dependent variables and display have been updated according to the parameter values.

 

public void resetAxis(Point lowerLeft, Point upperRight)

Mutator for axis values using Points

Receive: lowerLeft, upperRight, two Point values.

Postcondition: my axes and size-dependent variables and display have been updated according to the parameter values.

 

public void paintComponent(Graphics pen)

Method to draw my axes

Receive: pen, a Graphics object.

Postcondition: I have been drawn, showing axes iff myAxisVisible.

 

public void clear()

Method to "clear" the grid of anything that has been drawn on me (except for my axes).

Postcondition: I have just a set of axes showing.

 

public void setPenColor(Color newColor)

Method to mutate my pen/drawing color

Receive: newColor, a Color value

Postcondition: myPenColor = newColor

 

public Color getPenColor()

Accessor to retrieve my current pen/drawing color

Return: myPenColor

 

Classwide constants and Methods

public final static int AXIS_MARGIN = 32
rows/columns at edge of axis

public final static int AXIS_GAP = 50

rows/columns btwn axis markings

 

public static int round(double number)

Rounding method

Receive: number, a double

Return: the nearest int to number.

 


Back to the package documentation index


Back to the Introduction


Copyright 2000 by Prentice Hall. All rights reserved.