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

fr.ird.observe.client.util.list.ReferentialReferenceListCellRenderer Maven / Gradle / Ivy

package fr.ird.observe.client.util.list;

/*-
 * #%L
 * ObServe Toolkit :: Common Client
 * %%
 * Copyright (C) 2008 - 2017 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import fr.ird.observe.dto.reference.ReferentialDtoReference;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;


import static org.nuiton.i18n.I18n.t;

/**
 * Un renderer de liste d'entites d'un referentiel dans le quel on veut
 * differencier les entites qui sont desactivees.
 *
 * @author Tony Chemit - [email protected]
 * @since 1.2
 */
public class ReferentialReferenceListCellRenderer implements ListCellRenderer {

    /** la couleur normal pour les entites non desactivees */
    private Color normalColor;

    /** la couleur a utiliser pour les entites desactivees */
    private Color disableColor = Color.LIGHT_GRAY;

    private ListCellRenderer delegate;

    public ReferentialReferenceListCellRenderer(ListCellRenderer delegate) {
        this.delegate = delegate;
    }

    @Override
    public Component getListCellRendererComponent(JList list, R value, int index, boolean isSelected, boolean cellHasFocus) {
        JComponent comp;
        comp = (JComponent) delegate.getListCellRendererComponent(
                list,
                value,
                index,
                isSelected,
                cellHasFocus);
        if (normalColor == null) {
            // premiere fois, on intialise la couleur dite normale
            normalColor = comp.getForeground();
        }

        String tip = null;

        // par defaut, on utilise la couleur normale
        Color col = normalColor;
        if (value != null) {

            boolean enabled = value.isEnabled();

            if (!enabled) {
                // l'entite est desactivee
                // on la grise pour bien la differencier
                col = disableColor;
                tip = t("observe.common.ReferentialDto.obsolete", ((JLabel) comp).getText());
            }
        }
        comp.setForeground(col);
        comp.setToolTipText(tip);
        return comp;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy