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 * This layout manager lays prefixed unary operators.<BR>
10 * Basically, unary + and unary - because these operators have the particularity to select the operand located
11 * to its left when selected.
12 *
13 * @author © 1999 DIRAT Laurent
14 * @version 2.0 13/12/1999
15 */
16 public abstract class LeftAssocPrefixedUnaryOperatorLayout extends UnaryOperatorLayout {
17 /***
18 * Do we have to select the display to the left of the one the instance lays ?
19 */
20 private boolean selectLeftDisplay;
21
22 /***
23 * Returns <CODE>true</CODE> if during the selection, the display which is located
24 * to the left of the display that the instance lays, must be selected too.
25 * <CODE>false</CODE> otherwise.
26 */
27 public boolean selectLeftDisplay() {
28
29
30
31
32 if (displayToLay.isSelected())
33 return selectLeftDisplay;
34 else
35 return false;
36 }
37
38 /***
39 * Sets if the display to the left of that laid by the instance have to be selected
40 * or not.
41 * @param selectLeftDisplay <CODE>true</CODE> if the left display have to be selected.
42 * <CODE>false</CODE> otherwise.
43 */
44 public void setSelectLeftDisplay(boolean selectLeftDisplay) {
45 this.selectLeftDisplay = selectLeftDisplay;
46 }
47
48 /***
49 * Checks the validity of the selection.
50 */
51 public void validateSelection() {
52 SelectionEvent selEvt = new SelectionEvent(displayToLay);
53
54
55
56
57 Display op = (Display) displayToLay.getComponent(0);
58 Display opRand = (Display) displayToLay.getComponent(1);
59 if (op.isSelected() || opRand.isSelected()) {
60
61 selectLeftDisplay = op.isSelected() ? true : false;
62
63 displayToLay.select();
64
65 selEvt.setAction(SelectionEvent.PURGE, null);
66 displayToLay.fireSelectionEvent(selEvt);
67
68 selEvt.setAction(SelectionEvent.ADD, displayToLay);
69 displayToLay.fireSelectionEvent(selEvt);
70 }
71
72
73
74 Display display = displayToLay;
75 if (displayToLay.getParent() instanceof Display) {
76 display = (Display) displayToLay.getParent();
77 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
78 if (fts.getFather() != null)
79 ((DisplayLayout) display.getLayout()).validateSelection();
80 }
81
82
83 display.repaint();
84 }
85
86 /***
87 * Checks the validity of the deselection.
88 * @param display the display to deselect.
89 */
90 public void validateDeselection(Display display) {
91
92 Display father = displayToLay;
93 Display tmp;
94 SelectionEvent selEvt = new SelectionEvent(father);
95
96
97 if (father.isSelected()) {
98 selectLeftDisplay = false;
99 father.deselect();
100
101 selEvt.setAction(SelectionEvent.REMOVE, father);
102 father.fireSelectionEvent(selEvt);
103
104
105 if (father.getParent() instanceof Display) {
106 father = (Display) father.getParent();
107 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
108 if (fts.getFather() != null)
109 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
110 }
111
112
113
114
115 validateSelection();
116
117
118 father.repaint();
119 }
120 }
121 }