View Javadoc

1   /*
2   $Id: GroupLayout.java 711 2005-03-21 16:46:11Z guest $
3   */
4   
5   
6   /*
7   Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
8   
9   This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13  
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  Lesser General Public License for more details.
18  
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  
23  For further information on the GNU Lesser General Public License,
24  see: http://www.gnu.org/copyleft/lesser.html
25  For further information on this library, contact: mainline@essi.fr
26  */
27  
28  
29  package fr.ove.openmath.jome.ctrlview.bidim;
30  
31  import java.awt.*;
32  import fr.ove.openmath.jome.ctrlview.bidim.*;
33  import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
34  import fr.ove.openmath.jome.model.*;
35  import fr.ove.openmath.jome.behaviour.*;
36  
37  /***
38  * A layout manager that lays components to be displayed between something.<BR>
39  * Obviously, what is called something will be parenthesis, braces, ....
40  *
41  * @author © 1999 DIRAT Laurent
42  * @version 2.0  13/12/1999
43  */
44  public class GroupLayout extends HorizontalLayout {
45  
46      
47  	/***
48  	* According to the operator, the layout manager has to add some components (e.g. brackets, ...)
49  	* or has to perform some "re-oganisation" before rendering.<BR>
50  	* As soon as the layout manager is set to the display, this mehtod MUST be called with the display laid out
51  	* as parameter. This method serves as well as a registering method. So all sub-classes of the instance MUST
52  	* call super.initDisplay(displayToLay).
53  	* @param displayToLay the display laid by the instance
54  	*/
55  	public void initDisplay(Display displayToLay) {
56  		super.initDisplay(displayToLay);
57        
58  	}
59      
60  	/***
61  	* Checks the validity of the selection.
62  	*/
63  	public void validateSelection() {
64  
65  		// On a vÈrifiÈ la validitÈ de la sÈlection de la puissance. On doit maitenant
66  		// la contrÙler au niveau supÈrieur, au niveau du pËre.
67  		Display display = displayToLay;
68  		if (displayToLay.getParent() instanceof Display) {
69  			display = (Display) displayToLay.getParent();
70  			FormulaTreeStructure fts = (FormulaTreeStructure) display.getListener();
71  			if (fts.getFather() != null)
72  				((DisplayLayout) display.getLayout()).validateSelection();
73  		}
74  
75  		// On met ? jour l'affichage.
76  		display.repaint();
77  	}
78  
79  	/***
80  	* Checks the validity of the deselection.
81  	* @param display the display to deselect.
82  	*/
83  	public void validateDeselection(Display display) {
84  		Display father = displayToLay;
85  		Display tmp;
86  		SelectionEvent selEvt = new SelectionEvent(displayToLay);
87  
88  		// Si les parenthËses sont sÈlectionnÈes, alors il faut les dÈselectionner.
89  		if (father.isSelected()) {
90  			father.setNotSelected();
91  			// On enlËve le display pËre de la liste des display sÈlectionnÈs.
92  			selEvt.setAction(SelectionEvent.REMOVE, father);
93  			father.fireSelectionEvent(selEvt);
94  
95  			// Comme pour la sÈlection, on contrÙle la validitÈ de la dÈsÈlection.
96  			if (father.getParent() instanceof Display) {
97  				father = (Display) father.getParent();
98  				FormulaTreeStructure fts = (FormulaTreeStructure) father.getListener();
99  				if (fts.getFather() != null)
100 					((DisplayLayout) father.getLayout()).validateDeselection(displayToLay);
101 			}
102 
103 			// HÈ oui, on contrÙle la validitÈ de la sÈlection... dans une dÈsÈlection.
104 			// Toujours le mÍme pb, est-ce que le nouvel Ètat de la sÈlection (aprËs
105 			// dÈsÈlection donc) est syntaxiquement cohÈrent ?
106 			validateSelection();
107 
108 			// On met ? jour l'affichage.
109 			father.repaint();
110 		}
111 
112 	}
113 
114 	/***
115 	* Computes the size of the display according to its children size (if any),
116 	* and its different attributes.
117 	* @return the size of the display.
118 	*/
119 	public Dimension computeAttributes() {
120 		Display display = null;
121 
122 		if (((Maskable) displayToLay.getListener()).isVisible()) {
123             
124 			((Display) displayToLay.getComponent(0)).setShiftX(0);
125             
126 			Dimension dim = super.computeAttributes();
127             
128 			// Par contre, par rapport ? comment est calculÈe la taille display, dim comprend
129 			// dÈj? la largeur de opening et closing
130             
131 			// Mais il faut l'enlever au display du milieu qui doit Ítre contre l'opening (because HonrizontalLayout)
132 			//((Display) displayToLay.getComponent(2)).setShiftX(-closing.getShiftX() - closing.getWidth());
133             
134 			return dim;
135 		}
136 		else
137 			return super.computeAttributes();
138 	}
139 
140 	/***
141 	* The display needs to be rebuilt. We do this.
142 	*/
143 	public void rebuildDisplay() {
144 		// La taille des displays est probablement diffÈrente de ceux qui Ètaient
145 		// prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
146 		displayToLay.computeAncestorsAttributes();
147 	}
148         
149 	// ############################################
150 	// ### Les diffÈrentes mÈthodes abstraites  ###
151 	// ############################################
152 }