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 © 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          // Possibles changements ? effectuer pour ne pas mettre la
40          // la ligne de rÈfÈrence au milieu de la BBox
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      // ### ImplÈmentation des diffÈrentes interfaces ###
54      // #################################################
55  
56      // ***************************************************
57      // *** ImplÈmentation de l'interface LayoutManager ***
58  
59      /*
60       * Lays out the container in the specified panel.
61       * @param parent the component which needs to be laid out
62       */
63       public void layoutContainer(Container parent) {
64          int x, y;
65          Display display, previous;
66  
67          // Ca c'est parce que c'est le layout manager de la formule. Et comme personne ne dit au container
68          // contenant la formule, que la taille de la formule a besoin d'Ítre recalculÈe, il faut bien le
69          // faire qque part. Chaque display informe son pËre qu'il doit Ítre recalculÈ, mais la formule ne
70          // le fait pas pour le sien.
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              // On place maintenant les Èventuels display enfants du display courant
91              display.doLayout();
92          }
93      }
94  
95      // *** Fin de l'interface LayoutManager ***
96      // ****************************************
97  }