Coverage Report - com.buckosoft.PicMan.business.PosterManager
 
Classes in this File Line Coverage Branch Coverage Complexity
PosterManager
0%
0/53
0%
0/10
2.75
 
 1  
 /******************************************************************************
 2  
  * PosterManager.java - Setup for building Posters
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2012 - Dick Balaska
 6  
  * 
 7  
  */
 8  
 package com.buckosoft.PicMan.business;
 9  
 
 10  
 import java.util.LinkedList;
 11  
 import java.util.List;
 12  
 
 13  
 import org.apache.commons.logging.Log;
 14  
 import org.apache.commons.logging.LogFactory;
 15  
 
 16  
 import com.buckosoft.PicMan.domain.ContactParams;
 17  
 import com.buckosoft.PicMan.domain.Mosaic;
 18  
 import com.buckosoft.PicMan.domain.Pic;
 19  
 import com.buckosoft.PicMan.domain.Poster;
 20  
 import com.buckosoft.PicMan.domain.PosterParams;
 21  
 
 22  
 
 23  
 /**Poster Manager.  Setup to get Posters built.
 24  
  * <pre>
 25  
  *     +------ Paper Width * DPI ----- +
 26  
  * +---+    L     Overspray     R      +----+
 27  
  * +-+      L       Margin      R        +--+
 28  
  *   +--------   Project Width ----------+</pre>
 29  
  * <ul>
 30  
  * <li> jpeg size is PaperWidth*DPI + Overspray LR
 31  
  * <li> Project Width = jpeg size - Margin LR
 32  
  * <li> Use the calibration sheet to determine values for Overspray and Margin
 33  
  * <li> My working values PrintableWidth = PaperWidth*DPI + OL+OR -ML-MR
 34  
  * <li> = x =  
 35  
  * </ul>
 36  
  * @author Dick Balaska
 37  
  * @since 2012/08/17
 38  
  * @version $Revision: 1.1 $ <br> $Date: 2013/12/26 01:26:08 $
 39  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/business/PosterManager.java">PosterManager.java</a>
 40  
  */
 41  0
 public class PosterManager {
 42  0
         private final Log log = LogFactory.getLog(getClass());
 43  
 
 44  
         private        PicManFacade        pmf;
 45  
         
 46  
         /** Set the reference to the primary PicMan api.
 47  
          * @param pmf The one and only PicManFacade
 48  
          */
 49  
         public        void setPicMan(PicManFacade pmf) {
 50  0
                 this.pmf = pmf;
 51  0
         }
 52  
 
 53  
         /** Construct a PosterParams from this Poster
 54  
          * @param poster The Poster to use as our basis
 55  
          * @return a new PosterParams
 56  
          */
 57  
         public PosterParams getPosterParams(Poster poster) {
 58  0
                 PosterParams pp = new PosterParams();
 59  0
                 pp.setPoster(poster);
 60  0
                 pp.setEngineName("Poster");
 61  0
                 pp.setSetName(poster.getName());
 62  0
                 pp.setOutputDirectory(poster.getOutputPath());
 63  0
                 return(pp);
 64  
         }
 65  
 
 66  
         /** Calculate the parameters to build this Poster
 67  
          * @param pp The PosterParams to fill out.
 68  
          */
 69  
         public void determineProjectBuild(PosterParams pp) {
 70  0
                 Poster p = pp.getPoster();
 71  0
                 Mosaic m = pmf.getDB().getMosaic(p.getMasterMid());
 72  0
                 if (m != null) {
 73  0
                         Pic pic = pmf.getDB().getPic(m.getMasterPic());
 74  0
                         if (pic != null) {
 75  0
                                 pp.getMasterPicXY().x = pic.getWidth();
 76  0
                                 pp.getMasterPicXY().y = pic.getHeight();
 77  
                         } else {
 78  0
                                 return;
 79  
                         }
 80  0
                 } else {
 81  0
                         return;
 82  
                 }
 83  
                 // get the number of inches needed
 84  0
                 p.setProjectWidth (pp.getMasterPicXY().x * p.getMultiplier() / p.getDpi());
 85  0
                 p.setProjectHeight(pp.getMasterPicXY().y * p.getMultiplier() / p.getDpi());
 86  0
                 log.debug("Project w/h = " + p.getProjectWidth() + "/" + p.getProjectHeight());
 87  
                 // get the number of sheets in the project
 88  0
                 pp.getSheetsXY().x = (int)(p.getProjectWidth() / p.getPaperWidth())+1;
 89  0
                 pp.getSheetsXY().y = (int)(p.getProjectHeight() / p.getPaperHeight())+1;
 90  
 
 91  0
                 int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
 92  0
                 int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
 93  
                 // get the starting offset
 94  0
                 pp.getGeneratedOffsetXY().x = -(int)(((pp.getSheetsXY().x*pixelsPerPageX)  - (p.getProjectWidth()*p.getDpi()))  / 2.0); 
 95  0
                 pp.getGeneratedOffsetXY().y = -(int)(((pp.getSheetsXY().y*pixelsPerPageY) - (p.getProjectHeight()*p.getDpi())) / 2.0);
 96  0
                 log.debug("GenXY = " + pp.getGeneratedOffsetXY().x + "/" + pp.getGeneratedOffsetXY().y);
 97  0
         }
 98  
         
 99  
         /** Given a Poster, chop it up into several PosterParams and submit them to the BatchManager for construction
 100  
          * @param p The Poster to build
 101  
          * @throws CloneNotSupportedException Yeah, not really.
 102  
          */
 103  
         public void buildPoster(Poster p, boolean calibration) throws CloneNotSupportedException {
 104  0
                 PosterParams pp = getPosterParams(p);
 105  0
                 determineProjectBuild(pp);
 106  0
                 List<ContactParams> spinList = new LinkedList<ContactParams>();
 107  0
                 if (calibration) {
 108  0
                         pp.setCalibration();
 109  0
                         spinList.add(pp);
 110  
                 } else {
 111  0
                         int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
 112  0
                         int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
 113  0
                         int sheet=-1;
 114  0
                         for (int y=0; y<pp.getSheetsXY().y; y++) {
 115  0
                                 for (int x=0; x<pp.getSheetsXY().x; x++) {
 116  0
                                         sheet++;
 117  0
                                         PosterParams pp0 = pp.clone();
 118  0
                                         pp0.getSheetXY().x = x;
 119  0
                                         pp0.getSheetXY().y = y;
 120  0
                                         pp0.getGeneratedOffsetXY().x = pp.getGeneratedOffsetXY().x + (x * pixelsPerPageX);
 121  0
                                         pp0.getGeneratedOffsetXY().y = pp.getGeneratedOffsetXY().y + (y * pixelsPerPageY);
 122  0
                                         log.debug("sheet-" + sheet + " " + x + "/" + y + " genXY = " +  pp0.getGeneratedOffsetXY().x + "/" + pp0.getGeneratedOffsetXY().y);
 123  0
                                         pp0.setContactNumber(y*pp.getSheetsXY().x+x);
 124  
 //                                        if (sheet<6)
 125  
 //                                                continue;
 126  0
                                         spinList.add(pp0);
 127  
                                 }
 128  
                         }
 129  
                 }
 130  0
                 pmf.getBatchManager().getContactManager().addSpin(spinList);
 131  0
         }
 132  
 }