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 formula.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 22/07/1999
14 */
15 public class OneFormulaLayout 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 int width = 10;
23 int height = 10;
24
25 if (displayToLay.getComponentCount() != 0) {
26 updateLevel(displayToLay.getLevel());
27 Display display = (Display) displayToLay.getComponent(0);
28 display.setSize(display.getPreferredSize());
29 width = 2*display.getShiftX() + display.getWidth();
30 height = 2*display.getShiftY() + display.getHeight();
31
32 displayToLay.setAscent(display.getShiftY() + display.getAscent());
33 displayToLay.setDescent(height - display.getAscent());
34
35 displayToLay.setSize(width , height);
36 displayToLay.setComputeAttributes(false);
37 }
38
39 return new Dimension(width , height);
40 }
41
42 /***
43 * Selects the display (and its children if any)
44 * @param the display to select.
45 */
46 public void selectDisplay() {
47 Display display = (Display) displayToLay.getComponent(0);
48 display.select();
49
50 SelectionEvent selEvt = new SelectionEvent(display);
51
52 selEvt.setAction(SelectionEvent.PURGE, null);
53 display.fireSelectionEvent(selEvt);
54 selEvt.setAction(SelectionEvent.ADD, display);
55 display.fireSelectionEvent(selEvt);
56 }
57
58
59 /***
60 * Deselects the display.
61 * @param the display to deselect.
62 */
63 public void deselectDisplay() {
64 Display display = (Display) displayToLay.getComponent(0);
65 display.deselect();
66
67 SelectionEvent selEvt = new SelectionEvent(display);
68 selEvt.setAction(SelectionEvent.PURGE, null);
69 display.fireSelectionEvent(selEvt);
70 }
71
72 /***
73 * Checks the validity of the selection.
74 */
75 public void validateSelection() {
76 }
77
78 /***
79 * Checks the validity of the deselection.
80 * @param display the display to deselect.
81 */
82 public void validateDeselection(Display display) {
83 }
84
85 /***
86 * The display needs to be rebuilt. We do this.
87 */
88 public void rebuildDisplay() {
89
90
91 displayToLay.computeAncestorsAttributes();
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public void layoutContainer(Container parent) {
107
108
109
110
111 parent.setSize(parent.getPreferredSize());
112
113 if (parent.getComponentCount() != 0) {
114
115
116
117 Display display = (Display) parent.getComponent(0);
118 display.setSize(display.getPreferredSize());
119 display.setLocation(display.getShiftX(), display.getShiftY());
120
121
122 display.doLayout();
123 }
124 }
125
126
127
128 }