* When the '-' key is pressed, halves the current zoom.
* When the 'z' key is pressed, does a zoom fit.
*/
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
HasViewTransform canvas = (HasViewTransform) e.getComponent();
JComponent comp = (JComponent) e.getComponent();
AffineTransform vt = canvas.viewTransform();
if (c == 'c' || c == 'C') {
Rectangle vb = comp.getBounds();
Rectangle2D db = canvas.dataBounds();
double xmargin = vb.width/vt.getScaleX()-db.getWidth();
double ymargin = vb.height/vt.getScaleY()-db.getHeight();
double tx = db.getMinX()-(xmargin/2);
double ty = db.getMinY()-(ymargin/2);
AffineTransform t = AffineTransform.getScaleInstance(vt.getScaleX(), vt.getScaleY());
t.translate(-tx,-ty);
canvas.viewTransform(t, false);
} else if (c == '+' || c == '=') {
vt.scale(2, 2);
canvas.viewTransform(vt, false);
} else if (c == '-' || c == '_') {
vt.scale(.5,.5);
canvas.viewTransform(vt, false);
} else if (c == 'z' || c == 'Z') {
canvas.zoomFit();
}
}