Coverage Report - net.wotonomy.ui.swing.components.ColorCellRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
ColorCellRenderer
0% 
0% 
3
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Michael Powers
 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.1 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, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.ui.swing.components;
 20  
 
 21  
 import java.awt.Color;
 22  
 import java.awt.Component;
 23  
 
 24  
 import javax.swing.BorderFactory;
 25  
 import javax.swing.JLabel;
 26  
 import javax.swing.JTable;
 27  
 import javax.swing.border.Border;
 28  
 import javax.swing.table.TableCellRenderer;
 29  
 
 30  
 /**
 31  
 * A TableCellRenderer that renders colors.
 32  
 *
 33  
 * @author michael@mpowers.net
 34  
 * @author $Author: cgruber $
 35  
 * @version $Revision: 904 $
 36  
 */
 37  
 public class ColorCellRenderer extends JLabel implements TableCellRenderer {
 38  0
     Border unselectedBorder = null;
 39  0
     Border selectedBorder = null;
 40  0
     boolean isBordered = true;
 41  
 
 42  
     public ColorCellRenderer(boolean isBordered)
 43  
     {
 44  0
         super();
 45  0
         this.isBordered = isBordered;
 46  0
         setOpaque(true); // must do this for background to show up.
 47  0
     }
 48  
 
 49  
     public Component getTableCellRendererComponent(
 50  
                             JTable table, Object color,
 51  
                             boolean isSelected, boolean hasFocus,
 52  
                             int row, int column)
 53  
     {
 54  0
         setBackground((Color)color);
 55  0
         if (isBordered)
 56  
         {
 57  0
             if (isSelected)
 58  
             {
 59  0
                 if (selectedBorder == null)
 60  
                 {
 61  0
                     selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
 62  0
                                               table.getSelectionBackground());
 63  
                 }
 64  0
                 setBorder(selectedBorder);
 65  0
             }
 66  
             else
 67  
             {
 68  0
                 if (unselectedBorder == null)
 69  
                 {
 70  0
                     unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
 71  0
                                               table.getBackground());
 72  
                 }
 73  0
                 setBorder(unselectedBorder);
 74  
             }
 75  
         }
 76  0
         return this;
 77  
     }
 78  
 }
 79  
 
 80  
 
 81