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 the display of a slot.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 22/07/1999
14 */
15 public class SlotLayout extends DisplayLayout {
16 /***
17 * Computes the size of the display according to its children size (if any),
18 * and its different attributes.
19 * @return the size of the display.
20 */
21 public Dimension computeAttributes() {
22 updateLevel(displayToLay.getLevel());
23
24 Display display = (Display) displayToLay.getComponent(0);
25 display.setSize(display.getPreferredSize());
26 int width = display.getShiftX() + display.getWidth();
27 int height = display.getShiftY() + display.getHeight();
28
29 displayToLay.setAscent(display.getShiftY() + display.getAscent());
30 displayToLay.setDescent(height - display.getAscent());
31
32 displayToLay.setSize(width , height);
33 displayToLay.setComputeAttributes(false);
34
35 return new Dimension(width , height);
36 }
37
38 /***
39 * Checks the validity of the selection.
40 */
41 public void validateSelection() {
42 Display childDisplay = (Display) displayToLay.getComponent(0);
43 if (childDisplay.isSelected()) {
44 displayToLay.setSelected();
45 SelectionEvent selEvt = new SelectionEvent(displayToLay);
46
47 selEvt.setAction(SelectionEvent.PURGE, null);
48 displayToLay.fireSelectionEvent(selEvt);
49
50 selEvt.setAction(SelectionEvent.ADD, displayToLay);
51 displayToLay.fireSelectionEvent(selEvt);
52 }
53
54
55
56 Display display = displayToLay;
57 if (display.getParent() instanceof Display) {
58 display = (Display) display.getParent();
59 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
60 if (fts.getFather() != null)
61 ((DisplayLayout) display.getLayout()).validateSelection();
62 }
63
64
65 display.repaint();
66 }
67
68 /***
69 * Checks the validity of the deselection.
70 * @param display the display to deselect.
71 */
72 public void validateDeselection(Display display) {
73 Display father = displayToLay;
74 SelectionEvent selEvt = new SelectionEvent(father);
75
76 if (father.isSelected()) {
77 father.setNotSelected();
78
79 selEvt.setAction(SelectionEvent.REMOVE, father);
80 father.fireSelectionEvent(selEvt);
81
82
83 if (father.getParent() instanceof Display) {
84 father = (Display) father.getParent();
85
86 FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
87 if (fts.getFather() != null)
88 ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
89 }
90
91
92
93
94 validateSelection();
95
96
97 father.repaint();
98 }
99 }
100
101 /***
102 * The display needs to be rebuilt. We do this.
103 */
104 public void rebuildDisplay() {
105
106
107 displayToLay.computeAncestorsAttributes();
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public void layoutContainer(Container parent) {
123
124
125
126
127 parent.setSize(parent.getPreferredSize());
128
129 Display display = (Display) parent.getComponent(0);
130 display.setSize(display.getPreferredSize());
131 display.setLocation(display.getShiftX(), display.getShiftY());
132
133
134 display.doLayout();
135 }
136
137
138
139 }