import java.awt.*;
import javax.swing.*;

/**
 * A cell renderer that can be used for cells containing Fraction objects.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class FractionCellRenderer extends FractionLabel implements ListCellRenderer<Fraction> 
{
  private static final long serialVersionUID = 1L;
  

  /**
   * Default Constructor.
   */
  public FractionCellRenderer() 
  {
    super();
    setOpaque(true);
  }

  /**
   * Get the component that does the rendering.
   *
   * @param table      The JTable that is being rendered
   * @param value      The value of the cell to be rendered
   * @param isSelected true if the cell is to be rendered with highlighting
   * @param hasFocus   true if the cell has the focus
   * @param row        The row of the cell being rendered
   * @param column     The column of the cell being rendered
   * @return           The Component to use as the renderer
   */
  public Component getListCellRendererComponent(JList<? extends Fraction> list, Fraction value, int index, boolean isSelected, boolean hasFocus) 
  {
    setFraction(value);
    
    if (isSelected) setBorder(BorderFactory.createLineBorder(getForeground()));
    else            setBorder(BorderFactory.createLineBorder(getBackground()));
    
    return this;
  }
}
