Coverage Report - org.jtheque.core.managers.view.impl.components.renderers.UpdatableListRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
UpdatableListRenderer
0 %
0/27
0 %
0/2
1.333
 
 1  
 package org.jtheque.core.managers.view.impl.components.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.update.IUpdateManager;
 21  
 import org.jtheque.core.managers.update.Updatable;
 22  
 import org.jtheque.core.managers.view.able.IViewManager;
 23  
 import org.jtheque.core.utils.ui.PanelBuilder;
 24  
 import org.jtheque.utils.ui.GridBagUtils;
 25  
 
 26  
 import javax.swing.JLabel;
 27  
 import javax.swing.JList;
 28  
 import javax.swing.JPanel;
 29  
 import javax.swing.ListCellRenderer;
 30  
 import java.awt.Color;
 31  
 import java.awt.Component;
 32  
 import java.awt.Font;
 33  
 
 34  
 /**
 35  
  * A renderer to display a module in a list.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  
 public final class UpdatableListRenderer extends JPanel implements ListCellRenderer {
 40  
     private final JLabel labelName;
 41  
     private final JLabel labelCurrentVersion;
 42  
     private final JLabel labelOnlineVersion;
 43  
     private final JLabel labelCurrentVersion1;
 44  
     private final JLabel labelOnlineVersion1;
 45  
 
 46  
     private static final int TITLE_FONT_SIZE = 16;
 47  
 
 48  
     /**
 49  
      * Construct a new ModuleListRenderer.
 50  
      */
 51  
     public UpdatableListRenderer() {
 52  0
         super();
 53  
 
 54  0
         PanelBuilder builder = new PanelBuilder(this);
 55  
 
 56  0
         labelName = builder.add(new JLabel(), builder.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE, 2, 1));
 57  0
         labelName.setFont(labelName.getFont().deriveFont(Font.BOLD, TITLE_FONT_SIZE));
 58  
 
 59  0
         labelCurrentVersion1 = builder.addI18nLabel("modules.view.label.versions.current", builder.gbcSet(0, 1));
 60  0
         labelCurrentVersion = builder.add(new JLabel(), builder.gbcSet(1, 1));
 61  
 
 62  0
         labelOnlineVersion1 = builder.addI18nLabel("modules.view.label.versions.online", builder.gbcSet(0, 2));
 63  0
         labelOnlineVersion = builder.addLabel("", builder.gbcSet(1, 2));
 64  0
     }
 65  
 
 66  
     @Override
 67  
     public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
 68  0
         if (isSelected) {
 69  0
             setBackground(Managers.getManager(IViewManager.class).getViewDefaults().getSelectedBackgroundColor());
 70  0
             setChildsForeground(Managers.getManager(IViewManager.class).getViewDefaults().getSelectedForegroundColor());
 71  
         } else {
 72  0
             setBackground(Managers.getManager(IViewManager.class).getViewDefaults().getBackgroundColor());
 73  0
             setChildsForeground(Managers.getManager(IViewManager.class).getViewDefaults().getForegroundColor());
 74  
         }
 75  
 
 76  0
         labelOnlineVersion.setBackground(getBackground());
 77  0
         labelOnlineVersion.removeAll();
 78  
 
 79  0
         Updatable updatable = (Updatable) value;
 80  
 
 81  0
         labelName.setText(updatable.getName());
 82  0
         labelCurrentVersion.setText(updatable.getVersion().getVersion());
 83  0
         labelOnlineVersion.setText(Managers.getManager(IUpdateManager.class).getMostRecentVersion(updatable).getVersion());
 84  
 
 85  0
         return this;
 86  
     }
 87  
 
 88  
     /**
 89  
      * Set the foreground of the childs.
 90  
      *
 91  
      * @param color The foreground color.
 92  
      */
 93  
     private void setChildsForeground(Color color) {
 94  0
         labelName.setForeground(color);
 95  0
         labelCurrentVersion.setForeground(color);
 96  0
         labelCurrentVersion1.setForeground(color);
 97  0
         labelOnlineVersion.setForeground(color);
 98  0
         labelOnlineVersion1.setForeground(color);
 99  0
     }
 100  
 }