ch.aplu.jgamegrid
Class GGPanel

java.lang.Object
  extended by ch.aplu.jgamegrid.GGBackground
      extended by ch.aplu.jgamegrid.GGPanel

public class GGPanel
extends GGBackground

Class derived from GGBackground with a user-definable double coordinate system. All passed coordinates in the drawing methods are user coordinates. Default coordinate system xmin = 0, xmax = 1, ymin = 0, ymax = 1.


Method Summary
 void arc(double radius, double startAngle, double extentAngle, boolean fill)
          Draws an arc with center at current graph position, radius in user x-coordinates, start angle and angle extent.
 void arc(double centerX, double centerY, double radius, double startAngle, double extentAngle, boolean fill)
          Draws an arc with given center coordinates, radius in user x-coordinates, start angle and angle extent.
 void arc(java.awt.geom.Point2D.Double center, double radius, double startAngle, double extentAngle, boolean fill)
          Draws an arc with given center, radius in user x-coordinates, start angle and angle extent.
 void circle(double radius, boolean fill)
          Draws a circle with center at current graph position and given radius in user x-coordinates.
 void circle(double centerX, double centerY, double radius, boolean fill)
          Draws a circle with given center coordinates and given radius in user x-coordinates.
 void circle(java.awt.geom.Point2D.Double center, double radius, boolean fill)
          Draws a circle with given center and given radius in user x-coordinates.
 void clean()
          Clears the frame buffer by painting it with the current background color.
 void color(java.awt.Color color)
          Sets the current paint color.
 void draw(double x, double y)
          Draws a line from current graph position to the given coordinates and sets the graph position to these coordinates.
 void draw(java.awt.geom.Point2D.Double pt)
          Draws a line from current graph position to the given point and sets the graph position to this point.
 void drawText(java.lang.String text, double x, double y)
          Displays the given text at the given user coordinates using the current font.
 void drawText(java.lang.String text, java.awt.geom.Point2D.Double pt)
          Displays the given text at the given point using the current font.
 void erase()
          Same as clear(), but remains the current graph position unchanged.
 void generalPath(java.awt.geom.GeneralPath gp, boolean fill)
          Draws a figure defined by the given GeneralPath.
 double getXmax()
          Returns the right value of the x-coordinate axis.
 double getXmin()
          Returns the left value of the x-coordinate axis.
 double getYmax()
          Returns the top value of the y-coordinate axis.
 double getYmin()
          Returns the bottom value of the y-coordinate axis.
 void image(java.awt.image.BufferedImage bi)
          Draws the given image at position (0, 0) into the background buffer.
 void image(java.awt.image.BufferedImage bi, double x, double y)
          Draws the given image into the background buffer.
 void line(double x1, double y1, double x2, double y2)
          Draws a line from (x1, y1) to (x2, y2)
 void line(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2)
          Draws a line from the first vertext to the second vertex.
 void move(double x, double y)
          Sets the current graph position to the given coordinates (without drawin anything).
 void move(java.awt.geom.Point2D.Double pt)
          Sets the current graph position to the given point (without drawin anything).
 void point()
          Draws a single point at the current graph position.
 void point(double x, double y)
          Draws a single point at given coordinates.
 void point(java.awt.geom.Point2D.Double pt)
          Draws a single point at given coordinates.
 void polygon(double[] x, double[] y, boolean fill)
          Draws a polygon with given vertexes.
 void polygon(java.awt.geom.Point2D.Double[] vertexes, boolean fill)
          Draws a polygon with given vertexes.
 void rectangle(double width, double height, boolean fill)
          Draws a rectangle with center at the current graph position and given width and height.
 void rectangle(double x1, double y1, double x2, double y2, boolean fill)
          Draws/fills a rectangle with given opposite vertexes.
 void rectangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, boolean fill)
          Draws a rectangle with given opposite vertexes.
 void setRefreshEnabled(boolean enabled)
          Enables/disables automatic refresh in all graphics methods of GGPanel.
 java.awt.Point toPixelPoint(java.awt.geom.Point2D.Double pt)
          Transforms horizontal user coordinates to pixel coordinates.
 int toPixelX(double x)
          Transforms horizontal user coordinates to pixel coordinates.
 int toPixelY(double y)
          Transforms vertical user coordinates to pixel coordinates.
 java.awt.geom.Point2D.Double toUserPoint(java.awt.Point ptPix)
          Transforms pixel coordinates to user coordinates.
 double toUserX(int xPix)
          Transforms horizontal pixel coordinates to user coordinates.
 double toUserY(int yPix)
          Transforms vertical pixel coordinates to user coordinates.
 void triangle(double x1, double y1, double x2, double y2, double x3, double y3, boolean fill)
          Draws a triangle with given vertexes.
 void triangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, java.awt.geom.Point2D.Double pt3, boolean fill)
          Draws a triangle with given vertexes.
 void window(double xmin, double xmax, double ymin, double ymax)
          Sets the user coordinate system (x from left to right, y from bottom to top).
 
