package aleksandar.djuric.gui;
import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import aleksandar.djuric.entities.Player;
public class LeafCellRenderer extends DefaultTreeCellRenderer {
private static final long serialVersionUID = 1L;
private ImageIcon offline;
private ImageIcon online;
private Color defaultForeground;
public LeafCellRenderer(ImageIcon offline, ImageIcon online)
{
super();
this.offline = offline;
this.online = online;
defaultForeground = getForeground();
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded,
leaf, row, hasFocus);
Player p = null;
try{
p = (Player)(((DefaultMutableTreeNode)value).getUserObject());
if(p.isOnline())
setIcon(online);
else
setIcon(offline);
if(p.getActivity() != Player.ACTIVE)
setForeground(p.getActivityColor());
else
setForeground(defaultForeground);
}catch (Exception e)
{
setIcon(null);
setForeground(defaultForeground);
}
return this;
}
}