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   import fr.ove.openmath.jome.behaviour.*;
8   
9   
10  
11  public  class Function2Layout extends HorizontalLayout{
12  	
13  	/***
14  	* According to the operator, the layout manager has to add some components (e.g. brackets, ...)
15  	* or has to perform some "re-oganisation" before rendering.<BR>
16  	* As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
17  	* as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
18  	* call super.initDisplay(displayToLay).
19  	* @param displayToLay the display laid by the instance
20  	*/
21  	public void initDisplay(Display displayToLay) {
22  		super.initDisplay(displayToLay);
23        
24  	}
25      
26  	/***
27  	* Checks the validity of the selection.
28  	*/
29  	public void validateSelection() {
30  
31  		// On a vÈrifiÈ la validitÈ de la sÈlection de la puissance. On doit maitenant
32  		// la contrÙler au niveau supÈrieur, au niveau du pËre.
33  		Display display = displayToLay;
34  		if (displayToLay.getParent() instanceof Display) {
35  			display = (Display) displayToLay.getParent();
36  			FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
37  			if (fts.getFather() != null)
38  				((DisplayLayout) display.getLayout()).validateSelection();
39  		}
40  
41  		// On met ? jour l'affichage.
42  		display.repaint();
43  	}
44  
45  	/***
46  	* Checks the validity of the deselection.
47  	* @param display the display to deselect.
48  	*/
49  	public void validateDeselection(Display display) {
50  		Display father = displayToLay;
51  		Display tmp;
52  		SelectionEvent selEvt = new SelectionEvent(displayToLay);
53  
54  		// Si les parenthËses sont sÈlectionnÈes, alors il faut les dÈselectionner.
55  		if (father.isSelected()) {
56  			father.setNotSelected();
57  			// On enlËve le display pËre de la liste des display sÈlectionnÈs.
58  			selEvt.setAction(SelectionEvent.REMOVE, father);
59  			father.fireSelectionEvent(selEvt);
60  
61  			// Comme pour la sÈlection, on contrÙle la validitÈ de la dÈsÈlection.
62  			if (father.getParent() instanceof Display) {
63  				father = (Display) father.getParent();
64  				FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
65  				if (fts.getFather() != null)
66  					((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
67  			}
68  
69  			// HÈ oui, on contrÙle la validitÈ de la sÈlection... dans une dÈsÈlection.
70  			// Toujours le mÍme pb, est-ce que le nouvel Ètat de la sÈlection (aprËs
71  			// dÈsÈlection donc) est syntaxiquement cohÈrent ?
72  			validateSelection();
73  
74  			// On met ? jour l'affichage.
75  			father.repaint();
76  		}
77  
78  	}
79  
80  	/***
81  	* Computes the size of the display according to its children size (if any),
82  	* and its different attributes.
83  	* @return the size of the display.
84  	*/
85  	public Dimension computeAttributes() {
86  		Display display = null;
87  
88  		if (((Maskable) displayToLay.getListener()).isVisible()) {
89              
90  			((Display) displayToLay.getComponent(0)).setShiftX(0);
91              
92  			Dimension dim = super.computeAttributes();
93              
94  			// Par contre, par rapport ? comment est calculÈe la taille display, dim comprend
95  			// dÈj? la largeur de opening et closing
96              
97  			// Mais il faut l'enlever au display du milieu qui doit Ítre contre l'opening (because HonrizontalLayout)
98  			//((Display) displayToLay.getComponent(2)).setShiftX(-closing.getShiftX() - closing.getWidth());
99              
100 			return dim;
101 		}
102 		else
103 			return super.computeAttributes();
104 	}
105 
106 	/***
107 	* The display needs to be rebuilt. We do this.
108 	*/
109 	public void rebuildDisplay() {
110 		// La taille des displays est probablement diffÈrente de ceux qui Ètaient
111 		// prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
112 		displayToLay.computeAncestorsAttributes();
113 	}
114         
115 	// ############################################
116 	// ### Les diffÈrentes mÈthodes abstraites  ###
117 	// ############################################
118 	
119 	
120 }