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

bibliothek.gui.dock.common.perspective.CPerspectiveMultipleIdentifierCollection 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) 2007 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.common.perspective;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import bibliothek.gui.dock.common.intern.CommonMultipleDockableFactory;
import bibliothek.gui.dock.perspective.PerspectiveElement;

/**
 * A helper class for {@link CommonMultipleDockableFactory}, used when interacting with a {@link CPerspective}.
 * @author Benjamin Sigg
 */
public class CPerspectiveMultipleIdentifierCollection{
	private CPerspective perspective;

	private Map ids = new HashMap();
	
	/**
	 * Creates a new object
	 * @param factoryId the unique identifier of the factory that is using this collection
	 * @param perspective the owner of this object, not null
	 */
	public CPerspectiveMultipleIdentifierCollection( String factoryId, CPerspective perspective ){
		this.perspective = perspective;
		
		Iterator iterator = perspective.elements();
		while( iterator.hasNext() ){
			PerspectiveElement element = iterator.next();
			if( element instanceof CommonElementPerspective ){
				CElementPerspective celement = ((CommonElementPerspective)element).getElement();
				if( celement instanceof MultipleCDockablePerspective ){
					MultipleCDockablePerspective dockable = (MultipleCDockablePerspective)celement;
					if( dockable.getFactoryID().equals( factoryId ) && dockable.getUniqueId() != null ){
						ids.put( dockable.getUniqueId(), dockable );
					}
				}
			}
		}
	}
	
	/**
	 * Gets the owner of this access object.
	 * @return the owner
	 */
	public CPerspective getPerspective(){
		return perspective;
	}
	
	/**
	 * Searches or creates a unique identifier that matches element.
	 * @param element the element whose identifier is searched
	 * @return the identifier, may be null
	 */
	public String getUniqueId( MultipleCDockablePerspective element ){
		String id = element.getUniqueId();
		if( id == null ){
			String factory = element.getFactoryID();
			int count = 0;
	        id = count + " " + factory;
	        while( ids.containsKey( id )){
	            count++;
	            id = count + " " + factory;
	        }
	        element.setUniqueId( id );
		}
		MultipleCDockablePerspective old = ids.put( id, element );
		if( old != null && old != element ){
			throw new IllegalStateException( "unique identifier collision, id='" + id + "', old item='" + old + "', new item='" + element + "'");
		}
		return id;
	}

	/**
	 * Stores the element perspective using the identifier id.
	 * @param id the unique identifier of perspective
	 * @param perspective the new perspective
	 */
	public void putDockable( String id, MultipleCDockablePerspective perspective ){
		ids.put( id, perspective );
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy