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    //  static Alignment last = new Alignment();
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   //  public boolean selection = true;
27   //  public boolean absolute = false;
28   //  public boolean datum = false;
29   //  public boolean floating = false;
30   
31     public Vector targets = null;
32   
33     public transient ViewTransform source;
34     public int mask = 0;
35   
36     public Alignment() {
37   //    System.out.println("new alignment");
38       name = "Alignment";
39     }
40   
41   //  public void copy(Alignment that) {
42   //    x = that.x;
43   //    y = that.y;
44   //    zero=that.zero;
45   //    rotation = that.rotation;
46   //    scale = that.scale;
47   //    selection = that.selection;
48   //    absolute = that.absolute;
49   //    datum = that.datum;
50   //    floating = that.floating;
51   //  }
52   
53     transient ViewTransform sel = null;
54   
55   //  public Alignment(Symbol sel) {
56   //    name = "Align";
57   //    this.sel = sel;
58   //    copy(last);
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   //    System.out.println("alignment newpane");
72   //    pane = new javax.swing.Box(BoxLayout.Y_AXIS);
73   
74   //    javax.swing.Box row = new javax.swing.Box(BoxLayout.X_AXIS);
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  //    pane.add(row);
118  
119  //    ButtonGroup group = new ButtonGroup();
120  //    group.add((JRadioButton)setRadio(pane,"absolute","Absolute"));
121  //    group.add((JRadioButton)setRadio(pane,"datum","Datum"));
122  //    group.add((JRadioButton)setRadio(pane,"floating","Float"));
123  //    group.add((JRadioButton)setRadio(pane,"selection","Use Aligner"));
124  //    System.out.println("newpane return");
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  //    if (selection && (sel!=null)) source = sel;
136  //    else if (absolute) source = Aligner.absolute;
137  //    else if (datum) source = Aligner.datum;
138  //    else if (floating) source = Aligner.floating;
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  //    System.out.println("mask ="+mask+" source = "+source);
148  //    last.copy(this);
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