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

bibliothek.gui.dock.common.preference.ThemeChoice 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) 2008 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.preference;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import bibliothek.extension.gui.dock.preference.preferences.choice.DefaultChoice;
import bibliothek.gui.DockController;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.gui.dock.themes.ThemeFactory;
import bibliothek.gui.dock.themes.ThemeMeta;
import bibliothek.gui.dock.themes.ThemeMetaListener;

/**
 * A choice offering all the {@link ThemeFactory}s a {@link ThemeMap} provides.
 * @author Benjamin Sigg
 */
public class ThemeChoice extends DefaultChoice{
	/** all the wrappers that are currently used */
	private List wrappers = new ArrayList();
	
    /**
     * Creates a new set of choices.
     * @param themes the map to read
     * @param controller the controller in whose realm this choice is required, can be null
     */
    public ThemeChoice( ThemeMap themes, DockController controller ){
    	super( controller );
    	
        setNullEntryAllowed( false );
        
        for( int i = 0, n = themes.size(); i iterator = wrappers.iterator();
    	while( iterator.hasNext() ){
    		FactoryWrapper wrapper = iterator.next();
    		if( wrapper.key.equals( id )){
    			wrapper.setController( null );
    			iterator.remove();
    		}
    	}
    }
    
    /**
     * A wrapper around a {@link ThemeFactory}, updates the name if required.
     * @author Benjamin Sigg
     */
    private class FactoryWrapper implements ThemeMetaListener{
    	private String key;
    	private ThemeFactory factory;
    	private ThemeMeta meta;
    	private Entry entry;
    	
    	public FactoryWrapper( String key, ThemeFactory factory ){
    		this.key = key;
    		this.factory = factory;
    	}
    	
    	public void install(){
    		entry = add( key, "", factory );
    	}
    	
    	public void setController( DockController controller ){
    		if( controller == null ){
    			entry.setEntryText( "" );
    			if( meta != null ){
	    			meta.removeListener( this );
	    			meta = null;
    			}
    		}
    		else{
    			if( meta != null ){
    				meta.removeListener( this );
    				meta = null;
    			}
    			meta = factory.createMeta( controller );
    			meta.addListener( this );
    			entry.setEntryText( meta.getName() );
    		}
    	}
    	
    	public void nameChanged( ThemeMeta meta ){
    		entry.setEntryText( meta.getName() );
    	}
    	
    	public void authorsChanged( ThemeMeta meta ){
    		// ignore
    	}
    	
    	public void descriptionChanged( ThemeMeta meta ){
    		// ignore
    	}
    	
    	public void webpagesChanged( ThemeMeta meta ){
	    	// ignore	
    	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy