View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import java.awt.*;
4   import java.util.*;
5   import fr.ove.openmath.jome.ctrlview.bidim.Display;
6   import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
7   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
8   import fr.ove.openmath.jome.model.*;
9   
10  /***
11  * Layout manager for horizontal list operator.<BR>
12  * If the list operator is set as as visible list, curly brackets are displayed on both
13  * sides of the list elements.
14  *
15  * @author © 1999 DIRAT Laurent
16  * @version 2.0 15/12/1999
17  */
18  public class HorizontalListLayout extends CurlyLayout {
19      /***
20      * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
21      * or has to perform some "re-oganisation" before rendering.<BR>
22      * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
23      * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
24      * call super.initDisplay(displayToLay).
25      * @param displayToLay the display laid by the instance
26      */
27      public void initDisplay(Display displayToLay) {
28          super.initDisplay(displayToLay);  // Par cet appel, on ajoute dans displayToLay les accolades
29          // On va maintenant y rajouter un display, dans lequel on va mettre tous les displays correspondants
30          // aux ÈlÈments de la liste, display ? qui on va affecter un SeparatorOperatorLayout, qui va se charger
31          // d'afficher les ÈlÈments de la liste de maniËre horizontale avec chacun des ÈlÈments sÈparÈs par une
32          // virgule (un sÈparateur)
33          Display elementsDisplay = new BidimDisplay(displayToLay.getGraphicContext());
34          // On met un listener ? elementsDisplay
35          // En fait, il n'y en a pas besoin, dans le sens o? il n'y a pas spÈcifiquement de fts qui
36          // Ècoute le comportement de ce display. NÈanmoins, il s'avËre nÈcessaire qu'il en ait
37          // un, par exemple lors de l'iconification, car c'est le display qui reÁoit la demande
38          // d'iconification qui envoie l'ÈvÈnement correspondant ? la FTS. Or si ce display n'a pas
39          // d'Ècouteur, alors pb. Par cohÈrence, l'Ècouteur du display d'opÈrateur, est le fts qui
40          // reprÈsente cette opÈration. Par contre, la fts en question, n'Ècoute pas le display
41          // d'opÈrateur.
42          elementsDisplay.addControlListener((FormulaTreeStructure) displayToLay.getListener());
43          
44          SeparatorOperatorLayout layout = new SeparatorOperatorLayout();
45          layout.initDisplay(elementsDisplay);
46          elementsDisplay.setLayout(layout);
47          
48          // On l'ajoute comme fils ? display
49          this.displayToLay.add(elementsDisplay);
50      }
51      
52      /***
53      * Computes the size of the display according to its children size (if any),
54      * and its different attributes.
55      * @return the size of the display.
56      */
57      public Dimension computeAttributes() {
58          updateLevel(displayToLay.getLevel());
59          
60          if (displayToLay.getComponentCount() > 3) {
61              // Dans l'ordre, displayToLay contient [opening, closing, elementsDisplay, var1, var2, ...]
62              // Il faut mettre tous les vari dans elementsDisplay.
63              
64              Display elementsDisplay = (Display) displayToLay.getComponent(2);
65              Display d;
66              for (int i = 3; i < displayToLay.getComponentCount(); ) {
67                  d = (Display) displayToLay.getComponent(i);
68                  // elementsDisplay.add(d) appelle un displayToLay.remove(d).
69                  // remove(d), enlËve Ègalement d de la liste des listeners de l'objet (fts) qu'il Ècoutait.
70                  // Ce qu'on ne veut pas, puisqu'il s'agit d'un simple dÈplacement de display. 
71                  d.setDoRemoveFromListListeners(false);
72                  elementsDisplay.add(d);
73                  // On remet le comportement de suppression par dÈfault.
74                  d.setDoRemoveFromListListeners(true);
75              }
76          }
77          
78          return super.computeAttributes();
79      }
80  }