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 * A layout manager that lays components for the variables of differentiation.<BR>
10 * We assume the display laid out contains what should be a variable for the visualisation of a differentiation,
11 * i.e. a variable (differentiation of first order) or a power of a variable (differentiation of higher order).<BR>
12 * According to the type of differentiation, either the symbol "d" is added (differentiation) or the symbol delta (the
13 * greek letter) is added (partial differentiation) to the display laid out, for correct rendering.
14 *
15 * @author © 1999 DIRAT Laurent
16 * @version 2.0 15/10/1999
17 */
18 public class VarDiffLayout extends HorizontalLayout {
19 /***
20 * <CODE>true</CODE> if we are dealing with a partial derivative. <CODEW>false</CODE> otherwise.
21 */
22 private boolean isPartial;
23
24 /***
25 * The constructor.
26 * @param isPartial <CODE>true</CODE> if we have a partial differentiation. <CODE>false</CODE> otherwise.
27 */
28 public VarDiffLayout(boolean isPartial) {
29 this.isPartial = isPartial;
30 }
31
32 /***
33 * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
34 * or has to perform some "re-oganisation" before rendering.<BR>
35 * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
36 * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
37 * call super.initDisplay(displayToLay).
38 * @param displayToLay the display laid by the instance
39 */
40 public void initDisplay(Display displayToLay) {
41 super.initDisplay(displayToLay);
42
43 FormulaTreeStructure fts = (FormulaTreeStructure) this.displayToLay.getListener();
44
45 Display d;
46
47 if (isPartial) {
48 d = new SymbolDisplay(this.displayToLay.getGraphicContext(), new ImageSymbol("delta", this.displayToLay));
49
50 d.setIsSymbolOperatorDisplay(true);
51 }
52 else {
53 d = new StringDisplay(this.displayToLay.getGraphicContext(), "d", true);
54 }
55
56 this.displayToLay.add(d, d, 0);
57
58
59
60
61
62
63
64
65
66 d.addControlListener(fts);
67 }
68
69 /***
70 * Checks the validity of the selection.
71 */
72 public void validateSelection() {
73 SelectionEvent selEvt = new SelectionEvent(displayToLay);
74
75
76
77 Display d = (Display) displayToLay.getComponent(0);
78 Display v = (Display) displayToLay.getComponent(1);
79 if (d.isSelected() || v.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
96 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
97 if (fts.getFather() != null)
98 ((DisplayLayout) display.getLayout()).validateSelection();
99 }
100
101
102 display.repaint();
103 }
104
105 /***
106 * Checks the validity of the deselection.
107 * @param display the display to deselect.
108 */
109 public void validateDeselection(Display display) {
110 Display father = displayToLay;
111 Display tmp;
112 SelectionEvent selEvt = new SelectionEvent(father);
113
114
115
116 if (father.isSelected()) {
117 father.deselect();
118
119 selEvt.setAction(SelectionEvent.REMOVE, father);
120 father.fireSelectionEvent(selEvt);
121
122
123 if (father.getParent() instanceof Display) {
124 father = (Display) father.getParent();
125
126 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
127 if (fts.getFather() != null)
128 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
129 }
130
131
132
133
134 validateSelection();
135
136
137 father.repaint();
138 }
139 }
140
141 /***
142 * The display needs to be rebuilt. We do this.
143 */
144 public void rebuildDisplay() {
145
146
147 displayToLay.computeAncestorsAttributes();
148 }
149
150 }