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

com.alee.laf.menu.MenuPainter Maven / Gradle / Ivy

package com.alee.laf.menu;

import com.alee.managers.style.StyleManager;
import com.alee.painter.decoration.IDecoration;

import javax.swing.*;
import java.awt.event.HierarchyEvent;
import java.util.List;

/**
 * Basic painter for {@link JMenu} component.
 * It is used as {@link WebMenuUI} default painter.
 *
 * @param  component type
 * @param  component UI type
 * @param  decoration type
 * @author Alexandr Zernov
 */

public class MenuPainter> extends AbstractMenuItemPainter
        implements IMenuPainter
{
    @Override
    protected void hierarchyChanged ( final HierarchyEvent e )
    {
        // Ensure default actions are performed
        super.hierarchyChanged ( e );

        // Update states on hierarchy changes
        // This is needed due to parent-based decoration states
        if ( e.getID () == HierarchyEvent.HIERARCHY_CHANGED )
        {
            updateDecorationState ();
        }
    }

    @Override
    public List getDecorationStates ()
    {
        final List states = super.getDecorationStates ();

        // State based on where exactly this menu is placed
        if ( component.getParent () != null )
        {
            final boolean inPopupMenu = component.getParent () instanceof JPopupMenu;
            final Class clazz = inPopupMenu ? JPopupMenu.class : JMenuBar.class;
            final String state = StyleManager.getDescriptor ( clazz ).getId ();
            states.add ( state );
        }

        return states;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy