package jas.plot.java1; import jas.plot.SetablePlotGraphics; import jas.plot.Transformation; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Image; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; public class PlotGraphics11 implements SetablePlotGraphics { private Transformation xt, yt; private Graphics g; private Shape oldClip; public void setStroke(Stroke s) { // no-op } public void setGraphics(Graphics g) { this.g = g; if (g == null) { oldClip = null; } else { oldClip = g.getClip(); } clearTransformation(); } public void setTransformation(Transformation x, Transformation y) { xt = x == null ? defaultTransformation : x; yt = y == null ? defaultTransformation : y; } public void clearTransformation() { xt = defaultTransformation; yt = defaultTransformation; } private final static Transformation defaultTransformation = new Transformation() { public double convert(double value) { return value; } }; public void setClip(int xmin, int xmax, int ymin, int ymax) { g.clipRect(xmin,ymax,xmax-xmin,ymin-ymax); } public void clearClip() { g.setClip(oldClip); } public void drawLine(double x1, double y1, double x2, double y2) { int ix1 = (int) xt.convert(x1); int ix2 = (int) xt.convert(x2); int iy1 = (int) yt.convert(y1); int iy2 = (int) yt.convert(y2); g.drawLine(ix1,iy1,ix2,iy2); } public void drawPolyLine(double[] x, double[] y, int n) { polyConvert(x,y,n); g.drawPolyline(ix,iy,n); } public void fillRect(double x1, double y1, double x2, double y2) { int ix1 = (int) xt.convert(x1); int iy1 = (int) yt.convert(y1); int ix2 = (int) xt.convert(x2); int iy2 = (int) yt.convert(y2); int ixmin = Math.min(ix1,ix2); int ixmax = Math.max(ix1,ix2); int iymin = Math.min(iy1,iy2); int iymax = Math.max(iy1,iy2); // force oval width and height to be at least 1 pixel int w = ixmax-ixmin; if (w < 1.0) w = 1; int h = iymax-iymin; if (h < 1.0) h = 1; g.fillRect(ixmin,iymin,w,h); } public void drawRect(double x1, double y1, double x2, double y2) { int ix1 = (int) xt.convert(x1); int iy1 = (int) yt.convert(y1); int ix2 = (int) xt.convert(x2); int iy2 = (int) yt.convert(y2); int ixmin = Math.min(ix1,ix2); int ixmax = Math.max(ix1,ix2); int iymin = Math.min(iy1,iy2); int iymax = Math.max(iy1,iy2); // force oval width and height to be at least 1 pixel int w = ixmax-ixmin; if (w < 1.0) w = 1; int h = iymax-iymin; if (h < 1.0) h = 1; g.drawRect(ixmin,iymin,w,h); } public void drawOval(double x1, double y1, double x2, double y2) { int ix1 = (int) xt.convert(x1); int iy1 = (int) yt.convert(y1); int ix2 = (int) xt.convert(x2); int iy2 = (int) yt.convert(y2); int ixmin = Math.min(ix1,ix2); int ixmax = Math.max(ix1,ix2); int iymin = Math.min(iy1,iy2); int iymax = Math.max(iy1,iy2); // force oval width and height to be at least 1 pixel int w = ixmax-ixmin; if (w < 1.0) w = 1; int h = iymax-iymin; if (h < 1.0) h = 1; g.drawOval(ixmin,iymin,w,h); } public void setColor(Color c) { g.setColor(c); } public void drawString(String s, double x, double y) { g.drawString(s,(int) xt.convert(x), (int) yt.convert(y)); } public FontMetrics getFontMetrics() { return g.getFontMetrics(); } public void setFont(Font f) { g.setFont(f); } public Font getFont() { return g.getFont(); } public void drawPolySymbol(double[] x, double[] y, double size, int type, int n) { polyConvert(x,y,n); int is = (int) size; for (int i=0; i bufSize) { ix = new int[n]; iy = new int[n]; bufSize = n; } if (xt != defaultTransformation) { for (int i=0; i