1
2
3
4
5
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class PosterManager {
42 private final Log log = LogFactory.getLog(getClass());
43
44 private PicManFacade pmf;
45
46
47
48
49 public void setPicMan(PicManFacade pmf) {
50 this.pmf = pmf;
51 }
52
53
54
55
56
57 public PosterParams getPosterParams(Poster poster) {
58 PosterParams pp = new PosterParams();
59 pp.setPoster(poster);
60 pp.setEngineName("Poster");
61 pp.setSetName(poster.getName());
62 pp.setOutputDirectory(poster.getOutputPath());
63 return(pp);
64 }
65
66
67
68
69 public void determineProjectBuild(PosterParams pp) {
70 Poster p = pp.getPoster();
71 Mosaic m = pmf.getDB().getMosaic(p.getMasterMid());
72 if (m != null) {
73 Pic pic = pmf.getDB().getPic(m.getMasterPic());
74 if (pic != null) {
75 pp.getMasterPicXY().x = pic.getWidth();
76 pp.getMasterPicXY().y = pic.getHeight();
77 } else {
78 return;
79 }
80 } else {
81 return;
82 }
83
84 p.setProjectWidth (pp.getMasterPicXY().x * p.getMultiplier() / p.getDpi());
85 p.setProjectHeight(pp.getMasterPicXY().y * p.getMultiplier() / p.getDpi());
86 log.debug("Project w/h = " + p.getProjectWidth() + "/" + p.getProjectHeight());
87
88 pp.getSheetsXY().x = (int)(p.getProjectWidth() / p.getPaperWidth())+1;
89 pp.getSheetsXY().y = (int)(p.getProjectHeight() / p.getPaperHeight())+1;
90
91 int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
92 int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
93
94 pp.getGeneratedOffsetXY().x = -(int)(((pp.getSheetsXY().x*pixelsPerPageX) - (p.getProjectWidth()*p.getDpi())) / 2.0);
95 pp.getGeneratedOffsetXY().y = -(int)(((pp.getSheetsXY().y*pixelsPerPageY) - (p.getProjectHeight()*p.getDpi())) / 2.0);
96 log.debug("GenXY = " + pp.getGeneratedOffsetXY().x + "/" + pp.getGeneratedOffsetXY().y);
97 }
98
99
100
101
102
103 public void buildPoster(Poster p, boolean calibration) throws CloneNotSupportedException {
104 PosterParams pp = getPosterParams(p);
105 determineProjectBuild(pp);
106 List<ContactParams> spinList = new LinkedList<ContactParams>();
107 if (calibration) {
108 pp.setCalibration();
109 spinList.add(pp);
110 } else {
111 int pixelsPerPageX = (int)(p.getPaperWidth() *p.getDpi()+p.getOverSprayL()+p.getOverSprayR()-p.getMarginL()-p.getMarginR());
112 int pixelsPerPageY = (int)(p.getPaperHeight()*p.getDpi()+p.getOverSprayT()+p.getOverSprayB()-p.getMarginT()-p.getMarginB());
113 int sheet=-1;
114 for (int y=0; y<pp.getSheetsXY().y; y++) {
115 for (int x=0; x<pp.getSheetsXY().x; x++) {
116 sheet++;
117 PosterParams pp0 = pp.clone();
118 pp0.getSheetXY().x = x;
119 pp0.getSheetXY().y = y;
120 pp0.getGeneratedOffsetXY().x = pp.getGeneratedOffsetXY().x + (x * pixelsPerPageX);
121 pp0.getGeneratedOffsetXY().y = pp.getGeneratedOffsetXY().y + (y * pixelsPerPageY);
122 log.debug("sheet-" + sheet + " " + x + "/" + y + " genXY = " + pp0.getGeneratedOffsetXY().x + "/" + pp0.getGeneratedOffsetXY().y);
123 pp0.setContactNumber(y*pp.getSheetsXY().x+x);
124
125
126 spinList.add(pp0);
127 }
128 }
129 }
130 pmf.getBatchManager().getContactManager().addSpin(spinList);
131 }
132 }