<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>łukasz milewski home</title>
	
	<link>http://www.milewski.ws</link>
	<description>foobar damaged brain</description>
	<pubDate>Mon, 18 May 2009 20:26:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/milewski" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="milewski" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Vista glass in SWT application - continuation</title>
		<link>http://www.milewski.ws/2009/05/vista-glass-in-swt-application-continuation/</link>
		<comments>http://www.milewski.ws/2009/05/vista-glass-in-swt-application-continuation/#comments</comments>
		<pubDate>Mon, 18 May 2009 20:16:11 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Desktop Window Manager]]></category>

		<category><![CDATA[Glass]]></category>

		<category><![CDATA[SWT]]></category>

		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=371</guid>
		<description><![CDATA[In my previous post about Vista glass I&#8217;ve introduced very simple way to enable DWM glass in SWT. Since that time, I did a lot of experiments how one can improve that experience, and I&#8217;ve found solutions to almost all issues with DWM/Glass/Vista in SWT. This post became much bigger than I&#8217;ve anticipated, therefore it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.milewski.ws/2009/02/vista-glass-in-swt-application/">previous post about Vista glass</a> I&#8217;ve introduced very simple way to enable DWM glass in SWT. Since that time, I did a lot of experiments how one can improve that experience, and I&#8217;ve found solutions to almost all issues with DWM/Glass/Vista in SWT. This post became much bigger than I&#8217;ve anticipated, therefore it&#8217;s divided into &#8220;text after <strong>more&#8230;</strong>&#8221; :-)</p>
<p>First, let&#8217;s see some screenshot of application in work:</p>
<p style="text-align: center;"><img src="http://www.milewski.ws/wp-content/uploads/2009/05/swt-vista-glass.png" alt="Vista native look for SWT - glass" title="Vista native look for SWT - glass" width="393" height="432" class="size-full wp-image-368" style="margin: 0px; padding: 0px;" /></p>
<p><span id="more-371"></span><br />
Above you see an application running on Windows Vista with DWM and Glass enabled. That part was covered in <a href="http://www.milewski.ws/2009/02/vista-glass-in-swt-application/">previous post</a>, but since then I was able to place native widgets on glass without alpha blending of black (and gray) regions. Trick is rather complicated, explaining without an example code would be problematic, so let us see how this widget looks like (beware, it&#8217;s work in progress code, and I&#8217;m not yet very proficient in writing native widgets in SWT, some errors/memory leaks could be there).</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">public</span> <span class="kw2">class</span> OpaqueText <span class="kw2">extends</span> Text<br />
<span class="br0">&#123;</span></p>
<p><span class="kw2">private</span> <span class="kw4">boolean</span> glass;</p>
<p><span class="kw2">public</span> OpaqueText<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AComposite+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Composite</span></a> parent, <span class="kw4">int</span> style<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">this</span><span class="br0">&#40;</span>parent, style, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">public</span> OpaqueText<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AComposite+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Composite</span></a> parent, <span class="kw4">int</span> style, <span class="kw4">boolean</span> glass<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">super</span><span class="br0">&#40;</span>parent, style<span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw2">this</span>.<span class="me1">glass</span> = glass;</p>
<p>&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>glass<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; OS.<span class="me1">BufferedPaintInit</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">int</span> <span class="coMULTI">/* long */</span>callWindowProc<span class="br0">&#40;</span><span class="kw4">int</span> <span class="coMULTI">/* long */</span>hwnd, <span class="kw4">int</span> msg, <span class="kw4">int</span> <span class="coMULTI">/* long */</span>wParam,<br />
&nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span>lParam<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>handle == <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="nu0">0</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!glass<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">callWindowProc</span><span class="br0">&#40;</span>hwnd, msg, wParam, lParam<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw4">boolean</span> redraw = <span class="kw2">false</span>;</p>
<p>&nbsp; <span class="kw1">switch</span> <span class="br0">&#40;</span>msg<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_ERASEBKGND</span>:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>findImageControl<span class="br0">&#40;</span><span class="br0">&#41;</span> != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">break</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_HSCROLL</span>:<br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_VSCROLL</span>:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; redraw = findImageControl<span class="br0">&#40;</span><span class="br0">&#41;</span> != <span class="kw2">null</span> &amp;&amp; drawCount == <span class="nu0">0</span> &amp;&amp; OS.<span class="me1">IsWindowVisible</span><span class="br0">&#40;</span>handle<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>redraw<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">DefWindowProc</span><span class="br0">&#40;</span>handle, OS.<span class="me1">WM_SETREDRAW</span>, <span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">break</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_PAINT</span>:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span>paintDC = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; PAINTSTRUCT ps = <span class="kw2">new</span> PAINTSTRUCT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; paintDC = OS.<span class="me1">BeginPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw4">int</span> width = ps.<span class="me1">right</span> - ps.<span class="me1">left</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw4">int</span> height = ps.<span class="me1">bottom</span> - ps.<span class="me1">top</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>width != <span class="nu0">0</span> &amp;&amp; height != <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span><span class="br0">&#91;</span><span class="br0">&#93;</span> phdc = <span class="kw2">new</span> <span class="kw4">int</span> <span class="coMULTI">/* long */</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; RECT prcTarget = <span class="kw2">new</span> RECT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">SetRect</span><span class="br0">&#40;</span>prcTarget, ps.<span class="me1">left</span>, ps.<span class="me1">top</span>, ps.<span class="me1">right</span>, ps.<span class="me1">bottom</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> flags = OS.<span class="me1">BPBF_TOPDOWNDIB</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span>hBufferedPaint =<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">BeginBufferedPaint</span><span class="br0">&#40;</span>paintDC, prcTarget, flags, <span class="kw2">null</span>, phdc<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span>hDC = paintDC;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; hDC = phdc<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">CallWindowProc</span><span class="br0">&#40;</span>EditProc, hwnd, OS.<span class="me1">WM_PAINT</span>, hDC, lParam<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">BufferedPaintSetAlpha</span><span class="br0">&#40;</span>hBufferedPaint, prcTarget, <span class="br0">&#40;</span><span class="kw4">byte</span><span class="br0">&#41;</span> <span class="nu0">255</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">EndBufferedPaint</span><span class="br0">&#40;</span>hBufferedPaint, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; OS.<span class="me1">EndPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw2">break</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="kw4">int</span> <span class="coMULTI">/* long */</span>code = OS.<span class="me1">CallWindowProc</span><span class="br0">&#40;</span>EditProc, hwnd, msg, wParam, lParam<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">switch</span> <span class="br0">&#40;</span>msg<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_HSCROLL</span>:<br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">WM_VSCROLL</span>:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>redraw<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">DefWindowProc</span><span class="br0">&#40;</span>handle, OS.<span class="me1">WM_SETREDRAW</span>, <span class="nu0">1</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">InvalidateRect</span><span class="br0">&#40;</span>handle, <span class="kw2">null</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; OS.<span class="me1">UpdateWindow</span><span class="br0">&#40;</span>handle<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">break</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="kw2">return</span> code;<br />
<span class="br0">&#125;</span></p>
<p>LRESULT wmCommandChild<span class="br0">&#40;</span><span class="kw4">int</span> <span class="coMULTI">/* long */</span>wParam, <span class="kw4">int</span> <span class="coMULTI">/* long */</span>lParam<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!glass<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">wmCommandChild</span><span class="br0">&#40;</span>wParam, lParam<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw4">int</span> code = OS.<span class="me1">HIWORD</span><span class="br0">&#40;</span>wParam<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">switch</span> <span class="br0">&#40;</span>code<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> OS.<span class="me1">EN_CHANGE</span>:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; OS.<span class="me1">InvalidateRect</span><span class="br0">&#40;</span>handle, <span class="kw2">null</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; OS.<span class="me1">UpdateWindow</span><span class="br0">&#40;</span>handle<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; sendEvent<span class="br0">&#40;</span>SWT.<span class="me1">Modify</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>isDisposed<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> LRESULT.<span class="me1">ZERO</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">null</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">wmCommandChild</span><span class="br0">&#40;</span>wParam, lParam<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
<p>Bottom line is, we need to overwrite native widget WM_PAINT message and introduce buffered painting with alpha capabilities. Method callWindowProc() is a bit trimmed down from original Text.callWindowProc() but additional functionalities were not needed for purpose of this example. Another change that had to be made specifically to Text widget was its handling of EN_CHANGE message, without invalidating and updating content of native widget, entire widget was falling back to not buffered paint until new WM_PAINT message was dispatched. Following this pattern, we&#8217;re able to place any native widget on glass without loosing its correct painting (as was hinted by Steve in <a href="http://www.milewski.ws/2009/02/vista-glass-in-swt-application/#comment-209">3rd comment</a>).</p>
<p>Having this done, example application started to look how it should be in glass - the Search text field was now correctly painted and I was able to continue my work on handling scenario when DWM is disabled, but default Vista theme is enabled. You may notice that Explorer (even Internet Explorer > 7) is falling back very nicely to extended chrome (here I will call it header pane):</p>
<p style="text-align: center;"><img src="http://www.milewski.ws/wp-content/uploads/2009/05/internet-explorer-default.png" alt="Internet Explorer in default theme" title="Internet Explorer in default theme" width="466" height="401" class="alignnone size-full wp-image-388" style="margin: 0px; padding: 0px;" /></p>
<p>Very nice indeed, folks that don&#8217;t have DWM and glass enabled still have same user interface, just a little bit differently painted. So how we can achieve similar effect in SWT. Well, it&#8217;s also very complicated, and showing once again code example would be easier. This time it&#8217;ll be two classes that we need to write.</p>
<p>First class is GlassAwareShell that we need to use instead of original Shell class:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">public</span> <span class="kw2">class</span> GlassAwareShell <span class="kw2">extends</span> Shell<br />
<span class="br0">&#123;</span></p>
<p><span class="kw2">public</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw4">int</span> DWM_CHANGE = <span class="nu0">50</span>;</p>
<p><span class="kw2">public</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw4">int</span> WM_DWMCOMPOSITIONCHANGED = 0&#215;31e;</p>
<p><span class="kw2">protected</span> <span class="kw4">boolean</span> activeValue = <span class="kw2">true</span>;</p>
<p><span class="kw2">public</span> GlassAwareComposite header = <span class="kw2">null</span>;</p>
<p><span class="kw2">public</span> GlassAwareShell<span class="br0">&#40;</span>Display display, <span class="kw4">int</span> style<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">super</span><span class="br0">&#40;</span>display, style<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
LRESULT WM_ACTIVATE<span class="br0">&#40;</span><span class="kw4">int</span> wParam, <span class="kw4">int</span> lParam<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; header.<span class="me1">setActive</span><span class="br0">&#40;</span>activeValue = OS.<span class="me1">LOWORD</span><span class="br0">&#40;</span>wParam<span class="br0">&#41;</span> != <span class="nu0">0</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>header != <span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; RECT rect = <span class="kw2">new</span> RECT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; rect.<span class="me1">right</span> = header.<span class="me1">getClientArea</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">width</span>;<br />
&nbsp; &nbsp; rect.<span class="me1">bottom</span> = header.<span class="me1">getClientArea</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">height</span>;</p>
<p>&nbsp; &nbsp; OS.<span class="me1">InvalidateRect</span><span class="br0">&#40;</span>header.<span class="me1">handle</span>, rect, <span class="kw2">false</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; OS.<span class="me1">UpdateWindow</span><span class="br0">&#40;</span>header.<span class="me1">handle</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">WM_ACTIVATE</span><span class="br0">&#40;</span>wParam, lParam<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
<span class="kw4">int</span> windowProc<span class="br0">&#40;</span><span class="kw4">int</span> hwnd, <span class="kw4">int</span> msg, <span class="kw4">int</span> wParam, <span class="kw4">int</span> lParam<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>handle == <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="nu0">0</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hwnd != handle<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">windowProc</span><span class="br0">&#40;</span>hwnd, msg, wParam, lParam<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw1">switch</span> <span class="br0">&#40;</span>msg<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">case</span> WM_DWMCOMPOSITIONCHANGED:<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; postEvent<span class="br0">&#40;</span>DWM_CHANGE<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="nu0">0</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">windowProc</span><span class="br0">&#40;</span>hwnd, msg, wParam, lParam<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">public</span> <span class="kw4">void</span> setHeader<span class="br0">&#40;</span>GlassAwareComposite header<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">this</span>.<span class="me1">header</span> = header;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
<p>New shell provides new method to store header inside shell object, it&#8217;s useful in requesting for invalidation and update of its native widget. What&#8217;s important is WM_ACTIVATE message handling method. Essentially in default theme, colors change when window is focused or blurred, we need to handle this scenario also. Here I&#8217;ve faced a big roadblock. After sending InvalidateRect message to header native widget I had big delays between painting chrome (windows border) and header pane, so noticeable that it was unacceptable. After days of studying MSDN I found that one can request WM_PAINT without going to dispatcher queue using UpdateWindow method on header. That was a big relief, because header started to paint itself immediately after border (still there&#8217;s sometimes noticeable, few milliseconds of delay, but I found this delay in Internet Explorer also). Last thing that was added to this shell is listener DWM_CHANGE that is posted when WM_DWMCOMPOSITIONCHANGED message is received by shell. This message is not declared in OS, therefore I&#8217;ve added it at the top of the GlassAwareShell class. Message is sent by operating system, when there&#8217;s a change of DWM state (disabled/enabled).</p>
<p>Now we need to implement this header pane for ourselves. It&#8217;s not provided. Here&#8217;s the example code:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">public</span> <span class="kw2">class</span> GlassAwareComposite <span class="kw2">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AComposite+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Composite</span></a><br />
<span class="br0">&#123;</span></p>
<p><span class="kw2">private</span> <span class="kw2">final</span> <span class="kw4">int</span> WP_FRAMELEFT = <span class="nu0">7</span>;</p>
<p><span class="kw2">private</span> <span class="kw2">final</span> <span class="kw4">int</span> FS_ACTIVE = <span class="nu0">1</span>;</p>
<p><span class="kw2">private</span> <span class="kw2">final</span> <span class="kw4">int</span> FS_INACTIVE = <span class="nu0">2</span>;</p>
<p><span class="kw2">private</span> <span class="kw4">boolean</span> activeValue = <span class="kw2">true</span>;</p>
<p><span class="kw2">private</span> <span class="kw4">int</span> hWindowTheme;</p>
<p><span class="kw2">private</span> <span class="kw4">boolean</span> dwmGlass;</p>
<p><span class="kw2">private</span> <span class="kw4">boolean</span> classicTheme;</p>
<p><span class="kw2">private</span> <span class="kw4">boolean</span> windowsVistaOrLater;</p>
<p><span class="kw2">public</span> GlassAwareComposite<span class="br0">&#40;</span>Shell shell, <span class="kw4">int</span> style<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">super</span><span class="br0">&#40;</span>shell, style<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
LRESULT WM_PAINT<span class="br0">&#40;</span><span class="kw4">int</span> wParam, <span class="kw4">int</span> lParam<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>dwmGlass<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> wmPaintDwmGlass<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>windowsVistaOrLater<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> wmPaintVistaOrLaterGlassDisabled<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw2">return</span> <span class="kw2">super</span>.<span class="me1">WM_PAINT</span><span class="br0">&#40;</span>wParam, lParam<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">private</span> LRESULT wmPaintDwmGlass<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; PAINTSTRUCT ps = <span class="kw2">new</span> PAINTSTRUCT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw4">int</span> hDC = OS.<span class="me1">BeginPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;</p>
<p>&nbsp; RECT rect = <span class="kw2">new</span> RECT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; rect.<span class="me1">left</span> = <span class="nu0">0</span>;<br />
&nbsp; rect.<span class="me1">top</span> = <span class="nu0">0</span>;<br />
&nbsp; rect.<span class="me1">right</span> = getClientArea<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">width</span>;<br />
&nbsp; rect.<span class="me1">bottom</span> = getClientArea<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">height</span>;</p>
<p>&nbsp; <span class="kw4">int</span> hBrush = OS.<span class="me1">GetStockObject</span><span class="br0">&#40;</span>OS.<span class="me1">BLACK_BRUSH</span><span class="br0">&#41;</span>;<br />
&nbsp; OS.<span class="me1">FillRect</span><span class="br0">&#40;</span>hDC, rect, hBrush<span class="br0">&#41;</span>;</p>
<p>&nbsp; OS.<span class="me1">EndPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw2">return</span> LRESULT.<span class="me1">ZERO</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">private</span> LRESULT wmPaintVistaOrLaterGlassDisabled<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hWindowTheme == <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">final</span> <span class="kw4">char</span><span class="br0">&#91;</span><span class="br0">&#93;</span> WINDOW = <span class="kw2">new</span> <span class="kw4">char</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span><span class="st0">&#8216;W&#8217;</span>, <span class="st0">&#8216;I&#8217;</span>, <span class="st0">&#8216;N&#8217;</span>, <span class="st0">&#8216;D&#8217;</span>, <span class="st0">&#8216;O&#8217;</span>, <span class="st0">&#8216;W&#8217;</span>, <span class="nu0">0</span><span class="br0">&#125;</span>;<br />
&nbsp; &nbsp; hWindowTheme = OS.<span class="me1">OpenThemeData</span><span class="br0">&#40;</span>getShell<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">handle</span>, WINDOW<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; PAINTSTRUCT ps = <span class="kw2">new</span> PAINTSTRUCT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw4">int</span> hDC = OS.<span class="me1">BeginPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;</p>
<p>&nbsp; RECT rect = <span class="kw2">new</span> RECT<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; rect.<span class="me1">left</span> = <span class="nu0">-5</span>;<br />
&nbsp; rect.<span class="me1">top</span> = <span class="nu0">0</span>;<br />
&nbsp; rect.<span class="me1">right</span> = getShell<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getClientArea</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">width</span>;<br />
&nbsp; rect.<span class="me1">bottom</span> = getShell<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getClientArea</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">height</span>;</p>
<p>&nbsp; <span class="kw4">int</span> active = activeValue ? FS_ACTIVE : FS_INACTIVE;</p>
<p>&nbsp; OS.<span class="me1">DrawThemeBackground</span><span class="br0">&#40;</span>hWindowTheme, hDC, WP_FRAMELEFT, active, rect, <span class="kw2">null</span><span class="br0">&#41;</span>;<br />
&nbsp; OS.<span class="me1">EndPaint</span><span class="br0">&#40;</span>handle, ps<span class="br0">&#41;</span>;</p>
<p>&nbsp; <span class="kw2">return</span> LRESULT.<span class="me1">ZERO</span>;<br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
<span class="kw2">public</span> <span class="kw4">void</span> dispose<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hWindowTheme != <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; OS.<span class="me1">CloseThemeData</span><span class="br0">&#40;</span>hWindowTheme<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp; <br />
&nbsp; <span class="kw2">super</span>.<span class="me1">dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// &#8230; getters and setters for fields</span></p>
<p><span class="br0">&#125;</span></div>
<p>This GlassAwareComposite is actually useful for DWM enabled and disabled. In each case different paint method will be used, for DWM enabled we draw black background, for DWM disabled we are doing something more interesting. Header pane is painted by UxTheme method DrawThemeBackground. Biggest problem with that was to get correct theme data and image index. Unfortunately in SWT theme data for &#8220;WINDOW&#8221; object is not available, therefore we need to open it for ourselves. Theme data also needs to be released, which we&#8217;re doing in dispose() method. For purpose of painting header pain, we can use same image that is painted on top left side under chrome title bar, but we need to shift it few pixels, because of left border. This is where our WM_ACTIVATE message is extensively used. GlassAwareShell when receive WM_ACTIVATE, sets active state on header pane, then invalidate and update header pane, GlassAwareComposite receive WM_PAINT message and paint it&#8217;s content.</p>
<p>After applying all those magic stuff, our application can looks following, activate:</p>
<p style="text-align: center;"><img src="http://www.milewski.ws/wp-content/uploads/2009/05/swt-vista-header-active.png" alt="Vista native look for SWT - header pane active" title="Vista native look for SWT - header pane active" width="361" height="400" class="size-full wp-image-369" style="margin: 0px; padding: 0px;" /></p>
<p>and inactive:</p>
<p style="text-align: center;"><img src="http://www.milewski.ws/wp-content/uploads/2009/05/swt-vista-header-inactive.png" alt="Vista native look for SWT - header pane inactive" title="Vista native look for SWT - header pane inactive" width="361" height="400" class="size-full wp-image-370" style="margin: 0px; padding: 0px;" /></p>
<p>Thanks to DWM_CHANGE listener introduced in GlassAwareShell application can handle DWM change, accordingly to its desires - I found that if we want to have the same user interface alignment in both DWM enabled and disabled we need to change margins in our layout. I&#8217;ve also noticed that Glass information (created with DwmExtendFrameIntoClientArea() method) is lost after DWM change, so it&#8217;s suggested to call this method once again in DWM_CHANGE listener.</p>
<p>Notice! Due to heavy use of overriding methods with default visibility in Shell, Text and Composite new widgets needs to stay inside org.eclipse.swt.widgets package. This is annoying limitation that could be easily resolved by marking methods <strong>protected</strong>.</p>
<p>I hope that too much of code wasn&#8217;t discouraging and examples were proficient enough to discover that SWT applications under Vista can look the same as those written in C++.</p>
<p>PS. You can observe that I&#8217;m also experimenting with explorer toolbar, but unfortunately I wasn&#8217;t able to find any windows api to draw it, so I just placed background image on Composite ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/05/vista-glass-in-swt-application-continuation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Combo Box with Images in SWT</title>
		<link>http://www.milewski.ws/2009/04/combo-box-with-images-in-swt/</link>
		<comments>http://www.milewski.ws/2009/04/combo-box-with-images-in-swt/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 17:17:56 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Combo]]></category>

		<category><![CDATA[ComboBoxEx]]></category>

		<category><![CDATA[ComboItem]]></category>

		<category><![CDATA[Images]]></category>

		<category><![CDATA[SWT]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=351</guid>
		<description><![CDATA[For past few days I&#8217;ve been working on new SWT widget called ComboBoxEx. This widget is capable of displaying items in Combo along with assigned images. At current state it&#8217;s more or less completed for Windows (win32) SWT. Code base for this widget is derived from SWT Combo class. Windows widget used in this class [...]]]></description>
			<content:encoded><![CDATA[<p>For past few days I&#8217;ve been working on new SWT widget called ComboBoxEx. This widget is capable of displaying items in Combo along with assigned images. At current state it&#8217;s more or less completed for Windows (win32) SWT. Code base for this widget is derived from SWT Combo class. Windows widget used in this class has class name &#8220;COMBOBOXEX32&#8243; and was introduced long time ago by Internet Explorer 4.0 and is currently available for all Windows versions.</p>
<p>Currently widget is only available on Windows, but I&#8217;m planning to provide separate classes for use in other major operating systems (GTK and MacOs) that will encapsulate Combo widget with same interface, e.g. ComboItem instead of String based item.</p>
<p>Here&#8217;s the widget example as it is drawn by operating system on Windows XP.</p>
<p><img class="alignnone size-full wp-image-352" title="ComboBoxEx32 on Windows XP" src="http://www.milewski.ws/wp-content/uploads/2009/04/comboboxex32-xp.png" alt="ComboBoxEx32 on Windows XP" width="550" height="248" style="margin: 0px; padding: 0px;"/></p>
<p><del datetime="2009-04-21T18:16:52+00:00">Similar image will be posted for Windows Vista, later today.</del> Here&#8217;s an image from Windows Vista.</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/04/comboboxex32-vista.png" alt="ComboBoxEx32 on Windows Vista" title="ComboBoxEx32 on Windows Vista" width="550" height="248" class="alignnone size-full wp-image-359"  style="margin: 0px; padding: 0px;"/></p>
<p>Code for example shown above:</p>
<div class="dean_ch" style="white-space: wrap;">ComboBoxEx combo = <span class="kw2">new</span> ComboBoxEx<span class="br0">&#40;</span>shell, SWT.<span class="me1">READ_ONLY</span><span class="br0">&#41;</span>;<br />
combo.<span class="me1">setLayoutData</span><span class="br0">&#40;</span><span class="kw2">new</span> GridData<span class="br0">&#40;</span>GridData.<span class="me1">FILL_HORIZONTAL</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">new</span> ComboItem<span class="br0">&#40;</span>combo, <span class="st0">&quot;Question Icon 32&#215;32&quot;</span>, display.<span class="me1">getSystemImage</span><span class="br0">&#40;</span>SWT.<span class="me1">ICON_QUESTION</span><span class="br0">&#41;</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
<span class="kw2">new</span> ComboItem<span class="br0">&#40;</span>combo, <span class="st0">&quot;Error Icon 32&#215;32&quot;</span>, display.<span class="me1">getSystemImage</span><span class="br0">&#40;</span>SWT.<span class="me1">ICON_ERROR</span><span class="br0">&#41;</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
combo.<span class="me1">select</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;</div>
<p>Unfortunately this widget has a dependency on Java Native Access library from Sun. Let me explain. OS class that has native method declared doesn&#8217;t provide COMBOBOXEXITEM structure and appropriate SendMessage method that takes this structure as a LWORD parameter. Without this changes we&#8217;re not able to send COMBOBOXEXITEM structure to underlying widget.</p>
<p>I&#8217;ll try to release this widget within 2 weeks first for Windows, after that for other operating systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/04/combo-box-with-images-in-swt/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Photo: Wieliczka</title>
		<link>http://www.milewski.ws/2009/04/photo-wieliczka/</link>
		<comments>http://www.milewski.ws/2009/04/photo-wieliczka/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 15:48:17 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Photo]]></category>

		<category><![CDATA[Polish]]></category>

		<category><![CDATA[Kopalnia Soli]]></category>

		<category><![CDATA[Kraków]]></category>

		<category><![CDATA[Sony α350]]></category>

		<category><![CDATA[Wieliczka]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=343</guid>
		<description><![CDATA[
Kilka zdjęć z wycieczki do Kopalni Soli Wieliczka.




]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.milewski.ws/wp-content/uploads/2009/04/dsc00555.jpg" alt="Wieliczka schody" title="Wieliczka schody" class="alignnone size-full wp-image-342" style="margin: 0px; padding: 0px;" /></p>
<p>Kilka zdjęć z wycieczki do Kopalni Soli Wieliczka.<br />
<span id="more-343"></span><br />
<img src="http://www.milewski.ws/wp-content/uploads/2009/04/dsc00626.jpg" alt="Wieliczka" title="Wieliczka" class="alignnone size-full wp-image-344" style="margin: 0px; padding: 0px;" /></p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/04/dsc00647.jpg" alt="Wieliczka" title="Wieliczka" class="alignnone size-full wp-image-345" style="margin: 0px; padding: 0px;" /></p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/04/dsc00670.jpg" alt="Wieliczka" title="Wieliczka" class="alignnone size-full wp-image-346" style="margin: 0px; padding: 0px;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/04/photo-wieliczka/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Vista’s UAC in SWT</title>
		<link>http://www.milewski.ws/2009/04/using-vistas-uac-in-swt/</link>
		<comments>http://www.milewski.ws/2009/04/using-vistas-uac-in-swt/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 22:48:57 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[SWT]]></category>

		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=337</guid>
		<description><![CDATA[UAC allows users to launch specific applications with elevated privileges, e.g. Changing some system settings, or launching an application that needs to have access to files not in your profile (e.g. C:/Program Files/ directory). To accomplish that we need to do two things.
First is to launch application with elevated privileges, it&#8217;s quite easy to do, [...]]]></description>
			<content:encoded><![CDATA[<p>UAC allows users to launch specific applications with elevated privileges, e.g. Changing some system settings, or launching an application that needs to have access to files not in your profile (e.g. C:/Program Files/ directory). To accomplish that we need to do two things.</p>
<p>First is to launch application with elevated privileges, it&#8217;s quite easy to do, we need to use <strong>OS.ShellExecuteEx</strong> and <strong>SHELLEXECUTEINFO</strong> in which there&#8217;s a field called <strong>lpVerb</strong>. This field needs to have <strong>runas</strong> string. Here&#8217;s the example code (it&#8217;s modified version of launch(String) method from Program class.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="coMULTI">/**<br />
&nbsp;* Launches the operating system executable associated with the file or<br />
&nbsp;* URL (http:// or https://) with elevated privileges. &nbsp;If the file is an <br />
&nbsp;* executable then the executable is launched. &nbsp;Note that a <br />
&nbsp;* &lt;code&gt;Display&lt;/code&gt; must already exist to guarantee that this method<br />
&nbsp;* returns an appropriate result. This method waits on OS.ShellExecuteEx<br />
&nbsp;* until user close UAC warning. This works only with Windows Vista and<br />
&nbsp;* higher. On lower versions of Windows there will be no visible difference.<br />
&nbsp;*<br />
&nbsp;* @param fileName the file or program name or URL (http:// or https://)<br />
&nbsp;* @return &lt;code&gt;true&lt;/code&gt; if the file is launched, otherwise<br />
&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &lt;code&gt;false&lt;/code&gt;<br />
&nbsp;* <br />
&nbsp;* @exception IllegalArgumentException &lt;ul&gt;<br />
&nbsp;* &nbsp; &nbsp;&lt;li&gt;ERROR_NULL_ARGUMENT when fileName is null&lt;/li&gt;<br />
&nbsp;* &lt;/ul&gt;<br />
&nbsp;*/</span><br />
<span class="kw2">public</span> <span class="kw2">static</span> <span class="kw4">boolean</span> launchElevated <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> fileName<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>fileName == <span class="kw2">null</span><span class="br0">&#41;</span> SWT.<span class="me1">error</span> <span class="br0">&#40;</span>SWT.<span class="me1">ERROR_NULL_ARGUMENT</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="coMULTI">/* Use the character encoding for the default locale */</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/*long*/</span> hHeap = OS.<span class="me1">GetProcessHeap</span> <span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; TCHAR buffer = <span class="kw2">new</span> TCHAR <span class="br0">&#40;</span><span class="nu0">0</span>, fileName, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> byteCount = buffer.<span class="me1">length</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> * TCHAR.<span class="me1">sizeof</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/*long*/</span> lpFile = OS.<span class="me1">HeapAlloc</span> <span class="br0">&#40;</span>hHeap, OS.<span class="me1">HEAP_ZERO_MEMORY</span>, byteCount<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; OS.<span class="me1">MoveMemory</span> <span class="br0">&#40;</span>lpFile, buffer, byteCount<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; TCHAR verbBuffer = <span class="kw2">new</span> TCHAR <span class="br0">&#40;</span><span class="nu0">0</span>, <span class="st0">&quot;runas&quot;</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> verbByteCount = verbBuffer.<span class="me1">length</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> * TCHAR.<span class="me1">sizeof</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/*long*/</span> lpVerb = OS.<span class="me1">HeapAlloc</span> <span class="br0">&#40;</span>hHeap, OS.<span class="me1">HEAP_ZERO_MEMORY</span>, verbByteCount<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; OS.<span class="me1">MoveMemory</span> <span class="br0">&#40;</span>lpVerb, verbBuffer, verbByteCount<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; SHELLEXECUTEINFO info = <span class="kw2">new</span> SHELLEXECUTEINFO <span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; info.<span class="me1">cbSize</span> = SHELLEXECUTEINFO.<span class="me1">sizeof</span>;<br />
&nbsp; &nbsp; info.<span class="me1">lpFile</span> = lpFile;<br />
&nbsp; &nbsp; info.<span class="me1">lpVerb</span> = lpVerb;<br />
&nbsp; &nbsp; info.<span class="me1">nShow</span> = OS.<span class="me1">SW_SHOW</span>;<br />
&nbsp; &nbsp; <span class="kw4">boolean</span> result = OS.<span class="me1">ShellExecuteEx</span> <span class="br0">&#40;</span>info<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>lpFile != <span class="nu0">0</span><span class="br0">&#41;</span> OS.<span class="me1">HeapFree</span> <span class="br0">&#40;</span>hHeap, <span class="nu0">0</span>, lpFile<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>lpVerb != <span class="nu0">0</span><span class="br0">&#41;</span> OS.<span class="me1">HeapFree</span> <span class="br0">&#40;</span>hHeap, <span class="nu0">0</span>, lpVerb<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw2">return</span> result;<br />
<span class="br0">&#125;</span></div>
<p>Second thing is visual approach. All Vista&#8217;s applications that tries to elevate privileges have shield icon as button image. We don&#8217;t need to provide this icon by ourselves, we just simply send a message <strong>BCM_SETSHIELD</strong> to button widget with lParam 1 (true) or 0 (false).</p>
<div class="dean_ch" style="white-space: wrap;">OS.<span class="me1">SendMessageW</span><span class="br0">&#40;</span>button.<span class="me1">handle</span>, BCM_SETSHIELD, <span class="nu0">0</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
<p>Since BCM_SETSHIELD is not available in OS class (I wonder why?) we need to declare it:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">public</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw4">int</span> BCM_SETSHIELD = OS.<span class="me1">BCM_FIRST</span> + 0xc;</div>
<p>Here&#8217;s obligatory screenshot of BCM_SETSHIELD message in use. In this screenshot there&#8217;s an example of retrieving icon from my previous post.</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/04/elevated-icon.png" alt="Launch notepad.exe elevated" title="Launch notepad.exe elevated" width="550" height="175" class="alignnone size-full wp-image-338" style="margin: 0px; padding: 0px;" /></p>
<p>Hope it will help, it did me :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/04/using-vistas-uac-in-swt/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Extracting executable file icon under SWT</title>
		<link>http://www.milewski.ws/2009/03/extracting-executable-file-icon-under-swt/</link>
		<comments>http://www.milewski.ws/2009/03/extracting-executable-file-icon-under-swt/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 22:20:39 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Icon]]></category>

		<category><![CDATA[SWT]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=334</guid>
		<description><![CDATA[Recently one of my colleagues at work found out that in pure SWT you&#8217;re not able to extract icon from an executable file, what you can only do is to get an icon from a file that is associated with specific file type (extension). So, I decided to write a method of my own, and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently one of my colleagues at work found out that in pure SWT you&#8217;re not able to extract icon from an executable file, what you can only do is to get an icon from a file that is associated with specific file type (extension). So, I decided to write a method of my own, and here is it.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">public</span> ImageData getExecutableFileIcon<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> fileName, <span class="kw4">boolean</span> large<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> nIconIndex = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; ImageData imageData = <span class="kw2">null</span>;</p>
<p>&nbsp; &nbsp; TCHAR lpszFile = <span class="kw2">new</span> TCHAR<span class="br0">&#40;</span><span class="nu0">0</span>, fileName, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/*long*/</span> <span class="br0">&#91;</span><span class="br0">&#93;</span> phiconSmall = <span class="kw2">new</span> <span class="kw4">int</span> <span class="coMULTI">/*long*/</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; <span class="kw4">int</span> <span class="coMULTI">/*long*/</span> <span class="br0">&#91;</span><span class="br0">&#93;</span> phiconLarge = <span class="kw2">new</span> <span class="kw4">int</span> <span class="coMULTI">/*long*/</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; OS.<span class="me1">ExtractIconEx</span><span class="br0">&#40;</span>lpszFile, nIconIndex, phiconLarge, phiconSmall, <span class="nu0">1</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>phiconSmall<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> != <span class="nu0">0</span> &amp;&amp; !large<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AImage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Image</span></a> image = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AImage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Image</span></a>.<span class="me1">win32_new</span><span class="br0">&#40;</span><span class="kw2">null</span>, SWT.<span class="me1">ICON</span>, phiconSmall<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; imageData = image.<span class="me1">getImageData</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; image.<span class="me1">dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>phiconLarge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> != <span class="nu0">0</span> &amp;&amp; large<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AImage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Image</span></a> image = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AImage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Image</span></a>.<span class="me1">win32_new</span><span class="br0">&#40;</span><span class="kw2">null</span>, SWT.<span class="me1">ICON</span>, phiconLarge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; imageData = image.<span class="me1">getImageData</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; image.<span class="me1">dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">return</span> imageData;<br />
<span class="br0">&#125;</span></div>
<p>At this moment I don&#8217;t really know whether we should call OS.ExtractIconEx for both images, or depending on the flag ask for one of them, dunno.</p>
<p>Although, I have a question for Eclipse community, why similar functionality isn&#8217;t available in SWT? Or if it is, where to find it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/03/extracting-executable-file-icon-under-swt/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Vista glass in SWT application</title>
		<link>http://www.milewski.ws/2009/02/vista-glass-in-swt-application/</link>
		<comments>http://www.milewski.ws/2009/02/vista-glass-in-swt-application/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 23:01:18 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Chromium]]></category>

		<category><![CDATA[Desktop Window Manager]]></category>

		<category><![CDATA[SWT]]></category>

		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=317</guid>
		<description><![CDATA[Desktop Java applications by definition are/should be portable to multiple operating systems. Writing with SWT refines set of available operating systems, but it also gives you some opportunities to make application aware of operating system and blends it visually. With Windows Vista&#8217;s new Desktop Window Manager we are able to create visually more stunning and [...]]]></description>
			<content:encoded><![CDATA[<p>Desktop Java applications by definition are/should be portable to multiple operating systems. Writing with SWT refines set of available operating systems, but it also gives you some opportunities to make application aware of operating system and blends it visually. With Windows Vista&#8217;s new Desktop Window Manager we are able to create visually more stunning and eye catching applications. Look at the Chrome screenshot below, notice the decoration of window, it&#8217;s transparent and blurred:</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/02/chrome-vista-planet.png" alt="Chrome" title="Chrome" width="550" height="485" class="alignnone size-full wp-image-323" style="margin: 0px; padding: 0px;" /></p>
<p>You can actually do similar thing in SWT (under Windows Vista only) and here&#8217;s a small example screenshot:</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/02/vista-glass-swt.png" alt="Vista glass in SWT" title="Vista glass in SWT" width="550" height="237" class="alignnone size-full wp-image-321" style="margin: 0px; padding: 0px;" /></p>
<p>So, what do we need to do to accomplish that? It&#8217;s quite easy, as a matter of fact, but requires nasty access to internal OS class which makes it SWT windows only!</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="coMULTI">/**<br />
&nbsp;* Applies vista glass frame - works only on Vista with Areo.<br />
&nbsp;*/</span><br />
<span class="kw2">private</span> <span class="kw4">void</span> applyVistaGlassFrame<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> glassHeight = <span class="nu0">100</span>;</p>
<p>&nbsp; &nbsp; MARGINS margins = <span class="kw2">new</span> MARGINS<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; margins.<span class="me1">cyTopHeight</span> = glassHeight;</p>
<p>&nbsp; &nbsp; OS.<span class="me1">DwmExtendFrameIntoClientArea</span><span class="br0">&#40;</span>shell.<span class="me1">handle</span>, margins<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Example above will add 100 pixels of glass area at top of the dialog.</p>
<p>But that&#8217;s not enough, we need also to cover glass area with black color, for this we can add Composite widget that will have background color set to SWT.COLOR_BLACK.</p>
<p>Unfortunately this functionality is not 100% covered by SWT. Additional checks against Vista needs to be done. We also need to know if Desktop Window Manager&#8217;s Compositions are enabled. Unfortunately we don&#8217;t have access to DwmIsCompositionEnabled (it&#8217;s not declared in OS class).</p>
<p>While writing this article, I&#8217;ve came up with idea how this can be used in Eclipse - about dialog. Recent changes to about dialog are great, but what if go a little bit further and make top of the dialog similar to <a href="http://brh.numbera.com/blog/wp-content/uploads/2007/03/aptana_vista.png">this</a>, but under Windows Vista with composition instead of white background use glass?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/02/vista-glass-in-swt-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Icons in preferences dialog in Eclipse</title>
		<link>http://www.milewski.ws/2009/02/icons-in-preferences-dialog-in-eclipse/</link>
		<comments>http://www.milewski.ws/2009/02/icons-in-preferences-dialog-in-eclipse/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 16:49:44 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Preference Pages]]></category>

		<category><![CDATA[RCP]]></category>

		<category><![CDATA[Workbench]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=252</guid>
		<description><![CDATA[When you&#8217;re working on custom RCP based applications you&#8217;re sometimes forced to change visual aspects of parts of the application that are provided by Eclipse RCP itself. Preferences is a good example of that visual aspect. Since we want to reuse code from RCP as much as possible we decided to use JFace preferences dialog. [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re working on custom RCP based applications you&#8217;re sometimes forced to change visual aspects of parts of the application that are provided by Eclipse RCP itself. Preferences is a good example of that visual aspect. Since we want to reuse code from RCP as much as possible we decided to use JFace preferences dialog. </p>
<p>After implementing first pages we were pointed out that items should have icons next to label. I thought I would have to patch JFace plug-in to achieve that, but I was wrong! Preferences dialog (and therefore Properties dialog) have undocumented functionality of showing image next to item on the tree view and above content composite. No coding is required to achieve that!</p>
<p>Here&#8217;s how preference page (in this case wklej.org plug-in&#8217;s page) is shown</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/02/preferences-without-icons.png" alt="Preferences without icons" title="Preferences without icons" width="540" height="464" class="alignnone size-full wp-image-302"  style="margin: 0px; padding: 0px;" /></p>
<p>After adding attribute icon to extension point we&#8217;re presented with nice image</p>
<p><img src="http://www.milewski.ws/wp-content/uploads/2009/02/icons-in-preferences.png" alt="Preferences with icons" title="Preferences with icons" width="540" height="464" class="alignnone size-full wp-image-303" style="margin: 0px; padding: 0px;" /></p>
<p>And here&#8217;s modified extension point entry in your plugin.xml (or fragment.xml):</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="sc3"><span class="re1">&lt;extension</span> <span class="re0">point</span>=<span class="st0">&quot;org.eclipse.ui.preferencePages&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">class</span>=<span class="st0">&quot;org.example.plugin.preferences.ExamplePreferencePage&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">id</span>=<span class="st0">&quot;org.example.preferencepage&quot;</span> <span class="re0">name</span>=<span class="st0">&quot;Preference page with image&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">icon</span>=<span class="st0">&quot;images/example.png&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/page<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/extension<span class="re2">&gt;</span></span></span></div>
<p>Notice that Eclipse will show you a warning that icon element is illegal. Fortunately it just a warning, and extension point <strong>org.eclipse.ui.preferencePages</strong> does support images (icons) but it just doesn&#8217;t expose this publicly.</p>
<p>As you can see on the screenshots above, placing image in a plug-in that will be used in standard Eclipse IDE just looks wrong, I agree. But for a custom applications, when you&#8217;re providing <strong>all</strong> pages, it looks great and helps non-developers to find what they&#8217;re looking for.</p>
<p><em>On the other note, I would like to welcome everyone at Eclipse Planet. It&#8217;s a pleasure to be here :-)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/02/icons-in-preferences-dialog-in-eclipse/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some developers have trouble writing Singleton</title>
		<link>http://www.milewski.ws/2009/02/some-developers-have-trouble-writing-singleton/</link>
		<comments>http://www.milewski.ws/2009/02/some-developers-have-trouble-writing-singleton/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 17:37:00 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Interview]]></category>

		<category><![CDATA[Singleton]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=285</guid>
		<description><![CDATA[Lately I&#8217;ve been interviewing developers and while you would think that they should have some knowledge about Java, J2EE, you&#8217;re wrong! Unfortunately I&#8217;ve been faced with &#8220;developers&#8221; without any knowledge.
DISCLAIMER! Developers that I&#8217;ve been interviewing doesn&#8217;t work in company I&#8217;m working on. They&#8217;re from big outsourcing company which name I&#8217;ll not disclose here.
Without further explanation [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been interviewing developers and while you would think that they should have some knowledge about Java, J2EE, you&#8217;re wrong! Unfortunately I&#8217;ve been faced with &#8220;developers&#8221; without any knowledge.</p>
<p>DISCLAIMER! Developers that I&#8217;ve been interviewing doesn&#8217;t work in company I&#8217;m working on. They&#8217;re from big outsourcing company which name I&#8217;ll not disclose here.</p>
<p>Without further explanation let me showcase two examples of Singleton pattern written by a &#8220;developer&#8221;.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">public</span> <span class="kw2">class</span> SingleTon <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">static</span> <span class="kw2">final</span> SingleTon INSTANCE;<br />
&nbsp; &nbsp; SingleTon<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; INSTANCE=<span class="kw4">null</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>The most noticeable here is name of the class and 2 compile time errors with INSTANCE variable. Final modifier requires to add static value to field. Default visibility of constructor means, that class from the same package can instantiate this &#8220;SingleTon&#8221;.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">public</span> <span class="kw2">synchronized</span> <span class="kw2">class</span> MySingleton <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span class="kw21">String</span></a> singleton = <span class="st0">&quot;Singleton String&quot;</span>;<br />
<span class="br0">&#125;</span></div>
<p>Another bright idea! Developer didn&#8217;t noticed that you can&#8217;t add modifier &#8220;synchronized&#8221; to class.</p>
<p>General recommendation. If you&#8217;re Java Developer (in those cases Senior Java Developer), please try to learn simple design patterns used in object oriented languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/02/some-developers-have-trouble-writing-singleton/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Introducing wklej.org integration for Eclipse JDT plug-in</title>
		<link>http://www.milewski.ws/2009/02/introducing-wklejorg-integration-for-eclipse-jdt-plug-in/</link>
		<comments>http://www.milewski.ws/2009/02/introducing-wklejorg-integration-for-eclipse-jdt-plug-in/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 19:05:27 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JDT]]></category>

		<category><![CDATA[Plug-in]]></category>

		<category><![CDATA[Projects]]></category>

		<category><![CDATA[wklej.org]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=237</guid>
		<description><![CDATA[Although I&#8217;ve wrote dozens of Eclipse plug-ins, all of them (except those for Eclipse DemoCamp) are during my day job. This time, I&#8217;ve managed to find enough free time and wrote simple yet useful plug-in for Eclipse JDT.
 wklej.org integration for Eclipse JDT
Main purpose of this plug-in is to provide convenient way of sharing pieces [...]]]></description>
			<content:encoded><![CDATA[<p>Although I&#8217;ve wrote dozens of Eclipse plug-ins, all of them (except those for Eclipse DemoCamp) are during my day job. This time, I&#8217;ve managed to find enough free time and wrote simple yet useful plug-in for Eclipse JDT.</p>
<p><strong><img src="http://www.milewski.ws/wp-content/uploads/2009/02/wklejorg.png" alt="wklej.org icon" title="wklej.org icon" width="16" height="16" class="alignnone size-full wp-image-265" style="margin: 0px; padding: 0px;" /> wklej.org integration for Eclipse JDT</strong></p>
<p>Main purpose of this plug-in is to provide convenient way of sharing pieces of code through <a href="http://wklej.org">wklej.org</a> service.<br />
<img src="http://www.milewski.ws/wp-content/uploads/2009/02/wklejorg-jdt-1.png" alt="wklej.org QuickFix" title="wklej.org QuickFix" width="393" height="268" class="alignnone size-full wp-image-268" style="margin: 0px; padding: 0px;" /></p>
<p>You&#8217;re able to send selection to <a href="http://wklej.org">wklej.org</a> privately or publicly. To do that, select part of the code you want to share and press <strong>Ctrl+1</strong> (Quick Fix context menu item). After successful send plug-in will open browser window/tab with result page from <a href="http://wklej.org">wklej.org</a>. Plug-in also contribute preference page to set up your name displayed on the result page.</p>
<p class="download">Download it here:<br /><a href="http://www.milewski.ws/download/org.khrone.eclipse.jdt.wklej_0.1.0.200902100044.jar">org.khrone.eclipse.jdt.wklej_0.1.0 (14.71 KB)</a><br /><a href="http://www.milewski.ws/download/org.khrone.eclipse.jdt.wklej_0.1.0.200902100044.zip">org.khrone.eclipse.jdt.wklej_0.1.0 source code (13.26 KB)</a></p>
<p>Plug-in requires Eclipse 3.4 Ganymede. First version supports only JDT (Java class files). Future version will support more environments, e.g. PDT, CDT.</p>
<p>Plug-in is published under Eclipse Public License (EPL). Read up on it <a href="http://www.eclipse.org/legal/epl-v10.html">here</a>.</p>
<p>For a quick installation, drop plug-in file (org.khrone.eclipse.jdt.wklej_0.1.0.200902100044.jar) to dropins folder.</p>
<p>Enjoy and leave comments if you found the plug-in useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/02/introducing-wklejorg-integration-for-eclipse-jdt-plug-in/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Example plug-ins from Eclipse DemoCamp are now available</title>
		<link>http://www.milewski.ws/2009/01/example-plug-ins-from-eclipse-democamp-are-now-available/</link>
		<comments>http://www.milewski.ws/2009/01/example-plug-ins-from-eclipse-democamp-are-now-available/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 23:00:53 +0000</pubDate>
		<dc:creator>Łukasz Milewski</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[English]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[DemoCamp]]></category>

		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.milewski.ws/?p=207</guid>
		<description><![CDATA[It took a while to find some spare time to write JavaDoc comments (with the exception of org.khrone.example.app.rssview plug-in) but I&#8217;ve finally managed to do that and here it is. Simple application that I&#8217;ve presented during my presentation.
Download it here:1.0.0 - org.khrone.example.app (426.08 KB)
RssView plug-in includes software developed by the JDOM Project and Project ROME
]]></description>
			<content:encoded><![CDATA[<p>It took a while to find some spare time to write JavaDoc comments (with the exception of org.khrone.example.app.rssview plug-in) but I&#8217;ve finally managed to do that and here it is. Simple application that I&#8217;ve presented during my presentation.</p>
<p class="download">Download it here:<br />1.0.0 - <a href="http://www.milewski.ws/download/org.khrone.example.app.zip">org.khrone.example.app (426.08 KB)</a></p>
<p>RssView plug-in includes software developed by the <a href="http://www.jdom.org/">JDOM Project</a> and <a href="https://rome.dev.java.net/">Project ROME</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milewski.ws/2009/01/example-plug-ins-from-eclipse-democamp-are-now-available/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
