View Javadoc

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 © 1999 DIRAT Laurent
11  * @version 2.0  15/12/1999
12  */
13  public abstract class VerticalCenteredLayout 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 width1 = 0;
22          int width2 = 0;
23          int width = 0;
24          int ascent;
25          int descent;
26          Display tmp;
27          
28          updateLevel(displayToLay.getLevel());
29          
30          int count = displayToLay.getComponentCount();
31          for (int i = 0; i < count; i++) {
32              tmp = (Display) displayToLay.getComponent(i);
33              tmp.setSize(tmp.getPreferredSize());
34          }
35                      
36          for (int i = 0; i < count; i++) {
37              tmp = (Display) displayToLay.getComponent(i);
38              
39              width = (tmp.getWidth() / 2);
40              
41              width1 = Math.max( width - tmp.getShiftX(),
42                                 width1 );
43              
44              width = ((tmp.getWidth() % 2) == 0 ) ? width : (width + 1);
45              width2 = Math.max( width + tmp.getShiftX(),
46                                 width2 );
47              
48              height += tmp.getAscent() + tmp.getDescent() + tmp.getShiftY();
49          }
50          
51          // Possibles changements ? effectuer pour ne pas mettre la
52          // la ligne de rÈfÈrence au milieu de la BBox
53          ascent = ( (height%2) == 0 ) ? (height / 2) : (height / 2) + 1 ;
54          descent = ( (height%2) == 0 ) ? ascent : ascent - 1 ;
55          
56          displayToLay.setAscent(ascent);
57          displayToLay.setDescent(descent);
58          displayToLay.setSize(width1 + width2 , height);
59          displayToLay.setComputeAttributes(false);
60          
61          return new Dimension(width1 + width2 , height);
62      }
63      
64      // #################################################
65      // ### ImplÈmentation des diffÈrentes interfaces ###
66      // #################################################
67  
68      // ***************************************************
69      // *** ImplÈmentation de l'interface LayoutManager ***
70  
71      /*
72       * Lays out the container in the specified panel.
73       * @param parent the component which needs to be laid out 
74       */
75       public void layoutContainer(Container parent) {
76          int x, y;
77          Display display, previous;
78          
79          int count = parent.getComponentCount();
80          for ( int i = 0; i < count; i++ ) {
81              display = (Display) parent.getComponent(i);
82              
83              display.setSize(display.getPreferredSize());
84              
85              x = (((Display) parent).getWidth() / 2) -
86                  (display.getWidth() / 2) +
87                  display.getShiftX();
88              
89              if ( i == 0 )
90                  y = display.getShiftY();
91              else {
92                  previous = (Display) parent.getComponent(i-1);
93                  y = previous.getY() + previous.getHeight() + display.getShiftY();
94              }
95              
96              display.setLocation(x, y);
97              
98              // On place maintenant les Èventuels display enfants du display courant
99              display.doLayout();
100         }
101     }
102 
103     // *** Fin de l'interface LayoutManager ***
104     // ****************************************
105 }