/Users/lyon/j4p/src/j2d/rotator/AffineMediator.java
|
1 package j2d.rotator;
2
3 import gui.ClosableJFrame;
4 import j2d.ImageUtils;
5
6 import javax.swing.*;
7 import java.awt.*;
8 import java.awt.geom.AffineTransform;
9 import java.awt.geom.Point2D;
10
11 /**
12 * Copyright DocJava, inc. User: lyon
13 * <p/>
14 * Date: Dec 10, 2004
15 * <p/>
16 * Time: 7:20:50 PM
17 */
18 public class AffineMediator {
19 protected Image image;
20 protected final AffineBean affineBean = new AffineBean();
21 protected ClosableJFrame controlFrame = new ClosableJFrame("Operations in Descending Order:");
22 protected Point2D location = new Point2D.Float(0, 0);
23 protected Point2D mousePoint = new Point2D.Double(0, 0);
24 private AffineTransform op;
25 protected AffineTransform lastTransform = new AffineTransform();
26 protected AffineTransform priorTransform = new AffineTransform();
27 protected final ImagePanel imagePanel = new ImagePanel();
28
29 protected void getNewImage() {
30 image = ImageUtils.getImage();
31 //Set the mousePoint to the image center
32 mousePoint = new Point(image.getWidth(imagePanel) / 2, image.getHeight(imagePanel) / 2);
33 }
34
35
36 public class ImagePanel extends JPanel {
37 public void paint(Graphics g) {
38 Graphics2D g2 = (Graphics2D) g;
39 Dimension d = getSize();
40 g2.setColor(Color.blue);
41 g2.fillRect(0, 0, d.width, d.height);
42 AffineTransform tr1 = new AffineTransform();
43 AffineTransform tr2 = new AffineTransform();
44 AffineTransform tr3 = new AffineTransform();
45
46 tr1.translate(-mousePoint.getX(), -mousePoint.getY());
47 tr1.concatenate(priorTransform);
48 op = affineBean.getOperation();
49 op.concatenate(tr1);
50 tr2.translate(mousePoint.getX(), mousePoint.getY());
51 tr2.concatenate(op);
52 tr3.translate(location.getX(), location.getY());
53 tr3.concatenate(tr2);
54
55 g2.setTransform(tr3);
56 lastTransform = tr3;
57 if (image == null) return;
58 g2.drawImage(image, 0, 0, this);
59 }
60 }
61 }
62