org.rosuda.javaGD
Class GDInterface

java.lang.Object
  extended by org.rosuda.javaGD.GDInterface
Direct Known Subclasses:
DeviceInterface, GDPreviewJPanel, iGD, JavaGD, JavaGD

public class GDInterface
extends java.lang.Object

CGInterface defines an interface (and provides a simple implementation) between the JavaGD R device and the Java code. Any back-end that desires to display R graphics in Java can subclass this class are provide its name to JavaGD package via JAVAGD_CLASS_NAME environment variable. The default implementation handles most callbacks, but subclasses should override at least gdOpen(double, double) to create an instance of GDContainer c which will be used for all subsequent drawing.

external API: those methods are called via JNI from the GD C code

 public void     gdOpen(int devNr, double w, double h);
 public void     gdActivate();
 public void     gdCircle(double x, double y, double r);
 public void     gdClip(double x0, double x1, double y0, double y1);
 public void     gdClose();
 public void     gdDeactivate();
 public void     gdFlush(boolean flush);
 public void     gdHold();
 public double[] gdLocator();
 public void     gdLine(double x1, double y1, double x2, double y2);
 public double[] gdMetricInfo(int ch);
 public void     gdMode(int mode);
 public void     gdNewPage(int deviceNumber);
 public void     gdPath(int npoly, int[] nper, double[] x, double[] y, int mode);
 public void     gdPolygon(int n, double[] x, double[] y);
 public void     gdPolyline(int n, double[] x, double[] y);
 public void     gdRaster(byte img[], int img_w, int img_h, double x, double y, double w, double h, double rot, boolean interpolate);
 public void     gdRect(double x0, double y0, double x1, double y1);
 public double[] gdSize();
 public double   gdStrWidth(String str);
 public void     gdText(double x, double y, String str, double rot, double hadj);
 

GDC - manipulation of the current graphics state

 public void gdcSetColor(int cc);
 public void gdcSetFill(int cc);
 public void gdcSetLine(double lwd, int lty);
 public void gdcSetFont(double cex, double ps, double lineheight, int fontface, String fontfamily);
 


Field Summary
 boolean active
          flag indicating whether this device is active (current) in R
 GDContainer c
          container that will receive all drawing methods.
 boolean holding
          flag indicating whether hold is in progress
 LocatorSync ls
          synchronization object for locator calls
 boolean open
          flag indicating whether this device has currently an open instance
 
Constructor Summary
GDInterface()
           
 
Method Summary
 void executeDevOff()
          close the device in R associted with this instance
 void gdActivate()
          the device became active (current)
 void gdCircle(double x, double y, double r)
          draw a circle
 void gdClip(double x0, double x1, double y0, double y1)
          clip drawing to the specified region
 void gdClose()
          close the display
 void gdcSetColor(int cc)
          set drawing color
 void gdcSetFill(int cc)
          set fill color
 void gdcSetFont(double cex, double ps, double lineheight, int fontface, java.lang.String fontfamily)
          set current font
 void gdcSetLine(double lwd, int lty)
          set line width and type
 void gdDeactivate()
          the device became inactive (i.e. another device is now current)
 void gdFlush(boolean flush)
          hold/flush
 void gdHold()
          (unimplemented - this call is now obsolete in R)
 void gdLine(double x1, double y1, double x2, double y2)
          draw a line
 double[] gdLocator()
          invoke the locator
 double[] gdMetricInfo(int ch)
          retrieve font metrics info for the given unicode character
 void gdMode(int mode)
          R signalled a mode change
 void gdNewPage()
          create a new, blank page (old API, not used anymore)
 void gdNewPage(int devNr)
          create a new, blank page
 void gdOpen(double w, double h)
          requests a new device of the specified size
 void gdPath(int npoly, int[] nper, double[] x, double[] y, boolean winding)
          create multi-polygon path
 void gdPolygon(int n, double[] x, double[] y)
           
 void gdPolyline(int n, double[] x, double[] y)
           
 void gdRaster(byte[] img, int img_w, int img_h, double x, double y, double w, double h, double rot, boolean interpolate)
           
 void gdRect(double x0, double y0, double x1, double y1)
           
 double[] gdSize()
          retrieve the current size of the device
 double gdStrWidth(java.lang.String str)
          retrieve width of the given text when drawn in the current font
 void gdText(double x, double y, java.lang.String str, double rot, double hadj)
          draw text
 int getDeviceNumber()
          returns the device number
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

active

public boolean active
flag indicating whether this device is active (current) in R


open

public boolean open
flag indicating whether this device has currently an open instance


holding

public boolean holding
flag indicating whether hold is in progress


c

public GDContainer c
container that will receive all drawing methods. It should be created by subclasses in the gdOpen(double, double) method.