Methods inherited from class ch.aplu.jgamegrid.GGBackground
clear, clear, drawArc, drawCircle, drawGeneralPath, drawGridLines, drawImage, drawImage, drawImage, drawLine, drawLine, drawPoint, drawPolygon, drawRectangle, drawText, fillArc, fillCell, fillCell, fillCircle, fillGeneralPath, fillPolygon, fillRectangle, getAvailableFontFamilies, getBackgroundImage, getBgColor, getColor, getColor, getContext, getLineWidth, getPaintColor, restore, save, setBgColor, setFont, setLineWidth, setPaintColor, setPaintMode, setXORMode
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toPixelX

public int toPixelX(double x)
Transforms horizontal user coordinates to pixel coordinates.

Parameters:
x - the user x-coordinate
Returns:
the pixel x-coordinate

toPixelY

public int toPixelY(double y)
Transforms vertical user coordinates to pixel coordinates.

Parameters:
y - the user y-coordinate
Returns:
the pixel y-coordinate

toPixelPoint

public java.awt.Point toPixelPoint(java.awt.geom.Point2D.Double pt)
Transforms horizontal user coordinates to pixel coordinates.

Parameters:
pt - the user x-y-coordinates
Returns:
the pixel x-y-coordinate

toUserX

public double toUserX(int xPix)
Transforms horizontal pixel coordinates to user coordinates.

Parameters:
xPix - the pixel x-coordinate
Returns:
the user x-coordinate

toUserY

public double toUserY(int yPix)
Transforms vertical pixel coordinates to user coordinates.

Parameters:
yPix - the pixel x-coordinate
Returns:
the user y-coordinate

toUserPoint

public java.awt.geom.Point2D.Double toUserPoint(java.awt.Point ptPix)
Transforms pixel coordinates to user coordinates.

Parameters:
ptPix - the pixel x-y-coordinates
Returns:
the user x-y-coordinates

window

public void window(double xmin,
                   double xmax,
                   double ymin,
                   double ymax)
Sets the user coordinate system (x from left to right, y from bottom to top).

Parameters:
xmin - x-axis value at left
xmax - x-axis value at right
ymin - y-axis value at bottom
ymax - y-axis value at top

line

public void line(double x1,
                 double y1,
                 double x2,
                 double y2)
Draws a line from (x1, y1) to (x2, y2)

Parameters:
x1 - the x-coordinate of the first vertex.
y1 - the y-coordinate of the first vertex.
x2 - the x-coordinate of the second vertex.
y2 - the y-coordinate of the second vertex.

line

public void line(java.awt.geom.Point2D.Double pt1,
                 java.awt.geom.Point2D.Double pt2)
Draws a line from the first vertext to the second vertex.

Parameters:
pt1 - the first vertex
pt2 - the second vertex

image

public void image(java.awt.image.BufferedImage bi,
                  double x,
                  double y)
