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 rendering functions.
12  *
13  * @author © 1999 DIRAT Laurent
14  * @version 2.0 17/12/1999
15  */
16  public class FunctionLayout extends UnaryOperatorLayout {
17      /***
18      * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
19      * or has to perform some "re-oganisation" before rendering.<BR>
20      * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
21      * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
22      * call super.initDisplay(displayToLay).
23      * @param displayToLay the display laid by the instance
24      */
25      public void initDisplay(Display displayToLay) {
26          super.initDisplay(displayToLay);  // Par cet appel, on ajoute dans displayToLay le display du nom de la fonction
27          // On va maintenant y rajouter un display, dans lequel on va mettre tous les displays correspondants
28          // aux arguments de la fonction, display ? qui on va affecter un EnumerationOperatorLayout, qui va se charger
29          // d'afficher les arguments de la function de maniËre horizontale avec chacun des arguments sÈparÈs par une
30          // virgule (un sÈparateur)
31          Display argumentsDisplay = new BidimDisplay(displayToLay.getGraphicContext());
32          // On met un listener ? argumentsDisplay
33          // En fait, il n'y en a pas besoin, dans le sens o? il n'y a pas spÈcifiquement de fts qui
34          // Ècoute le comportement de ce display. NÈanmoins, il s'avËre nÈcessaire qu'il en ait
35          // un, par exemple lors de l'iconification, car c'est le display qui reÁoit la demande
36          // d'iconification qui envoie l'ÈvÈnement correspondant ? la FTS. Or si ce display n'a pas
37          // d'Ècouteur, alors pb. Par cohÈrence, l'Ècouteur du display d'opÈrateur, est le fts qui
38          // reprÈsente cette opÈration. Par contre, la fts en question, n'Ècoute pas le display
39          // d'opÈrateur.
40          argumentsDisplay.addControlListener((FormulaTreeStructure) this.displayToLay.getListener());
41          
42          EnumerationLayout layout = new EnumerationLayout();
43          layout.initDisplay(argumentsDisplay);
44          argumentsDisplay.setLayout(layout);
45          
46          // On l'ajoute comme fils ? display
47          this.displayToLay.add(argumentsDisplay);
48      }
49      
50      /***
51      * Computes the size of the display according to its children size (if any),
52      * and its different attributes.
53      * @return the size of the display.
54      */
55      public Dimension computeAttributes() {
56          updateLevel(displayToLay.getLevel());
57          
58          if (displayToLay.getComponentCount() > 2) {
59              // Dans l'ordre, displayToLay contient [displayOperator, argumentsDisplay, var1, var2, ...]
60              // Il faut mettre tous les vari dans argumentsDisplay.
61              
62              Display argumentsDisplay = (Display) displayToLay.getComponent(1);
63              Display d;
64              for (int i = 2; i < displayToLay.getComponentCount(); ) {
65                  d = (Display) displayToLay.getComponent(i);
66                  // argumentsDisplay.add(d) appelle un displayToLay.remove(d).
67                  // remove(d), enlËve Ègalement d de la liste des listeners de l'objet (fts) qu'il Ècoutait.
68                  // Ce qu'on ne veut pas, puisqu'il s'agit d'un simple dÈplacement de display. 
69                  d.setDoRemoveFromListListeners(false);
70                  argumentsDisplay.add(d);
71                  // On remet le comportement de suppression par dÈfault.
72                  d.setDoRemoveFromListListeners(true);
73              }
74          }
75          
76          return super.computeAttributes();
77      }
78      
79      /***
80      * Returns the display of the operator
81      */
82      public Display createOperatorDisplay() {
83          Operator fts = (Operator) displayToLay.getListener();
84          // On crÈÈ un display pour l'opÈrateur.
85          // Attention, fts.getOperatorName() retourne le nom de la fonction, mais "(" y est collÈe.
86          // Il faut donc la supprimer.
87          String funcName = fts.getTheOperator();
88          funcName = funcName.substring(0, funcName.length()-1);
89          
90          StringDisplay stringDisplay = new StringDisplay(displayToLay.getGraphicContext(), funcName, true);
91          stringDisplay.setIsSymbolOperatorDisplay(true);
92          
93          return stringDisplay;
94          
95          /*
96          Display operatorDisplay;
97          if (ImageLoader.exists(funcName)) {
98              SpecialSymbolView symbolOperator = new SpecialSymbolView(funcName, displayToLay);
99              operatorDisplay = new SymbolDisplay(displayToLay.getGraphicContext(), symbolOperator);
100             operatorDisplay.setIsSymbolOperatorDisplay(true);
101         }
102         else
103             operatorDisplay = new StringDisplay(displayToLay.getGraphicContext(), funcName, true);
104             
105         return operatorDisplay;
106         
107         // En fait, si au nom de la fonction est associÈe une image (e.g. alpha), alors le nom de la func
108         // est reprÈsentÈ par l'image.
109         */
110     }
111 }