Implementing BitmapChart
Entrance
has an extensible, Java-based chart system, and it
was easy to write a first BitmapChart implementation (with a
hardwired bitmap) by extending ScatterChart. Here is the code:
/*
*
Copyright (c) 2008 Tod Landis All Rights Reserved
*
Released subject to the GPL, v2
*/
package
com.dbentrance.charts;
import
java.awt.Graphics2D;
import
java.awt.geom.AffineTransform;
import
java.awt.image.BufferedImage;
import
java.io.File;
import
javax.imageio.ImageIO;
/**
*
A BitmapChart is an XY chart drawn on a bitmap.
*/
public
class BitmapChart extends ScatterChart {
// this will be "bitmap"
private String fileName =
"/Users/todlandis/proj/maps/PathfinderMap1024.jpg";
@Override
public void draw(Graphics2D g) {
File f = new File(fileName);
try {
BufferedImage bi = ImageIO.read(f);
g.drawImage(bi, new
AffineTransform(), null);
setClearBackground(false);
getXAxis().setDrawAxis(false);
getYAxis().setDrawAxis(false);
super.draw(g);
} catch(Exception e) {
System.err.println(e);
}
}
@Override
public void calculateFrame(Graphics2D g) {
setFrame(0, 0, 1024, 512);
setFrameToFit(false);
}
}
With small changes, eg. to allow the user to set the bitmap, this
became BitmapChart in Entrance.
BitmapChart
is in turn extended by EarthChart, which draws an image of the Earth
and makes it easy to plot lat,lon points onto it. You'll
find source for ScatterChart, BitmapChart, and EarthChart in the
Entrance community download.