public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform trans = new AffineTransform(); int width = getSize().width; int height = getSize().height; g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, width, height); trans.setTransform(identity); trans.scale(scale, scale); g2d.drawImage(image, trans, this); }
public void mouseDragged(MouseEvent e) { if (e.getModifiers() == modifiers) { Point2D pEndScale = e.getPoint(); double scale = pEndScale.distance(viewOrigin) / pStartScale.distance(viewOrigin); AffineTransform transform = super.plot.getTransform(); transform.setTransform( transform.getScaleX() * scale, transform.getShearY(), transform.getShearX(), transform.getScaleY() * scale, transform.getTranslateX() * scale, transform.getTranslateY() * scale); pStartScale = pEndScale; super.plot.setTransform(transform); } }