Coverage Report - org.jtheque.films.controllers.impl.FilmController
 
Classes in this File Line Coverage Branch Coverage Complexity
FilmController
0 %
0/62
0 %
0/24
1.684
 
 1  
 package org.jtheque.films.controllers.impl;
 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.log.ILoggingManager;
 21  
 import org.jtheque.core.managers.resource.IResourceManager;
 22  
 import org.jtheque.core.managers.view.able.IViewManager;
 23  
 import org.jtheque.films.controllers.able.IFilmController;
 24  
 import org.jtheque.films.persistence.od.able.Film;
 25  
 import org.jtheque.films.services.able.IFilmsService;
 26  
 import org.jtheque.films.utils.Constants;
 27  
 import org.jtheque.films.view.able.IFilmView;
 28  
 import org.jtheque.films.view.impl.models.able.IFilmsModel;
 29  
 import org.jtheque.primary.controller.able.ControllerState;
 30  
 import org.jtheque.primary.controller.impl.PrincipalController;
 31  
 import org.jtheque.primary.view.impl.models.tree.TreeElement;
 32  
 import org.jtheque.utils.DesktopMail;
 33  
 import org.jtheque.utils.DesktopUtils;
 34  
 import org.jtheque.utils.StringUtils;
 35  
 import org.jtheque.utils.io.CopyException;
 36  
 import org.jtheque.utils.io.FileUtils;
 37  
 import org.jtheque.utils.io.SimpleFilter;
 38  
 import org.jtheque.utils.print.PrintUtils;
 39  
 
 40  
 import javax.annotation.PostConstruct;
 41  
 import javax.annotation.Resource;
 42  
 import javax.swing.JTree;
 43  
 import javax.swing.event.TreeSelectionEvent;
 44  
 import javax.swing.tree.TreePath;
 45  
 import java.awt.event.MouseEvent;
 46  
 import java.awt.image.BufferedImage;
 47  
 import java.util.Collection;
 48  
 
 49  
 /**
 50  
  * A film controller implementation.
 51  
  *
 52  
  * @author Baptiste Wicht
 53  
  */
 54  0
 public final class FilmController extends PrincipalController<Film> implements IFilmController {
 55  
     @Resource
 56  
     private IFilmsService filmService;
 57  
 
 58  
     @Resource
 59  
     private IFilmView filmView;
 60  
 
 61  0
     private final SimpleFilter imagesFilter = new SimpleFilter("Images(*.jpg,*.png)", ".jpg,.png,.gif");
 62  
 
 63  
     /**
 64  
      * Init the view.
 65  
      */
 66  
     @PostConstruct
 67  
     public void init() {
 68  0
         setState(getViewState());
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public void mouseClicked(MouseEvent event) {
 73  0
         if (event.getClickCount() == 2 && filmView.isEnabled()) {
 74  0
             String image = Managers.getManager(IViewManager.class).chooseFile(imagesFilter);
 75  
 
 76  0
             if (StringUtils.isNotEmpty(image)) {
 77  0
                 String extension = image.substring(image.lastIndexOf('.'));
 78  
 
 79  0
                 String destination = Constants.Files.MINIATURE_FOLDER + '/' +
 80  
                         getViewModel().getCurrentFilm().getTitle() + extension;
 81  
 
 82  
                 try {
 83  0
                     FileUtils.copy(image, destination);
 84  0
                 } catch (CopyException e1) {
 85  0
                     Managers.getManager(ILoggingManager.class).getLogger(getClass()).error(e1);
 86  0
                 }
 87  
 
 88  0
                 BufferedImage bufferedImage = Managers.getManager(IResourceManager.class).getImage(image, Constants.MINIATURE_WIDTH);
 89  
 
 90  0
                 filmView.setImageOfPanel(bufferedImage);
 91  
 
 92  0
                 filmView.refresh();
 93  
             }
 94  
         }
 95  0
     }
 96  
 
 97  
     @Override
 98  
     public void valueChanged(TreeSelectionEvent event) {
 99  0
         TreePath current = ((JTree) event.getSource()).getSelectionPath();
 100  
 
 101  0
         if (current != null && current.getLastPathComponent() instanceof TreeElement) {
 102  0
             Film film = (Film) current.getLastPathComponent();
 103  
 
 104  0
             if (film != null) {
 105  0
                 view(film);
 106  
             }
 107  
         }
 108  0
     }
 109  
 
 110  
     @Override
 111  
     public void save() {
 112  0
         ControllerState newState = getState().save(filmView.fillFilmFormBean());
 113  
 
 114  0
         if (newState != null) {
 115  0
             setAndApplyState(newState);
 116  
         }
 117  0
     }
 118  
 
 119  
     @Override
 120  
     public IFilmsModel getViewModel() {
 121  0
         return (IFilmsModel) filmView.getModel();
 122  
     }
 123  
 
 124  
     @Override
 125  
     public void view(Film film) {
 126  0
         ControllerState newState = getState().view(film);
 127  
 
 128  0
         if (newState != null) {
 129  0
             setAndApplyState(newState);
 130  
         }
 131  0
     }
 132  
 
 133  
     @Override
 134  
     public void manualEdit() {
 135  0
         ControllerState newState = getState().manualEdit();
 136  
 
 137  0
         if (newState != null) {
 138  0
             setAndApplyState(newState);
 139  
         }
 140  0
     }
 141  
 
 142  
     @Override
 143  
     public void createFilm() {
 144  0
         ControllerState newState = getState().create();
 145  
 
 146  0
         if (newState != null) {
 147  0
             setAndApplyState(newState);
 148  
         }
 149  0
     }
 150  
 
 151  
     @Override
 152  
     public void deleteCurrentFilm() {
 153  0
         ControllerState newState = getState().delete();
 154  
 
 155  0
         if (newState != null) {
 156  0
             setAndApplyState(newState);
 157  
         }
 158  0
     }
 159  
 
 160  
     @Override
 161  
     public void cancel() {
 162  0
         ControllerState newState = getState().cancel();
 163  
 
 164  0
         if (newState != null) {
 165  0
             setAndApplyState(newState);
 166  
         }
 167  0
     }
 168  
 
 169  
     @Override
 170  
     public void sendCurrentFilmByMail() {
 171  0
         DesktopMail mail = new DesktopMail();
 172  0
         mail.setSubject("Fiche du film : " + getViewModel().getCurrentFilm().getTitle());
 173  0
         mail.setBody(filmService.generateEmail(getViewModel().getCurrentFilm()));
 174  
 
 175  0
         DesktopUtils.mail(mail);
 176  0
     }
 177  
 
 178  
     @Override
 179  
     public void printCurrentFilm() {
 180  0
         PrintUtils.printString(filmService.generateFilmDescriptionForPrinting(getViewModel().getCurrentFilm()));
 181  0
     }
 182  
 
 183  
     @Override
 184  
     public void mouseEntered(MouseEvent e) {
 185  
         //Nothing to be done
 186  0
     }
 187  
 
 188  
     @Override
 189  
     public void mouseExited(MouseEvent e) {
 190  
         //Nothing to be done
 191  0
     }
 192  
 
 193  
     @Override
 194  
     public void mousePressed(MouseEvent e) {
 195  
         //Nothing to be done
 196  0
     }
 197  
 
 198  
     @Override
 199  
     public void mouseReleased(MouseEvent e) {
 200  
         //Nothing to be done
 201  0
     }
 202  
 
 203  
     @Override
 204  
     public IFilmView getView() {
 205  0
         return filmView;
 206  
     }
 207  
 
 208  
     @Override
 209  
     public String getDataType() {
 210  0
         return IFilmsService.DATA_TYPE;
 211  
     }
 212  
 
 213  
     @Override
 214  
     public Collection<Film> getDisplayList() {
 215  0
         return getViewModel().getDisplayList();
 216  
     }
 217  
 }