Back to index

wims  3.65+svn20090927
DisplayLayout.java
Go to the documentation of this file.
00001 /*
00002 $Id: DisplayLayout.java,v 1.3 2003/02/18 11:48:46 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 java.io.Serializable;
00033 import java.lang.IllegalArgumentException;
00034 import fr.ove.openmath.jome.ctrlview.bidim.Display;
00035 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
00036 
00043 public abstract class DisplayLayout implements LayoutManager2, Serializable , Cloneable {
00047     protected Display displayToLay = null;
00048     
00049     
00058     public void initDisplay(Display displayToLay) {
00059         this.displayToLay = displayToLay;
00060     }
00061     
00062     
00068     public boolean selectLeftDisplay() {
00069         return false;
00070     }
00071     
00077     public boolean selectRightDisplay() {
00078         return false;
00079     }
00080     
00085     public void selectDisplay() {
00086         displayToLay.select();
00087         
00088         SelectionEvent selEvt = new SelectionEvent(displayToLay);
00089         // On purge la liste des éléments sélectionnés.
00090         selEvt.setAction(SelectionEvent.PURGE, null);
00091         displayToLay.fireSelectionEvent(selEvt);
00092         selEvt.setAction(SelectionEvent.ADD, displayToLay);
00093         displayToLay.fireSelectionEvent(selEvt);
00094         
00095         Display display = displayToLay;
00096         if (displayToLay.getParent() instanceof Display) {
00097             display = (Display) displayToLay.getParent();
00098             ((DisplayLayout) display.getLayout()).validateSelection();
00099         }
00100     }
00101 
00102 
00107     public void deselectDisplay() {
00108         displayToLay.deselect();
00109 
00110         SelectionEvent selEvt = new SelectionEvent(displayToLay);
00111         selEvt.setAction(SelectionEvent.REMOVE, displayToLay);
00112         displayToLay.fireSelectionEvent(selEvt);
00113         
00114         if (displayToLay.getParent() instanceof Display) {
00115             Display display = (Display) displayToLay.getParent();
00116             ((DisplayLayout) display.getLayout()).validateDeselection(displayToLay);
00117         }
00118     }
00119     
00120     
00126     public void updateLevel(int level) {
00127         Display tmp;
00128         
00129         if (displayToLay.getUpdateLevel()) {
00130             // On met le niveau adéquat
00131             displayToLay.setLevel(level);
00132             // On scale le display en fonction du niveau
00133             displayToLay.scaleDisplay();
00134             // On n'a plus besoin de mettre à jour le niveau de l'instance
00135             displayToLay.setUpdateLevel(false);
00136             // Le comportement par défaut est que les displays enfant de l'instance courante
00137             // ont le même niveau que leur père.
00138             int count = displayToLay.getComponentCount();
00139             for (int i = 0; i < count; i++) {
00140                 tmp = (Display) displayToLay.getComponent(i);
00141                 ((DisplayLayout) tmp.getLayout()).updateLevel(level);
00142             }
00143         }
00144     }
00145     
00146     
00147     // ############################################
00148     // ### Les différentes méthodes abstraites  ###
00149     // ############################################
00150     
00151     
00155     public abstract void validateSelection();
00156     
00161     public abstract void validateDeselection(Display display);
00162     
00166     public abstract void rebuildDisplay();
00167     
00174     public abstract Dimension computeAttributes();
00175     
00176     // #################################################
00177     // ### Implémentation des différentes interfaces ###
00178     // #################################################
00179     
00180     // ***************************************************
00181     // *** Implémentation de l'interface LayoutManager ***
00182     
00189     public void addLayoutComponent(String name, Component comp) {
00190     }
00191 
00196     public void removeLayoutComponent(Component comp) {
00197     }
00198 
00205     public Dimension minimumLayoutSize(Container parent) {
00206         return preferredLayoutSize(parent);
00207     }
00208     
00216     public Dimension preferredLayoutSize(Container parent) {
00217         if (((Display) parent).getComputeAttributes())
00218             return computeAttributes();
00219         else
00220             return parent.getSize();
00221     }
00222     
00223     // *** Fin de l'interface LayoutManager ***
00224     // ****************************************
00225     
00226     
00227     // ****************************************************
00228     // *** Implémentation de l'interface LayoutManager2 ***
00229 
00236     public void addLayoutComponent(Component comp, Object constraints) {
00237            if (!(constraints instanceof Display))
00238               throw new IllegalArgumentException("The component to add must be a Display instance !!!");
00239     }
00240 
00247     public Dimension maximumLayoutSize(Container target) {
00248         return preferredLayoutSize(target);
00249     }
00250 
00258     public float getLayoutAlignmentX(Container target) {
00259         return 0.0f;
00260     }
00261 
00269     public float getLayoutAlignmentY(Container target) {
00270         return 0.0f;
00271     }
00272 
00277     public void invalidateLayout(Container target) {
00278     }
00279     
00280     // *** Fin de l'interface LayoutManager ***
00281     // ****************************************
00282 }
00283