View Javadoc

1   /*
2   $Id: OverLayout.java 726 2005-04-05 12:09:09Z 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  
33  import fr.ove.openmath.jome.ctrlview.bidim.Display;
34  import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
35  import fr.ove.openmath.jome.ctrlview.bidim.HorizontalLayout;
36  import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
37  import fr.ove.openmath.jome.model.*;
38  
39  /***
40  * A layout manager that lays components horyzontally, but the last one in the
41  * list, is treated as a superscript (there is an upward shitf).
42  *
43  * @author © 1999 DIRAT Laurent
44  * @version 2.0 13/12/1999
45  */
46  public class OverLayout extends HorizontalLayout {
47  //public class OverLayout extends VerticalCenteredLayout{
48  	/***
49  	* Computes the size of the display according to its children size (if any),
50  	* and its different attributes.
51  	* @return the size of the display.
52  	*/
53  
54  	public Dimension computeAttributes() {
55  		int ascent = 0;
56  		int descent = 0;
57  		int width = 0;
58  		int height = 0;
59          
60  		Display base, exponent;
61  		int decalage = 0;
62          
63  		base = (Display) displayToLay.getComponent(0);
64  		base.setSize(base.getPreferredSize());
65  		width += base.getWidth();
66          
67  		exponent = (Display) displayToLay.getComponent(1);
68  
69  		if (base.getLayout() instanceof OverLayout)
70  			((DisplayLayout) exponent.getLayout()).updateLevel(((Display) base.getComponent(1)).getLevel()+ 1);
71  		else
72  			((DisplayLayout) exponent.getLayout()).updateLevel(base.getLevel()+ 1);
73          
74  		exponent.setSize(exponent.getPreferredSize());
75  		
76  		width = Math.max(width, exponent.getWidth());
77          
78  		if (base.getLayout() instanceof OverLayout) {
79  			Display exp_base = (Display) base.getComponent(1);
80  			decalage = computeExponentShift(exp_base, exponent);
81  		}
82  		else
83  			decalage = computeExponentShift(base, exponent);
84          
85  		/* ############################# */
86  	//	base.setShiftY(0); // ATTENTION : rajout !!!!!!
87  		/* ############################# */
88  
89  		exponent.setShiftY(-decalage);
90  		exponent.setShiftX(- (base.getWidth() + exponent.getWidth()) /2);
91  		//exponent.setShiftX(-(exponent.getWidth() + base.getWidth())/2);
92  	
93  		base.setShiftX((width - base.getWidth())/2);
94  		
95  		//exponent.setShiftX();
96  	//	base.setShiftX(0);
97  		
98  		//width += exponent.getWidth() + exponent.getShiftX();
99                  
100 		displayToLay.setDescent(base.getDescent()); 
101 		displayToLay.setAscent(decalage + exponent.getAscent());
102 		height += displayToLay.getAscent() + displayToLay.getDescent();
103 		displayToLay.setSize(width , height);
104         
105 		displayToLay.setComputeAttributes(false);
106 		return new Dimension(width, height);
107 	}
108     
109 	/***
110 	* Computes the shift of the script display.
111 	* @param base the base of the script.
112 	* @param script the script of the script.
113 	*/
114 	private /*public*/ int computeExponentShift(Display base, Display script) {
115 		//if (base instanceof StringDisplay)
116 			return (int) (base.getAscent() + script.getDescent());// - base.getShiftY();
117 		//else 
118 		//	return (int) (Math.round(base.getAscent()*0.7)) + script.getDescent() -
119 			//						 base.getShiftY();
120 	}
121 	
122     public void rebuildDisplay() {
123         
124         //Faudra faire ce qui faut !!!!
125         
126         // La taille des displays est probablement diffÈrente de ceux qui Ètaient
127         // prÈcÈdemment. On demande alors le recalcul des display ancÍtres.
128         displayToLay.computeAncestorsAttributes();
129     }
130 
131     public void validateSelection() {
132         // To Do !!!!
133     }
134      /***
135     * Checks the validity of the deselection.
136     * @param display the display to deselect.
137     */
138     public void validateDeselection(Display display) {
139         // To Do !!!!
140     }
141     
142 	
143 }