1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package fr.ove.openmath.jome.ctrlview.bidim;
30
31 import java.awt.*;
32
33 import fr.ove.openmath.jome.ctrlview.bidim.Display;
34 import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
35 import fr.ove.openmath.jome.ctrlview.bidim.HorizontalLayout;
36 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
37 import fr.ove.openmath.jome.model.*;
38
39 /***
40 * A layout manager that lays components horyzontally, but the last one in the
41 * list, is treated as a superscript (there is an upward shitf).
42 *
43 * @author © 1999 DIRAT Laurent
44 * @version 2.0 13/12/1999
45 */
46 public class OverLayout extends HorizontalLayout {
47
48 /***
49 * Computes the size of the display according to its children size (if any),
50 * and its different attributes.
51 * @return the size of the display.
52 */
53
54 public Dimension computeAttributes() {
55 int ascent = 0;
56 int descent = 0;
57 int width = 0;
58 int height = 0;
59
60 Display base, exponent;
61 int decalage = 0;
62
63 base = (Display) displayToLay.getComponent(0);
64 base.setSize(base.getPreferredSize());
65 width += base.getWidth();
66
67 exponent = (Display) displayToLay.getComponent(1);
68
69 if (base.getLayout() instanceof OverLayout)
70 ((DisplayLayout) exponent.getLayout()).updateLevel(((Display) base.getComponent(1)).getLevel()+ 1);
71 else
72 ((DisplayLayout) exponent.getLayout()).updateLevel(base.getLevel()+ 1);
73
74 exponent.setSize(exponent.getPreferredSize());
75
76 width = Math.max(width, exponent.getWidth());
77
78 if (base.getLayout() instanceof OverLayout) {
79 Display exp_base = (Display) base.getComponent(1);
80 decalage = computeExponentShift(exp_base, exponent);
81 }
82 else
83 decalage = computeExponentShift(base, exponent);
84
85
86
87
88
89 exponent.setShiftY(-decalage);
90 exponent.setShiftX(- (base.getWidth() + exponent.getWidth()) /2);
91
92
93 base.setShiftX((width - base.getWidth())/2);
94
95
96
97
98
99
100 displayToLay.setDescent(base.getDescent());
101 displayToLay.setAscent(decalage + exponent.getAscent());
102 height += displayToLay.getAscent() + displayToLay.getDescent();
103 displayToLay.setSize(width , height);
104
105 displayToLay.setComputeAttributes(false);
106 return new Dimension(width, height);
107 }
108
109 /***
110 * Computes the shift of the script display.
111 * @param base the base of the script.
112 * @param script the script of the script.
113 */
114 private
115
116 return (int) (base.getAscent() + script.getDescent());
117
118
119
120 }
121
122 public void rebuildDisplay() {
123
124
125
126
127
128 displayToLay.computeAncestorsAttributes();
129 }
130
131 public void validateSelection() {
132
133 }
134 /***
135 * Checks the validity of the deselection.
136 * @param display the display to deselect.
137 */
138 public void validateDeselection(Display display) {
139
140 }
141
142
143 }