1
2 package hep.wired.edit;
3
4 import org.freehep.swing.undo.AnimatedCompoundEdit;
5 import org.freehep.swing.undo.LinkableEdit;
6
7 import hep.wired.services.RecordPlot;
8 import hep.wired.services.Edit;
9
10 /***
11 * Class for a compound edit. A compound edit contains a series of edits (which may be
12 * compound edits as well).
13 * This class keeps a reference to the plot when the edit is posted to the plot.
14 *
15 * @author Mark Donszelmann
16 * @version $Id: WiredCompoundEdit.java 674 2005-03-11 04:53:14Z duns $
17 */
18 public class WiredCompoundEdit extends AnimatedCompoundEdit implements Edit {
19
20 private RecordPlot recordPlot;
21
22 private String name;
23
24 /***
25 * Creates an empty composite edit with given name.
26 */
27 public WiredCompoundEdit(String name) {
28 super(name);
29 this.name = name;
30 }
31
32 public String getID() {
33 return getPresentationName();
34 }
35
36 /***
37 * Returns the record plot to which this edit was sent. Returns null if the
38 * edit was not (yet) sent to a plot.
39 */
40 protected RecordPlot getRecordPlot() {
41 return recordPlot;
42 }
43
44 /***
45 * To be called as part of the copy procedure to set the recordPlot variable.
46 */
47 public void setRecordPlot(RecordPlot recordPlot) {
48 this.recordPlot = recordPlot;
49 }
50
51 /***
52 * Creates a copy of the compound edit and its contained edits.
53 * This copy method calls setRecordPlot() on each of them to initialize the
54 * recordPlot variable(s).
55 */
56 public WiredCompoundEdit copy(RecordPlot plot) {
57
58 WiredCompoundEdit copy = new WiredCompoundEdit(getPresentationName());
59 copy.setRecordPlot(plot);
60
61
62 LinkableEdit edit = getFirstEdit();
63 while (edit != null) {
64 if (edit instanceof WiredEdit) {
65 copy.addEdit(((WiredEdit)edit).copy(plot));
66 } else if (edit instanceof WiredCompoundEdit) {
67 copy.addEdit(((WiredCompoundEdit)edit).copy(plot));
68 } else {
69 copy.addEdit(edit);
70 }
71 edit = edit.getNextEdit();
72 }
73 copy.end();
74 return copy;
75 }
76
77 public String toString() {
78 if (name != null) return name;
79 LinkableEdit last = getLastEdit();
80 if (last != null) return last.toString();
81 return super.toString();
82 }
83 }