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

bibliothek.gui.dock.station.toolbar.layout.DockablePlaceholderToolbarGrid 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.Collections;
import java.util.HashSet;
import java.util.Set;

import bibliothek.gui.DockStation;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.station.support.ConvertedPlaceholderListItem;
import bibliothek.gui.dock.station.support.DockablePlaceholderList;
import bibliothek.gui.dock.station.support.PlaceholderList;
import bibliothek.gui.dock.station.support.PlaceholderListItem;
import bibliothek.gui.dock.station.support.PlaceholderMap;
import bibliothek.gui.dock.station.support.PlaceholderMap.Key;
import bibliothek.gui.dock.station.support.PlaceholderStrategy;
import bibliothek.gui.dock.util.DockUtilities;
import bibliothek.gui.dock.util.DockUtilities.DockVisitor;
import bibliothek.util.Path;

/**
 * An implementation of {@link PlaceholderToolbarGrid} that uses {@link Dockable}s and {@link DockStation}s.
 * 
 * @author Benjamin Sigg
 * @param 

the kind of object that represents a {@link Dockable} */ public class DockablePlaceholderToolbarGrid

> extends ModeledPlaceholderToolbarGrid { /** * Creates and initializes a new grid */ public DockablePlaceholderToolbarGrid(){ init(); } @Override protected PlaceholderList createColumn(){ return new DockablePlaceholderList

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

(); } @Override protected Set getPlaceholders( Dockable dockable ){ final PlaceholderStrategy strategy = getStrategy(); if( strategy == null ) { return Collections.emptySet(); } final Set placeholders = new HashSet(); DockUtilities.visit( dockable, new DockVisitor(){ @Override public void handleDockable( Dockable dockable ){ final Path placeholder = strategy.getPlaceholderFor( dockable ); if( placeholder != null ) { placeholders.add( placeholder ); } } @Override public void handleDockStation( DockStation station ){ final PlaceholderMap map = station.getPlaceholders(); if( map != null ) { for( final Key key : map.getPlaceholders() ) { for( final Path placeholder : key.getPlaceholders() ) { placeholders.add( placeholder ); } } } } } ); return placeholders; } @Override protected void fill( Dockable dockable, ConvertedPlaceholderListItem item ){ final PlaceholderStrategy strategy = getStrategy(); if( strategy != null ) { final Path placeholder = strategy.getPlaceholderFor( dockable ); if( placeholder != null ) { item.putString( "placeholder", placeholder.toString() ); item.setPlaceholder( placeholder ); } } DockStation station = dockable.asDockStation(); if( station != null ){ item.setPlaceholderMap( station.getPlaceholders() ); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy