1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import java.awt.*;
4 import java.util.*;
5 import fr.ove.openmath.jome.ctrlview.bidim.Display;
6 import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
7 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
8 import fr.ove.openmath.jome.model.*;
9
10 /***
11 * A layout manager that lays components horizontally and inserts between
12 * them, the display of the operator that the layout manager lays.<BR>
13 * For example, if this layout manager lays an equality, it will insert
14 * between the components (i.e. operands) the display of the symbol "=",
15 * and so on, for all the relational operators.<BR>
16 *
17 * @author © 1999 DIRAT Laurent
18 * @version 2.0 17/12/1999
19 */
20 public class Mfd2SubstitutionLayout extends HorizontalLayout {
21 /***
22 * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
23 * or has to perform some "re-oganisation" before rendering.<BR>
24 * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
25 * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
26 * call super.initDisplay(displayToLay).
27 * @param displayToLay the display laid by the instance
28 */
29 public void initDisplay(Display displayToLay) {
30 super.initDisplay(displayToLay);
31
32
33 SymbolDisplay arrow = new SymbolDisplay(this.displayToLay.getGraphicContext(), new ImageSymbol("LeftArrow", this.displayToLay));
34
35
36
37
38
39
40
41
42
43 arrow.addControlListener(this.displayToLay.getListener());
44 arrow.setIsSymbolOperatorDisplay(true);
45 this.displayToLay.add(arrow);
46 }
47
48 /***
49 * Checks the validity of the selection.
50 */
51 public void validateSelection() {
52 }
53
54 /***
55 * Checks the validity of the deselection.
56 * @param display the display to deselect.
57 */
58 public void validateDeselection(Display display) {
59 }
60
61 /***
62 * Computes the size of the display according to its children size (if any),
63 * and its different attributes.
64 * @return the size of the display.
65 */
66 public Dimension computeAttributes() {
67 Dimension dim = super.computeAttributes();
68
69 Display arrow = (Display) displayToLay.getComponent(0);
70 Display left = (Display) displayToLay.getComponent(1);
71 Display right = (Display) displayToLay.getComponent(2);
72 arrow.setShiftX(left.getShiftX() + left.getWidth());
73 left.setShiftX(-(arrow.getShiftX() + arrow.getWidth()));
74 right.setShiftX(arrow.getWidth());
75
76 return dim;
77 }
78
79 /***
80 * The display needs to be rebuilt. We do this.
81 */
82 public void rebuildDisplay() {
83 Display tmp;
84 Display listDisplay[] = new Display[2];
85
86 for (int i = 0; i < 3; i++) {
87 tmp = (Display) displayToLay.getComponent(i);
88 if (!tmp.isSymbolOperatorDisplay()) {
89
90
91
92 tmp.setLocation(0, 0);
93 listDisplay[((FormulaTreeStructure) tmp.getListener()).getRank()] = tmp;
94 }
95 }
96
97
98
99 ((Display) displayToLay.getComponent(0)).setIsSymbolOperatorDisplay(false);
100
101
102
103 displayToLay.removeAllDisplays();
104
105
106 ((Display) displayToLay.getComponent(0)).setIsSymbolOperatorDisplay(true);
107
108 for (int i = 0; i < 2; i++)
109 displayToLay.add(listDisplay[i]);
110
111
112
113 displayToLay.computeAncestorsAttributes();
114 }
115
116 }