1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import java.awt.*;
4 import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
5 import fr.ove.openmath.jome.ctrlview.bidim.Display;
6 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
7 import fr.ove.openmath.jome.model.*;
8
9 /***
10 * A layout manager that lays components of a function.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 20/07/1999
14 */
15 public class LambdaExpLayout extends HorizontalLayout {
16 private boolean arrangeDisplay = true;
17 private Display enumeration = null;
18 /***
19 * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
20 * or has to perform some "re-oganisation" before rendering.<BR>
21 * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
22 * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
23 * call super.initDisplay(displayToLay).
24 * @param displayToLay the display laid by the instance
25 */
26 public void initDisplay(Display displayToLay) {
27 super.initDisplay(displayToLay);
28
29
30 LambdaExpression fts = (LambdaExpression) this.displayToLay.getListener();
31 GraphicContext gc = this.displayToLay.getGraphicContext();
32
33 Display displayElems = null;
34 if (!fts.isJustFunction()) {
35 if (fts.getNbChildren() > 2) {
36
37
38 enumeration = new BidimDisplay(gc);
39 enumeration.addControlListener(fts);
40 EnumerationLayout layout = new EnumerationLayout();
41 layout.initDisplay(enumeration);
42 enumeration.setLayout(layout);
43 this.displayToLay.add(enumeration);
44 }
45
46
47 SymbolDisplay arrow = new SymbolDisplay(gc, new ImageSymbol("RightArrow", this.displayToLay));
48
49 arrow.setIsSymbolOperatorDisplay(true);
50 this.displayToLay.add(arrow);
51 arrow.addControlListener(fts);
52 }
53
54
55
56
57
58
59
60
61
62
63 }
64
65 /***
66 * Checks the validity of the selection.
67 */
68 public void validateSelection() {
69 }
70
71 /***
72 * Checks the validity of the deselection.
73 * @param display the display to deselect.
74 */
75 public void validateDeselection(Display display) {
76 }
77
78 /***
79 * Computes the size of the display according to its children size (if any),
80 * and its different attributes.
81 * @return the size of the display.
82 */
83 public Dimension computeAttributes() {
84 updateLevel(displayToLay.getLevel());
85 LambdaExpression fts = (LambdaExpression) displayToLay.getListener();
86
87 if (displayToLay.getComponentCount() > 3) {
88
89 if (!fts.isJustFunction()) {
90 if (fts.getNbChildren() > 2) {
91
92
93
94 Display d;
95 for (int i = 3; i < displayToLay.getComponentCount(); ) {
96 d = (Display) displayToLay.getComponent(i);
97
98
99
100 d.setDoRemoveFromListListeners(false);
101 enumeration.add(d);
102
103 d.setDoRemoveFromListListeners(true);
104 }
105 }
106 }
107 else {
108
109 for (int i = 1; i < displayToLay.getComponentCount(); )
110 displayToLay.remove(i);
111 }
112 arrangeDisplay = false;
113 }
114
115 Dimension dim = super.computeAttributes();
116
117 if ((!fts.isJustFunction()) && (fts.getNbChildren() == 2)) {
118
119
120 ((Display) displayToLay.getComponent(0)).setShiftX(((Display) displayToLay.getComponent(2)).getWidth());
121 ((Display) displayToLay.getComponent(2)).setShiftX(-dim.width);
122 }
123
124 return dim;
125 }
126
127 /***
128 * The display needs to be rebuilt. We do this.
129 */
130 public void rebuildDisplay() {
131
132
133
134
135 LambdaExpression fts = (LambdaExpression) displayToLay.getListener();
136 if (!fts.isJustFunction() && (fts.getNbChildren() == 2)) {
137 Display variable = (Display) displayToLay.getComponent(1);
138
139 variable.setDoRemoveFromListListeners(false);
140 displayToLay.remove(variable);
141
142 variable.setDoRemoveFromListListeners(true);
143
144 displayToLay.add(variable);
145
146 int count = displayToLay.getComponentCount();
147 for (int i = 0; i < count; i++)
148 ((Display) displayToLay.getComponent(i)).setShiftX(0);
149 }
150
151
152
153
154 displayToLay.computeAncestorsAttributes();
155 }
156
157 }