1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import fr.ove.openmath.jome.ctrlview.bidim.*;
4 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
5 import fr.ove.openmath.jome.model.*;
6
7 /***
8 * A layout manager for an binary infix operator.
9 *
10 * @author © 1999 DIRAT Laurent
11 * @version 2.0 14/12/1999
12 */
13 public abstract class BinaryInfixOperatorLayout extends InfixOperatorLayout {
14 /***
15 * Checks the validity of the selection.
16 */
17 public void validateSelection() {
18 SelectionEvent selEvt = new SelectionEvent(displayToLay);
19
20
21
22
23 Display left = (Display) displayToLay.getComponent(0);
24 Display ope = (Display) displayToLay.getComponent(1);
25 Display right = (Display) displayToLay.getComponent(2);
26 if ((left.gotSelectedElements() && right.gotSelectedElements()) ||
27 (ope.isSelected())) {
28
29 displayToLay.select();
30
31 selEvt.setAction(SelectionEvent.PURGE, null);
32 displayToLay.fireSelectionEvent(selEvt);
33
34 selEvt.setAction(SelectionEvent.ADD, displayToLay);
35 displayToLay.fireSelectionEvent(selEvt);
36 }
37
38
39
40 Display display = displayToLay;
41 if (displayToLay.getParent() instanceof Display) {
42 display = (Display) displayToLay.getParent();
43 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
44 if (fts.getFather() != null)
45 ((DisplayLayout) display.getLayout()).validateSelection();
46 }
47
48
49 display.repaint();
50 }
51
52 /***
53 * Checks the validity of the deselection.
54 * @param display the display to deselect.
55 */
56 public void validateDeselection(Display display) {
57 Display father = displayToLay;
58 SelectionEvent selEvt = new SelectionEvent(father);
59
60
61 if (father.isSelected()) {
62 father.setNotSelected();
63
64 selEvt.setAction(SelectionEvent.REMOVE, father);
65 father.fireSelectionEvent(selEvt);
66
67 Display left = (Display) father.getComponent(0);
68 Display ope = (Display) father.getComponent(1);
69 Display right = (Display) father.getComponent(2);
70
71 if (display == left) {
72 ope.setNotSelected();
73 selEvt.setAction(SelectionEvent.ADD, right);
74 father.fireSelectionEvent(selEvt);
75 }
76 else if (display == right) {
77 ope.setNotSelected();
78 selEvt.setAction(SelectionEvent.ADD, left);
79 father.fireSelectionEvent(selEvt);
80 }
81 else {
82 left.deselect();
83 ope.setNotSelected();
84 right.deselect();
85 }
86
87
88 if (father.getParent() instanceof Display) {
89 father = (Display) father.getParent();
90 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
91 if (fts.getFather() != null)
92 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
93 }
94
95
96
97
98 validateSelection();
99
100
101 father.repaint();
102 }
103 }
104 }