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.plugin;
020
021import icy.gui.component.renderer.CustomComboBoxRenderer;
022import icy.plugin.PluginDescriptor;
023import icy.plugin.PluginLoader;
024import icy.resource.ResourceUtil;
025
026import javax.swing.JComboBox;
027import javax.swing.JList;
028
029/**
030 * @author Stephane
031 */
032public class PluginComboBoxRenderer extends CustomComboBoxRenderer
033{
034    /**
035     * 
036     */
037    private static final long serialVersionUID = -8450810538242826922L;
038
039    private final boolean showLabel;
040
041    public PluginComboBoxRenderer(JComboBox combo, boolean showLabel)
042    {
043        super(combo);
044
045        this.showLabel = showLabel;
046    }
047
048    @Override
049    protected void updateItem(JList list, Object value)
050    {
051        if (value instanceof String)
052        {
053            final PluginDescriptor plugin = PluginLoader.getPlugin((String) value);
054
055            if (plugin != null)
056            {
057                setIcon(ResourceUtil.scaleIcon(plugin.getIcon(), 20));
058                if (showLabel)
059                    setText(plugin.getName());
060                else
061                    setText("");
062                setToolTipText(plugin.getDescription());
063            }
064
065            setEnabled(list.isEnabled());
066            setFont(list.getFont());
067        }
068        else
069            super.updateItem(list, value);
070    }
071}