<?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>Wed, 16 Nov 2011 02:45:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Groovy project using Gradle</title>
		<link>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/</link>
		<comments>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 02:40:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Gradle]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=378</guid>
		<description><![CDATA[Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.]]></description>
			<content:encoded><![CDATA[<p>Hello fellow Groovyists <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have been kicking the tires on using Gradle for my Groovy projects. I had a few stumbles along the way and wanted to share what I came up with for getting a very simple example working.</p>
<p>build.gradle<br />
<code><br />
apply plugin: 'groovy'<br />
version = "1.0-${new Date().format('yyyyMMdd')}"</p>
<p>manifest.mainAttributes("Main-Class" : "com.javazquez.HelloThere")</p>
<p>repositories {<br />
    mavenCentral()<br />
	mavenRepo urls: "http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"<br />
}<br />
dependencies {<br />
	groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.4'<br />
	groovy group: 'org.mongodb', name: 'mongo-java-driver', version: '2.6.5'<br />
	groovy group: 'com.gmongo', name: 'gmongo', version: '0.9.1'<br />
	testCompile "org.spockframework:spock-core:0.5-groovy-1.8"<br />
}</p>
<p>jar {<br />
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }<br />
}<br />
</code></p>
<p>below is the the HelloThere.groovy file located src/main/groovy/com/javazquez/HelloThere<br />
<code><br />
package com.javazquez<br />
public class HelloThere {</p>
<p>    public static void main(String []args) {<br />
        println "Hello coders!"</p>
<p>    }    </p>
<p>}<br />
</code></p>
<p>after running <strong>gradle build</strong>, I can navigate to the build/libs directory and run <strong>java -jar HelloThere-1.0-20111115.jar </strong> and get the following ouptut</p>
<p>Hello coders!</p>
<p>Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POP3 Gmail access with Clojure and JavaMail</title>
		<link>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/</link>
		<comments>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:44:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google api]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[javamail]]></category>
		<category><![CDATA[pop3]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=357</guid>
		<description><![CDATA[I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful Enjoy (use '[clojure.contrib.duck-streams]) (def props (System/getProperties)) ; Get the default Session object. (def session (javax.mail.Session/getDefaultInstance props)) ; Get a Store [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful  Enjoy <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code><br />
(use '[clojure.contrib.duck-streams])<br />
(def props (System/getProperties))<br />
  ; Get the default Session object.<br />
  (def session (javax.mail.Session/getDefaultInstance props))</p>
<p>  ; Get a Store object that implements the specified protocol.<br />
  (def store (.getStore session "pop3s"))</p>
<p>  ;Connect to the current host using the specified username and password.<br />
  (.connect store "pop.gmail.com" "username@gmail.com" "password")</p>
<p>  ;Create a Folder object corresponding to the given name.<br />
  (def folder (. store getFolder "inbox"))</p>
<p>  ; Open the Folder.<br />
(.open folder (javax.mail.Folder/READ_ONLY ))<br />
  ; Get the messages from the server<br />
  (def messages (.getMessages folder))</p>
<p>   (defn getFrom [message](javax.mail.internet.InternetAddress/toString (.getFrom message)))<br />
   (defn getReplyTo [message] (javax.mail.internet.InternetAddress/toString (.getReplyTo message)) )<br />
   (defn getSubject [message] (.getSubject message))</p>
<p>   ;print out the body of the message<br />
      (for [m messages] (read-lines(.getInputStream m)) )</p>
<p>;;;;;code for sending an email</p>
<p>(def props (System/getProperties))<br />
(. props put "mail.smtp.host", "smtp.gmail.com")<br />
(. props put "mail.smtp.port", "465")<br />
(. props put "mail.smtp.auth", "true")<br />
(. props put "mail.transport.protocol", "smtps")</p>
<p>(def session (javax.mail.Session/getDefaultInstance props nil))<br />
(def msg (javax.mail.internet.MimeMessage. session))<br />
(. msg setFrom (javax.mail.internet.InternetAddress. "sender@gmail.com"))<br />
(. msg addRecipients javax.mail.Message$RecipientType/TO<br />
   "receiver@gmail.com") </p>
<p>(. msg  setSubject "i am the subject")<br />
(. msg setText "I am the body!!!")</p>
<p>(. msg setHeader "X-Mailer", "msgsend")<br />
(. msg setSentDate (java.util.Date.))</p>
<p>    ; send the email<br />
(def transport (. session getTransport))<br />
(. transport connect "smtp.gmail.com" 465 "sender@gmail.com" "password")<br />
(. transport sendMessage msg (. msg getRecipients javax.mail.Message$RecipientType/TO))<br />
(. transport close)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a PayPal SOAP client with Java 6</title>
		<link>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/</link>
		<comments>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 02:50:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consume]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=318</guid>
		<description><![CDATA[I have always been mystified on the inner workings of SOAP. That was until I learned about the "wsimport" utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal's Sandbox. This code will execute the SetExpressCheckout API call. ]]></description>
			<content:encoded><![CDATA[<p>I have always been mystified on the inner workings of SOAP. That was until I learned about the &#8220;wsimport&#8221; utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal&#8217;s Sandbox. This code will execute the SetExpressCheckout API call. </p>
<p>Just enter the following on your command line to generate the com.javazquez package</p>
<p><strong>wsimport -keep -XadditionalHeaders -Xnocompile -p com.javazquez http://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl</strong></p>
<p>open your favorite java editor(I used eclipse) and add the package(“com.javazquez”..created in the above command) to your new project </p>
<p>next, write some code to test out the APIs<br />
<code><br />
package com.javazquez;</p>
<p>import javax.xml.ws.Holder;<br />
public class TestEC {</p>
<p>	public static void main(String[] args) {<br />
         SetExpressCheckoutReq req = new SetExpressCheckoutReq();<br />
         SetExpressCheckoutRequestType reqType = new SetExpressCheckoutRequestType();<br />
         SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();<br />
         AddressType addr = new AddressType();<br />
         addr.cityName = "omaha";<br />
         addr.street1 = "123 main";<br />
         addr.country = CountryCodeType.US;<br />
         addr.name = "joe tester";</p>
<p>         details.address = addr;<br />
         details.orderTotal = new BasicAmountType();<br />
         details.orderTotal.currencyID = CurrencyCodeType.USD;<br />
         details.orderTotal.value = "1.00";<br />
         details.cancelURL = "http://javazquez.com/cancel";<br />
         details.returnURL = "http://javazquez.com/return";</p>
<p>         reqType.setVersion("2.10");</p>
<p>         reqType.setExpressCheckoutRequestDetails = details;<br />
         req.setSetExpressCheckoutRequest(reqType);</p>
<p>         UserIdPasswordType user = new UserIdPasswordType();<br />
         user.username = "XXX";<br />
         user.password = "XXXX";<br />
         user.signature = "XXXX";</p>
<p>         PayPalAPIInterfaceService pp = new PayPalAPIInterfaceService();<br />
         PayPalAPIAAInterface pinterface = pp.getPayPalAPIAA();<br />
         Holder<CustomSecurityHeaderType> security = new Holder(new CustomSecurityHeaderType());<br />
         security.value.setCredentials(user);<br />
         try{<br />
               SetExpressCheckoutResponseType resp = pinterface.setExpressCheckout(req, security);<br />
               System.out.println(resp.token);<br />
               System.out.println(resp.correlationID);<br />
               for(ErrorType msg: resp.errors){<br />
                     System.out.println(msg.longMessage);<br />
               }<br />
         }<br />
         catch(Exception ex){<br />
               System.out.println(ex.getMessage());</p>
<p>         }<br />
	}</p>
<p>}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(def Bonjour-Clojure &#8220;Welcome to functional programming&#8221;)</title>
		<link>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/</link>
		<comments>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 20:54:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=285</guid>
		<description><![CDATA[This post will follow my usual getting started with a language snippets.<br/><br/> 

(defn count-consonants [string] (count ( re-seq  #"[^aeiouAEIOU\s]" string )))
<br/> 
(defn count-vowels [string] (count ( re-seq  #"[aeiouAEIOU\s]" string )))
<br/> 
;read a file into a list.. any suggestions on other ways are welcome :)<br/> 
;usage (file-lines "string_path_to_file")<br/> 
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))
<br/> ]]></description>
			<content:encoded><![CDATA[<p>After the briefest of introductions to functional programming in college(a la Lisp) and dabbling with Scala, I took the functional plunge and started using Clojure recently. At this point, I have only written a couple of small programs and haven&#8217;t formed much of an opinion on where it stacks against my current favorite language at the moment(Groovy). This post will follow my usual getting started with a language snippets. I plan to write more entries as I get more familiar with the language.  On to the code!</p>
<p>&#8212;<br />
;binding<br />
user=> (def Bonjour-Clojure &#8220;Welcome to functional programming&#8221;)<br />
#&#8217;user/Bonjour-Clojure<br />
user=> Bonjour-Clojure<br />
&#8220;Welcome to functional programming&#8221;</p>
<p>;items in a list can be seperated via a comma or white space..<br />
user=> (= [ 1 2 3] [1,2,3])<br />
true</p>
<p>;count the number of consonants in a string<br />
(defn count-consonants [string] (count ( re-seq  #&#8221;[^aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-consonants &#8220;writing code is fun&#8221;)<br />
10</p>
<p>;count the number of vowels in a string<br />
(defn count-vowels [string] (count ( re-seq  #&#8221;[aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-vowels &#8220;lukaskiewicz&#8221;)<br />
5</p>
<p>;read a file into a list.. any suggestions on other ways are welcome <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
;usage (file-lines &#8220;string_path_to_file&#8221;) or to read a webpage ((file-lines &#8220;http://javazquez.com&#8221;)<br />
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))</p>
<p>;view objects class<br />
user=>(class &#8220;Im a string&#8221;)<br />
java.lang.String</p>
<p>;length of string<br />
user=>(count &#8220;I am 18 chars long&#8221;)<br />
18</p>
<p>user=>(range 1 9)<br />
(1 2 3 4 5 6 7 8 )</p>
<p>;repeat a digit<br />
user=>(repeat 4 3)<br />
(3 3 3 3)</p>
<p>;list comprehension<br />
user=>(for [fruit ["apple" "orange" "grape"] ] (str fruit))<br />
(&#8220;apple&#8221; &#8220;orange&#8221; &#8220;grape&#8221;)</p>
<p>;use map to create a new list&#8230; #() is a shortcut for an anonymous<br />
user=>(map #(* 2 %1) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>; also an anonymous function<br />
user=> (map (fn [item](* 2 item)) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>;simple fiter example on a list using odd?<br />
user=> (filter odd? [1, 2,3,4,5])<br />
(1 3 5)</p>
<p>;factorial using reduce<br />
user=> (reduce * [1 2 3])<br />
6</p>
<p>;if statement<br />
user=> (if true (str &#8220;i am true&#8221;)(str &#8220;i am false&#8221;))<br />
&#8220;i am true&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Windows]]></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[code]]></category>
		<category><![CDATA[Groovy]]></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.<br />
<a href="http://github.com/javazquez/glickr">Link to my GitHub Repo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/03/30/a-groovy-flickr-api/feed/</wfw:commentRss>
		<slash:comments>2</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[code]]></category>
		<category><![CDATA[Groovy]]></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>5</slash:comments>
		</item>
	</channel>
</rss>

