// (c) MIT 2003.  All rights reserved.

// $Id: StringGeneratedJList.java,v 1.2 2003/03/06 00:40:38 moltmans Exp $
// StringGeneratedJList.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon Jul 17 17:31:57 2000> 
// Time-stamp: <2000-07-17 18:09:27 moltmans> 
package rec.util;

import java.awt.Component;
import java.util.*;
import javax.swing.*;

/**
 * Generate the strings with something other than toString().
 * Specified via a StringGenerator class.
 **/
public class StringGeneratedJList extends JList
{
  private StringGenerator m_generator;

  public StringGeneratedJList( StringGenerator gen )
  {
    m_generator = gen;
    setCellRenderer( new MyCellRenderer() );
  }

  class MyCellRenderer extends DefaultListCellRenderer {
     public Component getListCellRendererComponent(
         JList list,
         Object value,
         int index,
         boolean isSelected,
         boolean cellHasFocus)
     {
       String text = m_generator.makeString( value );
       return super.getListCellRendererComponent( list,
						  text,
						  index,
						  isSelected,
						  cellHasFocus );
     }
  }
}



