/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QuickPlotRenderer.java
 *
 * Created on Jun 10, 2011, 5:54:02 PM
 */
package usda.weru.util.table;

import com.klg.jclass.cell.JCCellInfo;
import com.klg.jclass.cell.JCComponentCellRenderer;
import java.awt.Component;

/**
 *
 * @author Joseph Levin <joelevin@weru.ksu.edu>
 */
public class QuickPlotRenderer extends javax.swing.JPanel implements JCComponentCellRenderer{
    private static final long serialVersionUID = 1L;

    /** Creates new form QuickPlotRenderer */
    public QuickPlotRenderer() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        checkbox = new TriStateCheckBox();

        checkbox.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        checkbox.setOpaque(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(checkbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(checkbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private TriStateCheckBox checkbox;
    // End of variables declaration//GEN-END:variables

    @Override
    public Component getRendererComponent(JCCellInfo cellInfo, Object o, boolean selected) {
        setBackground(selected ? cellInfo.getSelectedBackground() : cellInfo.getBackground());
        checkbox.setBackground(getBackground());
        int value = 0;        
        if(o instanceof Integer){
            value = (Integer) o;
        }
        
        checkbox.setSelectionState(value);
        
        return this;
    }

}
