All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bibliothek.gui.dock.common.intern.station.CFlapLayoutManager Maven / Gradle / Ivy

The newest version!
/*
 * Bibliothek - DockingFrames
 * Library built on Java/Swing, allows the user to "drag and drop"
 * panels containing any Swing-Component the developer likes to add.
 * 
 * Copyright (C) 2007 Benjamin Sigg
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Benjamin Sigg
 * [email protected]
 * CH - Switzerland
 */
package bibliothek.gui.dock.common.intern.station;

import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;

import bibliothek.gui.DockStation;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.FlapDockStation;
import bibliothek.gui.dock.StackDockStation;
import bibliothek.gui.dock.FlapDockStation.Direction;
import bibliothek.gui.dock.common.event.CDockableAdapter;
import bibliothek.gui.dock.common.event.CDockablePropertyListener;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.intern.CommonDockable;
import bibliothek.gui.dock.event.DockStationAdapter;
import bibliothek.gui.dock.event.DockStationListener;
import bibliothek.gui.dock.station.flap.AbstractFlapLayoutManager;
import bibliothek.gui.dock.station.flap.FlapLayoutManager;
import bibliothek.util.FrameworkOnly;

/**
 * A {@link FlapLayoutManager} that uses the properties of {@link CDockable} to
 * find and store size and hold values.
 * @author Benjamin Sigg
 */
@FrameworkOnly
public class CFlapLayoutManager extends AbstractFlapLayoutManager implements FlapLayoutManager {
    /**
     * A listener added to each {@link FlapDockStation}.
     */
    private DockStationListener stationListener = new DockStationAdapter(){
        @Override
        public void dockableAdded( DockStation station, Dockable dockable ) {
            if( dockable instanceof CommonDockable ){
                ((CommonDockable)dockable).getDockable().addCDockablePropertyListener( propertyListener );
            }
        }
        @Override
        public void dockableRemoved( DockStation station, Dockable dockable ) {
            if( dockable instanceof CommonDockable ){
                ((CommonDockable)dockable).getDockable().removeCDockablePropertyListener( propertyListener );
            }
            else{
                holds.remove( dockable );
                sizes.remove( dockable );
            }
        }
    };
    
    /**
     * A listener added to each {@link CDockable}.
     */
    private CDockablePropertyListener propertyListener = new CDockableAdapter(){
        @Override
        public void stickyChanged( CDockable dockable ) {
            DockStation parent = dockable.intern().getDockParent();
            if( parent instanceof FlapDockStation ){
                ((FlapDockStation)parent).updateHold( dockable.intern() );
            }
        }
        @Override
        public void minimizeSizeChanged( CDockable dockable ) {
            DockStation parent = dockable.intern().getDockParent();
            if( parent instanceof FlapDockStation ){
                ((FlapDockStation)parent).updateWindowSize( dockable.intern() );
            }
        }
        public void stickySwitchableChanged( CDockable dockable ){
        	DockStation parent = dockable.intern().getDockParent();
            if( parent instanceof FlapDockStation ){
                fireHoldSwitchableChanged( (FlapDockStation)parent, dockable.intern() );
            }
        }
    };
    
    /** temporary storage of holds for non CommonDockables */
    private Map holds = new HashMap();
    
    /** temporary storage of sizes for non CommonDockables */
    private Map sizes = new HashMap();
    
    public void install( FlapDockStation station ) {
        station.addDockStationListener( stationListener );
        for( int i = 0, n = station.getDockableCount(); i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy