View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import java.awt.*;
4   import fr.ove.openmath.jome.ctrlview.bidim.Display;
5   import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
6   import fr.ove.openmath.jome.ctrlview.bidim.HorizontalLayout;
7   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
8   import fr.ove.openmath.jome.model.*;
9   
10  /***
11  * A layout manager that lays components horyzontally, but the last one in the
12  * list, is treated as a underscript (there is an downward shitf).
13  *
14  * @author © 1999 DIRAT Laurent
15  * @version 2.0  13/12/1999
16  */
17  public class UnderscriptLayout extends ScriptLayout {
18      /***
19      * Computes the size of the display according to its children size (if any),
20      * and its different attributes.
21      * @return the size of the display.
22      */
23      public Dimension computeAttributes() {
24          int ascent = 0;
25          int descent = 0;
26          int width = 0;
27          int height = 0;
28          
29          Display base, indice;
30          int decalage = 0;
31          
32          base = (Display) displayToLay.getComponent(0);
33          base.setSize(base.getPreferredSize());
34          width += base.getWidth() + base.getShiftX();
35          
36          indice = (Display) displayToLay.getComponent(1);
37  
38          if (base.getLayout() instanceof UnderscriptLayout)
39              ((DisplayLayout) indice.getLayout()).updateLevel(((Display) base.getComponent(1)).getLevel()+ 1);
40          else
41              ((DisplayLayout) indice.getLayout()).updateLevel(base.getLevel()+ 1);
42          
43          indice.setSize(indice.getPreferredSize());
44          
45          if (base.getLayout() instanceof UnderscriptLayout) {
46              Display ind_base = (Display) base.getComponent(1);
47              decalage = ind_base.getDescent() + ind_base.getShiftY();
48          }
49          else
50              decalage = base.getDescent();
51  
52          /* ############################# */
53          base.setShiftY(0); // ATTENTION : rajout !!!!!!
54          /* ############################# */
55          
56          indice.setShiftY(decalage);
57          width += indice.getWidth() + indice.getShiftX();
58          
59          displayToLay.setAscent(base.getAscent()); 
60          displayToLay.setDescent(decalage + indice.getDescent());
61          
62          height += displayToLay.getAscent() + displayToLay.getDescent();
63          displayToLay.setSize(width , height);
64          
65          displayToLay.setComputeAttributes(false);
66          return new Dimension(width, height);
67      }
68  }