1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.business.contact.engine;
9
10 import java.awt.Graphics2D;
11 import java.awt.image.BufferedImage;
12 import java.util.Date;
13 import java.util.LinkedList;
14 import java.util.List;
15
16 import com.buckosoft.PicMan.business.contact.ContactEngine;
17 import com.buckosoft.PicMan.domain.Contact;
18
19
20
21
22
23
24
25
26 public class Ribbon extends ContactEngine {
27
28
29
30
31 protected boolean _makeContact() {
32
33 boolean success = true;
34
35 logger.info("makeContact '" + cName + "'");
36
37
38
39
40 List<String> picNames = this.contactManager.getPicNames(contactParams);
41 List<String> f = randomize(picNames);
42 logger.info("select from " + f.size() + " filters");
43 if (f.size() == 0) {
44 RuntimeException e = new RuntimeException("No pics to make contact " + contactParams.getUuid());
45 pmf.addError(e);
46 return(false);
47 }
48 LinkedList<String> ll = new LinkedList<String>();
49 BufferedImage bi = new BufferedImage(cWidth, cHeight, BufferedImage.TYPE_3BYTE_BGR);
50 Graphics2D g = bi.createGraphics();
51 String tName;
52 Contact c = new Contact();
53 c.setName(cUuid);
54 c.setStartTime(new Date());
55 c.setCid(chain.getCid());
56 try {
57 int irow = 0;
58 int row = 0;
59 while (row < cHeight) {
60 int icol = 0;
61 int col = 0;
62 while (col < cWidth) {
63 if (ll.isEmpty())
64 ll = new LinkedList<String>(f);
65 tName = (String)ll.removeFirst();
66 int widthDrawn = drawThumb(g, tName, tHeight, col, row);
67
68
69 c.setPic(tName, irow, icol);
70 col += widthDrawn;
71 icol++;
72 }
73 row += contactParams.getSize();
74 irow++;
75 if (isAbort())
76 break;
77 }
78 drawContactLabel(g);
79 } catch (Exception e) {
80 logger.error("Error drawing contact", e);
81 pmf.addError(e);
82 return(false);
83
84 }
85 success = writePic(bi, false);
86 c.setEndTime(new Date());
87 pmf.getDB().addContact(c);
88 return(success);
89 }
90
91 }