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

bibliothek.gui.dock.common.action.CDropDownButton 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.action;

import javax.swing.Icon;

import bibliothek.gui.dock.action.DockAction;
import bibliothek.gui.dock.common.action.core.CommonDockAction;
import bibliothek.gui.dock.common.action.core.CommonSimpleDropDownAction;
import bibliothek.gui.dock.common.intern.action.CDecorateableAction;

/**
 * A dropdown-button, the last action which was selected by the user will be
 * marked graphically.
 * @author Benjamin Sigg
 */
public class CDropDownButton extends CDecorateableAction{
    /**
     * Creates a new dropdown-button
     */
    public CDropDownButton(){
    	super( null );
        init( new CommonSimpleDropDownAction( this ));
    }
    
    /**
     * Creates a new dropdown-button
     * @param text the text of this button
     * @param icon the icon of this button
     */
    public CDropDownButton( String text, Icon icon ){
        this();
        setText( text );
        setIcon( icon );
    }
    
    /**
     * Adds an action to this menu.
     * @param action the new action
     */
    public void add( CAction action ){
       intern().add( action.intern() );
    }

    /**
     * Adds an action to the menu.
     * @param index the location of the action
     * @param action the new action
     */
    public void insert( int index, CAction action ){
    	intern().insert( index, action.intern() );
    }
    
    /**
     * Adds a separator at the end of this menu.
     */
    public void addSeparator(){
        add( CSeparator.SEPARATOR );
    }
    
    /**
     * Adds a separator. 
     * @param index the location of the new separator
     */
    public void insertSeparator( int index ){
        insert( index, CSeparator.SEPARATOR );
    }
    
    /**
     * Gets the number of {@link DockAction}s that were added to this menu.
     * @return the number of actions
     */
    public int getActionCount(){
    	return intern().size();
    }
    
    /**
     * Gets the index'th action of this menu.
     * @param index the index of the action
     * @return the action or null if the index'th 
     * {@link DockAction} is not a {@link CommonDockAction} (and hence no {@link CAction}
     * can be found)
     */
    public CAction getAction( int index ){
    	DockAction action = intern().getDockAction( index );
    	if( action instanceof CommonDockAction ){
    		return ((CommonDockAction)action).getAction();
    	}
    	return null;
    }
    
    /**
     * Removes the action at location index.
     * @param index the location of the element to remove
     */
    public void remove( int index ){
    	intern().remove( index );
    }
    
    /**
     * Removes an action from this menu
     * @param action the action to remove
     */
    public void remove( CAction action ){
    	intern().remove( action.intern() );
    }
    
    /**
     * Sets the current selected action.
     * @param action the action to select.
     */
    public void setSelection( CAction action ){
    	intern().setSelection( action.intern() );
    }
    
    /**
     * Gets the currently selected action.
     * @return the selected action or null
     */
    public CAction getSelection(){
    	DockAction action = intern().getSelection();
    	if( action instanceof CommonDockAction ){
    		return ((CommonDockAction)action).getAction();
    	}
    	return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy