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 import fr.ove.utils.FontInfo;
8
9 /***
10 * Layout manager that lays the display of an operator whose symbol is superposed to its operand.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 15/12/1999
14 */
15 public abstract class SuperposedOperatorLayout extends VerticalCenteredLayout implements OperatorDisplayCreator {
16 /***
17 * Computes the size of the display according to its children size (if any),
18 * and its different attributes.
19 * @return the size of the display.
20 */
21 public Dimension computeAttributes() {
22
23
24
25 Dimension dim = super.computeAttributes();
26
27 displayToLay.setAscent(((Display) displayToLay.getComponent(0)).getShiftY() +
28 ((Display) displayToLay.getComponent(0)).getHeight() +
29 ((Display) displayToLay.getComponent(1)).getShiftY() +
30 ((Display) displayToLay.getComponent(1)).getAscent());
31
32 displayToLay.setDescent(displayToLay.getHeight() - displayToLay.getAscent());
33
34 return dim;
35 }
36
37 /***
38 * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
39 * or has to perform some "re-oganisation" before rendering.<BR>
40 * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
41 * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
42 * call super.initDisplay(displayToLay).
43 * @param displayToLay the display laid by the instance
44 */
45 public void initDisplay(Display displayToLay) {
46 super.initDisplay(displayToLay);
47
48
49 FormulaTreeStructure fts = (FormulaTreeStructure) displayToLay.getListener();
50
51 Display displayOperator = createOperatorDisplay();
52
53
54
55
56
57
58
59
60
61 displayOperator.addControlListener(fts);
62
63
64
65 this.displayToLay.add(displayOperator);
66
67 this.displayToLay.computeAncestorsAttributes();
68 }
69
70 /***
71 * Checks the validity of the selection.
72 */
73 public void validateSelection() {
74 SelectionEvent selEvt = new SelectionEvent(displayToLay);
75
76
77
78 Display displayOperator = (Display) displayToLay.getComponent(0);
79 if (displayOperator.isSelected()) {
80
81 displayToLay.select();
82
83 selEvt.setAction(SelectionEvent.PURGE, null);
84 displayToLay.fireSelectionEvent(selEvt);
85
86 selEvt.setAction(SelectionEvent.ADD, displayToLay);
87 displayToLay.fireSelectionEvent(selEvt);
88 }
89
90
91
92 Display display = displayToLay;
93 if (display.getParent() instanceof Display) {
94 display = (Display) display.getParent();
95 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
96 if (fts.getFather() != null)
97 ((DisplayLayout) display.getLayout()).validateSelection();
98 }
99
100
101 display.repaint();
102 }
103
104 /***
105 * Checks the validity of the deselection.
106 * @param display the display to deselect.
107 */
108 public void validateDeselection(Display display) {
109 Display father = displayToLay;
110 SelectionEvent selEvt = new SelectionEvent(father);
111
112
113 if (father.isSelected()) {
114 father.setNotSelected();
115
116 selEvt.setAction(SelectionEvent.REMOVE, father);
117 father.fireSelectionEvent(selEvt);
118
119 Display displayOperator = (Display) displayToLay.getComponent(0);
120 Display argument = (Display) displayToLay.getComponent(1);
121
122 if (display == displayOperator) {
123 displayOperator.setNotSelected();
124 selEvt.setAction(SelectionEvent.ADD, argument);
125 father.fireSelectionEvent(selEvt);
126 }
127 else {
128 displayOperator.setNotSelected();
129 argument.deselect();
130 }
131
132
133 if (father.getParent() instanceof Display) {
134 father = (Display) father.getParent();
135 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
136 if (fts.getFather() != null)
137 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
138 }
139
140
141
142
143 validateSelection();
144
145
146 father.repaint();
147 }
148
149 }
150
151 /***
152 * The display needs to be rebuilt. We do this.
153 */
154 public void rebuildDisplay() {
155
156
157 displayToLay.computeAncestorsAttributes();
158 }
159 }