/*
 * CustomListRender.java
 *
 * Created on November 24, 2005, 2:32 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package cz.pcland.knapsack;
import cz.pcland.ga.GenerationInfo;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import javax.swing.border.*;

/**
 *
 * @author petr
 */
public class CustomListRender /*extends DefaultListCellRenderer*/ extends JPanel implements ListCellRenderer {
    //private PopulationDiversityView popView;
    private JLabel lbl;
    private static final Border EMPTY_BORDER = new EmptyBorder(1, 1, 1, 1);
    
    /** Creates a new instance of CustomListRender */
    public CustomListRender() {
        lbl = new JLabel();
       // popView = new PopulationDiversityView();
        setLayout(new FlowLayout(FlowLayout.LEFT));
        //setLayout(new GridLayout(2,1));
        this.add(lbl);
        //this.add(popView);
                    
    }
    
    
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        
       // super.getListCellRendererComponent(list, value, index,  isSelected, cellHasFocus);
        GenerationInfo GI;
        
        if(value instanceof GenerationInfo) {
            GI = ((GenerationInfo)value);
            
            //KSPanel.setBestString(GI.getBestString());
            
           // popView.setData(GI);  
            lbl.setText(GI.toString());
            
        }else  {
            lbl.setText("Nastala neocekavana chyba ... :( ");
            //GI = null;
        }
        
        if (cellHasFocus)
            setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
        else
            setBorder(EMPTY_BORDER);
        
        
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        
        return this;
    }
    
}
