Coverage Report - org.jtheque.core.managers.view.impl.components.filthy.FilthyComboBox
 
Classes in this File Line Coverage Branch Coverage Complexity
FilthyComboBox
0 %
0/11
0 %
0/4
2
FilthyComboBox$1
N/A
N/A
2
FilthyComboBox$FilthyRenderer
0 %
0/6
N/A
2
 
 1  
 package org.jtheque.core.managers.view.impl.components.filthy;
 2  
 
 3  
 import org.jtheque.core.managers.Managers;
 4  
 import org.jtheque.core.managers.resource.IResourceManager;
 5  
 import org.jtheque.core.utils.ui.Borders;
 6  
 
 7  
 import javax.swing.AbstractButton;
 8  
 import javax.swing.BorderFactory;
 9  
 import javax.swing.ComboBoxModel;
 10  
 import javax.swing.DefaultListCellRenderer;
 11  
 import javax.swing.JComboBox;
 12  
 import javax.swing.JList;
 13  
 import javax.swing.UIManager;
 14  
 import javax.swing.border.CompoundBorder;
 15  
 import java.awt.Color;
 16  
 import java.awt.Component;
 17  
 
 18  
 /*
 19  
  * This file is part of JTheque.
 20  
  *            
 21  
  * JTheque is free software: you can redistribute it and/or modify
 22  
  * it under the terms of the GNU General Public License as published by
 23  
  * the Free Software Foundation, either version 3 of the License. 
 24  
  *
 25  
  * JTheque is distributed in the hope that it will be useful,
 26  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 27  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 28  
  * GNU General Public License for more details.
 29  
  *
 30  
  * You should have received a copy of the GNU General Public License
 31  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 32  
  */
 33  
 
 34  
 /**
 35  
  * A filthy combo box.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  
 public final class FilthyComboBox extends JComboBox {
 40  
     /**
 41  
      * Construct a new <code>FilthyComboBox</code>.
 42  
      *
 43  
      * @param model The model to store data.
 44  
      */
 45  
     public FilthyComboBox(ComboBoxModel model) {
 46  0
         super(model);
 47  
 
 48  0
         IResourceManager resources = Managers.getManager(IResourceManager.class);
 49  
 
 50  0
         setOpaque(false);
 51  0
         setBackground(resources.getColor("filthyInputColor"));
 52  
 
 53  0
         setBorder(new CompoundBorder(
 54  
                 BorderFactory.createLineBorder(resources.getColor("filthyInputBorderColor"), 2),
 55  
                 BorderFactory.createEmptyBorder(2, 2, 2, 2)));
 56  
 
 57  0
         UIManager.put("ComboBox.selectionBackground", new Color(0, 0, 0, 0));
 58  
 
 59  0
         for (int i = 0; i < getComponentCount(); i++) {
 60  0
             if (getComponent(i) instanceof AbstractButton) {
 61  0
                 ((AbstractButton) getComponent(i)).setBorderPainted(false);
 62  
             }
 63  
         }
 64  
 
 65  0
         setRenderer(new FilthyRenderer());
 66  0
     }
 67  
 
 68  
     /**
 69  
      * A basic renderer for this combo box.
 70  
      *
 71  
      * @author Baptiste Wicht
 72  
      */
 73  0
     private static final class FilthyRenderer extends DefaultListCellRenderer {
 74  
         @Override
 75  
         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
 76  0
             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
 77  
 
 78  0
             setBorder(Borders.createEmptyBorder(0, 0, 0, 0));
 79  0
             setForeground(Color.white);
 80  0
             setOpaque(false);
 81  
 
 82  0
             return this;
 83  
         }
 84  
     }
 85  
 }