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

bibliothek.gui.dock.facile.menu.SubmenuPiece 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.facile.menu;

import java.awt.Component;
import java.util.List;

import javax.swing.JMenu;

import bibliothek.gui.dock.support.menu.MenuPiece;

/**
 * A {@link MenuPiece} which consists only of one {@link JMenu}. There is a
 * new subtree attached to this {@link SubmenuPiece}.
 * @author Benjamin Sigg
 *
 */
public class SubmenuPiece extends MenuPiece{
    /** the root of this submenu */
    private RootMenuPiece root;
    
    /**
     * Creates a new submenu-piece, using a normal {@link JMenu} to inserts
     * its content.
     */
    public SubmenuPiece(){
        root = new RootMenuPiece();
        root.setParent( this );
    }
    
    /**
     * Creates a new submenu-piece, using a normal {@link JMenu}.
     * @param text the text of the menu
     * @param disableWhenEmpty whether to disable the menu when it is empty
     * @param pieces the elements of this piece
     */
    public SubmenuPiece( String text, boolean disableWhenEmpty, MenuPiece... pieces ){
        root = new RootMenuPiece( text, disableWhenEmpty, pieces );
        root.setParent( this );
    }
    
    /**
     * Creates a new submenu-piece.
     * @param menu the menu into which this piece will insert its content
     */
    public SubmenuPiece( JMenu menu ){
        root = new RootMenuPiece( menu );
        root.setParent( this );
    }
    
    @Override
    public void bind(){
    	super.bind();
    	root.bind();
    }
    
    @Override
    public void unbind(){
    	super.unbind();
    	root.unbind();
    }
    
    @Override
    public void fill( List items ) {
        items.add( getMenu() );
    }
    
    @Override
    public int getItemCount() {
        return 1;
    }
    
    /**
     * Disables the menu if there are no items in the menu. 
     * @param disableWhenEmpty true if the menu should be
     * disabled when empty
     */
    public void setDisableWhenEmpty( boolean disableWhenEmpty ) {
        root.setDisableWhenEmpty( disableWhenEmpty );
    }
    
    /**
     * Whether to disable the menu when it is empty or not.
     * @return true if the menu gets disabled
     */
    public boolean isDisableWhenEmpty() {
        return root.isDisableWhenEmpty();
    }
    
    /**
     * Sets whether the submenu can be enabled. The actual state of the
     * menu also depends on {@link #isDisableWhenEmpty()}.
     * @param enabled whether the submenu can be enabled
     */
    public void setEnabled( boolean enabled ){
    	root.setEnabled( enabled );
    }
    
    /**
     * Tells whether the submenu could be enabled. The actual state of the 
     * menu also depends on {@link #isDisableWhenEmpty()}
     * @return whether the menu could be enabled
     */
    public boolean isEnabled(){
    	return root.isEnabled();
    }
    
    @Override
    public JMenu getMenu(){
        return root.getMenu();
    }
    
    /**
     * Gets the root of this subtree.
     * @return the root
     */
    public RootMenuPiece getRoot() {
        return root;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy