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   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
7   import fr.ove.openmath.jome.model.*;
8   
9   /***
10  * A layout manager that lays the display of a formula.
11  *
12  * @author © 1999 DIRAT Laurent
13  * @version 2.0 22/07/1999
14  */
15  public class OneFormulaLayout extends DisplayLayout {
16      /***
17      * Computes the size of the display according to its children size (if any),
18      * and its different attributes.
19      * @return the size of the display.
20      */
21      public Dimension computeAttributes() {
22          int width = 10;  // Ca c'est parce que c'est la taille prÈferÈe du display de la formule
23          int height = 10; // faudra voir de modifier Áa de maniËre plus propre.
24          
25          if (displayToLay.getComponentCount() != 0) {
26              updateLevel(displayToLay.getLevel());
27              Display display = (Display) displayToLay.getComponent(0);
28              display.setSize(display.getPreferredSize());
29              width = 2*display.getShiftX() + display.getWidth();
30              height = 2*display.getShiftY() + display.getHeight();
31  
32              displayToLay.setAscent(display.getShiftY() + display.getAscent());
33              displayToLay.setDescent(height - display.getAscent());
34              
35              displayToLay.setSize(width , height);
36              displayToLay.setComputeAttributes(false);
37          }
38          
39          return new Dimension(width , height);
40      }
41      
42      /***
43      * Selects the display (and its children if any)
44      * @param the display to select.
45      */
46      public void selectDisplay() {
47          Display display = (Display) displayToLay.getComponent(0);
48          display.select();
49          
50          SelectionEvent selEvt = new SelectionEvent(display);
51          // On purge la liste des ÈlÈments sÈlectionnÈs.
52          selEvt.setAction(SelectionEvent.PURGE, null);
53          display.fireSelectionEvent(selEvt);
54          selEvt.setAction(SelectionEvent.ADD, display);
55          display.fireSelectionEvent(selEvt);
56      }
57  
58  
59      /***
60      * Deselects the display.
61      * @param the display to deselect.
62      */
63      public void deselectDisplay() {
64          Display display = (Display) displayToLay.getComponent(0);
65          display.deselect();
66          
67          SelectionEvent selEvt = new SelectionEvent(display);
68          selEvt.setAction(SelectionEvent.PURGE, null);
69          display.fireSelectionEvent(selEvt);
70      }
71      
72      /***
73      * Checks the validity of the selection.
74      */
75      public void validateSelection() {
76      }
77      
78      /***
79      * Checks the validity of the deselection.
80      * @param display the display to deselect.
81      */
82      public void validateDeselection(Display display) {
83      }
84  
85      /***
86      * The display needs to be rebuilt. We do this.
87      */
88      public void rebuildDisplay() {
89          // La taille des displays est probablement diffÈrente de ceux qui Ètaient
90          // prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
91          displayToLay.computeAncestorsAttributes();
92      }
93     
94      // #################################################
95      // ### ImplÈmentation des diffÈrentes interfaces ###
96      // #################################################
97  
98      // ***************************************************
99      // *** ImplÈmentation de l'interface LayoutManager ***
100 
101 
102     /*
103      * Lays out the container in the specified panel.
104      * @param parent the component which needs to be laid out
105      */
106      public void layoutContainer(Container parent) {
107         // Ca c'est parce que c'est le layout manager de la formule. Et comme personne ne dit au container
108         // contenant la formule, que la taille de la formule a besoin d'Ítre recalculÈe, il faut bien le
109         // faire qque part. Chaque display informe son pËre qu'il doit Ítre recalculÈ, mais la formule ne
110         // le fait pas pour le sien.
111         parent.setSize(parent.getPreferredSize());
112         
113         if (parent.getComponentCount() != 0) {
114             // On est obligÈ de faire ce test car comme lorsque la formule est "vide", on ne met pas template,
115             // parent ne contient aucun display fils.
116             
117             Display display = (Display) parent.getComponent(0);
118             display.setSize(display.getPreferredSize());
119             display.setLocation(display.getShiftX(), display.getShiftY());
120 
121             // On place maintenant les Èventuels display enfants du display courant
122             display.doLayout();
123         }
124     }
125 
126     // *** Fin de l'interface LayoutManager ***
127     // ****************************************
128 }