Coverage Report - org.jtheque.core.managers.view.impl.components.panel.ModulePanel
 
Classes in this File Line Coverage Branch Coverage Complexity
ModulePanel
0 %
0/31
0 %
0/4
1.5
 
 1  
 package org.jtheque.core.managers.view.impl.components.panel;
 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.language.ILanguageManager;
 21  
 import org.jtheque.core.managers.module.IModuleManager;
 22  
 import org.jtheque.core.managers.update.repository.ModuleDescription;
 23  
 import org.jtheque.core.managers.update.versions.VersionsFile;
 24  
 import org.jtheque.core.managers.update.versions.VersionsFileReader;
 25  
 import org.jtheque.core.managers.view.able.IViewManager;
 26  
 import org.jtheque.core.managers.view.able.ViewDefaults;
 27  
 import org.jtheque.core.utils.ui.PanelBuilder;
 28  
 
 29  
 import javax.swing.JLabel;
 30  
 import javax.swing.JPanel;
 31  
 import java.awt.Color;
 32  
 import java.awt.Font;
 33  
 
 34  
 /**
 35  
  * A module panel.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  
 public final class ModulePanel extends JPanel {
 40  
     private final JLabel labelName;
 41  
     private final JLabel labelDescription;
 42  
     private final JLabel onlineLabel;
 43  
     private final JLabel currentLabel;
 44  
 
 45  
     private final ModuleDescription module;
 46  
 
 47  
     private static final int TITLE_FONT_SIZE = 16;
 48  
 
 49  
     /**
 50  
      * Construct a new ModulePanel.
 51  
      *
 52  
      * @param value      The value.
 53  
      * @param isSelected A boolean tag indicating if the module is selected or not.
 54  
      */
 55  
     public ModulePanel(Object value, boolean isSelected) {
 56  0
         super();
 57  
 
 58  0
         PanelBuilder builder = new PanelBuilder(this);
 59  
 
 60  0
         module = (ModuleDescription) value;
 61  
 
 62  0
         labelName = builder.add(new JLabel(module.getName()), builder.gbcSet(0, 0));
 63  0
         labelName.setFont(labelName.getFont().deriveFont(Font.BOLD, TITLE_FONT_SIZE));
 64  
 
 65  0
         labelDescription = builder.add(new JLabel(module.getDescription().toString()), builder.gbcSet(0, 1));
 66  
 
 67  0
         onlineLabel = builder.addLabel("...", builder.gbcSet(0, 3));
 68  0
         currentLabel = builder.addLabel("...", builder.gbcSet(0, 4));
 69  
 
 70  0
         setSelected(isSelected);
 71  0
     }
 72  
 
 73  
     /**
 74  
      * Set selected.
 75  
      *
 76  
      * @param isSelected A boolean tag indicating if the module is selected or not.
 77  
      */
 78  
     public void setSelected(boolean isSelected) {
 79  0
         ViewDefaults defaults = Managers.getManager(IViewManager.class).getViewDefaults();
 80  
 
 81  0
         if (isSelected) {
 82  0
             setColors(defaults.getSelectedBackgroundColor(), defaults.getSelectedForegroundColor());
 83  
         } else {
 84  0
             setColors(defaults.getBackgroundColor(), defaults.getForegroundColor());
 85  
         }
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Set the colors of the renderer.
 90  
      *
 91  
      * @param background The background color.
 92  
      * @param foreground The foreground color.
 93  
      */
 94  
     private void setColors(Color background, Color foreground) {
 95  0
         setBackground(background);
 96  
 
 97  0
         labelName.setBackground(background);
 98  0
         labelDescription.setBackground(background);
 99  0
         onlineLabel.setBackground(background);
 100  0
         currentLabel.setBackground(background);
 101  
 
 102  0
         labelName.setForeground(foreground);
 103  0
         labelDescription.setForeground(foreground);
 104  0
         onlineLabel.setForeground(foreground);
 105  0
         currentLabel.setForeground(foreground);
 106  0
     }
 107  
 
 108  
     /**
 109  
      * Expand the version.
 110  
      */
 111  
     public void expand() {
 112  0
         VersionsFile file = new VersionsFileReader().readURL(module.getVersionsFileURL());
 113  
 
 114  0
         onlineLabel.setText(Managers.getManager(ILanguageManager.class).getMessage(
 115  
                 "repository.module.online",
 116  
                 file.getMostRecentVersion().getStringVersion()));
 117  
 
 118  0
         if (Managers.getManager(IModuleManager.class).isInstalled(module.getId())) {
 119  0
             currentLabel.setText(Managers.getManager(ILanguageManager.class).getMessage(
 120  
                     "repository.module.current",
 121  
                     Managers.getManager(IModuleManager.class).getModuleById(module.getId()).getInfos().version()));
 122  
         } else {
 123  0
             currentLabel.setText(Managers.getManager(ILanguageManager.class).getMessage("repository.module.current.notinstalled"));
 124  
         }
 125  0
     }
 126  
 }