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

bibliothek.gui.dock.facile.mode.DefaultLocationMode 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) 2009 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.facile.mode;

import bibliothek.gui.DockStation;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.layout.DockableProperty;
import bibliothek.gui.dock.support.mode.AffectedSet;
import bibliothek.gui.dock.support.mode.Mode;


/**
 * Abstract implementation of a {@link Mode} that works with {@link Location}s. This 
 * implementation offers a {@link #runApply(Dockable, Location, AffectedSet)} and 
 * {@link Mode#apply(Dockable, Object, AffectedSet)} method.
 * @author Benjamin Sigg
 * @param  the areas that are managed by this mode
 */
public abstract class DefaultLocationMode extends AbstractLocationMode{
	/**
	 * This default implementation just returns the location of
	 * dockable but does not change any properties.
	 */
	public Location current( Dockable dockable ){
		A area = get( dockable, true );
		if( area == null )
			return null;
		DockableProperty location = area.getLocation( dockable );
		return new Location( getUniqueIdentifier(), area.getUniqueId(), location, false );
	}
	
	/**
	 * This default implementation uses the {@link DockStation#move(Dockable, DockableProperty)}
	 * and {@link DockStation#drop(Dockable, DockableProperty)} methods to put
	 * dockable at its location.
	 */
	public boolean runApply( Dockable dockable, Location history, AffectedSet set ){
		A area = null;
		if( history != null ) 
			area = get( history.getRoot() );
		if( area == null )
			area = getDefaultArea();
		
		if( area == null ){
			if( history == null ){
				throw new IllegalStateException( "unable to find valid target, no history available" );	
			}
			else{
				throw new IllegalStateException( "unable to find valid target '" + history.getRoot() + "'" );
			}
		}
		
		DockableProperty location = history == null ? null : history.getLocation();
		return area.setLocation( dockable, location, set );
	}

	/**
	 * This default implementation calls {@link StationModeArea#isChild(Dockable)} on each
	 * area of this mode and returns true if at least one area returns true.
	 */
	public boolean isCurrentMode( Dockable dockable ){
		for( A area : this ){
			if( area.isChild( dockable )){
				return true;
			}
		}
		return false;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy