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 superscript (there is an upward shitf).
13  *
14  * @author © 1999 DIRAT Laurent
15  * @version 2.0 13/12/1999
16  */
17  public class SuperscriptLayout 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, exponent;
30          int decalage = 0;
31          
32          base = (Display) displayToLay.getComponent(0);
33          base.setSize(base.getPreferredSize());
34          width += base.getWidth() + base.getShiftX();
35          
36          exponent = (Display) displayToLay.getComponent(1);
37  
38          if (base.getLayout() instanceof SuperscriptLayout)
39              ((DisplayLayout) exponent.getLayout()).updateLevel(((Display) base.getComponent(1)).getLevel()+ 1);
40          else
41              ((DisplayLayout) exponent.getLayout()).updateLevel(base.getLevel()+ 1);
42          
43          exponent.setSize(exponent.getPreferredSize());
44          
45          if (base.getLayout() instanceof SuperscriptLayout) {
46              Display exp_base = (Display) base.getComponent(1);
47              decalage = computeExponentShift(exp_base, exponent);
48          }
49          else
50              decalage = computeExponentShift(base, exponent);
51          
52          /* ############################# */
53          base.setShiftY(0); // ATTENTION : rajout !!!!!!
54          /* ############################# */
55  
56          exponent.setShiftY(-decalage);
57          width += exponent.getWidth() + exponent.getShiftX();
58                  
59          displayToLay.setDescent(base.getDescent()); 
60          displayToLay.setAscent(decalage + exponent.getAscent());
61          height += displayToLay.getAscent() + displayToLay.getDescent();
62          displayToLay.setSize(width , height);
63          
64          displayToLay.setComputeAttributes(false);
65          return new Dimension(width, height);
66      }
67      
68      /***
69      * Computes the shift of the script display.
70      * @param base the base of the script.
71      * @param script the script of the script.
72      */
73      private /*public*/ int computeExponentShift(Display base, Display script) {
74          if (base instanceof StringDisplay)
75              return (int) (Math.round(base.getAscent()*0.3)) + script.getDescent() -
76                                       base.getShiftY();
77          else 
78              return (int) (Math.round(base.getAscent()*0.7)) + script.getDescent() -
79                                       base.getShiftY();
80      }
81  }