ls

public LocatorSync ls
synchronization object for locator calls

Constructor Detail

GDInterface

public GDInterface()
Method Detail

gdOpen

public void gdOpen(double w,
                   double h)
requests a new device of the specified size

Parameters:
w - width of the device
h - height of the device

gdActivate

public void gdActivate()
the device became active (current)


gdCircle

public void gdCircle(double x,
                     double y,
                     double r)
draw a circle

Parameters:
x - x coordinate of the center
y - y coordinate of the center
r - radius

gdClip

public void gdClip(double x0,
                   double x1,
                   double y0,
                   double y1)
clip drawing to the specified region

Parameters:
x0 - left coordinate
x1 - right coordinate
y0 - top coordinate
y1 - bottom coordinate

gdClose

public void gdClose()
close the display


gdDeactivate

public void gdDeactivate()
the device became inactive (i.e. another device is now current)


gdHold

public void gdHold()
(unimplemented - this call is now obsolete in R)


gdFlush

public void gdFlush(boolean flush)
hold/flush

Parameters:
flush - if false then the device started holding and no updates should be shown on screen, if true then the device should flush right away and resume normal operation after than. Note that the flush must either be synchronous, or it must be guaranteed that shown content will be identical to the state up till now, otherwise the device will break animations.

gdLocator

public double[] gdLocator()
invoke the locator

Returns:
array of indices or null is cancelled

gdLine

public void gdLine(double x1,
                   double y1,
                   double x2,
                   double y2)
draw a line

Parameters:
x1 - x coordinate of the origin
y1 - y coordinate of the origin
x2 - x coordinate of the end
y2 - y coordinate of the end

gdMetricInfo

public double[] gdMetricInfo(int ch)
retrieve font metrics info for the given unicode character

Parameters:
ch - character (encoding may depend on the font type)
Returns:
an array consisting for three doubles: ascent, descent and width

gdMode

public void gdMode(int mode)
R signalled a mode change

Parameters:
mode - mode as signalled by R (currently 0=R stopped drawing, 1=R started drawing, 2=graphical input exists)

gdNewPage

public void gdNewPage()
create a new, blank page (old API, not used anymore)


gdNewPage

public void gdNewPage(int devNr)
create a new, blank page

Parameters:
devNr - device number assigned to this device by R

gdPath

public void gdPath(int npoly,
                   int[] nper,
                   double[] x,
                   double[] y,
                   boolean winding)
create multi-polygon path

Parameters:
winding: - use winding rule (true) or odd-even rule (false)

gdPolygon

public void gdPolygon(int n,
                      double[] x,
                      double[] y)

gdPolyline

public void gdPolyline(int n,
                       double[] x,
                       double[] y)

gdRect

public void gdRect(double x0,
                   double y0,
                   double x1,
                   double y1)

gdRaster

public void gdRaster(byte[] img,
                     int img_w,
                     int img_h,
                     double x,
                     double y,
                     double w,
                     double h,
                     double rot,
                     boolean interpolate)

gdSize

public double[] gdSize()
retrieve the current size of the device

Returns:
an array of four doubles: 0, width, height, 0

gdStrWidth

public double gdStrWidth(java.lang.String str)
retrieve width of the given text when drawn in the current font

Parameters:
str - text
Returns:
width of the text

gdText

public void gdText(double x,
                   double y,
                   java.lang.String str,
                   double rot,
                   double hadj)
draw text

Parameters:
x - x coordinate of the origin
y - y coordinate of the origin
str - text to draw
rot - rotation (in degrees)
hadj - horizontal adjustment with respect to the text size (0=left-aligned wrt origin, 0.5=centered, 1=right-aligned wrt origin)

gdcSetColor

public void gdcSetColor(int cc)
set drawing color

Parameters:
cc - color

gdcSetFill

public void gdcSetFill(int cc)
set fill color

Parameters:
cc - color

gdcSetLine

public void gdcSetLine(double lwd,
                       int lty)
set line width and type

Parameters:
lwd - line width (see lwd parameter in R)
lty - line type (see lty parameter in R)

gdcSetFont

public void gdcSetFont(double cex,
                       double ps,
                       double lineheight,
                       int fontface,
                       java.lang.String fontfamily)
set current font

Parameters:
cex - character expansion (see cex parameter in R)
ps - point size (see ps parameter in R - for all practical purposes the requested font size in points is cex * ps)
lineheight - line height
fontface - font face (see font parameter in R: 1=plain, 2=bold, 3=italic, 4=bold-italic, 5=symbol)
fontfamily - font family (see family parameter in R)

getDeviceNumber

public int getDeviceNumber()
returns the device number

Returns:
device number or -1 is unknown

executeDevOff

public void executeDevOff()
close the device in R associted with this instance