View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import fr.ove.openmath.jome.ctrlview.bidim.*;
4   import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
5   import fr.ove.openmath.jome.model.*;
6   
7   /***
8   * A layout manager for an binary infix operator.
9   *
10  * @author © 1999 DIRAT Laurent
11  * @version 2.0  14/12/1999
12  */
13  public abstract class BinaryInfixOperatorLayout extends InfixOperatorLayout {    
14      /***
15      * Checks the validity of the selection.
16      */
17      public void validateSelection() {
18          SelectionEvent selEvt = new SelectionEvent(displayToLay);
19  
20          // La validitÈ de la sÈlection est triviale.
21          // Si les opÈrandes sont sÈlectionnÈs ou ont un ÈlÈment sÈlectionnÈ, ou si l'opÈrateur
22          // est sÈlectionnÈe, alors on sÈlectionne tout.
23          Display left = (Display) displayToLay.getComponent(0);
24          Display ope = (Display) displayToLay.getComponent(1);
25          Display right = (Display) displayToLay.getComponent(2);
26          if ((left.gotSelectedElements() && right.gotSelectedElements()) ||
27              (ope.isSelected())) {
28              // SÈlectionne le display.
29              displayToLay.select();
30              // On purge la liste des ÈlÈments sÈlectionnÈs.
31              selEvt.setAction(SelectionEvent.PURGE, null);
32              displayToLay.fireSelectionEvent(selEvt);
33              // On y ajoute l'opÈration
34              selEvt.setAction(SelectionEvent.ADD, displayToLay);
35              displayToLay.fireSelectionEvent(selEvt);
36          }
37  
38          // On a vÈrifiÈ la validitÈ de la sÈlection de la puissance. On doit maitenant
39          // la contrÙler au niveau supÈrieur, au niveau du pËre.
40          Display display = displayToLay;
41          if (displayToLay.getParent() instanceof Display) {
42              display = (Display) displayToLay.getParent();
43              FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
44              if (fts.getFather() != null)
45                  ((DisplayLayout) display.getLayout()).validateSelection();
46          }
47  
48          // On met ? jour l'affichage.
49          display.repaint();
50      }
51      
52      /***
53      * Checks the validity of the deselection.
54      * @param display the display to deselect.
55      */
56      public void validateDeselection(Display display) {
57          Display father = displayToLay;
58          SelectionEvent selEvt = new SelectionEvent(father);
59          
60          // Si l'opÈration est sÈlectionnÈe, alors il faut la dÈselectionner.
61          if (father.isSelected()) {
62              father.setNotSelected();
63              // On enlËve le display pËre de la liste des display sÈlectionnÈs.
64              selEvt.setAction(SelectionEvent.REMOVE, father);
65              father.fireSelectionEvent(selEvt);
66              
67              Display left = (Display) father.getComponent(0);
68              Display ope = (Display) father.getComponent(1);
69              Display right = (Display) father.getComponent(2);
70              
71              if (display == left) {
72                  ope.setNotSelected();
73                  selEvt.setAction(SelectionEvent.ADD, right);
74                  father.fireSelectionEvent(selEvt);
75              }
76              else if (display == right) {
77                  ope.setNotSelected();
78                  selEvt.setAction(SelectionEvent.ADD, left);
79                  father.fireSelectionEvent(selEvt);
80              }
81              else {
82                  left.deselect();
83                  ope.setNotSelected();
84                  right.deselect();
85              }
86  
87              // Comme pour la sÈlection, on contrÙle la validitÈ de la dÈsÈlection.
88              if (father.getParent() instanceof Display) {
89                  father = (Display) father.getParent();
90                  FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
91                  if (fts.getFather() != null)
92                      ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
93              }
94              
95              // HÈ oui, on contrÙle la validitÈ de la sÈlection... dans une dÈsÈlection.
96              // Toujours le mÍme pb, est-ce que le nouvel Ètat de la sÈlection (aprËs
97              // dÈsÈlection donc) est syntaxiquement cohÈrent ?
98              validateSelection();
99              
100             // On met ? jour l'affichage.
101             father.repaint();
102         }        
103     }
104 }