1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import java.awt.*;
4 import fr.ove.openmath.jome.ctrlview.bidim.*;
5 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
6 import fr.ove.openmath.jome.model.*;
7
8 /***
9 * This layout manager lays unary operators.
10 *
11 * @author © 1999 DIRAT Laurent
12 * @version 2.0 14/12/1999
13 */
14 public abstract class UnaryOperatorLayout extends HorizontalLayout implements OperatorDisplayCreator {
15 /***
16 * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
17 * or has to perform some "re-oganisation" before rendering.<BR>
18 * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
19 * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
20 * call super.initDisplay(displayToLay).
21 * @param displayToLay the display laid by the instance
22 */
23 public void initDisplay(Display displayToLay) {
24 super.initDisplay(displayToLay);
25
26
27 FormulaTreeStructure fts = (FormulaTreeStructure) displayToLay.getListener();
28
29 Display displayOperator = createOperatorDisplay();
30
31
32
33
34
35
36
37
38
39 displayOperator.addControlListener(fts);
40
41
42
43
44 this.displayToLay.add(displayOperator);
45
46 this.displayToLay.computeAncestorsAttributes();
47 }
48
49 /***
50 * Checks the validity of the selection.
51 */
52 public void validateSelection() {
53 SelectionEvent selEvt = new SelectionEvent(displayToLay);
54
55
56
57
58 Display op = (Display) displayToLay.getComponent(0);
59 Display opRand = (Display) displayToLay.getComponent(1);
60 if (op.isSelected() || opRand.isSelected()) {
61 displayToLay.select();
62
63 selEvt.setAction(SelectionEvent.PURGE, null);
64 displayToLay.fireSelectionEvent(selEvt);
65
66 selEvt.setAction(SelectionEvent.ADD, displayToLay);
67 displayToLay.fireSelectionEvent(selEvt);
68 }
69
70
71
72 Display display = displayToLay;
73 if (displayToLay.getParent() instanceof Display) {
74 display = (Display) displayToLay.getParent();
75 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
76 if (fts.getFather() != null)
77 ((DisplayLayout) display.getLayout()).validateSelection();
78 }
79
80
81 display.repaint();
82 }
83
84 /***
85 * Checks the validity of the deselection.
86 * @param display the display to deselect.
87 */
88 public void validateDeselection(Display display) {
89
90 Display father = displayToLay;
91 Display tmp;
92 SelectionEvent selEvt = new SelectionEvent(father);
93
94
95 if (father.isSelected()) {
96 father.deselect();
97
98 selEvt.setAction(SelectionEvent.REMOVE, father);
99 father.fireSelectionEvent(selEvt);
100
101
102 if (father.getParent() instanceof Display) {
103 father = (Display) father.getParent();
104 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
105 if (fts.getFather() != null)
106 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
107 }
108
109
110
111
112 validateSelection();
113
114
115 father.repaint();
116 }
117 }
118
119 /***
120 * The display needs to be rebuilt. We do this.
121 */
122 public void rebuildDisplay() {
123
124
125 displayToLay.computeAncestorsAttributes();
126 }
127 }