/Users/lyon/j4p/src/j2d/rotator/AffineBean.java
|
1 package j2d.rotator;
2
3 import javax.swing.*;
4 import java.awt.geom.AffineTransform;
5 import java.awt.geom.Point2D;
6 import java.beans.PropertyChangeListener;
7 import java.beans.PropertyChangeSupport;
8
9 /**
10 * Copyright DocJava, inc. User: lyon
11 * <p/>
12 * Date: Dec 10, 2004
13 * <p/>
14 * Time: 6:26:35 PM
15 */
16 public class AffineBean {
17 private JLabel[] sliderLabels = new JLabel[]{new JLabel("Translate X"),
18 new JLabel("Translate Y"),
19 new JLabel("Rotate"),
20 new JLabel("Scale X"),
21 new JLabel("Scale Y"),
22 new JLabel("Shear X"),
23 new JLabel("Shear Y")};
24
25 private Point2D scale = new Point2D.Double(1.0, 1.0);
26 private Point2D shear = new Point2D.Double(0, 0);
27 private double theta = 0;
28 private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
29
30 // The listener list wrapper methods
31 public synchronized void addPropertyChangeListener(
32 PropertyChangeListener pcl) {
33 pcs.addPropertyChangeListener(pcl);
34 }
35
36
37 public AffineTransform getOperation() {
38 AffineTransform at = new AffineTransform();
39
40 for (int i = 0; i < 7; i++) {
41 final JLabel sl = sliderLabels[i];
42 if (sl.getText() ==
43 "Rotate")
44 at.rotate(theta * Math.PI / 180);
45 if (sl.getText() ==
46 "Scale X")
47 at.scale(scale.getX(), 1);
48 if (sl.getText() ==
49 "Scale Y")
50 at.scale(1, scale.getY());
51 if (sl.getText() ==
52 "Shear X")
53 at.shear(shear.getX(), 0);
54 if (sl.getText() ==
55 "Shear Y")
56 at.shear(0, shear.getY());
57 }
58
59 return at;
60 }
61
62 public JLabel[] getSliderLabels() {
63 return sliderLabels;
64 }
65
66 public Point2D getScale() {
67 return scale;
68 }
69
70 public void setScale(Point2D scale) {
71 this.scale = scale;
72 pcs.firePropertyChange("AffineTransform", null, getOperation());
73 }
74
75 public Point2D getShear() {
76 return shear;
77 }
78
79 public void setShear(Point2D shear) {
80 this.shear = shear;
81 pcs.firePropertyChange("AffineTransform", null, getOperation());
82 }
83
84 public double getTheta() {
85 return theta;
86
87 }
88
89 public void setTheta(double theta) {
90 this.theta = theta;
91 pcs.firePropertyChange("AffineTransform", null, getOperation());
92 }
93 }
94