// Carnegie Mellon University
//   Information Networking Institute and
//   School of Computer Science
//
// Master Thesis: A Monitoring Tool for Overlay Network
// By: TungFai Chan and Annie Cheng
//
// File: LabelListCellRenderer.java
// Path: userInterfaces/
// Description: Cell Renderer for JList control


package userInterfaces;

import userInterfaces.componentManagers.*;

import java.awt.*;
import javax.swing.*;


public class LabelListCellRenderer extends JLabel implements ListCellRenderer {

    public LabelListCellRenderer() {
        setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
    }

    public Component getListCellRendererComponent(JList list, Object value,
                                                  int index, boolean isSelected,
                                                  boolean cellHasFocus) {
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }

        setText(((LightWeightLabel)value).text);
        setForeground(((LightWeightLabel)value).color);
        setIcon(((LightWeightLabel)value).icon);
        setFont(list.getFont());
        return this;
    }

}
