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

bibliothek.gui.dock.extension.css.path.DefaultCssNode 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) 2012 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.extension.css.path;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import bibliothek.gui.dock.extension.css.CssNode;

/**
 * This {@link CssNode} offers the possibility to set any property
 * from outside at any time.
 * @author Benjamin Sigg
 */
public class DefaultCssNode extends AbstractCssNode{
	private String name;
	private String identifier;
	private Map properties;
	private Set classes;
	private Set pseudoClasses;

	/**
	 * Creates a new node
	 * @param name the name of this node, must not be null
	 */
	public DefaultCssNode( String name ){
		setName( name );
	}
	
	@Override
	public String getName(){
		return name;
	}
	
	@Override
	protected void bind(){
		// ignore
	}
	
	@Override
	protected void unbind(){
		// ignore	
	}
	
	/**
	 * Changes the name of this node.
	 * @param name the new name, not null
	 */
	public void setName( String name ){
		if( name == null || name.length() == 0 ){
			throw new IllegalArgumentException( "name must not be null nor must it have a length of 0" );
		}
		this.name = name;
		fireNodeChanged();
	}
	
	@Override
	public String getIdentifier(){
		return identifier;
	}
	
	/**
	 * Changes the identifier of this node.
	 * @param identifier the new identifier, can be null
	 */
	public void setIdentifier( String identifier ){
		this.identifier = identifier;
		fireNodeChanged();
	}
	
	@Override
	public String getProperty( String key ){
		if( properties == null ){
			return null;
		}
		return properties.get( key );
	}
	
	/**
	 * Changes a property of this node.
	 * @param key the name of the property
	 * @param value the new value, can be null
	 */
	public void putProperty( String key, String value ){
		if( value == null ){
			if( properties != null ){
				properties.remove( key );
				if( properties.isEmpty() ){
					properties = null;
				}
			}
		}
		else{
			if( properties == null ){
				properties = new HashMap();
			}
			properties.put( key, value );
		}
		fireNodeChanged();
	}
	
	@Override
	public boolean hasClass( String className ){
		if( classes == null ){
			return false;
		}
		return classes.contains( className );
	}
	
	/**
	 * Adds a class to this node.
	 * @param className the name of the class
	 */
	public void addClass( String className ){
		if( classes == null ){
			classes = new HashSet();
		}
		classes.add( className );
		fireNodeChanged();
	}
	
	/**
	 * Removes a class of this node.
	 * @param className the name of the class to remove
	 */
	public void removeClass( String className ){
		if( classes != null ){
			classes.remove( className );
			if( classes.isEmpty() ){
				classes = null;
			}
			fireNodeChanged();
		}
	}
	
	@Override
	public boolean hasPseudoClass( String className ){
		if( pseudoClasses == null ){
			return false;
		}
		return pseudoClasses.contains( className );
	}

	/**
	 * Adds a pseudo-class to this node.
	 * @param className the name of the class
	 */
	public void addPseudoClass( String className ){
		if( pseudoClasses == null ){
			pseudoClasses = new HashSet();
		}
		pseudoClasses.add( className );
		fireNodeChanged();
	}
	
	/**
	 * Removes a pseudo-class of this node.
	 * @param className the name of the class to remove
	 */
	public void removePseudoClass( String className ){
		if( pseudoClasses != null ){
			pseudoClasses.remove( className );
			if( pseudoClasses.isEmpty() ){
				pseudoClasses = null;
			}
			fireNodeChanged();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy