View Javadoc
1   /******************************************************************************
2    * Ribbon.java - Make the original contact sheet
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2005 - Dick Balaska
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  /** Make one of the original contact sheets.
20   * @author Dick Balaska
21   * @since 2011/12/17
22   * @since 2005/08/06
23   * @version $Revision: 1.2 $ <br> $Date: 2014/02/13 07:24:02 $
24   * @see <a href="http://cvs.buckosoft.com/Projects/PicMan/PicMan/src/main/java/com/buckosoft/PicMan/business/contact/engine/Ribbon.java">Ribbon.java</a>
25   */
26  public class Ribbon extends ContactEngine {
27  
28  	/** Make a contact sheet based on the setup.
29  	 * @return Success
30  	 */
31  	protected	boolean	_makeContact() {
32  
33  		boolean	success = true;
34  		
35  		logger.info("makeContact '" + cName + "'");
36  
37  		
38  //		List<String> picNames = pmf.getDB().getPicNamesBySet(contactParams.getSetName(), contactParams.getSize());
39  //		picNames = setupPicsList(contactParams, picNames);
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  }