Coverage Report - org.jtheque.films.view.impl.frames.SitesView
 
Classes in this File Line Coverage Branch Coverage Complexity
SitesView
0 %
0/30
N/A
1.167
 
 1  
 package org.jtheque.films.view.impl.frames;
 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.error.JThequeError;
 20  
 import org.jtheque.core.managers.log.IJThequeLogger;
 21  
 import org.jtheque.core.managers.log.Logger;
 22  
 import org.jtheque.core.managers.view.impl.components.model.SimpleListModel;
 23  
 import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView;
 24  
 import org.jtheque.core.utils.ui.PanelBuilder;
 25  
 import org.jtheque.films.controllers.able.ISitesController;
 26  
 import org.jtheque.films.utils.Constants.Site;
 27  
 import org.jtheque.films.utils.FileUtils;
 28  
 import org.jtheque.films.view.able.ISitesView;
 29  
 import org.jtheque.films.view.impl.actions.CloseViewAction;
 30  
 import org.jtheque.utils.ui.GridBagUtils;
 31  
 
 32  
 import javax.annotation.PostConstruct;
 33  
 import javax.annotation.Resource;
 34  
 import javax.swing.DefaultListModel;
 35  
 import javax.swing.JList;
 36  
 import javax.swing.JTextPane;
 37  
 import javax.swing.ListSelectionModel;
 38  
 import javax.swing.text.html.HTMLEditorKit;
 39  
 import java.awt.Container;
 40  
 import java.awt.Dimension;
 41  
 import java.awt.Frame;
 42  
 import java.io.IOException;
 43  
 import java.util.Collection;
 44  
 
 45  
 /**
 46  
  * User interface to display informations about the site used to automatically import films from internet.
 47  
  *
 48  
  * @author Baptiste Wicht
 49  
  */
 50  
 public final class SitesView extends SwingDialogView implements ISitesView {
 51  
     private static final long serialVersionUID = -600407247345067765L;
 52  
 
 53  
     private JList listSites;
 54  
     private DefaultListModel sitesModel;
 55  
     private JTextPane textSites;
 56  
 
 57  
     @Logger
 58  
     private IJThequeLogger logger;
 59  
 
 60  
     @Resource
 61  
     private ISitesController sitesController;
 62  
 
 63  
     private static final int MINIMUM_WIDTH = 200;
 64  
 
 65  
     /**
 66  
      * Construct a new JFrameSites.
 67  
      *
 68  
      * @param parent The parent frame.
 69  
      */
 70  
     public SitesView(Frame parent) {
 71  0
         super(parent);
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Build the view.
 76  
      */
 77  
     @PostConstruct
 78  
     private void build() {
 79  0
         setTitleKey("sites.view.title");
 80  0
         setContentPane(buildContentPane());
 81  0
         setMinimumSize(new Dimension(MINIMUM_WIDTH, getMinimumSize().height));
 82  0
         pack();
 83  
 
 84  0
         setLocationRelativeTo(getOwner());
 85  0
     }
 86  
 
 87  
     /**
 88  
      * Build the content pane.
 89  
      *
 90  
      * @return The content pane.
 91  
      */
 92  
     private Container buildContentPane() {
 93  0
         PanelBuilder builder = new PanelBuilder();
 94  
 
 95  0
         sitesModel = new SimpleListModel<Site>(Site.values());
 96  
 
 97  0
         listSites = new JList(sitesModel);
 98  0
         listSites.setSelectedIndex(0);
 99  0
         listSites.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 100  
 
 101  0
         listSites.getSelectionModel().addListSelectionListener(sitesController);
 102  
 
 103  0
         builder.addScrolled(listSites, builder.gbcSet(0, 0));
 104  
 
 105  0
         textSites = new JTextPane();
 106  0
         textSites.setContentType("text/html");
 107  0
         textSites.setEditable(false);
 108  0
         textSites.setEditorKit(new HTMLEditorKit());
 109  
 
 110  
         try {
 111  0
             textSites.setPage(FileUtils.getLocalisedPage(((Site) sitesModel.getElementAt(0)).value()));
 112  0
         } catch (IOException e) {
 113  0
             logger.error(e);
 114  0
             textSites.setText("");
 115  0
         }
 116  
 
 117  0
         builder.addScrolled(textSites, builder.gbcSet(1, 0));
 118  
 
 119  0
         builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, 2, 1), new CloseViewAction("generic.view.actions.cancel", this));
 120  
 
 121  0
         return builder.getPanel();
 122  
     }
 123  
 
 124  
     @Override
 125  
     public JTextPane getSitesTextComponent() {
 126  0
         return textSites;
 127  
     }
 128  
 
 129  
     @Override
 130  
     public String getSelectedSite() {
 131  0
         return ((Site) sitesModel.get(listSites.getSelectedIndex())).value();
 132  
     }
 133  
 
 134  
     @Override
 135  
     protected void validate(Collection<JThequeError> errors) {
 136  0
     }
 137  
 }