Draws the given image into the background buffer.

Parameters:
x - x-coordinate of upper left vertex
y - y-coordinate of upper left vertex

image

public void image(java.awt.image.BufferedImage bi)
Draws the given image at position (0, 0) into the background buffer.


move

public void move(double x,
                 double y)
Sets the current graph position to the given coordinates (without drawin anything).

Parameters:
x - the x-coordinate of the graph position
y - the y-coordinate of the graph position

move

public void move(java.awt.geom.Point2D.Double pt)
Sets the current graph position to the given point (without drawin anything).

Parameters:
pt - the new graph position

draw

public void draw(double x,
                 double y)
Draws a line from current graph position to the given coordinates and sets the graph position to these coordinates.

Parameters:
x - the x-coordinate of the end point
y - the y-coordinate of the end point

draw

public void draw(java.awt.geom.Point2D.Double pt)
Draws a line from current graph position to the given point and sets the graph position to this point.

Parameters:
pt - the end point

circle

public void circle(double centerX,
                   double centerY,
                   double radius,
                   boolean fill)
Draws a circle with given center coordinates and given radius in user x-coordinates. The graph position is unchanged.

Parameters:
centerX - the x-coordinate of the center
centerY - the y-coordinate of the center
radius - the radius in x-coordinate units
fill - if true, the shape is filled

circle

public void circle(java.awt.geom.Point2D.Double center,
                   double radius,
                   boolean fill)
Draws a circle with given center and given radius in user x-coordinates. The graph position is unchanged.

Parameters:
center - the center of the circle
radius - the radius in x-coordinate units
fill - if true, the shape is filled

circle

public void circle(double radius,
                   boolean fill)
Draws a circle with center at current graph position and given radius in user x-coordinates. The graph position is unchanged.

Parameters:
radius - the radius in x-coordinate units
fill - if true, the shape is filled

rectangle

public void rectangle(double x1,
                      double y1,
                      double x2,
                      double y2,
                      boolean fill)
Draws/fills a rectangle with given opposite vertexes. and given width and height. The graph position is unchanged.

Parameters:
x1 - x-coordinate of the first vertex
y1 - y-coordinate of the first vertex
x2 - x-coordinate of the opposite vertex
y2 - y-coordinate of the opposite vertex
fill - if true, the shape is filled

rectangle

public void rectangle(java.awt.geom.Point2D.Double pt1,
                      java.awt.geom.Point2D.Double pt2,
                      boolean fill)
Draws a rectangle with given opposite vertexes. The graph position is unchanged.

Parameters:
pt1 - the first vertex
pt2 - the opposite vertex
fill - if true, the shape is filled

rectangle

public void rectangle(double width,
                      double height,
                      boolean fill)
Draws a rectangle with center at the current graph position and given width and height. The graph position is unchanged.

Parameters:
width - the width of the rectangle
height - the height of the rectangle
fill - if true, the shape is filled

arc

public void arc(double centerX,
                double centerY,
                double radius,
                double startAngle,
                double extentAngle,
                boolean fill)
Draws an arc with given center coordinates, radius in user x-coordinates, start angle and angle extent. The graph position is unchanged.

Parameters:
centerX - the x-coordinate of the center
centerY - the y-coordinate of the center
radius - the radius in x-coordinate units
startAngle - the start angle in degrees (zero at east, positive counter-clockwise)
extentAngle - the angle extent in degrees
fill - if true, the shape is filled

arc

public void arc(java.awt.geom.Point2D.Double center,
                double radius,
                double startAngle,
                double extentAngle,
                boolean fill)
Draws an arc with given center, radius in user x-coordinates, start angle and angle extent. The graph position is unchanged.

Parameters:
center - the center of the arc
radius - the radius in x-coordinate units
startAngle - the start angle in degrees (zero at east, positive counter-clockwise)
extentAngle - the angle extent of the arc in degrees
fill - if true, the shape is filled

arc

