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

bibliothek.gui.dock.station.toolbar.layout.PerspectivePlaceholderToolbarGrid Maven / Gradle / Ivy

/*
 * 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) 2012 Herve Guillaume, 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
 * 
 * Herve Guillaume
 * [email protected]
 * FR - France
 *
 * Benjamin Sigg
 * [email protected]
 * CH - Switzerland
 */
package bibliothek.gui.dock.station.toolbar.layout;

import java.util.HashSet;
import java.util.Set;

import bibliothek.gui.dock.perspective.PerspectiveDockable;
import bibliothek.gui.dock.perspective.PerspectiveStation;
import bibliothek.gui.dock.station.support.ConvertedPlaceholderListItem;
import bibliothek.gui.dock.station.support.PerspectivePlaceholderList;
import bibliothek.gui.dock.station.support.PlaceholderList;
import bibliothek.util.Path;

/**
 * An implementation of {@link PlaceholderToolbarGrid} that uses {@link PerspectiveDockable}s
 * and {@link PerspectiveStation}s, thus is ideal to be used in the perspective API.
 * @author Benjamin Sigg
 */
public class PerspectivePlaceholderToolbarGrid extends ModeledPlaceholderToolbarGrid{
	/**
	 * Creates a new, empty grid.
	 */
	public PerspectivePlaceholderToolbarGrid(){
		init();
	}
	
	@Override
	protected PlaceholderList createColumn(){
		return new PerspectivePlaceholderList();
	}

	@Override
	protected GridPlaceholderList createGrid(){
		return new PerspectiveGridPlaceholderList();
	}

	@Override
	protected Set getPlaceholders( PerspectiveDockable dockable ){
		Set result = new HashSet();
		fill( result, dockable );
		return result;
	}
	
	private void fill( Set placeholders, PerspectiveDockable dockable ){
		Path placeholder = dockable.getPlaceholder();
		if( placeholder != null ){
			placeholders.add( placeholder );
		}
		PerspectiveStation station = dockable.asStation();
		if( station != null ){
			for( int i = 0, n = station.getDockableCount(); ioldDockable with newDockable.
	 * @param oldDockable a child of this grid
	 * @param newDockable the replacement of oldDockable
	 */
	public void replace( PerspectiveDockable oldDockable, PerspectiveDockable newDockable ){
		int column = getColumn( oldDockable );
		if( column == -1 ){
			throw new IllegalArgumentException( "oldDockable is not known to this grid" );
		}
		PlaceholderList list = getColumn( column );
		int index = list.dockables().indexOf( oldDockable );
		list.remove( index );
		list.dockables().add( index, newDockable );
	}

	@Override
	protected void fill( PerspectiveDockable dockable, ConvertedPlaceholderListItem item ){
		Path placeholder = dockable.getPlaceholder();
		if( placeholder != null ) {
			item.putString( "placeholder", placeholder.toString() );
			item.setPlaceholder( placeholder );
		}
		
		PerspectiveStation station = dockable.asStation();
		if( station != null ){
			item.setPlaceholderMap( station.getPlaceholders() );
		}
	}
	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy