<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>It's not a blog, It's a feature &#187; java</title>
	<atom:link href="http://javazquez.com/juan/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://javazquez.com/juan</link>
	<description>Juan A. Vazquez</description>
	<lastBuildDate>Tue, 06 Apr 2010 03:43:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Windows GUI File Parser using Groovy</title>
		<link>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/</link>
		<comments>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 19:53:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[DND]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[java swing]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=221</guid>
		<description><![CDATA[I find myself doing a lot of file parsing on my Windows XP machine lately. I decide to write a quick utility that would allow me to drag and drop files and search for the key words that I have identified. The utility doesn&#8217;t have the logic for searching using regex&#8217;s yet, but it should [...]]]></description>
			<content:encoded><![CDATA[<p>   I find myself doing a lot of file parsing on my Windows XP machine lately. I decide to write a quick utility that would allow me to drag and drop files and search for the key words that I have identified. The utility doesn&#8217;t have the logic for searching using regex&#8217;s yet, but it should be really easy to add this functionality. </p>
<p> I hacked some Groovy Code with some Java Code and came up with the following script. Hope it is useful.</p>
<p><strong>DISCLAIMER:</strong></p>
<p>  As the title suggests, I have only been able to get this to work on my Windows XP machine, OS X didn&#8217;t like the <strong> javax.swing.TransferHandler </strong>and it appears some other operating systems have a hard time with this also.</p>
<p><code><br />
import java.awt.datatransfer.DataFlavor;<br />
import java.awt.datatransfer.Transferable;<br />
import java.awt.datatransfer.UnsupportedFlavorException;<br />
import java.io.File;<br />
import java.io.IOException;<br />
import java.security.NoSuchAlgorithmException;<br />
import java.util.List;<br />
import java.awt.BorderLayout;<br />
import java.awt.*;<br />
import java.awt.event.ActionListener;<br />
import java.awt.event.ActionEvent;<br />
import javax.swing.JFrame;<br />
import javax.swing.JPanel;<br />
import javax.swing.JLabel;<br />
import javax.swing.JButton;<br />
import javax.swing.JTextArea;<br />
import javax.swing.JTextField;<br />
import javax.swing.TransferHandler.*;</p>
<p>class FileDropHandler extends TransferHandler {</p>
<p>	private static final long serialVersionUID = 1L;</p>
<p>	def wordsToFind =[]<br />
	JTextArea output<br />
	private JLabel errorMsg;<br />
	private String fileText = "";<br />
	private boolean test = false;<br />
	private boolean same = true;</p>
<p>	public boolean canImport(TransferSupport supp) {<br />
	/* for the demo, we'll only support drops (not clipboard paste) */<br />
	if (!supp.isDrop()) {<br />
		return false;<br />
	}</p>
<p>	/* return false if the drop doesn't contain a list of files */<br />
	if (!supp.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {<br />
	return false;<br />
	}</p>
<p>	boolean copySupported = (COPY &#038; supp.getSourceDropActions()) == COPY;</p>
<p>	if (copySupported) {<br />
	supp.setDropAction(COPY);<br />
	return true;<br />
	}</p>
<p>	return false;<br />
	}</p>
<p>	public boolean importData(TransferSupport supp) {<br />
	if (!canImport(supp)) {<br />
	return false;<br />
	}</p>
<p>	/* get the Transferable */<br />
	Transferable t = supp.getTransferable();</p>
<p>	try {</p>
<p>	Object data = t.getTransferData(DataFlavor.javaFileListFlavor);</p>
<p>	List fileList = (List) data;</p>
<p>	for (int j = 0; j < fileList.size(); j++) {</p>
<p>	File file = (File) fileList.get(j);<br />
	//file.getAbsolutePath()<br />
	def tmpfh = new File("FileParser.txt")<br />
	println wordsToFind.inspect()<br />
	 new File(file.getAbsolutePath()).eachLine{line-><br />
	   wordsToFind.each{   if(line =~ "${it}" ){<br />
	        println "${line}"<br />
	        tmpfh.append(line)<br />
	        tmpfh.append("\n\n")<br />
			this.output.setText(this.output.getText()+line+"\n")<br />
	   }<br />
	  }<br />
	 }//end for</p>
<p>	tmpfh.close()</p>
<p>	}<br />
	} catch (UnsupportedFlavorException e) {<br />
	return false;<br />
	} catch (IOException e) {<br />
	return false;<br />
	} catch (NoSuchAlgorithmException e) {<br />
	// TODO Auto-generated catch block<br />
	e.printStackTrace();<br />
	}</p>
<p>	return true;<br />
	}</p>
<p>	public void setOutput(JTextArea jta) {<br />
	this.output = jta;<br />
	}</p>
<p>	public void setOutput(JLabel jta) {<br />
	errorMsg = jta;<br />
	}</p>
<p>	public String getText() {<br />
	return fileText;<br />
	}</p>
<p>	public void clearAll() {<br />
	fileText = "";<br />
	test = false;<br />
	same = true;</p>
<p>	}<br />
}</p>
<p>class AL implements ActionListener{<br />
   public JTextField jtf<br />
   public FileDropHandler dh<br />
    public AL(JTextField jtf,FileDropHandler dh){<br />
     this.jtf = jtf<br />
     this.dh =dh<br />
    }<br />
    public void actionPerformed(ActionEvent actionEvent){<br />
        println "${this.jtf.getText()}"<br />
        dh.wordsToFind= this.jtf.getText().split(' ')<br />
        }<br />
}</p>
<p>JTextArea dTextArea = new JTextArea("Drop on me");<br />
FileDropHandler dh = new FileDropHandler()<br />
dh.setOutput(dTextArea)<br />
JTextField jta = new JTextField("Enter words seperated by spaces")<br />
dh.wordsToFind= jta.getText().split(' ')<br />
JButton jb =new JButton("Update Word List")<br />
jb.addActionListener( new AL(jta ,dh  ))</p>
<p>dh.setOutput(dTextArea);<br />
dTextArea.setDragEnabled(true);<br />
dTextArea.setTransferHandler(dh);</p>
<p>JPanel p =new JPanel(new BorderLayout());<br />
JFrame f = new JFrame()<br />
p.add(jta, BorderLayout.NORTH)<br />
p.add(dTextArea, BorderLayout.CENTER)<br />
p.add(jb, BorderLayout.SOUTH)</p>
<p>f.getContentPane().add(p)<br />
f.setSize(400,400)<br />
f.setVisible(true)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/04/18/windows-gui-file-parser-using-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Groovy Flickr API</title>
		<link>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/</link>
		<comments>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 16:19:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Flickr]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[java swing]]></category>
		<category><![CDATA[pictures]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=204</guid>
		<description><![CDATA[The hardest part of the whole thing was figuring out how to post images to Fickr, for that, I used the flickrj code as reference. If it was not for the available source code, I don't think I would have ever figured it out. So a big thanks to all the folks working on that project!]]></description>
			<content:encoded><![CDATA[<p>     A long time ago I wanted to write a desktop GUI interface for Flickr. At the time I had just learned Java and thought it would be really cool to write it using swing. Little did I know how not cool working with swing would be <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  </p>
<p>     About halfway through the project I heard about a cool new dynamic way to write Java code called Groovy. From that day on Groovy has been making my life a whole lot easier. I didn&#8217;t need all the functionality in the flickrj library, so I decide to write a few methods for my app using Groovy. The hardest part of the whole thing was figuring out how to post images to Flickr, for that, I used the flickrj code as a reference. If that source code was not available, I don&#8217;t think I would have ever figured it out. So a big thanks to all the folks working on that project!</p>
<p>This is not a complete API for Flickr, but should provide enough to get started. Also, <a href="http://javazquez.com/code/Groovy/glickr.txt">here </a>is a link to a text file with the below code for an easier way to view the source.<br />
<code></p>
<p>import java.io.IOException<br />
import java.security.MessageDigest<br />
import java.security.NoSuchAlgorithmException<br />
import java.util.ArrayList<br />
import java.util.Date<br />
import java.util.Hashtable<br />
import javax.imageio.ImageIO<br />
import org.w3c.dom.Element<br />
import org.w3c.dom.NodeList<br />
import java.io.File;<br />
import java.net.*;<br />
import java.io.IOException;<br />
import org.xml.sax.SAXException;<br />
public class FlickrAPI {<br />
	 String nsid = ""</p>
<p>	private String secret = "your secret"</p>
<p>	/**<br />
	 * api key<br />
	 */<br />
	private String akey = "your key goes here"</p>
<p>	private String sig = ""</p>
<p>	private String url = ""</p>
<p>	 String authToken = ""</p>
<p>	private String frob = ""</p>
<p>	private String restString = "http://flickr.com/services/rest/?method="</p>
<p>	public FlickrAPI() {<br />
		println("Created FlickerAPI")<br />
	}</p>
<p>	public void authNewUser() {<br />
		constructFrobUrl()<br />
		createAuthURL()<br />
		getToken()<br />
	}<br />
	private String constructUrl(String flickrMethod,Map m,boolean authCall =false){<br />
	  String s= this.restString+flickrMethod+"&#038;api_key="+this.akey<br />
		m.each{key,value-><br />
			s+=key+value<br />
			}<br />
			if(authCall){s+="&#038;auth_token=${this.authToken}&#038;api_sig=${this.sig}"}<br />
		return s<br />
	}<br />
	def mapFlickrUser(){</p>
<p>	}<br />
	//if bool is true then this is a Authenticated call<br />
public void setSig(String method,boolean bool = false){<br />
			String sigString="${this.secret}api_key${this.akey}"<br />
		try {<br />
			if(bool){<br />
				sigString +="auth_token${this.authToken}${method}"<br />
				println "Sig is true"<br />
			}else{sigString+=method}<br />
		} catch (NoSuchAlgorithmException e) {<br />
			e.printStackTrace()<br />
		}<br />
	println "sig is " +sigString<br />
		this.sig = calcMD5(sigString)<br />
}</p>
<p>def jupload(String filePath,Map parameters=[:]){<br />
	println("parameters ${parameters.inspect()}")<br />
	def paramMessages=[]<br />
	int paramLength=0</p>
<p>	    if(parameters==[:]){<br />
			this.sig = calcMD5("${this.secret}api_key${this.akey}auth_token${this.authToken}")<br />
		}else{<br />
			//sort them and add them to the signature<br />
			String p=""<br />
			parameters.keySet().toList().sort().each{key-><br />
				//if the key ='tags' make it into space separated string<br />
		         p+= "${key}${parameters[key]}"<br />
				paramMessages.add(addParameter([key,parameters[key]]) )<br />
			}<br />
			this.sig = calcMD5("${this.secret}api_key${this.akey}auth_token${this.authToken}${p}")<br />
			paramMessages.each{stringMsg->paramLength+=stringMsg.length()}<br />
		}</p>
<p>		File file=new File(filePath)<br />
	    String CrLf = "\r\n";<br />
		def url = new URL("http://api.flickr.com/services/upload/")<br />
		//def connection = url.openConnection()<br />
		HttpURLConnection conn = url.openConnection()<br />
			def is = new FileInputStream(file)<br />
			def flength= file.length()<br />
			byte[] imgData= new byte[(int)flength]</p>
<p>			int offset = 0;<br />
			int numRead = 0;<br />
			while (offset < imgData.length &#038;&#038; (numRead=is.read(imgData, offset, imgData.length-offset)) >= 0) {<br />
				offset += numRead;<br />
			}</p>
<p>			// Ensure all the bytes have been read in<br />
			if (offset < imgData.length) {<br />
				throw new IOException("The file was not completely read: "+file.getName());<br />
			}<br />
			println "filesize ->${imgData.length}"<br />
			// Close the input stream, all file contents are in the bytes variable<br />
			is.close();<br />
        String message01=addParameter(['api_key',this.akey])<br />
		String message02 = addParameter(['auth_token',this.authToken])<br />
		String message03 = addParameter(['api_sig',this.sig])</p>
<p>		String message1 = "";<br />
		message1 += "---------------------------6d72u458s1587" + CrLf;<br />
		message1 += "Content-Disposition: form-data; name=\"photo\"; filename=\""+filePath+"\"" + CrLf;<br />
		message1 += "Content-Type: image/jpeg" + CrLf;<br />
		message1 += CrLf;</p>
<p>		// the image is sent between the messages in the multipart message.</p>
<p>		String message2 = "";<br />
		message2 += CrLf + "---------------------------6d72u458s1587--" + CrLf;</p>
<p>		def totalLength = String.valueOf((message01.length() + message02.length() + message03.length() + message1.length() + message2.length() + imgData.length+ paramLength))<br />
		conn.setRequestMethod("POST")<br />
		conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=-------------------------6d72u458s1587");<br />
		conn.setRequestProperty("Host", "api.flickr.com");<br />
		conn.setRequestProperty("Content-Length",totalLength );<br />
		conn.setDoOutput(true)</p>
<p>		System.out.println("open os");<br />
		def os = conn.getOutputStream();</p>
<p>		System.out.println(message01);<br />
		os.write(message01.getBytes());</p>
<p>		System.out.println(message02);<br />
		os.write(message02.getBytes());<br />
 //write the params here before the image<br />
    	paramMessages.each{msg->os.write(msg.getBytes())}</p>
<p>		System.out.println(message03);<br />
		os.write(message03.getBytes());</p>
<p>		System.out.println(message1);<br />
		os.write(message1.getBytes());<br />
    	os.write(imgData,0 ,imgData.length)</p>
<p>		os.write(message2.getBytes());</p>
<p>		println "end writing"<br />
		os.flush()<br />
		os.close()</p>
<p>		conn.connect()<br />
		conn.disconnect()<br />
		println	conn.content.text</p>
<p>}<br />
//[name value]<br />
private String addParameter(List para){<br />
	String CrLf = "\r\n";<br />
	String message01 = "";<br />
	message01 += "---------------------------6d72u458s1587" + CrLf;<br />
	message01 += "Content-Disposition: form-data; name=\"${para[0]}\"" + CrLf;<br />
	message01 += CrLf;<br />
	message01 += para[1] + CrLf;<br />
	return message01<br />
}</p>
<p>	public void constructFrobUrl() {<br />
		setSig("methodflickr.auth.getFrob")<br />
		this.url = "http://flickr.com/services/rest/?method=flickr.auth.getFrob&#038;api_key=${this.akey}&#038;api_sig=${this.sig}"<br />
		println("here is url-> ${this.url}")<br />
		def node = new XmlParser().parse(this.url)//dom.parseXML("frob")<br />
		this.frob = node['frob'].text().toString()<br />
		println("frob =>${this.frob}\n\n")<br />
	}</p>
<p>	/**<br />
	 * This function will calculate an MD5 sum of String Signature and return<br />
	 * the String value of the Hash via strBuildup<br />
	 *<br />
	 * @param signature<br />
	 * @throws NoSuchAlgorithmException<br />
	 * @returns strBuildup<br />
	 */<br />
	private String calcMD5(String signature) throws NoSuchAlgorithmException {<br />
		// get Instance from Java Security Classes<br />
		String strBuildup = ""<br />
		MessageDigest md5 = MessageDigest.getInstance("MD5")<br />
		byte[] md5summe = md5.digest(signature.getBytes())<br />
		for (int k = 0; k < md5summe.length; k++) {<br />
			byte b = md5summe[k]<br />
			String temp = Integer.toHexString(b &#038; 0xFF)<br />
			/*<br />
			 * toHexString has the side effect of making stuff like 0x0F only<br />
			 * one char F(when it should be '0F') so I check the length of<br />
			 * string<br />
			 */<br />
			if (temp.length() < 2) {<br />
				temp = "0" + temp<br />
			}<br />
			temp = temp.toUpperCase()<br />
			strBuildup += temp<br />
		}<br />
		return strBuildup<br />
	}</p>
<p>	/**<br />
	 * get the authentication token<br />
	 *<br />
	 * @return<br />
	 */<br />
	public checkToken(){<br />
		setSig("methodflickr.auth.checkToken",true)<br />
		this.url=constructUrl('flickr.auth.checkToken',[:],true)<br />
		println(this.url)<br />
		def node = new XmlParser().parse(this.url)<br />
		println("done parsing check Token INFO ===>${node.children()}")<br />
	}<br />
	public void getToken() {<br />
		println("Entering getToken\n\n")<br />
		setSig("frob${this.frob}methodflickr.auth.getToken")<br />
		this.url = "${this.restString}flickr.auth.getToken&#038;api_key=${this.akey}&#038;frob=${this.frob}&#038;api_sig=${this.sig}"<br />
		//println(this.url)<br />
		def node = new XmlParser().parse(this.url)<br />
		//need to get the nsid and the authtoken<br />
		this.authToken = node['auth']['token'].text()<br />
		this.nsid = node['auth']['user'].'@nsid'.text()<br />
		println "token is ${this.authToken}"<br />
		println("Token =>${node['auth']['token'].text()}")<br />
		println("nsid =>${node['auth']['user'].'@nsid'.text()}")<br />
		println("perms =>${node['auth']['perms'].text()}")</p>
<p>		// set user nsid<br />
		println("Exiting GET Token")<br />
	}</p>
<p>	public void createAuthURL() {<br />
		setSig("frob${this.frob}permsdelete")<br />
		String cmd = "open http://flickr.com/services/auth/?api_key="+ this.akey + "&#038;perms=delete" + "&#038;frob=" + this.frob + "&#038;api_sig=" + this.sig<br />
		try {<br />
			Process proc =	cmd.execute()<br />
			proc.waitForOrKill(10000)<br />
			sleep(2000)<br />
		} catch (IOException e) {<br />
			// TODO Auto-generated catch block<br />
			e.printStackTrace()<br />
		}<br />
	}</p>
<p>	/***************************************************************************<br />
	 * AUTH<br />
	 **************************************************************************/<br />
	/***************************************************************************<br />
	 * ACTIVITIES<br />
	 **************************************************************************/<br />
	//POLL ONLY ONCE AN HOUR!!!!!<br />
	public activityGetUserComments(){<br />
		setSig("methodflickr.activity.userComments",true)<br />
		this.url=constructUrl('flickr.activity.userComments',[:],true)<br />
		println(this.url)<br />
		def node = new XmlParser().parse(this.url)<br />
		println("done parsing GET user Comments INFO ===>${node.children()}")<br />
	}<br />
	/***************************************************************************<br />
	 * BLOGS<br />
	 **************************************************************************/<br />
	/***************************************************************************<br />
	 * CONTACTS<br />
	 **************************************************************************/<br />
	 public void contactsGetList(){<br />
			setSig("methodflickr.contacts.getList",true)<br />
			this.url=constructUrl('flickr.contacts.getList',[:],true)<br />
			println(this.url)<br />
			def node = new XmlParser().parse(this.url)<br />
			println("done parsing GET contact List INFO ===>${node.children()}")<br />
	}<br />
	/***************************************************************************<br />
	 * FAVORITES<br />
	 **************************************************************************/<br />
	/***************************************************************************<br />
	 * GROUPS<br />
	 **************************************************************************/<br />
	/***************************************************************************<br />
	 * GROUP POOLS<br />
	 **************************************************************************/</p>
<p>	/***************************************************************************<br />
	 * INTERESTINGNESS<br />
	 **************************************************************************/</p>
<p>/***************************************************************************<br />
 * PHOTOS<br />
*what if a return back an array of pictures?<br />
 **************************************************************************/<br />
def photosGetNotInSet(){<br />
		List piclist=[]<br />
		setSig("methodflickr.photos.getNotInSet",true)<br />
		this.url=constructUrl('flickr.photos.getNotInSet',[:],true)<br />
		println(this.url)<br />
		def node = new XmlParser().parse(this.url)<br />
		println("done parsing GET Not in Set INFO ===>${node.children()}\n\n\n")<br />
/*		test=f.photosGetNotInSet()<br />
		 println test.photos.each{it-> it.each{p-> println p}} //list of nodes</p>
<p>		test.photos.photo[3].attributes()<br />
		test.photos.photo.each{it-> println it.attribute('isfamily')} //gets the individual attr<br />
		test.photos.photo.each{it-> picList.push(new Picture(it))} //push a node into picture contructor</p>
<p>		*/</p>
<p>	return node<br />
	}</p>
<p>	def photosGetContactsPhotos(){<br />
		setSig("methodflickr.photos.getContactsPhotos",true)<br />
		this.url=constructUrl('flickr.photos.getContactsPhotos',[:],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		return node<br />
	}</p>
<p>	def photosGetRecentlyUploaded() {<br />
		setSig("methodflickr.photos.getRecent",true)<br />
		//this.url = "flickr.photos.getRecent&#038;api_key",[:],true)<br />
	    this.url= constructUrl('flickr.photos.getRecent',[:],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		println("done parsing RecentPhotos ===>${node.children()}")<br />
		return node<br />
	}<br />
	public void photosGetInfo(){</p>
<p>	}<br />
	/***************************************************************************<br />
	 * PEOPLE<br />
	 **************************************************************************/<br />
	def contactsGetList(){<br />
		setSig("methodflickr.contacts.getList",true)<br />
		this.url=constructUrl('flickr.contacts.getList',[:],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		//println("done parsing GET contact List INFO ===>${node.children()}")<br />
		return node<br />
	}<br />
	def peopleGetUploadStatus(){<br />
		setSig("methodflickr.people.getUploadStatus",true)<br />
		this.url=constructUrl('flickr.people.getUploadStatus',[:],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		println("done parsing GET upload Status INFO ===>${node.children()}")<br />
		return node<br />
	}<br />
	def peopleGetPublicPhotos() {<br />
		setSig("methodflickr.people.getPublicPhotosuser_id${this.nsid}",true)<br />
	 	this.url=constructUrl('flickr.people.getPublicPhotos',['&#038;user_id=':"${this.nsid}"],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		//def peepsInfo = node['auth']['peeps'].text()<br />
		println("done parsing GET  Public Photos ===>${node.children()}")<br />
		return node<br />
	}<br />
	def peopleGetPeopleInfo() {<br />
		setSig("methodflickr.people.getInfouser_id${this.nsid}",true)<br />
	 	this.url=constructUrl('flickr.people.getInfo',['&#038;user_id=':"${this.nsid}"],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		//def peepsInfo = node['auth']['peeps'].text()<br />
		return node<br />
	}</p>
<p>	/********************************************<br />
	* photosets<br />
	************************/<br />
   def photosetsGetList(String uid){<br />
		setSig("methodflickr.photosets.getListuser_id${uid}",true)<br />
	 	this.url=constructUrl('flickr.photosets.getList',['&#038;user_id=':"${uid}"],true)<br />
		def node = new XmlParser().parse(this.url)<br />
		//def peepsInfo = node['auth']['peeps'].text()<br />
		return node</p>
<p>}<br />
 def photosetsGetPhotos(String setID){<br />
		setSig("methodflickr.photosets.getPhotosphotoset_id${setID}",true)<br />
	 	this.url=constructUrl('flickr.photosets.getPhotos',['&#038;photoset_id=':"${setID}"],true)<br />
	println this.url<br />
		def node = new XmlParser().parse(this.url)<br />
		//def peepsInfo = node['auth']['peeps'].text()<br />
		return node</p>
<p>}<br />
/**<br />
Upload photos</p>
<p>http://api.flickr.com/services/upload/</p>
<p>*/<br />
//get the picture when supplied the proper args<br />
//http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg</p>
<p> public String getPicture(String farmId, String serverId, String photoid, String secret,String size ="s"){<br />
	return "http://farm${farmId}.static.flickr.com/${serverId}/${photoid}_${secret}_${size}.jpg"</p>
<p>}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rotating Java Images</title>
		<link>http://javazquez.com/juan/2008/07/11/rotating-java-images/</link>
		<comments>http://javazquez.com/juan/2008/07/11/rotating-java-images/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 22:10:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java swing]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=12</guid>
		<description><![CDATA[I am working on a swing flickr app and thought I would share some code to help those that are new to java gui programming( like me) and get them on their way to making their killer application. I’ll start off with my first problem,  “How do I show an Image?” After looking through Java [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a swing flickr app and thought I would share some code to help those that are new to java gui programming( like me) and get them on their way to making their killer application.</p>
<p>I’ll start off with my first problem,  “How do I show an Image?” After looking through Java forums and going through my Java books, I settled on using Image Icons in JLabels. The next thing I wanted to do was rotate the image 90 degrees. I used Java’s Graphics class to accomplish this. The following groovy code loads 100 JLabels containing a JPEG of Pixar’s Wall-e that I had in the same directory rotated 90 degrees.</p>
<p><code></p>
<pre>import java.awt.image.BufferedImage
import javax.swing.*
import java.awt.*;
import java.util.*;
import java.awt.image.AffineTransformOp
import java.awt.geom.AffineTransform

class ImageButton extends JLabel{
	ImageIcon picture

public ImageButton(ImageIcon icon){
	super(icon)
	this.setBackground(Color.BLACK)
	this.setForeground(Color.BLACK)
	this.picture=icon
	this.setPreferredSize(new Dimension(120,100))
}

public void rotateImage( int angle) {
	int w = this.picture.getImage().getWidth()
	int h = this.picture.getImage().getHeight()
	BufferedImage bi = new BufferedImage(w,h,
                      BufferedImage.TYPE_INT_RGB)
	Graphics bg = bi.createGraphics();
	bg.rotate(Math.toRadians(angle), w/2, h/2);
	bg.drawImage(this.picture.getImage(),0,0,w, h,
			0,0,w, h, null);

	bg.dispose()//cleans up resources
	this.setIcon(new ImageIcon(bi))
	this.setPreferredSize(new Dimension(this.picture.getIconHeight(),
                       this.picture.getIconWidth()))
	}
}

JFrame f= new JFrame()
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
JPanel panel=new JPanel();
def img= new ImageIcon("walle.jpg")
(1..100).each{i-&gt;
	def btn=new ImageButton(new ImageIcon(img.getImage()
                        .getScaledInstance(120,100,4)))
	panel.add(btn)
	btn.rotateImage(90)//rotate the image now
	println i
}

panel.setBackground(Color.BLACK)

f.setSize(300,400)
f.getContentPane().add(panel)
f.setVisible(true)</pre>
<p></code> </p></blockquote>
<p>My first few attempts at the code gave me <strong>out of memory Heap errors</strong>. I unknowingly had BufferedImage references hanging around.  Once I realized this, I cleaned up my code and remembered to call dispose() on the graphics bg object and everything came together quite nicely.</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2008/07/11/rotating-java-images/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
