<?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>batteryslave &#187; coding</title>
	<atom:link href="http://www.batteryslave.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.batteryslave.com</link>
	<description>minor thoughts about gadgets, code, podcasts and other technical stuff...</description>
	<lastBuildDate>Thu, 25 Aug 2011 15:46:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>python interop: using jython and ironruby</title>
		<link>http://www.batteryslave.com/2010/11/python-interop-using-jython-and-ironruby/</link>
		<comments>http://www.batteryslave.com/2010/11/python-interop-using-jython-and-ironruby/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 20:13:04 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[pyhton]]></category>
		<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[interop]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=197</guid>
		<description><![CDATA[in a project with java and .net komponents we needed to share some validation-code. this code should be executable on both platforms and act against pocos (plain old clr objects) and pojos (plain old java objects). we tested python as a language that can be executed on both sides using jython for java and ironpython [...]]]></description>
			<content:encoded><![CDATA[<p>in a project with java and .net komponents we needed to share some validation-code. this code should be executable on both platforms and act against pocos (plain old clr objects) and pojos (plain old java objects). we tested python as a language that can be executed on both sides using jython for java and ironpython for c#. i want to show you how simple an integration of python is here.</p>
<p>for c# and ironpython:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">IronPython.Hosting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Scripting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Scripting.Hosting</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> IronPythonValidationTest <span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> code <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;
if this.Von &gt; this.Bis:
    result = 'von soll kleiner sein als bis'
elif this.Child.Name != '':
    result = 'name soll gefüllt sein'&quot;</span><span style="color: #008000;">;</span>
&nbsp;
      ScriptEngine engine <span style="color: #008000;">=</span> Python<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateEngine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      ScriptScope scope <span style="color: #008000;">=</span> engine<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateScope</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      scope<span style="color: #008000;">.</span><span style="color: #0000FF;">SetVariable</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;this&quot;</span>, <span style="color: #008000;">new</span> TestType <span style="color: #008000;">&#123;</span>Von <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddDays</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>, Bis <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span>, Child <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TestTypeNested<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      ScriptSource source <span style="color: #008000;">=</span> engine<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateScriptSourceFromString</span><span style="color: #008000;">&#40;</span>code, SourceCodeKind<span style="color: #008000;">.</span><span style="color: #0000FF;">SingleStatement</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      source<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span>scope<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> validationResult <span style="color: #008000;">=</span> scope<span style="color: #008000;">.</span><span style="color: #0000FF;">GetVariable</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;result&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>validationResult<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> TestType <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> DateTime Von <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> DateTime Bis <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> TestTypeNested Child <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> TestTypeNested <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> NochName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>and almost the same for java:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.python.util.PythonInterpreter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.python.core.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JythonValidationTest <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		PythonInterpreter python <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PythonInterpreter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> code <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;if this.Von &gt; this.Bis:<span style="color: #000099; font-weight: bold;">\n</span>    result = <span style="color: #000099; font-weight: bold;">\&quot;</span>von soll kleiner sein als bis<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>elif this.Child.Name != <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\n</span>    result = <span style="color: #000099; font-weight: bold;">\&quot;</span>name soll gefüllt sein<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
		PyCode pc <span style="color: #339933;">=</span> python.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span>code<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		TestType l <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		l.<span style="color: #006633;">setVon</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        l.<span style="color: #006633;">setBis</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		python.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;this&quot;</span>, l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this has to be a public class, so one could not put it in one classfile</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestType <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> von<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> bis<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getVon<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> von<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setVon<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> von<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">von</span> <span style="color: #339933;">=</span> von<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getBis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> bis<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setBis<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> bis<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">bis</span> <span style="color: #339933;">=</span> bis<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>remaining problems:</p>
<ul>
<li>because of naming-convention ifferences you have to wrap python code so that you can intersept calls to get*() methods. as in c# getters and setters look like Name instead of getName()</li>
<li>if there are user visible strings involved, you have to think about translating them</li>
<li>checking the python code before deployment</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2010/11/python-interop-using-jython-and-ironruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java-bits #1: filedragdrop handler</title>
		<link>http://www.batteryslave.com/2010/11/java-bits-1-filedragdrop-handler/</link>
		<comments>http://www.batteryslave.com/2010/11/java-bits-1-filedragdrop-handler/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 18:06:53 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[dragdrop]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=178</guid>
		<description><![CDATA[drop a file from the explorer to a textbox and make the path the text of that textbox: // imports omitted, dont know why... public class Foo extends TransferHandler &#123; &#160; //... &#160; /* DRAG &#38;amp;amp; DROP */ @Override public boolean importData&#40;JComponent comp, Transferable t&#41; &#123; // Make sure we have the right starting points [...]]]></description>
			<content:encoded><![CDATA[<p>drop a file from the explorer to a textbox and make the path the text of that textbox:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// imports omitted, dont know why...</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #000000; font-weight: bold;">extends</span> TransferHandler <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//...</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
DRAG &amp;amp;amp; DROP
*/</span>
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> importData<span style="color: #009900;">&#40;</span><span style="color: #003399;">JComponent</span> comp, <span style="color: #003399;">Transferable</span> t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Make sure we have the right starting points</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>comp <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">JTextField</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>t.<span style="color: #006633;">isDataFlavorSupported</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">DataFlavor</span>.<span style="color: #006633;">javaFileListFlavor</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Grab the tree, its model and the root node</span>
<span style="color: #003399;">JTextField</span> textField <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">JTextField</span><span style="color: #009900;">&#41;</span> comp<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">List</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> t.<span style="color: #006633;">getTransferData</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">DataFlavor</span>.<span style="color: #006633;">javaFileListFlavor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object <span style="color: #339933;">:</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">File</span> f <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span><span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
textField.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedFlavorException</span> ufe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ack! we should not be here.<span style="color: #000099; font-weight: bold;">\n</span>Bad Flavor.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ioe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Something failed during import:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> ioe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> canImport<span style="color: #009900;">&#40;</span><span style="color: #003399;">JComponent</span> comp, <span style="color: #003399;">DataFlavor</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> transferFlavors<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>comp <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">JTextField</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">DataFlavor</span> transferFlavor <span style="color: #339933;">:</span> transferFlavors<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>transferFlavor.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">DataFlavor</span>.<span style="color: #006633;">javaFileListFlavor</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2010/11/java-bits-1-filedragdrop-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>walk in the park: installing mod_rails aka phusion passenger</title>
		<link>http://www.batteryslave.com/2009/10/walk-in-the-park-installing-mod_rails-aka-phusion-passenger/</link>
		<comments>http://www.batteryslave.com/2009/10/walk-in-the-park-installing-mod_rails-aka-phusion-passenger/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 15:43:41 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=158</guid>
		<description><![CDATA[man that was easy. after my problems with getting ruby, gem and rails to run installing mod_rails aka phusion passenger was really easy: gem install passenger passenger-install-apache2-module i followed the steps that the installer told me and go. just needed to apt-get some apache dev packages and was ready to run. cant tell you how [...]]]></description>
			<content:encoded><![CDATA[<p>man that was easy. after my <a href="http://www.batteryslave.com/2009/10/getting-ruby-on-rails-to-run-on-my-debian-4-vps/">problems</a> with getting ruby, gem and rails to run installing mod_rails aka phusion passenger was really easy:</p>
<ul>
<li>gem install passenger</li>
<li>passenger-install-apache2-module</li>
</ul>
<p>i followed the steps that the installer told me and go. just needed to apt-get some apache dev packages and was ready to run. </p>
<p>cant tell you how happy i am.</p>
<p>now the rails fun can start.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/10/walk-in-the-park-installing-mod_rails-aka-phusion-passenger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>getting ruby on rails to run on my debian 4 vps</title>
		<link>http://www.batteryslave.com/2009/10/getting-ruby-on-rails-to-run-on-my-debian-4-vps/</link>
		<comments>http://www.batteryslave.com/2009/10/getting-ruby-on-rails-to-run-on-my-debian-4-vps/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 12:29:26 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=151</guid>
		<description><![CDATA[man&#8230;always fighting to get a recent version of anything to run on the debian 4 (etch) vps i have. this time: ruby on rails. ruby v1.9.1, gems 1.3.5 and ror 2.3.4 is what i had i mind. first step: download ruby. execute the usual ./configure &#038;&#038; make &#038;&#038; make install triplet. worked fine. then download [...]]]></description>
			<content:encoded><![CDATA[<p>man&#8230;always fighting to get a recent version of anything to run on the debian 4 (etch) vps i have. this time: ruby on rails. ruby v1.9.1, gems 1.3.5 and ror 2.3.4 is what i had i mind. </p>
<p>first step: download ruby. execute the usual ./configure &#038;&#038; make &#038;&#038; make install triplet. worked fine. then download ruby gems. but when i tried to run anything with gem i got:</p>
<p><code><br />
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- zlib (LoadError)<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:1<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:5<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:167:in `load_and_instantiate'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:88:in `[]'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:144:in `find_command'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:131:in `process_args'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:102:in `run'<br />
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:in `run'<br />
	from /usr/local/bin/gem:21<br />
</code></p>
<p>after googleing and trying some stuff i solved it this way:</p>
<ul>
<li>edit ruby-1.9.1-p0/ext/Setup</li>
<li>uncomment the line zlib</li>
<li>make &#038;&#038; make install again</li>
</ul>
<p>next step. successfully let gem install rails. but then <code>ruby script/server</code> stopped with:</p>
<p><code><br />
=> Booting WEBrick<br />
=> Rails 2.3.4 application starting on http://0.0.0.0:3000<br />
/usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.4/lib/initializer.rb:271:in `rescue in require_frameworks': no such file to load -- openssl (RuntimeError)<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.4/lib/initializer.rb:268:in `require_frameworks'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.4/lib/initializer.rb:134:in `process'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.4/lib/initializer.rb:113:in `run'<br />
	from /var/www/rails/ukk/config/environment.rb:9:in `<top (required)>'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `block in require'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'<br />
	from /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.4/lib/commands/server.rb:84:in `<top (required)>'<br />
	from script/server:3:in `require'<br />
	from script/server:3:in `<main>'<br />
</code></p>
<p>after a another round i found <a href="http://linuxnuggetz.blogspot.com/2009/06/ruby-on-rail-on-ubuntu.html">this site</a> with help:</p>
<ul>
<li>apt-get install openssl libssl-dev</li>
<li>apt-get install ruby1.9-dev</li>
<li>cd ruby-1.9.1-p129/ext/openssl</li>
<li>ruby extconf.rb</li>
<li>make &#038;&#038; make install</li>
</ul>
<p>that worked. nice. so now i am waiting for the next fail</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/10/getting-ruby-on-rails-to-run-on-my-debian-4-vps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>itemtemplate selection by type in xaml only</title>
		<link>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/</link>
		<comments>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 17:29:23 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=136</guid>
		<description><![CDATA[some days ago i found my self in need to change the itemtemplate in a listbox according to their type. and if with less code as possible. i had done this in a treeview but i couldnt find the code again. so i needed to figure it out again and with some help from a [...]]]></description>
			<content:encoded><![CDATA[<p>some days ago i found my self in need to change the itemtemplate in a listbox according to their type. and if with less code as possible. i had done this in a treeview but i couldnt find the code again. so i needed to figure it out again and with some help from a collegue we ended with this:</p>
<p>[source language='xml']<br />
<!-- more xaml here --></p>
<p><ItemsControl ItemsSource="{Binding Items}"><br />
  <ItemsControl.Resources><br />
    <DataTemplate DataType="{x:Type MyNameSpace:MyType1}"><br />
      <RadioButton /><br />
    </DataTemplate><br />
    <DataTemplate DataType="{x:Type MyNameSpace:MyType2}"><br />
      <ComboBox  /><br />
    </DataTemplate><br />
    <DataTemplate DataType="{x:Type MyNameSpace:MyType3}"><br />
      <TextBox /><br />
    </DataTemplate><br />
  </ItemsControl.Resources><br />
</ItemsControl></p>
<p><!-- more xaml here --><br />
[/source]</p>
<p><strong>remark</strong>: you arent allowed to give a key to that resources. i suppose the type is kind of key here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/09/itemtemplate-selection-by-type-in-xaml-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>prio conf 28.-29.10. in munich</title>
		<link>http://www.batteryslave.com/2009/09/prio-conf-28-29-10-in-munich/</link>
		<comments>http://www.batteryslave.com/2009/09/prio-conf-28-29-10-in-munich/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 17:28:41 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[conference]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=135</guid>
		<description><![CDATA[i am existed about a conference i am attending end of oktober in munich, germany: prio conference. its totally ui centric and that why its so hot. never saw such an interesting conference all about ui in germany before.]]></description>
			<content:encoded><![CDATA[<p>i am existed about a conference i am attending end of oktober in munich, germany: <a href="http://www.prio-conference.de">prio conference</a>. its totally ui centric and that why its so hot. never saw such an interesting conference all about ui in germany before. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/09/prio-conf-28-29-10-in-munich/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what is wrong with focus in wpf</title>
		<link>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/</link>
		<comments>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/#comments</comments>
		<pubDate>Thu, 14 May 2009 18:13:20 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=114</guid>
		<description><![CDATA[lately we wanted to set the initial focus on a window in wpf to improve the keyboard experience in our app. what we want to achieve is just the initial focus. so when one opens the window he can type or push the most meaningful button instantly. unfortunately we encountered several problems. at first lets [...]]]></description>
			<content:encoded><![CDATA[<p>lately we wanted to set the initial focus on a window in wpf to improve the  keyboard experience in our app. what we want to achieve is just the initial  focus. so when one opens the window he can type or push the most meaningful  button instantly. unfortunately we encountered several problems. at first lets  see what wpf offers to set the focus. there are at least 4 possibilities:</p>
<ul>
<li>FocusManager</li>
<li>Keyboard.Focus</li>
<li>InputElement.Focus</li>
<li>InputElement.MoveFocus</li>
</ul>
<p>what i understand from <a href="http://msdn.microsoft.com/en-us/library/aa969768.aspx">msdn</a> is that  the best way to set the initial focus is the focusmanager. but we encountered  two problems where that wont work:</p>
<ul>
<li>set initial focus to a button with a commandbinding</li>
<li>set initial focus to an element defined through a contenttemplate</li>
</ul>
<p>i did not understand why that is. but i found two strange things: when  setting a breakpoint in the ContentRendered-Event you can see the button is  visible, but it is disabled. so i understand that i doesnt make sense to set the  focus to a disabled element. this seems like a bug to me. another thing i could  not understand is when the content of the control is set through a  ContentTemplate the Method FrameworkElement.FindName(string elementName) wouldnt  find the element. isnt that a bug too? when you inspect the window on screen  with scoop u can see all the elements of course.<br />
i tried to use the other  focus-methods in various events but none worked. funny thing: if you set the  focus and have a breakpoint in the Loaded-Event and just go on after stopping  there the focus is correct. Racecondition?</p>
<p>so is there someone who had similar problems? am i wrong with my feeling that  these are bugs?</p>
<p>i added an example <a href="http://www.batteryslave.com/wp-content/focustests.zip">solution</a> where you can see the sourcecode.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/05/what-is-wrong-with-focus-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>skillsmatter, london: day 3</title>
		<link>http://www.batteryslave.com/2009/05/skillsmatter-london-day-3/</link>
		<comments>http://www.batteryslave.com/2009/05/skillsmatter-london-day-3/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:52:29 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=121</guid>
		<description><![CDATA[man, again a hour too early. but needed to pack my stuff so i arrived at the old sessions house on time. first session with david laribee: &#8220;towards a new architect&#8221;. man is dave a good speaker. nice minimalistic slides. and we got teamwork. i think a great exercise was the condensation of team values. [...]]]></description>
			<content:encoded><![CDATA[<p>man, again a hour too early. but needed to pack my stuff so i arrived at the old sessions house on time. first session with david laribee: &#8220;towards a new architect&#8221;.</p>
<p>man is dave a good speaker. nice minimalistic slides. and we got teamwork. i think a great exercise was the condensation of team values. we startet in small groups (5 people) &#8211; diversion phase. where we found around 25 values. all the stuff that came to our minds. then we voted on the values and found 5 top values (conversion phase, we could have summed al the teams values up but to see how it works it was enough) for which we had to find sentences to declare why we honour that value. dave suggested to print those team values so the team have them in mind always. great idea.</p>
<p>after the usual lunchbox i decided to attend the second workshop from dave. unfortunately it started a bit messy. not everybody understood what to do because the exercises where really abstract. and because i had to depart about an hour too early i couldnt see the end result.</p>
<p>as i mentioned my flight was early so i had to leave skillsmatter at 17 o&#8217;clock. too bad because they instantiated a discussion with all the speakers at 18 o&#8217;clock and a beer at the crown pub nearby after that. i should have planned my home ride on thursday. hmmm&#8230;next time.</p>
<p>baseline:<br />
i think the progressive .net workshops from skillsmatter where great. i had very good conversations (mostly limited by my speaking skills). the speakers where always near. not that they leaved after their talk but one could always get to them and ask questions. the atmosphere was very familiar. i liked the location and the organisation was very good. two things i didnt like: the internet-connection was very bad. that was really really annoying. many attendees had 3g-connections but i think if i had used mine (german provider!!) i think by boss had killed me. the second thing: the lunch boxes where a little small for my taste. but i can recommend the workshops without a doubt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/05/skillsmatter-london-day-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>skillsmatter, london: day 2</title>
		<link>http://www.batteryslave.com/2009/05/skillsmatter-london-day-2/</link>
		<comments>http://www.batteryslave.com/2009/05/skillsmatter-london-day-2/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:22:23 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=117</guid>
		<description><![CDATA[i am still not adapted to the hour time difference between germany and the uk. so i awoke a hour to early. arrived early at the old session house where the workshops take place and decided to hear the f#-workshop with robert pickering. the workshop was full of f# content. robert is real expert. the [...]]]></description>
			<content:encoded><![CDATA[<p>i am still not adapted to the hour time difference between germany and the uk. so i awoke a hour to early.</p>
<p>arrived early at the old session house where the workshops take place and decided to hear the f#-workshop with robert pickering. the workshop was full of f# content. robert is real expert. the speed we rushed through the slides was amazing. but at the and we arrived at some beautiful examples of the power of f# which robert ported from python out of the book &#8220;collective intelligence&#8221; by <span class="ptBrand">toby segaran &#8211; great read by the way. he drawed some nice dendrogramms e.g. of a blogclustering algorithm. </span></p>
<p><span class="ptBrand">after the light lunchbag (nearly the same like yesterday) james, david and i got a small beer before we joined the advanced nhibernate workshop with ayende.</span></p>
<p><span class="ptBrand">wow the room was full. big speaker, big room, big audience &#8211; great. so ayende told he has no slides and nothing prepared at all. he questioned the audience to supply topics he would then talk about. he collected about 25 topics&#8230;for a 4h workshop&#8230;not bad. and it was fun. for example the suggested topic &#8220;stored procedures&#8221; he wrote down as &#8220;stored procedures, and how they bite you in the ass&#8221;. ayende is really cool. the rest of the talk was also very passionate.</span></p>
<p>after that gojko guided the group to the alt.net beers. snacks and drinks where sponsored by thoughtworks and skillsmatter (thanks for that). i learned serialseb is the dictator of the alt.net beers. he managed the geeky crowd to really get to two talks around document databases and bdd. some of the speakers had an alcohol clouded mind to say the least. but it was real fun. it was an amazing day 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/05/skillsmatter-london-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>skillsmatter, london: day 1</title>
		<link>http://www.batteryslave.com/2009/05/skillsmatter-london-day-1/</link>
		<comments>http://www.batteryslave.com/2009/05/skillsmatter-london-day-1/#comments</comments>
		<pubDate>Mon, 11 May 2009 22:06:15 +0000</pubDate>
		<dc:creator>batteryslave</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.batteryslave.com/?p=110</guid>
		<description><![CDATA[so the first day is finished. when i arrived at skillsmatter i met michel. like expected. first talk with ian cooper about internal dsls in c#. cool intro to the matter. now i need to have a look at some stuff: push-button- vs. fluent-api nbuilder closures are code handled like data static reflection rhino dsl [...]]]></description>
			<content:encoded><![CDATA[<p>so the first day is finished. when i arrived at skillsmatter i met michel. like expected. first talk with ian cooper about internal dsls in c#. cool intro to the matter. now i need to have a look at some stuff:</p>
<ul>
<li>push-button- vs. fluent-api</li>
<li><a href="http://code.google.com/p/nbuilder/">nbuilder</a></li>
<li>closures are code handled like data</li>
<li><a href="http://ayende.com/Blog/2005/10/29/StaticReflection.aspx">static reflection</a></li>
<li><a href="http://ayende.com/default.aspx">rhino dsl</a></li>
<li><a href="http://code.google.com/p/mite-net/">mite</a></li>
</ul>
<p>after that we got a lunchbag and sat in the sun for an hour. then sebastien lambla joined. i didnt know much about him but he seemed funny and interesting so i decided to see his talk instead of the fitnesse one. and it was great. he stated that he had only 3h of sleep because he had to get openrasta to work for the workshop. but he got it and the workshop went great.<br />
when the workshop ended we all went to have a beer. there where some discussions with lambla aka serialseb, oren aka ayende and some other nice guys.<br />
we ended the evening with pizza at pizza express with 14 funny people where we had also some great discussions about latin as a language in school and introducing agile techniques to teams in very big and long lasting projects. very interesting.</p>
<p>know i am done, have a good night</p>
]]></content:encoded>
			<wfw:commentRss>http://www.batteryslave.com/2009/05/skillsmatter-london-day-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

