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
7 /***
8 * A layout manager that lays components vertically.
9 *
10 * @author © 1998 DIRAT Laurent
11 * @version 2.0 16/12/1999
12 */
13 public abstract class VerticalLayout extends DisplayLayout {
14 /***
15 * Computes the size of the display according to its children size (if any),
16 * and its different attributes.
17 * @return the size of the display.
18 */
19 public Dimension computeAttributes() {
20 int height = 0;
21 int width = 0;
22 int ascent;
23 int descent;
24 Display tmp;
25
26 int count = displayToLay.getComponentCount();
27 for ( int i = 0; i < count; i++ ) {
28 tmp = (Display) displayToLay.getComponent(i);
29 tmp.setSize(tmp.getPreferredSize());
30 }
31
32 for (int i = 0; i < count; i++) {
33 tmp = (Display) displayToLay.getComponent(i);
34
35 width = Math.max(width, tmp.getWidth() + tmp.getShiftX());
36 height += tmp.getHeight() + tmp.getShiftY();
37 }
38
39
40
41 ascent = ( (height%2) == 0 ) ? (height / 2) : (height / 2) + 1 ;
42 descent = ( (height%2) == 0 ) ? ascent : ascent - 1 ;
43
44 displayToLay.setAscent(ascent);
45 displayToLay.setDescent(descent);
46 displayToLay.setSize(width , height);
47 displayToLay.setComputeAttributes(false);
48
49 return new Dimension(width, height);
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63 public void layoutContainer(Container parent) {
64 int x, y;
65 Display display, previous;
66
67
68
69
70
71 parent.setSize(parent.getPreferredSize());
72
73 int count = parent.getComponentCount();
74 for ( int i = 0; i < count; i++ ) {
75 display = (Display) parent.getComponent(i);
76
77 display.setSize(display.getPreferredSize());
78
79 x = display.getShiftX();
80
81 if ( i == 0 )
82 y = display.getShiftY();
83 else {
84 previous = (Display) parent.getComponent(i-1);
85 y = previous.getY() + previous.getHeight() + display.getShiftY();
86 }
87
88 display.setLocation(x, y);
89
90
91 display.doLayout();
92 }
93 }
94
95
96
97 }