/*
 * 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.sat;
import cz.pcland.ga.GenerationInfo;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import javax.swing.border.*;

import java.awt.Component;

import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet;
import cz.pcland.gavisualization.*;
/**
 *
 * @author petr
 */
public class SATInstancesRenderer extends JPanel implements ListCellRenderer {
    
    private JLabel lblDone;
    private static final Border EMPTY_BORDER = new EmptyBorder(1, 1, 1, 1);
    SATInstance instance;
    
    private final JCheckBox _checkBox = new JCheckBox();
    private final JLabel _titleLabel = new JLabel();
    private AccessibleContext _accessibleContext;
    
    
    
    /** Creates a new instance of CustomListRender */
    public SATInstancesRenderer() {
        lblDone = new JLabel();
        JCheckBox chckBox = new JCheckBox();
        setLayout(new FlowLayout(FlowLayout.LEFT));
        this.add(lblDone);
        lblDone.setText("<html>" + Operations.getColoredText(Color.orange, "Not computed") + "</html>");
        this.add(_titleLabel);
    }
    
    
    
    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 SATInstance) {
            instance = ((SATInstance)value);

            _titleLabel.setText(instance.toString());
            if(instance.checked){
                if(instance.canSatisfy){
                    lblDone.setText("<html>"+Operations.getColoredText(Color.green, "OK")+"</html>");
                } else {
                    lblDone.setText("<html>"+Operations.getColoredText(Color.red, "not found")+"</html>");
                }
            } else {
                lblDone.setText("<html>" + Operations.getColoredText(Color.orange, "Not computed") + "</html>");
                
            }
            
        } else {
            _titleLabel.setText("Nastala neocekavana chyba ... :( ");
        }
        
        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;
    }
    
}
