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
with{ /** * 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(); i oldDockable newDockable
. * @param oldDockable a child of this grid * @param newDockable the replacement ofoldDockable
*/ public void replace( PerspectiveDockable oldDockable, PerspectiveDockable newDockable ){ int column = getColumn( oldDockable ); if( column == -1 ){ throw new IllegalArgumentException( "oldDockable is not known to this grid" ); } PlaceholderListlist = 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() ); } } }