Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/book/swing/BibleListCellRenderer.java


1   
2   package com.eireneh.bible.book.swing;
3   
4   import java.awt.*;
5   import javax.swing.*;
6   import javax.swing.border.Border;
7   
8   import com.eireneh.bible.book.*;
9   import com.eireneh.swing.GuiUtil;
10  
11  /**
12  * A custom list view that paints icons alongside the words. This is a
13  * simple modification of DeafultListCellRenderer
14  * 
15  * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
16  * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
17  * Distribution Licence:<br />
18  * Project B is free software; you can redistribute it
19  * and/or modify it under the terms of the GNU General Public License,
20  * version 2 as published by the Free Software Foundation.<br />
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  * General Public License for more details.<br />
25  * The License is available on the internet
26  * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
27  * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28  * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
29  * The copyright to this program is held by it's authors.
30  * </font></td></tr></table>
31  * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
32  * @see docs.Licence
33  * @author Joe Walker
34  * @version D0.I0.T0
35  */
36  public class BibleListCellRenderer extends JLabel implements ListCellRenderer
37  {
38      /**
39      * Constructs a default renderer object for an item in a list.
40      */
41      public BibleListCellRenderer()
42      {
43          if (no_focus == null)
44              no_focus = BorderFactory.createEmptyBorder(1, 1, 1, 1);
45  
46          setOpaque(true);
47          setBorder(no_focus);
48      }
49  
50      /**
51      * This is the only method defined by ListCellRenderer.  We just
52      * reconfigure the Jlabel each time we're called.
53      * @param list The JLists that we are part of
54      * @param value Value to display
55      * @param index Cell index
56      * @param selected Is the cell selected
57      * @param focus Does the list and the cell have the focus
58      */
59      public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus)
60      {
61          if (selected) 
62          {
63              setBackground(list.getSelectionBackground());
64              setForeground(list.getSelectionForeground());
65          }
66          else 
67          {
68              setBackground(list.getBackground());
69              setForeground(list.getForeground());
70          }
71  
72          setText((value == null) ? "" : value.toString());
73          setIcon(small_icon);
74  
75          setEnabled(list.isEnabled());
76          setFont(list.getFont());
77          setBorder(focus ? UIManager.getBorder("List.focusCellHighlightBorder") : no_focus);
78  
79          return this;
80      }
81  
82      /** The small version icon */
83      private final static ImageIcon small_icon = GuiUtil.loadImageIcon("/com/eireneh/resources/task_small.gif");
84  
85      /** border if we do not have focus */
86      protected static Border no_focus;
87  }