View Javadoc

1   package org.wcb.autohome.util;
2   /***
3    * Copyright (C) 1999  Walter Bogaardt
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18   *
19   * Project:  Alice X10 Home Automation
20   */
21  
22  import javax.swing.JList;
23  import javax.swing.JLabel;
24  import javax.swing.ListCellRenderer;
25  import javax.swing.BorderFactory;
26  import javax.swing.border.Border;
27  import java.awt.Component;
28  import java.awt.Color;
29  
30  public class DeviceIDRenderer extends JLabel implements ListCellRenderer {
31  
32      private Border redBorder = BorderFactory.createLineBorder(Color.red,2);
33      private Border emptyBorder = BorderFactory.createEmptyBorder(2,2,2,2);
34  
35      public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
36      {
37          Item item = (Item)value;
38          setIcon(item.getIcon());
39          setText(item.toString());
40          if (isSelected)
41          {
42              setBorder(redBorder);
43          }
44          else
45          {
46              setBorder(emptyBorder);
47          }
48          return this;
49      }
50  }