View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import java.awt.*;
4   import fr.ove.openmath.jome.ctrlview.bidim.*;
5   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
6   import fr.ove.openmath.jome.model.*;
7   
8   /***
9   * A layout manager that lays components for the limit operator.
10  *
11  * @author © 2000 DIRAT Laurent
12  * @version 2.0 25/02/2000
13  */
14  public class LimitLayout extends HorizontalLayout {
15      /***
16      * According to the operator, the layout manager has to add some components (e.g. brackets, ...)
17      * or has to perform some "re-oganisation" before rendering.<BR>
18      * As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
19      * as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
20      * call super.initDisplay(displayToLay).
21      * @param displayToLay the display laid by the instance
22      */
23      public void initDisplay(Display displayToLay) {
24          super.initDisplay(displayToLay);
25          
26          KaryOperator limit = (KaryOperator) this.displayToLay.getListener();
27          
28          // Allocation d'un display, qui va correspondre ? la partie "lim" de la reprÈsentation
29          Display display = new BidimDisplay(displayToLay.getGraphicContext());
30          // On met un listener ? display
31          // En fait, il n'y en a pas besoin, dans le sens o? il n'y a pas spÈcifiquement de fts qui
32          // Ècoute le comportement de ce display. NÈanmoins, il s'avËre nÈcessaire qu'il en ait
33          // un, par exemple lors de l'iconification, car c'est le display qui reÁoit la demande
34          // d'iconification qui envoie l'ÈvÈnement correspondant ? la FTS. Or si ce display n'a pas
35          // d'Ècouteur, alors pb. Par cohÈrence, l'Ècouteur du display d'opÈrateur, est le fts qui
36          // reprÈsente cette opÈration. Par contre, la fts en question, n'Ècoute pas le display
37          // d'opÈrateur.
38          display.addControlListener(limit);
39          // On lui met dont un SymbolLimLayout
40          DisplayLayout layout = new SymbolLimLayout();
41          layout.initDisplay(display);
42          display.setLayout(layout);
43          
44          // On l'ajoute comme fils ? display
45          this.displayToLay.add(display);
46          
47          // On met un display pour l'affichage de lim
48          StringDisplay lim = new StringDisplay(this.displayToLay.getGraphicContext(), "lim", true);
49          // idem
50          lim.addControlListener(limit);
51          display.add(lim);
52          
53          // On met un display pour l'affichage de qui tend vers quoi
54          Display towards = new BidimDisplay(displayToLay.getGraphicContext());
55          towards.addControlListener(limit);
56          // On lui met un 
57          layout = new ImageBinaryInfixOperatorLayout();
58          layout.initDisplay(towards);
59          towards.setLayout(layout);
60          display.add(towards);
61      }
62      
63      /***
64      * Updates the level of the display that is layed out.<BR>
65      * @param level the level put to the display
66      */
67      public void updateLevel(int level) {
68          // Pour Èviter de refaire le calcul plusieurs fois....
69          if (displayToLay.getUpdateLevel()) {
70              super.updateLevel(level);
71              
72              // sauf que l'affichage de quoi tend vers quoi est a un niveu supÈrieur
73              Display towards = (Display) displayToLay.getComponent(0);
74              towards = (Display) towards.getComponent(1);
75              towards.setUpdateLevel(true);
76              ((DisplayLayout) towards.getLayout()).updateLevel(level+1);
77              towards = null;
78          }
79      }
80      
81      /***
82      * Checks the validity of the selection.
83      */
84      public void validateSelection() {
85          /*
86          SelectionEvent selEvt = new SelectionEvent(displayToLay);
87  
88          Display derivator = (Display) displayToLay.getComponent(0);
89          Display func = (Display) displayToLay.getComponent(1);
90          // Si le display de ce qui est la partie fraction de la dÈrivÈe (derivator) est sÈlectionnÈe,
91          // alors on sÈlectionne tout.
92          // Si la function et dÈrivator ont qque chose de sÈlectionnÈ, alors on sÈlectionne tout.
93          if (derivator.isSelected() || (func.gotSelectedElements() && derivator.gotSelectedElements())) {
94              displayToLay.select();
95              // On purge la liste des ÈlÈments sÈlectionnÈs.
96              selEvt.setAction(SelectionEvent.PURGE, null);
97              displayToLay.fireSelectionEvent(selEvt);
98              // On y ajoute l'instance dans la liste des sÈlectionnÈs
99              selEvt.setAction(SelectionEvent.ADD, displayToLay);
100             displayToLay.fireSelectionEvent(selEvt);
101         }
102         
103         // On a vÈrifiÈ la validitÈ de la sÈlection de l'opÈrateur. On doit maitenant
104         // la contrÙler au niveau supÈrieur, au niveau du pËre.
105         Display display = displayToLay;
106         if (displayToLay.getParent() instanceof Display) {
107             display = (Display) displayToLay.getParent();
108             //if (!(display.getListener() instanceof Formula))
109             FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
110             if (fts.getFather() != null)
111                 ((DisplayLayout) display.getLayout()).validateSelection();
112         }
113 
114         // On met ? jour l'affichage.
115         display.repaint();
116         */
117     }
118     
119     /***
120     * Checks the validity of the deselection.
121     * @param display the display to deselect.
122     */
123     public void validateDeselection(Display display) {
124         /*
125         // father est le display de l'opÈrateur unaire.
126         Display father = displayToLay;
127         Display tmp;
128         SelectionEvent selEvt = new SelectionEvent(father);
129         
130         // Si l'opÈrateur en entier est sÈlectionnÈ, il faut le dÈsÈlectionner
131         if (father.isSelected()) {
132             father.deselect();
133             // On enlËve le display pËre de la liste des display sÈlectionnÈs.
134             selEvt.setAction(SelectionEvent.REMOVE, father);
135             father.fireSelectionEvent(selEvt);
136             
137             // Si display est l'opÈrateur (on vient de dÈselectionner l'opÈrateur), alors
138             // on ajoute l'opÈrande dans la liste des sÈlectionnÈs.
139             if (display == displayToLay.getComponent(0)) {
140                 ((Display) displayToLay.getComponent(1)).select();
141                 selEvt.setAction(SelectionEvent.ADD, (Display) displayToLay.getComponent(1));
142                 father.fireSelectionEvent(selEvt);
143             }                
144             
145             // Comme pour la sÈlection, on contrÙle la validitÈ de la dÈsÈlection.
146             if (father.getParent() instanceof Display) {
147                 father = (Display) father.getParent();
148                 //((DisplayLayout) father.getLayout()).validateDeselection((Display) display.getParent());
149                 if (!(father.getListener() instanceof Formula))
150                     ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
151             }
152             
153             // HÈ oui, on contrÙle la validitÈ de la sÈlection... dans une dÈsÈlection.
154             // Toujours le mÍme pb, est-ce que le nouvel Ètat de la sÈlection (aprËs
155             // dÈsÈlection donc) est syntaxiquement cohÈrent ?
156             validateSelection();
157             
158             // On met ? jour l'affichage.
159             father.repaint();
160         } 
161         */
162     }
163         
164     
165     /***
166     * Computes the size of the display according to its children size (if any),
167     * and its different attributes.
168     * @return the size of the display.
169     */
170     public Dimension computeAttributes() {
171         Display towards = (Display) displayToLay.getComponent(0);
172         towards = (Display) towards.getComponent(1);
173         
174         if (displayToLay.getComponentCount() > 2) {
175             // Dans l'ordre, displayToLay contient [[lim, []], fct, var, borne]
176             // Il faut mettre var et borne, comme fils au display frËre de lim.
177             // Ce display a un LM qui rajoutera une --> entre var et borne.
178             // On aura donc [[lim, [var, rightArrow, borne]], fct]
179             
180             Display d;
181             d = (Display) displayToLay.getComponent(2);
182             // towards.add(d) appelle un displayToLay.remove(d).
183             // remove(d), enlËve Ègalement d de la liste des listeners de l'objet (fts) qu'il Ècoutait.
184             // Ce qu'on ne veut pas, puisqu'il s'agit d'un simple dÈplacement de display. 
185             d.setDoRemoveFromListListeners(false);
186             towards.add(d);
187             d.setDoRemoveFromListListeners(true);
188             //displayToLay contient [[lim [var]], fct, borne]
189             
190             d = (Display) displayToLay.getComponent(2);
191             // towards.add(d) appelle un displayToLay.remove(d).
192             // remove(d), enlËve Ègalement d de la liste des listeners de l'objet (fts) qu'il Ècoutait.
193             // Ce qu'on ne veut pas, puisqu'il s'agit d'un simple dÈplacement de display. 
194             d.setDoRemoveFromListListeners(false);
195             towards.add(d);
196             d.setDoRemoveFromListListeners(true);
197             //displayToLay contient [[lim [var, borne]], fct]            
198         }        
199         
200         ((Display) displayToLay.getComponent(1)).setShiftX(5);
201         updateLevel(displayToLay.getLevel());
202         Dimension dim = super.computeAttributes();
203         
204         return new Dimension(dim.width + 5, dim.height);
205     }
206     
207     /***
208     * The display needs to be rebuilt. We do this.
209     */
210     public void rebuildDisplay() {
211         // La taille des displays est probablement diffÈrente de ceux qui Ètaient
212         // prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
213         displayToLay.computeAncestorsAttributes();
214     }
215 }
216 
217 
218 class SymbolLimLayout extends VerticalCenteredLayout {
219     /***
220     * Computes the size of the display according to its children size (if any),
221     * and its different attributes.
222     * @return the size of the display.
223     */
224     public Dimension computeAttributes() {
225         Dimension dim = super.computeAttributes();
226         
227         displayToLay.setAscent(((Display) displayToLay.getComponent(0)).getAscent());
228         displayToLay.setDescent(displayToLay.getHeight() - displayToLay.getAscent());
229         
230         return dim;
231     }
232     
233     /***
234     * Checks the validity of the selection.
235     */
236     public void validateSelection() {
237         // To Do !!!!
238     }
239      /***
240     * Checks the validity of the deselection.
241     * @param display the display to deselect.
242     */
243     public void validateDeselection(Display display) {
244         // To Do !!!!
245     }
246     
247    /***
248     * The display needs to be rebuilt. We do this.
249     */
250     public void rebuildDisplay() {
251         // La taille des displays est probablement diffÈrente de ceux qui Ètaient
252         // prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
253         displayToLay.computeAncestorsAttributes();
254     }
255 }