import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /** * MessageCellRenderer - Class built to handle the implementation of the * renderer for UserName data objects. This allows the data objects to * be rendered into a list format convenient for making selectios from. * * @extends JPanel * * @author Jayme Manning * @author Paul Kronenwetter * @version * $Revision: 1.1 $
* $Date: 1998/12/17 17:13:50 $

* *

 * $Log: MessageCellRenderer.java,v $
 * Revision 1.1  1998/12/17 17:13:50  cps606
 * First take at a cell renderer for the messages list.
 *
 * 
*/ public class MessageCellRenderer extends JLabel implements ListCellRenderer { /** * box - JList component that we render to. */ private JList box; /** * selectedBackground - The color to use for the background of a * selected cell. */ private Color selectedBackground; /** * selectedForeground - The color to use for the foreground of a * selected cell. */ private Color selectedForeground; /** * defaultBackground - The color to use for the background of a * normal cell. */ private Color defaultBackground; /** * defaultForeground - The color to use for the foreground of a * normal cell. */ private Color defaultForeground; private JScrollPane scrollPane; private DefaultListModel listModel; /** * MessageCellRenderer - Constructor used to setup the data objects * for our class. * * @param newBox JList to render the cells to. */ public MessageCellRenderer(JList newBox) { box = newBox; setOpaque(true); selectedBackground = Color.blue; selectedForeground = Color.white; defaultBackground = Color.white; defaultForeground = Color.black; } /** * MessageCellRenderer - Constructor used to setup the data objects * for our class. * * @param newBox JList to render the cells to. * @param sb1 Color to render the selected background as. * @param sf1 Color to render the selected foreground as. * @param db1 Color to render the default background as. * @param df1 Color to render the default foreground as. */ public MessageCellRenderer(JList newBox, Color sb1, Color sf1, Color db1, Color df1) { box = newBox; setOpaque(true); selectedBackground = sb1; selectedForeground = sf1; defaultBackground = db1; defaultForeground = df1; } /** * getListCellRendererComponent - Method used to return the * ListCellRenderer for this list. * * @param listbox The JList to be rendered to. * @param value The object that will be rendered. * @param index Where we are in the list. * @param isSelected Is this object currently selected. * @param cellHasFocus Does this object currently have the focus. * * @return Component - The renderable component. */ public Component getListCellRendererComponent(JList listbox, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel message = (JLabel)value; setText(message.getText()); setForeground(message.getForeground()); setBackground(message.getBackground()); if(value == null) { setText("No Message"); } else if(isSelected) { setBackground(selectedBackground); setForeground(selectedForeground); } else { setForeground(message.getForeground()); setBackground(message.getBackground()); // setBackground(defaultBackground); // setForeground(defaultForeground); } // System.out.println("User Name: " + getText()); return this; } }