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  * A layout manager that lays components horizontally and inserts between
12  * them, the display of the operator that the layout manager lays.<BR>
13  * For example, if this layout manager lays an equality, it will insert
14  * between the components (i.e. operands) the display of the symbol "=",
15  * and so on, for all the relational operators.<BR>
16  *
17  * @author © 1999 DIRAT Laurent
18  * @version 2.0 17/12/1999
19  */
20  public class Mfd2SubstitutionLayout extends HorizontalLayout {
21      /***
22      * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
23      * or has to perform some "re-oganisation" before rendering.<BR>
24      * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
25      * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
26      * call super.initDisplay(displayToLay).
27      * @param displayToLay the display laid by the instance
28      */
29      public void initDisplay(Display displayToLay) {
30          super.initDisplay(displayToLay);
31          
32          // On ajoute un display d'opÈrateur.
33          SymbolDisplay arrow = new SymbolDisplay(this.displayToLay.getGraphicContext(), new ImageSymbol("LeftArrow", this.displayToLay));
34          
35          // On met un listener ? l'opÈrateur.
36          // En fait, il n'y en a pas besoin, dans le sens o? il n'y a pas spÈcifiquement de fts qui
37          // Ècoute le comportement de ce display. NÈanmoins, il s'avËre nÈcessaire qu'il en ait
38          // un, par exemple lors de l'iconification, car c'est le display qui reÁoit la demande
39          // d'iconification qui envoie l'ÈvÈnement correspondant ? la FTS. Or si ce display n'a pas
40          // d'Ècouteur, alors pb. Par cohÈrence, l'Ècouteur du display d'opÈrateur, est le fts qui
41          // reprÈsente cette opÈration. Par contre, la fts en question, n'Ècoute pas le display
42          // d'opÈrateur.
43          arrow.addControlListener(this.displayToLay.getListener());
44          arrow.setIsSymbolOperatorDisplay(true);
45          this.displayToLay.add(arrow);
46      }
47      
48      /***
49      * Checks the validity of the selection.
50      */
51      public void validateSelection() {
52      }
53      
54      /***
55      * Checks the validity of the deselection.
56      * @param display the display to deselect.
57      */
58      public void validateDeselection(Display display) {
59      }
60      
61      /***
62      * Computes the size of the display according to its children size (if any),
63      * and its different attributes.
64      * @return the size of the display.
65      */
66      public Dimension computeAttributes() {
67          Dimension dim = super.computeAttributes();
68          
69          Display arrow = (Display) displayToLay.getComponent(0);
70          Display left = (Display) displayToLay.getComponent(1);
71          Display right = (Display) displayToLay.getComponent(2);
72          arrow.setShiftX(left.getShiftX() + left.getWidth());
73          left.setShiftX(-(arrow.getShiftX() + arrow.getWidth()));
74          right.setShiftX(arrow.getWidth());
75          
76          return dim;
77      }
78      
79      /***
80      * The display needs to be rebuilt. We do this.
81      */
82      public void rebuildDisplay() {
83          Display tmp;
84          Display listDisplay[] = new Display[2];  // y en a 2 (en ne comptant pas celui de la flËche)
85          
86          for (int i = 0; i < 3; i++) {
87              tmp = (Display) displayToLay.getComponent(i);
88              if (!tmp.isSymbolOperatorDisplay()) {
89                  // A voir !!!!!
90                  // Mais il semblerai que bon, sinon ? la (re)construction du display il se base
91                  // sur des anciennes valeurs, et donc pas tarrible niveau affichage.
92                  tmp.setLocation(0, 0);
93                  listDisplay[((FormulaTreeStructure) tmp.getListener()).getRank()] = tmp;
94              }
95          }
96          
97          // Pour que la flËche soient gardÈe, on la met temporairement comme un display "classique".
98          // Autrement dit, ce n'est plus un display d'opÈrateur.
99          ((Display) displayToLay.getComponent(0)).setIsSymbolOperatorDisplay(false);
100         
101         // ATTENTION : ici, on enlËve les displays fils de display, mais on ne les enlËve pas de la liste
102         // des listeners de la fts qu'il sont en train d'Ècouter. Exception faite pour les displays d'opÈrateur.
103         displayToLay.removeAllDisplays();
104                 
105         // On remet la flËche dans un Ètat qui est le sien, i.e. display d'opÈrateur.
106         ((Display) displayToLay.getComponent(0)).setIsSymbolOperatorDisplay(true);
107         
108         for (int i = 0; i < 2; i++)
109             displayToLay.add(listDisplay[i]);
110             
111         // La taille des displays est probablement diffÈrente de ceux qui Ètaient
112         // prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
113         displayToLay.computeAncestorsAttributes();
114     }
115    
116 }