1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.*;
4 import java.awt.geom.*;
5 import java.util.*;
6
7 public class PrefTrans extends PrefEditor implements java.io.Serializable,ActionListener {
8
9 private static final long serialVersionUID = Version.getSUID();
10
11 public static String ALIGN = "Align";
12 public static String UNALIGN = "UnAlign";
13 public static String ZERO = "Zero";
14
15 public double x = 0;
16 public double y = 0;
17 public double scale = 1;
18 public double angle = 0;
19
20 CompPane cpane = null;
21 Scale scalebar = null;
22 Rose rose = null;
23
24 ViewTransform target = null;
25 double xoff=0,yoff=0;
26
27 public PrefTrans() {
28 name = "Transform";
29 }
30
31
47
48 public PrefTrans(ViewTransform target) {
49 pane=null;
50 setTarget(target);
51 }
52
53 void setTarget(ViewTransform target) {
54 this.target = target;
55 x = target.getTranslateX();
56 y = target.getTranslateY();
57 scale = target.scale;
58 angle = target.angle*180/Math.PI;
59
60
61
62 if (target.aligner!=null) {
63 x -= target.oldx;
64 y -= target.oldy;
65 scale /= target.oldscale;
66 angle -= target.oldangle*180/Math.PI;
67
68 }
69
70 while (angle < 0) angle += 360;
71 while (angle > 360) angle -= 360;
72 }
73
74 public PrefTrans(Scale scalebar,Rose rose,CompPane cpane) {
75 target=null;
76 this.cpane = cpane;
77 Point2D pos = cpane.getCenter();
78 x = 0;
79 y = 0;
80 this.scalebar = scalebar;
81 scale = scalebar.fact;
82 this.rose = rose;
83 angle = rose.theta*180/Math.PI;
84
85 }
86
87 JTextField xfield = null;
88 JTextField yfield = null;
89 JTextField scalefield = null;
90 JTextField rotfield = null;
91
92 public void actionPerformed(ActionEvent e) {
93 String command = ((AbstractButton)e.getSource()).getActionCommand();
94 if (command == ALIGN) {}
95 else if (command == UNALIGN) {
96 if (target!=null && target.hasAlignment()) {
97 target.clearAlignment();
98 setTarget(target);
99 reset();
100 }
101 }
102 else if (command == ZERO) {
103
119 }
120 }
121
122 public void newPane() throws NoSuchFieldException {
123 setup();
124
125 pane.setLayout(new javax.swing.BoxLayout(pane,javax.swing.BoxLayout.Y_AXIS));
126 JPanel sub = new JPanel();
127 sub.setLayout(new GridLayout(2,2));
128
142 pane.add(sub);
143 javax.swing.JPanel controls = new javax.swing.JPanel();
144
145 JButton but = new JButton(ZERO);
146 but.addActionListener(this);
147 controls.add(but);
148
149 if (target!=null) {
150
151
152
153 but = new JButton(UNALIGN);
154 but.addActionListener(this);
155 controls.add(but);
156 }
157
158 pane.add(controls);
159 }
160
161 public void save() {
162 if (pane==null) return;
163 super.save();
164 apply();
165 }
166
167 public void apply() {
168 if (cpane!=null) {
169 rose.change(angle*Math.PI/180);
170 scalebar.change(scale);
171 }
172 if (target!=null) {
173 if (target.aligner!=null) {
174 x += target.oldx;
175 y += target.oldy;
176 scale *= target.oldscale;
177 angle += target.oldangle*180/Math.PI;
178 }
179 target.setTransform(scale,angle*Math.PI/180,x,y);
180 }
181 }
182 }
183