Back to index

wims  3.65+svn20090927
VerticalCenteredLayout.java
Go to the documentation of this file.
00001 /*
00002 $Id: VerticalCenteredLayout.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 VerticalCenteredLayout extends DisplayLayout {
00047     public Dimension computeAttributes() {
00048         int height = 0;
00049         int width1 = 0;
00050         int width2 = 0;
00051         int width = 0;
00052         int ascent;
00053         int descent;
00054         Display tmp;
00055         
00056         updateLevel(displayToLay.getLevel());
00057         
00058         int count = displayToLay.getComponentCount();
00059         for (int i = 0; i < count; i++) {
00060             tmp = (Display) displayToLay.getComponent(i);
00061             tmp.setSize(tmp.getPreferredSize());
00062         }
00063                     
00064         for (int i = 0; i < count; i++) {
00065             tmp = (Display) displayToLay.getComponent(i);
00066             
00067             width = (tmp.getWidth() / 2);
00068             
00069             width1 = Math.max( width - tmp.getShiftX(),
00070                                width1 );
00071             
00072             width = ((tmp.getWidth() % 2) == 0 ) ? width : (width + 1);
00073             width2 = Math.max( width + tmp.getShiftX(),
00074                                width2 );
00075             
00076             height += tmp.getAscent() + tmp.getDescent() + tmp.getShiftY();
00077         }
00078         
00079         // Possibles changements à effectuer pour ne pas mettre la
00080         // la ligne de référence au milieu de la BBox
00081         ascent = ( (height%2) == 0 ) ? (height / 2) : (height / 2) + 1 ;
00082         descent = ( (height%2) == 0 ) ? ascent : ascent - 1 ;
00083         
00084         displayToLay.setAscent(ascent);
00085         displayToLay.setDescent(descent);
00086         displayToLay.setSize(width1 + width2 , height);
00087         displayToLay.setComputeAttributes(false);
00088         
00089         return new Dimension(width1 + width2 , height);
00090     }
00091     
00092     // #################################################
00093     // ### Implémentation des différentes interfaces ###
00094     // #################################################
00095 
00096     // ***************************************************
00097     // *** Implémentation de l'interface LayoutManager ***
00098 
00099     /*
00100      * Lays out the container in the specified panel.
00101      * @param parent the component which needs to be laid out 
00102      */
00103      public void layoutContainer(Container parent) {
00104         int x, y;
00105         Display display, previous;
00106         
00107         int count = parent.getComponentCount();
00108         for ( int i = 0; i < count; i++ ) {
00109             display = (Display) parent.getComponent(i);
00110             
00111             display.setSize(display.getPreferredSize());
00112             
00113             x = (((Display) parent).getWidth() / 2) -
00114                 (display.getWidth() / 2) +
00115                 display.getShiftX();
00116             
00117             if ( i == 0 )
00118                 y = display.getShiftY();
00119             else {
00120                 previous = (Display) parent.getComponent(i-1);
00121                 y = previous.getY() + previous.getHeight() + display.getShiftY();
00122             }
00123             
00124             display.setLocation(x, y);
00125             
00126             // On place maintenant les éventuels display enfants du display courant
00127             display.doLayout();
00128         }
00129     }
00130 
00131     // *** Fin de l'interface LayoutManager ***
00132     // ****************************************
00133 }