public void arc(double radius,
                double startAngle,
                double extentAngle,
                boolean fill)
Draws an arc with center at current graph position, radius in user x-coordinates, start angle and angle extent. The graph position is unchanged.

Parameters:
radius - the radius in x-coordinate units
startAngle - the start angle in degrees (zero at east, positive counter-clockwise)
extentAngle - the angle extent of the arc in degrees
fill - if true, the shape is filled

polygon

public void polygon(double[] x,
                    double[] y,
                    boolean fill)
Draws a polygon with given vertexes. (Both arrays must be of equal size.) The graph position is unchanged.

Parameters:
x - an array of the x-coordinates of the vertexes
y - an array of the y-coordinates of the vertexes
fill - if true, the shape is filled

polygon

public void polygon(java.awt.geom.Point2D.Double[] vertexes,
                    boolean fill)
Draws a polygon with given vertexes. The graph position is unchanged.

Parameters:
vertexes - an array of the vertexes
fill - if true, the shape is filled

triangle

public void triangle(double x1,
                     double y1,
                     double x2,
                     double y2,
                     double x3,
                     double y3,
                     boolean fill)
Draws a triangle with given vertexes. The graph position is unchanged.

Parameters:
x1 - the x-coordinate of the first vertex
y1 - the y-coordinate of the first vertex
x2 - the x-coordinate of the second vertex
y2 - the y-coordinate of the second vertex
x3 - the x-coordinate of the third vertex
y3 - the y-coordinate of the third vertex
fill - if true, the shape is filled

triangle

public void triangle(java.awt.geom.Point2D.Double pt1,
                     java.awt.geom.Point2D.Double pt2,
                     java.awt.geom.Point2D.Double pt3,
                     boolean fill)
Draws a triangle with given vertexes. The graph position is unchanged.

Parameters:
pt1 - the first vertex
pt2 - the second vertex
pt3 - the third vertex
fill - if true, the shape is filled

generalPath

public void generalPath(java.awt.geom.GeneralPath gp,
                        boolean fill)
Draws a figure defined by the given GeneralPath. The graph position is unchanged.

Parameters:
gp - the GeneralPath that defines the shape
fill - if true, the shape is filled

point

public void point(double x,
                  double y)
Draws a single point at given coordinates.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point

point

public void point(java.awt.geom.Point2D.Double pt)
Draws a single point at given coordinates.

Parameters:
pt - the point where to draw

point

public void point()
Draws a single point at the current graph position.


drawText

public void drawText(java.lang.String text,
                     double x,
                     double y)
Displays the given text at the given user coordinates using the current font.

Parameters:
text - the text to display
x - the x-coordinate of the start point of the text baseline
y - the y-coordinate of the start point of the text baseline

drawText

public void drawText(java.lang.String text,
                     java.awt.geom.Point2D.Double pt)
Displays the given text at the given point using the current font.

Parameters:
text - the text to display
pt - the start point of the text baseline

clean

public void clean()
Clears the frame buffer by painting it with the current background color. Draws an available background image and the grid lines into the frame buffer. Sets the current graph position to (0, 0). Renders the frame buffer to the screen unless setRefreshEnabled(false) was called.


erase

public void erase()
Same as clear(), but remains the current graph position unchanged.


getXmin

public double getXmin()
Returns the left value of the x-coordinate axis.

Returns:
xmin

getXmax

public double getXmax()
Returns the right value of the x-coordinate axis.

Returns:
xmax

getYmin

public double getYmin()
Returns the bottom value of the y-coordinate axis.

Returns:
xmin

getYmax

public double getYmax()
Returns the top value of the y-coordinate axis.

Returns:
xmin

color

public void color(java.awt.Color color)
Sets the current paint color.

Parameters:
color - the new paint color

setRefreshEnabled

public void setRefreshEnabled(boolean enabled)
Enables/disables automatic refresh in all graphics methods of GGPanel.

Parameters:
enabled - if true, refresh is enabled (default); otherwise no refresh is done