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   * This layout manager lays prefixed unary operators.<BR>
10  * Basically, unary + and unary - because these operators have the particularity to select the operand located
11  * to its left when selected.
12  *
13  * @author © 1999 DIRAT Laurent
14  * @version 2.0  13/12/1999
15  */
16  public abstract class LeftAssocPrefixedUnaryOperatorLayout extends UnaryOperatorLayout {
17      /***
18      * Do we have to select the display to the left of the one the instance lays ?
19      */
20      private boolean selectLeftDisplay;
21      
22      /***
23      * Returns <CODE>true</CODE> if during the selection, the display which is located
24      * to the left of the display that the instance lays, must be selected too.
25      * <CODE>false</CODE> otherwise.
26      */
27      public boolean selectLeftDisplay() {
28          // On est dans les opÈrateurs unaires, donc si le display tout entier
29          // est sÈlectionnÈ, alors cela revient ? avoir sÈlectionnÈ l'opÈrateur,
30          // et donc il faut sÈlectionner le display de gauche dans la liste de 
31          // display de son pËre.
32          if (displayToLay.isSelected())
33              return selectLeftDisplay;
34          else
35              return false;
36      }    
37      
38      /***
39      * Sets if the display to the left of that laid by the instance have to be selected
40      * or not.
41      * @param selectLeftDisplay <CODE>true</CODE> if the left display have to be selected.
42      * <CODE>false</CODE> otherwise.
43      */
44      public void setSelectLeftDisplay(boolean selectLeftDisplay) {
45          this.selectLeftDisplay = selectLeftDisplay;
46      }
47      
48      /***
49      * Checks the validity of the selection.
50      */
51      public void validateSelection() {
52          SelectionEvent selEvt = new SelectionEvent(displayToLay);
53  
54          // La validitÈ de la sÈlection est triviale.
55          // Si le display de l'opÈrateur ou si le display de l'opÈrande est
56          // sÈlectionnÈ, on sÈlectionne tout le display.
57          Display op = (Display) displayToLay.getComponent(0);
58          Display opRand = (Display) displayToLay.getComponent(1);
59          if (op.isSelected() || opRand.isSelected()) {
60              
61              selectLeftDisplay = op.isSelected() ? true : false;
62              
63              displayToLay.select();
64              // On purge la liste des ÈlÈments sÈlectionnÈs.
65              selEvt.setAction(SelectionEvent.PURGE, null);
66              displayToLay.fireSelectionEvent(selEvt);
67              // On y ajoute l'instance dans la liste des sÈlectionnÈs
68              selEvt.setAction(SelectionEvent.ADD, displayToLay);
69              displayToLay.fireSelectionEvent(selEvt);
70          }
71          
72          // On a vÈrifiÈ la validitÈ de la sÈlection de l'opÈrateur. On doit maitenant
73          // la contrÙler au niveau supÈrieur, au niveau du pËre.
74          Display display = displayToLay;
75          if (displayToLay.getParent() instanceof Display) {
76              display = (Display) displayToLay.getParent();
77              FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
78              if (fts.getFather() != null)
79                  ((DisplayLayout) display.getLayout()).validateSelection();
80          }
81  
82          // On met ? jour l'affichage.
83          display.repaint();
84      }             
85      
86      /***
87      * Checks the validity of the deselection.
88      * @param display the display to deselect.
89      */
90      public void validateDeselection(Display display) {
91          // father est le display de l'opÈrateur unaire.
92          Display father = displayToLay;
93          Display tmp;
94          SelectionEvent selEvt = new SelectionEvent(father);
95          
96          // Si l'opÈrateur en entier est sÈlectionnÈ, il faut le dÈsÈlectionner
97          if (father.isSelected()) {
98              selectLeftDisplay = false;
99              father.deselect();
100             // On enlËve le display pËre de la liste des display sÈlectionnÈs.
101             selEvt.setAction(SelectionEvent.REMOVE, father);
102             father.fireSelectionEvent(selEvt);
103             
104             // Comme pour la sÈlection, on contrÙle la validitÈ de la dÈsÈlection.
105             if (father.getParent() instanceof Display) {
106                 father = (Display) father.getParent();
107                 FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
108                 if (fts.getFather() != null)
109                     ((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
110             }
111             
112             // HÈ oui, on contrÙle la validitÈ de la sÈlection... dans une dÈsÈlection.
113             // Toujours le mÍme pb, est-ce que le nouvel Ètat de la sÈlection (aprËs
114             // dÈsÈlection donc) est syntaxiquement cohÈrent ?
115             validateSelection();
116             
117             // On met ? jour l'affichage.
118             father.repaint();
119         }
120     }
121 }