Coverage Report - org.jtheque.films.view.impl.renderers.VideoListRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
VideoListRenderer
0 %
0/20
0 %
0/2
1.333
 
 1  
 package org.jtheque.films.view.impl.renderers;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque 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
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.resource.IResourceManager;
 21  
 import org.jtheque.core.managers.resource.ImageType;
 22  
 import org.jtheque.core.utils.ui.PanelBuilder;
 23  
 import org.jtheque.films.services.impl.utils.VideoFile;
 24  
 import org.jtheque.films.utils.Constants;
 25  
 import org.jtheque.utils.ui.GridBagUtils;
 26  
 
 27  
 import javax.swing.JLabel;
 28  
 import javax.swing.JList;
 29  
 import javax.swing.JPanel;
 30  
 import javax.swing.ListCellRenderer;
 31  
 import java.awt.Color;
 32  
 import java.awt.Component;
 33  
 import java.awt.Font;
 34  
 
 35  
 /**
 36  
  * A renderer to display a module in a list.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  
 public final class VideoListRenderer extends JPanel implements ListCellRenderer {
 41  
     private static final long serialVersionUID = -4146856433184922449L;
 42  
 
 43  
     private final JLabel labelIcon;
 44  
     private final JLabel labelFilm;
 45  
     private final JLabel labelFile;
 46  
 
 47  
     /**
 48  
      * Construct a new ModuleListRenderer.
 49  
      */
 50  
     public VideoListRenderer() {
 51  0
         super();
 52  
 
 53  0
         PanelBuilder builder = new PanelBuilder(this);
 54  
 
 55  0
         labelIcon = builder.add(
 56  
                 new JLabel(Managers.getManager(IResourceManager.class).getIcon(Constants.IMAGE_BASE_NAME, "videofile", ImageType.PNG)),
 57  
                 builder.gbcSet(0, 0, GridBagUtils.NONE, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 2, 0.0, 0.0));
 58  
 
 59  0
         labelFilm = builder.add(new JLabel(),
 60  
                 builder.gbcSet(1, 0, GridBagUtils.NONE, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 1, 1.0, 0.0));
 61  0
         labelFilm.setFont(labelFilm.getFont().deriveFont(Font.BOLD, 16));
 62  
 
 63  0
         labelFile = builder.add(new JLabel(),
 64  
                 builder.gbcSet(1, 1, GridBagUtils.NONE, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 1, 1.0, 0.0));
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
 69  
 
 70  0
         if (isSelected) {
 71  0
             setBackground(Color.blue);
 72  0
             setChildsForeground(Color.white);
 73  
         } else {
 74  0
             setBackground(Color.white);
 75  0
             setChildsForeground(Color.black);
 76  
         }
 77  
 
 78  0
         VideoFile video = (VideoFile) value;
 79  
 
 80  0
         labelFilm.setText(video.getFilm().getTitle());
 81  0
         labelFile.setText(video.getFile());
 82  
 
 83  0
         return this;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Set the foregound of the childs.
 88  
      *
 89  
      * @param color The foreground color.
 90  
      */
 91  
     private void setChildsForeground(Color color) {
 92  0
         labelIcon.setForeground(color);
 93  0
         labelFilm.setForeground(color);
 94  0
         labelFile.setForeground(color);
 95  0
     }
 96  
 }