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

bibliothek.gui.dock.facile.mode.MappingLocationModeActionProvider 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 java.util.HashMap;
import java.util.Map;

import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.DockActionSource;
import bibliothek.gui.dock.support.mode.Mode;

/**
 * This {@link LocationModeActionProvider} mimics a map with keys managed by 
 * a subclass. In its {@link #getActions(Dockable, Mode, DockActionSource)}
 * method it selects the one provider whose key matches the current mode to provide the actions. 
 * @author Benjamin Sigg
 */
public abstract class MappingLocationModeActionProvider implements LocationModeActionProvider {
	/** tells for each dockable which provider was used last */
	private Map lastUsedProviders = new HashMap();
	
	public void destroy( Dockable dockable, DockActionSource source ){
		LocationModeActionProvider provider = lastUsedProviders.remove( dockable );
		if( provider != null ){
			provider.destroy( dockable, source );
		}
	}
	
	public DockActionSource getActions( Dockable dockable, Mode currentMode, DockActionSource currentSource ){
		LocationModeActionProvider provider = getProvider( dockable, currentMode, currentSource );
		if( provider == null ){
			lastUsedProviders.remove( dockable );
			return null;
		}
		else{
			lastUsedProviders.put( dockable, provider );
			return provider.getActions( dockable, currentMode, currentSource );
		}
	}
	
	/**
	 * Gets the {@link LocationModeActionProvider} which fits the key generated by the arguments
	 * of this method.
	 * @param dockable the element for which the actions will be used
	 * @param currentMode the current mode of dockable
	 * @param currentSource the current actions of dockable
	 * @return the provider or null
	 */
	protected abstract LocationModeActionProvider getProvider( Dockable dockable, Mode currentMode, DockActionSource currentSource );
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy