package mil.navy.nps.logger; import java.awt.*; import javax.swing.*; /** * This class is designed to neatly draw icons in the scrolling list * of pdus in the edit frame. the ListCellRenderer is designed to * do the drawing of each and every line in the scrolling list; depending * on what type of pdu we have, we can draw a different icon for each. * this also gives us some user feedback for the user during drag and * drop operations--it looks like we're manipulating a physical object * in the icon, rather than a complete abstraction like text.

* * Swiped shamelessly from the javadocs.

* * @author DMcG */ class PduCellRenderer extends JLabel implements ListCellRenderer { final static ImageIcon longIcon = new ImageIcon("images/stop_dn.gif"); final static ImageIcon shortIcon = new ImageIcon("images/stop_up.gif"); // This is the only method defined by ListCellRenderer. // We just reconfigure the JLabel each time we're called. public Component getListCellRendererComponent( JList list, Object value, // value to display int index, // cell index boolean isSelected, // is the cell selected boolean cellHasFocus) // the list and the cell have the focus { //System.out.println("Index is " + index); String s = value.toString(); setIcon((s.length() > 10) ? longIcon : shortIcon); if (isSelected) { //System.out.println("drawing selected"); setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); //System.out.println(list.getSelectionBackground() + " " + list.getSelectionForeground()); } else { //System.out.println("drawing unselected"); setBackground(list.getBackground()); setForeground(list.getForeground()); } setText(s);; setEnabled(list.isEnabled()); setFont(list.getFont()); return this; } }