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

bibliothek.gui.dock.common.intern.CDockFrontend Maven / Gradle / Ivy

Go to download

DockingFrames is an open source Java Swing docking framework, licenced under LGPL 2.1. This is the same distribution as the original distribution (http://www.docking-frames.org/), only reinstalled in maven

There is a newer version: 1.1.2p20b.fix-1
Show 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) 2008 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;

import java.util.ArrayList;
import java.util.List;

import bibliothek.gui.DockController;
import bibliothek.gui.DockFrontend;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.intern.layout.CLayoutChangeStrategy;
import bibliothek.gui.dock.common.mode.CLocationModeManager;
import bibliothek.gui.dock.facile.mode.Location;
import bibliothek.gui.dock.facile.mode.LocationSettingConverter;
import bibliothek.gui.dock.frontend.Setting;
import bibliothek.gui.dock.support.mode.ModeSettings;
import bibliothek.util.FrameworkOnly;

/**
 * A {@link DockFrontend} that uses {@link CSetting} instead of {@link Setting}.
 * @author Benjamin Sigg
 */
@FrameworkOnly
public class CDockFrontend extends DockFrontend{
    /** access to the internals of a {@link CControl} */
    private CControlAccess control;
    
    /** all the listeners of this frontend */
    private List listeners = new ArrayList();
    
    /** whether basic modes should be applied when loading a layout */
    private boolean revertToBasicModes = true;
    
    /**
     * Creates a new frontend.
     * @param control the owner of this object
     * @param controller the controller to use
     */
    public CDockFrontend( CControlAccess control, DockController controller ){
        super( controller );
        this.control = control;
        setLayoutChangeStrategy( new CLayoutChangeStrategy( control.getOwner() ) );
        registerAdjacentFactory( new RootStationAdjacentFactory() );
    }
    
    /**
     * Adds listener to this frontend, listener will be informed
     * about changes of this frontend.
     * @param listener the listener to add, not null
     */
    public void addListener( CDockFrontendListener listener ){
    	listeners.add( listener );
    }
    
    /**
     * Gets all the listeners that are registered at this frontend.
     * @return the listeners
     */
    protected CDockFrontendListener[] frontendListeners(){
    	return listeners.toArray( new CDockFrontendListener[ listeners.size() ] );
    }

    /**
     * Removes listener from this frontend.
     * @param listener the listener to remove
     */
    public void removeListener( CDockFrontendListener listener ){
    	listeners.remove( listener );
    }
    
    /**
     * If set, then loading a layout will trigger a call to {@link CLocationModeManager#ensureBasicModes()}.
     * @param revertToBasicModes whether to allow only basic modes after loading
     */
    public void setRevertToBasicModes( boolean revertToBasicModes ){
		this.revertToBasicModes = revertToBasicModes;
	}
    
    /**
     * Tells whether only basic modes are allowed after loading a layout.
     * @return true if non-basic modes are forbidden
     */
    public boolean isRevertToBasicModes(){
		return revertToBasicModes;
	}
    
    @Override
    public void remove( Dockable dockable ){
    	if( dockable instanceof CommonDockable ){
    		CDockable cdockable = ((CommonDockable)dockable).getDockable();
    		String key = control.shouldStore( cdockable );
    		if( key != null ){
    			addEmpty( key );
    		}
    	}
    	super.remove( dockable );
    }
    
    @Override
    protected Setting createSetting() {
        CSetting setting = new CSetting();
        CLocationModeManager manager = control.getLocationManager();
        ModeSettings modeSettings = manager.createSettings( new LocationSettingConverter( getController() ) );
        setting.setModes( modeSettings );
        return setting;
    }

    @Override
    public Setting getSetting( boolean entry ) {
    	CLocationModeManager manager = control.getLocationManager();
    	
    	CSetting setting = (CSetting)super.getSetting( entry );
        
        ModeSettings modeSettings = manager.createSettings( new LocationSettingConverter( getController() ) );
        setting.setModes( modeSettings );
        manager.writeSettings( modeSettings );
        
        return setting;
    }

    @Override
    public void setSetting( final Setting setting, final boolean entry ) {
    	for( CDockFrontendListener listener : frontendListeners() ){
    		listener.loading( this, (CSetting)setting );
    	}
    	try{
	    	CLocationModeManager manager = control.getLocationManager();
	        if( entry ){
	            manager.resetWorkingAreaChildren();
	        }
	
	        // location manager reads first to be able to change modes of dockables
	        manager.readSettings( ((CSetting)setting).getModes() );
	
	        // set new layout as transaction, preventing the manager to react on events
	        manager.runLayoutTransaction( new Runnable() {
				public void run(){
					CDockFrontend.super.setSetting( setting, entry );		
				}
	        });

	        if( revertToBasicModes ){
	        	manager.ensureBasicModes();
	        }
	        manager.refresh();
    	}
    	finally{
    		for( CDockFrontendListener listener : frontendListeners() ){
        		listener.loaded( this, (CSetting)setting );
        	}	
    	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy