edu.msoe.se1010.winPlotter
Class WinPlotter

java.lang.Object
  extended by edu.msoe.se1010.winPlotter.WinPlotter

public class WinPlotter
extends java.lang.Object

WinPlotter - a programmable drawing window class.

Version:
2009.12.8
Author:
hornick

Constructor Summary
WinPlotter()
          Default constructor.
 
Method Summary
 void drawPoint(double x, double y)
          Draws a point at the specified logical coordinates using the current pen color
 void drawTo(double x, double y)
          Draws a line from the current pen position to the specified logical coordinates, using the current pen color.
 void erase()
          Erases the contents of the current WinPlotter window
 void moveTo(double x, double y)
          Moves the pen from the current pen position to the specified logical coordinates.
 void printAt(double x, double y, java.lang.String text)
          Prints a text string at the specified logical coordinates using the current pen color
 void setBackgroundColor(int red, int green, int blue)
          Sets the background color of the WinPlotter window
 boolean setGrid(boolean showGrid, double xinc, double yinc, java.awt.Color gridColor)
          Specifies whether a grid is to be automatically drawn within the WinPlotter window, and sets the grid increment
 void setPenColor(int red, int green, int blue)
          Sets the pen color used for drawing lines
 boolean setPlotBoundaries(double xmin, double ymin, double xmax, double ymax)
          Sets the logical extents of plotting coordinates, corresponding to the lower left and upper right corners of the window.
 void setVisible(boolean visibilityFlag)
          Hides or displays the WinPlotter window.
 void setWindowListener(java.awt.event.WindowListener wl)
          Registers a WindowListener to the underlying SketchPad JFrame.
 boolean setWindowSize(int width, int height)
          Sets the size of an individual WinPlotter window
 void setWindowTitle(java.lang.String title)
          Sets the title of an individual WinPlotter window
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WinPlotter

public WinPlotter()
Default constructor.

When a new WinPlotter instance is created, its window is initialized to appear at screen coordinates (10,10) with a size of 200 units in both x and y. The background color is initialized to WHITE, and the pen color is initialized to BLACK. The window title is initialized to "A plot of something". The logical boundaries of the window are initialized to (0,0), corresponding to the lower left corner of the window, and (100,100) corresponding to the upper right corner of the window. The pen position is initialized to (0,0) in logical coordinates coordinates extend to the right, while positive y (vertical) coordinates' extend upward.

Note: All WinPlotter objects must be closed before the hosting application program will terminate.

Method Detail

setWindowListener

public void setWindowListener(java.awt.event.WindowListener wl)
Registers a WindowListener to the underlying SketchPad JFrame. WindowListener is an interface that must be implemented by the caller of this method, which can be done by extending the WindowAdapter class (for example). Once registered, the WindowListener methods are called whenever a window event is generated

Parameters:
wl - reference to an object that implements the WindowListener interface.

drawTo

public void drawTo(double x,
                   double y)
Draws a line from the current pen position to the specified logical coordinates, using the current pen color. The current pen position is wherever the last line was drawn to; otherwise wherever the current pen position was moved to via the moveTo() method.

Parameters:
x - - x (horizontal) coordinate of the line endpoint
y - - y (vertical) coordinate of the line endpoint

erase

public void erase()
Erases the contents of the current WinPlotter window


moveTo

public void moveTo(double x,
                   double y)
Moves the pen from the current pen position to the specified logical coordinates. A line drawn subsequently begins at this set of coordinates.

Parameters:
x - - x (horizontal) coordinate of the pen position
y - - y (vertical) coordinate of the pen position

drawPoint

public void drawPoint(double x,
                      double y)
Draws a point at the specified logical coordinates using the current pen color

Parameters:
x - - x (horizontal) coordinate of the point
y - - y (vertical) coordinate of the point

printAt

public void printAt(double x,
                    double y,
                    java.lang.String text)
Prints a text string at the specified logical coordinates using the current pen color

Parameters:
x - - x (horizontal) coordinate of the first character in the string
y - - y (vertical) coordinate of the first character in the string

setBackgroundColor

public void setBackgroundColor(int red,
                               int green,
                               int blue)
Sets the background color of the WinPlotter window

Parameters:
red - - the red component of the color value
green - - the green component of the color value
blue - - the blue component of the color value

background colors are specified as values of primary color components (red, green, blue)

The valid range for values for the color components is 0 - 255. If an invalid value is supplied for a color component, the value 0 is automagically substituted. No error is generated.


setPenColor

public void setPenColor(int red,
                        int green,
                        int blue)
Sets the pen color used for drawing lines

Parameters:
red - - the red component of the color value
green - - the green component of the color value
blue - - the blue component of the color value

Pen colors are specified as values of primary color components (red, green, blue)

The valid range for values for the color components is 0 - 255. If an invalid value is supplied for a color component, the value 0 is automatically substituted. No error is generated.


setWindowSize

public boolean setWindowSize(int width,
                             int height)
Sets the size of an individual WinPlotter window

Parameters:
width - - window width in pixel units
height - - window height in pixel units
Returns:
true if successful; false if invalid (negative) coordinates are specified

setPlotBoundaries

public boolean setPlotBoundaries(double xmin,
                                 double ymin,
                                 double xmax,
                                 double ymax)
Sets the logical extents of plotting coordinates, corresponding to the lower left and upper right corners of the window. Note that logical coordinates can be negative as well as positive, but minimum coordinates must be less than maximum coordinates in any case.

Parameters:
xmin - - minimum x coordinate (corresponding to left window boundary)
ymin - - minimum y coordinate (corresponding to bottom window boundary)
xmax - - maximum x coordinate (corresponding to right window boundary)
ymax - - maximum y coordinate (corresponding to top window boundary)
Returns:
true if successful; false if invalid coordinates are specified.

setGrid

public boolean setGrid(boolean showGrid,
                       double xinc,
                       double yinc,
                       java.awt.Color gridColor)
Specifies whether a grid is to be automatically drawn within the WinPlotter window, and sets the grid increment

Parameters:
showGrid - - flag indicating whether to display a grid
xinc - - grid increment in logical x coordinates
yinc - - grid increment in logical y coordinates
gridColor - - grid color
Returns:
true if successful; false if invalid grid increments (negative or greater than max-min) are specified. Note: no checking is done if showGrid is false

setWindowTitle

public void setWindowTitle(java.lang.String title)
Sets the title of an individual WinPlotter window

Parameters:
title - - the window title

setVisible

public void setVisible(boolean visibilityFlag)
Hides or displays the WinPlotter window. By default, the window is displayed.

Parameters:
visibilityFlag - set this argument to false to hide the window; true to show it