001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.component.menu;
020
021import icy.action.IcyAbstractAction;
022import icy.resource.icon.IcyIcon;
023
024import java.awt.event.ActionListener;
025
026import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind;
027import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
028import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary;
029
030/**
031 * @author Stephane
032 */
033public class IcyRibbonApplicationMenuEntryPrimary extends RibbonApplicationMenuEntryPrimary
034{
035    private final IcyAbstractAction action;
036
037    public IcyRibbonApplicationMenuEntryPrimary(ResizableIcon icon, String text, ActionListener mainActionListener,
038            CommandButtonKind entryKind)
039    {
040        super(icon, text, mainActionListener, entryKind);
041
042        action = null;
043    }
044
045    public IcyRibbonApplicationMenuEntryPrimary(IcyAbstractAction action)
046    {
047        super((action.getIcon() != null) ? new IcyIcon(action.getIcon()) : null, action.getName(), action,
048                CommandButtonKind.ACTION_ONLY);
049
050        this.action = action;
051
052        // set tooltip
053        setActionRichTooltip(action.getRichToolTip());
054    }
055
056    @Override
057    public boolean isEnabled()
058    {
059        return super.isEnabled() && ((action == null) || action.isEnabled());
060    }
061
062    @Override
063    public void setEnabled(boolean b)
064    {
065        final boolean oldValue = isEnabled();
066
067        super.setEnabled(b);
068
069        if ((oldValue != b) && (action != null))
070            action.setEnabled(b);
071    }
072}