1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.*;
4 import java.util.*;
5
6 public class Alignment extends PrefEditor implements java.io.Serializable {
7 private static final long serialVersionUID = Version.getSUID();
8
9
10
11 public boolean zerox = false;
12 public boolean zeroy = false;
13 public boolean zerorot = false;
14 public boolean zeroscale = false;
15
16 public boolean distributex = false;
17 public boolean distributey = false;
18
19 public boolean rotation = false;
20 public boolean scale = false;
21 public boolean x = true;
22 public boolean y = true;
23
24 public boolean rotatefirst = true;
25
26
27
28
29
30
31 public Vector targets = null;
32
33 public transient ViewTransform source;
34 public int mask = 0;
35
36 public Alignment() {
37
38 name = "Alignment";
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52
53 transient ViewTransform sel = null;
54
55
56
57
58
59
60
61 public void setSource(Symbol newal) {
62 if (newal == null || !(newal instanceof Aligner))
63 ErrorLog.log("Select exctly one symbol to allign things to.\n"+
64 "(not all things can be aligners\n"+
65 "more will be added in the future)\n"+
66 "Tried to allign to "+newal);
67 else sel = ((Aligner)newal).getAlignTransform();;
68 }
69
70 public void newPane() throws NoSuchFieldException {
71
72
73
74
75 pane.setLayout(new GridLayout(4,4));
76
77 pane.add(new JLabel("Scale"));
78 ButtonGroup group = new ButtonGroup();
79 setParm("scale","Slave");
80 group.add(setRadio(pane,"zeroscale","Resize"));
81 pane.add(new JLabel(""));
82 JRadioButton nochange = new JRadioButton("No Action",!zeroscale);
83 pane.add(nochange);
84 group.add(nochange);
85
86 pane.add(new JLabel("Rotation"));
87 group = new ButtonGroup();
88 setParm("rotation","Slave");
89 group.add(setRadio(pane,"zerorot","Align"));
90 pane.add(new JLabel(""));
91 nochange = new JRadioButton("No action",!zerorot);
92 pane.add(nochange);
93 group.add(nochange);
94
95 pane.add(new JLabel("X"));
96 group = new ButtonGroup();
97 setParm("x","Slave");
98 group.add(setRadio(pane,"zerox","Align"));
99 JRadioButton dist = setRadio(pane,"distributex","Distribute");
100 group.add(dist);
101 dist.setEnabled(targets.size()>1);
102 nochange = new JRadioButton("No action",!zerox && !distributex);
103 pane.add(nochange);
104 group.add(nochange);
105
106 pane.add(new JLabel("Y"));
107 group = new ButtonGroup();
108 setParm("y","Slave");
109 group.add(setRadio(pane,"zerox","Align"));
110 dist = setRadio(pane,"distributey","Distribute");
111 group.add(dist);
112 dist.setEnabled(targets.size()>1);
113 nochange = new JRadioButton("No action",!zerox && !distributex);
114 pane.add(nochange);
115 group.add(nochange);
116
117
118
119
120
121
122
123
124
125 }
126
127 public void save() {
128 if (pane==null) return;
129 super.save();
130 apply();
131 }
132
133 public void apply() {
134 source = sel;
135
136
137
138
139
140 mask =0;
141 if (x) mask+=1;
142 if (y) mask+=2;
143 if (scale) mask+=4;
144 if (rotation) mask+=8;
145
146 source.alignAll(targets,this);
147
148
149 }
150
151 public void setTargets(HashSet newtargets) {
152 targets = new Vector();
153 for (Iterator it = newtargets.iterator();it.hasNext();) {
154 Symbol item = (Symbol)it.next();
155 if (item instanceof Aligner)
156 targets.add(((Aligner)item).getAlignTransform());
157 }
158 }
159 }
160