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

bibliothek.gui.dock.perspective.PredefinedPerspective Maven / Gradle / Ivy

The 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) 2010 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.perspective;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import bibliothek.gui.dock.layout.PredefinedDockSituation;

/**
 * A {@link Perspective} that works together with {@link PredefinedDockSituation}. These perspectives
 * cannot be created directly, clients need to call {@link PredefinedDockSituation#createPerspective()} to
 * obtain an instance.
* Clients need to call {@link #put(String, PerspectiveElement)} in order to register the {@link PerspectiveElement}s * that are "predefined". * @author Benjamin Sigg */ public abstract class PredefinedPerspective extends Perspective{ private Map stringToElement = new HashMap(); private Map elementToString = new HashMap(); private List maps = new ArrayList(); /** * Creates a new perspective using situation to read and write elements. * @param situation the set of factories to use */ public PredefinedPerspective( PredefinedDockSituation situation ){ super( situation ); } @Override public PredefinedDockSituation getSituation() { return (PredefinedDockSituation)super.getSituation(); } /** * Adds an additional set of items to this perspective. * @param map the set of known items, not null */ public void put( PredefinedMap map ){ if( map == null ){ throw new IllegalArgumentException( "map must no be null" ); } maps.add( map ); } /** * Registers element on this {@link PredefinedPerspective}. When writing the layout the * identifier key will be written instead of element. * @param key the key of the element * @param element the new element */ public void put( String key, PerspectiveElement element ){ PerspectiveElement old = stringToElement.remove( key ); if( old != null ){ elementToString.remove( old ); } stringToElement.put( key, element ); elementToString.put( element, key ); } /** * Gets all the keys known to this perspective. * @return all the keys */ public String[] getKeys(){ return stringToElement.keySet().toArray( new String[ stringToElement.size() ] ); } /** * Gets the key for element. * @param element some element whose key is searched, not null * @return the key or null */ public String get( PerspectiveElement element ){ String result = elementToString.get( element ); if( result == null ){ for( PredefinedMap map : maps ){ result = map.get( element ); if( result != null ){ return result; } } } return result; } /** * Gets the element which was stored using key. * @param key the key of some element * @return the element or null */ public PerspectiveElement get( String key ){ PerspectiveElement result = stringToElement.get( key ); if( result == null ){ for( PredefinedMap map : maps ){ result = map.get( key ); if( result != null ){ return result; } } } return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy