Back to index

wims  3.65+svn20090927
VerticalLayout.java
Go to the documentation of this file.
00001 /*
00002 $Id: VerticalLayout.java,v 1.3 2003/02/18 11:48:47 sander Exp $
00003 */
00004 
00005 
00006 /*
00007 Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2.1 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 For further information on the GNU Lesser General Public License,
00024 see: http://www.gnu.org/copyleft/lesser.html
00025 For further information on this library, contact: mainline@essi.fr
00026 */
00027 
00028 
00029 package fr.ove.openmath.jome.ctrlview.bidim;
00030 
00031 import java.awt.*;
00032 import fr.ove.openmath.jome.ctrlview.bidim.DisplayLayout;
00033 import fr.ove.openmath.jome.ctrlview.bidim.Display;
00034 
00041 public abstract class VerticalLayout extends DisplayLayout {
00047     public Dimension computeAttributes() {
00048         int height = 0;
00049         int width = 0;
00050         int ascent;
00051         int descent;
00052         Display tmp;
00053         
00054         int count = displayToLay.getComponentCount();
00055         for ( int i = 0; i < count; i++ ) {
00056             tmp = (Display) displayToLay.getComponent(i);
00057             tmp.setSize(tmp.getPreferredSize());
00058         }
00059         
00060         for (int i = 0; i < count; i++) {
00061             tmp = (Display) displayToLay.getComponent(i);
00062             
00063             width = Math.max(width, tmp.getWidth() + tmp.getShiftX());
00064             height += tmp.getHeight() + tmp.getShiftY();
00065         }
00066         
00067         // Possibles changements à effectuer pour ne pas mettre la
00068         // la ligne de référence au milieu de la BBox
00069         ascent = ( (height%2) == 0 ) ? (height / 2) : (height / 2) + 1 ;
00070         descent = ( (height%2) == 0 ) ? ascent : ascent - 1 ;
00071         
00072         displayToLay.setAscent(ascent);
00073         displayToLay.setDescent(descent);
00074         displayToLay.setSize(width , height);
00075         displayToLay.setComputeAttributes(false);
00076         
00077         return new Dimension(width, height);
00078     }
00079 
00080     // #################################################
00081     // ### Implémentation des différentes interfaces ###
00082     // #################################################
00083 
00084     // ***************************************************
00085     // *** Implémentation de l'interface LayoutManager ***
00086 
00087     /*
00088      * Lays out the container in the specified panel.
00089      * @param parent the component which needs to be laid out
00090      */
00091      public void layoutContainer(Container parent) {
00092         int x, y;
00093         Display display, previous;
00094 
00095         // Ca c'est parce que c'est le layout manager de la formule. Et comme personne ne dit au container
00096         // contenant la formule, que la taille de la formule a besoin d'être recalculée, il faut bien le
00097         // faire qque part. Chaque display informe son père qu'il doit être recalculé, mais la formule ne
00098         // le fait pas pour le sien.
00099         parent.setSize(parent.getPreferredSize());
00100         
00101         int count = parent.getComponentCount();
00102         for ( int i = 0; i < count; i++ ) {
00103             display = (Display) parent.getComponent(i);
00104             
00105             display.setSize(display.getPreferredSize());
00106             
00107             x = display.getShiftX();
00108 
00109             if ( i == 0 )
00110                 y = display.getShiftY();
00111             else {
00112                 previous = (Display) parent.getComponent(i-1);
00113                 y = previous.getY() + previous.getHeight() + display.getShiftY();
00114             }
00115             
00116             display.setLocation(x, y);
00117             
00118             // On place maintenant les éventuels display enfants du display courant
00119             display.doLayout();
00120         }
00121     }
00122 
00123     // *** Fin de l'interface LayoutManager ***
00124     // ****************************************
00125 }