<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Rotate an Icon in Java</title>
	<atom:link href="http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/</link>
	<description>Love being a Swing developer</description>
	<pubDate>Wed, 20 Aug 2008 20:43:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Swing links of the week: March 2, 2008</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2703</link>
		<dc:creator>Swing links of the week: March 2, 2008</dc:creator>
		<pubDate>Mon, 03 Mar 2008 17:07:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2703</guid>
		<description>[...] an active blog to showcase the new features as they are made available. While the latest entry on rotating icons is quite useful, the previous &#8220;real&#8221; one was back in December. And on a related note, [...]</description>
		<content:encoded><![CDATA[<p>[...] an active blog to showcase the new features as they are made available. While the latest entry on rotating icons is quite useful, the previous &#8220;real&#8221; one was back in December. And on a related note, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Orr</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2692</link>
		<dc:creator>Ken Orr</dc:creator>
		<pubDate>Fri, 29 Feb 2008 20:53:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2692</guid>
		<description>No problem...this will be useful!</description>
		<content:encoded><![CDATA[<p>No problem&#8230;this will be useful!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Qiao</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2690</link>
		<dc:creator>David Qiao</dc:creator>
		<pubDate>Fri, 29 Feb 2008 18:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2690</guid>
		<description>I updated the source code in the original post. Thanks for the suggestion, Ken!</description>
		<content:encoded><![CDATA[<p>I updated the source code in the original post. Thanks for the suggestion, Ken!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Qiao</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2689</link>
		<dc:creator>David Qiao</dc:creator>
		<pubDate>Fri, 29 Feb 2008 16:14:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2689</guid>
		<description>Good point. Your code to translate coord to center makes the code logic a lot simpler. I will change the implementation once I get a chance.

Thanks,</description>
		<content:encoded><![CDATA[<p>Good point. Your code to translate coord to center makes the code logic a lot simpler. I will change the implementation once I get a chance.</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Orr</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2688</link>
		<dc:creator>Ken Orr</dc:creator>
		<pubDate>Fri, 29 Feb 2008 16:10:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2688</guid>
		<description>There is a slight deficiency in my supplied code - the getWidth() and getHeight() methods need to be over-ridden with the code David used to calculate the width and height.</description>
		<content:encoded><![CDATA[<p>There is a slight deficiency in my supplied code - the getWidth() and getHeight() methods need to be over-ridden with the code David used to calculate the width and height.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Orr</title>
		<link>http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2686</link>
		<dc:creator>Ken Orr</dc:creator>
		<pubDate>Fri, 29 Feb 2008 12:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/#comment-2686</guid>
		<description>Hi David,

There's actually a much simpler way to do this. If you transform the actual graphics object, you don't need to do all the nasty math:

[cc lang="java"]
 public static class RotatedImageIcon implements Icon {

        private Icon fIcon;
        
        private double fRotationAngle_degress = 0;
        
        public RotatedImageIcon(Icon icon, double rotationAngle_degrees) {
            fIcon = icon;
            fRotationAngle_degress = rotationAngle_degrees;
        }
        
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D myGraphics = (Graphics2D) g.create();
            
            // calculate the center of the icon.
            int centerX = fIcon.getIconWidth()/2;
            int centerY = fIcon.getIconHeight()/2;
            
            // move the graphics center point to the center of the icon.
            myGraphics.translate(centerX, centerY);
            // rotate the graphcis about the center point of the icon
            myGraphics.rotate(Math.toRadians(fRotationAngle_degress));
            
            // request the icon paint itself with the transformed graphics at
            // its original x, y coordinate.
            fIcon.paintIcon(c, myGraphics, -centerX, -centerY);
            
            g.dispose();
        }

        public int getIconWidth() {
            return fIcon.getIconWidth();
        }

        public int getIconHeight() {
            return fIcon.getIconHeight();
        }
    }
[/cc]

</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>There&#8217;s actually a much simpler way to do this. If you transform the actual graphics object, you don&#8217;t need to do all the nasty math:</p>
<div class="codecolorer-container java" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="kw2">public</span> <span class="kw2">static</span> <span class="kw2">class</span> RotatedImageIcon <span class="kw2">implements</span> <span class="kw3">Icon</span> <span class="br0">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw3">Icon</span> fIcon;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">double</span> fRotationAngle_degress = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> RotatedImageIcon<span class="br0">&#40;</span><span class="kw3">Icon</span> icon, <span class="kw4">double</span> rotationAngle_degrees<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fIcon = icon;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fRotationAngle_degress = rotationAngle_degrees;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> paintIcon<span class="br0">&#40;</span><span class="kw3">Component</span> c, <span class="kw3">Graphics</span> g, <span class="kw4">int</span> x, <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Graphics2D</span> myGraphics = <span class="br0">&#40;</span><span class="kw3">Graphics2D</span><span class="br0">&#41;</span> g.<span class="me1">create</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// calculate the center of the icon.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> centerX = fIcon.<span class="me1">getIconWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> centerY = fIcon.<span class="me1">getIconHeight</span><span class="br0">&#40;</span><span class="br0">&#41;</span>/<span class="nu0">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// move the graphics center point to the center of the icon.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myGraphics.<span class="me1">translate</span><span class="br0">&#40;</span>centerX, centerY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// rotate the graphcis about the center point of the icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myGraphics.<span class="me1">rotate</span><span class="br0">&#40;</span><span class="kw3">Math</span>.<span class="me1">toRadians</span><span class="br0">&#40;</span>fRotationAngle_degress<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// request the icon paint itself with the transformed graphics at</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// its original x, y coordinate.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fIcon.<span class="me1">paintIcon</span><span class="br0">&#40;</span>c, myGraphics, -centerX, -centerY<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g.<span class="me1">dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">int</span> getIconWidth<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> fIcon.<span class="me1">getIconWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">int</span> getIconHeight<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> fIcon.<span class="me1">getIconHeight</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div></div>
]]></content:encoded>
	</item>
</channel>
</rss>
