Coverage Report - org.jtheque.films.view.impl.frames.FilmographyView
 
Classes in this File Line Coverage Branch Coverage Complexity
FilmographyView
0 %
0/41
0 %
0/8
1.5
 
 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.view.impl.frame.abstraction.SwingDialogView;
 21  
 import org.jtheque.core.utils.ui.PanelBuilder;
 22  
 import org.jtheque.films.services.impl.utils.Filmography;
 23  
 import org.jtheque.films.view.able.IFilmographyView;
 24  
 import org.jtheque.films.view.impl.actions.CloseViewAction;
 25  
 import org.jtheque.films.view.impl.models.able.IFilmographyModel;
 26  
 import org.jtheque.utils.ui.GridBagUtils;
 27  
 
 28  
 import javax.swing.JTextPane;
 29  
 import javax.swing.text.html.HTMLEditorKit;
 30  
 import java.awt.Container;
 31  
 import java.awt.Frame;
 32  
 import java.util.Collection;
 33  
 
 34  
 /**
 35  
  * A frame to display a filmography of an actor.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  0
 public final class FilmographyView extends SwingDialogView implements IFilmographyView {
 40  
     private static final long serialVersionUID = 7168128065378572964L;
 41  
 
 42  
     private JTextPane textFilmo;
 43  
 
 44  
     /**
 45  
      * Construct a new <code>JFrameFilmography</code>.
 46  
      *
 47  
      * @param parent The parent frame.
 48  
      */
 49  
     public FilmographyView(Frame parent) {
 50  0
         super(parent);
 51  
 
 52  0
         setLocationRelativeTo(getOwner());
 53  0
     }
 54  
 
 55  
     @Override
 56  
     public void sendMessage(String message, Object value) {
 57  0
         if ("filmo".equals(message)) {
 58  0
             getModel().setFilmo(value);
 59  0
             updateFilmo(value);
 60  
         }
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Update the filmography.
 65  
      *
 66  
      * @param value The filmography object.
 67  
      */
 68  
     private void updateFilmo(Object value) {
 69  0
         Filmography filmo = (Filmography) value;
 70  
 
 71  0
         setTitle(getMessage("filmography.view.title") + ' ' + filmo.getActor());
 72  
 
 73  0
         if (getModel().isBuilded()) {
 74  0
             updateFilmo(filmo);
 75  
         } else {
 76  0
             setContentPane(buildContentPane(filmo));
 77  
 
 78  0
             pack();
 79  
 
 80  0
             getModel().setBuilded();
 81  
         }
 82  0
     }
 83  
 
 84  
     /**
 85  
      * Return the content pane initialized.
 86  
      *
 87  
      * @param filmo The filmography we want to display.
 88  
      * @return The content pane.
 89  
      */
 90  
     private Container buildContentPane(Filmography filmo) {
 91  0
         PanelBuilder builder = new PanelBuilder();
 92  
 
 93  0
         textFilmo = new JTextPane();
 94  0
         textFilmo.setContentType("text/html");
 95  0
         textFilmo.setEditable(false);
 96  0
         textFilmo.setEditorKit(new HTMLEditorKit());
 97  
 
 98  0
         updateFilmo(filmo);
 99  
 
 100  0
         builder.addScrolled(textFilmo, builder.gbcSet(0, 0, GridBagUtils.BOTH));
 101  
 
 102  0
         builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL), new CloseViewAction("generic.view.actions.close", this));
 103  
 
 104  0
         return builder.getPanel();
 105  
     }
 106  
 
 107  
     /**
 108  
      * Update the content of the text pane with a new filmography.
 109  
      *
 110  
      * @param filmo The filmography.
 111  
      */
 112  
     private void updateFilmo(Filmography filmo) {
 113  0
         StringBuilder builder = new StringBuilder("<html><body>");
 114  
 
 115  0
         builder.append("<h2>").append(getMessage("filmography.view.header.actor")).append(' ').append(filmo.getActor()).append("</h2>");
 116  0
         builder.append("<h3>").append(getMessage("filmography.view.header.films")).append("</h3>");
 117  0
         builder.append("<ul>");
 118  
 
 119  0
         for (String film : filmo.getFilms()) {
 120  0
             builder.append("<li>").append(film).append("</li>");
 121  
         }
 122  
 
 123  0
         builder.append("</ul>");
 124  0
         builder.append("</body></html>");
 125  
 
 126  0
         textFilmo.setText(builder.toString());
 127  0
     }
 128  
 
 129  
     @Override
 130  
     public IFilmographyModel getModel() {
 131  0
         return (IFilmographyModel) super.getModel();
 132  
     }
 133  
 
 134  
     @Override
 135  
     public void refreshText() {
 136  0
         super.refreshText();
 137  
 
 138  0
         if (getModel() != null) {
 139  0
             updateFilmo(getModel().getFilmo());
 140  
         }
 141  0
     }
 142  
 
 143  
     @Override
 144  
     protected void validate(Collection<JThequeError> errors) {
 145  0
     }
 146  
 }