package net.trolans.IRC;

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

class UserListCellRenderer extends JLabel implements ListCellRenderer
{
	final static ImageIcon opImg = new ImageIcon("imgs/op.gif");
	final static ImageIcon halfOpImg = new ImageIcon("imgs/halfop.gif");
	final static ImageIcon voiceImg = new ImageIcon("imgs/voice.gif");
	final static ImageIcon defImg = new ImageIcon("imgs/none.gif");

	public Component getListCellRendererComponent(
		JList list,
		Object value,            // value to display
		int index,               // cell index
		boolean isSelected,      // is the cell selected
		boolean cellHasFocus)    // the list and the cell have the focus
	{
		if(((IRCUser)value).getPrefix().equals("@"))
			setIcon(opImg);
		else if(((IRCUser)value).getPrefix().equals("%"))
			setIcon(halfOpImg);
		else if(((IRCUser)value).getPrefix().equals("+"))
			setIcon(voiceImg);
		else
			setIcon(defImg);

		setText(((IRCUser)value).getNick());
		
		if(isSelected)
		{
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		}
		else
		{
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		setEnabled(list.isEnabled());
		setFont(list.getFont());
		return this;
	}
}
